diff options
author | Guido van Rossum <guido@python.org> | 1994-01-07 10:55:15 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1994-01-07 10:55:15 (GMT) |
commit | f62f68745374579e615c348d2f592dfb90eec947 (patch) | |
tree | 689a3ea5e8c2a85394726e1616b7683bb2dbf53b | |
parent | 4e8aef842cf2f1b0b6115fffbd79796c54afa325 (diff) | |
download | cpython-f62f68745374579e615c348d2f592dfb90eec947.zip cpython-f62f68745374579e615c348d2f592dfb90eec947.tar.gz cpython-f62f68745374579e615c348d2f592dfb90eec947.tar.bz2 |
Various changes, andded -c option
-rwxr-xr-x | Tools/scripts/fixcid.py | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/Tools/scripts/fixcid.py b/Tools/scripts/fixcid.py index 4f72e9e..b5147c9 100755 --- a/Tools/scripts/fixcid.py +++ b/Tools/scripts/fixcid.py @@ -47,19 +47,23 @@ dbg = err rep = sys.stdout.write def usage(): - err('Usage: ' + sys.argv[0] + \ - ' [-r] [-s file] ... file-or-directory ...\n') + progname = sys.argv[0] + err('Usage: ' + progname + + ' [-c] [-r] [-s file] ... file-or-directory ...\n') err('\n') + err('-c : substitute inside comments\n') err('-r : reverse direction for following -s options\n') err('-s substfile : add a file of substitutions\n') err('\n') err('Each non-empty non-comment line in a substitution file must\n') err('contain exactly two words: an identifier and its replacement.\n') err('Comments start with a # character and end at end of line.\n') + err('If an identifier is preceded with a *, it is not substituted\n') + err('inside a comment even when -c is specified.\n') def main(): try: - opts, args = getopt.getopt(sys.argv[1:], 'rs:') + opts, args = getopt.getopt(sys.argv[1:], 'crs:') except getopt.error, msg: err('Options error: ' + str(msg) + '\n') usage() @@ -69,6 +73,8 @@ def main(): usage() sys.exit(2) for opt, arg in opts: + if opt == '-c': + setdocomments() if opt == '-r': setreverse() if opt == '-s': @@ -146,7 +152,7 @@ def fix(filename): g = open(tempname, 'w') except IOError, msg: f.close() - err(tempname+': cannot create: '+\ + err(tempname+': cannot create: '+ str(msg)+'\n') return 1 f.seek(0) @@ -239,13 +245,15 @@ def fixline(line): if Dict.has_key(found): subst = Dict[found] if Program is InsideCommentProgram: + if not Docomments: + print 'Found in comment:', found + continue if NotInComment.has_key(found): - pass ## print 'Ignored in comment:', ## print found, '-->', subst ## print 'Line:', line, subst = found - else: +## else: ## print 'Substituting in comment:', ## print found, '-->', subst ## print 'Line:', line, @@ -254,6 +262,11 @@ def fixline(line): i = i + n return line +Docomments = 0 +def setdocomments(): + global Docomments + Docomments = 1 + Reverse = 0 def setreverse(): global Reverse @@ -279,7 +292,7 @@ def addsubst(substfile): words = string.split(line[:i]) if not words: continue if len(words) <> 2: - err(substfile + ':' + `lineno` + \ + err(substfile + ':' + `lineno` + ': warning: bad line: ' + line) continue if Reverse: @@ -292,10 +305,10 @@ def addsubst(substfile): key = key[1:] NotInComment[key] = value if Dict.has_key(key): - err(substfile + ':' + `lineno` + \ - ': warning: overriding: ' + \ + err(substfile + ':' + `lineno` + + ': warning: overriding: ' + key + ' ' + value + '\n') - err(substfile + ':' + `lineno` + \ + err(substfile + ':' + `lineno` + ': warning: previous: ' + Dict[key] + '\n') Dict[key] = value fp.close() |