File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ PDFLATEX=pdflatex -shell-escape
33all : comprog.pdf
44
55comprog.pdf : comprog.tex
6- python2 preprocess.py
6+ python3 preprocess.py
77 $(PDFLATEX ) comprog
88 $(PDFLATEX ) comprog
99 $(PDFLATEX ) comprog
Original file line number Diff line number Diff line change 88def mkhash (dat ):
99 conc = ""
1010 for i in dat :
11- conc += re .sub ('\s*' , '' , i ) + "\n "
12- yield hashlib .md5 (conc .decode ('utf8' )).hexdigest ()[:2 ]
11+ conc += re .sub (r '\s*' , '' , i ) + "\n "
12+ yield hashlib .md5 (conc .encode ('utf8' )).hexdigest ()[:2 ]
1313
1414for path , dirs , files in os .walk ('./code' ):
1515 for f in files :
@@ -23,31 +23,31 @@ def mkhash(dat):
2323 pass
2424
2525 dat = [ line for line in open (p ).read ().splitlines () if not line .startswith ('// vim: ' ) and not line .startswith ('# vim: ' ) ]
26- out = open (q , 'w' )
2726
28- warning = False
29- error = False
30- last = False
31- for dat , hash in zip (dat , mkhash (dat )):
27+ with open (q , 'w' ) as out :
28+ warning = False
29+ error = False
3230 last = False
33- s = dat .lstrip (' ' )
34- add = len (dat ) - len (s )
35- if add > 0 :
36- s = ' ' + s
37- add -= 1
38- s = '-' * add + s
39- if (len (s ) > MARGIN ):
40- print >> out , s
41- warning = True
42- last = True
43- if len (s ) > MARGIN + 4 :
44- error = True
45- print len (s ), MARGIN
46- print repr (s )
47- else :
48- if len (s ) < MARGIN :
49- s = s + ' '
50- print >> out , s .ljust (MARGIN , '-' ) + "//" + hash
31+ for dat , hash in zip (dat , mkhash (dat )):
32+ last = False
33+ s = dat .lstrip (' ' )
34+ add = len (dat ) - len (s )
35+ if add > 0 :
36+ s = ' ' + s
37+ add -= 1
38+ s = '-' * add + s
39+ if (len (s ) > MARGIN ):
40+ out .write ('%s\n ' % s )
41+ warning = True
42+ last = True
43+ if len (s ) > MARGIN + 4 :
44+ error = True
45+ print ('%d %s' % (len (s ), MARGIN ))
46+ print (repr (s ))
47+ else :
48+ if len (s ) < MARGIN :
49+ s = s + ' '
50+ out .write ('%s//%s\n ' % (s .ljust (MARGIN , '-' ), hash ))
5151
5252 if last :
5353 error = True
You can’t perform that action at this time.
0 commit comments