@@ -31,6 +31,7 @@ Other options:
3131import getopt
3232import glob
3333import os
34+ import re
3435import shutil
3536import string
3637import sys
@@ -166,6 +167,7 @@ class Options:
166167class Job :
167168 def __init__ (self , options , path ):
168169 self .options = options
170+ self .doctype = get_doctype (path )
169171 self .filedir , self .doc = split_pathname (path )
170172 self .log_filename = self .doc + ".how"
171173 if os .path .exists (self .log_filename ):
@@ -243,26 +245,43 @@ class Job:
243245 indfix .process (self .doc + ".ind" )
244246 if self .use_bibtex :
245247 self .run ("%s %s" % (BIBTEX_BINARY , self .doc ))
246- synopsis_file = self .doc + ".syn"
247- if os .path .isfile (synopsis_file ):
248- # impose uniq requirement on last line....
249- uniqify_module_table (synopsis_file )
250- self .run ("%s %s" % (binary , self .doc ))
251- if os .path .isfile ("mod%s.idx" % self .doc ):
252- self .run ("%s -s %s mod%s.idx"
253- % (MAKEINDEX_BINARY , ISTFILE , self .doc ))
254- if os .path .isfile (self .doc + ".idx" ):
255- self .run ("%s -s %s %s.idx" % (MAKEINDEX_BINARY , ISTFILE , self .doc ))
248+ self .process_synopsis_files ()
249+ #
250+ # let the doctype-specific handler do some intermediate work:
251+ #
252+ if self .doctype == "manual" :
253+ self .use_latex_manual (binary = binary )
254+ elif self .doctype == "howto" :
255+ self .use_latex_howto (binary = binary )
256+ else :
257+ raise RuntimeError , "unsupported document type: " + self .doctype
258+ #
259+ # and now finish it off:
260+ #
256261 if os .path .isfile (self .doc + ".toc" ) and binary == PDFLATEX_BINARY :
257262 import toc2bkm
258263 toc2bkm .process (self .doc + ".toc" , self .doc + ".bkm" , "section" )
259- if os .path .isfile (synopsis_file ):
260- # impose uniq requirement on last line....
261- uniqify_module_table (synopsis_file )
262264 if self .use_bibtex :
263265 self .run ("%s %s" % (BIBTEX_BINARY , self .doc ))
264266 self .run ("%s %s" % (binary , self .doc ))
265267
268+ def use_latex_howto (self , binary ):
269+ self .run ("%s %s" % (binary , self .doc ))
270+ if os .path .isfile ("mod%s.idx" % self .doc ):
271+ self .run ("%s -s %s mod%s.idx"
272+ % (MAKEINDEX_BINARY , ISTFILE , self .doc ))
273+ if os .path .isfile (self .doc + ".idx" ):
274+ self .run ("%s -s %s %s.idx" % (MAKEINDEX_BINARY , ISTFILE , self .doc ))
275+ self .process_synopsis_files ()
276+
277+ def use_latex_manual (self , binary ):
278+ pass
279+
280+ def process_synopsis_files (self ):
281+ synopsis_files = glob .glob (self .doc + "*.syn" )
282+ for path in synopsis_files :
283+ uniqify_module_table (path )
284+
266285 def build_ps (self ):
267286 self .run ("%s -N0 -o %s.ps %s" % (DVIPS_BINARY , self .doc , self .doc ))
268287
@@ -338,11 +357,12 @@ class Job:
338357 def cleanup (self ):
339358 self .__have_temps = 0
340359 for pattern in ("%s.aux" , "%s.log" , "%s.out" , "%s.toc" , "%s.bkm" ,
341- "%s.idx" , "%s.ilg" , "%s.ind" , "%s.syn" , "%s. pla" ,
360+ "%s.idx" , "%s.ilg" , "%s.ind" , "%s.pla" ,
342361 "%s.bbl" , "%s.blg" ,
343362 "mod%s.idx" , "mod%s.ind" , "mod%s.ilg" ,
344363 ):
345364 safe_unlink (pattern % self .doc )
365+ map (safe_unlink , glob .glob (self .doc + "*.syn" ))
346366 for spec in ("IMG*" , "*.pl" , "WARNINGS" , "index.dat" , "modindex.dat" ):
347367 pattern = os .path .join (self .doc , spec )
348368 map (safe_unlink , glob .glob (pattern ))
@@ -381,14 +401,30 @@ def safe_unlink(path):
381401 pass
382402
383403
384- def split_pathname (pathname ):
385- pathname = os .path .normpath (os .path .join (os .getcwd (), pathname ))
386- dirname , basename = os .path .split (pathname )
404+ def split_pathname (path ):
405+ path = os .path .normpath (os .path .join (os .getcwd (), path ))
406+ dirname , basename = os .path .split (path )
387407 if basename [- 4 :] == ".tex" :
388408 basename = basename [:- 4 ]
389409 return dirname , basename
390410
391411
412+ _doctype_rx = re .compile (r"\\documentclass(?:\[[^]]*\])?{([a-zA-Z]*)}" )
413+ def get_doctype (path ):
414+ fp = open (path )
415+ doctype = None
416+ while 1 :
417+ line = fp .readline ()
418+ if not line :
419+ break
420+ m = _doctype_rx .match (line )
421+ if m :
422+ doctype = m .group (1 )
423+ break
424+ fp .close ()
425+ return doctype
426+
427+
392428def main ():
393429 options = Options ()
394430 try :
0 commit comments