Commit 0b7b4b8a authored by Jeremy Hylton's avatar Jeremy Hylton

satisfy the tabnanny

parent 9082cdd0
......@@ -24,32 +24,33 @@ matcher = re.compile(expr)
def treat_file(file, outfp):
"""Append tags found in file named 'file' to the open file 'outfp'"""
try:
fp = open(file, 'r')
fp = open(file, 'r')
except:
sys.stderr.write('Cannot open %s\n'%file)
return
sys.stderr.write('Cannot open %s\n'%file)
return
charno = 0
lineno = 0
tags = []
size = 0
while 1:
line = fp.readline()
if not line: break
lineno = lineno + 1
m = matcher.search(line)
if m:
tag = m.group(0) + '\177%d,%d\n'%(lineno,charno)
tags.append(tag)
size = size + len(tag)
charno = charno + len(line)
line = fp.readline()
if not line:
break
lineno = lineno + 1
m = matcher.search(line)
if m:
tag = m.group(0) + '\177%d,%d\n'%(lineno,charno)
tags.append(tag)
size = size + len(tag)
charno = charno + len(line)
outfp.write('\f\n%s,%d\n'%(file,size))
for tag in tags:
outfp.write(tag)
outfp.write(tag)
def main():
outfp = open('TAGS', 'w')
for file in sys.argv[1:]:
treat_file(file, outfp)
treat_file(file, outfp)
if __name__=="__main__":
main()
......@@ -21,15 +21,15 @@ def parse(text,pos=0,endpos=None):
pos = 0
if endpos is None:
endpos = len(text)
endpos = len(text)
d = {}
while 1:
m = entityRE.search(text,pos,endpos)
if not m:
break
name,charcode,comment = m.groups()
d[name] = charcode,comment
pos = m.end()
m = entityRE.search(text,pos,endpos)
if not m:
break
name,charcode,comment = m.groups()
d[name] = charcode,comment
pos = m.end()
return d
def writefile(f,defs):
......@@ -38,27 +38,27 @@ def writefile(f,defs):
items = defs.items()
items.sort()
for name,(charcode,comment) in items:
if charcode[:2] == '&#':
code = int(charcode[2:-1])
if code < 256:
charcode = "'\%o'" % code
else:
charcode = repr(charcode)
else:
charcode = repr(charcode)
comment = TextTools.collapse(comment)
f.write(" '%s':\t%s, \t# %s\n" % (name,charcode,comment))
if charcode[:2] == '&#':
code = int(charcode[2:-1])
if code < 256:
charcode = "'\%o'" % code
else:
charcode = repr(charcode)
else:
charcode = repr(charcode)
comment = TextTools.collapse(comment)
f.write(" '%s':\t%s, \t# %s\n" % (name,charcode,comment))
f.write('\n}\n')
if __name__ == '__main__':
if len(sys.argv) > 1:
infile = open(sys.argv[1])
infile = open(sys.argv[1])
else:
infile = sys.stdin
infile = sys.stdin
if len(sys.argv) > 2:
outfile = open(sys.argv[2],'w')
outfile = open(sys.argv[2],'w')
else:
outfile = sys.stdout
outfile = sys.stdout
text = infile.read()
defs = parse(text)
writefile(outfile,defs)
......
This diff is collapsed.
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