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+"/usr/man3m/"
18 $dstman3m = $currentdir+"/ja/man3m/"
20 $sampledir="sample/man3/"
22 $headfile = $currentdir+"manhead"
23 headbuf = open($headfile, "r").readlines
26 # Extra information about header strings Doxygen generates in a man file.
29 def nextheader(text,index)
30 header = text[index+1..text.size].find{|i| i =~ /\.S(S|H)/}
34 grouptext = open($sampledir+"SampleGroup.3","r").readlines.reverse
36 fd = grouptext.index(grouptext.find{|i| i =~ /SampleFunction/})
37 $fdheader = nextheader(grouptext,fd)
39 restofthetext = grouptext[fd+1..grouptext.size]
41 fl = restofthetext.index(restofthetext.find{|i| i =~ /SampleFunction/})
42 $flheader = nextheader(restofthetext,fl)
44 dd = grouptext.index(grouptext.find{|i| i =~ /long group document/})
45 $ddheader = nextheader(grouptext,dd)
48 structext = open($sampledir+"SampleStructure.3","r").readlines.reverse
50 fieldd = structext.index(structext.find{|i| i =~ /SampleField/})
51 $fielddheader = nextheader(structext,fieldd)
53 restofstructext = structext[fieldd+1..structext.size]
55 fieldl = restofstructext.index(restofstructext.find{|i| i =~ /SampleField/})
56 $fieldlheader = nextheader(restofstructext, fieldl)
62 #### to find data structure documentation files and rewriting them
64 def writeuntilsectionheader(buf, text, index)
65 for line in text[index .. text.size]
73 def writedocumentation(buf, text, index)
74 for line in text[index .. text.size]
79 line =~ /^.SS\s"(.+)"/
80 buf.push(".PP\n\\fB".concat($1).concat("\\fP\n"))
88 def datastructure(struct)
90 text = open(struct.concat(".3m"),"r").readlines
95 if tline = text.index("\.SH NAME\n")
96 if text[tline+1] =~ /^([\w\s]+)\s\\-\s(.+)$/
97 buf.push(".SS ".concat($1).concat("\n"))
99 buf.push($2.concat("\n"))
101 writeuntilsectionheader(buf, text, nl)
104 text[tline+1] =~ /^([\w\s]+)\s\\-/
105 buf.push(".SS ".concat($1).concat("\n"))
108 buf.push(text[tline+1])
114 if ddline = text.index(text.find{|i| i = $ddheader})
116 writeuntilsectionheader(buf, text, nl)
120 if ptline = text.index("\.SS \"Public Types\"\n")
121 buf.push("\\fBPublic Types:\\fP\n")
123 writeuntilsectionheader(buf, text, nl)
127 # member enumeration documentation
128 if medline = text.index("\.SH \"MEMBER ENUMERATION DOCUMENTATION\"\n")
129 buf.push("\.PP\n\\fBMEMBER ENUMERATION DOCUMENTATION:\\fP\n")
131 writedocumentation(buf, text, nl)
135 # if dfline = text.index($fieldlheader)
136 # buf.push("\\fBData Fields:\\fP\n")
138 # writeuntilsectionheader(buf, text, nl)
142 # field documentation
143 if fdline = text.index($fielddheader)
144 buf.push("\.PP\n\\fBFIELD DOCUMENTATION:\\fP\n")
146 writedocumentation(buf, text, nl)
149 # File.delete(struct) if FileTest.file?(struct)
154 ###############################
157 def documentfunc(title, func_text, short_text)
158 func_text.grep(/^\.SS/){|i|
160 func_rest = func_text[func_text.index(i)..func_text.size]
161 documentfunc2(i, title, func_rest, short_text)}
164 def documentfunc2 (dstart, title, func_text, short_text)
165 #func_text¤ÎºÇ½é¤Î¹ÔÃæ¤Î´Ø¿ô̾
167 dstart =~ /\s([a-z0-9_]+)\s\(/
171 ffname = "\\fB".concat($1.concat("\\fP"))
172 #short_text¤Î´Ø¿ô̾¤Î£²¹Ô¸å¤¬brief¡£
173 brief = short_text[short_text.index(short_text.find{|i| i.index(ffname)}) + 2]
174 #´Ø¿ô¤´¤È¤Î¥Õ¥¡¥¤¥ë¤òºî¤ë¡£
175 file = open($doxywork+fname+".3m", "w")
176 file.puts("@function")
178 /^\.TH \"([^"]*)\"\s/ =~ title
180 ##????? newtitle = title.gsub(oname, fname.chop.chop)
181 newtitle = title.gsub(oname, fname)
184 file.print("@brief ")
187 else file.print("\n")
190 file.puts(func_text[0])
191 for line in func_text[1 .. func_text.size]
192 break if /.SS/ =~ line
198 ####rewriting each man file
199 ### rewriting a man file for a function
202 # let the library name appear in the header
203 buf = [text[0].gsub!("\" \"", "\" \"\" \"")]
205 title = text[0].split(" ")[1].chop!.reverse.chop!.reverse
207 buf.push(".ad l\n.nh\n.SH NAME\n")
209 if text[1] =~ /\"\\fI(.+)\\fP\"/
210 buf.push(title.concat(" \- ").concat($1))
214 synopsys = text.find{|line| line =~ /\.SS/}
215 buf.push("\n\n.SH SYNOPSIS").push(formatsynopsys(synopsys)).push("\n")
217 description = text[text.index(synopsys)+2..text.size]
220 print title, ": No description found\n"
222 descriptiontext = womanrewrite(desrewrite(description))
223 buf.push("\n.SH DESCRIPTION\n").push(descriptiontext)
228 ####synopsys section of a function
230 def formatsynopsys(line)
231 line.chop!.chop!.reverse!.chop!.chop!.chop!.chop!.chop!.reverse!
233 # line.gsub!(/\\fP\s*/,"\n.ft\n")
234 # line.gsub!(/\\fB/,"\n.ft B\n")
236 line.gsub!(/\s(\w*)\)/){"\n\\fI" << $1 << "\\fP)"}
237 line.gsub!(/\s(\w*),/){"\n\\fI" << $1 << "\\fP,"}
238 line.gsub!(/\s(\w*)\s\(/){"\n\\fB" << $1 << "\\fP ("}
241 ####non-synopsys section of a function
244 returndescribed = false
245 errordescribed = false
248 text.grep(/^\\fB.+\\fP/){|line|
249 ind = text.index(line)
250 text.delete_at(ind+1) if text[ind+1] == (".in +1c\n")}
253 text.each_with_index{|line,i|
256 line.gsub!(".RS 4","")
258 ### letting verbatim end in place
259 line.gsub!(/^.nf/,".NF")
261 #removing "More..." hyperlink
262 line.gsub!(/More.../,"")
264 line.gsub!(/^\.TP/,"")
267 if line =~ /Return\svalue:/
268 returndescribed = true
270 line.gsub!(/^\\fBReturn value:\\fP/,"\n.SH RETURN VALUE\n.PP")
272 errordescribed = true
274 line.gsub!(/^\\fBErrors:\\fP/,"\n.SH ERRORS\n.PP")
275 line.gsub!(/^\\fBSee Also:\\fP/,"\n.SH \"SEE ALSO\"\n.PP")
277 line.gsub!(/^\\fB(.+)[^\)]\\fP/){"\n.SS " << $1}
278 # [^\)] in the pattern is added to avoid the first function in see also section.
280 #removing indentation
281 if text[i - 1] =~ /^.PP/
283 line.reverse!.chop!.reverse!
287 # removing the results of doxygen bug
288 # \fP required for . , ; and <>
289 line.gsub!(/\s*(\\fP)+\s*(,|\.|;)\s+/){"\\fP" << $2 << "\n.ft R\n"}
291 line.gsub!(/(\\fP)+\s*>/,"\\fP>")
292 line.gsub!(/<\s+\\f(P|I|B|C|)/){"<\\f" << $1}
295 line.gsub!(/\s*(\\fP)+\s+/,"\n.ft R\n")
297 line.gsub!(/\s+\\f(I|C)\\fB\s*/,"\n.ft B\n")
298 line.gsub!(/\s+\\f(B|I)\\fC\s*/,"\n.ft C\n")
299 line.gsub!(/\s+\\f(B|C)\\fI\s*/,"\n.ft I\n")
300 line.gsub!(/\s+\\fB\s*/,"\n.ft B\n")
301 line.gsub!(/\s+\\fC\s*/,"\n.ft C\n")
302 line.gsub!(/\s+\\fI\s*/,"\n.ft I\n")
306 unless returndescribed == true
307 print (" return not described \n")
309 unless errordescribed == true
310 print (" errors not described \n")
316 def womanrewrite(text)
318 if sasectionstart = text.index(text.find{|line| line =~ /^\.SH\s"SEE ALSO"/})
319 aftersasection = text[sasectionstart+1 .. text.size]
320 if sasectionend = aftersasection.index(aftersasection.find{|line| line =~ /^\.SH/})
321 for line in text[sasectionstart+1 .. sasectionend + sasectionstart]
322 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
325 for line in text[sasectionstart+1 .. text.size]
326 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
333 # rewriting a man file for a non-function
337 structures = ["\.SH \"Data Structure Documentation\"\n"]
339 if ddind = text.index($ddheader)
340 if odind = text.index(text.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/})
342 text[ddind+1 .. odind-1].find{|line| line =~ /^[^\.]/}
343 text = text[0 .. ddind-1] + text[odind .. text.size]
346 text.each_with_index{|line,i|
347 line.gsub!(/More.../,"")
349 ### let verbatim end in place
350 line.gsub!(/^.nf/,".NF")
352 # let the library name appear in the header
354 line = line.gsub!("\" \"", "\" \"\" \"")
357 # finding structure documentations and merging into "structures"
358 if line =~ /^\.RI\s\"struct\s\\fB(.*)\\fP\"/
359 structures.push(datastructure($1))
362 #removing indentation
363 if text[i - 1] =~ /^.PP/
365 line.reverse!.chop!.reverse!
370 if text[i - 1] =~ /^.SH\sNAME/
372 unless line =~ /\\-\s./
373 line.chop!.chop!.chop!.chop!
378 #removing author section
379 line.gsub!(/^\.SH\s\"AUTHOR\"/,"")
380 line.gsub!("Generated automatically by Doxygen for m17n_test from the source code.","")
382 line.gsub!(/\\fP\s+,/,"\\fP,")
383 line.gsub!(/\\fP\s+\./,"\\fP.")
384 line.gsub!(/\\fC\\fB(\w+)\\fP\\fP/){"\\fB" << $1 << "\\fP"}
389 unless structures == ["\.SH \"Data Structure Documentation\"\n"]
391 if dindex = buf.index(buf.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/i})
392 buf = buf[0 .. dindex-1] + structures + buf[dindex .. buf.size]
394 buf = buf + structures
401 #############################dividing files
403 Dir.mkdir $doxywork unless FileTest.directory? $doxywork
407 Dir.open(".").each{|filename|
409 if FileTest.directory? filename
413 #if filename =~ /\.c\./
417 file = open(filename,"r")
418 text = file.readlines
422 sfunctionstart = text.index(text.find{|i| i == $flheader})
423 if sfunctionend = text.index(text[sfunctionstart+1 .. text.size].find{|i| i =~ /^\.SS|^\.SH/})
424 short_text = text[sfunctionstart .. sfunctionend - 1]
426 short_text = text[sfunctionstart .. text.size - 1]
429 if lfunctionstart = text.index(text.find{|i| i == $fdheader})
430 if lfunctionend = text.index(text[lfunctionstart+1 .. text.size].find{|i| i =~ /^\.SH/})
431 func_text = text[lfunctionstart .. lfunctionend - 1]
432 group_text = text[0 .. lfunctionstart - 1] + text[lfunctionend ..text.size]
434 func_text = text[lfunctionstart .. text.size]
435 group_text = text[0 .. lfunctionstart - 1]
442 documentfunc(title, func_text, short_text)
450 filetowrite = open($doxywork+filename,"w")
451 filetowrite.puts(group_text)
455 #############################rewriting files
459 Dir.open(".").each{|f| File.delete(f) if FileTest.file?(f)}
463 Dir.open(".").each{|filename|
464 unless FileTest.directory? filename
466 file = open(filename,"r")
467 text = file.readlines
469 if text.include?($fielddheader)
473 print "PROCESSING: ", filename, "\n"
475 if /@function/ =~ text[0]
476 buf = frewrite(text[1..text.size])
477 else buf = orewrite(text)
480 filetowrite = open($dstman3m+filename,"w")
481 filetowrite.puts(headbuf)
482 filetowrite.puts(buf)