1 /* Copyright (C) 2001 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
10 import com.sun.javadoc.*;
12 public class TexinfoDoclet
14 static PrintStream outfile;
16 public static int optionLength(String option)
18 if (option.equals("-outfile"))
23 private static String replace (String s, String text, String replacement)
25 int i = s.indexOf (text);
28 s = s.substring(0, i) + replacement + s.substring(i+text.length());
35 private static String texify (String s)
37 if (s.indexOf('<') == -1)
40 s = replace (s, "<code>", "@code{");
41 s = replace (s, "</code>", "}");
42 s = replace (s, "<ol>", "\n@itemize @bullet\n");
43 s = replace (s, "</ol>", "\n@end itemize\n");
44 s = replace (s, "<ul>", "\n@itemize @bullet\n");
45 s = replace (s, "</ul>", "\n@end itemize\n");
46 s = replace (s, "<li>", "\n@item\n");
47 s = replace (s, "</li>", "\n");
48 s = replace (s, "<p>", "\n\n");
50 s = replace (s, "<CODE>", "@code{");
51 s = replace (s, "</CODE>", "}");
52 s = replace (s, "<OL>", "\n@itemize @bullet\n");
53 s = replace (s, "</OL>", "\n@end itemize\n");
54 s = replace (s, "<UL>", "\n@itemize @bullet\n");
55 s = replace (s, "</UL>", "\n@end itemize\n");
56 s = replace (s, "<LI>", "\n@item\n");
57 s = replace (s, "</LI>", "\n");
58 s = replace (s, "<P>", "\n\n");
63 private static void emitMethod (ClassDoc c, MethodDoc m)
65 outfile.print ("@deftypemethod " + c.typeName()
66 + " {" + m.modifiers()
67 + " " + m.returnType().typeName()
71 Parameter p[] = m.parameters();
74 for (int i = 0; i < p.length; i++)
78 outfile.print (p[i].typeName()
86 ClassDoc exceptions[] = m.thrownExceptions();
87 if (exceptions.length > 0)
89 outfile.print ("@*throws ");
91 for (int i = 0; i < exceptions.length; i++)
95 outfile.print (exceptions[i].typeName());
101 outfile.println (texify (m.commentText()));
103 outfile.println ("@end deftypemethod");
106 private static void emitClass (ClassDoc c)
108 MethodDoc[] methods = c.methods();
109 for (int i = 0; i < methods.length; i++)
111 emitMethod (c, methods[i]);
115 public static boolean start (RootDoc root)
117 String options[][] = root.options ();
119 for (int i = 0; i < options.length; i++)
123 if (options[i][0].equals ("-outfile"))
125 outfile = new PrintStream (new FileOutputStream (options[i][1]));
127 } catch (java.io.IOException e) {
128 System.err.println ("Can't write to file " + options[i][1]);
133 ClassDoc[] classes = root.classes();
134 for (int i = 0; i < classes.length; i++)
136 emitClass (classes[i]);