2 #¼Â¹Ô¤¹¤ë¤È/tmp/doxyman¤ò¤Ä¤«¤Ã¤Æ¥Õ¥¡¥¤¥ë¤òʬ¤±¡¢
3 #¤â¤È¤Îdirectory¤Ë¤«¤¤Ê¤ª¤¹¡£
4 # see also ¤ÎÃæ¿È¤ò woman ¸þ¤±¤Ë½ñ¤´¹¤¨¤ë¡£
8 currentdir = Dir.pwd+"/"
9 $doxywork = currentdir+"doxywork/"
10 $srcman3 = currentdir+usr_or_ja+"/man/man3/"
12 $dstman3m = currentdir+"/man/man3m/"
14 $dstman3m = currentdir+"/man/ja/man3m/"
17 headertexts = open("doxyhead.txt","r").readlines
18 $fdheader = headertexts[0]
19 $flheader = headertexts[1]
20 $ddheader = headertexts[2]
21 $fielddheader = headertexts[3]
22 $fieldlheader = headertexts[4]
24 #### to find data structure documentation files and rewriting them
26 def writeuntilsectionheader(buf, text, index)
27 for line in text[index .. text.size]
35 def writedocumentation(buf, text, index)
36 for line in text[index .. text.size]
41 line =~ /^.SS\s"(.+)"/
42 buf.push(".PP\n\\fB".concat($1).concat("\\fP\n"))
50 def datastructure(struct)
52 text = open(struct.concat(".3m"),"r").readlines
57 if tline = text.index("\.SH NAME\n")
58 if text[tline+1] =~ /^([\w\s]+)\s\\-\s(.+)$/
59 buf.push(".SS ".concat($1).concat("\n"))
61 buf.push($2.concat("\n"))
63 writeuntilsectionheader(buf, text, nl)
66 text[tline+1] =~ /^([\w\s]+)\s\\-/
67 buf.push(".SS ".concat($1).concat("\n"))
70 buf.push(text[tline+1])
76 if ddline = text.index(text.find{|i| i = $ddheader})
78 writeuntilsectionheader(buf, text, nl)
82 if ptline = text.index("\.SS \"Public Types\"\n")
83 buf.push("\\fBPublic Types:\\fP\n")
85 writeuntilsectionheader(buf, text, nl)
89 # member enumeration documentation
90 if medline = text.index("\.SH \"MEMBER ENUMERATION DOCUMENTATION\"\n")
91 buf.push("\.PP\n\\fBMEMBER ENUMERATION DOCUMENTATION:\\fP\n")
93 writedocumentation(buf, text, nl)
97 if dfline = text.index($fieldlheader)
98 buf.push("\\fBData Fields:\\fP\n")
100 writeuntilsectionheader(buf, text, nl)
104 # field documentation
105 if fdline = text.index($fielddheader)
106 buf.push("\.PP\n\\fBFIELD DOCUMENTATION:\\fP\n")
108 writedocumentation(buf, text, nl)
114 ###############################
117 def documentfunc(title, func_text, short_text)
118 func_text.grep(/^\.SS/){|i|
120 func_rest = func_text[func_text.index(i)..func_text.size]
121 documentfunc2(i, title, func_rest, short_text)}
124 def documentfunc2 (dstart, title, func_text, short_text)
125 #func_text¤ÎºÇ½é¤Î¹ÔÃæ¤Î´Ø¿ô̾
126 dstart =~ /\s([a-z_]+)\s\(/
129 ffname = "\\fB".concat($1.concat("\\fP"))
130 #short_text¤Î´Ø¿ô̾¤Î£²¹Ô¸å¤¬brief¡£
131 brief = short_text[short_text.index(short_text.find{|i| i.index(ffname)}) + 2]
132 #´Ø¿ô¤´¤È¤Î¥Õ¥¡¥¤¥ë¤òºî¤ë¡£
133 file = open($doxywork+fname+".3m", "w")
134 file.puts("@function")
136 /^\.TH \"([^"]*)\"\s/ =~ title
138 newtitle = title.gsub(oname, fname.chop.chop)
141 file.print("@brief ")
144 else file.print("\n")
147 file.puts(func_text[0])
148 for line in func_text[1 .. func_text.size]
149 break if /.SS/ =~ line
155 ####rewriting each man file
156 ### rewriting a man file for a function
159 # let the library name appear in the header
160 buf = [text[0].gsub!("\" \"", "\" \"\" \"")]
162 title = text[0].split(" ")[1].chop!.reverse.chop!.reverse
164 if text.index("\\fBReturns: \\fP\n") == nil
165 print title, ": Returns not described\n"
167 if text.index("\\fBErrors: \\fP\n") == nil
168 print title, ": Errors not described\n"
171 buf.push(".ad l\n.nh\n.SH NAME\n")
173 if text[1] =~ /\"\\fI(.+)\\fP\"/
174 buf.push(title.concat(" \- ").concat($1))
178 synopsys = text.find{|line| line =~ /\.SS/}
179 buf.push("\n\n.SH SYNOPSIS").push(formatsynopsys(synopsys)).push("\n")
181 description = text[text.index(synopsys)+2..text.size]
184 print title, ": No description found\n"
186 buf.push("\n.SH DESCRIPTION\n").push(womanrewrite(desrewrite(description)))
191 ####synopsys section of a function
193 def formatsynopsys(line)
194 line.chop!.chop!.reverse!.chop!.chop!.chop!.chop!.chop!.reverse!
196 # line.gsub!(/\\fP\s*/,"\n.ft\n")
197 # line.gsub!(/\\fB/,"\n.ft B\n")
199 line.gsub!(/\s(\w*)\)/){"\n\\fI" << $1 << "\\fP)"}
200 line.gsub!(/\s(\w*),/){"\n\\fI" << $1 << "\\fP,"}
201 line.gsub!(/\s(\w*)\s\(/){"\n\\fB" << $1 << "\\fP ("}
204 ####non-synopsys section of a function
209 text.grep(/^\\fB.+\\fP/){|line|
210 ind = text.index(line)
211 text.delete_at(ind+1) if text[ind+1] == (".in +1c\n")}
214 text.each_with_index{|line,i|
216 #removing "More..." hyperlink
217 line.gsub!(/More.../,"")
219 line.gsub!(/^\.TP/,"")
222 line.gsub!(/^\\fBReturn value:\\fP/,"\n.SH RETURNS\n.PP")
223 line.gsub!(/^\\fBSee Also:\\fP/,"\n.SH \"SEE ALSO\"\n.PP")
224 line.gsub!(/^\\fBErrors:\\fP/,"\n.SH ERRORS\n.PP")
226 line.gsub!(/^\\fB(.+)\\fP/){"\n.SS " << $1}
228 #removing indentation
229 if text[i - 1] =~ /^.PP/
231 line.reverse!.chop!.reverse!
235 # removing the results of doxygen bug
236 # \fP required for . , ; and <>
237 line.gsub!(/\s*(\\fP)+\s*(,|\.|;)\s+/){"\\fP" << $2 << "\n.ft R\n"}
239 line.gsub!(/(\\fP)+\s*>/,"\\fP>")
240 line.gsub!(/<\s+\\f(P|I|B|C|)/){"<\\f" << $1}
243 line.gsub!(/\s*(\\fP)+\s+/,"\n.ft R\n")
245 line.gsub!(/\s+\\f(I|C)\\fB\s*/,"\n.ft B\n")
246 line.gsub!(/\s+\\f(B|I)\\fC\s*/,"\n.ft C\n")
247 line.gsub!(/\s+\\f(B|C)\\fI\s*/,"\n.ft I\n")
248 line.gsub!(/\s+\\fB\s*/,"\n.ft B\n")
249 line.gsub!(/\s+\\fC\s*/,"\n.ft C\n")
250 line.gsub!(/\s+\\fI\s*/,"\n.ft I\n")
257 def womanrewrite(text)
259 if sasectionstart = text.index(text.find{|line| line =~ /^\.SH\s"SEE ALSO"/})
260 aftersasection = text[sasectionstart+1 .. text.size]
261 if sasectionend = aftersasection.index(aftersasection.find{|line| line =~ /^\.SH/})
262 for line in text[sasectionstart+1 .. sasectionend + sasectionstart]
263 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
266 for line in text[sasectionstart+1 .. text.size]
267 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
274 # rewriting a man file for a non-function
278 structures = ["\.SH \"Data Structure Documentation\"\n"]
280 if ddind = text.index($ddheader)
281 if odind = text.index(text.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/})
283 text[ddind+1 .. odind-1].find{|line| line =~ /^[^\.]/}
284 text = text[0 .. ddind-1] + text[odind .. text.size]
287 text.each_with_index{|line,i|
288 line.gsub!(/More.../,"")
290 # let the library name appear in the header
292 line = line.gsub!("\" \"", "\" \"\" \"")
295 # finding structure documentations and merging into "structures"
296 if line =~ /^\.RI\s\"struct\s\\fB(.*)\\fP\"/
297 structures.push(datastructure($1))
300 #removing indentation
301 if text[i - 1] =~ /^.PP/
303 line.reverse!.chop!.reverse!
308 if text[i - 1] =~ /^.SH\sNAME/
310 unless line =~ /\\-\s./
311 line.chop!.chop!.chop!.chop!
316 #removing author section
317 line.gsub!(/^\.SH\s\"AUTHOR\"/,"")
318 line.gsub!("Generated automatically by Doxygen for m17n_test from the source code.","")
320 line.gsub!(/\\fP\s+,/,"\\fP,")
321 line.gsub!(/\\fP\s+\./,"\\fP.")
322 line.gsub!(/\\fC\\fB(\w+)\\fP\\fP/){"\\fB" << $1 << "\\fP"}
327 unless structures == ["\.SH \"Data Structure Documentation\"\n"]
329 if dindex = buf.index(buf.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/i})
330 buf = buf[0 .. dindex-1] + structures + buf[dindex .. buf.size]
332 buf = buf + structures
339 #############################dividing files
341 Dir.mkdir $doxywork unless FileTest.directory? $doxywork
345 Dir.open(".").each{|filename|
346 if FileTest.directory? filename
350 if filename =~ /\.c\./
354 file = open(filename,"r")
355 text = file.readlines
359 sfunctionstart = text.index(text.find{|i| i == $flheader})
360 if sfunctionend = text.index(text[sfunctionstart+1 .. text.size].find{|i| i =~ /^\.SS|^\.SH/})
361 short_text = text[sfunctionstart .. sfunctionend - 1]
363 short_text = text[sfunctionstart .. text.size - 1]
366 if lfunctionstart = text.index(text.find{|i| i == $fdheader})
367 if lfunctionend = text.index(text[lfunctionstart+1 .. text.size].find{|i| i =~ /^\.SH/})
368 func_text = text[lfunctionstart .. lfunctionend - 1]
369 group_text = text[0 .. lfunctionstart - 1] + text[lfunctionend ..text.size]
371 func_text = text[lfunctionstart .. text.size]
372 group_text = text[0 .. lfunctionstart - 1]
379 documentfunc(title, func_text, short_text)
387 filetowrite = open($doxywork+filename,"w")
388 filetowrite.puts(group_text)
392 #############################rewriting files
396 Dir.open(".").each{|f| File.delete(f) if FileTest.file?(f)}
400 Dir.open(".").each{|filename|
401 unless FileTest.directory? filename
403 print "PROCESSING: ", filename, "\n"
405 file = open(filename,"r")
406 text = file.readlines
408 if /@function/ =~ text[0]
409 buf = frewrite(text[1..text.size])
410 else buf = orewrite(text)
413 filetowrite = open($dstman3m+filename,"w")
414 filetowrite.puts(buf)
422 Dir.open(".").each{|f| File.delete(f) if FileTest.file?(f)}