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

satisfy the tabnanny

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