fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / libjava / scripts / TexinfoDoclet.java
blobaadc21786f342b9bc3fc7c55ed621ba5adb9982e
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
7 details. */
9 import java.io.*;
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"))
19 return 2;
20 return 0;
23 private static String replace (String s, String text, String replacement)
25 int i = s.indexOf (text);
26 while (i != -1)
28 s = s.substring(0, i) + replacement + s.substring(i+text.length());
29 i = s.indexOf (text);
32 return s;
35 private static String texify (String s)
37 if (s.indexOf('<') == -1)
38 return s;
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");
60 return s;
63 private static void emitMethod (ClassDoc c, MethodDoc m)
65 outfile.print ("@deftypemethod " + c.typeName()
66 + " {" + m.modifiers()
67 + " " + m.returnType().typeName()
68 + "} " + m.name());
70 outfile.print (" (");
71 Parameter p[] = m.parameters();
72 boolean first = true;
74 for (int i = 0; i < p.length; i++)
76 if (!first)
77 outfile.print (", ");
78 outfile.print (p[i].typeName()
79 + "@w{ }@var{"
80 + p[i].name()
81 + "}");
82 first = false;
84 outfile.print (") ");
86 ClassDoc exceptions[] = m.thrownExceptions();
87 if (exceptions.length > 0)
89 outfile.print ("@*throws ");
90 first = true;
91 for (int i = 0; i < exceptions.length; i++)
93 if (!first)
94 outfile.print (", ");
95 outfile.print (exceptions[i].typeName());
96 first = false;
99 outfile.println ("");
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++)
121 try
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]);
129 return false;
133 ClassDoc[] classes = root.classes();
134 for (int i = 0; i < classes.length; i++)
136 emitClass (classes[i]);
138 return true;