2 # Usage: mkman.rb SRCDIR DSTDIR
4 #¼Â¹Ô¤¹¤ë¤È/tmp/doxyman¤ò¤Ä¤«¤Ã¤Æ¥Õ¥¡¥¤¥ë¤òʬ¤±¡¢
5 #¤â¤È¤Îdirectory¤Ë¤«¤¤Ê¤ª¤¹¡£
6 # see also ¤ÎÃæ¿È¤ò woman ¸þ¤±¤Ë½ñ¤´¹¤¨¤ë¡£
11 # Setting up directory names.
14 $currentdir = Dir.pwd+"/"
15 $srcdir=$currentdir+$*[1]+"/"
16 $dstdir=$currentdir+$*[2]+"/"
17 $doxywork = $currentdir+"doxywork/"
18 $sampledir="sample/man3/"
19 $headfile = $currentdir+"manhead"
21 headbuf = open($headfile, "r").readlines
24 # Extra information about header strings Doxygen generates in a man file.
27 def nextheader(text,index)
28 header = text[index+1..text.size].find{|i| i =~ /\.S(S|H)/}
32 grouptext = open($sampledir+"SampleGroup.3","r").readlines.reverse
34 fd = grouptext.index(grouptext.find{|i| i =~ /SampleFunction/})
35 $fdheader = nextheader(grouptext,fd)
37 restofthetext = grouptext[fd+1..grouptext.size]
39 fl = restofthetext.index(restofthetext.find{|i| i =~ /SampleFunction/})
40 $flheader = nextheader(restofthetext,fl)
42 dd = grouptext.index(grouptext.find{|i| i =~ /long group document/})
43 $ddheader = nextheader(grouptext,dd)
46 structext = open($sampledir+"SampleStructure.3","r").readlines.reverse
48 fieldd = structext.index(structext.find{|i| i =~ /SampleField/})
49 $fielddheader = nextheader(structext,fieldd)
51 restofstructext = structext[fieldd+1..structext.size]
53 fieldl = restofstructext.index(restofstructext.find{|i| i =~ /SampleField/})
54 $fieldlheader = nextheader(restofstructext, fieldl)
60 #### to find data structure documentation files and rewriting them
62 def writeuntilsectionheader(buf, text, index)
63 for line in text[index .. text.size]
71 def writedocumentation(buf, text, index)
72 for line in text[index .. text.size]
77 line =~ /^.SS\s"(.+)"/
78 buf.push(".PP\n\\fB".concat($1).concat("\\fP\n"))
86 def datastructure(struct)
88 text = open(struct.concat($manext),"r").readlines
93 if tline = text.index("\.SH NAME\n")
94 if text[tline+1] =~ /^([\w\s]+)\s\\-\s(.+)$/
95 buf.push(".SS ".concat($1).concat("\n"))
97 buf.push($2.concat("\n"))
99 writeuntilsectionheader(buf, text, nl)
102 text[tline+1] =~ /^([\w\s]+)\s\\-/
103 buf.push(".SS ".concat($1).concat("\n"))
106 buf.push(text[tline+1])
112 if ddline = text.index(text.find{|i| i = $ddheader})
114 writeuntilsectionheader(buf, text, nl)
118 if ptline = text.index("\.SS \"Public Types\"\n")
119 buf.push("\\fBPublic Types:\\fP\n")
121 writeuntilsectionheader(buf, text, nl)
125 # member enumeration documentation
126 if medline = text.index("\.SH \"MEMBER ENUMERATION DOCUMENTATION\"\n")
127 buf.push("\.PP\n\\fBMEMBER ENUMERATION DOCUMENTATION:\\fP\n")
129 writedocumentation(buf, text, nl)
133 # if dfline = text.index($fieldlheader)
134 # buf.push("\\fBData Fields:\\fP\n")
136 # writeuntilsectionheader(buf, text, nl)
140 # field documentation
141 if fdline = text.index($fielddheader)
142 buf.push("\.PP\n\\fBFIELD DOCUMENTATION:\\fP\n")
144 writedocumentation(buf, text, nl)
147 # File.delete(struct) if FileTest.file?(struct)
152 ###############################
155 def documentfunc(title, func_text, short_text)
156 func_text.grep(/^\.SS/){|i|
158 func_rest = func_text[func_text.index(i) ..func_text.size]
159 if funclast = func_rest.index(func_rest[1 .. func_rest.size].find{|m| m =~ /^\.SS/})
160 func_desc = func_rest[0 .. funclast - 1]
162 func_desc = func_rest
172 #fname: func_text¤ÎºÇ½é¤Î¹ÔÃæ¤Î´Ø¿ô̾
173 i =~ /\s([a-z0-9_]+)\s\(/
177 ffname = "\\fB".concat($1.concat("\\fP"))
178 #short_text¤Î´Ø¿ô̾¤Î£²¹Ô¸å¤¬brief¡£
179 if short_text.find{|i| i.index(ffname)}
180 brief = short_text[short_text.index(short_text.find{|i| i.index(ffname)}) + 2]
181 documentfunc2(fname, title, func_desc, brief)
183 # print " Cannot find short desc for "
190 def documentfunc2 (fname, title, func_desc, brief)
192 #´Ø¿ô¤´¤È¤Î¥Õ¥¡¥¤¥ë¤òºî¤ë¡£
193 file = open($doxywork+fname+$manext, "w")
194 file.puts("@function")
196 /^\.TH \"([^"]*)\"\s/ =~ title
198 ##????? newtitle = title.gsub(oname, fname.chop.chop)
199 newtitle = title.gsub(oname, fname)
202 file.print("@brief ")
205 else file.print("\n")
209 # for line in func_desc[1 .. func_desc.size]
210 # break if /.SS/ =~ line
217 ####rewriting each man file
218 ### rewriting a man file for a function
222 # let the library name appear in the header
223 buf = [text[0].gsub!(/\" \"/, "\" \"\" \"")]
225 title = text[0].split(" ")[1].chop!.reverse.chop!.reverse
227 buf.push(".ad l\n.nh\n.SH NAME\n")
229 if text[1] =~ /\"\\fI(.+)\\fP\"/
230 buf.push(title.concat(" \- ").concat($1))
234 synopsys = text.find{|line| line =~ /\.SS/}
235 buf.push("\n\n.SH SYNOPSIS").push(formatsynopsys(synopsys)).push("\n")
237 description = text[text.index(synopsys)+2..text.size]
240 print title, ": No description found\n"
242 descriptiontext = womanrewrite(desrewrite(description))
243 buf.push("\n.SH DESCRIPTION\n").push(descriptiontext)
248 ####synopsys section of a function
250 def formatsynopsys(line)
251 line.chop!.chop!.reverse!.chop!.chop!.chop!.chop!.chop!.reverse!
253 # line.gsub!(/\\fP\s*/,"\n.ft\n")
254 # line.gsub!(/\\fB/,"\n.ft B\n")
256 line.gsub!(/\s(\w*)\)/){"\n\\fI" << $1 << "\\fP)"}
257 line.gsub!(/\s(\w*),/){"\n\\fI" << $1 << "\\fP,"}
258 line.gsub!(/\s(\w*)\s\(/){"\n\\fB" << $1 << "\\fP ("}
261 ####non-synopsys section of a function
264 returndescribed = false
265 errordescribed = false
268 text.grep(/^\\fB.+\\fP/){|line|
269 ind = text.index(line)
270 text.delete_at(ind+1) if text[ind+1] == (".in +1c\n")}
272 ### letting verbatim end in place Part1
275 text.each_with_index{|line,i|
278 line.gsub!(/^\.RS 4/,"")
280 ### letting verbatim end in place Part2
287 line.gsub!(/^\.PP/,".fi")
292 #removing "More..." hyperlink
293 line.gsub!(/More.../,"")
295 line.gsub!(/^\.TP/,"")
299 if line =~ /Return\svalue:/
300 returndescribed = true
302 line.gsub!(/^\\fBReturn value:\\fP/,"\n.SH RETURN VALUE\n.PP")
304 errordescribed = true
306 line.gsub!(/^\\fBErrors:\\fP/,"\n.SH ERRORS\n.PP")
307 line.gsub!(/^\\fBSee Also:\\fP/,"\n.SH \"SEE ALSO\"\n.PP")
309 line.gsub!(/^\\fB(.+)[^\)]\\fP/){"\n.SS " << $1}
310 # [^\)] in the pattern is added to avoid the first function in see also section.
312 #removing indentation
313 if text[i - 1] =~ /^.PP/
315 line.reverse!.chop!.reverse!
319 # removing the results of doxygen bug
320 # \fP required for . , ; and <>
321 line.gsub!(/\s*(\\fP)+\s*(,|\.|;)\s+/){"\\fP" << $2 << "\n.ft R\n"}
323 line.gsub!(/(\\fP)+\s*>/,"\\fP>")
324 line.gsub!(/<\s+\\f(P|I|B|C|)/){"<\\f" << $1}
327 line.gsub!(/\s*(\\fP)+\s+/,"\n.ft R\n")
329 line.gsub!(/\s+\\f(I|C)\\fB\s*/,"\n.ft B\n")
330 line.gsub!(/\s+\\f(B|I)\\fC\s*/,"\n.ft C\n")
331 line.gsub!(/\s+\\f(B|C)\\fI\s*/,"\n.ft I\n")
332 line.gsub!(/\s+\\fB\s*/,"\n.ft B\n")
333 line.gsub!(/\s+\\fC\s*/,"\n.ft C\n")
334 line.gsub!(/\s+\\fI\s*/,"\n.ft I\n")
338 unless returndescribed == true
339 print (" return not described \n")
341 unless errordescribed == true
342 print (" errors not described \n")
348 def womanrewrite(text)
350 if sasectionstart = text.index(text.find{|line| line =~ /^\.SH\s"SEE ALSO"/})
351 aftersasection = text[sasectionstart+1 .. text.size]
352 if sasectionend = aftersasection.index(aftersasection.find{|line| line =~ /^\.SH/})
353 for line in text[sasectionstart+1 .. sasectionend + sasectionstart]
354 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
357 for line in text[sasectionstart+1 .. text.size]
358 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
365 # rewriting a man file for a non-function
369 structures = ["\.SH \"Data Structure Documentation\"\n"]
371 if ddind = text.index($ddheader)
372 if odind = text.index(text.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/})
374 text[ddind+1 .. odind-1].find{|line| line =~ /^[^\.]/}
375 text = text[0 .. ddind-1] + text[odind .. text.size]
378 text.each_with_index{|line,i|
379 line.gsub!(/More.../,"")
381 ### let verbatim end in place
382 line.gsub!(/^.nf/,".NF")
384 ### test1/16/2004 changes the type of list, and indentation
393 ### end of test1/20/2004
395 # let the library name appear in the header
397 line = line.gsub!(/\" \"/, "\" \"\" \"")
400 # finding structure documentations and merging into "structures"
401 if line =~ /^\.RI\s\"struct\s\\fB(.*)\\fP\"/
402 structures.push(datastructure($1))
405 #removing indentation
406 if text[i - 1] =~ /^.PP/
408 line.reverse!.chop!.reverse!
413 if text[i - 1] =~ /^.SH\sNAME/
415 unless line =~ /\\-\s./
416 line.chop!.chop!.chop!.chop!
421 #removing author section
422 line.gsub!(/^\.SH\s\"AUTHOR\"/,"")
423 line.gsub!(/Generated automatically by Doxygen for m17n_test from the source code\./,"")
425 line.gsub!(/\\fP\s+,/,"\\fP,")
426 line.gsub!(/\\fP\s+\./,"\\fP.")
427 line.gsub!(/\\fC\\fB(\w+)\\fP\\fP/){"\\fB" << $1 << "\\fP"}
432 unless structures == ["\.SH \"Data Structure Documentation\"\n"]
434 if dindex = buf.index(buf.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/i})
435 buf = buf[0 .. dindex-1] + structures + buf[dindex .. buf.size]
437 buf = buf + structures
444 #############################dividing files
446 Dir.mkdir $doxywork unless FileTest.directory? $doxywork
450 Dir.open(".").each{|filename|
452 if FileTest.directory? filename
456 if filename =~ /\.[ch]\./
460 if filename =~ /\.txt\./
464 print "RUBY DIVIDING: ", filename, "\n"
466 file = open(filename,"r")
467 text = file.readlines
471 sfunctionstart = text.index(text.find{|i| i == $flheader})
472 if sfunctionend = text.index(text[sfunctionstart+1 .. text.size].find{|i| i =~ /^\.SS|^\.SH/})
473 short_text = text[sfunctionstart .. sfunctionend - 1]
475 short_text = text[sfunctionstart .. text.size - 1]
478 if lfunctionstart = text.index(text.find{|i| i == $fdheader})
479 if lfunctionend = text.index(text[lfunctionstart+1 .. text.size].find{|i| i =~ /^\.SH/})
480 func_text = text[lfunctionstart .. lfunctionend - 1]
481 group_text = text[0 .. lfunctionstart - 1] + text[lfunctionend ..text.size]
483 func_text = text[lfunctionstart .. text.size]
484 group_text = text[0 .. lfunctionstart - 1]
491 documentfunc(title, func_text, short_text)
498 filetowrite = open($doxywork+filename,"w")
499 filetowrite.puts(group_text)
503 #############################rewriting files
507 Dir.open(".").each{|f| File.delete(f) if FileTest.file?(f)}
511 Dir.open(".").each{|filename|
512 unless FileTest.directory? filename
514 file = open(filename,"r")
515 text = file.readlines
517 if text.include?($fielddheader)
521 print "RUBY REWRINTING: ", filename, "\n"
523 if /@function/ =~ text[0]
524 buf = frewrite(text[1..text.size])
525 else buf = orewrite(text)
528 filetowrite = open($dstdir+filename,"w")
529 filetowrite.puts(headbuf)
530 filetowrite.puts(buf)