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 documentfunc2(i, title, func_rest, short_text)}
162 def documentfunc2 (dstart, title, func_text, short_text)
163 #func_text¤ÎºÇ½é¤Î¹ÔÃæ¤Î´Ø¿ô̾
165 dstart =~ /\s([a-z0-9_]+)\s\(/
169 ffname = "\\fB".concat($1.concat("\\fP"))
170 #short_text¤Î´Ø¿ô̾¤Î£²¹Ô¸å¤¬brief¡£
171 brief = short_text[short_text.index(short_text.find{|i| i.index(ffname)}) + 2]
172 #´Ø¿ô¤´¤È¤Î¥Õ¥¡¥¤¥ë¤òºî¤ë¡£
173 file = open($doxywork+fname+$manext, "w")
174 file.puts("@function")
176 /^\.TH \"([^"]*)\"\s/ =~ title
178 ##????? newtitle = title.gsub(oname, fname.chop.chop)
179 newtitle = title.gsub(oname, fname)
182 file.print("@brief ")
185 else file.print("\n")
188 file.puts(func_text[0])
189 for line in func_text[1 .. func_text.size]
190 break if /.SS/ =~ line
196 ####rewriting each man file
197 ### rewriting a man file for a function
200 # let the library name appear in the header
201 buf = [text[0].gsub!(/\" \"/, "\" \"\" \"")]
203 title = text[0].split(" ")[1].chop!.reverse.chop!.reverse
205 buf.push(".ad l\n.nh\n.SH NAME\n")
207 if text[1] =~ /\"\\fI(.+)\\fP\"/
208 buf.push(title.concat(" \- ").concat($1))
212 synopsys = text.find{|line| line =~ /\.SS/}
213 buf.push("\n\n.SH SYNOPSIS").push(formatsynopsys(synopsys)).push("\n")
215 description = text[text.index(synopsys)+2..text.size]
218 print title, ": No description found\n"
220 descriptiontext = womanrewrite(desrewrite(description))
221 buf.push("\n.SH DESCRIPTION\n").push(descriptiontext)
226 ####synopsys section of a function
228 def formatsynopsys(line)
229 line.chop!.chop!.reverse!.chop!.chop!.chop!.chop!.chop!.reverse!
231 # line.gsub!(/\\fP\s*/,"\n.ft\n")
232 # line.gsub!(/\\fB/,"\n.ft B\n")
234 line.gsub!(/\s(\w*)\)/){"\n\\fI" << $1 << "\\fP)"}
235 line.gsub!(/\s(\w*),/){"\n\\fI" << $1 << "\\fP,"}
236 line.gsub!(/\s(\w*)\s\(/){"\n\\fB" << $1 << "\\fP ("}
239 ####non-synopsys section of a function
242 returndescribed = false
243 errordescribed = false
246 text.grep(/^\\fB.+\\fP/){|line|
247 ind = text.index(line)
248 text.delete_at(ind+1) if text[ind+1] == (".in +1c\n")}
250 ### letting verbatim end in place Part1
253 text.each_with_index{|line,i|
256 line.gsub!(/^\.RS 4/,"")
258 ### letting verbatim end in place Part2
265 line.gsub!(/^\.PP/,".fi")
270 #removing "More..." hyperlink
271 line.gsub!(/More.../,"")
273 line.gsub!(/^\.TP/,"")
277 if line =~ /Return\svalue:/
278 returndescribed = true
280 line.gsub!(/^\\fBReturn value:\\fP/,"\n.SH RETURN VALUE\n.PP")
282 errordescribed = true
284 line.gsub!(/^\\fBErrors:\\fP/,"\n.SH ERRORS\n.PP")
285 line.gsub!(/^\\fBSee Also:\\fP/,"\n.SH \"SEE ALSO\"\n.PP")
287 line.gsub!(/^\\fB(.+)[^\)]\\fP/){"\n.SS " << $1}
288 # [^\)] in the pattern is added to avoid the first function in see also section.
290 #removing indentation
291 if text[i - 1] =~ /^.PP/
293 line.reverse!.chop!.reverse!
297 # removing the results of doxygen bug
298 # \fP required for . , ; and <>
299 line.gsub!(/\s*(\\fP)+\s*(,|\.|;)\s+/){"\\fP" << $2 << "\n.ft R\n"}
301 line.gsub!(/(\\fP)+\s*>/,"\\fP>")
302 line.gsub!(/<\s+\\f(P|I|B|C|)/){"<\\f" << $1}
305 line.gsub!(/\s*(\\fP)+\s+/,"\n.ft R\n")
307 line.gsub!(/\s+\\f(I|C)\\fB\s*/,"\n.ft B\n")
308 line.gsub!(/\s+\\f(B|I)\\fC\s*/,"\n.ft C\n")
309 line.gsub!(/\s+\\f(B|C)\\fI\s*/,"\n.ft I\n")
310 line.gsub!(/\s+\\fB\s*/,"\n.ft B\n")
311 line.gsub!(/\s+\\fC\s*/,"\n.ft C\n")
312 line.gsub!(/\s+\\fI\s*/,"\n.ft I\n")
316 unless returndescribed == true
317 print (" return not described \n")
319 unless errordescribed == true
320 print (" errors not described \n")
326 def womanrewrite(text)
328 if sasectionstart = text.index(text.find{|line| line =~ /^\.SH\s"SEE ALSO"/})
329 aftersasection = text[sasectionstart+1 .. text.size]
330 if sasectionend = aftersasection.index(aftersasection.find{|line| line =~ /^\.SH/})
331 for line in text[sasectionstart+1 .. sasectionend + sasectionstart]
332 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
335 for line in text[sasectionstart+1 .. text.size]
336 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
343 # rewriting a man file for a non-function
347 structures = ["\.SH \"Data Structure Documentation\"\n"]
349 if ddind = text.index($ddheader)
350 if odind = text.index(text.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/})
352 text[ddind+1 .. odind-1].find{|line| line =~ /^[^\.]/}
353 text = text[0 .. ddind-1] + text[odind .. text.size]
356 text.each_with_index{|line,i|
357 line.gsub!(/More.../,"")
359 ### let verbatim end in place
360 line.gsub!(/^.nf/,".NF")
362 ### test1/16/2004 changes the type of list, and indentation
371 ### end of test1/20/2004
373 # let the library name appear in the header
375 line = line.gsub!(/\" \"/, "\" \"\" \"")
378 # finding structure documentations and merging into "structures"
379 if line =~ /^\.RI\s\"struct\s\\fB(.*)\\fP\"/
380 structures.push(datastructure($1))
383 #removing indentation
384 if text[i - 1] =~ /^.PP/
386 line.reverse!.chop!.reverse!
391 if text[i - 1] =~ /^.SH\sNAME/
393 unless line =~ /\\-\s./
394 line.chop!.chop!.chop!.chop!
399 #removing author section
400 line.gsub!(/^\.SH\s\"AUTHOR\"/,"")
401 line.gsub!(/Generated automatically by Doxygen for m17n_test from the source code\./,"")
403 line.gsub!(/\\fP\s+,/,"\\fP,")
404 line.gsub!(/\\fP\s+\./,"\\fP.")
405 line.gsub!(/\\fC\\fB(\w+)\\fP\\fP/){"\\fB" << $1 << "\\fP"}
410 unless structures == ["\.SH \"Data Structure Documentation\"\n"]
412 if dindex = buf.index(buf.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/i})
413 buf = buf[0 .. dindex-1] + structures + buf[dindex .. buf.size]
415 buf = buf + structures
422 #############################dividing files
424 Dir.mkdir $doxywork unless FileTest.directory? $doxywork
428 Dir.open(".").each{|filename|
430 if FileTest.directory? filename
434 if filename =~ /\.[ch]\./
438 if filename =~ /\.txt\./
442 file = open(filename,"r")
443 text = file.readlines
447 sfunctionstart = text.index(text.find{|i| i == $flheader})
448 if sfunctionend = text.index(text[sfunctionstart+1 .. text.size].find{|i| i =~ /^\.SS|^\.SH/})
449 short_text = text[sfunctionstart .. sfunctionend - 1]
451 short_text = text[sfunctionstart .. text.size - 1]
454 if lfunctionstart = text.index(text.find{|i| i == $fdheader})
455 if lfunctionend = text.index(text[lfunctionstart+1 .. text.size].find{|i| i =~ /^\.SH/})
456 func_text = text[lfunctionstart .. lfunctionend - 1]
457 group_text = text[0 .. lfunctionstart - 1] + text[lfunctionend ..text.size]
459 func_text = text[lfunctionstart .. text.size]
460 group_text = text[0 .. lfunctionstart - 1]
467 documentfunc(title, func_text, short_text)
475 filetowrite = open($doxywork+filename,"w")
476 filetowrite.puts(group_text)
480 #############################rewriting files
484 Dir.open(".").each{|f| File.delete(f) if FileTest.file?(f)}
488 Dir.open(".").each{|filename|
489 unless FileTest.directory? filename
491 file = open(filename,"r")
492 text = file.readlines
494 if text.include?($fielddheader)
498 print "PROCESSING: ", filename, "\n"
500 if /@function/ =~ text[0]
501 buf = frewrite(text[1..text.size])
502 else buf = orewrite(text)
505 filetowrite = open($dstdir+filename,"w")
506 filetowrite.puts(headbuf)
507 filetowrite.puts(buf)