X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=utils%2Fmkman.rb;h=adcaf187a7f996dd0e87a5d4f6f72dc997f4f370;hb=6632c8a83d59ae2330184680bbade4810f25749a;hp=5cf667dd307d39dcf92d4571a77bd8d82e5a014a;hpb=b5bb3d2f3ead81781c9918cb9267d7885a35fefd;p=m17n%2Fm17n-docs.git diff --git a/utils/mkman.rb b/utils/mkman.rb index 5cf667d..adcaf18 100644 --- a/utils/mkman.rb +++ b/utils/mkman.rb @@ -1,25 +1,23 @@ #! /usr/local/bin/ruby +# Usage: mkman.rb SRCDIR DSTDIR + #¼Â¹Ô¤¹¤ë¤È/tmp/doxyman¤ò¤Ä¤«¤Ã¤Æ¥Õ¥¡¥¤¥ë¤òʬ¤±¡¢ #¤â¤È¤Îdirectory¤Ë¤«¤­¤Ê¤ª¤¹¡£ # see also ¤ÎÃæ¿È¤ò woman ¸þ¤±¤Ë½ñ¤­´¹¤¨¤ë¡£ -usr_or_ja=$*[0] +$manext="."+$*[0] # # Setting up directory names. # $currentdir = Dir.pwd+"/" +$srcdir=$currentdir+$*[1]+"/" +$dstdir=$currentdir+$*[2]+"/" $doxywork = $currentdir+"doxywork/" -$srcman3 = $currentdir+usr_or_ja+"/man/man3/" -if usr_or_ja == "usr" - $dstman3m = $currentdir+"/usr/man3m/" -else - $dstman3m = $currentdir+"/ja/man3m/" -end $sampledir="sample/man3/" - $headfile = $currentdir+"manhead" + headbuf = open($headfile, "r").readlines # @@ -87,7 +85,7 @@ def writedocumentation(buf, text, index) def datastructure(struct) - text = open(struct.concat(".3m"),"r").readlines + text = open(struct.concat($manext),"r").readlines buf = [] @@ -156,23 +154,36 @@ end def documentfunc(title, func_text, short_text) 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 +# print " Cannot find short desc for " +# print ffname + end + end + } +end - dstart =~ /\s([a-z0-9_]+)\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 @@ -187,20 +198,22 @@ def documentfunc2 (dstart, title, func_text, short_text) 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 @@ -212,16 +225,16 @@ def frewrite(text) 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 - descriptiontext = womanrewrite(desrewrite(description)) - buf.push("\n.SH DESCRIPTION\n").push(descriptiontext) - 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 @@ -249,20 +262,32 @@ def desrewrite(text) 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 6/24 - line.gsub!(".RS 4","") + line.gsub!(/^\.RS 4/,"") -### letting verbatim end in place - line.gsub!(/^.nf/,".NF") +### 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 if line =~ /Return\svalue:/ returndescribed = true @@ -349,9 +374,20 @@ def orewrite(text) ### let verbatim end in place line.gsub!(/^.nf/,".NF") + ### test1/16/2004 changes the type of list, and indentation + if line =~ /^.IP/ + line = ".TP" + text[i+2] = "" + end + + if line =~ /^.TP/ + text[i+2] = "" + end + ### end of test1/20/2004 + # 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" @@ -377,7 +413,7 @@ def orewrite(text) #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!(/\\fP\s+,/,"\\fP,") line.gsub!(/\\fP\s+\./,"\\fP.") @@ -402,7 +438,7 @@ end Dir.mkdir $doxywork unless FileTest.directory? $doxywork -Dir.chdir($srcman3) +Dir.chdir($srcdir) Dir.open(".").each{|filename| @@ -410,9 +446,15 @@ Dir.open(".").each{|filename| next end - #if filename =~ /\.c\./ - # next - #end + if filename =~ /\.[ch]\./ + next + end + + if filename =~ /\.txt\./ + next + end + + print "RUBY DIVIDING: ", filename, "\n" file = open(filename,"r") text = file.readlines @@ -439,8 +481,7 @@ Dir.open(".").each{|filename| group_text = text end - documentfunc(title, func_text, short_text) - + documentfunc(title, func_text, short_text) else group_text = text @@ -454,7 +495,7 @@ Dir.open(".").each{|filename| #############################rewriting files -Dir.chdir($dstman3m) +Dir.chdir($dstdir) Dir.open(".").each{|f| File.delete(f) if FileTest.file?(f)} @@ -470,14 +511,14 @@ unless FileTest.directory? filename next end - print "PROCESSING: ", filename, "\n" + print "RUBY REWRINTING: ", filename, "\n" if /@function/ =~ text[0] buf = frewrite(text[1..text.size]) else buf = orewrite(text) end - filetowrite = open($dstman3m+filename,"w") + filetowrite = open($dstdir+filename,"w") filetowrite.puts(headbuf) filetowrite.puts(buf) filetowrite.flush