2 #¼Â¹Ô¤¹¤ë¤È/tmp/doxyman¤ò¤Ä¤«¤Ã¤Æ¥Õ¥¡¥¤¥ë¤òʬ¤±¡¢
3 #¤â¤È¤Îdirectory¤Ë¤«¤¤Ê¤ª¤¹¡£
4 # see also ¤ÎÃæ¿È¤ò woman ¸þ¤±¤Ë½ñ¤´¹¤¨¤ë¡£
9 doxywork = currentdir+"doxywork"+usr_dev_ja+"man3"
10 doxyman3 = currentdir+usr_dev_ja+"man/man3"
11 doxyman3m = currentdir+usr_dev_ja+"man/man3m"
13 headertexts = open("doxyhead.txt","r").readlines
14 $fdheader = headertexts[0]
15 $flheader = headertexts[1]
16 $ddheader = headertexts[2]
17 $fielddheader = headertexts[3]
18 $fieldlheader = headertexts[4]
20 #### to find data structure documentation files and rewriting them
22 def writeuntilsectionheader(buf, text, index)
23 for line in text[index .. text.size]
31 def writedocumentation(buf, text, index)
32 for line in text[index .. text.size]
37 line =~ /^.SS\s"(.+)"/
38 buf.push(".PP\n\\fB".concat($1).concat("\\fP\n"))
46 def datastructure(struct)
48 text = open(struct.concat(".3"),"r").readlines
53 if tline = text.index("\.SH NAME\n")
54 if text[tline+1] =~ /^([\w\s]+)\s\\-\s(.+)$/
55 buf.push(".SS ".concat($1).concat("\n"))
57 buf.push($2.concat("\n"))
59 writeuntilsectionheader(buf, text, nl)
62 text[tline+1] =~ /^([\w\s]+)\s\\-/
63 buf.push(".SS ".concat($1).concat("\n"))
66 buf.push(text[tline+1])
72 if ddline = text.index(text.find{|i| i = $ddheader})
74 writeuntilsectionheader(buf, text, nl)
78 if ptline = text.index("\.SS \"Public Types\"\n")
79 buf.push("\\fBPublic Types:\\fP\n")
81 writeuntilsectionheader(buf, text, nl)
85 # member enumeration documentation
86 if medline = text.index("\.SH \"MEMBER ENUMERATION DOCUMENTATION\"\n")
87 buf.push("\.PP\n\\fBMEMBER ENUMERATION DOCUMENTATION:\\fP\n")
89 writedocumentation(buf, text, nl)
93 if dfline = text.index($fieldlheader)
94 buf.push("\\fBData Fields:\\fP\n")
96 writeuntilsectionheader(buf, text, nl)
100 # field documentation
101 if fdline = text.index($fielddheader)
102 buf.push("\.PP\n\\fBFIELD DOCUMENTATION:\\fP\n")
104 writedocumentation(buf, text, nl)
110 ###############################
113 def documentfunc(title, func_text, short_text)
114 func_text.grep(/^\.SS/){|i|
116 func_rest = func_text[func_text.index(i)..func_text.size]
117 documentfunc2(i, title, func_rest, short_text)}
120 def documentfunc2 (dstart, title, func_text, short_text)
121 #func_text¤ÎºÇ½é¤Î¹ÔÃæ¤Î´Ø¿ô̾
122 dstart =~ /\s([a-z_]+)\s\(/
125 ffname = "\\fB".concat($1.concat("\\fP"))
126 #short_text¤Î´Ø¿ô̾¤Î£²¹Ô¸å¤¬brief¡£
127 brief = short_text[short_text.index(short_text.find{|i| i.index(ffname)}) + 2]
128 #´Ø¿ô¤´¤È¤Î¥Õ¥¡¥¤¥ë¤òºî¤ë¡£
129 file = open(doxywork+fname+".3", "w")
130 file.puts("@function")
132 /^\.TH \"([^"]*)\"\s/ =~ title
134 newtitle = title.gsub(oname, fname.chop.chop)
137 file.print("@brief ")
140 else file.print("\n")
143 file.puts(func_text[0])
144 for line in func_text[1 .. func_text.size]
145 break if /.SS/ =~ line
151 ####rewriting each man file
152 ### rewriting a man file for a function
155 # let the library name appear in the header
156 buf = [text[0].gsub!("\" \"", "\" \"\" \"")]
158 title = text[0].split(" ")[1].chop!.reverse.chop!.reverse
160 if text.index("\\fBReturns: \\fP\n") == nil
161 print title, ": Returns not described\n"
163 if text.index("\\fBErrors: \\fP\n") == nil
164 print title, ": Errors not described\n"
167 buf.push(".ad l\n.nh\n.SH NAME\n")
169 if text[1] =~ /\"\\fI(.+)\\fP\"/
170 buf.push(title.concat(" \- ").concat($1))
174 synopsys = text.find{|line| line =~ /\.SS/}
175 buf.push("\n\n.SH SYNOPSIS").push(formatsynopsys(synopsys)).push("\n")
177 description = text[text.index(synopsys)+2..text.size]
180 print title, ": No description found\n"
182 buf.push("\n.SH DESCRIPTION\n").push(womanrewrite(desrewrite(description)))
187 ####synopsys section of a function
189 def formatsynopsys(line)
190 line.chop!.chop!.reverse!.chop!.chop!.chop!.chop!.chop!.reverse!
192 # line.gsub!(/\\fP\s*/,"\n.ft\n")
193 # line.gsub!(/\\fB/,"\n.ft B\n")
195 line.gsub!(/\s(\w*)\)/){"\n\\fI" << $1 << "\\fP)"}
196 line.gsub!(/\s(\w*),/){"\n\\fI" << $1 << "\\fP,"}
197 line.gsub!(/\s(\w*)\s\(/){"\n\\fB" << $1 << "\\fP ("}
200 ####non-synopsys section of a function
205 text.grep(/^\\fB.+\\fP/){|line|
206 ind = text.index(line)
207 text.delete_at(ind+1) if text[ind+1] == (".in +1c\n")}
210 text.each_with_index{|line,i|
212 #removing "More..." hyperlink
213 line.gsub!(/More.../,"")
215 line.gsub!(/^\.TP/,"")
218 line.gsub!(/^\\fBReturn value:\\fP/,"\n.SH RETURNS\n.PP")
219 line.gsub!(/^\\fBSee Also:\\fP/,"\n.SH \"SEE ALSO\"\n.PP")
220 line.gsub!(/^\\fBErrors:\\fP/,"\n.SH ERRORS\n.PP")
222 line.gsub!(/^\\fB(.+)\\fP/){"\n.SS " << $1}
224 #removing indentation
225 if text[i - 1] =~ /^.PP/
227 line.reverse!.chop!.reverse!
231 # removing the results of doxygen bug
232 # \fP required for . , ; and <>
233 line.gsub!(/\s*(\\fP)+\s*(,|\.|;)\s+/){"\\fP" << $2 << "\n.ft R\n"}
235 line.gsub!(/(\\fP)+\s*>/,"\\fP>")
236 line.gsub!(/<\s+\\f(P|I|B|C|)/){"<\\f" << $1}
239 line.gsub!(/\s*(\\fP)+\s+/,"\n.ft R\n")
241 line.gsub!(/\s+\\f(I|C)\\fB\s*/,"\n.ft B\n")
242 line.gsub!(/\s+\\f(B|I)\\fC\s*/,"\n.ft C\n")
243 line.gsub!(/\s+\\f(B|C)\\fI\s*/,"\n.ft I\n")
244 line.gsub!(/\s+\\fB\s*/,"\n.ft B\n")
245 line.gsub!(/\s+\\fC\s*/,"\n.ft C\n")
246 line.gsub!(/\s+\\fI\s*/,"\n.ft I\n")
253 def womanrewrite(text)
255 if sasectionstart = text.index(text.find{|line| line =~ /^\.SH\s"SEE ALSO"/})
256 aftersasection = text[sasectionstart+1 .. text.size]
257 if sasectionend = aftersasection.index(aftersasection.find{|line| line =~ /^\.SH/})
258 for line in text[sasectionstart+1 .. sasectionend + sasectionstart]
259 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
262 for line in text[sasectionstart+1 .. text.size]
263 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
270 # rewriting a man file for a non-function
274 structures = ["\.SH \"Data Structure Documentation\"\n"]
276 if ddind = text.index($ddheader)
277 if odind = text.index(text.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/})
279 text[ddind+1 .. odind-1].find{|line| line =~ /^[^\.]/}
280 text = text[0 .. ddind-1] + text[odind .. text.size]
283 text.each_with_index{|line,i|
284 line.gsub!(/More.../,"")
286 # let the library name appear in the header
288 line = line.gsub!("\" \"", "\" \"\" \"")
291 # finding structure documentations and merging into "structures"
292 if line =~ /^\.RI\s\"struct\s\\fB(.*)\\fP\"/
293 structures.push(datastructure($1))
296 #removing indentation
297 if text[i - 1] =~ /^.PP/
299 line.reverse!.chop!.reverse!
304 if text[i - 1] =~ /^.SH\sNAME/
306 unless line =~ /\\-\s./
307 line.chop!.chop!.chop!.chop!
312 #removing author section
313 line.gsub!(/^\.SH\s\"AUTHOR\"/,"")
314 line.gsub!("Generated automatically by Doxygen for m17n_test from the source code.","")
316 line.gsub!(/\\fP\s+,/,"\\fP,")
317 line.gsub!(/\\fP\s+\./,"\\fP.")
318 line.gsub!(/\\fC\\fB(\w+)\\fP\\fP/){"\\fB" << $1 << "\\fP"}
323 unless structures == ["\.SH \"Data Structure Documentation\"\n"]
325 if dindex = buf.index(buf.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/i})
326 buf = buf[0 .. dindex-1] + structures + buf[dindex .. buf.size]
328 buf = buf + structures
335 #############################dividing files
337 Dir.mkdir "doxywork/man3" unless FileTest.directory? "doxywork/man3"
338 Dir.mkdir "man" unless FileTest.directory? "man"
339 Dir.mkdir "man/man3m" unless FileTest.directory? "man/man3m"
341 Dir.chdir("usr/man/man3")
343 Dir.open(".").each{|filename|
344 if FileTest.directory? filename
348 if filename =~ /\.c\./
352 file = open(filename,"r")
353 text = file.readlines
357 sfunctionstart = text.index(text.find{|i| i == $flheader})
358 if sfunctionend = text.index(text[sfunctionstart+1 .. text.size].find{|i| i =~ /^\.SS|^\.SH/})
359 short_text = text[sfunctionstart .. sfunctionend - 1]
361 short_text = text[sfunctionstart .. text.size - 1]
364 if lfunctionstart = text.index(text.find{|i| i == $fdheader})
365 if lfunctionend = text.index(text[lfunctionstart+1 .. text.size].find{|i| i =~ /^\.SH/})
366 func_text = text[lfunctionstart .. lfunctionend - 1]
367 group_text = text[0 .. lfunctionstart - 1] + text[lfunctionend ..text.size]
369 func_text = text[lfunctionstart .. text.size]
370 group_text = text[0 .. lfunctionstart - 1]
377 documentfunc(title, func_text, short_text)
385 filetowrite = open("../../../doxywork/man3/".concat(filename),"w")
386 print "filetowrite=", filetowrite
387 filetowrite.puts(group_text)
391 Dir.chdir(currentdir)
392 #############################rewriting files
394 Dir.chdir("doxywork/man3")
396 Dir.open(".").each{|filename|
397 unless FileTest.directory? filename
399 print "PROCESSING: ", filename, "\n"
401 file = open(filename,"r")
402 text = file.readlines
404 if /@function/ =~ text[0]
405 buf = frewrite(text[1..text.size])
406 else buf = orewrite(text)
409 filetowrite = open("../../man/man3m/".concat(filename).concat("m"),"w")
410 filetowrite.puts(buf)
417 # Dir.chdir("/tmp/doxyman")
419 # Dir.open(".").each{|f| File.delete(f) if FileTest.file?(f)}