fixed propagation of user mode changes (user should ALWAYS be notified)
[ircu2.10.12-pk.git] / tools / autodoc.py
1 #
2 # Structure AutoDocumentator for ircu.
3 # 26/02/2000 --Gte
4 #
5 # Creates a 'structs.html', containing HTML Table definitions
6 # for all structures encountered in *.h in the current directory.
7 #
8 # $Id: autodoc.py,v 1.1 2000/03/18 05:20:30 bleep Exp $
9
10 import string, fnmatch, os
11
12 def parse(filename):
13         OutFile = open('structs.html', 'a')
14         OutFile.write("<B><H2>"+filename+"</H2>")
15         stage = 1
16         try:
17                 IncFile = open(filename, 'r')
18                 line = IncFile.readline()
19         
20                 while line != "": 
21                         line = string.replace(line,"\n","") # Stript out LF's.
22                         splitline = string.split(line, " ")
23                         try:
24                                 if ((stage == 2) & (splitline[0] == "};")):
25                                         OutFile.write("</TABLE><P>"+"\n")
26                                         stage = 1
27                                 if (stage == 2):
28                                         # Begin reading member information.
29                                         declr = string.split(string.strip(line), ";", 1)
30                                         comment = string.replace(declr[1], "*", "")
31                                         comment = string.replace(comment, "/", "")
32         
33                                         OutFile.write("<tr>\n")
34                                         OutFile.write("<td WIDTH=\"22%\">"+string.strip(declr[0])+"</td>\n")
35                                         if (declr[1][-1] == "/"):
36                                                 OutFile.write("<td WIDTH=\"78%\">"+string.strip(comment)+"</td>\n")
37                                         else:
38                                                 # Loop until end of comment string.
39                                                 while (declr[-1] != "/"):
40                                                         line = IncFile.readline()
41                                                         line = string.replace(line,"\n","") # Stript out LF's.
42                                                         declr = string.strip(line)
43                                                         comment = comment + line
44                                                 comment = string.replace(comment, "*", "")
45                                                 comment = string.replace(comment, "/", "")
46                                                 OutFile.write("<td WIDTH=\"78%\">"+string.strip(comment)+"</td>\n")
47                                         OutFile.write("</tr>\n")                                                
48         
49                                 if ((splitline[0] == "struct") & (splitline[2] == "{") & (stage == 1)):
50                                         # We've found a "Standard" structure definition.
51                                         OutFile.write("Structure table for: \"<B>"+splitline[1]+"</B>\"<P>\n")
52                                         OutFile.write("<table BORDER CELLSPACING=0 CELLPADDING=2 WIDTH=\"100%\" ><tr><td VALIGN=TOP WIDTH=\"22%\"><b>Variable</b></td><td VALIGN=TOP WIDTH=\"78%\"><b>Description</b></td></tr>")
53                                         # Now, carry on until we encounter a "};".
54                                         stage = 2
55                         except IndexError:
56                                 pass
57                         line = IncFile.readline()
58         
59                 IncFile.close
60                 OutFile.write("<HR>")
61         
62         except IOError:
63                 print("** Error, File does not exist.") 
64         OutFile.close
65
66 files = os.listdir(".")
67 files.sort()
68 for file in files:
69         if (fnmatch.fnmatch(file, "*.h")):
70                 parse(file)