4747rep = sys .stdout .write
4848
4949def 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
6064def 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+
257270Reverse = 0
258271def 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