1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/scripts/titlegen.py Wed Nov 05 17:10:54 2008 +0000
1.3 @@ -0,0 +1,79 @@
1.4 +#! /usr/bin/env python
1.5 +
1.6 +import sys
1.7 +import os
1.8 +import copy
1.9 +import re
1.10 +
1.11 +def sec_inc(section, lev):
1.12 + while len(section)<lev:
1.13 + section.append(0)
1.14 + section[lev-1]+=1
1.15 + section=section[:lev]
1.16 + return section
1.17 +
1.18 +def format_sec(sec):
1.19 + s=""
1.20 + for i in sec:
1.21 + s+=str(i)+'.'
1.22 + s=s[:-1]
1.23 + return s
1.24 +
1.25 +section = [];
1.26 +toc={}
1.27 +ind={}
1.28 +
1.29 +prev_page=''
1.30 +for l in open("toc.txt").readlines():
1.31 + sl = l.split()
1.32 + if len(sl)==2 and len(sl[0])>0:
1.33 + lev=len(sl[0])
1.34 + section=sec_inc(section,lev)
1.35 + t_sec=copy.copy(section)
1.36 + t_link=sl[1];
1.37 + print format_sec(t_sec),t_link
1.38 + ind[t_link]=[t_sec,'','']
1.39 + if lev==1:
1.40 + ind[t_link][1]=prev_page
1.41 + if prev_page:
1.42 + ind[prev_page][2]=t_link
1.43 + prev_page=t_link
1.44 + toc[format_sec(t_sec)]=t_link
1.45 +
1.46 +for doxfile in os.listdir('.'):
1.47 + if doxfile[-4:]=='.dox':
1.48 + print 'Generate ',doxfile
1.49 + page=''
1.50 + fo=open(os.path.join("gen-dox",doxfile),"w")
1.51 + for l in open(doxfile).readlines():
1.52 + gr = re.match(r"(^[[]PAGE[]].*[[]PAGE[]])?(^[[]SEC[]].*[[]SEC[]])?(^[[]TRAILER[]])?(^[[]TOC[]])?(.*)$", l).groups()
1.53 + if gr[0]:
1.54 + page=gr[0][6:-6]
1.55 + fo.write("\page %s %s%s\n"%(page,
1.56 + format_sec(ind[page][0]),gr[4]))
1.57 + elif gr[1]:
1.58 + sec=gr[1][5:-5]
1.59 + fo.write("\section %s %s%s\n"%(sec,
1.60 + format_sec(ind[sec][0]),gr[4]))
1.61 + elif gr[2]:
1.62 + prev_page=ind[page][1]
1.63 + if prev_page:
1.64 + prev_str= ( '<< \\ref '+prev_page+' ')
1.65 + else:
1.66 + prev_str=''
1.67 + next_page=ind[page][2]
1.68 + if next_page:
1.69 + next_str= ( ' \\ref '+next_page+' >>')
1.70 + else:
1.71 + next_str=''
1.72 + fo.write('%s| \\ref toc "Home" |%s\n'%\
1.73 + (prev_str,next_str))
1.74 + elif gr[3]:
1.75 + secs = [ x for x in toc]
1.76 + secs.sort()
1.77 + for num in secs:
1.78 + fo.write("%s - \\ref %s\n"%(' '*((len(ind[toc[num]][0]))),
1.79 + toc[num]))
1.80 + else:
1.81 + fo.write(gr[4]+'\n')
1.82 + fo.close()