2 #¼Â¹Ô¤¹¤ë¤È../work¤ò¤Ä¤«¤Ã¤Æ¥Õ¥¡¥¤¥ë¤òʬ¤±¡¢
3 #¤â¤È¤Îdirectory¤Ë¤«¤¤Ê¤ª¤¹¡£
4 # see also ¤ÎÃæ¿È¤ò woman ¸þ¤±¤Ë½ñ¤´¹¤¨¤ë¡£
6 #### to find data structure documentation files and rewriting them
8 def writeuntilsectionheader(buf, text, index)
9 for line in text[index .. text.size]
17 def writedocumentation(buf, text, index)
18 for line in text[index .. text.size]
23 line =~ /^.SS\s"(.+)"/
24 buf.push(".PP\n\\fB".concat($1).concat("\\fP\n"))
32 def datastructure(struct)
34 text = open(struct.concat(".3"),"r").readlines
39 if tline = text.index("\.SH NAME\n")
40 if text[tline+1] =~ /^([\w\s]+)\s\\-\s(.+)$/
41 buf.push(".SS ".concat($1).concat("\n"))
43 buf.push($2.concat("\n"))
45 writeuntilsectionheader(buf, text, nl)
48 text[tline+1] =~ /^([\w\s]+)\s\\-/
49 buf.push(".SS ".concat($1).concat("\n"))
52 buf.push(text[tline+1])
58 if ddline = text.index("\.SH \"DETAILED DESCRIPTION\"\n")
60 writeuntilsectionheader(buf, text, nl)
64 if ptline = text.index("\.SS \"Public Types\"\n")
65 buf.push("\\fBPublic Types:\\fP\n")
67 writeuntilsectionheader(buf, text, nl)
71 # member enumeration documentation
72 if medline = text.index("\.SH \"MEMBER ENUMERATION DOCUMENTATION\"\n")
73 buf.push("\.PP\n\\fBMEMBER ENUMERATION DOCUMENTATION:\\fP\n")
75 writedocumentation(buf, text, nl)
79 if dfline = text.index("\.SS \"Data Fields\"\n")
80 buf.push("\\fBData Fields:\\fP\n")
82 writeuntilsectionheader(buf, text, nl)
87 if fdline = text.index("\.SH \"FIELD DOCUMENTATION\"\n")
88 buf.push("\.PP\n\\fBFIELD DOCUMENTATION:\\fP\n")
90 writedocumentation(buf, text, nl)
96 ###############################
99 def documentfunc(title, func_text, short_text)
100 func_text.grep(/^\.SS/){|i|
102 func_rest = func_text[func_text.index(i)..func_text.size]
103 documentfunc2(i, title, func_rest, short_text)}
106 def documentfunc2 (dstart, title, func_text, short_text)
107 #func_text¤ÎºÇ½é¤Î¹ÔÃæ¤Î´Ø¿ô̾
108 dstart =~ /\s([a-z_]+)\s\(/
111 ffname = "\\fB".concat($1.concat("\\fP"))
112 #short_text¤Î´Ø¿ô̾¤Î£²¹Ô¸å¤¬brief¡£
113 brief = short_text[short_text.index(short_text.find{|i| i.index(ffname)}) + 2]
114 #´Ø¿ô¤´¤È¤Î¥Õ¥¡¥¤¥ë¤òºî¤ë¡£
115 file = open("../work/".concat(fname.concat(".3")), "w")
116 file.puts("@function")
118 /^\.TH \"([^"]*)\"\s/ =~ title
120 newtitle = title.gsub(oname, fname.chop.chop)
123 file.print("@brief ")
126 else file.print("\n")
129 file.puts(func_text[0])
130 for line in func_text[1 .. func_text.size]
131 break if /.SS/ =~ line
137 ####rewriting each man file
138 ### rewriting a man file for a function
142 title = text[0].split(" ")[1].chop!.reverse.chop!.reverse
144 if text.index("\\fBReturns: \\fP\n") == nil
145 print title, ": Returns not described\n"
147 if text.index("\\fBErrors: \\fP\n") == nil
148 print title, ": Errors not described\n"
151 buf.push(".ad l\n.nh\n.SH NAME\n")
153 if text[1] =~ /\"\\fI(.+)\\fP\"/
154 buf.push(title.concat(" \- ").concat($1))
158 synopsys = text.find{|line| line =~ /\.SS/}
159 buf.push("\n\n.SH SYNOPSIS").push(formatsynopsys(synopsys)).push("\n")
161 description = text[text.index(synopsys)+2..text.size]
164 print title, ": No description found\n"
166 buf.push("\n.SH DESCRIPTION\n").push(womanrewrite(desrewrite(description)))
171 ####synopsys section of a function
173 def formatsynopsys(line)
174 line.chop!.chop!.reverse!.chop!.chop!.chop!.chop!.chop!.reverse!
176 # line.gsub!(/\\fP\s*/,"\n.ft\n")
177 # line.gsub!(/\\fB/,"\n.ft B\n")
179 line.gsub!(/\s(\w*)\)/){"\n\\fI" << $1 << "\\fP)"}
180 line.gsub!(/\s(\w*),/){"\n\\fI" << $1 << "\\fP,"}
181 line.gsub!(/\s(\w*)\s\(/){"\n\\fB" << $1 << "\\fP ("}
184 ####non-synopsys section of a function
189 text.grep(/^\\fB.+\\fP/){|line|
190 ind = text.index(line)
191 text.delete_at(ind+1) if text[ind+1] == (".in +1c\n")}
194 text.each_with_index{|line,i|
196 #removing "More..." hyperlink
197 line.gsub!(/More.../,"")
199 line.gsub!(/^\.TP/,"")
202 line.gsub!(/^\\fBReturns: \\fP/,"\n.SH RETURNS\n.PP")
203 line.gsub!(/^\\fBSee Also:\\fP/,"\n.SH \"SEE ALSO\"\n.PP")
204 line.gsub!(/^\\fBErrors:\\fP/,"\n.SH ERRORS\n.PP")
206 line.gsub!(/^\\fB(.+)\\fP/){"\n.SS " << $1}
208 #removing indentation
209 if text[i - 1] =~ /^.PP/
211 line.reverse!.chop!.reverse!
215 # removing the results of doxygen bug
216 # \fP required for . , ; and <>
217 line.gsub!(/\s*(\\fP)+\s*(,|\.|;)\s+/){"\\fP" << $2 << "\n.ft R\n"}
219 line.gsub!(/(\\fP)+\s*>/,"\\fP>")
220 line.gsub!(/<\s+\\f(P|I|B|C|)/){"<\\f" << $1}
223 line.gsub!(/\s*(\\fP)+\s+/,"\n.ft R\n")
225 line.gsub!(/\s+\\f(I|C)\\fB\s*/,"\n.ft B\n")
226 line.gsub!(/\s+\\f(B|I)\\fC\s*/,"\n.ft C\n")
227 line.gsub!(/\s+\\f(B|C)\\fI\s*/,"\n.ft I\n")
228 line.gsub!(/\s+\\fB\s*/,"\n.ft B\n")
229 line.gsub!(/\s+\\fC\s*/,"\n.ft C\n")
230 line.gsub!(/\s+\\fI\s*/,"\n.ft I\n")
237 def womanrewrite(text)
239 if sasectionstart = text.index(text.find{|line| line =~ /^\.SH\s"SEE ALSO"/})
240 aftersasection = text[sasectionstart+1 .. text.size]
241 if sasectionend = aftersasection.index(aftersasection.find{|line| line =~ /^\.SH/})
242 for line in text[sasectionstart+1 .. sasectionend + sasectionstart]
243 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
246 for line in text[sasectionstart+1 .. text.size]
247 line.gsub!(/(\w*)\\fP\(\)/){ $1 << "(3)\\fP"}
254 # rewriting a man file for a non-function
258 structures = ["\.SH \"Data Structure Documentation\"\n"]
260 if ddind = text.index("\.SH \"DETAILED DESCRIPTION\"\n")
261 if odind = text.index(text.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/})
263 text[ddind+1 .. odind-1].find{|line| line =~ /^[^\.]/}
264 text = text[0 .. ddind-1] + text[odind .. text.size]
267 text.each_with_index{|line,i|
268 line.gsub!(/More.../,"")
270 # finding structure documentations and merging into "structures"
271 if line =~ /^\.RI\s\"struct\s\\fB(.*)\\fP\"/
272 structures.push(datastructure($1))
275 #removing indentation
276 if text[i - 1] =~ /^.PP/
278 line.reverse!.chop!.reverse!
283 if text[i - 1] =~ /^.SH\sNAME/
285 unless line =~ /\\-\s./
286 line.chop!.chop!.chop!.chop!
291 #removing author section
292 line.gsub!(/^\.SH\s\"AUTHOR\"/,"")
293 line.gsub!("Generated automatically by Doxygen for m17n_test from the source code.","")
295 line.gsub!(/\\fP\s+,/,"\\fP,")
296 line.gsub!(/\\fP\s+\./,"\\fP.")
297 line.gsub!(/\\fC\\fB(\w+)\\fP\\fP/){"\\fB" << $1 << "\\fP"}
302 unless structures == ["\.SH \"Data Structure Documentation\"\n"]
304 if dindex = buf.index(buf.find{|line| line =~ /\.SH\s+.+\s+DOCUMENTATION/})
305 buf = buf[0 .. dindex-1] + structures + buf[dindex .. buf.size]
307 buf = buf + structures
314 #############################dividing files
316 Dir.mkdir "../work" unless FileTest.directory? "../work"
318 Dir.open(".").each{|filename|
319 if FileTest.directory? filename
323 if filename =~ /\.c\./
324 # File.delete(filename)
328 file = open(filename,"r")
329 text = file.readlines
333 sfunctionstart = text.index(text.find{|i| i =~ /^\.SS "Function/})
334 if sfunctionend = text.index(text[sfunctionstart+1 .. text.size].find{|i| i =~ /^\.SS|^\.SH/})
335 short_text = text[sfunctionstart .. sfunctionend - 1]
337 short_text = text[sfunctionstart .. text.size - 1]
340 if lfunctionstart = text.index(text.find{|i| i =~ /^\.SH "FUNCTION DOCUMENTATION"/})
341 if lfunctionend = text.index(text[lfunctionstart+1 .. text.size].find{|i| i =~ /^\.SH/})
342 func_text = text[lfunctionstart .. lfunctionend - 1]
343 group_text = text[0 .. lfunctionstart - 1] + text[lfunctionend ..text.size]
345 func_text = text[lfunctionstart .. text.size]
346 group_text = text[0 .. lfunctionstart - 1]
353 documentfunc(title, func_text, short_text)
361 filetowrite = open("../work/".concat(filename),"w")
362 filetowrite.puts(group_text)
367 #############################rewriting files
368 Dir.mkdir "../../man" unless FileTest.directory? "../../man"
369 Dir.mkdir "../../man/man3" unless FileTest.directory? "../../man/man3"
372 Dir.open("../work").each{|filename|
373 unless FileTest.directory? filename
375 print "PROCESSING: ", filename, "\n"
377 file = open("../work/".concat(filename),"r")
378 text = file.readlines
380 if /@function/ =~ text[0]
381 buf = frewrite(text[1..text.size])
382 else buf = orewrite(text)
385 filetowrite = open("../../man/man3/".concat(filename),"w")
386 filetowrite.puts(buf)
395 Dir.open(".").each{|f| File.delete(f) if FileTest.file?(f)}