Skip to content

Commit

Permalink
Update preprocess.py to Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
SuprDewd committed Dec 30, 2024
1 parent fe3e900 commit 7fc16e7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PDFLATEX=pdflatex -shell-escape
all: comprog.pdf

comprog.pdf: comprog.tex
python2 preprocess.py
python3 preprocess.py
$(PDFLATEX) comprog
$(PDFLATEX) comprog
$(PDFLATEX) comprog
Expand Down
Binary file modified comprog.pdf
Binary file not shown.
50 changes: 25 additions & 25 deletions preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
def mkhash(dat):
conc = ""
for i in dat:
conc += re.sub('\s*', '', i) + "\n"
yield hashlib.md5(conc.decode('utf8')).hexdigest()[:2]
conc += re.sub(r'\s*', '', i) + "\n"
yield hashlib.md5(conc.encode('utf8')).hexdigest()[:2]

for path, dirs, files in os.walk('./code'):
for f in files:
Expand All @@ -23,31 +23,31 @@ def mkhash(dat):
pass

dat = [ line for line in open(p).read().splitlines() if not line.startswith('// vim: ') and not line.startswith('# vim: ') ]
out = open(q, 'w')

warning = False
error = False
last = False
for dat, hash in zip(dat, mkhash(dat)):
with open(q, 'w') as out:
warning = False
error = False
last = False
s = dat.lstrip(' ')
add = len(dat) - len(s)
if add > 0:
s = ' ' + s
add -= 1
s = '-'*add + s
if(len(s) > MARGIN):
print>>out, s
warning = True
last = True
if len(s) > MARGIN+4:
error = True
print len(s), MARGIN
print repr(s)
else:
if len(s) < MARGIN:
s = s+' '
print>>out, s.ljust(MARGIN, '-') + "//" + hash
for dat, hash in zip(dat, mkhash(dat)):
last = False
s = dat.lstrip(' ')
add = len(dat) - len(s)
if add > 0:
s = ' ' + s
add -= 1
s = '-'*add + s
if(len(s) > MARGIN):
out.write('%s\n' % s)
warning = True
last = True
if len(s) > MARGIN+4:
error = True
print('%d %s' % (len(s), MARGIN))
print(repr(s))
else:
if len(s) < MARGIN:
s = s+' '
out.write('%s//%s\n' % (s.ljust(MARGIN, '-'), hash))

if last:
error = True
Expand Down

0 comments on commit 7fc16e7

Please sign in to comment.