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/"
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 #removing "More..." hyperlink
259 line.gsub!(/More.../,"")
261 line.gsub!(/^\.TP/,"")
264 if line =~ /Return\svalue:/
265 returndescribed = true
267 line.gsub!(/^\\fBReturn value:\\fP/,"\n.SH RETURN VALUE\n.PP")
269 errordescribed = true
271 line.gsub!(/^\\fBErrors:\\fP/,"\n.SH ERRORS\n.PP")
272 line.gsub!(/^\\fBSee Also:\\fP/,"\n.SH \"SEE ALSO\"\n.PP")
274 line.gsub!(/^\\fB(.+)[^\)]\\fP/){"\n.SS " << $1}
275 # [^\)] in the pattern is added to avoid the first function in see also section.
277 #removing indentation
278 if text[i - 1] =~ /^.PP/
280 line.reverse!.chop!.reverse!
284 # removing the results of doxygen bug
285 # \fP required for . , ; and <>
286 line.gsub!(/\s*(\\fP)+\s*(,|\.|;)\s+/){"\\fP" << $2 << "\n.ft R\n"}
288 line.gsub!(/(\\fP)+\s*>/,"\\fP>")
289 line.gsub!(/<\s+\\f(P|I|B|C|)/){"<\\f" << $1}
292 line.gsub!(/\s*(\\fP)+\s+/,"\n.ft R\n")
294 line.gsub!(/\s+\\f(I|C)\\fB\s*/,"\n.ft B\n")
295 line.gsub!(/\s+\\f(B|I)\\fC\s*/,"\n.ft C\n")
296 line.gsub!(/\s+\\f(B|C)\\fI\s*/,"\n.ft I\n")
297 line.gsub!(/\s+\\fB\s*/,"\n.ft B\n")
298 line.gsub!(/\s+\\fC\s*/,"\n.ft C\n")
299 line.gsub!(/\s+\\fI\s*/,"\n.ft I\n")
303 unless returndescribed == true
304 print (" return not described \n")
306 unless errordescribed == true
307 print (" errors not described \n")
313 def womanrewrite(text)
315 if sasectionstart = text.index(text.find{|line| line =~ /^\.SH\s"SEE ALSO"/})
316 aftersasection = text[sasectionstart+1 .. text.size]
317 if sasectionend = aftersasection.index(aftersasection.find{|line| line =~ /^\.SH/})
318 for line in text[sasectionstart+1 .. sasectionend + sasectionstart]
319 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
322 for line in text[sasectionstart+1 .. text.size]
323 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
330 # rewriting a man file for a non-function
334 structures = ["\.SH \"Data Structure Documentation\"\n"]
336 if ddind = text.index($ddheader)
337 if odind = text.index(text.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/})
339 text[ddind+1 .. odind-1].find{|line| line =~ /^[^\.]/}
340 text = text[0 .. ddind-1] + text[odind .. text.size]
343 text.each_with_index{|line,i|
344 line.gsub!(/More.../,"")
346 # let the library name appear in the header
348 line = line.gsub!("\" \"", "\" \"\" \"")
351 # finding structure documentations and merging into "structures"
352 if line =~ /^\.RI\s\"struct\s\\fB(.*)\\fP\"/
353 structures.push(datastructure($1))
356 #removing indentation
357 if text[i - 1] =~ /^.PP/
359 line.reverse!.chop!.reverse!
364 if text[i - 1] =~ /^.SH\sNAME/
366 unless line =~ /\\-\s./
367 line.chop!.chop!.chop!.chop!
372 #removing author section
373 line.gsub!(/^\.SH\s\"AUTHOR\"/,"")
374 line.gsub!("Generated automatically by Doxygen for m17n_test from the source code.","")
376 line.gsub!(/\\fP\s+,/,"\\fP,")
377 line.gsub!(/\\fP\s+\./,"\\fP.")
378 line.gsub!(/\\fC\\fB(\w+)\\fP\\fP/){"\\fB" << $1 << "\\fP"}
383 unless structures == ["\.SH \"Data Structure Documentation\"\n"]
385 if dindex = buf.index(buf.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/i})
386 buf = buf[0 .. dindex-1] + structures + buf[dindex .. buf.size]
388 buf = buf + structures
395 #############################dividing files
397 Dir.mkdir $doxywork unless FileTest.directory? $doxywork
401 Dir.open(".").each{|filename|
403 if FileTest.directory? filename
407 #if filename =~ /\.c\./
411 file = open(filename,"r")
412 text = file.readlines
416 sfunctionstart = text.index(text.find{|i| i == $flheader})
417 if sfunctionend = text.index(text[sfunctionstart+1 .. text.size].find{|i| i =~ /^\.SS|^\.SH/})
418 short_text = text[sfunctionstart .. sfunctionend - 1]
420 short_text = text[sfunctionstart .. text.size - 1]
423 if lfunctionstart = text.index(text.find{|i| i == $fdheader})
424 if lfunctionend = text.index(text[lfunctionstart+1 .. text.size].find{|i| i =~ /^\.SH/})
425 func_text = text[lfunctionstart .. lfunctionend - 1]
426 group_text = text[0 .. lfunctionstart - 1] + text[lfunctionend ..text.size]
428 func_text = text[lfunctionstart .. text.size]
429 group_text = text[0 .. lfunctionstart - 1]
436 documentfunc(title, func_text, short_text)
444 filetowrite = open($doxywork+filename,"w")
445 filetowrite.puts(group_text)
449 #############################rewriting files
453 Dir.open(".").each{|f| File.delete(f) if FileTest.file?(f)}
457 Dir.open(".").each{|filename|
458 unless FileTest.directory? filename
460 file = open(filename,"r")
461 text = file.readlines
463 if text.include?($fielddheader)
467 print "PROCESSING: ", filename, "\n"
469 if /@function/ =~ text[0]
470 buf = frewrite(text[1..text.size])
471 else buf = orewrite(text)
474 filetowrite = open($dstman3m+filename,"w")
475 filetowrite.puts(headbuf)
476 filetowrite.puts(buf)