*** empty log message ***
[m17n/m17n-docs.git] / utils / mkman.rb
index b136889..33b9fc7 100644 (file)
@@ -1,5 +1,5 @@
 #! /usr/local/bin/ruby
-# Usage: mkman.rb SRCDIR DSTDIR
+# Usage: mkman.rb SRCDIR DSTDIR                        -*- coding: euc-japan; -*-
 
 #¼Â¹Ô¤¹¤ë¤È/tmp/doxyman¤ò¤Ä¤«¤Ã¤Æ¥Õ¥¡¥¤¥ë¤òʬ¤±¡¢
 #¤â¤È¤Îdirectory¤Ë¤«¤­¤Ê¤ª¤¹¡£
@@ -153,22 +153,36 @@ 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-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+$manext, "w")
    file.puts("@function")
@@ -185,18 +199,20 @@ 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!(/\" \"/, "\" \"\" \"")]
 
@@ -210,16 +226,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
 
@@ -439,6 +455,8 @@ Dir.open(".").each{|filename|
         next
      end   
 
+     print "RUBY DIVIDING: ", filename, "\n"
+
      file = open(filename,"r") 
      text = file.readlines
      title = text[0]
@@ -451,20 +469,25 @@ Dir.open(".").each{|filename|
         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
   
@@ -495,7 +518,7 @@ 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])