Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f62f687

Browse files
committed
Various changes, andded -c option
1 parent 4e8aef8 commit f62f687

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

Tools/scripts/fixcid.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,23 @@
4747
rep = sys.stdout.write
4848

4949
def usage():
50-
err('Usage: ' + sys.argv[0] + \
51-
' [-r] [-s file] ... file-or-directory ...\n')
50+
progname = sys.argv[0]
51+
err('Usage: ' + progname +
52+
' [-c] [-r] [-s file] ... file-or-directory ...\n')
5253
err('\n')
54+
err('-c : substitute inside comments\n')
5355
err('-r : reverse direction for following -s options\n')
5456
err('-s substfile : add a file of substitutions\n')
5557
err('\n')
5658
err('Each non-empty non-comment line in a substitution file must\n')
5759
err('contain exactly two words: an identifier and its replacement.\n')
5860
err('Comments start with a # character and end at end of line.\n')
61+
err('If an identifier is preceded with a *, it is not substituted\n')
62+
err('inside a comment even when -c is specified.\n')
5963

6064
def main():
6165
try:
62-
opts, args = getopt.getopt(sys.argv[1:], 'rs:')
66+
opts, args = getopt.getopt(sys.argv[1:], 'crs:')
6367
except getopt.error, msg:
6468
err('Options error: ' + str(msg) + '\n')
6569
usage()
@@ -69,6 +73,8 @@ def main():
6973
usage()
7074
sys.exit(2)
7175
for opt, arg in opts:
76+
if opt == '-c':
77+
setdocomments()
7278
if opt == '-r':
7379
setreverse()
7480
if opt == '-s':
@@ -146,7 +152,7 @@ def fix(filename):
146152
g = open(tempname, 'w')
147153
except IOError, msg:
148154
f.close()
149-
err(tempname+': cannot create: '+\
155+
err(tempname+': cannot create: '+
150156
str(msg)+'\n')
151157
return 1
152158
f.seek(0)
@@ -239,13 +245,15 @@ def fixline(line):
239245
if Dict.has_key(found):
240246
subst = Dict[found]
241247
if Program is InsideCommentProgram:
248+
if not Docomments:
249+
print 'Found in comment:', found
250+
continue
242251
if NotInComment.has_key(found):
243-
pass
244252
## print 'Ignored in comment:',
245253
## print found, '-->', subst
246254
## print 'Line:', line,
247255
subst = found
248-
else:
256+
## else:
249257
## print 'Substituting in comment:',
250258
## print found, '-->', subst
251259
## print 'Line:', line,
@@ -254,6 +262,11 @@ def fixline(line):
254262
i = i + n
255263
return line
256264

265+
Docomments = 0
266+
def setdocomments():
267+
global Docomments
268+
Docomments = 1
269+
257270
Reverse = 0
258271
def setreverse():
259272
global Reverse
@@ -279,7 +292,7 @@ def addsubst(substfile):
279292
words = string.split(line[:i])
280293
if not words: continue
281294
if len(words) <> 2:
282-
err(substfile + ':' + `lineno` + \
295+
err(substfile + ':' + `lineno` +
283296
': warning: bad line: ' + line)
284297
continue
285298
if Reverse:
@@ -292,10 +305,10 @@ def addsubst(substfile):
292305
key = key[1:]
293306
NotInComment[key] = value
294307
if Dict.has_key(key):
295-
err(substfile + ':' + `lineno` + \
296-
': warning: overriding: ' + \
308+
err(substfile + ':' + `lineno` +
309+
': warning: overriding: ' +
297310
key + ' ' + value + '\n')
298-
err(substfile + ':' + `lineno` + \
311+
err(substfile + ':' + `lineno` +
299312
': warning: previous: ' + Dict[key] + '\n')
300313
Dict[key] = value
301314
fp.close()

0 commit comments

Comments
 (0)