]>
git.saurik.com Git - wxWidgets.git/blob - misc/scripts/update_doc_libs.py
1 ##############################################################################
2 # Name: misc/scripts/update_doc_libs.py
3 # Purpose: Automatically insert \Library{} headers in the doc files
5 # Copyright: (c) 2007 Francesco Montorsi
6 # Licence: wxWindows licence
7 ##############################################################################
9 from update_doc_utils
import scanTexFiles
11 INCLUDE_PATH
="../../include"
13 def myCallback(classname
, texFileName
, content
, i
):
14 tofix
.add(texFileName
) # consider this .tex broken
16 # now search the include file for this class
18 for j
in range(i
,len(content
)):
20 if "wx/" in line
and ".h" in line
:
21 include
= line
[line
.find("wx/"):line
.find(".h")+2]
24 print " no include file declared for class %s" % classname
25 return True # go on with next \class
27 include
= include
.replace("\\_", "_")
28 print " the include file for %s is %s" % (classname
, include
)
30 # does this .tex already contains the \wxheading{Library} section nearby the include file?
31 for k
in range(j
,min(len(content
), j
+3)):
33 if "\wxheading{Library}" in line
:
34 print " this \class section already has its \wxheading{Library} section... skipping"
35 tofix
.remove(texFileName
) # was a valid .tex (at least for current class)
36 return True # go on with next \class
38 # now try to understand which lib contains this class
39 include
= INCLUDE_PATH
+ "/" + include
40 header
= open(include
, "r")
42 print " could not open %s" % include
43 return True # go on with next \class
46 content2
= header
.readlines()
48 # if they exist append port-specific headers contents
49 for c
in ["wx/gtk/", "wx/msw/", "wx/mac/", "wx/generic/"]:
51 temp
= include
.replace("wx/", c
)
52 print " trying to open %s..." % temp
53 header
= open(temp
, "r")
54 headercontents
= header
.readlines()
55 content2
= content2
+ headercontents
56 print " added %d lines from %s" % (len(headercontents
), temp
)
60 # now search for the export-declaration associated with this class
62 if "class " in line
and classname
in line
:
63 if line
.find("class") < line
.find(classname
): # could be a comment
65 decl
= line
[line
.find("_")+1:]
66 decl
= decl
[:decl
.find(" ")]
67 decl
= decl
.replace("FWD_", "")
68 decl
= decl
[0:1].upper() + decl
[1:].lower()
70 elif " WXDLLEXPORT " in line
:
75 print " no declaration associated with %s" % classname
76 return True # go on with next \class
78 print " the declaration associated with %s is %s" % (classname
, decl
)
79 tofix
.remove(texFileName
) # was a valid .tex (at least for current class)
81 # now modify the .tex file
82 content
.insert(j
+2, "\wxheading{Library}\n\n\helpref{wx%s}{librarieslist}\n\n" % decl
)
85 file = open(texFileName
, "w")
86 file.write(''.join(content
))
89 print " updated %s" % texFileName
96 count
= scanTexFiles(myCallback
)
98 print "\nProcessed %d files, automatically fixed %d files." % (count
, fixed
)
99 print "There are %d files to fix manually:\n%s" % (len(tofix
), '\n'.join(tofix
))