2 #¼Â¹Ô¤¹¤ë¤È/tmp/doxyman¤ò¤Ä¤«¤Ã¤Æ¥Õ¥¡¥¤¥ë¤òʬ¤±¡¢
3 #¤â¤È¤Îdirectory¤Ë¤«¤¤Ê¤ª¤¹¡£
4 # see also ¤ÎÃæ¿È¤ò woman ¸þ¤±¤Ë½ñ¤´¹¤¨¤ë¡£
8 currentdir = Dir.pwd+"/"
9 $doxywork = currentdir+"doxywork/"
10 $srcman3 = currentdir+usr_or_ja+"/man/man3/"
12 $dstman3m = currentdir+"/man/man3m/"
14 $dstman3m = currentdir+"/man/ja/man3m/"
17 headertexts = open("doxyhead.txt","r").readlines
18 $fdheader = headertexts[0]
19 $flheader = headertexts[1]
20 $ddheader = headertexts[2]
21 $fielddheader = headertexts[3]
22 $fieldlheader = headertexts[4]
24 #### to find data structure documentation files and rewriting them
26 def writeuntilsectionheader(buf, text, index)
27 for line in text[index .. text.size]
35 def writedocumentation(buf, text, index)
36 for line in text[index .. text.size]
41 line =~ /^.SS\s"(.+)"/
42 buf.push(".PP\n\\fB".concat($1).concat("\\fP\n"))
50 def datastructure(struct)
52 text = open(struct.concat(".3m"),"r").readlines
57 if tline = text.index("\.SH NAME\n")
58 if text[tline+1] =~ /^([\w\s]+)\s\\-\s(.+)$/
59 buf.push(".SS ".concat($1).concat("\n"))
61 buf.push($2.concat("\n"))
63 writeuntilsectionheader(buf, text, nl)
66 text[tline+1] =~ /^([\w\s]+)\s\\-/
67 buf.push(".SS ".concat($1).concat("\n"))
70 buf.push(text[tline+1])
76 if ddline = text.index(text.find{|i| i = $ddheader})
78 writeuntilsectionheader(buf, text, nl)
82 if ptline = text.index("\.SS \"Public Types\"\n")
83 buf.push("\\fBPublic Types:\\fP\n")
85 writeuntilsectionheader(buf, text, nl)
89 # member enumeration documentation
90 if medline = text.index("\.SH \"MEMBER ENUMERATION DOCUMENTATION\"\n")
91 buf.push("\.PP\n\\fBMEMBER ENUMERATION DOCUMENTATION:\\fP\n")
93 writedocumentation(buf, text, nl)
97 # if dfline = text.index($fieldlheader)
98 # buf.push("\\fBData Fields:\\fP\n")
100 # writeuntilsectionheader(buf, text, nl)
104 # field documentation
105 if fdline = text.index($fielddheader)
106 buf.push("\.PP\n\\fBFIELD DOCUMENTATION:\\fP\n")
108 writedocumentation(buf, text, nl)
114 ###############################
117 def documentfunc(title, func_text, short_text)
118 func_text.grep(/^\.SS/){|i|
120 func_rest = func_text[func_text.index(i)..func_text.size]
121 documentfunc2(i, title, func_rest, short_text)}
124 def documentfunc2 (dstart, title, func_text, short_text)
125 #func_text¤ÎºÇ½é¤Î¹ÔÃæ¤Î´Ø¿ô̾
127 dstart =~ /\s([a-z_]+)\s\(/
131 ffname = "\\fB".concat($1.concat("\\fP"))
132 #short_text¤Î´Ø¿ô̾¤Î£²¹Ô¸å¤¬brief¡£
133 brief = short_text[short_text.index(short_text.find{|i| i.index(ffname)}) + 2]
134 #´Ø¿ô¤´¤È¤Î¥Õ¥¡¥¤¥ë¤òºî¤ë¡£
135 file = open($doxywork+fname+".3m", "w")
136 file.puts("@function")
138 /^\.TH \"([^"]*)\"\s/ =~ title
140 ##????? newtitle = title.gsub(oname, fname.chop.chop)
141 newtitle = title.gsub(oname, fname)
144 file.print("@brief ")
147 else file.print("\n")
150 file.puts(func_text[0])
151 for line in func_text[1 .. func_text.size]
152 break if /.SS/ =~ line
158 ####rewriting each man file
159 ### rewriting a man file for a function
162 # let the library name appear in the header
163 buf = [text[0].gsub!("\" \"", "\" \"\" \"")]
165 title = text[0].split(" ")[1].chop!.reverse.chop!.reverse
167 if text.index("\\fBReturns: \\fP\n") == nil
168 print title, ": Returns not described\n"
170 if text.index("\\fBErrors: \\fP\n") == nil
171 print title, ": Errors not described\n"
174 buf.push(".ad l\n.nh\n.SH NAME\n")
176 if text[1] =~ /\"\\fI(.+)\\fP\"/
177 buf.push(title.concat(" \- ").concat($1))
181 synopsys = text.find{|line| line =~ /\.SS/}
182 buf.push("\n\n.SH SYNOPSIS").push(formatsynopsys(synopsys)).push("\n")
184 description = text[text.index(synopsys)+2..text.size]
187 print title, ": No description found\n"
189 buf.push("\n.SH DESCRIPTION\n").push(womanrewrite(desrewrite(description)))
194 ####synopsys section of a function
196 def formatsynopsys(line)
197 line.chop!.chop!.reverse!.chop!.chop!.chop!.chop!.chop!.reverse!
199 # line.gsub!(/\\fP\s*/,"\n.ft\n")
200 # line.gsub!(/\\fB/,"\n.ft B\n")
202 line.gsub!(/\s(\w*)\)/){"\n\\fI" << $1 << "\\fP)"}
203 line.gsub!(/\s(\w*),/){"\n\\fI" << $1 << "\\fP,"}
204 line.gsub!(/\s(\w*)\s\(/){"\n\\fB" << $1 << "\\fP ("}
207 ####non-synopsys section of a function
212 text.grep(/^\\fB.+\\fP/){|line|
213 ind = text.index(line)
214 text.delete_at(ind+1) if text[ind+1] == (".in +1c\n")}
217 text.each_with_index{|line,i|
219 #removing "More..." hyperlink
220 line.gsub!(/More.../,"")
222 line.gsub!(/^\.TP/,"")
225 line.gsub!(/^\\fBReturn value:\\fP/,"\n.SH RETURNS\n.PP")
226 line.gsub!(/^\\fBSee Also:\\fP/,"\n.SH \"SEE ALSO\"\n.PP")
227 line.gsub!(/^\\fBErrors:\\fP/,"\n.SH ERRORS\n.PP")
229 line.gsub!(/^\\fB(.+)\\fP/){"\n.SS " << $1}
231 #removing indentation
232 if text[i - 1] =~ /^.PP/
234 line.reverse!.chop!.reverse!
238 # removing the results of doxygen bug
239 # \fP required for . , ; and <>
240 line.gsub!(/\s*(\\fP)+\s*(,|\.|;)\s+/){"\\fP" << $2 << "\n.ft R\n"}
242 line.gsub!(/(\\fP)+\s*>/,"\\fP>")
243 line.gsub!(/<\s+\\f(P|I|B|C|)/){"<\\f" << $1}
246 line.gsub!(/\s*(\\fP)+\s+/,"\n.ft R\n")
248 line.gsub!(/\s+\\f(I|C)\\fB\s*/,"\n.ft B\n")
249 line.gsub!(/\s+\\f(B|I)\\fC\s*/,"\n.ft C\n")
250 line.gsub!(/\s+\\f(B|C)\\fI\s*/,"\n.ft I\n")
251 line.gsub!(/\s+\\fB\s*/,"\n.ft B\n")
252 line.gsub!(/\s+\\fC\s*/,"\n.ft C\n")
253 line.gsub!(/\s+\\fI\s*/,"\n.ft I\n")
260 def womanrewrite(text)
262 if sasectionstart = text.index(text.find{|line| line =~ /^\.SH\s"SEE ALSO"/})
263 aftersasection = text[sasectionstart+1 .. text.size]
264 if sasectionend = aftersasection.index(aftersasection.find{|line| line =~ /^\.SH/})
265 for line in text[sasectionstart+1 .. sasectionend + sasectionstart]
266 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
269 for line in text[sasectionstart+1 .. text.size]
270 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
277 # rewriting a man file for a non-function
281 structures = ["\.SH \"Data Structure Documentation\"\n"]
283 if ddind = text.index($ddheader)
284 if odind = text.index(text.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/})
286 text[ddind+1 .. odind-1].find{|line| line =~ /^[^\.]/}
287 text = text[0 .. ddind-1] + text[odind .. text.size]
290 text.each_with_index{|line,i|
291 line.gsub!(/More.../,"")
293 # let the library name appear in the header
295 line = line.gsub!("\" \"", "\" \"\" \"")
298 # finding structure documentations and merging into "structures"
299 if line =~ /^\.RI\s\"struct\s\\fB(.*)\\fP\"/
300 structures.push(datastructure($1))
303 #removing indentation
304 if text[i - 1] =~ /^.PP/
306 line.reverse!.chop!.reverse!
311 if text[i - 1] =~ /^.SH\sNAME/
313 unless line =~ /\\-\s./
314 line.chop!.chop!.chop!.chop!
319 #removing author section
320 line.gsub!(/^\.SH\s\"AUTHOR\"/,"")
321 line.gsub!("Generated automatically by Doxygen for m17n_test from the source code.","")
323 line.gsub!(/\\fP\s+,/,"\\fP,")
324 line.gsub!(/\\fP\s+\./,"\\fP.")
325 line.gsub!(/\\fC\\fB(\w+)\\fP\\fP/){"\\fB" << $1 << "\\fP"}
330 unless structures == ["\.SH \"Data Structure Documentation\"\n"]
332 if dindex = buf.index(buf.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/i})
333 buf = buf[0 .. dindex-1] + structures + buf[dindex .. buf.size]
335 buf = buf + structures
342 #############################dividing files
344 Dir.mkdir $doxywork unless FileTest.directory? $doxywork
348 Dir.open(".").each{|filename|
349 if FileTest.directory? filename
353 if filename =~ /\.c\./
357 file = open(filename,"r")
358 text = file.readlines
362 sfunctionstart = text.index(text.find{|i| i == $flheader})
363 if sfunctionend = text.index(text[sfunctionstart+1 .. text.size].find{|i| i =~ /^\.SS|^\.SH/})
364 short_text = text[sfunctionstart .. sfunctionend - 1]
366 short_text = text[sfunctionstart .. text.size - 1]
369 if lfunctionstart = text.index(text.find{|i| i == $fdheader})
370 if lfunctionend = text.index(text[lfunctionstart+1 .. text.size].find{|i| i =~ /^\.SH/})
371 func_text = text[lfunctionstart .. lfunctionend - 1]
372 group_text = text[0 .. lfunctionstart - 1] + text[lfunctionend ..text.size]
374 func_text = text[lfunctionstart .. text.size]
375 group_text = text[0 .. lfunctionstart - 1]
382 documentfunc(title, func_text, short_text)
390 filetowrite = open($doxywork+filename,"w")
391 filetowrite.puts(group_text)
395 #############################rewriting files
399 Dir.open(".").each{|f| File.delete(f) if FileTest.file?(f)}
403 Dir.open(".").each{|filename|
404 unless FileTest.directory? filename
406 print "PROCESSING: ", filename, "\n"
408 file = open(filename,"r")
409 text = file.readlines
411 if /@function/ =~ text[0]
412 buf = frewrite(text[1..text.size])
413 else buf = orewrite(text)
416 filetowrite = open($dstman3m+filename,"w")
417 filetowrite.puts(buf)
425 Dir.open(".").each{|f| File.delete(f) if FileTest.file?(f)}