*** empty log message ***
[m17n/m17n-docs.git] / utils / mkman.rb
index 78b857f..8ee755f 100644 (file)
@@ -1,5 +1,5 @@
 #! /usr/local/bin/ruby
-# Usage: mkman.rb SRCDIR DSTDIR
+# Usage: mkman.rb SRCDIR DSTDIR                        -*- coding: euc-jp; -*-
 
 #¼Â¹Ô¤¹¤ë¤È/tmp/doxyman¤ò¤Ä¤«¤Ã¤Æ¥Õ¥¡¥¤¥ë¤òʬ¤±¡¢
 #¤â¤È¤Îdirectory¤Ë¤«¤­¤Ê¤ª¤¹¡£
@@ -16,9 +16,14 @@ $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.
@@ -221,8 +226,8 @@ def frewrite(text)
   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/} 
@@ -268,8 +273,9 @@ def desrewrite(text)
 
   text.each_with_index{|line,i|
 
-### TEST 6/24
-  line.gsub!(/^\.RS 4/,"")
+### TEST 2008/3/3
+  line.gsub!(/\.RS 4/,"\n.RS 4")
+#  line.gsub!(/^\.RE/,"")
 
 ### letting verbatim end in place Part2
   if line =~ /^\.nf/
@@ -294,13 +300,16 @@ def desrewrite(text)
      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
@@ -370,21 +379,16 @@ def orewrite(text)
   end  end  end
 
   text.each_with_index{|line,i|
-             line.gsub!(/More.../,"")
-     
-     ### 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
+     ###  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
+    #    if line =~ /^.TP/
+    #     text[i+2] = ""
+    #     end
 
      # let the library name appear in the header 
               if line =~ /^.TH/
@@ -404,23 +408,39 @@ def orewrite(text)
              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!(/^\\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"]
@@ -442,62 +462,66 @@ Dir.mkdir $doxywork unless FileTest.directory? $doxywork
 Dir.chdir($srcdir)
 
 Dir.open(".").each{|filename|
-
-     if FileTest.directory? filename 
-       next
-     end   
-
-     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]
-
-   if
-      sfunctionstart = text.index(text.find{|i| i == $flheader})
-        if sfunctionend = text.index(text[sfunctionstart+1 .. text.size].find{|i| i =~ /^\.SS|^\.SH/})
+  
+  if FileTest.directory? filename 
+    next
+  end   
+  
+  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]
+  
+  if filename =~ /m17nExProg.1/
+    next
+  else
+    
+    if sfunctionstart = text.index(text.find{|i| i == $flheader})
+      if sfunctionend = text.index(text[sfunctionstart+1 .. text.size].find{|i| i =~ /^\.SS|^\.SH/})
         short_text = text[sfunctionstart .. sfunctionend - 1] 
-       else
+      else
         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/})
-         func_text = text[lfunctionstart .. lfunctionend - 1] 
-         group_text = text[0 .. lfunctionstart - 1] + text[lfunctionend ..text.size]
+      end
+      
+      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 
-         func_text = text[lfunctionstart .. text.size]
-         group_text = text[0 .. lfunctionstart - 1]
-       end
+          func_text = text[lfunctionstart .. text.size]
+          group_text = text[0 .. lfunctionstart - 1]
+        end
       else 
-       func_text = [] 
-       group_text = text  
+        func_text = [] 
+        group_text = text  
+      end
+      
+      residue = documentfunc(title, func_text, short_text)
+      
+      if residue == []
+      else 
+        group_text = group_text + [".SH \"Function Documentation\"\n.PP\n"] + residue
+      end
+      
+    else
+      
+      group_text = text
+      
     end
 
-  residue = documentfunc(title, func_text, short_text)
-
-  if residue == []
-     else 
-     group_text = group_text + [".SH \"Function Documentation\"\n.PP\n"] + residue
-  end
-
-  else
-  
-  group_text = text
-  
+    filetowrite = open($doxywork+filename,"w")
+    filetowrite.puts(group_text)
+    filetowrite.flush
   end
-   
-  filetowrite = open($doxywork+filename,"w")
-  filetowrite.puts(group_text)
-  filetowrite.flush
 }
 
 #############################rewriting files
@@ -528,6 +552,7 @@ unless FileTest.directory? filename
      filetowrite = open($dstdir+filename,"w")
      filetowrite.puts(headbuf)
      filetowrite.puts(buf)
+     filetowrite.puts(footbuf)
      filetowrite.flush
 end
 }