COIN-OR::LEMON - Graph Library

source: lemon-tutorial/scripts/titlegen.py

Last change on this file was 59:5d9170b19285, checked in by Alpar Juttner <alpar@…>, 10 years ago

Support of the PDF version

  • Property exe set to *
File size: 4.2 KB
Line 
1#! /usr/bin/env python
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#
17
18import sys
19import os
20import copy
21import re
22
23max_sec_number=100
24max_sec_depth=4
25
26def 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
33def format_sec(sec):
34    s=""
35    for i in sec:
36        s+=str(i)+'.'
37    s=s[:-1]
38    return s
39
40def 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
55section = [];
56toc={}
57ind={}
58page_files={}
59ordered_pages = []
60
61for 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
68
69prev_page=''
70for 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
84            ordered_pages.append(t_link)
85        toc[format_sec(t_sec)]=t_link
86
87for 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]
104                if prev_page:
105                    prev_str= ( '<< \\ref '+prev_page+' ')
106                else:
107                    prev_str=''
108                next_page=ind[page][2]
109                if next_page:
110                    next_str= ( ' \\ref '+next_page+' >>')
111                else:
112                    next_str=''
113                fo.write('%s| \\ref sec_toc "Home" |%s\n'%\
114                             (prev_str,next_str))
115            elif gr[3]:
116                secs = [ x for x in toc ]
117                secs.sort(compare_sec)
118                for num in secs:
119                    fo.write("%s - \\ref %s\n"%('  '*((len(ind[toc[num]][0]))),
120                                                toc[num]))
121            else:
122                fo.write(gr[4]+'\n')
123        fo.close()
124
125fpdf=open(os.path.join("gen-pdf-dox","full.dox"),"w")
126for 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')
142fpdf.close()
Note: See TracBrowser for help on using the repository browser.