File: gendoc.py

package info (click to toggle)
python-scipy 0.6.0-12
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 32,016 kB
  • ctags: 46,675
  • sloc: cpp: 124,854; ansic: 110,614; python: 108,664; fortran: 76,260; objc: 424; makefile: 384; sh: 10
file content (41 lines) | stat: -rw-r--r-- 1,073 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python

"""generate cephes_doc.h from included_functions.html"""

import string

def parse(infile):
    d={}
    key=None
    val=''
    prev_line = ''
    for line in infile.readlines():
        if not string.strip(line):
            continue
        if line[0]=='<':
            if key and val:
                d[key]=string.strip(val)
                key,val=None,None
            if line[:4]=='<DT>':
                tok=string.split(line)
                tok=string.split(tok[-1],'(')
                key=tok[0]
            elif line[:4]=='<DD>' and key:
                prev_line = prev_line[4:]
                tok = string.split(prev_line,' = ')
                val=tok[0]+'='+line[4:]
        else:
            if val:
                val=val+line
        prev_line = line

    return d

if __name__=="__main__":
    d = parse(open("docs/included_functions.html",'r'))
    keys = d.keys()
    keys.sort()
    ofile=open("cephes_doc.h",'w')
    for key in keys:
        ofile.write('#define %s_doc "%s"\n'%(key,repr(d[key])[1:-1]))
    ofile.close()