Update of /cvsroot/hibernate/Hibernate2
In directory sc8-pr-cvs1:/tmp/cvs-serv14211
Added Files:
indent.py
Log Message:
reformatted code with beautiful, shiny, happy TABS!
improved an exception
--- NEW FILE: indent.py ---
import re
import sys
sys.argv.pop(0)
for fname in sys.argv:
file = open(fname)
inlines = file.read().split('\n')
file.close()
out= []
tabcount = 0
for ln in inlines:
code = ln.lstrip('\t ').rstrip('\t ')
clen = len(code)
if clen > 0 and code[0]=='*':
code = ' ' + code
begincb = clen > 0 and ( code[0]=='}' or code[0]==')' )
tabcount -= begincb
tabs = '\t' * tabcount
if clen>5 and code[0:6] == '} else':
code = '}\n' + tabs + 'else' + code[6:]
if clen>6 and code[0:7] == '} catch':
code = '}\n' + tabs + 'catch' + code[7:]
out.append( tabs + code + '\n' )
uncommented = code.split('//')[0].rstrip()
clen = len(uncommented)
endob = clen > 0 and ( code[clen-1]=='{' or code[clen-1]=='(' )
tabcount += endob
file = open( fname, 'w' )
for ln in out:
file.write(ln)
file.close()
|