~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to libhover/org.eclipse.linuxtools.cdt.libhover.texinfoparsers/src/org/eclipse/linuxtools/cdt/libhover/texinfoparsers/ParseGlibcTexinfo.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2007 Red Hat Inc..
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 *     Red Hat Incorporated - initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.linuxtools.cdt.libhover.texinfoparsers;
 
12
import java.io.*;
 
13
import java.util.regex.*;
 
14
import java.util.*;
 
15
 
 
16
//This file contains a texinfo parser that can be
 
17
//run to create the Autotools glibc.xml file.
 
18
//Usage is as follows:
 
19
//1. compile this file using javac
 
20
//2. run this file using java, passing the
 
21
//arguments: ${glibc_source_path}/manual glibc.xml
 
22
 
 
23
public class ParseGlibcTexinfo {
 
24
        static final boolean DEBUG = false;
 
25
 
 
26
        //                           1
 
27
        static final String ATcmd = "(@\\w*)";
 
28
 
 
29
 
 
30
        //                              3   4
 
31
        static final String RtnTypeM = "(\\{([^\\}]*)\\})";
 
32
        static final int    RtnTypeMIndex = 4;
 
33
 
 
34
        //                              5
 
35
        static final String RtnTypeS = "(\\w*)";
 
36
        static final int    RtnTypeSIndex = 5;
 
37
 
 
38
        //                             2
 
39
        static final String RtnType = "(" + RtnTypeM + "|" + RtnTypeS + ")";
 
40
        //                                  6
 
41
        static final String FunctionName = "(\\w*)";
 
42
        static final int    FunctionNameIndex = 6;
 
43
 
 
44
        //                          7    8
 
45
        static final String Parms = "(\\((.*)\\))";
 
46
        static final int    ParmsIndex = 8;
 
47
 
 
48
        static final String rest = ".*";
 
49
 
 
50
        static final String WhiteSpace = "\\s*";
 
51
 
 
52
        static final Pattern DeftypefunPattern
 
53
        = Pattern.compile("^" + ATcmd + WhiteSpace +
 
54
                        RtnType + WhiteSpace +
 
55
                        FunctionName + WhiteSpace +
 
56
                        Parms +
 
57
                        rest, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE);
 
58
 
 
59
        static final String TPDataType = "\\{[^\\}]*\\}";
 
60
 
 
61
 
 
62
        //                             3   4
 
63
        static final String TPTypeM = "(\\{([^\\}]*)\\})";
 
64
        static final int    TPTypeMIndex = 4;
 
65
 
 
66
        //                             5
 
67
        static final String TPTypeS = "(\\w*)";
 
68
        static final int    TPTypeSIndex = 5;
 
69
 
 
70
        //                            2
 
71
        static final String TPType = "(" + TPTypeM + "|" + TPTypeS + ")";
 
72
 
 
73
        static final Pattern DeftpPattern
 
74
        = Pattern.compile("^" + ATcmd + WhiteSpace + TPDataType + WhiteSpace + TPType + rest,
 
75
                        Pattern.MULTILINE + Pattern.CASE_INSENSITIVE);
 
76
 
 
77
        static final Pattern IncludePattern             = Pattern.compile("^@comment ((\\w*/)*\\w*\\.h\\s*)*\\s*$");
 
78
        static final Pattern PindexPattern              = Pattern.compile("^@pindex\\s*\\w*\\s*$");
 
79
        static final Pattern ParmBracketPattern = Pattern.compile("\\((.*)\\)");
 
80
        static final Pattern IndexPattern               = Pattern.compile("@\\w*index\\s+[a-zA-Z0-9_@\\{\\}]*");
 
81
        static final Pattern IndexPattern2              = Pattern.compile("@\\w*index\\{[a-zA-Z0-9_@\\{\\}]*\\}");
 
82
        static final Pattern ExamplePattern             = Pattern.compile("@example");
 
83
        static final Pattern EndExamplePattern  = Pattern.compile("@end\\s+example");
 
84
        static final Pattern EnumeratePattern   = Pattern.compile("@enumerate");
 
85
        static final Pattern EndEnumeratePattern  = Pattern.compile("@end\\s+enumerate");
 
86
        static final Pattern VerbatimPattern    = Pattern.compile("@verbatim");
 
87
        static final Pattern ItemPattern                = Pattern.compile("@item");
 
88
        static final Pattern NoIndentPattern    = Pattern.compile("@noindent");
 
89
        static final Pattern BRPattern                  = Pattern.compile("<br>");
 
90
        static final Pattern EOLPattern                 = Pattern.compile("<eol>");
 
91
        static final Pattern EndVerbatimPattern = Pattern.compile("@end\\s+verbatim");
 
92
        static final Pattern TableSampItemPattern = Pattern.compile("(@table\\s*@samp.*)@item\\s*([a-zA-Z_0-9+\\-<>/ ]*)<eol>(.*@end\\s*table)", Pattern.DOTALL);
 
93
        static final Pattern TableAsisItemPattern = Pattern.compile("(@table\\s*@asis.*)@item\\s*([a-zA-Z_0-9+\\-,<>/ ]*)<eol>(.*@end\\s*table)", Pattern.DOTALL);
 
94
        static final Pattern TableSampPattern   = Pattern.compile("@table\\s*@samp", Pattern.MULTILINE);
 
95
        static final Pattern TableAsisPattern   = Pattern.compile("@table\\s*@asis", Pattern.MULTILINE);
 
96
        static final Pattern EndTablePattern    = Pattern.compile("@end\\s+table");
 
97
        static final Pattern DotsPattern                = Pattern.compile("@dots\\{\\}");
 
98
        static final Pattern ItemizeMinusPattern= Pattern.compile("@itemize\\s+@minus" + "(.*)" + "@end\\s+itemize", Pattern.MULTILINE);
 
99
        static final Pattern ItemizeBulletPattern= Pattern.compile("@itemize\\s+@bullet" + "(.*)" + "@end\\s+itemize", Pattern.MULTILINE);
 
100
        static final Pattern XrefPattern                = Pattern.compile("@xref\\{[^\\}]*\\}", Pattern.MULTILINE);
 
101
        static final Pattern CommandPattern             = Pattern.compile("@command\\{([^\\}]*)\\}");
 
102
        static final Pattern KbdPattern                 = Pattern.compile("@kbd\\{([^\\}]*)\\}");
 
103
        static final Pattern RPattern                   = Pattern.compile("@r\\{([^\\}]*)\\}");
 
104
        static final Pattern FilePattern                = Pattern.compile("@file\\{([^\\}]*)\\}");
 
105
        static final Pattern VarPattern                 = Pattern.compile("@var\\{([^\\}]*)\\}");
 
106
        static final Pattern OVarPattern                = Pattern.compile("@ovar\\{([^\\}]*)\\}");
 
107
        static final Pattern DVarPattern                = Pattern.compile("@dvar\\{([^\\},\\,]*),([^\\}]*)\\}");
 
108
        static final Pattern CodePattern                = Pattern.compile("@code\\{([^\\}]*)\\}");
 
109
        static final Pattern EmphPattern                = Pattern.compile("@emph\\{([^\\}]*)\\}");
 
110
        static final Pattern SampPattern                = Pattern.compile("@samp\\{([^\\}]*)\\}");
 
111
        static final Pattern OptionPattern              = Pattern.compile("@option\\{([^\\}]*)\\}");
 
112
        static final Pattern TagPattern         = Pattern.compile("@\\w*\\{([^\\}]*)\\}");
 
113
        static final Pattern AmpersandPattern   = Pattern.compile("&");
 
114
        static final Pattern LeftAnglePattern   = Pattern.compile("<");
 
115
        static final Pattern RightAnglePattern  = Pattern.compile(">");
 
116
 
 
117
        static List IncludeList = new ArrayList();
 
118
 
 
119
 
 
120
        static class FunctionDef {
 
121
                String ReturnType;
 
122
                String FunctionName;
 
123
                String[] Parameters;
 
124
                Object[] IncludeList;
 
125
        }
 
126
 
 
127
        static class TPElement {
 
128
                String Content;
 
129
                String Synopsis;
 
130
        }
 
131
 
 
132
        static class TPDef {
 
133
                String TPType;
 
134
                String TPName;
 
135
                String TPSynopsis;
 
136
                TPElement[] TPElements;
 
137
                Object[] IncludeList;
 
138
        }
 
139
 
 
140
        private static FunctionDef BuildFunctionDef(Matcher m) {
 
141
                FunctionDef fd = new FunctionDef();
 
142
 
 
143
                fd.ReturnType = ((null != m.group(RtnTypeSIndex))
 
144
                                ? m.group(RtnTypeSIndex)
 
145
                                                : m.group(RtnTypeMIndex));
 
146
                fd.FunctionName = m.group(FunctionNameIndex);
 
147
 
 
148
                if (null != m.group(ParmsIndex)) {
 
149
                        String tt = TexinfoUtils.stripProtoTags(m.group(ParmsIndex));
 
150
                        String[] parms = tt.split(",\\s");
 
151
                        fd.Parameters = parms;
 
152
                }
 
153
 
 
154
                if (IncludeList.size() > 0) {
 
155
                        fd.IncludeList = IncludeList.toArray();
 
156
                        IncludeList.clear();
 
157
                }
 
158
                return fd;
 
159
        }
 
160
 
 
161
        private static void HandleDeftp(BufferedWriter os, BufferedReader is, String s) throws IOException {
 
162
                TPDef td = new TPDef();
 
163
                String il;
 
164
                String Synopsis = null;
 
165
                boolean ItemsAccumulating = false;
 
166
                TPElement tpe = new TPElement();
 
167
                List ElementList = new ArrayList();
 
168
 
 
169
                Matcher m = DeftpPattern.matcher(s);
 
170
                if (m.matches()) {
 
171
                        if (null != m.group(TPTypeMIndex)) {
 
172
                                String[] ss = m.group(TPTypeMIndex).split("\\s");
 
173
                                switch(ss.length) {
 
174
                                case 0:
 
175
                                        td.TPType = "";
 
176
                                        td.TPName = "type";
 
177
                                        break;
 
178
                                case 1:
 
179
                                        td.TPType = "type";
 
180
                                        td.TPName = ss[0];
 
181
                                        break;
 
182
                                case 2:
 
183
                                        td.TPType = ss[0];
 
184
                                        td.TPName = ss[1];
 
185
                                        break;
 
186
                                default:
 
187
                                        td.TPType = "type";
 
188
                                td.TPName = ss[ss.length - 1];
 
189
                                break;
 
190
                                }
 
191
                        }
 
192
                        else {
 
193
                                td.TPType = "dtype";
 
194
                                td.TPName = m.group(TPTypeSIndex);
 
195
                        }
 
196
 
 
197
                        while (null != (il = is.readLine())) {
 
198
                                if (il.startsWith("@end deftp")) {
 
199
                                        WriteString(os, "  <construct id=\"" + td.TPType + "-" + td.TPName
 
200
                                                        + "\" type=\"" + td.TPType + "\">");
 
201
                                        WriteString(os, "    <structure>");
 
202
                                        if (null != td.TPSynopsis) WriteSynopsis(os, td.TPSynopsis, false);
 
203
                                        if (ElementList.size() > 0) {
 
204
                                                WriteString(os, "      <elements>");
 
205
                                                for (int ee = 0; ee < ElementList.size(); ee++) {
 
206
                                                        TPElement ttt = (TPElement)ElementList.get(ee);
 
207
                                                        WriteString(os, "        <element content=\"" + ttt.Content + "\">");
 
208
                                                        if (null != ttt.Synopsis) WriteSynopsis(os, ttt.Synopsis, true);
 
209
                                                        WriteString(os, "        </element>");
 
210
                                                }
 
211
                                                WriteString(os, "      </elements>");
 
212
                                        }
 
213
                                        WriteString(os, "    </structure>");
 
214
                                        WriteString(os, "  </construct>");
 
215
                                        return;
 
216
                                }
 
217
                                else if (il.startsWith("@item")) {
 
218
                                        if (ItemsAccumulating) {
 
219
                                                tpe.Synopsis = Synopsis;
 
220
                                                ElementList.add(tpe);
 
221
                                        }
 
222
                                        else {
 
223
                                                td.TPSynopsis  = Synopsis;
 
224
                                                ItemsAccumulating = true;
 
225
                                        }
 
226
                                        Synopsis = null;
 
227
                                        tpe = new TPElement();
 
228
                                        tpe.Content = TexinfoUtils.transformTags(il.replaceFirst("@item ", ""));
 
229
                                }
 
230
                                else {
 
231
                                        if (!il.startsWith("@table")) 
 
232
                                                Synopsis = ((Synopsis == null) ? "" : Synopsis + " " ) + ((il.length() == 0) ? "<br><br>" : 
 
233
                                                        il + "<eol>");
 
234
                                }
 
235
                        }
 
236
                }
 
237
        }
 
238
 
 
239
        private static FunctionDef HandleFunctionDef(BufferedReader is, String s) throws IOException {
 
240
                FunctionDef fd;
 
241
 
 
242
                Matcher m = DeftypefunPattern.matcher(s);
 
243
 
 
244
                if (m.matches()) fd = BuildFunctionDef(m);
 
245
                else {                                          // assume the line got split and retry
 
246
                        String il = is.readLine();
 
247
                        m = DeftypefunPattern.matcher(s + il);
 
248
                        if (m.matches()) fd = BuildFunctionDef(m);
 
249
                        else fd = null;
 
250
                }
 
251
 
 
252
                return fd;
 
253
        }
 
254
 
 
255
        private static void WriteString(BufferedWriter os, String s) throws IOException {
 
256
                //      System.out.println(s);
 
257
                os.write(s+"\n", 0, 1+s.length());
 
258
        }
 
259
 
 
260
        private static void CreateHeader(BufferedWriter os) throws IOException {
 
261
                WriteString(os, "<!-- This file automatically generated by an Eclipse utility -->");
 
262
                WriteString(os, "<!DOCTYPE descriptions [");
 
263
                WriteString(os, "");
 
264
                WriteString(os, "  <!ELEMENT descriptions (construct)*>");
 
265
                WriteString(os, "");
 
266
                WriteString(os, "  <!ELEMENT construct (structure|function)*>");
 
267
                WriteString(os, "  <!ATTLIST construct");
 
268
                WriteString(os, "    id ID #REQUIRED");
 
269
                WriteString(os, "    type CDATA #REQUIRED");
 
270
                WriteString(os, "  >");
 
271
                WriteString(os, "");
 
272
                WriteString(os, "  <!ELEMENT structure       (synopsis?, elements?)?>");
 
273
                WriteString(os, "");
 
274
                WriteString(os, "  <!ELEMENT elements     (element*)>");
 
275
                WriteString(os, "");
 
276
                WriteString(os, "  <!ELEMENT element (synopsis*)>");
 
277
                WriteString(os, "  <!ATTLIST element");
 
278
                WriteString(os, "    content CDATA #REQUIRED");
 
279
                WriteString(os, "  >");
 
280
                WriteString(os, "");
 
281
                WriteString(os, "  <!ELEMENT synopsis     (#PCDATA)*>");
 
282
                WriteString(os, "");
 
283
                WriteString(os, "  <!ELEMENT function     (prototype,headers?,synopsis)>");
 
284
                WriteString(os, "  <!ATTLIST function");
 
285
                WriteString(os, "    returntype CDATA #REQUIRED");
 
286
                WriteString(os, "  >");
 
287
                WriteString(os, "");
 
288
                WriteString(os, "  <!ELEMENT prototype    (parameter+)?>");
 
289
                WriteString(os, "");
 
290
                WriteString(os, "  <!ELEMENT parameter (#PCDATA)*>");
 
291
                WriteString(os, "  <!ATTLIST parameter");
 
292
                WriteString(os, "    content CDATA #REQUIRED");
 
293
                WriteString(os, "  >");
 
294
                WriteString(os, "");
 
295
                WriteString(os, "  <!ELEMENT headers      (header+)?>");
 
296
                WriteString(os, "");
 
297
                WriteString(os, "  <!ELEMENT header (#PCDATA)*>");
 
298
                WriteString(os, "  <!ATTLIST header");
 
299
                WriteString(os, "    filename CDATA #REQUIRED");
 
300
                WriteString(os, "  >");
 
301
                WriteString(os, "");
 
302
                WriteString(os, "]>");
 
303
                WriteString(os, "");
 
304
        }
 
305
 
 
306
//  // For now we will use an aggregate document license instead of one per
 
307
//  // document.
 
308
//      private static void CreateLicense(BufferedWriter os) throws IOException {
 
309
//              WriteString(os, "<!--");
 
310
//              WriteString(os, "A.1 GNU Free Documentation License");
 
311
//              WriteString(os,"Version 1.2, November 2002");
 
312
//              WriteString(os, "");
 
313
//              WriteString(os, "Copyright &copy; 2000,2001,2002 Free Software Foundation, Inc.");
 
314
//              WriteString(os, "59 Temple Place, Suite 330, Boston, MA  02111-1307, USA");
 
315
//              WriteString(os, "");
 
316
//              WriteString(os, "Everyone is permitted to copy and distribute verbatim copies");
 
317
//              WriteString(os, "of this license document, but changing it is not allowed.");
 
318
//              WriteString(os, "");
 
319
//              WriteString(os, "1. PREAMBLE");
 
320
//              WriteString(os, "");
 
321
//              WriteString(os, "The purpose of this License is to make a manual, textbook, or other");
 
322
//              WriteString(os, "functional and useful document free in the sense of freedom: to");
 
323
//              WriteString(os, "assure everyone the effective freedom to copy and redistribute it,");
 
324
//              WriteString(os, "with or without modifying it, either commercially or noncommercially.");
 
325
//              WriteString(os, "Secondarily, this License preserves for the author and publisher a way");
 
326
//              WriteString(os, "to get credit for their work, while not being considered responsible");
 
327
//              WriteString(os, "for modifications made by others.");
 
328
//              WriteString(os, "");
 
329
//              WriteString(os, "This License is a kind of \"copyleft\", which means that derivative");
 
330
//              WriteString(os, "works of the document must themselves be free in the same sense.  It");
 
331
//              WriteString(os, "complements the GNU General Public License, which is a copyleft");
 
332
//              WriteString(os, "license designed for free software.");
 
333
//              WriteString(os, "");
 
334
//              WriteString(os, "We have designed this License in order to use it for manuals for free");
 
335
//              WriteString(os, "software, because free software needs free documentation: a free");
 
336
//              WriteString(os, "program should come with manuals providing the same freedoms that the");
 
337
//              WriteString(os, "software does.  But this License is not limited to software manuals;");
 
338
//              WriteString(os, "it can be used for any textual work, regardless of subject matter or");
 
339
//              WriteString(os, "whether it is published as a printed book.  We recommend this License");
 
340
//              WriteString(os, "principally for works whose purpose is instruction or reference.");
 
341
//              WriteString(os, "");
 
342
//              WriteString(os, "2. APPLICABILITY AND DEFINITIONS");
 
343
//              WriteString(os, "");
 
344
//              WriteString(os, "This License applies to any manual or other work, in any medium, that");
 
345
//              WriteString(os, "contains a notice placed by the copyright holder saying it can be");
 
346
//              WriteString(os, "distributed under the terms of this License.  Such a notice grants a");
 
347
//              WriteString(os, "world-wide, royalty-free license, unlimited in duration, to use that");
 
348
//              WriteString(os, "work under the conditions stated herein.  The \"Document\", below,");
 
349
//              WriteString(os, "refers to any such manual or work.  Any member of the public is a");
 
350
//              WriteString(os, "licensee, and is addressed as \"you\".  You accept the license if you");
 
351
//              WriteString(os, "copy, modify or distribute the work in a way requiring permission");
 
352
//              WriteString(os, "under copyright law.");
 
353
//              WriteString(os, "");
 
354
//              WriteString(os, "A \"Modified Version\" of the Document means any work containing the");
 
355
//              WriteString(os, "Document or a portion of it, either copied verbatim, or with");
 
356
//              WriteString(os, "modifications and/or translated into another language.");
 
357
//              WriteString(os, "");
 
358
//              WriteString(os, "A \"Secondary Section\" is a named appendix or a front-matter section");
 
359
//              WriteString(os, "of the Document that deals exclusively with the relationship of the");
 
360
//              WriteString(os, "publishers or authors of the Document to the Document's overall");
 
361
//              WriteString(os, "subject (or to related matters) and contains nothing that could fall");
 
362
//              WriteString(os, "directly within that overall subject.  (Thus, if the Document is in");
 
363
//              WriteString(os, "part a textbook of mathematics, a Secondary Section may not explain");
 
364
//              WriteString(os, "any mathematics.)  The relationship could be a matter of historical");
 
365
//              WriteString(os, "connection with the subject or with related matters, or of legal,");
 
366
//              WriteString(os, "commercial, philosophical, ethical or political position regarding");
 
367
//              WriteString(os, "them.");
 
368
//              WriteString(os, "");
 
369
//              WriteString(os, "The \"Invariant Sections\" are certain Secondary Sections whose titles");
 
370
//              WriteString(os, "are designated, as being those of Invariant Sections, in the notice");
 
371
//              WriteString(os, "that says that the Document is released under this License.  If a");
 
372
//              WriteString(os, "section does not fit the above definition of Secondary then it is not");
 
373
//              WriteString(os, "allowed to be designated as Invariant.  The Document may contain zero");
 
374
//              WriteString(os, "Invariant Sections.  If the Document does not identify any Invariant");
 
375
//              WriteString(os, "Sections then there are none.");
 
376
//              WriteString(os, "");
 
377
//              WriteString(os, "The \"Cover Texts\" are certain short passages of text that are listed,");
 
378
//              WriteString(os, "as Front-Cover Texts or Back-Cover Texts, in the notice that says that");
 
379
//              WriteString(os, "the Document is released under this License.  A Front-Cover Text may");
 
380
//              WriteString(os, "be at most 5 words, and a Back-Cover Text may be at most 25 words.");
 
381
//              WriteString(os, "");
 
382
//              WriteString(os, "A \"Transparent\" copy of the Document means a machine-readable copy,");
 
383
//              WriteString(os, "represented in a format whose specification is available to the");
 
384
//              WriteString(os, "general public, that is suitable for revising the document");
 
385
//              WriteString(os, "straightforwardly with generic text editors or (for images composed of");
 
386
//              WriteString(os, "pixels) generic paint programs or (for drawings) some widely available");
 
387
//              WriteString(os, "drawing editor, and that is suitable for input to text formatters or");
 
388
//              WriteString(os, "for automatic translation to a variety of formats suitable for input");
 
389
//              WriteString(os, "to text formatters.  A copy made in an otherwise Transparent file");
 
390
//              WriteString(os, "format whose markup, or absence of markup, has been arranged to thwart");
 
391
//              WriteString(os, "or discourage subsequent modification by readers is not Transparent.");
 
392
//              WriteString(os, "An image format is not Transparent if used for any substantial amount");
 
393
//              WriteString(os, "of text.  A copy that is not \"Transparent\" is called \"Opaque\".");
 
394
//              WriteString(os, "");
 
395
//              WriteString(os, "Examples of suitable formats for Transparent copies include plain");
 
396
//              WriteString(os, "ASCII without markup, Texinfo input format, LaTeX input");
 
397
//              WriteString(os, "format, SGML or XML using a publicly available");
 
398
//              WriteString(os, "DTD, and standard-conforming simple HTML,");
 
399
//              WriteString(os, "PostScript or PDF designed for human modification.  Examples");
 
400
//              WriteString(os, "of transparent image formats include PNG, XCF and");
 
401
//              WriteString(os, "JPG.  Opaque formats include proprietary formats that can be");
 
402
//              WriteString(os, "read and edited only by proprietary word processors, SGML or");
 
403
//              WriteString(os, "XML for which the DTD and/or processing tools are");
 
404
//              WriteString(os, "not generally available, and the machine-generated HTML,");
 
405
//              WriteString(os, "PostScript or PDF produced by some word processors for");
 
406
//              WriteString(os, "output purposes only.");
 
407
//              WriteString(os, "");
 
408
//              WriteString(os, "The \"Title Page\" means, for a printed book, the title page itself,");
 
409
//              WriteString(os, "plus such following pages as are needed to hold, legibly, the material");
 
410
//              WriteString(os, "this License requires to appear in the title page.  For works in");
 
411
//              WriteString(os, "formats which do not have any title page as such, \"Title Page\" means");
 
412
//              WriteString(os, "the text near the most prominent appearance of the work's title,");
 
413
//              WriteString(os, "preceding the beginning of the body of the text.");
 
414
//              WriteString(os, "");
 
415
//              WriteString(os, "A section \"Entitled XYZ\" means a named subunit of the Document whose");
 
416
//              WriteString(os, "title either is precisely XYZ or contains XYZ in parentheses following");
 
417
//              WriteString(os, "text that translates XYZ in another language.  (Here XYZ stands for a");
 
418
//              WriteString(os, "specific section name mentioned below, such as \"Acknowledgements\",");
 
419
//              WriteString(os, "\"Dedications\", \"Endorsements\", or \"History\".)  To \"Preserve the Title\"");
 
420
//              WriteString(os, "of such a section when you modify the Document means that it remains a");
 
421
//              WriteString(os, "section \"Entitled XYZ\" according to this definition.");
 
422
//              WriteString(os, "");
 
423
//              WriteString(os, "The Document may include Warranty Disclaimers next to the notice which");
 
424
//              WriteString(os, "states that this License applies to the Document.  These Warranty");
 
425
//              WriteString(os, "Disclaimers are considered to be included by reference in this");
 
426
//              WriteString(os, "License, but only as regards disclaiming warranties: any other");
 
427
//              WriteString(os, "implication that these Warranty Disclaimers may have is void and has");
 
428
//              WriteString(os, "no effect on the meaning of this License.");
 
429
//              WriteString(os, "");
 
430
//              WriteString(os, "3. VERBATIM COPYING");
 
431
//              WriteString(os, "");
 
432
//              WriteString(os, "You may copy and distribute the Document in any medium, either");
 
433
//              WriteString(os, "commercially or noncommercially, provided that this License, the");
 
434
//              WriteString(os, "copyright notices, and the license notice saying this License applies");
 
435
//              WriteString(os, "to the Document are reproduced in all copies, and that you add no other");
 
436
//              WriteString(os, "conditions whatsoever to those of this License.  You may not use");
 
437
//              WriteString(os, "technical measures to obstruct or control the reading or further");
 
438
//              WriteString(os, "copying of the copies you make or distribute.  However, you may accept");
 
439
//              WriteString(os, "compensation in exchange for copies.  If you distribute a large enough");
 
440
//              WriteString(os, "number of copies you must also follow the conditions in section 3.");
 
441
//              WriteString(os, "");
 
442
//              WriteString(os, "You may also lend copies, under the same conditions stated above, and");
 
443
//              WriteString(os, "you may publicly display copies.");
 
444
//              WriteString(os, "");
 
445
//              WriteString(os, "4. COPYING IN QUANTITY");
 
446
//              WriteString(os, "");
 
447
//              WriteString(os, "If you publish printed copies (or copies in media that commonly have");
 
448
//              WriteString(os, "printed covers) of the Document, numbering more than 100, and the");
 
449
//              WriteString(os, "Document's license notice requires Cover Texts, you must enclose the");
 
450
//              WriteString(os, "copies in covers that carry, clearly and legibly, all these Cover");
 
451
//              WriteString(os, "Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on");
 
452
//              WriteString(os, "the back cover.  Both covers must also clearly and legibly identify");
 
453
//              WriteString(os, "you as the publisher of these copies.  The front cover must present");
 
454
//              WriteString(os, "the full title with all words of the title equally prominent and");
 
455
//              WriteString(os, "visible.  You may add other material on the covers in addition.");
 
456
//              WriteString(os, "Copying with changes limited to the covers, as long as they preserve");
 
457
//              WriteString(os, "the title of the Document and satisfy these conditions, can be treated");
 
458
//              WriteString(os, "as verbatim copying in other respects.");
 
459
//              WriteString(os, "");
 
460
//              WriteString(os, "If the required texts for either cover are too voluminous to fit");
 
461
//              WriteString(os, "legibly, you should put the first ones listed (as many as fit");
 
462
//              WriteString(os, "reasonably) on the actual cover, and continue the rest onto adjacent");
 
463
//              WriteString(os, "pages.");
 
464
//              WriteString(os, "");
 
465
//              WriteString(os, "If you publish or distribute Opaque copies of the Document numbering");
 
466
//              WriteString(os, "more than 100, you must either include a machine-readable Transparent");
 
467
//              WriteString(os, "copy along with each Opaque copy, or state in or with each Opaque copy");
 
468
//              WriteString(os, "a computer-network location from which the general network-using");
 
469
//              WriteString(os, "public has access to download using public-standard network protocols");
 
470
//              WriteString(os, "a complete Transparent copy of the Document, free of added material.");
 
471
//              WriteString(os, "If you use the latter option, you must take reasonably prudent steps,");
 
472
//              WriteString(os, "when you begin distribution of Opaque copies in quantity, to ensure");
 
473
//              WriteString(os, "that this Transparent copy will remain thus accessible at the stated");
 
474
//              WriteString(os, "location until at least one year after the last time you distribute an");
 
475
//              WriteString(os, "Opaque copy (directly or through your agents or retailers) of that");
 
476
//              WriteString(os, "edition to the public.");
 
477
//              WriteString(os, "");
 
478
//              WriteString(os, "It is requested, but not required, that you contact the authors of the");
 
479
//              WriteString(os, "Document well before redistributing any large number of copies, to give");
 
480
//              WriteString(os, "them a chance to provide you with an updated version of the Document.");
 
481
//              WriteString(os, "");
 
482
//              WriteString(os, "5. MODIFICATIONS");
 
483
//              WriteString(os, "");
 
484
//              WriteString(os, "You may copy and distribute a Modified Version of the Document under");
 
485
//              WriteString(os, "the conditions of sections 2 and 3 above, provided that you release");
 
486
//              WriteString(os, "the Modified Version under precisely this License, with the Modified");
 
487
//              WriteString(os, "Version filling the role of the Document, thus licensing distribution");
 
488
//              WriteString(os, "and modification of the Modified Version to whoever possesses a copy");
 
489
//              WriteString(os, "of it.  In addition, you must do these things in the Modified Version:");
 
490
//              WriteString(os, "");
 
491
//              WriteString(os, "   1. Use in the Title Page (and on the covers, if any) a title distinct");
 
492
//              WriteString(os, "      from that of the Document, and from those of previous versions");
 
493
//              WriteString(os, "      (which should, if there were any, be listed in the History section");
 
494
//              WriteString(os, "      of the Document).  You may use the same title as a previous version");
 
495
//              WriteString(os, "      if the original publisher of that version gives permission.");
 
496
//              WriteString(os, "");
 
497
//              WriteString(os, "   2. List on the Title Page, as authors, one or more persons or entities");
 
498
//              WriteString(os, "      responsible for authorship of the modifications in the Modified");
 
499
//              WriteString(os, "      Version, together with at least five of the principal authors of the");
 
500
//              WriteString(os, "      Document (all of its principal authors, if it has fewer than five),");
 
501
//              WriteString(os, "      unless they release you from this requirement.");
 
502
//              WriteString(os, "");
 
503
//              WriteString(os, "   3. State on the Title page the name of the publisher of the");
 
504
//              WriteString(os, "      Modified Version, as the publisher.");
 
505
//              WriteString(os, "");
 
506
//              WriteString(os, "   4. Preserve all the copyright notices of the Document.");
 
507
//              WriteString(os, "");
 
508
//              WriteString(os, "   5. Add an appropriate copyright notice for your modifications");
 
509
//              WriteString(os, "      adjacent to the other copyright notices.");
 
510
//              WriteString(os, "");
 
511
//              WriteString(os, "   6. Include, immediately after the copyright notices, a license notice");
 
512
//              WriteString(os, "      giving the public permission to use the Modified Version under the");
 
513
//              WriteString(os, "      terms of this License, in the form shown in the Addendum below.");
 
514
//              WriteString(os, "");
 
515
//              WriteString(os, "   7. Preserve in that license notice the full lists of Invariant Sections");
 
516
//              WriteString(os, "      and required Cover Texts given in the Document's license notice.");
 
517
//              WriteString(os, "");
 
518
//              WriteString(os, "   8. Include an unaltered copy of this License.");
 
519
//              WriteString(os, "");
 
520
//              WriteString(os, "   9. Preserve the section Entitled \"History\", Preserve its Title, and add");
 
521
//              WriteString(os, "      to it an item stating at least the title, year, new authors, and");
 
522
//              WriteString(os, "      publisher of the Modified Version as given on the Title Page.  If");
 
523
//              WriteString(os, "      there is no section Entitled \"History\" in the Document, create one");
 
524
//              WriteString(os, "      stating the title, year, authors, and publisher of the Document as");
 
525
//              WriteString(os, "      given on its Title Page, then add an item describing the Modified");
 
526
//              WriteString(os, "      Version as stated in the previous sentence.");
 
527
//              WriteString(os, "");
 
528
//              WriteString(os, "  10. Preserve the network location, if any, given in the Document for");
 
529
//              WriteString(os, "      public access to a Transparent copy of the Document, and likewise");
 
530
//              WriteString(os, "      the network locations given in the Document for previous versions");
 
531
//              WriteString(os, "      it was based on.  These may be placed in the \"History\" section.");
 
532
//              WriteString(os, "      You may omit a network location for a work that was published at");
 
533
//              WriteString(os, "      least four years before the Document itself, or if the original");
 
534
//              WriteString(os, "      publisher of the version it refers to gives permission.");
 
535
//              WriteString(os, "");
 
536
//              WriteString(os, "  11. For any section Entitled \"Acknowledgements\" or \"Dedications\", Preserve");
 
537
//              WriteString(os, "      the Title of the section, and preserve in the section all the");
 
538
//              WriteString(os, "      substance and tone of each of the contributor acknowledgements and/or");
 
539
//              WriteString(os, "      dedications given therein.");
 
540
//              WriteString(os, "");
 
541
//              WriteString(os, "  12. Preserve all the Invariant Sections of the Document,");
 
542
//              WriteString(os, "      unaltered in their text and in their titles.  Section numbers");
 
543
//              WriteString(os, "      or the equivalent are not considered part of the section titles.");
 
544
//              WriteString(os, "");
 
545
//              WriteString(os, "  13. Delete any section Entitled \"Endorsements\".  Such a section");
 
546
//              WriteString(os, "      may not be included in the Modified Version.");
 
547
//              WriteString(os, "");
 
548
//              WriteString(os, "  14. Do not retitle any existing section to be Entitled \"Endorsements\" or");
 
549
//              WriteString(os, "      to conflict in title with any Invariant Section.");
 
550
//              WriteString(os, "");
 
551
//              WriteString(os, "  15. Preserve any Warranty Disclaimers.");
 
552
//              WriteString(os, "");
 
553
//              WriteString(os, "");
 
554
//              WriteString(os, "If the Modified Version includes new front-matter sections or");
 
555
//              WriteString(os, "appendices that qualify as Secondary Sections and contain no material");
 
556
//              WriteString(os, "copied from the Document, you may at your option designate some or all");
 
557
//              WriteString(os, "of these sections as invariant.  To do this, add their titles to the");
 
558
//              WriteString(os, "list of Invariant Sections in the Modified Version's license notice.");
 
559
//              WriteString(os, "These titles must be distinct from any other section titles.");
 
560
//              WriteString(os, "");
 
561
//              WriteString(os, "You may add a section Entitled \"Endorsements\", provided it contains");
 
562
//              WriteString(os, "nothing but endorsements of your Modified Version by various");
 
563
//              WriteString(os, "parties - for example, statements of peer review or that the text has");
 
564
//              WriteString(os, "been approved by an organization as the authoritative definition of a");
 
565
//              WriteString(os, "standard.");
 
566
//              WriteString(os, "");
 
567
//              WriteString(os, "You may add a passage of up to five words as a Front-Cover Text, and a");
 
568
//              WriteString(os, "passage of up to 25 words as a Back-Cover Text, to the end of the list");
 
569
//              WriteString(os, "of Cover Texts in the Modified Version.  Only one passage of");
 
570
//              WriteString(os, "Front-Cover Text and one of Back-Cover Text may be added by (or");
 
571
//              WriteString(os, "through arrangements made by) any one entity.  If the Document already");
 
572
//              WriteString(os, "includes a cover text for the same cover, previously added by you or");
 
573
//              WriteString(os, "by arrangement made by the same entity you are acting on behalf of,");
 
574
//              WriteString(os, "you may not add another; but you may replace the old one, on explicit");
 
575
//              WriteString(os, "permission from the previous publisher that added the old one.");
 
576
//              WriteString(os, "");
 
577
//              WriteString(os, "The author(s) and publisher(s) of the Document do not by this License");
 
578
//              WriteString(os, "give permission to use their names for publicity for or to assert or");
 
579
//              WriteString(os, "imply endorsement of any Modified Version.");
 
580
//              WriteString(os, "");
 
581
//              WriteString(os, "6. COMBINING DOCUMENTS");
 
582
//              WriteString(os, "");
 
583
//              WriteString(os, "You may combine the Document with other documents released under this");
 
584
//              WriteString(os, "License, under the terms defined in section 4 above for modified");
 
585
//              WriteString(os, "versions, provided that you include in the combination all of the");
 
586
//              WriteString(os, "Invariant Sections of all of the original documents, unmodified, and");
 
587
//              WriteString(os, "list them all as Invariant Sections of your combined work in its");
 
588
//              WriteString(os, "license notice, and that you preserve all their Warranty Disclaimers.");
 
589
//              WriteString(os, "");
 
590
//              WriteString(os, "The combined work need only contain one copy of this License, and");
 
591
//              WriteString(os, "multiple identical Invariant Sections may be replaced with a single");
 
592
//              WriteString(os, "copy.  If there are multiple Invariant Sections with the same name but");
 
593
//              WriteString(os, "different contents, make the title of each such section unique by");
 
594
//              WriteString(os, "adding at the end of it, in parentheses, the name of the original");
 
595
//              WriteString(os, "author or publisher of that section if known, or else a unique number.");
 
596
//              WriteString(os, "Make the same adjustment to the section titles in the list of");
 
597
//              WriteString(os, "Invariant Sections in the license notice of the combined work.");
 
598
//              WriteString(os, "");
 
599
//              WriteString(os, "In the combination, you must combine any sections Entitled \"History\"");
 
600
//              WriteString(os, "in the various original documents, forming one section Entitled");
 
601
//              WriteString(os, "\"History\"; likewise combine any sections Entitled \"Acknowledgements\",");
 
602
//              WriteString(os, "and any sections Entitled \"Dedications\".  You must delete all");
 
603
//              WriteString(os, "sections Entitled \"Endorsements.\"");
 
604
//              WriteString(os, "");
 
605
//              WriteString(os, "7. COLLECTIONS OF DOCUMENTS");
 
606
//              WriteString(os, "");
 
607
//              WriteString(os, "You may make a collection consisting of the Document and other documents");
 
608
//              WriteString(os, "released under this License, and replace the individual copies of this");
 
609
//              WriteString(os, "License in the various documents with a single copy that is included in");
 
610
//              WriteString(os, "the collection, provided that you follow the rules of this License for");
 
611
//              WriteString(os, "verbatim copying of each of the documents in all other respects.");
 
612
//              WriteString(os, "");
 
613
//              WriteString(os, "You may extract a single document from such a collection, and distribute");
 
614
//              WriteString(os, "it individually under this License, provided you insert a copy of this");
 
615
//              WriteString(os, "License into the extracted document, and follow this License in all");
 
616
//              WriteString(os, "other respects regarding verbatim copying of that document.");
 
617
//              WriteString(os, "");
 
618
//              WriteString(os, "8. AGGREGATION WITH INDEPENDENT WORKS");
 
619
//              WriteString(os, "");
 
620
//              WriteString(os, "A compilation of the Document or its derivatives with other separate");
 
621
//              WriteString(os, "and independent documents or works, in or on a volume of a storage or");
 
622
//              WriteString(os, "distribution medium, is called an \"aggregate\" if the copyright");
 
623
//              WriteString(os, "resulting from the compilation is not used to limit the legal rights");
 
624
//              WriteString(os, "of the compilation's users beyond what the individual works permit.");
 
625
//              WriteString(os, "When the Document is included an aggregate, this License does not");
 
626
//              WriteString(os, "apply to the other works in the aggregate which are not themselves");
 
627
//              WriteString(os, "derivative works of the Document.");
 
628
//              WriteString(os, "");
 
629
//              WriteString(os, "If the Cover Text requirement of section 3 is applicable to these");
 
630
//              WriteString(os, "copies of the Document, then if the Document is less than one half of");
 
631
//              WriteString(os, "the entire aggregate, the Document's Cover Texts may be placed on");
 
632
//              WriteString(os, "covers that bracket the Document within the aggregate, or the");
 
633
//              WriteString(os, "electronic equivalent of covers if the Document is in electronic form.");
 
634
//              WriteString(os, "Otherwise they must appear on printed covers that bracket the whole");
 
635
//              WriteString(os, "aggregate.");
 
636
//              WriteString(os, "");
 
637
//              WriteString(os, "9. TRANSLATION");
 
638
//              WriteString(os, "");
 
639
//              WriteString(os, "Translation is considered a kind of modification, so you may");
 
640
//              WriteString(os, "distribute translations of the Document under the terms of section 4.");
 
641
//              WriteString(os, "Replacing Invariant Sections with translations requires special");
 
642
//              WriteString(os, "permission from their copyright holders, but you may include");
 
643
//              WriteString(os, "translations of some or all Invariant Sections in addition to the");
 
644
//              WriteString(os, "original versions of these Invariant Sections.  You may include a");
 
645
//              WriteString(os, "translation of this License, and all the license notices in the");
 
646
//              WriteString(os, "Document, and any Warrany Disclaimers, provided that you also include");
 
647
//              WriteString(os, "the original English version of this License and the original versions");
 
648
//              WriteString(os, "of those notices and disclaimers.  In case of a disagreement between");
 
649
//              WriteString(os, "the translation and the original version of this License or a notice");
 
650
//              WriteString(os, "or disclaimer, the original version will prevail.");
 
651
//              WriteString(os, "");
 
652
//              WriteString(os, "If a section in the Document is Entitled \"Acknowledgements\",");
 
653
//              WriteString(os, "\"Dedications\", or \"History\", the requirement (section 4) to Preserve");
 
654
//              WriteString(os, "its Title (section 1) will typically require changing the actual");
 
655
//              WriteString(os, "title.");
 
656
//              WriteString(os, "");
 
657
//              WriteString(os, "10. TERMINATION");
 
658
//              WriteString(os, "");
 
659
//              WriteString(os, "You may not copy, modify, sublicense, or distribute the Document except");
 
660
//              WriteString(os, "as expressly provided for under this License.  Any other attempt to");
 
661
//              WriteString(os, "copy, modify, sublicense or distribute the Document is void, and will");
 
662
//              WriteString(os, "automatically terminate your rights under this License.  However,");
 
663
//              WriteString(os, "parties who have received copies, or rights, from you under this");
 
664
//              WriteString(os, "License will not have their licenses terminated so long as such");
 
665
//              WriteString(os, "parties remain in full compliance.");
 
666
//              WriteString(os, "");
 
667
//              WriteString(os, "11. FUTURE REVISIONS OF THIS LICENSE");
 
668
//              WriteString(os, "");
 
669
//              WriteString(os, "The Free Software Foundation may publish new, revised versions");
 
670
//              WriteString(os, "of the GNU Free Documentation License from time to time.  Such new");
 
671
//              WriteString(os, "versions will be similar in spirit to the present version, but may");
 
672
//              WriteString(os, "differ in detail to address new problems or concerns.  See");
 
673
//              WriteString(os, "http://www.gnu.org/copyleft/.");
 
674
//              WriteString(os, "");
 
675
//              WriteString(os, "Each version of the License is given a distinguishing version number.");
 
676
//              WriteString(os, "If the Document specifies that a particular numbered version of this");
 
677
//              WriteString(os, "License \"or any later version\" applies to it, you have the option of");
 
678
//              WriteString(os, "following the terms and conditions either of that specified version or");
 
679
//              WriteString(os, "of any later version that has been published (not as a draft) by the");
 
680
//              WriteString(os, "Free Software Foundation.  If the Document does not specify a version");
 
681
//              WriteString(os, "number of this License, you may choose any version ever published (not");
 
682
//              WriteString(os, "as a draft) by the Free Software Foundation.");
 
683
//              WriteString(os, "-->");
 
684
//      }
 
685
 
 
686
        private static void CreateTrailer(BufferedWriter os) throws IOException {
 
687
                WriteString(os, "</descriptions>");
 
688
        }
 
689
 
 
690
        private static void WriteSynopsis(BufferedWriter os, String Synopsis, boolean indent)  throws IOException {
 
691
                String ss = TexinfoUtils.transformTags(Synopsis);
 
692
                String[] tt = ss.split("<eol>");
 
693
                String aa = "";
 
694
                String spaces = indent ? "            " : "        ";
 
695
                WriteString(os, spaces + "<synopsis>");
 
696
                if (null != Synopsis) {
 
697
                        for (int pp = 0; pp < tt.length; pp++) {
 
698
                                WriteString(os, spaces + tt[pp]);
 
699
//                              if (tt[pp].equals("<br>")) {
 
700
//                                      WriteString(os, spaces + aa + "\n");
 
701
//                                      aa = "";
 
702
//                              }
 
703
//                              else {
 
704
//                                      if ((aa.length() + tt[pp].length()) > 64) {
 
705
//                                              WriteString(os, spaces + aa);
 
706
//                                              aa = "";
 
707
//                                      }
 
708
//                                      aa = aa + " " + tt[pp];
 
709
//                              }
 
710
                        }
 
711
                }
 
712
                if (aa.length() > 0) WriteString(os, "        " + aa);
 
713
                WriteString(os, spaces + "</synopsis>");
 
714
        }
 
715
 
 
716
        private static String HandleInclude (String srcdir, String line, String Synopsis) {
 
717
                Pattern p = Pattern.compile("@include\\s+(.*?)\\.texi");
 
718
                Matcher mm = p.matcher(line);
 
719
                if (mm.find()) {
 
720
                        String il;
 
721
                        BufferedReader is = null;
 
722
                        try {
 
723
                                String fileName = (srcdir.endsWith("/") ? srcdir : srcdir + "/") + mm.replaceAll("examples/$1");
 
724
                                is = new BufferedReader(new FileReader(fileName));
 
725
                                while (null != (il = is.readLine())) {
 
726
                                        // C Help does not ignore "<" or ">" inside a <pre> or <samp> tag
 
727
                                        // so we have to prepare for two levels of indirection.  The
 
728
                                        // first is for xml to interpret and the second is for the
 
729
                                        // C Help processor to interpret.  So, we put &lt; and &gt; which
 
730
                                        // will be transformed into &amp;lt; by the tag transformer.
 
731
                                        Pattern p1 = Pattern.compile("<");
 
732
                                        Pattern p2 = Pattern.compile(">");
 
733
                                        Matcher mm1 = p1.matcher(il);
 
734
                                        il = mm1.replaceAll("&lt;");
 
735
                                        Matcher mm2 = p2.matcher(il);
 
736
                                        il = mm2.replaceAll("&gt;");
 
737
                                        Synopsis = ((Synopsis == null) ? "" : Synopsis + " " ) + ((il.length() == 0) ? "<br><br>" : 
 
738
                                                il + "<eol>");
 
739
                                }
 
740
                        } catch (IOException e) {
 
741
                                System.out.println("IOException reading example file");
 
742
                        } finally {
 
743
                                if (is != null) {
 
744
                                        try {
 
745
                                                is.close();
 
746
                                        } catch (IOException e) {
 
747
                                        }
 
748
                                }
 
749
                        }
 
750
                }
 
751
                return Synopsis;
 
752
        }
 
753
        private static void HandleDeftypefun(BufferedWriter os, BufferedReader is, String s, String srcdir) throws IOException {
 
754
                String il;
 
755
                FunctionDef fd;
 
756
                List FDefs = new ArrayList();
 
757
                String Synopsis = null;
 
758
 
 
759
                if (null != (fd = HandleFunctionDef(is, s))) FDefs.add(fd);
 
760
 
 
761
                while (null != (il = is.readLine())) {
 
762
                        Matcher mm = IncludePattern.matcher(il);
 
763
                        if (il.startsWith("@deftypefunx")) {
 
764
                                if (null != (fd = HandleFunctionDef(is, il))) FDefs.add(fd);
 
765
                        }
 
766
                        else if (mm.matches()) {
 
767
                                if (!IncludeList.contains(mm.group(1)))
 
768
                                        IncludeList.add(mm.group(1));
 
769
                        }
 
770
                        else if (il.startsWith("@comment") ||
 
771
                                        il.startsWith("@c ") ||
 
772
                                        il.startsWith("@pindex")) {     // ignore
 
773
                        }
 
774
                        else if (il.startsWith("@include") && fd != null) {
 
775
                                Synopsis = HandleInclude(srcdir, il, Synopsis);
 
776
                        }
 
777
                        else if (il.startsWith("@end deftypefun")) {
 
778
                                for (int kk = 0; kk < FDefs.size(); kk++) {
 
779
                                        fd = (FunctionDef)FDefs.get(kk);
 
780
 
 
781
                                        WriteString(os, "  <construct id=\"function-" + fd.FunctionName + "\" type=\"function\">");
 
782
 
 
783
                                        WriteString(os, "    <function returntype=\"" + fd.ReturnType + "\">");
 
784
 
 
785
                                        WriteString(os, "      <prototype>");
 
786
                                        String[] parms = fd.Parameters;
 
787
                                        for (int i = 0; i < parms.length; i++) {
 
788
                                                String parm = TexinfoUtils.stripProtoTags(parms[i]);
 
789
                                                WriteString(os, "        <parameter content=\"" + parm + "\"/>");
 
790
                                        }
 
791
                                        WriteString(os, "      </prototype>");
 
792
 
 
793
                                        if (fd.IncludeList != null) {
 
794
                                                WriteString(os, "      <headers>");
 
795
                                                Object[] incs = fd.IncludeList;
 
796
                                                for (int j = 0; j < incs.length; j++) {
 
797
                                                        String inc = (String)incs[j];
 
798
                                                        WriteString(os, "        <header filename = \"" + inc + "\"/>");
 
799
                                                }
 
800
                                                WriteString(os, "      </headers>");
 
801
                                        }
 
802
 
 
803
                                        if (null != Synopsis) WriteSynopsis(os, Synopsis, false);
 
804
 
 
805
                                        WriteString(os, "    </function>");
 
806
                                        WriteString(os, "  </construct>");
 
807
                                }
 
808
                                return;
 
809
                        }
 
810
                        else {
 
811
                                Synopsis = ((Synopsis == null) ? "" : Synopsis + " " ) + ((il.length() == 0) ? "<br><br>" : 
 
812
                                        il + "<eol>");
 
813
                        }
 
814
                }
 
815
                FDefs.clear();
 
816
 
 
817
        }
 
818
 
 
819
        private static class OnlyTexi implements FilenameFilter {
 
820
                public boolean accept(File dir, String s) {
 
821
                        return (s.endsWith(".texi")) ? true : false;
 
822
                }
 
823
        }
 
824
 
 
825
        public static void BuildXMLFromTexinfo(String srcdir, String dstdir) {
 
826
                try {
 
827
                        BufferedWriter os = new BufferedWriter(new FileWriter(dstdir));
 
828
 
 
829
                        CreateHeader(os);
 
830
//                      CreateLicense(os);
 
831
 
 
832
                        WriteString(os, "<descriptions>");
 
833
 
 
834
                        try {
 
835
                                String[] dir = new java.io.File(srcdir).list(new OnlyTexi());
 
836
                                for (int i = 0; i < dir.length; i++) {
 
837
                                        String qFile = srcdir.endsWith("/")
 
838
                                        ? srcdir + dir[i]
 
839
                                                       : srcdir + "/" + dir[i];
 
840
 
 
841
                                        try {
 
842
                                                BufferedReader is = new BufferedReader(new FileReader(qFile));
 
843
                                                String il;
 
844
 
 
845
                                                while (null != (il = is.readLine())) {
 
846
                                                        Matcher mm = IncludePattern.matcher(il);
 
847
                                                        if (il.startsWith("@deftypefun")) {     // handle @deftypefun[x]
 
848
                                                                HandleDeftypefun(os, is, il, srcdir);
 
849
                                                        }
 
850
                                                        else if (il.startsWith("@deftp")) {     // handle @deftp
 
851
                                                                HandleDeftp(os, is, il);
 
852
                                                        }
 
853
                                                        else if (mm.matches()) {                // handle @comment <include_file>
 
854
                                                                if (!IncludeList.contains(mm.group(1)))
 
855
                                                                        IncludeList.add(mm.group(1));
 
856
                                                        }
 
857
                                                        else if (il.startsWith("@end deftypefn"))
 
858
                                                                // Handle accumulated header file comments that are in
 
859
                                                                // constructs we aren't parsing.
 
860
                                                                IncludeList.clear();
 
861
                                                }
 
862
                                                is.close();
 
863
                                        }
 
864
                                        catch (IOException e) {
 
865
                                                System.out.println("Input File IOException: " + e);
 
866
                                                return;
 
867
                                        }
 
868
                                }
 
869
                        }
 
870
                        catch (NullPointerException e) {
 
871
                                System.out.println("NullPointerException: " + e);
 
872
                                return;
 
873
                        }
 
874
 
 
875
                        CreateTrailer(os);
 
876
 
 
877
                        os.close();
 
878
                }
 
879
                catch (IOException e) {
 
880
                        System.out.println("Output File IOException: " + e);
 
881
                        return;
 
882
                }
 
883
        }
 
884
 
 
885
        public static void main(String[] args) {
 
886
                BuildXMLFromTexinfo(args[0], args[1]);
 
887
        }
 
888
 
 
889
}