]> git.saurik.com Git - wxWidgets.git/blame - misc/scripts/update_doc_libs.py
using #ifdef wxABORT_ON_CONFIG_ERROR not just #if as elsewhere
[wxWidgets.git] / misc / scripts / update_doc_libs.py
CommitLineData
61f2782a
VZ
1##############################################################################
2# Name: misc/scripts/update_doc_libs.py
3# Purpose: Automatically insert \Library{} headers in the doc files
4# Created: 2007-07-28
61f2782a
VZ
5# Copyright: (c) 2007 Francesco Montorsi
6# Licence: wxWindows licence
7##############################################################################
8
9from update_doc_utils import scanTexFiles
10
11INCLUDE_PATH="../../include"
12
13def myCallback(classname, texFileName, content, i):
14 tofix.add(texFileName) # consider this .tex broken
15
16 # now search the include file for this class
17 include = ""
18 for j in range(i,len(content)):
19 line = content[j]
20 if "wx/" in line and ".h" in line:
21 include = line[line.find("wx/"):line.find(".h")+2]
22 break
23 if include == "":
24 print " no include file declared for class %s" % classname
25 return True # go on with next \class
26
27 include = include.replace("\\_", "_")
28 print " the include file for %s is %s" % (classname, include)
29
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)):
32 line = content[k]
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
37
38 # now try to understand which lib contains this class
39 include = INCLUDE_PATH + "/" + include
40 header = open(include, "r")
41 if not header:
42 print " could not open %s" % include
43 return True # go on with next \class
44
45 decl = ""
46 content2 = header.readlines()
47
48 # if they exist append port-specific headers contents
49 for c in ["wx/gtk/", "wx/msw/", "wx/mac/", "wx/generic/"]:
50 try:
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)
57 except:
58 pass
59
60 # now search for the export-declaration associated with this class
61 for line in content2:
62 if "class " in line and classname in line:
63 if line.find("class") < line.find(classname): # could be a comment
64 if "_" in line:
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()
69 break
70 elif " WXDLLEXPORT " in line:
71 decl = "Core"
72 break
73
74 if decl == "":
75 print " no declaration associated with %s" % classname
76 return True # go on with next \class
77
78 print " the declaration associated with %s is %s" % (classname, decl)
79 tofix.remove(texFileName) # was a valid .tex (at least for current class)
80
81 # now modify the .tex file
82 content.insert(j+2, "\wxheading{Library}\n\n\helpref{wx%s}{librarieslist}\n\n" % decl)
83
84 # write it
85 file = open(texFileName, "w")
86 file.write(''.join(content))
87 file.flush()
88
89 print " updated %s" % texFileName
90 fixed = fixed+1
91
92 return True
93
94fixed = 0
95tofix = set()
96count = scanTexFiles(myCallback)
97
98print "\nProcessed %d files, automatically fixed %d files." % (count, fixed)
99print "There are %d files to fix manually:\n%s" % (len(tofix), '\n'.join(tofix))