[10] | 1 | #! /usr/bin/env python |
---|
[59] | 2 | # |
---|
| 3 | # This file is a part of LEMON, a generic C++ optimization library. |
---|
| 4 | # |
---|
| 5 | # Copyright (C) 2003-2010 |
---|
| 6 | # Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | # (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
| 8 | # |
---|
| 9 | # Permission to use, modify and distribute this software is granted |
---|
| 10 | # provided that this copyright notice appears in all copies. For |
---|
| 11 | # precise terms see the accompanying LICENSE file. |
---|
| 12 | # |
---|
| 13 | # This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | # express or implied, and with no claim as to its suitability for any |
---|
| 15 | # purpose. |
---|
| 16 | # |
---|
[10] | 17 | |
---|
| 18 | import sys |
---|
| 19 | import os |
---|
| 20 | import copy |
---|
| 21 | import re |
---|
| 22 | |
---|
[42] | 23 | max_sec_number=100 |
---|
| 24 | max_sec_depth=4 |
---|
| 25 | |
---|
[10] | 26 | def sec_inc(section, lev): |
---|
| 27 | while len(section)<lev: |
---|
| 28 | section.append(0) |
---|
| 29 | section[lev-1]+=1 |
---|
| 30 | section=section[:lev] |
---|
| 31 | return section |
---|
| 32 | |
---|
| 33 | def format_sec(sec): |
---|
| 34 | s="" |
---|
| 35 | for i in sec: |
---|
| 36 | s+=str(i)+'.' |
---|
[15] | 37 | s=s[:-1] |
---|
[10] | 38 | return s |
---|
| 39 | |
---|
[42] | 40 | def compare_sec(id1, id2): |
---|
| 41 | id1=id1.split('.') |
---|
| 42 | c1=0 |
---|
| 43 | for s in id1: |
---|
| 44 | c1=c1*max_sec_number+int(s) |
---|
| 45 | for i in range(len(id1), max_sec_depth+1): |
---|
| 46 | c1*=max_sec_number |
---|
| 47 | id2=id2.split('.') |
---|
| 48 | c2=0 |
---|
| 49 | for s in id2: |
---|
| 50 | c2=c2*max_sec_number+int(s) |
---|
| 51 | for i in range(len(id2), max_sec_depth+1): |
---|
| 52 | c2*=max_sec_number |
---|
| 53 | return c1-c2 |
---|
| 54 | |
---|
[10] | 55 | section = []; |
---|
| 56 | toc={} |
---|
| 57 | ind={} |
---|
[59] | 58 | page_files={} |
---|
| 59 | ordered_pages = [] |
---|
| 60 | |
---|
| 61 | for doxfile in os.listdir('.'): |
---|
| 62 | if doxfile[-4:]=='.dox': |
---|
| 63 | for l in open(doxfile).readlines(): |
---|
| 64 | gr = re.match(r"(^[[]PAGE[]].*[[]PAGE[]])?(.*)$", l).groups() |
---|
| 65 | if gr[0]: |
---|
| 66 | page=gr[0][6:-6] |
---|
| 67 | page_files[page]=doxfile |
---|
[10] | 68 | |
---|
| 69 | prev_page='' |
---|
| 70 | for l in open("toc.txt").readlines(): |
---|
| 71 | sl = l.split() |
---|
| 72 | if len(sl)==2 and len(sl[0])>0: |
---|
| 73 | lev=len(sl[0]) |
---|
| 74 | section=sec_inc(section,lev) |
---|
| 75 | t_sec=copy.copy(section) |
---|
| 76 | t_link=sl[1]; |
---|
| 77 | print format_sec(t_sec),t_link |
---|
| 78 | ind[t_link]=[t_sec,'',''] |
---|
| 79 | if lev==1: |
---|
| 80 | ind[t_link][1]=prev_page |
---|
| 81 | if prev_page: |
---|
| 82 | ind[prev_page][2]=t_link |
---|
| 83 | prev_page=t_link |
---|
[59] | 84 | ordered_pages.append(t_link) |
---|
[10] | 85 | toc[format_sec(t_sec)]=t_link |
---|
| 86 | |
---|
| 87 | for doxfile in os.listdir('.'): |
---|
| 88 | if doxfile[-4:]=='.dox': |
---|
| 89 | print 'Generate ',doxfile |
---|
| 90 | page='' |
---|
| 91 | fo=open(os.path.join("gen-dox",doxfile),"w") |
---|
| 92 | for l in open(doxfile).readlines(): |
---|
| 93 | gr = re.match(r"(^[[]PAGE[]].*[[]PAGE[]])?(^[[]SEC[]].*[[]SEC[]])?(^[[]TRAILER[]])?(^[[]TOC[]])?(.*)$", l).groups() |
---|
| 94 | if gr[0]: |
---|
| 95 | page=gr[0][6:-6] |
---|
| 96 | fo.write("\page %s %s%s\n"%(page, |
---|
| 97 | format_sec(ind[page][0]),gr[4])) |
---|
| 98 | elif gr[1]: |
---|
| 99 | sec=gr[1][5:-5] |
---|
| 100 | fo.write("\section %s %s%s\n"%(sec, |
---|
| 101 | format_sec(ind[sec][0]),gr[4])) |
---|
| 102 | elif gr[2]: |
---|
| 103 | prev_page=ind[page][1] |
---|
[13] | 104 | if prev_page: |
---|
[14] | 105 | prev_str= ( '<< \\ref '+prev_page+' ') |
---|
[13] | 106 | else: |
---|
| 107 | prev_str='' |
---|
[10] | 108 | next_page=ind[page][2] |
---|
[13] | 109 | if next_page: |
---|
[14] | 110 | next_str= ( ' \\ref '+next_page+' >>') |
---|
[13] | 111 | else: |
---|
| 112 | next_str='' |
---|
[26] | 113 | fo.write('%s| \\ref sec_toc "Home" |%s\n'%\ |
---|
[10] | 114 | (prev_str,next_str)) |
---|
| 115 | elif gr[3]: |
---|
[42] | 116 | secs = [ x for x in toc ] |
---|
| 117 | secs.sort(compare_sec) |
---|
[10] | 118 | for num in secs: |
---|
[15] | 119 | fo.write("%s - \\ref %s\n"%(' '*((len(ind[toc[num]][0]))), |
---|
| 120 | toc[num])) |
---|
[10] | 121 | else: |
---|
| 122 | fo.write(gr[4]+'\n') |
---|
| 123 | fo.close() |
---|
[59] | 124 | |
---|
| 125 | fpdf=open(os.path.join("gen-pdf-dox","full.dox"),"w") |
---|
| 126 | for doxfile in [page_files[p] for p in ordered_pages]: |
---|
| 127 | page='' |
---|
| 128 | for l in open(doxfile).readlines(): |
---|
| 129 | gr = re.match(r"(^[[]PAGE[]].*[[]PAGE[]])?(^[[]SEC[]].*[[]SEC[]])?(^[[]TRAILER[]])?(^[[]TOC[]])?(.*)$", l).groups() |
---|
| 130 | if gr[0]: |
---|
| 131 | page=gr[0][6:-6] |
---|
| 132 | fpdf.write("\page %s %s\n"%(page,gr[4])) |
---|
| 133 | elif gr[1]: |
---|
| 134 | sec=gr[1][5:-5] |
---|
| 135 | fpdf.write("\section %s %s\n"%(sec,gr[4])) |
---|
| 136 | elif gr[2]: |
---|
| 137 | pass |
---|
| 138 | elif gr[3]: |
---|
| 139 | pass |
---|
| 140 | else: |
---|
| 141 | fpdf.write(gr[4]+'\n') |
---|
| 142 | fpdf.close() |
---|