public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/modula-2] Improved comment formatting in Python3 scripts.
@ 2022-11-05 16:13 Gaius Mulley
0 siblings, 0 replies; only message in thread
From: Gaius Mulley @ 2022-11-05 16:13 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f879a1e7e7f4219c5aa264601411e1348a29c4a4
commit f879a1e7e7f4219c5aa264601411e1348a29c4a4
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date: Sat Nov 5 16:12:49 2022 +0000
Improved comment formatting in Python3 scripts.
gcc/m2/ChangeLog:
* tools-src/boilerplate.py: Improved comment formatting.
* tools-src/def2doc.py: Improved comment formatting.
* tools-src/tidydates.py: Improved comment formatting.
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Diff:
---
gcc/m2/tools-src/boilerplate.py | 52 ++++++++++++++++++---------------------
gcc/m2/tools-src/def2doc.py | 54 +++++++++++++++--------------------------
gcc/m2/tools-src/tidydates.py | 21 +++++++---------
3 files changed, 52 insertions(+), 75 deletions(-)
diff --git a/gcc/m2/tools-src/boilerplate.py b/gcc/m2/tools-src/boilerplate.py
index 5f5f1f6eaf5..697972f123b 100644
--- a/gcc/m2/tools-src/boilerplate.py
+++ b/gcc/m2/tools-src/boilerplate.py
@@ -45,12 +45,12 @@ CONTRIBUTED_BY = "ontributed by"
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=' ')
@@ -68,7 +68,7 @@ def basename(f):
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:
@@ -158,18 +158,15 @@ def analyseHeaderWithTerminator(f, start, end):
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()
@@ -340,9 +337,9 @@ def rewriteFile(f, magic, start, end, start_date, end_date,
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
@@ -396,33 +393,33 @@ def handleHeader(f, magic, start, end):
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
@@ -432,7 +429,7 @@ def inTidy(f):
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:
@@ -442,7 +439,7 @@ def doVisit(args, dirname, 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:
@@ -459,7 +456,7 @@ def visitDir(startDir, ext, func):
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)
@@ -472,11 +469,8 @@ def findFiles():
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 " +
@@ -516,15 +510,15 @@ def handleArguments():
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"):
@@ -538,7 +532,7 @@ def singleFile(name):
def main():
- # main - handleArguments and then find source files.
+ # main - handleArguments and then find source files.
global args, outputName
args = handleArguments()
outputName = args.outputfile
diff --git a/gcc/m2/tools-src/def2doc.py b/gcc/m2/tools-src/def2doc.py
index 0891b081acf..ea1ccd6f43b 100755
--- a/gcc/m2/tools-src/def2doc.py
+++ b/gcc/m2/tools-src/def2doc.py
@@ -67,10 +67,9 @@ def emitSubSection(name):
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 = ""
@@ -96,9 +95,8 @@ def displayLibraryClass():
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")
@@ -109,10 +107,9 @@ def displayMenu():
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()
@@ -135,11 +132,9 @@ def removeableField(line):
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),
@@ -148,9 +143,8 @@ def removeFields(file, 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)
@@ -228,11 +222,9 @@ def checkIndex(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()
@@ -288,9 +280,8 @@ def parseModules(up, dir, build, source, listOfModules):
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:
@@ -298,10 +289,9 @@ def doCat(name):
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)):
@@ -318,9 +308,8 @@ def moduleMenu(dir, build, source):
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)):
@@ -329,10 +318,9 @@ def checkDirectory(dir, build, source):
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
@@ -342,10 +330,9 @@ def foundFile(dir, build, source, file):
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
@@ -357,10 +344,9 @@ def findFile(dir, build, source, file):
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"))
diff --git a/gcc/m2/tools-src/tidydates.py b/gcc/m2/tools-src/tidydates.py
index 916e2073907..11fb4b90c49 100644
--- a/gcc/m2/tools-src/tidydates.py
+++ b/gcc/m2/tools-src/tidydates.py
@@ -32,7 +32,7 @@ COPYRIGHT = "Copyright (C)"
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:
@@ -46,7 +46,7 @@ def visitDir(directory, ext, func):
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:
@@ -56,7 +56,7 @@ def isYear(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)
@@ -77,14 +77,12 @@ def handleCopyright(outfile, lines, n, leader1, leader2):
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]
@@ -113,14 +111,13 @@ def handleCopyright(outfile, lines, n, leader1, leader2):
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:
@@ -142,22 +139,22 @@ def handleHeader(filename, leader1, leader2):
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)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-05 16:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-05 16:13 [gcc/devel/modula-2] Improved comment formatting in Python3 scripts Gaius Mulley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).