~ubuntu-branches/ubuntu/raring/eclipse-linuxtools/raring

« back to all changes in this revision

Viewing changes to .pc/libhover-fix-automake-texinfo-parser.patch/libhover/org.eclipse.linuxtools.cdt.libhover.texinfoparsers/src/org/eclipse/linuxtools/cdt/libhover/texinfoparsers/ParseAutomakeTexinfo.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-um7a5gz1w6yzx3hg
Tags: 1.0.0-1
* New upstream release.
* Remove eclipse-cdt-autotools binary package.
  - The code moved to Eclipse CDT.
* Drop d/patches/valgrind-remove-unused-emf-dependency.patch
  - Included upstream.

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.BufferedReader;
 
13
import java.io.BufferedWriter;
 
14
import java.io.File;
 
15
import java.io.FileReader;
 
16
import java.io.FileWriter;
 
17
import java.io.FilenameFilter;
 
18
import java.io.IOException;
 
19
import java.util.ArrayList;
 
20
import java.util.HashMap;
 
21
import java.util.List;
 
22
import java.util.Map;
 
23
import java.util.regex.Matcher;
 
24
import java.util.regex.Pattern;
 
25
 
 
26
//This file contains a texinfo parser that can be
 
27
//run to create the Autotools glibc.xml file.
 
28
//Usage is as follows:
 
29
//1. compile this file using javac
 
30
//2. run this file using java, passing the
 
31
//arguments: dir_to_automake_texi_files output_xml_file_name
 
32
 
 
33
public class ParseAutomakeTexinfo {
 
34
 
 
35
        static final boolean DEBUG = false;
 
36
 
 
37
        static final String ATcmd = "(@\\w*)";
 
38
 
 
39
        // Currently in automake docs, the macro section starts with
 
40
        // a subsection as below and a table which contains macros which
 
41
        // are item and itemx entries.
 
42
        static final String MacrosStart = "@subsection\\sPublic\\smacros";
 
43
        static final String OldMacrosStart = "@section\\sAutoconf\\smacros.*";
 
44
        static final Pattern MacroSection1 = Pattern.compile(MacrosStart);
 
45
        static final Pattern MacroSection2 = Pattern.compile(OldMacrosStart);
 
46
        //                           0
 
47
        static final String Defmac = "@item";
 
48
        static final String Defmacx = "@itemx";
 
49
 
 
50
        //                           1
 
51
        static final String MacroName = "(\\w*)";
 
52
        static final int    MacroNameIndex = 1;
 
53
 
 
54
        //                          2    3
 
55
        static final String Parms = "(\\((.*)\\))";
 
56
        static final int    ParmsIndex = 2;
 
57
 
 
58
        static final String rest = ".*";
 
59
 
 
60
        static final String WhiteSpace = "\\s*";
 
61
 
 
62
        static final Pattern MacroPattern
 
63
        = Pattern.compile("^" + Defmac + WhiteSpace +
 
64
                        MacroName + WhiteSpace +
 
65
                        Parms +
 
66
                        rest, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE);
 
67
 
 
68
        static final Pattern MacroPattern2
 
69
        = Pattern.compile("^" + Defmac + WhiteSpace + MacroName + rest, 
 
70
                        Pattern.MULTILINE + Pattern.CASE_INSENSITIVE);
 
71
 
 
72
        static final Pattern MacroPatternx
 
73
        = Pattern.compile("^" + Defmacx + WhiteSpace +
 
74
                        MacroName + WhiteSpace +
 
75
                        Parms +
 
76
                        rest, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE);
 
77
 
 
78
        static final Pattern MacroPatternx2
 
79
        = Pattern.compile("^" + Defmacx + WhiteSpace + MacroName + rest, 
 
80
                        Pattern.MULTILINE + Pattern.CASE_INSENSITIVE);
 
81
 
 
82
        static final Pattern ParmBracketPattern = Pattern.compile("\\((.*)\\)");
 
83
        static final Pattern IndexPattern               = Pattern.compile("@\\w*index.*");
 
84
        static final Pattern IndexPattern2              = Pattern.compile("@\\w*index\\{[a-zA-Z0-9_@\\{\\}]*\\}");
 
85
        static final Pattern ExamplePattern             = Pattern.compile("@example");
 
86
        static final Pattern EndExamplePattern  = Pattern.compile("@end\\s+example");
 
87
        static final Pattern EnumeratePattern   = Pattern.compile("@enumerate");
 
88
        static final Pattern EndEnumeratePattern  = Pattern.compile("@end\\s+enumerate");
 
89
        static final Pattern VerbatimPattern    = Pattern.compile("@verbatim");
 
90
        static final Pattern ItemPattern                = Pattern.compile("@item");
 
91
        static final Pattern NoIndentPattern    = Pattern.compile("@noindent");
 
92
        static final Pattern BRPattern                  = Pattern.compile("<br>");
 
93
        static final Pattern EOLPattern                 = Pattern.compile("<eol>");
 
94
        static final Pattern EndVerbatimPattern = Pattern.compile("@end\\s+verbatim");
 
95
        static final Pattern TableSampItemPattern = Pattern.compile("(@table\\s*@samp.*)@item\\s*([a-zA-Z_0-9+\\-<>/ ]*)<eol>(.*@end\\s*table)", Pattern.DOTALL);
 
96
        static final Pattern TableAsisItemPattern = Pattern.compile("(@table\\s*@asis.*)@item\\s*([a-zA-Z_0-9+\\-,<>/ ]*)<eol>(.*@end\\s*table)", Pattern.DOTALL);
 
97
        static final Pattern TableSampPattern   = Pattern.compile("@table\\s*@samp", Pattern.MULTILINE);
 
98
        static final Pattern TableAsisPattern   = Pattern.compile("@table\\s*@asis", Pattern.MULTILINE);
 
99
        static final Pattern EndTablePattern    = Pattern.compile("@end\\s+table");
 
100
        static final Pattern DotsPattern                = Pattern.compile("@dots\\{\\}");
 
101
        static final Pattern ItemizeMinusPattern= Pattern.compile("@itemize\\s+@minus" + "(.*)" + "@end\\s+itemize", Pattern.MULTILINE);
 
102
        static final Pattern ItemizeBulletPattern= Pattern.compile("@itemize\\s+@bullet" + "(.*)" + "@end\\s+itemize", Pattern.MULTILINE);
 
103
        static final Pattern XrefPattern                = Pattern.compile("@xref\\{[^\\}]*\\}", Pattern.MULTILINE);
 
104
        static final Pattern CommandPattern             = Pattern.compile("@command\\{([^\\}]*)\\}");
 
105
        static final Pattern KbdPattern                 = Pattern.compile("@kbd\\{([^\\}]*)\\}");
 
106
        static final Pattern RPattern                   = Pattern.compile("@r\\{([^\\}]*)\\}");
 
107
        static final Pattern FilePattern                = Pattern.compile("@file\\{([^\\}]*)\\}");
 
108
        static final Pattern VarPattern                 = Pattern.compile("@var\\{([^\\}]*)\\}");
 
109
        static final Pattern OVarPattern                = Pattern.compile("@ovar\\{([^\\}]*)\\}");
 
110
        static final Pattern DVarPattern                = Pattern.compile("@dvar\\{([^\\},\\,]*),([^\\}]*)\\}");
 
111
        static final Pattern CodePattern                = Pattern.compile("@code\\{([^\\}]*)\\}");
 
112
        static final Pattern EmphPattern                = Pattern.compile("@emph\\{([^\\}]*)\\}");
 
113
        static final Pattern SampPattern                = Pattern.compile("@samp\\{([^\\}]*)\\}");
 
114
        static final Pattern OptionPattern              = Pattern.compile("@option\\{([^\\}]*)\\}");
 
115
        static final Pattern UrefPattern                = Pattern.compile("@uref\\{([^,]*),\\s+([^\\}]*)\\}");
 
116
        static final Pattern TagPattern         = Pattern.compile("@\\w*\\{([^\\}]*)\\}");
 
117
        static final Pattern AmpersandPattern   = Pattern.compile("&");
 
118
        static final Pattern LeftAnglePattern   = Pattern.compile("<");
 
119
        static final Pattern RightAnglePattern  = Pattern.compile(">");
 
120
 
 
121
 
 
122
        private static Map macroMap;
 
123
        
 
124
        static class MacroParms {
 
125
                String[] parms;
 
126
                MacroParms nextParms = null;
 
127
                
 
128
                public MacroParms(String[] parms) {
 
129
                        this.parms = parms;
 
130
                }
 
131
        }
 
132
        
 
133
        static class MacroDef {
 
134
                String MacroName;
 
135
                MacroParms Parameters;
 
136
                String Synopsis;
 
137
        }
 
138
 
 
139
        static class TPElement {
 
140
                String Content;
 
141
                String Synopsis;
 
142
        }
 
143
 
 
144
        static class TPDef {
 
145
                String TPType;
 
146
                String TPName;
 
147
                String TPSynopsis;
 
148
                TPElement[] TPElements;
 
149
                Object[] IncludeList;
 
150
        }
 
151
        
 
152
        private static String killTagsParms(String tt) {
 
153
                Matcher mm;
 
154
                
 
155
                mm = ParmBracketPattern.matcher(tt);
 
156
                tt= mm.replaceAll("$1");
 
157
                
 
158
                mm = OVarPattern.matcher(tt);
 
159
                tt = mm.replaceAll("[$1]");
 
160
                
 
161
                mm = DVarPattern.matcher(tt);
 
162
                tt = mm.replaceAll("[$1=$2]");
 
163
 
 
164
                mm = VarPattern.matcher(tt);
 
165
                tt = mm.replaceAll("$1");
 
166
                
 
167
                mm = RPattern.matcher(tt);
 
168
                tt = mm.replaceAll("$1");
 
169
                
 
170
                mm = DotsPattern.matcher(tt);
 
171
                tt = mm.replaceAll("...");
 
172
                
 
173
                return tt;
 
174
        }
 
175
                
 
176
 
 
177
        private static String killTags(String tt) {
 
178
                Matcher mm;
 
179
                String ss = "";
 
180
                
 
181
                while (ss != tt) {
 
182
                        mm = XrefPattern.matcher(tt);
 
183
                        ss = tt;
 
184
                        tt = mm.replaceAll("");
 
185
                }
 
186
 
 
187
                ss = "";
 
188
                while (ss != tt) {
 
189
                        mm = IndexPattern.matcher(tt);
 
190
                        ss = tt;
 
191
                        tt = mm.replaceAll("");
 
192
                }
 
193
                
 
194
                ss = "";
 
195
                while (ss != tt) {
 
196
                        mm = IndexPattern2.matcher(tt);
 
197
                        ss = tt;
 
198
                        tt = mm.replaceAll("");
 
199
                }
 
200
                
 
201
                ss = "";
 
202
                while (ss != tt) {
 
203
                        mm = NoIndentPattern.matcher(tt);
 
204
                        ss = tt;
 
205
                        tt = mm.replaceAll("");
 
206
                }
 
207
                
 
208
                ss = "";
 
209
                while (ss != tt) {
 
210
                        mm = VarPattern.matcher(tt);
 
211
                        ss = tt;
 
212
                        tt = mm.replaceAll("<VAR>$1</VAR>");
 
213
                }
 
214
                
 
215
                ss = "";
 
216
                while (ss != tt) {
 
217
                        mm = DotsPattern.matcher(tt);
 
218
                        ss = tt;
 
219
                        tt = mm.replaceAll("<small>...</small>");
 
220
                }
 
221
                
 
222
                ss = "";
 
223
                while (ss != tt) {
 
224
                        mm = CommandPattern.matcher(tt);
 
225
                        ss = tt;
 
226
                        tt = mm.replaceAll("<CODE>$1</CODE>");
 
227
                }
 
228
                
 
229
                ss = "";
 
230
                while (ss != tt) {
 
231
                        mm = CodePattern.matcher(tt);
 
232
                        ss = tt;
 
233
                        tt = mm.replaceAll("<CODE>$1</CODE>");
 
234
                }
 
235
 
 
236
                ss = "";
 
237
                while (ss != tt) {
 
238
                        mm = UrefPattern.matcher(tt);
 
239
                        ss = tt;
 
240
                        tt = mm.replaceAll("<A HREF=\"$1>$2</A>");
 
241
                }
 
242
                
 
243
                ss = "";
 
244
                while (ss != tt) {
 
245
                        mm = KbdPattern.matcher(tt);
 
246
                        ss = tt;
 
247
                        tt = mm.replaceAll("<KBD>$1</KBD>");
 
248
                }
 
249
                
 
250
                ss = "";
 
251
                while (ss != tt) {
 
252
                        mm = EmphPattern.matcher(tt);
 
253
                        ss = tt;
 
254
                        tt = mm.replaceAll("<EM>$1</EM>");
 
255
                }
 
256
                
 
257
                ss = "";
 
258
                while (ss != tt) {
 
259
                        mm = FilePattern.matcher(tt);
 
260
                        ss = tt;
 
261
                        tt = mm.replaceAll("<TT>$1</TT>");
 
262
                }
 
263
                
 
264
                
 
265
                ss = "";
 
266
                while (ss != tt) {
 
267
                        mm = VerbatimPattern.matcher(tt);
 
268
                        ss = tt;
 
269
                        tt = mm.replaceAll("<CODE>");
 
270
                }
 
271
                
 
272
                ss = "";
 
273
                while (ss != tt) {
 
274
                        mm = EndVerbatimPattern.matcher(tt);
 
275
                        ss = tt;
 
276
                        tt = mm.replaceAll("</CODE>");
 
277
                }
 
278
                
 
279
                ss = "";
 
280
                while (ss != tt) {
 
281
                        mm = SampPattern.matcher(tt);
 
282
                        ss = tt;
 
283
                        tt = mm.replaceAll("<samp>$1</samp>");
 
284
                }
 
285
                
 
286
                ss = "";
 
287
                while (ss != tt) {
 
288
                        mm = OptionPattern.matcher(tt);
 
289
                        ss = tt;
 
290
                        tt = mm.replaceAll("<samp>$1</samp>");
 
291
                }
 
292
                
 
293
                ss = "";
 
294
                while (ss != tt) {
 
295
                        mm = ExamplePattern.matcher(tt);
 
296
                        ss = tt;
 
297
                        tt = mm.replaceAll("<TABLE><tr><td>&nbsp;</td><td class=example><pre>");
 
298
                }
 
299
                
 
300
                ss = "";
 
301
                while (ss != tt) {
 
302
                        mm = EndExamplePattern.matcher(tt);
 
303
                        ss = tt;
 
304
                        tt = mm.replaceAll("</pre></td></tr></table>");
 
305
                }
 
306
 
 
307
                ss = "";
 
308
                while (ss != tt) {
 
309
                        mm = EnumeratePattern.matcher(tt);
 
310
                        ss = tt;
 
311
                        tt = mm.replaceAll("<OL>");
 
312
                }
 
313
                
 
314
                ss = "";
 
315
                while (ss != tt) {
 
316
                        mm = EndEnumeratePattern.matcher(tt);
 
317
                        ss = tt;
 
318
                        tt = mm.replaceAll("</OL>");
 
319
                }
 
320
 
 
321
                ss = "";
 
322
                while (ss != tt) {
 
323
                        mm = TableSampItemPattern.matcher(tt);
 
324
                        ss = tt;
 
325
                        if (mm.matches()) {
 
326
                                System.out.println("group 1 is " + mm.group(1));
 
327
                                System.out.println("group 2 is " + mm.group(2));
 
328
                                System.out.println("group 3 is " + mm.group(3));
 
329
                        }
 
330
                        tt = mm.replaceAll("$1<DT>'<SAMP>$2</SAMP>'\n<DD>$3");
 
331
                }
 
332
 
 
333
                ss = "";
 
334
                while (ss != tt) {
 
335
                        mm = TableAsisItemPattern.matcher(tt);
 
336
                        ss = tt;
 
337
                        tt = mm.replaceAll("$1<DT>$2\n<DD>$3");
 
338
                }
 
339
 
 
340
                ss = "";
 
341
                while (ss != tt) {
 
342
                        mm = TableSampPattern.matcher(tt);
 
343
                        ss = tt;
 
344
                        tt = mm.replaceAll("<DL>\n");
 
345
                }
 
346
 
 
347
                ss = "";
 
348
                while (ss != tt) {
 
349
                        mm = TableAsisPattern.matcher(tt);
 
350
                        ss = tt;
 
351
                        tt = mm.replaceAll("<DL>\n");
 
352
                }
 
353
 
 
354
                ss = "";
 
355
                while (ss != tt) {
 
356
                        mm = EndTablePattern.matcher(tt);
 
357
                        ss = tt;
 
358
                        tt = mm.replaceAll("</DL>");
 
359
                }
 
360
 
 
361
                //FIXME: if there ever is a @itemize @bullet within a
 
362
                //       @itemize @minus or vice-versa, the following
 
363
                //       logic will get it wrong.
 
364
                ss = "";
 
365
                while (ss != tt) {
 
366
                        mm = ItemizeMinusPattern.matcher(tt);
 
367
                        ss = tt;
 
368
                        tt = mm.replaceAll("<UL>$1</UL>");
 
369
                }
 
370
 
 
371
                ss = "";
 
372
                while (ss != tt) {
 
373
                        mm = ItemizeBulletPattern.matcher(tt);
 
374
                        ss = tt;
 
375
                        tt = mm.replaceAll("<OL>$1</OL>");
 
376
                }
 
377
 
 
378
                ss = "";
 
379
                while (ss != tt) {
 
380
                        mm = ItemPattern.matcher(tt);
 
381
                        ss = tt;
 
382
                        tt = mm.replaceAll("<LI>");
 
383
                }
 
384
 
 
385
                ss = "";
 
386
                while (ss != tt) {
 
387
                        mm = TagPattern.matcher(tt);
 
388
                        ss = tt;
 
389
                        tt = mm.replaceAll("$1");
 
390
                }
 
391
                
 
392
                mm = AmpersandPattern.matcher(tt);
 
393
                tt = mm.replaceAll("&amp;");
 
394
 
 
395
                mm = LeftAnglePattern.matcher(tt);
 
396
                tt = mm.replaceAll("&lt;");
 
397
 
 
398
                mm = RightAnglePattern.matcher(tt);
 
399
                tt = mm.replaceAll("&gt;");     
 
400
 
 
401
                // Clean up the eol markers we used to mark end of line for items
 
402
                mm = EOLPattern.matcher(tt);
 
403
                tt = mm.replaceAll("");
 
404
                
 
405
                return tt;
 
406
        }
 
407
 
 
408
        private static MacroDef BuildMacroDef(Matcher m) {
 
409
                MacroDef md = new MacroDef();
 
410
 
 
411
                md.MacroName = m.group(MacroNameIndex);
 
412
 
 
413
                if (null != m.group(ParmsIndex)) {
 
414
                        String tt = killTagsParms(m.group(ParmsIndex));
 
415
                        String[] parms = tt.split(",\\s");
 
416
                        md.Parameters = new MacroParms(parms);
 
417
                }
 
418
                return md;
 
419
        }
 
420
 
 
421
        private static MacroParms AddMacroDefxParms(MacroParms mp, Matcher mx) {
 
422
                if (null != mx.group(ParmsIndex)) {
 
423
                        String tt = killTagsParms(mx.group(ParmsIndex));
 
424
                        String[] parms = tt.split(",\\s");
 
425
                        MacroParms mpnew = new MacroParms(parms);
 
426
                        mp.nextParms = mpnew;
 
427
                        return mpnew;
 
428
                }
 
429
                return null;
 
430
        }
 
431
 
 
432
        private static MacroDef HandleMacroDef(BufferedReader is, String s) throws IOException {
 
433
                MacroDef fd = null;
 
434
 
 
435
                Matcher m = MacroPattern.matcher(s);
 
436
 
 
437
                if (m.matches()) {
 
438
                        fd = BuildMacroDef(m);
 
439
                }
 
440
                else {                                          // assume the line got split and retry
 
441
                        is.mark(100);
 
442
                        String il = is.readLine();
 
443
                        m = MacroPattern.matcher(s + il);
 
444
                        if (m.matches()) fd = BuildMacroDef(m);
 
445
                        else {
 
446
                                is.reset();
 
447
                                m = MacroPattern2.matcher(s);
 
448
                                if (m.matches()) {
 
449
                                        fd = new MacroDef();
 
450
                                        fd.MacroName = m.group(MacroNameIndex);
 
451
                                        fd.Parameters = new MacroParms(new String[0]);
 
452
                                }
 
453
                        }
 
454
                }
 
455
                
 
456
                if (fd != null) {
 
457
                        // Look for @defmacx which are alternate prototypes for the macro
 
458
                        is.mark(100);
 
459
                        String il = is.readLine();
 
460
                        if (il != null) {
 
461
                                Matcher mx = MacroPatternx.matcher(il);
 
462
                                Matcher mx2 = MacroPatternx2.matcher(il);
 
463
                                MacroParms mp = fd.Parameters;
 
464
                                while (mx.matches() || mx2.matches()) {
 
465
                                        if (mx.matches())
 
466
                                        mp = AddMacroDefxParms(mp, mx);
 
467
                                        else {
 
468
                                                MacroParms mpnew = new MacroParms(new String[0]);
 
469
                                                mp.nextParms = mpnew;
 
470
                                                mp = mpnew;
 
471
                                        }
 
472
                                        is.mark(100);
 
473
                                        il = is.readLine();
 
474
                                        if (il != null) {
 
475
                                                mx = MacroPatternx.matcher(il);
 
476
                                                mx2 = MacroPatternx2.matcher(il);
 
477
                                        }
 
478
                                }
 
479
                                is.reset();
 
480
                        }
 
481
 
 
482
                        if (macroMap.get(fd.MacroName) != null)
 
483
                                return null;
 
484
                        macroMap.put(fd.MacroName, fd);
 
485
                }
 
486
 
 
487
                return fd;
 
488
        }
 
489
 
 
490
        private static void WriteString(BufferedWriter os, String s) throws IOException {
 
491
                //      System.out.println(s);
 
492
                os.write(s+"\n", 0, 1+s.length());
 
493
        }
 
494
        
 
495
    private static void CreateHeader(BufferedWriter os) throws IOException {
 
496
        WriteString(os, "<!-- This file automatically generated by ParseAutomakeTexinfo utility -->");
 
497
        WriteString(os, "<!-- cvs -d:pserver:anonymous@sources.redhat.com:/cvs/eclipse \\        -->");
 
498
        WriteString(os, "<!--   co autotools/ParseTexinfo                                       -->");
 
499
        WriteString(os, "<!DOCTYPE macros [");
 
500
        WriteString(os, "");
 
501
        WriteString(os, "  <!ELEMENT macros (macro)*>");
 
502
        WriteString(os, "");
 
503
        WriteString(os, "  <!ELEMENT macro (prototype*,synopsis)>");
 
504
        WriteString(os, "  <!ATTLIST macro");
 
505
        WriteString(os, "    id ID #REQUIRED");
 
506
        WriteString(os, "  >");
 
507
        WriteString(os, "");
 
508
        WriteString(os, "  <!ELEMENT synopsis     (#PCDATA)*>");
 
509
        WriteString(os, "");
 
510
        WriteString(os, "  <!ELEMENT prototype    (parameter+)?>");
 
511
        WriteString(os, "");
 
512
        WriteString(os, "  <!ELEMENT parameter (#PCDATA)*>");
 
513
        WriteString(os, "  <!ATTLIST parameter");
 
514
        WriteString(os, "    content CDATA #REQUIRED");
 
515
        WriteString(os, "  >");
 
516
        WriteString(os, "");
 
517
        WriteString(os, "]>");
 
518
        WriteString(os, "");
 
519
    }
 
520
 
 
521
 
 
522
 
 
523
        private static void CreateTrailer(BufferedWriter os) throws IOException {
 
524
                WriteString(os, "</macros>");
 
525
        }
 
526
 
 
527
        private static void WriteSynopsis(BufferedWriter os, String Synopsis, boolean indent)  throws IOException {
 
528
                String ss = Synopsis;
 
529
                String[] tt = ss.split("\\s");
 
530
                String aa = "";
 
531
                String spaces = indent ? "            " : "        ";
 
532
                WriteString(os, spaces + "<synopsis>");
 
533
                if (null != Synopsis) {
 
534
                        for (int pp = 0; pp < tt.length; pp++) {
 
535
                                if (tt[pp].equals("&lt;br&gt;")) {
 
536
                                        WriteString(os, spaces + aa + "&lt;/P&gt;&lt;P&gt;\n");
 
537
                                        aa = "";
 
538
                                }
 
539
                                else {
 
540
                                        if ((aa.length() + tt[pp].length()) > 64) {
 
541
                                                WriteString(os, spaces + aa);
 
542
                                                aa = "";
 
543
                                        }
 
544
                                        aa = aa + " " + tt[pp];
 
545
                                }
 
546
                        }
 
547
                }
 
548
                if (aa.length() > 0) WriteString(os, "        " + aa);
 
549
                WriteString(os, spaces + "</synopsis>");
 
550
        }
 
551
 
 
552
        private static void HandleDefmacro(BufferedWriter os, BufferedReader is, String s) throws IOException {
 
553
                String il;
 
554
                MacroDef md = null;
 
555
                List FDefs = new ArrayList();
 
556
 
 
557
                while (null != (il = is.readLine())) {
 
558
                        if (il.startsWith(Defmac)) {
 
559
                                if (null != (md = HandleMacroDef(is, il))) FDefs.add(md);
 
560
                        }
 
561
                        else if (il.startsWith("@comment") ||
 
562
                                        il.startsWith("@c ")) { // comment -- ignore it
 
563
                        }
 
564
                        else if (il.startsWith("@subsection") ||
 
565
                                        il.startsWith("@section")) {
 
566
                                for (int kk = 0; kk < FDefs.size(); kk++) {
 
567
                                        md = (MacroDef)FDefs.get(kk);
 
568
 
 
569
                                        WriteString(os, "  <macro id=\"" + md.MacroName + "\">");
 
570
 
 
571
                                        MacroParms mp = md.Parameters;
 
572
                                        do {
 
573
                                                WriteString(os, "      <prototype>");
 
574
                                                String[] parms = mp.parms;
 
575
                                                for (int i = 0; i < parms.length; i++) {
 
576
                                                        WriteString(os, "        <parameter content=\"" + parms[i] + "\"/>");
 
577
                                                }
 
578
                                                WriteString(os, "      </prototype>");
 
579
                                                mp = mp.nextParms;
 
580
                                        } while (mp != null);
 
581
 
 
582
                                        if (null != md.Synopsis) WriteSynopsis(os, md.Synopsis, false);
 
583
                                        
 
584
                                        WriteString(os, "  </macro>");
 
585
                                }
 
586
                                return;
 
587
                        }
 
588
                        else {
 
589
                                if (md != null)
 
590
                                        md.Synopsis = ((md.Synopsis == null) ? "" : md.Synopsis + " " ) + ((il.length() == 0) ? "&lt;br&gt;&lt;br&gt;" : 
 
591
                                                il.startsWith("@item") ? killTags(il) + "<eol>" : killTags(il));
 
592
                        }
 
593
                }
 
594
                FDefs.clear();
 
595
 
 
596
        }
 
597
 
 
598
        private static class OnlyTexi implements FilenameFilter {
 
599
                public boolean accept(File dir, String s) {
 
600
                        return (s.endsWith(".texi")) ? true : false;
 
601
                }
 
602
        }
 
603
 
 
604
        public static void BuildXMLFromTexinfo(String srcdir, String dstdir) {
 
605
                try {
 
606
                        macroMap = new HashMap();
 
607
                        BufferedWriter os = new BufferedWriter(new FileWriter(dstdir));
 
608
 
 
609
                        CreateHeader(os);
 
610
//                      CreateLicense(os);
 
611
 
 
612
                        WriteString(os, "<macros>");
 
613
 
 
614
                        try {
 
615
                                String[] dir = new java.io.File(srcdir).list(new OnlyTexi());
 
616
                                for (int i = 0; i < dir.length; i++) {
 
617
                                        String qFile = srcdir.endsWith("/")
 
618
                                        ? srcdir + dir[i]
 
619
                                                       : srcdir + "/" + dir[i];
 
620
 
 
621
                                        try {
 
622
                                                BufferedReader is = new BufferedReader(new FileReader(qFile));
 
623
                                                String il;
 
624
 
 
625
                                                while (null != (il = is.readLine())) {
 
626
                                                        Matcher mm1 = MacroSection1.matcher(il);
 
627
                                                        Matcher mm2 = MacroSection2.matcher(il);
 
628
                                                        if (mm1.matches() || mm2.matches()) {
 
629
                                                                HandleDefmacro(os, is, il);
 
630
                                                        }
 
631
                                                }
 
632
                                                is.close();
 
633
                                        }
 
634
                                        catch (IOException e) {
 
635
                                                System.out.println("Input File IOException: " + e);
 
636
                                                return;
 
637
                                        }
 
638
                                }
 
639
                        }
 
640
                        catch (NullPointerException e) {
 
641
                                System.out.println("NullPointerException: " + e);
 
642
                                return;
 
643
                        }
 
644
 
 
645
                        CreateTrailer(os);
 
646
 
 
647
                        os.close();
 
648
                }
 
649
                catch (IOException e) {
 
650
                        System.out.println("Output File IOException: " + e);
 
651
                        return;
 
652
                }
 
653
        }
 
654
 
 
655
        public static void main(String[] args) {
 
656
                // arg[0] is input directory containing .texi documents to read
 
657
                // arg[1] is output xml file to create
 
658
                BuildXMLFromTexinfo(args[0], args[1]);
 
659
        }
 
660
 
 
661
}