X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a9c3b09ee60c45f6980e8cf61c7f6e6715322353..ae901b234c4a0aa7c1777b3bd181dd7f8517ad21:/misc/scripts/update_doc_libs.py?ds=inline

diff --git a/misc/scripts/update_doc_libs.py b/misc/scripts/update_doc_libs.py
old mode 100644
new mode 100755
index 3a57056ca2..fbedee375e
--- a/misc/scripts/update_doc_libs.py
+++ b/misc/scripts/update_doc_libs.py
@@ -7,103 +7,94 @@
 # Licence:    wxWindows licence
 ##############################################################################
 
-import sys, os, glob, distutils.file_util
+from update_doc_utils import scanTexFiles
 
-tofix = set()
-count = 0
-for f in glob.glob('*.tex'):
-    file = open(f, "r")
-    if not file:
-        print "could not open %s" % f
-        continue
-    print "opened file %s" % f
-    count = count + 1
-    
-    # search \class
-    content = file.readlines()
-    classdecl = 0
-    for i in range(len(content)):
-        line = content[i]
-        if "\class{" in line:
-            classdecl = classdecl + 1
-            
-            classname = line
-            classname = classname[classname.find("\class{"):]
-            classname = classname[classname.find("{")+1:classname.find("}")]
-            print " the class declared is named '%s'" % classname
-            
-            tofix.add(f)     # consider this .tex broken
-            
-            # now search the include file for this class
-            include = ""
-            for j in range(i,len(content)):
-                line = content[j]
-                if "wx/" in line and ".h" in line:
-                    include = line[line.find("wx/"):line.find(".h")+2]
+INCLUDE_PATH="../../include"
+
+def myCallback(classname, texFileName, content, i):
+    tofix.add(texFileName)     # consider this .tex broken
+
+    # now search the include file for this class
+    include = ""
+    for j in range(i,len(content)):
+        line = content[j]
+        if "wx/" in line and ".h" in line:
+            include = line[line.find("wx/"):line.find(".h")+2]
+            break
+    if include == "":
+        print " no include file declared for class %s" % classname
+        return True # go on with next \class
+
+    include = include.replace("\\_", "_")
+    print " the include file for %s is %s" % (classname, include)
+
+    # does this .tex already contains the \wxheading{Library} section nearby the include file?
+    for k in range(j,min(len(content), j+3)):
+        line = content[k]
+        if "\wxheading{Library}" in line:
+            print " this \class section already has its \wxheading{Library} section... skipping"
+            tofix.remove(texFileName) # was a valid .tex (at least for current class)
+            return True   # go on with next \class
+
+    # now try to understand which lib contains this class
+    include = INCLUDE_PATH + "/" + include
+    header = open(include, "r")
+    if not header:
+        print " could not open %s" % include
+        return True # go on with next \class
+
+    decl = ""
+    content2 = header.readlines()
+
+    # if they exist append port-specific headers contents
+    for c in ["wx/gtk/", "wx/msw/", "wx/mac/", "wx/generic/"]:
+        try:
+            temp = include.replace("wx/", c)
+            print " trying to open %s..." % temp
+            header = open(temp, "r")
+            headercontents = header.readlines()
+            content2 = content2 + headercontents
+            print " added %d lines from %s" % (len(headercontents), temp)
+        except:
+            pass
+
+    # now search for the export-declaration associated with this class
+    for line in content2:
+        if "class " in line and classname in line:
+            if line.find("class") < line.find(classname):  # could be a comment
+                if "_" in line:
+                    decl = line[line.find("_")+1:]
+                    decl = decl[:decl.find(" ")]
+                    decl = decl.replace("FWD_", "")
+                    decl = decl[0:1].upper() + decl[1:].lower()
+                    break
+                elif " WXDLLEXPORT " in line:
+                    decl = "Core"
                     break
-            if include == "":
-                print " no include file declared for class %s" % classname
-                continue
-            
-            include = include.replace("\\_", "_")
-            print " the include file for %s is %s" % (classname, include)
-            
-            # now try to understand which libs contains this class
-            include = "../../../include/" + include
-            header = open(include, "r")
-            if not file:
-                print " could not open %s" % include
-                continue
-
-            decl = ""
-            content2 = header.readlines()
-            
-            # if they exist append port-specific headers contents
-            for c in ["wx/gtk/", "wx/msw/", "wx/mac/", "wx/generic/"]:
-                try:
-                    temp = include.replace("wx/", c)
-                    print " trying to open %s..." % temp
-                    header = open(temp, "r")
-                    headercontents = header.readlines()
-                    content2 = content2 + headercontents
-                    print " added %d lines from %s" % (len(headercontents), temp)
-                except:
-                    pass
-            
-            for line in content2:
-                if "class " in line and classname in line:
-                    if line.find("class") < line.find(classname):  # could be a comment
-                        if "_" in line:
-                            decl = line[line.find("_")+1:]
-                            decl = decl[:decl.find(" ")]
-                            decl = decl.replace("FWD_", "")
-                            decl = decl[0:1].upper() + decl[1:].lower()
-                            break
-                        elif " WXDLLEXPORT " in line:
-                            decl = "Core"
-                            break
-                        
-            if decl == "":
-                print " no declaration associated with %s" % classname
-                continue
-            
-            print " the declaration associated with %s is %s" % (classname, decl)
-            tofix.remove(f) # was a valid .tex (at least for current class)
-            
-            # now modify the .tex file
-            content.insert(j+2, "\wxheading{Library}\n\n\helpref{wx%s}{librarieslist}\n\n" % decl)
-            
-            # write it
-            file = open(f, "w")
-            file.write(''.join(content))
-            file.flush()
-            
-            file = open(f, "r")
-
-            print " updated %s" % f
-
-            
-    print " file %s contains %d class declarations" % (f, classdecl)
-
-print "\nProcessed %d files." % count
-print "There are %d files to fix:\n%s" % (len(tofix), '\n'.join(tofix))
+
+    if decl == "":
+        print " no declaration associated with %s" % classname
+        return True # go on with next \class
+
+    print " the declaration associated with %s is %s" % (classname, decl)
+    tofix.remove(texFileName) # was a valid .tex (at least for current class)
+
+    # now modify the .tex file
+    content.insert(j+2, "\wxheading{Library}\n\n\helpref{wx%s}{librarieslist}\n\n" % decl)
+
+    # write it
+    file = open(texFileName, "w")
+    file.write(''.join(content))
+    file.flush()
+
+    print " updated %s" % texFileName
+    fixed = fixed+1
+
+    return True
+
+fixed = 0
+tofix = set()
+count = scanTexFiles(myCallback)
+
+print "\nProcessed %d files, automatically fixed %d files." % (count, fixed)
+print "There are %d files to fix manually:\n%s" % (len(tofix), '\n'.join(tofix))