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)
146 # File.delete(struct) if FileTest.file?(struct)
151 ###############################
154 def documentfunc(title, func_text, short_text)
155 func_text.grep(/^\.SS/){|i|
157 func_rest = func_text[func_text.index(i)..func_text.size]
158 documentfunc2(i, title, func_rest, short_text)}
161 def documentfunc2 (dstart, title, func_text, short_text)
162 #func_text¤ÎºÇ½é¤Î¹ÔÃæ¤Î´Ø¿ô̾
164 dstart =~ /\s([a-z0-9_]+)\s\(/
168 ffname = "\\fB".concat($1.concat("\\fP"))
169 #short_text¤Î´Ø¿ô̾¤Î£²¹Ô¸å¤¬brief¡£
170 brief = short_text[short_text.index(short_text.find{|i| i.index(ffname)}) + 2]
171 #´Ø¿ô¤´¤È¤Î¥Õ¥¡¥¤¥ë¤òºî¤ë¡£
172 file = open($doxywork+fname+".3m", "w")
173 file.puts("@function")
175 /^\.TH \"([^"]*)\"\s/ =~ title
177 ##????? newtitle = title.gsub(oname, fname.chop.chop)
178 newtitle = title.gsub(oname, fname)
181 file.print("@brief ")
184 else file.print("\n")
187 file.puts(func_text[0])
188 for line in func_text[1 .. func_text.size]
189 break if /.SS/ =~ line
195 ####rewriting each man file
196 ### rewriting a man file for a function
199 # let the library name appear in the header
200 buf = [text[0].gsub!("\" \"", "\" \"\" \"")]
202 title = text[0].split(" ")[1].chop!.reverse.chop!.reverse
204 buf.push(".ad l\n.nh\n.SH NAME\n")
206 if text[1] =~ /\"\\fI(.+)\\fP\"/
207 buf.push(title.concat(" \- ").concat($1))
211 synopsys = text.find{|line| line =~ /\.SS/}
212 buf.push("\n\n.SH SYNOPSIS").push(formatsynopsys(synopsys)).push("\n")
214 description = text[text.index(synopsys)+2..text.size]
217 print title, ": No description found\n"
219 descriptiontext = womanrewrite(desrewrite(description))
220 buf.push("\n.SH DESCRIPTION\n").push(descriptiontext)
225 ####synopsys section of a function
227 def formatsynopsys(line)
228 line.chop!.chop!.reverse!.chop!.chop!.chop!.chop!.chop!.reverse!
230 # line.gsub!(/\\fP\s*/,"\n.ft\n")
231 # line.gsub!(/\\fB/,"\n.ft B\n")
233 line.gsub!(/\s(\w*)\)/){"\n\\fI" << $1 << "\\fP)"}
234 line.gsub!(/\s(\w*),/){"\n\\fI" << $1 << "\\fP,"}
235 line.gsub!(/\s(\w*)\s\(/){"\n\\fB" << $1 << "\\fP ("}
238 ####non-synopsys section of a function
241 returndescribed = false
242 errordescribed = false
245 text.grep(/^\\fB.+\\fP/){|line|
246 ind = text.index(line)
247 text.delete_at(ind+1) if text[ind+1] == (".in +1c\n")}
250 text.each_with_index{|line,i|
253 line.gsub!(".RS 4","")
255 #removing "More..." hyperlink
256 line.gsub!(/More.../,"")
258 line.gsub!(/^\.TP/,"")
261 if line =~ /Return\svalue:/
262 line = "\n.SH RETURNS\n.PP"
263 returndescribed = true
265 # line.gsub!(/^\\fBReturn value:\\fP/,"\n.SH RETURNS\n.PP")
267 line = "\n.SH ERRORS\n.PP"
268 errordescribed = true
270 # line.gsub!(/^\\fBErrors:\\fP/,"\n.SH ERRORS\n.PP")
271 line.gsub!(/^\\fBSee Also:\\fP/,"\n.SH \"SEE ALSO\"\n.PP")
273 line.gsub!(/^\\fB(.+)\\fP/){"\n.SS " << $1}
275 #removing indentation
276 if text[i - 1] =~ /^.PP/
278 line.reverse!.chop!.reverse!
282 # removing the results of doxygen bug
283 # \fP required for . , ; and <>
284 line.gsub!(/\s*(\\fP)+\s*(,|\.|;)\s+/){"\\fP" << $2 << "\n.ft R\n"}
286 line.gsub!(/(\\fP)+\s*>/,"\\fP>")
287 line.gsub!(/<\s+\\f(P|I|B|C|)/){"<\\f" << $1}
290 line.gsub!(/\s*(\\fP)+\s+/,"\n.ft R\n")
292 line.gsub!(/\s+\\f(I|C)\\fB\s*/,"\n.ft B\n")
293 line.gsub!(/\s+\\f(B|I)\\fC\s*/,"\n.ft C\n")
294 line.gsub!(/\s+\\f(B|C)\\fI\s*/,"\n.ft I\n")
295 line.gsub!(/\s+\\fB\s*/,"\n.ft B\n")
296 line.gsub!(/\s+\\fC\s*/,"\n.ft C\n")
297 line.gsub!(/\s+\\fI\s*/,"\n.ft I\n")
301 unless returndescribed == true
302 print (" return not described \n")
304 unless errordescribed == true
305 print (" errors not described \n")
311 def womanrewrite(text)
313 if sasectionstart = text.index(text.find{|line| line =~ /^\.SH\s"SEE ALSO"/})
314 aftersasection = text[sasectionstart+1 .. text.size]
315 if sasectionend = aftersasection.index(aftersasection.find{|line| line =~ /^\.SH/})
316 for line in text[sasectionstart+1 .. sasectionend + sasectionstart]
317 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
320 for line in text[sasectionstart+1 .. text.size]
321 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
328 # rewriting a man file for a non-function
332 structures = ["\.SH \"Data Structure Documentation\"\n"]
334 if ddind = text.index($ddheader)
335 if odind = text.index(text.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/})
337 text[ddind+1 .. odind-1].find{|line| line =~ /^[^\.]/}
338 text = text[0 .. ddind-1] + text[odind .. text.size]
341 text.each_with_index{|line,i|
342 line.gsub!(/More.../,"")
344 # let the library name appear in the header
346 line = line.gsub!("\" \"", "\" \"\" \"")
349 # finding structure documentations and merging into "structures"
350 if line =~ /^\.RI\s\"struct\s\\fB(.*)\\fP\"/
351 structures.push(datastructure($1))
354 #removing indentation
355 if text[i - 1] =~ /^.PP/
357 line.reverse!.chop!.reverse!
362 if text[i - 1] =~ /^.SH\sNAME/
364 unless line =~ /\\-\s./
365 line.chop!.chop!.chop!.chop!
370 #removing author section
371 line.gsub!(/^\.SH\s\"AUTHOR\"/,"")
372 line.gsub!("Generated automatically by Doxygen for m17n_test from the source code.","")
374 line.gsub!(/\\fP\s+,/,"\\fP,")
375 line.gsub!(/\\fP\s+\./,"\\fP.")
376 line.gsub!(/\\fC\\fB(\w+)\\fP\\fP/){"\\fB" << $1 << "\\fP"}
381 unless structures == ["\.SH \"Data Structure Documentation\"\n"]
383 if dindex = buf.index(buf.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/i})
384 buf = buf[0 .. dindex-1] + structures + buf[dindex .. buf.size]
386 buf = buf + structures
393 #############################dividing files
395 Dir.mkdir $doxywork unless FileTest.directory? $doxywork
399 Dir.open(".").each{|filename|
401 if FileTest.directory? filename
405 #if filename =~ /\.c\./
409 file = open(filename,"r")
410 text = file.readlines
414 sfunctionstart = text.index(text.find{|i| i == $flheader})
415 if sfunctionend = text.index(text[sfunctionstart+1 .. text.size].find{|i| i =~ /^\.SS|^\.SH/})
416 short_text = text[sfunctionstart .. sfunctionend - 1]
418 short_text = text[sfunctionstart .. text.size - 1]
421 if lfunctionstart = text.index(text.find{|i| i == $fdheader})
422 if lfunctionend = text.index(text[lfunctionstart+1 .. text.size].find{|i| i =~ /^\.SH/})
423 func_text = text[lfunctionstart .. lfunctionend - 1]
424 group_text = text[0 .. lfunctionstart - 1] + text[lfunctionend ..text.size]
426 func_text = text[lfunctionstart .. text.size]
427 group_text = text[0 .. lfunctionstart - 1]
434 documentfunc(title, func_text, short_text)
442 filetowrite = open($doxywork+filename,"w")
443 filetowrite.puts(group_text)
447 #############################rewriting files
451 Dir.open(".").each{|f| File.delete(f) if FileTest.file?(f)}
455 Dir.open(".").each{|filename|
456 unless FileTest.directory? filename
458 file = open(filename,"r")
459 text = file.readlines
461 if text.include?($fielddheader)
465 print "PROCESSING: ", filename, "\n"
467 if /@function/ =~ text[0]
468 buf = frewrite(text[1..text.size])
469 else buf = orewrite(text)
472 filetowrite = open($dstman3m+filename,"w")
473 filetowrite.puts(buf)