#! /usr/local/bin/ruby
+# Usage: mkman.rb SRCDIR DSTDIR -*- coding: euc-jp; -*-
+
#¼Â¹Ô¤¹¤ë¤È/tmp/doxyman¤ò¤Ä¤«¤Ã¤Æ¥Õ¥¡¥¤¥ë¤òʬ¤±¡¢
#¤â¤È¤Îdirectory¤Ë¤«¤¤Ê¤ª¤¹¡£
# see also ¤ÎÃæ¿È¤ò woman ¸þ¤±¤Ë½ñ¤´¹¤¨¤ë¡£
-usr_or_ja=$*[0]
+$manext="."+$*[0]
-currentdir = Dir.pwd+"/"
-$doxywork = currentdir+"doxywork/"
-$srcman3 = currentdir+usr_or_ja+"/man/man3/"
-if usr_or_ja == "usr"
- $dstman3m = currentdir+"/man/man3m/"
-else
- $dstman3m = currentdir+"/man/ja/man3m/"
-end
+#
+# Setting up directory names.
+#
+
+$currentdir = Dir.pwd+"/"
+$srcdir=$currentdir+$*[1]+"/"
+$dstdir=$currentdir+$*[2]+"/"
+$doxywork = $currentdir+"doxywork/"
+$sampledir="sample/man3/"
+
+# fixed text
+
+$headfile = $currentdir+"manhead"
+$footfile = $currentdir+"manfoot"
+
+headbuf = open($headfile, "r").readlines
+footbuf = open($footfile, "r").readlines
+
+#
+# Extra information about header strings Doxygen generates in a man file.
+#
+
+def nextheader(text,index)
+ header = text[index+1..text.size].find{|i| i =~ /\.S(S|H)/}
+ return header
+ end
+
+grouptext = open($sampledir+"SampleGroup.3","r").readlines.reverse
-headertexts = open("doxyhead.txt","r").readlines
- $fdheader = headertexts[0]
- $flheader = headertexts[1]
- $ddheader = headertexts[2]
- $fielddheader = headertexts[3]
- $fieldlheader = headertexts[4]
+fd = grouptext.index(grouptext.find{|i| i =~ /SampleFunction/})
+$fdheader = nextheader(grouptext,fd)
+
+restofthetext = grouptext[fd+1..grouptext.size]
+
+fl = restofthetext.index(restofthetext.find{|i| i =~ /SampleFunction/})
+$flheader = nextheader(restofthetext,fl)
+
+dd = grouptext.index(grouptext.find{|i| i =~ /long group document/})
+$ddheader = nextheader(grouptext,dd)
+
+####
+structext = open($sampledir+"SampleStructure.3","r").readlines.reverse
+
+fieldd = structext.index(structext.find{|i| i =~ /SampleField/})
+$fielddheader = nextheader(structext,fieldd)
+
+restofstructext = structext[fieldd+1..structext.size]
+
+fieldl = restofstructext.index(restofstructext.find{|i| i =~ /SampleField/})
+$fieldlheader = nextheader(restofstructext, fieldl)
+
+#
+# Main work
+#
#### to find data structure documentation files and rewriting them
def datastructure(struct)
- text = open(struct.concat(".3m"),"r").readlines
+ text = open(struct.concat($manext),"r").readlines
buf = []
end
# data fields
- if dfline = text.index($fieldlheader)
- buf.push("\\fBData Fields:\\fP\n")
- nl = dfline + 1
- writeuntilsectionheader(buf, text, nl)
- buf.push(".PP\n")
- end
+# if dfline = text.index($fieldlheader)
+# buf.push("\\fBData Fields:\\fP\n")
+# nl = dfline + 1
+# writeuntilsectionheader(buf, text, nl)
+# buf.push(".PP\n")
+# end
# field documentation
if fdline = text.index($fielddheader)
nl = fdline + 1
writedocumentation(buf, text, nl)
end
+
+# File.delete(struct) if FileTest.file?(struct)
return buf
end
### ¥Õ¥¡¥¤¥ëʬ¤±
def documentfunc(title, func_text, short_text)
+ residue = []
func_text.grep(/^\.SS/){|i|
- #¼«Ê¬¤è¤ê¸å¤í¤À¤±
- func_rest = func_text[func_text.index(i)..func_text.size]
- documentfunc2(i, title, func_rest, short_text)}
-end
+ #¼«Ê¬¤È¤½¤Î¸å¤í
+ func_rest = func_text[func_text.index(i) ..func_text.size]
+ if funclast = func_rest.index(func_rest[1 .. func_rest.size].find{|m| m =~ /^\.SS/})
+ func_desc = func_rest[0 .. funclast - 1]
+ else
+ func_desc = func_rest
+ end
-def documentfunc2 (dstart, title, func_text, short_text)
- #func_text¤ÎºÇ½é¤Î¹ÔÃæ¤Î´Ø¿ô̾
+ #fname: func_text¤ÎºÇ½é¤Î¹ÔÃæ¤Î´Ø¿ô̾
+ i =~ /\s([a-z0-9_]+)\s\(/
+ if $1 == nil
+ else
+ fname = $1
+ ffname = "\\fB".concat($1.concat("\\fP"))
+ #short_text¤Î´Ø¿ô̾¤Î£²¹Ô¸å¤¬brief¡£
+ if short_text.find{|i| i.index(ffname)}
+ brief = short_text[short_text.index(short_text.find{|i| i.index(ffname)}) + 2]
+ documentfunc2(fname, title, func_desc, brief)
+ else # obsolete function ¤Î¾ì¹ç
+ residue.push(func_desc)
+ end
+ end
+ }
+ return residue
+end
- dstart =~ /\s([a-z_]+)\s\(/
- return if $1 == nil
- fname = $1
+def documentfunc2 (fname, title, func_desc, brief)
- ffname = "\\fB".concat($1.concat("\\fP"))
- #short_text¤Î´Ø¿ô̾¤Î£²¹Ô¸å¤¬brief¡£
- brief = short_text[short_text.index(short_text.find{|i| i.index(ffname)}) + 2]
#´Ø¿ô¤´¤È¤Î¥Õ¥¡¥¤¥ë¤òºî¤ë¡£
- file = open($doxywork+fname+".3m", "w")
+ file = open($doxywork+fname+$manext, "w")
file.puts("@function")
#¥Ø¥Ã¥À
/^\.TH \"([^"]*)\"\s/ =~ title
else file.print("\n")
end
#¥í¥ó¥°
- file.puts(func_text[0])
- for line in func_text[1 .. func_text.size]
- break if /.SS/ =~ line
- file.puts(line)
- end
+ file.puts(func_desc)
+# for line in func_desc[1 .. func_desc.size]
+# break if /.SS/ =~ line
+# file.puts(line)
+# end
file.flush
+
end
####rewriting each man file
### rewriting a man file for a function
def frewrite(text)
+
# let the library name appear in the header
- buf = [text[0].gsub!("\" \"", "\" \"\" \"")]
+ buf = [text[0].gsub!(/\" \"/, "\" \"\" \"")]
title = text[0].split(" ")[1].chop!.reverse.chop!.reverse
- if text.index("\\fBReturns: \\fP\n") == nil
- print title, ": Returns not described\n"
- end
- if text.index("\\fBErrors: \\fP\n") == nil
- print title, ": Errors not described\n"
- end
-
buf.push(".ad l\n.nh\n.SH NAME\n")
# if @brief is given
if text[1] =~ /\"\\fI(.+)\\fP\"/
- buf.push(title.concat(" \- ").concat($1))
- else buf.push(title)
+ buf.push(title.concat(" \\- ").concat($1))
+ else buf.push(title.concat(" \\- "))
end
synopsys = text.find{|line| line =~ /\.SS/}
- buf.push("\n\n.SH SYNOPSIS").push(formatsynopsys(synopsys)).push("\n")
-
- description = text[text.index(synopsys)+2..text.size]
- if
- description == []
- print title, ": No description found\n"
- else
- buf.push("\n.SH DESCRIPTION\n").push(womanrewrite(desrewrite(description)))
- end
+ buf.push("\n\n.SH SYNOPSIS").push(formatsynopsys(synopsys)).push("\n")
+
+ description = text[text.index(synopsys)+2..text.size]
+ if
+ description == []
+ print title, ": No description found\n"
+ else
+ descriptiontext = womanrewrite(desrewrite(description))
+ buf.push("\n.SH DESCRIPTION\n").push(descriptiontext)
+ end
return buf
end
####non-synopsys section of a function
def desrewrite(text)
+ returndescribed = false
+ errordescribed = false
#removing identation
text.grep(/^\\fB.+\\fP/){|line|
ind = text.index(line)
text.delete_at(ind+1) if text[ind+1] == (".in +1c\n")}
+### letting verbatim end in place Part1
+ verbatim = false
text.each_with_index{|line,i|
+### TEST 2008/3/3
+ line.gsub!(/\.RS 4/,"\n.RS 4")
+# line.gsub!(/^\.RE/,"")
+
+### letting verbatim end in place Part2
+ if line =~ /^\.nf/
+ verbatim = true
+ end
+
+ if verbatim == true
+ if line =~ /^\.PP/
+ line.gsub!(/^\.PP/,".fi")
+ verbatim = false
+ end
+ end
+
#removing "More..." hyperlink
line.gsub!(/More.../,"")
# ? ad hoc
line.gsub!(/^\.TP/,"")
+
#headers
- line.gsub!(/^\\fBReturn value:\\fP/,"\n.SH RETURNS\n.PP")
- line.gsub!(/^\\fBSee Also:\\fP/,"\n.SH \"SEE ALSO\"\n.PP")
+ if line =~ /Return\svalue:/
+ returndescribed = true
+ end
+ line.gsub!(/^\\fBReturn value:\\fP/,"\n.SH RETURN VALUE\n.PP")
+ line.gsub!(/^\\fBReturn value:\s\\fP/,"\n.SH RETURN VALUE\n.PP")
+ if line =~ /Errors:/
+ errordescribed = true
+ end
line.gsub!(/^\\fBErrors:\\fP/,"\n.SH ERRORS\n.PP")
+ line.gsub!(/^\\fBSee Also:\\fP/,"\n.SH \"SEE ALSO\"\n.PP")
+# line.gsub!(/^\\fBSee Also:/,"\n.SH \"SEE ALSO\"\n.PP\n\\fB")
+ line.gsub!(/^\\fBExample:\\fP/,"\n.SH Example:\n.PP\n")
- line.gsub!(/^\\fB(.+)\\fP/){"\n.SS " << $1}
+ #test 2008/3/4 is there other headers? line.gsub!(/^\\fB(.+)[^\)]\\fP/){"\n.SS " << $1}
+ # [^\)] in the pattern is added to avoid the first function in see also section.
#removing indentation
if text[i - 1] =~ /^.PP/
}
+unless returndescribed == true
+ print (" return not described \n")
+end
+unless errordescribed == true
+ print (" errors not described \n")
+end
+
return text
end
end end end
text.each_with_index{|line,i|
- line.gsub!(/More.../,"")
+
+ ### changes the type of list, and indentation
+ # if line =~ /^.IP/
+ # line = ".TP"
+ # text[i+2] = ""
+ # end
+
+ # if line =~ /^.TP/
+ # text[i+2] = ""
+ # end
# let the library name appear in the header
if line =~ /^.TH/
- line = line.gsub!("\" \"", "\" \"\" \"")
+ line = line.gsub!(/\" \"/, "\" \"\" \"")
end
# finding structure documentations and merging into "structures"
end
#removing extra "-"
- if text[i - 1] =~ /^.SH\sNAME/
- if line =~ /\\-/
- unless line =~ /\\-\s./
- line.chop!.chop!.chop!.chop!
- end
- end
- end
-
+# if text[i - 1] =~ /^.SH\sNAME/
+# if line =~ /\\-/
+# unless line =~ /\\-\s./
+# line.chop!.chop!.chop!.chop!
+# end
+# end
+# end
+
+ if text[i-2] =~ /^.SH\sNAME/ && text[i] =~ /^.PP/ && text[i+1] =~ /./
+ # Convert this line sequence:
+ # .SH NAME
+ # M-text \-
+ # .PP
+ # M-text objects and API for them.
+ # to:
+ # .SH NAME
+ # M-text \- M-text objects and API for them.
+ prevline = buf.pop
+ text[i+1] = prevline.chop!.concat(text[i+1])
+ else
#removing author section
line.gsub!(/^\.SH\s\"AUTHOR\"/,"")
- line.gsub!("Generated automatically by Doxygen for m17n_test from the source code.","")
+ line.gsub!(/Generated automatically by Doxygen for m17n_test from the source code\./,"")
+
+ line.gsub!(/^\\fBSee Also:\\fP/,"\n\\fBSEE ALSO\\fp\n")
+ line.gsub!(/^\\fBReturn value:\\fP/,"\n\\fBRETURN VALUE\\fp\n")
+ line.gsub!(/More.../,"")
line.gsub!(/\\fP\s+,/,"\\fP,")
line.gsub!(/\\fP\s+\./,"\\fP.")
line.gsub!(/\\fC\\fB(\w+)\\fP\\fP/){"\\fB" << $1 << "\\fP"}
-
buf.push(line)
+ end
}
unless structures == ["\.SH \"Data Structure Documentation\"\n"]
Dir.mkdir $doxywork unless FileTest.directory? $doxywork
-Dir.chdir($srcman3)
+Dir.chdir($srcdir)
Dir.open(".").each{|filename|
+
if FileTest.directory? filename
next
end
- if filename =~ /\.c\./
+ if filename =~ /\.[ch]\./
next
end
+ if filename =~ /\.txt\./
+ next
+ end
+
+ print "RUBY DIVIDING: ", filename, "\n"
+
file = open(filename,"r")
text = file.readlines
title = text[0]
short_text = text[sfunctionstart .. text.size - 1]
end
- if lfunctionstart = text.index(text.find{|i| i == $fdheader})
- if lfunctionend = text.index(text[lfunctionstart+1 .. text.size].find{|i| i =~ /^\.SH/})
+ if lfunctionstart = text.index(text.find{|i| i == $fdheader})
+ if lfunctionend = text.index(text[lfunctionstart+1 .. text.size].find{|i| i =~ /^\.SH/})
func_text = text[lfunctionstart .. lfunctionend - 1]
group_text = text[0 .. lfunctionstart - 1] + text[lfunctionend ..text.size]
- else
+ else
func_text = text[lfunctionstart .. text.size]
group_text = text[0 .. lfunctionstart - 1]
- end
+ end
else
func_text = []
group_text = text
- end
+ end
+
+ residue = documentfunc(title, func_text, short_text)
- documentfunc(title, func_text, short_text)
+ if residue == []
+ else
+ group_text = group_text + [".SH \"Function Documentation\"\n.PP\n"] + residue
+ end
else
#############################rewriting files
-Dir.chdir($dstman3m)
+Dir.chdir($dstdir)
Dir.open(".").each{|f| File.delete(f) if FileTest.file?(f)}
Dir.open(".").each{|filename|
unless FileTest.directory? filename
- print "PROCESSING: ", filename, "\n"
+ file = open(filename,"r")
+ text = file.readlines
- file = open(filename,"r")
- text = file.readlines
+ if text.include?($fielddheader)
+ next
+ end
- if /@function/ =~ text[0]
- buf = frewrite(text[1..text.size])
- else buf = orewrite(text)
- end
+ print "RUBY REWRINTING: ", filename, "\n"
- filetowrite = open($dstman3m+filename,"w")
- filetowrite.puts(buf)
- filetowrite.flush
+ if /@function/ =~ text[0]
+ buf = frewrite(text[1..text.size])
+ else buf = orewrite(text)
+ end
+ filetowrite = open($dstdir+filename,"w")
+ filetowrite.puts(headbuf)
+ filetowrite.puts(buf)
+ filetowrite.puts(footbuf)
+ filetowrite.flush
end
}
-
-Dir.chdir($doxywork)
-
-#Dir.open(".").each{|f| File.delete(f) if FileTest.file?(f)}