scripts/titlegen.py
changeset 60 202688f8024a
parent 42 6df2bf124af4
equal deleted inserted replaced
2:3a49dd30094e 3:02c0d57d9479
     1 #! /usr/bin/env python
     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 #
     2 
    17 
     3 import sys
    18 import sys
     4 import os
    19 import os
     5 import copy
    20 import copy
     6 import re
    21 import re
    38     return c1-c2
    53     return c1-c2
    39 
    54 
    40 section = [];
    55 section = [];
    41 toc={}
    56 toc={}
    42 ind={}
    57 ind={}
       
    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
    43 
    68 
    44 prev_page=''
    69 prev_page=''
    45 for l in open("toc.txt").readlines():
    70 for l in open("toc.txt").readlines():
    46     sl = l.split()
    71     sl = l.split()
    47     if len(sl)==2 and len(sl[0])>0: 
    72     if len(sl)==2 and len(sl[0])>0: 
    54         if lev==1:
    79         if lev==1:
    55             ind[t_link][1]=prev_page
    80             ind[t_link][1]=prev_page
    56             if prev_page:
    81             if prev_page:
    57                 ind[prev_page][2]=t_link
    82                 ind[prev_page][2]=t_link
    58             prev_page=t_link
    83             prev_page=t_link
       
    84             ordered_pages.append(t_link)
    59         toc[format_sec(t_sec)]=t_link
    85         toc[format_sec(t_sec)]=t_link
    60 
    86 
    61 for doxfile in os.listdir('.'):
    87 for doxfile in os.listdir('.'):
    62     if doxfile[-4:]=='.dox':
    88     if doxfile[-4:]=='.dox':
    63         print 'Generate ',doxfile
    89         print 'Generate ',doxfile
    93                     fo.write("%s - \\ref %s\n"%('  '*((len(ind[toc[num]][0]))),
   119                     fo.write("%s - \\ref %s\n"%('  '*((len(ind[toc[num]][0]))),
    94                                                 toc[num]))
   120                                                 toc[num]))
    95             else:
   121             else:
    96                 fo.write(gr[4]+'\n')
   122                 fo.write(gr[4]+'\n')
    97         fo.close()
   123         fo.close()
       
   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()