| 1 | /* Copyright (C) 2001  Free Software Foundation | 
|---|
| 2 |  | 
|---|
| 3 | This file is part of libgcj. | 
|---|
| 4 |  | 
|---|
| 5 | This software is copyrighted work licensed under the terms of the | 
|---|
| 6 | Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for | 
|---|
| 7 | details.  */ | 
|---|
| 8 |  | 
|---|
| 9 | import java.io.*; | 
|---|
| 10 | import com.sun.javadoc.*; | 
|---|
| 11 |  | 
|---|
| 12 | public class TexinfoDoclet | 
|---|
| 13 | { | 
|---|
| 14 | static PrintStream outfile; | 
|---|
| 15 |  | 
|---|
| 16 | public static int optionLength(String option) | 
|---|
| 17 | { | 
|---|
| 18 | if (option.equals("-outfile")) | 
|---|
| 19 | return 2; | 
|---|
| 20 | return 0; | 
|---|
| 21 | } | 
|---|
| 22 |  | 
|---|
| 23 | private static String replace (String s, String text, String replacement) | 
|---|
| 24 | { | 
|---|
| 25 | int i = s.indexOf (text); | 
|---|
| 26 | while (i != -1) | 
|---|
| 27 | { | 
|---|
| 28 | s = s.substring(0, i) + replacement + s.substring(i+text.length()); | 
|---|
| 29 | i = s.indexOf (text); | 
|---|
| 30 | } | 
|---|
| 31 |  | 
|---|
| 32 | return s; | 
|---|
| 33 | } | 
|---|
| 34 |  | 
|---|
| 35 | private static String texify (String s) | 
|---|
| 36 | { | 
|---|
| 37 | if (s.indexOf('<') == -1) | 
|---|
| 38 | return s; | 
|---|
| 39 |  | 
|---|
| 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"); | 
|---|
| 49 |  | 
|---|
| 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"); | 
|---|
| 59 |  | 
|---|
| 60 | return s; | 
|---|
| 61 | } | 
|---|
| 62 |  | 
|---|
| 63 | private static void emitMethod (ClassDoc c, MethodDoc m) | 
|---|
| 64 | { | 
|---|
| 65 | outfile.print ("@deftypemethod " + c.typeName() | 
|---|
| 66 | + " {" + m.modifiers() | 
|---|
| 67 | + " " + m.returnType().typeName() | 
|---|
| 68 | + "} " + m.name()); | 
|---|
| 69 |  | 
|---|
| 70 | outfile.print (" ("); | 
|---|
| 71 | Parameter p[] = m.parameters(); | 
|---|
| 72 | boolean first = true; | 
|---|
| 73 |  | 
|---|
| 74 | for (int i = 0; i < p.length; i++) | 
|---|
| 75 | { | 
|---|
| 76 | if (!first) | 
|---|
| 77 | outfile.print (", "); | 
|---|
| 78 | outfile.print (p[i].typeName() | 
|---|
| 79 | + "@w{ }@var{" | 
|---|
| 80 | + p[i].name() | 
|---|
| 81 | + "}"); | 
|---|
| 82 | first = false; | 
|---|
| 83 | } | 
|---|
| 84 | outfile.print (") "); | 
|---|
| 85 |  | 
|---|
| 86 | ClassDoc exceptions[] = m.thrownExceptions(); | 
|---|
| 87 | if (exceptions.length > 0) | 
|---|
| 88 | { | 
|---|
| 89 | outfile.print ("@*throws "); | 
|---|
| 90 | first = true; | 
|---|
| 91 | for (int i = 0; i < exceptions.length; i++) | 
|---|
| 92 | { | 
|---|
| 93 | if (!first) | 
|---|
| 94 | outfile.print (", "); | 
|---|
| 95 | outfile.print (exceptions[i].typeName()); | 
|---|
| 96 | first = false; | 
|---|
| 97 | } | 
|---|
| 98 | } | 
|---|
| 99 | outfile.println (""); | 
|---|
| 100 |  | 
|---|
| 101 | outfile.println (texify (m.commentText())); | 
|---|
| 102 |  | 
|---|
| 103 | outfile.println ("@end deftypemethod"); | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | private static void emitClass (ClassDoc c) | 
|---|
| 107 | { | 
|---|
| 108 | MethodDoc[] methods = c.methods(); | 
|---|
| 109 | for (int i = 0; i < methods.length; i++) | 
|---|
| 110 | { | 
|---|
| 111 | emitMethod (c, methods[i]); | 
|---|
| 112 | } | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|
| 115 | public static boolean start (RootDoc root) | 
|---|
| 116 | { | 
|---|
| 117 | String options[][] = root.options (); | 
|---|
| 118 |  | 
|---|
| 119 | for (int i = 0; i < options.length; i++) | 
|---|
| 120 | { | 
|---|
| 121 | try | 
|---|
| 122 | { | 
|---|
| 123 | if (options[i][0].equals ("-outfile")) | 
|---|
| 124 | { | 
|---|
| 125 | outfile = new PrintStream (new FileOutputStream (options[i][1])); | 
|---|
| 126 | } | 
|---|
| 127 | } catch (java.io.IOException e) { | 
|---|
| 128 | System.err.println ("Can't write to file " + options[i][1]); | 
|---|
| 129 | return false; | 
|---|
| 130 | } | 
|---|
| 131 | } | 
|---|
| 132 |  | 
|---|
| 133 | ClassDoc[] classes = root.classes(); | 
|---|
| 134 | for (int i = 0; i < classes.length; i++) | 
|---|
| 135 | { | 
|---|
| 136 | emitClass (classes[i]); | 
|---|
| 137 | } | 
|---|
| 138 | return true; | 
|---|
| 139 | } | 
|---|
| 140 | } | 
|---|