Patch: generate texinfo documentation

Anthony Green green@cygnus.com
Sun Jan 7 16:22:00 GMT 2001


Here's a patch for generating texinfo documentation from our javadoc
sources.  It depends on Sun's javac and javadoc tools for now.  Tom
pointed out that classpath appears to have javadoc tool - so perhaps
we could switch to that sometime.

The texinfo conversion is not complete yet, but in the spirit of
release early, release often...

No effort was made to make the conversion process fast.  

I'm going to check this in as well as the texinfo files as they appear
right now.


2001-01-07  Anthony Green  <green@redhat.com>

	* Makefile.am (texinfo): Add texinfo target for generating texinfo
	documentation.
        * Makefile.in: Rebuilt.

        * scripts/TexinfoDoclet.java: New file.

Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.122
diff -c -u -r1.122 Makefile.am
--- Makefile.am	2000/12/30 12:22:15	1.122
+++ Makefile.am	2001/01/08 00:08:26
@@ -135,7 +135,7 @@
 	$(c_source_files) $(java_source_files) $(built_java_source_files)
 libgcj_la_DEPENDENCIES = libgcj.jar $(javao_files) \
 	$(c_files) $(GCOBJS) $(THREADOBJS) $(LIBLTDL)
-	
+
 # Include THREADLIBS here to ensure that the correct version of
 # certain linuxthread functions get linked:
 libgcj_la_LIBADD = $(javao_files) $(c_files) $(GCOBJS) \
@@ -1319,6 +1319,44 @@
 gnu/gcj/xlib/natXExposeEvent.cc \
 gnu/gcj/xlib/natXImage.cc \
 gnu/gcj/xlib/natXUnmapEvent.cc
+
+## ################################################################
+
+##
+## javadoc to texinfo conversion
+##
+
+TexinfoDoclet.class: $(srcdir)/scripts/TexinfoDoclet.java
+	javac -d . $(srcdir)/scripts/TexinfoDoclet.java
+
+texinfo: TexinfoDoclet.class
+	langsource=`ls $(srcdir)/java/lang/*.java`; \
+	lang=`echo $$langsource | sed -e 's/[^ ].*EcosProcess.java//g' | sed -e 's/[^ ].*PosixProcess.java//g'`; \
+	javadoc -outfile $(srcdir)/doc/java-lang.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $$lang
+	javadoc -outfile $(srcdir)/doc/java-lang-ref.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/lang/ref/*.java
+	javadoc -outfile $(srcdir)/doc/java-lang-reflect.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/lang/reflect/*.java
+	javadoc -outfile $(srcdir)/doc/java-applet.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/applet/*.java
+	javadoc -outfile $(srcdir)/doc/java-awt.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/awt/*.java
+	javadoc -outfile $(srcdir)/doc/java-awt-color.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/awt/color/*.java
+	javadoc -outfile $(srcdir)/doc/java-awt-datatransfer.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/awt/datatransfer/*.java
+	javadoc -outfile $(srcdir)/doc/java-awt-event.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/awt/event/*.java
+	javadoc -outfile $(srcdir)/doc/java-awt-geom.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/awt/geom/*.java
+	javadoc -outfile $(srcdir)/doc/java-awt-image.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/awt/image/*.java
+	javadoc -outfile $(srcdir)/doc/java-awt-peer.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/awt/peer/*.java
+	javadoc -outfile $(srcdir)/doc/java-beans.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/beans/*.java
+	javadoc -outfile $(srcdir)/doc/java-beans-beancontext.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/beans/beancontext/*.java
+	javadoc -outfile $(srcdir)/doc/java-io.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/io/*.java
+	javadoc -outfile $(srcdir)/doc/java-math.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/math/*.java
+	javadoc -outfile $(srcdir)/doc/java-net.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/net/*.java
+	javadoc -outfile $(srcdir)/doc/java-security.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/security/*.java
+	javadoc -outfile $(srcdir)/doc/java-security-cert.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/security-cert/*.java
+	javadoc -outfile $(srcdir)/doc/java-security-spec.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/security/spec/*.java
+	javadoc -outfile $(srcdir)/doc/java-security-interfaces.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/security/spec/interfaces/*.java
+	javadoc -outfile $(srcdir)/doc/java-sql.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/sql/*.java
+	javadoc -outfile $(srcdir)/doc/java-text.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/text/*.java
+	javadoc -outfile $(srcdir)/doc/java-util.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/util/*.java
+	javadoc -outfile $(srcdir)/doc/java-util-jar.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/util/jar/*.java
+	javadoc -outfile $(srcdir)/doc/java-util-zip.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/util/zip/*.java
 
 ## ################################################################
 
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.in,v
retrieving revision 1.131
diff -c -u -r1.131 Makefile.in
--- Makefile.in	2000/12/30 12:22:15	1.131
+++ Makefile.in	2001/01/08 00:08:28
@@ -1198,7 +1198,7 @@
 
 DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
 
-TAR = tar
+TAR = gtar
 GZIP_ENV = --best
 DIST_SUBDIRS =  @DIRLTDL@ testsuite gcj include @DIRLTDL@ gcj include
 DEP_FILES =  .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
@@ -2493,6 +2493,38 @@
 
 @NATIVE_TRUE@@MAINTAINER_MODE_TRUE@$(srcdir)/$(CONVERT_DIR)/Unicode_to_JIS.cc: ./gen-from-JIS$(EXEEXT)
 @NATIVE_TRUE@@MAINTAINER_MODE_TRUE@	 ./gen-from-JIS toJIS>$(srcdir)/$(CONVERT_DIR)/Unicode_to_JIS.cc
+
+TexinfoDoclet.class: $(srcdir)/scripts/TexinfoDoclet.java
+	javac -d . $(srcdir)/scripts/TexinfoDoclet.java
+
+texinfo: TexinfoDoclet.class
+	langsource=`ls $(srcdir)/java/lang/*.java`; \
+	lang=`echo $$langsource | sed -e 's/[^ ].*EcosProcess.java//g' | sed -e 's/[^ ].*PosixProcess.java//g'`; \
+	javadoc -outfile $(srcdir)/doc/java-lang.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $$lang
+	javadoc -outfile $(srcdir)/doc/java-lang-ref.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/lang/ref/*.java
+	javadoc -outfile $(srcdir)/doc/java-lang-reflect.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/lang/reflect/*.java
+	javadoc -outfile $(srcdir)/doc/java-applet.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/applet/*.java
+	javadoc -outfile $(srcdir)/doc/java-awt.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/awt/*.java
+	javadoc -outfile $(srcdir)/doc/java-awt-color.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/awt/color/*.java
+	javadoc -outfile $(srcdir)/doc/java-awt-datatransfer.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/awt/datatransfer/*.java
+	javadoc -outfile $(srcdir)/doc/java-awt-event.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/awt/event/*.java
+	javadoc -outfile $(srcdir)/doc/java-awt-geom.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/awt/geom/*.java
+	javadoc -outfile $(srcdir)/doc/java-awt-image.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/awt/image/*.java
+	javadoc -outfile $(srcdir)/doc/java-awt-peer.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/awt/peer/*.java
+	javadoc -outfile $(srcdir)/doc/java-beans.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/beans/*.java
+	javadoc -outfile $(srcdir)/doc/java-beans-beancontext.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/beans/beancontext/*.java
+	javadoc -outfile $(srcdir)/doc/java-io.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/io/*.java
+	javadoc -outfile $(srcdir)/doc/java-math.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/math/*.java
+	javadoc -outfile $(srcdir)/doc/java-net.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/net/*.java
+	javadoc -outfile $(srcdir)/doc/java-security.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/security/*.java
+	javadoc -outfile $(srcdir)/doc/java-security-cert.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/security-cert/*.java
+	javadoc -outfile $(srcdir)/doc/java-security-spec.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/security/spec/*.java
+	javadoc -outfile $(srcdir)/doc/java-security-interfaces.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/security/spec/interfaces/*.java
+	javadoc -outfile $(srcdir)/doc/java-sql.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/sql/*.java
+	javadoc -outfile $(srcdir)/doc/java-text.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/text/*.java
+	javadoc -outfile $(srcdir)/doc/java-util.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/util/*.java
+	javadoc -outfile $(srcdir)/doc/java-util-jar.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/util/jar/*.java
+	javadoc -outfile $(srcdir)/doc/java-util-zip.texi -doclet TexinfoDoclet -sourcepath .:$(srcdir) $(srcdir)/java/util/zip/*.java
 
 -include deps.mk
 
Index: scripts/TexinfoDoclet.java
===================================================================
RCS file: TexinfoDoclet.java
diff -N TexinfoDoclet.java
--- /dev/null	Tue May  5 13:32:27 1998
+++ TexinfoDoclet.java	Sun Jan  7 16:08:28 2001
@@ -0,0 +1,140 @@
+/* Copyright (C) 2001  Free Software Foundation
+
+   This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
+details.  */
+
+import java.io.*;
+import com.sun.javadoc.*;
+
+public class TexinfoDoclet
+{
+  static PrintStream outfile;
+  
+  public static int optionLength(String option) 
+  {
+    if (option.equals("-outfile")) 
+      return 2;
+    return 0;
+  }
+
+  private static String replace (String s, String text, String replacement)
+  {
+    int i = s.indexOf (text);
+    while (i != -1)
+      {
+	s = s.substring(0, i) + replacement + s.substring(i+text.length());
+	i = s.indexOf (text);
+      }
+    
+    return s;
+  }
+  
+  private static String texify (String s)
+  {
+    if (s.indexOf('<') == -1)
+      return s;
+    
+    s = replace (s, "<code>", "@code{");
+    s = replace (s, "</code>", "}");
+    s = replace (s, "<ol>", "\n@itemize @bullet\n");
+    s = replace (s, "</ol>", "\n@end itemize\n");
+    s = replace (s, "<ul>", "\n@itemize @bullet\n");
+    s = replace (s, "</ul>", "\n@end itemize\n");
+    s = replace (s, "<li>", "\n@item\n");
+    s = replace (s, "</li>", "\n");
+    s = replace (s, "<p>", "\n\n");
+    
+    s = replace (s, "<CODE>", "@code{");
+    s = replace (s, "</CODE>", "}");
+    s = replace (s, "<OL>", "\n@itemize @bullet\n");
+    s = replace (s, "</OL>", "\n@end itemize\n");
+    s = replace (s, "<UL>", "\n@itemize @bullet\n");
+    s = replace (s, "</UL>", "\n@end itemize\n");
+    s = replace (s, "<LI>", "\n@item\n");
+    s = replace (s, "</LI>", "\n");
+    s = replace (s, "<P>", "\n\n");
+    
+    return s;
+  }
+  
+  private static void emitMethod (ClassDoc c, MethodDoc m)
+  {
+    outfile.print ("@deftypemethod " + c.typeName()
+		   + " {" + m.modifiers()
+		   + " " + m.returnType().typeName()
+		   + "} " + m.name());
+    
+    outfile.print (" (");
+    Parameter p[] = m.parameters();
+    boolean first = true;
+    
+    for (int i = 0; i < p.length; i++)
+      {
+	if (!first)
+	  outfile.print (", ");
+	outfile.print (p[i].typeName() 
+		       + "@w{ }@var{"
+		       + p[i].name()
+		       + "}");
+	first = false;
+      }
+    outfile.print (") ");
+    
+    ClassDoc exceptions[] = m.thrownExceptions();
+    if (exceptions.length > 0)
+      {
+	outfile.print ("@*throws ");
+	first = true;
+	for (int i = 0; i < exceptions.length; i++)
+	  {
+	    if (!first)
+	      outfile.print (", ");
+	    outfile.print (exceptions[i].typeName());
+	    first = false;
+	  }
+      }
+    outfile.println ("");
+    
+    outfile.println (texify (m.commentText()));
+    
+    outfile.println ("@end deftypemethod");
+  }
+  
+  private static void emitClass (ClassDoc c)
+  {
+    MethodDoc[] methods = c.methods();
+    for (int i = 0; i < methods.length; i++)
+      {
+	emitMethod (c, methods[i]);
+      }
+  }
+  
+  public static boolean start (RootDoc root)
+  {
+    String options[][] = root.options ();
+    
+    for (int i = 0; i < options.length; i++)
+      {
+	try 
+	  {
+	    if (options[i][0].equals ("-outfile"))
+	      {
+		outfile = new PrintStream (new FileOutputStream (options[i][1]));
+	      }
+	  } catch (java.io.IOException e) {
+	    System.err.println ("Can't write to file " + options[i][1]);
+	    return false;
+	  }
+      }
+    
+    ClassDoc[] classes = root.classes();
+    for (int i = 0; i < classes.length; i++)
+      {
+	emitClass (classes[i]);
+      }
+    return true;
+  }
+}


More information about the Java-patches mailing list