def printf(fmt, *args):
- # printf - keeps C programmers happy :-)
+ # printf - keeps C programmers happy :-)
print(str(fmt) % args, end=' ')
def error(fmt, *args):
- # error - issue an error message.
+ # error - issue an error message.
global errorCount
print(str(fmt) % args, end=' ')
def analyseComment(text, f):
- # analyseComment determine the license from the top comment.
+ # analyseComment determine the license from the top comment.
start_date, end_date = None, None
contribution, summary, lic = None, None, None
if text.find(ISO_COPYRIGHT) > 0:
def analyseHeader(f, start, end):
- # analyseHeader -
+ # analyseHeader -
if end is None:
return analyseHeaderWithoutTerminator(f, start)
else:
return analyseHeaderWithTerminator(f, start, end)
-#
-# addStop - add a full stop to a sentance.
-#
-
def addStop(sentence):
+ # addStop - add a full stop to a sentance.
if sentence is None:
return None
sentence = sentence.rstrip()
def handleHeader(f, magic, start, end):
- # handleHeader keep reading lines of file, f, looking for start, end
- # sequences and comments inside. The comments are checked for:
- # date, contribution, summary
+ # handleHeader keep reading lines of file, f, looking for start, end
+ # sequences and comments inside. The comments are checked for:
+ # date, contribution, summary
global errorCount
errorCount = 0
def bashTidy(f):
- # bashTidy tidy up dates using '#' comment
+ # bashTidy tidy up dates using '#' comment
handleHeader(f, "#!/bin/bash", "#", None)
def pythonTidy(f):
- # pythonTidy tidy up dates using '#' comment
+ # pythonTidy tidy up dates using '#' comment
handleHeader(f, "#!/usr/bin/env python3", '#', None)
def bnfTidy(f):
- # bnfTidy tidy up dates using '--' comment
+ # bnfTidy tidy up dates using '--' comment
handleHeader(f, None, '--', None)
def cTidy(f):
- # cTidy tidy up dates using '/* */' comments
+ # cTidy tidy up dates using '/* */' comments
handleHeader(f, None, '/*', '*/')
def m2Tidy(f):
- # m2Tidy tidy up dates using '(* *)' comments
+ # m2Tidy tidy up dates using '(* *)' comments
handleHeader(f, None, '(*', '*)')
def inTidy(f):
- # inTidy tidy up dates using '#' as a comment and check
- # the first line for magic number.
+ # inTidy tidy up dates using '#' as a comment and check
+ # the first line for magic number.
first = open(f).readlines()[0]
if (len(first) > 0) and (first[:2] == "#!"):
# magic number found, use this
def doVisit(args, dirname, names):
- # doVisit helper function to call func on every extension file.
+ # doVisit helper function to call func on every extension file.
global outputName
func, extension = args
for f in names:
def visitDir(startDir, ext, func):
- # visitDir call func for each file in startDir which has ext.
+ # visitDir call func for each file in startDir which has ext.
global outputName, seenFiles
for dirName, subdirList, fileList in os.walk(startDir):
for fname in fileList:
def findFiles():
- # findFiles for each file extension call the appropriate tidy routine.
+ # findFiles for each file extension call the appropriate tidy routine.
visitDir(args.recursive, '.h.in', cTidy)
visitDir(args.recursive, '.in', inTidy)
visitDir(args.recursive, '.sh', inTidy)
visitDir(args.recursive, '.bnf', bnfTidy)
-#
-# handleArguments - check the legal arguments.
-#
-
def handleArguments():
+ # handleArguments create and return the args object.
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--contribution",
help="set the contribution string " +
def hasExt(name, ext):
- # hasExt return True if, name, ends with, ext.
+ # hasExt return True if, name, ends with, ext.
if len(name) > len(ext):
return name[-len(ext):] == ext
return False
def singleFile(name):
- # singleFile scan the single file for a GPL boilerplate which
- # has a GPL, contribution field and a summary heading.
+ # singleFile scan the single file for a GPL boilerplate which
+ # has a GPL, contribution field and a summary heading.
if hasExt(name, ".def") or hasExt(name, ".mod"):
m2Tidy(name)
elif hasExt(name, ".h") or hasExt(name, ".c") or hasExt(name, ".cc"):
def main():
- # main - handleArguments and then find source files.
+ # main - handleArguments and then find source files.
global args, outputName
args = handleArguments()
outputName = args.outputfile
output.write("-" * len(name) + "\n")
-# displayLibraryClass - displays a node for a library directory and invokes
-# a routine to summarize each module.
-
def displayLibraryClass():
+ # displayLibraryClass displays a node for a library directory and invokes
+ # a routine to summarize each module.
global args
previous = ""
nxt = libraryClassifications[i+1][1]
-# displayMenu - displays the top level menu for library documentation.
-
def displayMenu():
+ # displayMenu displays the top level menu for library documentation.
output.write("@menu\n")
for lib in libraryClassifications:
output.write("* " + lib[1] + "::" + lib[2] + "\n")
output.write("\n")
-# removeInitialComments - removes any (* *) at the top
-# of the definition module.
-
def removeInitialComments(file, line):
+ # removeInitialComments removes any (* *) at the top
+ # of the definition module.
while (str.find(line, "*)") == -1):
line = file.readline()
return False
-# removeFields - removes Author/Date/Last edit/SYSTEM/Revision
-# fields from a comment within the start of a
-# definition module.
-
def removeFields(file, line):
+ # removeFields removes Author/Date/Last edit/SYSTEM/Revision
+ # fields from a comment within the start of a definition module.
while (str.find(line, "*)") == -1):
if not removeableField(line):
output.write(str.replace(str.replace(str.rstrip(line),
output.write(str.rstrip(line) + "\n")
-# checkIndex - create an index entry for a PROCEDURE, TYPE, CONST or VAR.
-
def checkIndex(line):
+ # checkIndex - create an index entry for a PROCEDURE, TYPE, CONST or VAR.
global inVar, inType, inConst
words = str.split(line)
output.write("@findex " + proc + "\n")
-# parseDefinition - reads a definition module and creates
-# indices for procedures, constants,
-# variables and types.
-
def parseDefinition(dir, source, build, file, needPage):
+ # parseDefinition reads a definition module and creates
+ # indices for procedures, constants, variables and types.
output.write("\n")
with open(findFile(dir, build, source, file), "r") as f:
initState()
nxt = ""
-# doCat - displays the contents of file, name, to stdout
-
def doCat(name):
+ # doCat displays the contents of file, name, to stdout
with open(name, "r") as file:
line = file.readline()
while line:
line = file.readline()
-# moduleMenu - generates a simple menu for all definition modules
-# in dir
-
def moduleMenu(dir, build, source):
+ # moduleMenu generates a simple menu for all definition modules
+ # in dir
output.write("@menu\n")
listOfFiles = []
if os.path.exists(os.path.join(source, dir)):
output.write("\n")
-# checkDirectory - returns True if dir exists in either build or source.
-
def checkDirectory(dir, build, source):
+ # checkDirectory - returns True if dir exists in either build or source.
if os.path.isdir(build) and os.path.exists(os.path.join(build, dir)):
return True
elif os.path.isdir(source) and os.path.exists(os.path.join(source, dir)):
return False
-# foundFile - return True if file is found in build/dir/file or
-# source/dir/file.
-
def foundFile(dir, build, source, file):
+ # foundFile return True if file is found in build/dir/file or
+ # source/dir/file.
name = os.path.join(os.path.join(build, dir), file)
if os.path.exists(name):
return True
return False
-# findFile - return the path to file searching in build/dir/file
-# first then source/dir/file.
-
def findFile(dir, build, source, file):
+ # findFile return the path to file searching in build/dir/file
+ # first then source/dir/file.
name1 = os.path.join(os.path.join(build, dir), file)
if os.path.exists(name1):
return name1
os.sys.exit(1)
-# displayModules - walks though the files in dir and parses
-# definition modules and includes README.texi
-
def displayModules(up, dir, build, source):
+ # displayModules walks though the files in dir and parses
+ # definition modules and includes README.texi
if checkDirectory(dir, build, source):
if foundFile(dir, build, source, "README.texi"):
doCat(findFile(dir, build, source, "README.texi"))
def visitDir(directory, ext, func):
- # visitDir - call func for each file below, dir, matching extension, ext.
+ # visitDir - call func for each file below, dir, matching extension, ext.
listOfFiles = os.listdir(directory)
listOfFiles.sort()
for filename in listOfFiles:
def isYear(year):
- # isYear - returns True if, year, is legal.
+ # isYear - returns True if, year, is legal.
if len(year) == 5:
year = year[:-1]
for c in year:
def handleCopyright(outfile, lines, n, leader1, leader2):
- # handleCopyright look for Copyright in the comment.
+ # handleCopyright look for Copyright in the comment.
global maxLineLength
i = lines[n]
c = i.find(COPYRIGHT)+len(COPYRIGHT)
d = []
else:
d = d[1:]
-
if c > maxLineLength:
outfile.write("\n")
outfile.write(leader1)
outfile.write(leader2)
outfile.write(" "*(start-2))
c = start
-
if isYear(e):
if (e[-1] == ".") or (e[-1] == ","):
punctuation = e[-1]
for w in d:
outfile.write(" ")
outfile.write(w)
-
outfile.write("\n")
return outfile, n+1
def handleHeader(filename, leader1, leader2):
- # handleHeader reads in the header of a file and inserts
- # a line break around the Copyright dates.
+ # handleHeader reads in the header of a file and inserts
+ # a line break around the Copyright dates.
print("------------------------------")
lines = open(filename, "r").readlines()
if len(lines) > 20:
def bashTidy(filename):
- # bashTidy - tidy up dates using "#" comment
+ # bashTidy - tidy up dates using "#" comment
handleHeader(filename, "#", " ")
def cTidy(filename):
- # cTidy - tidy up dates using "/* */" comments
+ # cTidy - tidy up dates using "/* */" comments
handleHeader(filename, " ", "*")
def m2Tidy(filename):
- # m2Tidy - tidy up dates using "(* *)" comments
+ # m2Tidy - tidy up dates using "(* *)" comments
handleHeader(filename, " ", " ")
def main():
- # main - for each file extension call the appropriate tidy routine.
+ # main - for each file extension call the appropriate tidy routine.
visitDir(".", ".in", bashTidy)
visitDir(".", ".py", bashTidy)
visitDir(".", ".c", cTidy)