2 #¼Â¹Ô¤¹¤ë¤È/tmp/doxyman¤ò¤Ä¤«¤Ã¤Æ¥Õ¥¡¥¤¥ë¤òʬ¤±¡¢
3 #¤â¤È¤Îdirectory¤Ë¤«¤¤Ê¤ª¤¹¡£
4 # see also ¤ÎÃæ¿È¤ò woman ¸þ¤±¤Ë½ñ¤´¹¤¨¤ë¡£
9 # Setting up directory names.
12 $currentdir = Dir.pwd+"/"
13 $doxywork = $currentdir+"doxywork/"
14 $srcman3 = $currentdir+usr_or_ja+"/man/man3/"
16 $dstman3m = $currentdir+"/man/man3m/"
18 $dstman3m = $currentdir+"/man/ja/man3m/"
20 $sampledir="sample/man3/"
23 # Extra information about header strings Doxygen generates in a man file.
26 def nextheader(text,index)
27 header = text[index+1..text.size].find{|i| i =~ /\.S(S|H)/}
31 grouptext = open($sampledir+"SampleGroup.3","r").readlines.reverse
33 fd = grouptext.index(grouptext.find{|i| i =~ /SampleFunction/})
34 $fdheader = nextheader(grouptext,fd)
36 restofthetext = grouptext[fd+1..grouptext.size]
38 fl = restofthetext.index(restofthetext.find{|i| i =~ /SampleFunction/})
39 $flheader = nextheader(restofthetext,fl)
41 dd = grouptext.index(grouptext.find{|i| i =~ /long group document/})
42 $ddheader = nextheader(grouptext,dd)
45 structext = open($sampledir+"SampleStructure.3","r").readlines.reverse
47 fieldd = structext.index(structext.find{|i| i =~ /SampleField/})
48 $fielddheader = nextheader(structext,fieldd)
50 restofstructext = structext[fieldd+1..structext.size]
52 fieldl = restofstructext.index(restofstructext.find{|i| i =~ /SampleField/})
53 $fieldlheader = nextheader(restofstructext, fieldl)
59 #### to find data structure documentation files and rewriting them
61 def writeuntilsectionheader(buf, text, index)
62 for line in text[index .. text.size]
70 def writedocumentation(buf, text, index)
71 for line in text[index .. text.size]
76 line =~ /^.SS\s"(.+)"/
77 buf.push(".PP\n\\fB".concat($1).concat("\\fP\n"))
85 def datastructure(struct)
87 text = open(struct.concat(".3m"),"r").readlines
92 if tline = text.index("\.SH NAME\n")
93 if text[tline+1] =~ /^([\w\s]+)\s\\-\s(.+)$/
94 buf.push(".SS ".concat($1).concat("\n"))
96 buf.push($2.concat("\n"))
98 writeuntilsectionheader(buf, text, nl)
101 text[tline+1] =~ /^([\w\s]+)\s\\-/
102 buf.push(".SS ".concat($1).concat("\n"))
105 buf.push(text[tline+1])
111 if ddline = text.index(text.find{|i| i = $ddheader})
113 writeuntilsectionheader(buf, text, nl)
117 if ptline = text.index("\.SS \"Public Types\"\n")
118 buf.push("\\fBPublic Types:\\fP\n")
120 writeuntilsectionheader(buf, text, nl)
124 # member enumeration documentation
125 if medline = text.index("\.SH \"MEMBER ENUMERATION DOCUMENTATION\"\n")
126 buf.push("\.PP\n\\fBMEMBER ENUMERATION DOCUMENTATION:\\fP\n")
128 writedocumentation(buf, text, nl)
132 # if dfline = text.index($fieldlheader)
133 # buf.push("\\fBData Fields:\\fP\n")
135 # writeuntilsectionheader(buf, text, nl)
139 # field documentation
140 if fdline = text.index($fielddheader)
141 buf.push("\.PP\n\\fBFIELD DOCUMENTATION:\\fP\n")
143 writedocumentation(buf, text, nl)
149 ###############################
152 def documentfunc(title, func_text, short_text)
153 func_text.grep(/^\.SS/){|i|
155 func_rest = func_text[func_text.index(i)..func_text.size]
156 documentfunc2(i, title, func_rest, short_text)}
159 def documentfunc2 (dstart, title, func_text, short_text)
160 #func_text¤ÎºÇ½é¤Î¹ÔÃæ¤Î´Ø¿ô̾
162 dstart =~ /\s([a-z_]+)\s\(/
166 ffname = "\\fB".concat($1.concat("\\fP"))
167 #short_text¤Î´Ø¿ô̾¤Î£²¹Ô¸å¤¬brief¡£
168 brief = short_text[short_text.index(short_text.find{|i| i.index(ffname)}) + 2]
169 #´Ø¿ô¤´¤È¤Î¥Õ¥¡¥¤¥ë¤òºî¤ë¡£
170 file = open($doxywork+fname+".3m", "w")
171 file.puts("@function")
173 /^\.TH \"([^"]*)\"\s/ =~ title
175 ##????? newtitle = title.gsub(oname, fname.chop.chop)
176 newtitle = title.gsub(oname, fname)
179 file.print("@brief ")
182 else file.print("\n")
185 file.puts(func_text[0])
186 for line in func_text[1 .. func_text.size]
187 break if /.SS/ =~ line
193 ####rewriting each man file
194 ### rewriting a man file for a function
197 # let the library name appear in the header
198 buf = [text[0].gsub!("\" \"", "\" \"\" \"")]
200 title = text[0].split(" ")[1].chop!.reverse.chop!.reverse
202 if text.index("\\fBReturns: \\fP\n") == nil
203 print title, ": Returns not described\n"
205 if text.index("\\fBErrors: \\fP\n") == nil
206 print title, ": Errors not described\n"
209 buf.push(".ad l\n.nh\n.SH NAME\n")
211 if text[1] =~ /\"\\fI(.+)\\fP\"/
212 buf.push(title.concat(" \- ").concat($1))
216 synopsys = text.find{|line| line =~ /\.SS/}
217 buf.push("\n\n.SH SYNOPSIS").push(formatsynopsys(synopsys)).push("\n")
219 description = text[text.index(synopsys)+2..text.size]
222 print title, ": No description found\n"
224 buf.push("\n.SH DESCRIPTION\n").push(womanrewrite(desrewrite(description)))
229 ####synopsys section of a function
231 def formatsynopsys(line)
232 line.chop!.chop!.reverse!.chop!.chop!.chop!.chop!.chop!.reverse!
234 # line.gsub!(/\\fP\s*/,"\n.ft\n")
235 # line.gsub!(/\\fB/,"\n.ft B\n")
237 line.gsub!(/\s(\w*)\)/){"\n\\fI" << $1 << "\\fP)"}
238 line.gsub!(/\s(\w*),/){"\n\\fI" << $1 << "\\fP,"}
239 line.gsub!(/\s(\w*)\s\(/){"\n\\fB" << $1 << "\\fP ("}
242 ####non-synopsys section of a function
247 text.grep(/^\\fB.+\\fP/){|line|
248 ind = text.index(line)
249 text.delete_at(ind+1) if text[ind+1] == (".in +1c\n")}
252 text.each_with_index{|line,i|
254 #removing "More..." hyperlink
255 line.gsub!(/More.../,"")
257 line.gsub!(/^\.TP/,"")
260 line.gsub!(/^\\fBReturn value:\\fP/,"\n.SH RETURNS\n.PP")
261 line.gsub!(/^\\fBSee Also:\\fP/,"\n.SH \"SEE ALSO\"\n.PP")
262 line.gsub!(/^\\fBErrors:\\fP/,"\n.SH ERRORS\n.PP")
264 line.gsub!(/^\\fB(.+)\\fP/){"\n.SS " << $1}
266 #removing indentation
267 if text[i - 1] =~ /^.PP/
269 line.reverse!.chop!.reverse!
273 # removing the results of doxygen bug
274 # \fP required for . , ; and <>
275 line.gsub!(/\s*(\\fP)+\s*(,|\.|;)\s+/){"\\fP" << $2 << "\n.ft R\n"}
277 line.gsub!(/(\\fP)+\s*>/,"\\fP>")
278 line.gsub!(/<\s+\\f(P|I|B|C|)/){"<\\f" << $1}
281 line.gsub!(/\s*(\\fP)+\s+/,"\n.ft R\n")
283 line.gsub!(/\s+\\f(I|C)\\fB\s*/,"\n.ft B\n")
284 line.gsub!(/\s+\\f(B|I)\\fC\s*/,"\n.ft C\n")
285 line.gsub!(/\s+\\f(B|C)\\fI\s*/,"\n.ft I\n")
286 line.gsub!(/\s+\\fB\s*/,"\n.ft B\n")
287 line.gsub!(/\s+\\fC\s*/,"\n.ft C\n")
288 line.gsub!(/\s+\\fI\s*/,"\n.ft I\n")
295 def womanrewrite(text)
297 if sasectionstart = text.index(text.find{|line| line =~ /^\.SH\s"SEE ALSO"/})
298 aftersasection = text[sasectionstart+1 .. text.size]
299 if sasectionend = aftersasection.index(aftersasection.find{|line| line =~ /^\.SH/})
300 for line in text[sasectionstart+1 .. sasectionend + sasectionstart]
301 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
304 for line in text[sasectionstart+1 .. text.size]
305 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
312 # rewriting a man file for a non-function
316 structures = ["\.SH \"Data Structure Documentation\"\n"]
318 if ddind = text.index($ddheader)
319 if odind = text.index(text.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/})
321 text[ddind+1 .. odind-1].find{|line| line =~ /^[^\.]/}
322 text = text[0 .. ddind-1] + text[odind .. text.size]
325 text.each_with_index{|line,i|
326 line.gsub!(/More.../,"")
328 # let the library name appear in the header
330 line = line.gsub!("\" \"", "\" \"\" \"")
333 # finding structure documentations and merging into "structures"
334 if line =~ /^\.RI\s\"struct\s\\fB(.*)\\fP\"/
335 structures.push(datastructure($1))
338 #removing indentation
339 if text[i - 1] =~ /^.PP/
341 line.reverse!.chop!.reverse!
346 if text[i - 1] =~ /^.SH\sNAME/
348 unless line =~ /\\-\s./
349 line.chop!.chop!.chop!.chop!
354 #removing author section
355 line.gsub!(/^\.SH\s\"AUTHOR\"/,"")
356 line.gsub!("Generated automatically by Doxygen for m17n_test from the source code.","")
358 line.gsub!(/\\fP\s+,/,"\\fP,")
359 line.gsub!(/\\fP\s+\./,"\\fP.")
360 line.gsub!(/\\fC\\fB(\w+)\\fP\\fP/){"\\fB" << $1 << "\\fP"}
365 unless structures == ["\.SH \"Data Structure Documentation\"\n"]
367 if dindex = buf.index(buf.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/i})
368 buf = buf[0 .. dindex-1] + structures + buf[dindex .. buf.size]
370 buf = buf + structures
377 #############################dividing files
379 Dir.mkdir $doxywork unless FileTest.directory? $doxywork
383 Dir.open(".").each{|filename|
384 if FileTest.directory? filename
388 if filename =~ /\.c\./
392 file = open(filename,"r")
393 text = file.readlines
397 sfunctionstart = text.index(text.find{|i| i == $flheader})
398 if sfunctionend = text.index(text[sfunctionstart+1 .. text.size].find{|i| i =~ /^\.SS|^\.SH/})
399 short_text = text[sfunctionstart .. sfunctionend - 1]
401 short_text = text[sfunctionstart .. text.size - 1]
404 if lfunctionstart = text.index(text.find{|i| i == $fdheader})
405 if lfunctionend = text.index(text[lfunctionstart+1 .. text.size].find{|i| i =~ /^\.SH/})
406 func_text = text[lfunctionstart .. lfunctionend - 1]
407 group_text = text[0 .. lfunctionstart - 1] + text[lfunctionend ..text.size]
409 func_text = text[lfunctionstart .. text.size]
410 group_text = text[0 .. lfunctionstart - 1]
417 documentfunc(title, func_text, short_text)
425 filetowrite = open($doxywork+filename,"w")
426 filetowrite.puts(group_text)
430 #############################rewriting files
434 Dir.open(".").each{|f| File.delete(f) if FileTest.file?(f)}
438 Dir.open(".").each{|filename|
439 unless FileTest.directory? filename
441 print "PROCESSING: ", filename, "\n"
443 file = open(filename,"r")
444 text = file.readlines
446 if /@function/ =~ text[0]
447 buf = frewrite(text[1..text.size])
448 else buf = orewrite(text)
451 filetowrite = open($dstman3m+filename,"w")
452 filetowrite.puts(buf)