Commit ac6df95d authored by Andrew M. Kuchling's avatar Andrew M. Kuchling

Fix use of 'file' as a variable name.

    (I've tested the fixes, but please proofread anyway.)
parent bf1bef82
...@@ -34,15 +34,15 @@ status = 0 # Exit status, set to 1 on errors ...@@ -34,15 +34,15 @@ status = 0 # Exit status, set to 1 on errors
# Compute max file name length # Compute max file name length
maxlen = 1 maxlen = 1
for file in sys.argv[1:]: for filename in sys.argv[1:]:
if len(file) > maxlen: maxlen = len(file) maxlen = max(maxlen, len(filename))
# Process each argument in turn # Process each argument in turn
for file in sys.argv[1:]: for filename in sys.argv[1:]:
try: try:
st = statfunc(file) st = statfunc(filename)
except os.error, msg: except os.error, msg:
sys.stderr.write('can\'t stat ' + `file` + ': ' + `msg` + '\n') sys.stderr.write('can\'t stat ' + `filename` + ': ' + `msg` + '\n')
status = 1 status = 1
st = () st = ()
if st: if st:
...@@ -50,7 +50,7 @@ for file in sys.argv[1:]: ...@@ -50,7 +50,7 @@ for file in sys.argv[1:]:
size = st[ST_SIZE] size = st[ST_SIZE]
age = now - anytime age = now - anytime
byteyears = float(size) * float(age) / secs_per_year byteyears = float(size) * float(age) / secs_per_year
print file.ljust(maxlen), print filename.ljust(maxlen),
print repr(int(byteyears)).rjust(8) print repr(int(byteyears)).rjust(8)
sys.exit(status) sys.exit(status)
...@@ -11,8 +11,8 @@ def main(): ...@@ -11,8 +11,8 @@ def main():
while line[i] in '0123456789': i = i+1 while line[i] in '0123456789': i = i+1
size = eval(line[:i]) size = eval(line[:i])
while line[i] in ' \t': i = i+1 while line[i] in ' \t': i = i+1
file = line[i:-1] filename = line[i:-1]
comps = file.split('/') comps = filename.split('/')
if comps[0] == '': comps[0] = '/' if comps[0] == '': comps[0] = '/'
if comps[len(comps)-1] == '': del comps[len(comps)-1] if comps[len(comps)-1] == '': del comps[len(comps)-1]
total, d = store(size, comps, total, d) total, d = store(size, comps, total, d)
......
...@@ -21,12 +21,12 @@ import sys,re ...@@ -21,12 +21,12 @@ import sys,re
expr = r'^[ \t]*(def|class)[ \t]+([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*[:\(]' expr = r'^[ \t]*(def|class)[ \t]+([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*[:\(]'
matcher = re.compile(expr) matcher = re.compile(expr)
def treat_file(file, outfp): def treat_file(filename, outfp):
"""Append tags found in file named 'file' to the open file 'outfp'""" """Append tags found in file named 'filename' to the open file 'outfp'"""
try: try:
fp = open(file, 'r') fp = open(filename, 'r')
except: except:
sys.stderr.write('Cannot open %s\n'%file) sys.stderr.write('Cannot open %s\n'%filename)
return return
charno = 0 charno = 0
lineno = 0 lineno = 0
...@@ -39,18 +39,18 @@ def treat_file(file, outfp): ...@@ -39,18 +39,18 @@ def treat_file(file, outfp):
lineno = lineno + 1 lineno = lineno + 1
m = matcher.search(line) m = matcher.search(line)
if m: if m:
tag = m.group(0) + '\177%d,%d\n'%(lineno,charno) tag = m.group(0) + '\177%d,%d\n' % (lineno, charno)
tags.append(tag) tags.append(tag)
size = size + len(tag) size = size + len(tag)
charno = charno + len(line) charno = charno + len(line)
outfp.write('\f\n%s,%d\n'%(file,size)) outfp.write('\f\n%s,%d\n' % (filename,size))
for tag in tags: for tag in tags:
outfp.write(tag) outfp.write(tag)
def main(): def main():
outfp = open('TAGS', 'w') outfp = open('TAGS', 'w')
for file in sys.argv[1:]: for filename in sys.argv[1:]:
treat_file(file, outfp) treat_file(filename, outfp)
if __name__=="__main__": if __name__=="__main__":
main() main()
...@@ -37,8 +37,8 @@ def main(): ...@@ -37,8 +37,8 @@ def main():
if o == "-l": if o == "-l":
listnames = 1 listnames = 1
exit = None exit = None
for file in args: for filename in args:
x = process(file, listnames) x = process(filename, listnames)
exit = exit or x exit = exit or x
return exit return exit
...@@ -47,11 +47,11 @@ def usage(msg): ...@@ -47,11 +47,11 @@ def usage(msg):
sys.stderr.write("Usage: %s [-l] file ...\n" % sys.argv[0]) sys.stderr.write("Usage: %s [-l] file ...\n" % sys.argv[0])
sys.stderr.write("Try `%s -h' for more information.\n" % sys.argv[0]) sys.stderr.write("Try `%s -h' for more information.\n" % sys.argv[0])
def process(file, listnames): def process(filename, listnames):
if os.path.isdir(file): if os.path.isdir(filename):
return processdir(file, listnames) return processdir(filename, listnames)
try: try:
fp = open(file) fp = open(filename)
except IOError, msg: except IOError, msg:
sys.stderr.write("Can't open: %s\n" % msg) sys.stderr.write("Can't open: %s\n" % msg)
return 1 return 1
...@@ -60,11 +60,11 @@ def process(file, listnames): ...@@ -60,11 +60,11 @@ def process(file, listnames):
for type, token, (row, col), end, line in g: for type, token, (row, col), end, line in g:
if token in ("/", "/="): if token in ("/", "/="):
if listnames: if listnames:
print file print filename
break break
if row != lastrow: if row != lastrow:
lastrow = row lastrow = row
print "%s:%d:%s" % (file, row, line), print "%s:%d:%s" % (filename, row, line),
fp.close() fp.close()
def processdir(dir, listnames): def processdir(dir, listnames):
......
...@@ -164,8 +164,8 @@ def main(): ...@@ -164,8 +164,8 @@ def main():
return return
files.sort() files.sort()
exit = None exit = None
for file in files: for filename in files:
x = process(file, warnings[file]) x = process(filename, warnings[filename])
exit = exit or x exit = exit or x
return exit return exit
...@@ -194,23 +194,23 @@ def readwarnings(warningsfile): ...@@ -194,23 +194,23 @@ def readwarnings(warningsfile):
if line.find("division") >= 0: if line.find("division") >= 0:
sys.stderr.write("Warning: ignored input " + line) sys.stderr.write("Warning: ignored input " + line)
continue continue
file, lineno, what = m.groups() filename, lineno, what = m.groups()
list = warnings.get(file) list = warnings.get(filename)
if list is None: if list is None:
warnings[file] = list = [] warnings[filename] = list = []
list.append((int(lineno), intern(what))) list.append((int(lineno), intern(what)))
f.close() f.close()
return warnings return warnings
def process(file, list): def process(filename, list):
print "-"*70 print "-"*70
assert list # if this fails, readwarnings() is broken assert list # if this fails, readwarnings() is broken
try: try:
fp = open(file) fp = open(filename)
except IOError, msg: except IOError, msg:
sys.stderr.write("can't open: %s\n" % msg) sys.stderr.write("can't open: %s\n" % msg)
return 1 return 1
print "Index:", file print "Index:", filename
f = FileContext(fp) f = FileContext(fp)
list.sort() list.sort()
index = 0 # list[:index] has been processed, list[index:] is still to do index = 0 # list[:index] has been processed, list[index:] is still to do
......
...@@ -6,28 +6,28 @@ import sys ...@@ -6,28 +6,28 @@ import sys
def main(): def main():
args = sys.argv[1:] args = sys.argv[1:]
for file in args: for filename in args:
process(file) process(filename)
def process(file): def process(filename):
try: try:
f = open(file, 'r') f = open(filename, 'r')
except IOError, msg: except IOError, msg:
sys.stderr.write('%s: can\'t open: %s\n' % (file, str(msg))) sys.stderr.write('%s: can\'t open: %s\n' % (filename, str(msg)))
return return
data = f.read() data = f.read()
f.close() f.close()
if data[:2] <> '/*': if data[:2] <> '/*':
sys.stderr.write('%s does not begin with C comment\n' % file) sys.stderr.write('%s does not begin with C comment\n' % filename)
return return
try: try:
f = open(file, 'w') f = open(filename, 'w')
except IOError, msg: except IOError, msg:
sys.stderr.write('%s: can\'t write: %s\n' % (file, str(msg))) sys.stderr.write('%s: can\'t write: %s\n' % (filename, str(msg)))
return return
sys.stderr.write('Processing %s ...\n' % file) sys.stderr.write('Processing %s ...\n' % filename)
magic = 'Py_' magic = 'Py_'
for c in file: for c in filename:
if ord(c)<=0x80 and c.isalnum(): if ord(c)<=0x80 and c.isalnum():
magic = magic + c.upper() magic = magic + c.upper()
else: magic = magic + '_' else: magic = magic + '_'
......
...@@ -8,23 +8,23 @@ import re ...@@ -8,23 +8,23 @@ import re
def main(): def main():
for file in sys.argv[1:]: for filename in sys.argv[1:]:
try: try:
f = open(file, 'r') f = open(filename, 'r')
except IOError, msg: except IOError, msg:
print file, ': can\'t open :', msg print filename, ': can\'t open :', msg
continue continue
line = f.readline() line = f.readline()
if not re.match('^#! */usr/local/bin/python', line): if not re.match('^#! */usr/local/bin/python', line):
print file, ': not a /usr/local/bin/python script' print filename, ': not a /usr/local/bin/python script'
f.close() f.close()
continue continue
rest = f.read() rest = f.read()
f.close() f.close()
line = re.sub('/usr/local/bin/python', line = re.sub('/usr/local/bin/python',
'/usr/bin/env python', line) '/usr/bin/env python', line)
print file, ':', `line` print filename, ':', `line`
f = open(file, "w") f = open(filename, "w")
f.write(line) f.write(line)
f.write(rest) f.write(rest)
f.close() f.close()
......
...@@ -384,9 +384,9 @@ def makedir(pathname): ...@@ -384,9 +384,9 @@ def makedir(pathname):
# rval() but is still somewhat readable (i.e. not a single long line). # rval() but is still somewhat readable (i.e. not a single long line).
# Also creates a backup file. # Also creates a backup file.
def writedict(dict, filename): def writedict(dict, filename):
dir, file = os.path.split(filename) dir, fname = os.path.split(filename)
tempname = os.path.join(dir, '@' + file) tempname = os.path.join(dir, '@' + fname)
backup = os.path.join(dir, file + '~') backup = os.path.join(dir, fname + '~')
try: try:
os.unlink(backup) os.unlink(backup)
except os.error: except os.error:
......
...@@ -42,11 +42,11 @@ def main(): ...@@ -42,11 +42,11 @@ def main():
undefs.append(a) undefs.append(a)
if not args: if not args:
args = ['-'] args = ['-']
for file in args: for filename in args:
if file == '-': if filename == '-':
process(sys.stdin, sys.stdout) process(sys.stdin, sys.stdout)
else: else:
f = open(file, 'r') f = open(filename, 'r')
process(f, sys.stdout) process(f, sys.stdout)
f.close() f.close()
......
...@@ -38,9 +38,9 @@ def mkrealdir(name): ...@@ -38,9 +38,9 @@ def mkrealdir(name):
os.chmod(name, mode) os.chmod(name, mode)
linkto = join(os.pardir, linkto) linkto = join(os.pardir, linkto)
# #
for file in files: for filename in files:
if file not in (os.curdir, os.pardir): if filename not in (os.curdir, os.pardir):
os.symlink(join(linkto, file), join(name, file)) os.symlink(join(linkto, filename), join(name, filename))
def main(): def main():
sys.stdout = sys.stderr sys.stdout = sys.stderr
......
...@@ -63,9 +63,9 @@ undef2file = {} ...@@ -63,9 +63,9 @@ undef2file = {}
# Read one input file and merge the data into the tables. # Read one input file and merge the data into the tables.
# Argument is an open file. # Argument is an open file.
# #
def readinput(file): def readinput(fp):
while 1: while 1:
s = file.readline() s = fp.readline()
if not s: if not s:
break break
# If you get any output from this line, # If you get any output from this line,
...@@ -88,9 +88,9 @@ def readinput(file): ...@@ -88,9 +88,9 @@ def readinput(file):
def printcallee(): def printcallee():
flist = file2undef.keys() flist = file2undef.keys()
flist.sort() flist.sort()
for file in flist: for filename in flist:
print file + ':' print filename + ':'
elist = file2undef[file] elist = file2undef[filename]
elist.sort() elist.sort()
for ext in elist: for ext in elist:
if len(ext) >= 8: if len(ext) >= 8:
...@@ -107,38 +107,38 @@ def printcallee(): ...@@ -107,38 +107,38 @@ def printcallee():
def printcaller(): def printcaller():
files = file2def.keys() files = file2def.keys()
files.sort() files.sort()
for file in files: for filename in files:
callers = [] callers = []
for label in file2def[file]: for label in file2def[filename]:
if undef2file.has_key(label): if undef2file.has_key(label):
callers = callers + undef2file[label] callers = callers + undef2file[label]
if callers: if callers:
callers.sort() callers.sort()
print file + ':' print filename + ':'
lastfn = '' lastfn = ''
for fn in callers: for fn in callers:
if fn <> lastfn: if fn <> lastfn:
print '\t' + fn print '\t' + fn
lastfn = fn lastfn = fn
else: else:
print file + ': unused' print filename + ': unused'
# Print undefine names and where they are used. # Print undefined names and where they are used.
# #
def printundef(): def printundef():
undefs = {} undefs = {}
for file in file2undef.keys(): for filename in file2undef.keys():
for ext in file2undef[file]: for ext in file2undef[filename]:
if not def2file.has_key(ext): if not def2file.has_key(ext):
store(undefs, ext, file) store(undefs, ext, filename)
elist = undefs.keys() elist = undefs.keys()
elist.sort() elist.sort()
for ext in elist: for ext in elist:
print ext + ':' print ext + ':'
flist = undefs[ext] flist = undefs[ext]
flist.sort() flist.sort()
for file in flist: for filename in flist:
print '\t' + file print '\t' + filename
# Print warning messages about names defined in more than one file. # Print warning messages about names defined in more than one file.
# #
...@@ -181,11 +181,11 @@ def main(): ...@@ -181,11 +181,11 @@ def main():
optu = optc = optd = 1 optu = optc = optd = 1
if not args: if not args:
args = ['-'] args = ['-']
for file in args: for filename in args:
if file == '-': if filename == '-':
readinput(sys.stdin) readinput(sys.stdin)
else: else:
readinput(open(file, 'r')) readinput(open(filename, 'r'))
# #
warndups() warndups()
# #
......
...@@ -531,8 +531,8 @@ def test(): ...@@ -531,8 +531,8 @@ def test():
action(sys.stdin, sys.stdout, stepsize, tabsize, expandtabs) action(sys.stdin, sys.stdout, stepsize, tabsize, expandtabs)
else: else:
action = eval(action + '_file') action = eval(action + '_file')
for file in args: for filename in args:
action(file, stepsize, tabsize, expandtabs) action(filename, stepsize, tabsize, expandtabs)
# end for # end for
# end if # end if
# end def test # end def test
......
...@@ -16,7 +16,8 @@ tags = [] # Modified global variable! ...@@ -16,7 +16,8 @@ tags = [] # Modified global variable!
def main(): def main():
args = sys.argv[1:] args = sys.argv[1:]
for file in args: treat_file(file) for filename in args:
treat_file(filename)
if tags: if tags:
fp = open('tags', 'w') fp = open('tags', 'w')
tags.sort() tags.sort()
...@@ -26,16 +27,16 @@ def main(): ...@@ -26,16 +27,16 @@ def main():
expr = '^[ \t]*(def|class)[ \t]+([a-zA-Z0-9_]+)[ \t]*[:\(]' expr = '^[ \t]*(def|class)[ \t]+([a-zA-Z0-9_]+)[ \t]*[:\(]'
matcher = re.compile(expr) matcher = re.compile(expr)
def treat_file(file): def treat_file(filename):
try: try:
fp = open(file, 'r') fp = open(filename, 'r')
except: except:
sys.stderr.write('Cannot open %s\n' % file) sys.stderr.write('Cannot open %s\n' % filename)
return return
base = os.path.basename(file) base = os.path.basename(filename)
if base[-3:] == '.py': if base[-3:] == '.py':
base = base[:-3] base = base[:-3]
s = base + '\t' + file + '\t' + '1\n' s = base + '\t' + filename + '\t' + '1\n'
tags.append(s) tags.append(s)
while 1: while 1:
line = fp.readline() line = fp.readline()
...@@ -45,7 +46,7 @@ def treat_file(file): ...@@ -45,7 +46,7 @@ def treat_file(file):
if m: if m:
content = m.group(0) content = m.group(0)
name = m.group(2) name = m.group(2)
s = name + '\t' + file + '\t/^' + content + '/\n' s = name + '\t' + filename + '\t/^' + content + '/\n'
tags.append(s) tags.append(s)
main() main()
...@@ -9,21 +9,21 @@ import sys ...@@ -9,21 +9,21 @@ import sys
def main(): def main():
files = sys.argv[1:] files = sys.argv[1:]
suffixes = {} suffixes = {}
for file in files: for filename in files:
suff = getsuffix(file) suff = getsuffix(filename)
if not suffixes.has_key(suff): if not suffixes.has_key(suff):
suffixes[suff] = [] suffixes[suff] = []
suffixes[suff].append(file) suffixes[suff].append(filename)
keys = suffixes.keys() keys = suffixes.keys()
keys.sort() keys.sort()
for suff in keys: for suff in keys:
print `suff`, len(suffixes[suff]) print `suff`, len(suffixes[suff])
def getsuffix(file): def getsuffix(filename):
suff = '' suff = ''
for i in range(len(file)): for i in range(len(filename)):
if file[i] == '.': if filename[i] == '.':
suff = file[i:] suff = filename[i:]
return suff return suff
main() main()
...@@ -20,33 +20,33 @@ def main(): ...@@ -20,33 +20,33 @@ def main():
if optname == '-t': if optname == '-t':
tabsize = int(optvalue) tabsize = int(optvalue)
for file in args: for filename in args:
process(file, tabsize) process(filename, tabsize)
def process(file, tabsize): def process(filename, tabsize):
try: try:
f = open(file) f = open(filename)
text = f.read() text = f.read()
f.close() f.close()
except IOError, msg: except IOError, msg:
print "%s: I/O error: %s" % (`file`, str(msg)) print "%s: I/O error: %s" % (`filename`, str(msg))
return return
newtext = text.expandtabs(tabsize) newtext = text.expandtabs(tabsize)
if newtext == text: if newtext == text:
return return
backup = file + "~" backup = filename + "~"
try: try:
os.unlink(backup) os.unlink(backup)
except os.error: except os.error:
pass pass
try: try:
os.rename(file, backup) os.rename(filename, backup)
except os.error: except os.error:
pass pass
f = open(file, "w") f = open(filename, "w")
f.write(newtext) f.write(newtext)
f.close() f.close()
print file print filename
if __name__ == '__main__': if __name__ == '__main__':
main() main()
...@@ -25,29 +25,29 @@ if sys.argv[1:] and sys.argv[1][:2] == '-l': ...@@ -25,29 +25,29 @@ if sys.argv[1:] and sys.argv[1][:2] == '-l':
for prog in sys.argv[1:]: for prog in sys.argv[1:]:
ident = () ident = ()
for dir in pathlist: for dir in pathlist:
file = os.path.join(dir, prog) filename = os.path.join(dir, prog)
try: try:
st = os.stat(file) st = os.stat(filename)
except os.error: except os.error:
continue continue
if not S_ISREG(st[ST_MODE]): if not S_ISREG(st[ST_MODE]):
msg(file + ': not a disk file') msg(filename + ': not a disk file')
else: else:
mode = S_IMODE(st[ST_MODE]) mode = S_IMODE(st[ST_MODE])
if mode & 0111: if mode & 0111:
if not ident: if not ident:
print file print filename
ident = st[:3] ident = st[:3]
else: else:
if st[:3] == ident: if st[:3] == ident:
s = 'same as: ' s = 'same as: '
else: else:
s = 'also: ' s = 'also: '
msg(s + file) msg(s + filename)
else: else:
msg(file + ': not executable') msg(filename + ': not executable')
if longlist: if longlist:
sts = os.system('ls ' + longlist + ' ' + file) sts = os.system('ls ' + longlist + ' ' + filename)
if sts: msg('"ls -l" exit status: ' + `sts`) if sts: msg('"ls -l" exit status: ' + `sts`)
if not ident: if not ident:
msg(prog + ': not found') msg(prog + ': not found')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment