KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > codeswitcher > CodeSwitcher


1 package codeswitcher;
2
3 /* Copyrights and Licenses
4  *
5  * This product includes Hypersonic SQL.
6  * Originally developed by Thomas Mueller and the Hypersonic SQL Group.
7  *
8  * Copyright (c) 1995-2000 by the Hypersonic SQL Group. All rights reserved.
9  * Redistribution and use in source and binary forms, with or without modification, are permitted
10  * provided that the following conditions are met:
11  * - Redistributions of source code must retain the above copyright notice, this list of conditions
12  * and the following disclaimer.
13  * - Redistributions in binary form must reproduce the above copyright notice, this list of
14  * conditions and the following disclaimer in the documentation and/or other materials
15  * provided with the distribution.
16  * - All advertising materials mentioning features or use of this software must display the
17  * following acknowledgment: "This product includes Hypersonic SQL."
18  * - Products derived from this software may not be called "Hypersonic SQL" nor may
19  * "Hypersonic SQL" appear in their names without prior written permission of the
20  * Hypersonic SQL Group.
21  * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
22  * product includes Hypersonic SQL."
23  * This software is provided "as is" and any expressed or implied warranties, including, but
24  * not limited to, the implied warranties of merchantability and fitness for a particular purpose are
25  * disclaimed. In no event shall the Hypersonic SQL Group or its contributors be liable for any
26  * direct, indirect, incidental, special, exemplary, or consequential damages (including, but
27  * not limited to, procurement of substitute goods or services; loss of use, data, or profits;
28  * or business interruption). However caused any on any theory of liability, whether in contract,
29  * strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this
30  * software, even if advised of the possibility of such damage.
31  * This software consists of voluntary contributions made by many individuals on behalf of the
32  * Hypersonic SQL Group.
33  *
34  *
35  * For work added by the HSQL Development Group:
36  *
37  * Copyright (c) 2001-2002, The HSQL Development Group
38  * All rights reserved.
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions are met:
42  *
43  * Redistributions of source code must retain the above copyright notice, this
44  * list of conditions and the following disclaimer, including earlier
45  * license statements (above) and comply with all above license conditions.
46  *
47  * Redistributions in binary form must reproduce the above copyright notice,
48  * this list of conditions and the following disclaimer in the documentation
49  * and/or other materials provided with the distribution, including earlier
50  * license statements (above) and comply with all above license conditions.
51  *
52  * Neither the name of the HSQL Development Group nor the names of its
53  * contributors may be used to endorse or promote products derived from this
54  * software without specific prior written permission.
55  *
56  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
57  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59  * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
60  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
61  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
62  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
63  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
64  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
66  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67  *
68  * Work added by 3SP <a HREF="http://3sp.com">http://3sp.com</a> for
69  * the SSL-Explorer build system is licensed under the Apache license. See
70  * APACHE_LICENSE.txt in the root of this build module.
71  */

72
73 import java.io.File JavaDoc;
74 import java.io.FileReader JavaDoc;
75 import java.io.FileWriter JavaDoc;
76 import java.io.IOException JavaDoc;
77 import java.io.LineNumberReader JavaDoc;
78 import java.util.Vector JavaDoc;
79
80 // fredt@users 20020315 - patch 1.7.0 - minor fixes
81
// changed line separator to System based value
82
// moved the Profile class to org.hsqldb.test package
83
// fredt@users 20021020 - patch 1.7.1 - formatting fix
84
// avoid moving blank lines which would be interpreted as code change by CVS
85
// fredt@users 20021118 - patch 1.7.2 - no-change, no-save fix
86
// if the file contents do not change, do not save a new version of file
87

88 /**
89  * Modifies the source code to support different JDK or profile settings. <p>
90  * <pre>
91  * Usage: java CodeSwitcher [paths] [labels] [+][-]
92  * If no labels are specified then all used
93  * labels in the source code are shown.
94  * Use +MODE to switch on the things labeld MODE
95  * Use -MODE to switch off the things labeld MODE
96  * Path: Any number of path or files may be
97  * specified. Use . for the current directory
98  * (including sub-directories).
99  * Example: java CodeSwitcher +JAVA2 .
100  * This example switches on code labeled JAVA2
101  * in all *.java files in the current directory
102  * and all subdirectories.
103  * java CodeSwitcher + .
104  * Adds test code to the code.
105  * java CodeSwitcher - .
106  * Removes test code from the code
107  * </pre>
108  *
109  */

110 public class CodeSwitcher {
111
112     private static final String JavaDoc ls = System.getProperty("line.separator",
113     "\n");
114     private Vector JavaDoc vList;
115     private Vector JavaDoc vSwitchOn;
116     private Vector JavaDoc vSwitchOff;
117     private Vector JavaDoc vSwitches;
118     private boolean bAdd, bRemove;
119     private static final int MAX_LINELENGTH = 82;
120     private static boolean quiet;
121 // private boolean comment = true;
122

123     /**
124      * Method declaration
125      *
126      *
127      * @param a
128      */

129     public static void main(String JavaDoc a[]) {
130
131         CodeSwitcher s = new CodeSwitcher();
132
133         if (a.length == 0) {
134             showUsage();
135
136             return;
137         }
138
139         boolean path = false;
140
141         for (int i = 0; i < a.length; i++) {
142             String JavaDoc p = a[i];
143             if (p.equalsIgnoreCase("/strip")) {
144                 System.err.println("WARNING: /STRIP is deprecated, now always strips. ");
145 // s.comment = false;
146
}
147             else if (p.startsWith("#")) {
148                 String JavaDoc opt = p.substring(1);
149                 if(opt.equalsIgnoreCase("strip")) {
150                     System.err.println("WARNING: #STRIP is deprecated, now always strips. ");
151 // s.comment = false;
152
}
153                 else if(opt.equalsIgnoreCase("quiet")) {
154                     quiet = true;
155                 }
156             }
157             else if (p.startsWith("+")) {
158                 if (p.length() == 1) {
159                     s.bAdd = true;
160                 } else {
161                     s.vSwitchOn.addElement(p.substring(1));
162                 }
163             } else if (p.startsWith("-")) {
164                 if (p.length() == 1) {
165                     s.bRemove = true;
166                 } else {
167                     s.vSwitchOff.addElement(p.substring(1));
168                 }
169             } else {
170                 s.addDir(p);
171
172                 path = true;
173             }
174         }
175
176         if (!path) {
177             printError("no path specified");
178             showUsage();
179         }
180
181         s.process();
182
183         if (s.vSwitchOff.size() == 0 && s.vSwitchOn.size() == 0) {
184             s.printSwitches();
185         }
186     }
187
188     /**
189      * Method declaration
190      *
191      */

192     static void showUsage() {
193
194         System.out.print("Usage: java CodeSwitcher [paths] [labels] [+][-]\n"
195                 + "If no labels are specified then all used\n"
196                 + "labels in the source code are shown.\n"
197                 + "Use +MODE to switch on the things labeld MODE\n"
198                 + "Use -MODE to switch off the things labeld MODE\n"
199                 + "Path: Any number of path or files may be\n"
200                 + "specified. Use . for the current directory\n"
201                 + "(including sub-directories).\n"
202                 + "Example: java CodeSwitcher +JAVA2 .\n"
203                 + "This example switches on code labeled JAVA2\n"
204                 + "in all *.java files in the current directory\n"
205                 + "and all subdirectories.\n"
206                 + "java CodeSwitcher + .\n"
207                 + "Adds test code to the code.\n"
208                 + "java CodeSwitcher - .\n"
209                 + "Removed test code from the code.\n");
210     }
211
212     /**
213      * Constructor declaration
214      *
215      */

216     CodeSwitcher() {
217
218         vList = new Vector JavaDoc();
219         vSwitchOn = new Vector JavaDoc();
220         vSwitchOff = new Vector JavaDoc();
221         vSwitches = new Vector JavaDoc();
222     }
223
224     /**
225      * Method declaration
226      *
227      */

228     void process() {
229
230         int len = vList.size();
231
232         for (int i = 0; i < len; i++) {
233 // System.out.print(".");
234

235             String JavaDoc file = (String JavaDoc) vList.elementAt(i);
236
237             if (bAdd || bRemove) {
238                 int maxlen = testFile(file);
239
240                 if (bAdd &&!bRemove) {
241                     addTest(file, maxlen);
242                 } else {
243                     removeTest(file);
244                 }
245             } else {
246                 if (!processFile(file)) {
247                     printError("in file " + file + " !");
248                 }
249             }
250         }
251
252         System.out.println("");
253     }
254
255     /**
256      * Method declaration
257      *
258      */

259     void printSwitches() {
260
261         System.out.println("Used labels:");
262
263         for (int i = 0; i < vSwitches.size(); i++) {
264             System.out.println((String JavaDoc) (vSwitches.elementAt(i)));
265         }
266     }
267
268     /**
269      * Method declaration
270      *
271      *
272      * @param path
273      */

274     void addDir(String JavaDoc path) {
275         File JavaDoc f = new File JavaDoc(path);
276
277         if (f.isFile() && path.endsWith(".java")) {
278             vList.addElement(path);
279         } else if (f.isDirectory()) {
280             String JavaDoc list[] = f.list();
281
282             for (int i = 0; i < list.length; i++) {
283                 addDir(path + File.separatorChar + list[i]);
284             }
285         }
286     }
287
288     /**
289      * Method declaration
290      *
291      *
292      * @param name
293      */

294     void removeTest(String JavaDoc name) {
295
296         File JavaDoc f = new File JavaDoc(name);
297         File JavaDoc fnew = new File JavaDoc(name + ".new");
298         
299         LineNumberReader JavaDoc read = null;
300         FileWriter JavaDoc write = null;
301
302         try {
303             read = new LineNumberReader JavaDoc(new FileReader JavaDoc(f));
304             write = new FileWriter JavaDoc(fnew);
305
306             while (true) {
307                 String JavaDoc line = read.readLine();
308
309                 if (line == null) {
310                     break;
311                 }
312
313                 if (line.startsWith("Profile.visit(")) {
314                     int s = line.indexOf(';');
315
316                     line = line.substring(s + 1);
317                 }
318
319                 write.write(line + ls);
320             }
321
322             read.close();
323             read = null;
324             write.flush();
325             write.close();
326             write = null;
327
328             File JavaDoc fbak = new File JavaDoc(name + ".bak");
329
330             fbak.delete();
331             f.renameTo(fbak);
332
333             File JavaDoc fcopy = new File JavaDoc(name);
334
335             fnew.renameTo(fcopy);
336             fbak.delete();
337         } catch (Exception JavaDoc e) {
338             printError(e.getMessage());
339         }
340         finally {
341             if(read != null) {
342                 try {
343                     read.close();
344                 } catch (IOException JavaDoc e1) {
345                 }
346             }
347             if(write != null) {
348                 try {
349                     write.close();
350                 } catch (IOException JavaDoc e1) {
351                 }
352             }
353         }
354     }
355
356     /**
357      * Method declaration
358      *
359      *
360      * @param name
361      * @param maxline
362      */

363     void addTest(String JavaDoc name, int maxline) {
364
365         File JavaDoc f = new File JavaDoc(name);
366         File JavaDoc fnew = new File JavaDoc(name + ".new");
367         String JavaDoc key = name;
368
369         key = key.replace('\\', '.');
370         LineNumberReader JavaDoc read = null;
371         FileWriter JavaDoc write = null;
372
373         try {
374             read = new LineNumberReader JavaDoc(new FileReader JavaDoc(f));
375             write = new FileWriter JavaDoc(fnew);
376             int l = 0;
377             boolean longline = false;
378
379             while (true) {
380                 String JavaDoc line = read.readLine();
381
382                 if (line == null) {
383                     break;
384                 }
385
386                 if (line.startsWith(" ")) {
387                     int spaces = 0;
388
389                     for (; spaces < line.length(); spaces++) {
390                         if (line.charAt(spaces) != ' ') {
391                             break;
392                         }
393                     }
394
395                     if (spaces > 3 && testLine(line) &&!longline) {
396                         line = "org.hsqldb.test.Profile.visit(\"" + key
397                         + "\"," + l + "," + maxline + ");" + line;
398
399                         l++;
400                     } else if (isLongline(line)) {
401                         longline = true;
402                     } else {
403                         longline = false;
404                     }
405                 }
406
407                 write.write(line + ls);
408             }
409
410             read.close();
411             read = null;
412             write.flush();
413             write.close();
414             write = null;
415
416             File JavaDoc fbak = new File JavaDoc(name + ".bak");
417
418             fbak.delete();
419             f.renameTo(fbak);
420
421             File JavaDoc fcopy = new File JavaDoc(name);
422
423             fnew.renameTo(fcopy);
424             fbak.delete();
425         } catch (Exception JavaDoc e) {
426             printError(e.getMessage());
427         }
428         finally {
429
430             if(read != null) {
431                 try {
432                     read.close();
433                 } catch (IOException JavaDoc e1) {
434                 }
435             }
436             if(write != null) {
437                 try {
438                     write.close();
439                 } catch (IOException JavaDoc e1) {
440                 }
441             }
442         }
443     }
444
445     /**
446      * Method declaration
447      *
448      *
449      * @param name
450      *
451      * @return
452      */

453     int testFile(String JavaDoc name) {
454
455         File JavaDoc f = new File JavaDoc(name);
456         LineNumberReader JavaDoc read = null;
457
458         try {
459             read = new LineNumberReader JavaDoc(new FileReader JavaDoc(f));
460             int l = 1,
461             maxline = 0;
462             boolean longline = false;
463
464             while (true) {
465                 String JavaDoc line = read.readLine();
466
467                 if (line == null) {
468                     break;
469                 }
470
471                 if (line.length() > MAX_LINELENGTH
472                         &&!line.startsWith("org.hsqldb.test.Profile.")) {
473                     System.out.println("long line in " + name + " at line "
474                             + l);
475                 }
476
477                 if (line.startsWith(" ")) {
478                     int spaces = 0;
479
480                     for (; spaces < line.length(); spaces++) {
481                         if (line.charAt(spaces) != ' ') {
482                             break;
483                         }
484                     }
485
486                     if (spaces > 3 && testLine(line) &&!longline) {
487                         maxline++;
488                     } else if (isLongline(line)) {
489                         longline = true;
490                     } else {
491                         longline = false;
492                     }
493
494                     String JavaDoc s = line.substring(spaces);
495
496                     if (s.startsWith("if(")) {
497                         if (!s.endsWith(" {")) {
498                             System.out.println("if( without { in " + name
499                                     + " at line " + l);
500                         }
501                     } else if (s.startsWith("} else if(")) {
502                         if (!s.endsWith(" {")) {
503                             System.out.println("} else if without { in "
504                                     + name + " at line " + l);
505                         }
506                     } else if (s.startsWith("while(")) {
507                         if (!s.endsWith(" {")) {
508                             System.out.println("while( without { in " + name
509                                     + " at line " + l);
510                         }
511                     } else if (s.startsWith("switch(")) {
512                         if (!s.endsWith(" {")) {
513                             System.out.println("switch( without { in " + name
514                                     + " at line " + l);
515                         }
516                     } else if (s.startsWith("do ")) {
517                         if (!s.endsWith(" {")) {
518                             System.out.println("do without { in " + name
519                                     + " at line " + l);
520                         }
521                     }
522                 }
523
524                 l++;
525             }
526
527             return maxline;
528         } catch (Exception JavaDoc e) {
529             printError(e.getMessage());
530         }
531         finally {
532
533             if(read != null) {
534                 try {
535                     read.close();
536                 } catch (IOException JavaDoc e1) {
537                 }
538             }
539         }
540
541         return -1;
542     }
543
544     /**
545      * Method declaration
546      *
547      *
548      * @param line
549      *
550      * @return
551      */

552     boolean testLine(String JavaDoc line) {
553
554         if (!line.endsWith(";")) {
555             return false;
556         }
557
558         if (line.trim().startsWith("super(")) {
559             return false;
560         }
561
562         return true;
563     }
564
565     /**
566      * Method declaration
567      *
568      *
569      * @param s
570      *
571      * @return
572      */

573     boolean isLongline(String JavaDoc s) {
574
575         char c = s.charAt(s.length() - 1);
576
577         if (",(+-&|".indexOf(c) >= 0) {
578             return true;
579         }
580
581         return false;
582     }
583
584     /**
585      * Method declaration
586      *
587      *
588      * @param name
589      *
590      * @return
591      */

592     boolean processFile(String JavaDoc name) {
593
594         File JavaDoc f = new File JavaDoc(name);
595         File JavaDoc fnew = new File JavaDoc(name + ".new");
596         int state = 0; // 0=normal 1=inside_if 2=inside_else
597
boolean switchoff = false;
598         boolean working = false;
599         int removeFrom = -1;
600
601         try {
602             Vector JavaDoc v = getFileLines(f);
603             Vector JavaDoc v1 = new Vector JavaDoc(v.size());
604
605             for (int i = 0; i < v.size(); i++) {
606                 v1.addElement(v.elementAt(i));
607             }
608
609             for (int i = 0; i < v.size(); i++) {
610                 String JavaDoc line = (String JavaDoc) v.elementAt(i);
611
612                 if (line == null) {
613                     break;
614                 }
615                 
616                 String JavaDoc lineTrimmed = trimBoth(line);
617                 String JavaDoc lineStripped = stripSpaces(line);
618
619                 if (working) {
620                     if (lineTrimmed.equals("/*") || lineTrimmed.equals("*/")) {
621                         v.removeElementAt(i--);
622                         continue;
623                     }
624                     else if(lineTrimmed.startsWith("*")) {
625                       int idx = line.indexOf('*');
626                       v.setElementAt(line.substring(0, idx) + line.substring(idx + 1), i);
627                     }
628                     
629                 }
630
631                 if (lineStripped.indexOf("//#") != -1) {
632                     if (lineStripped.startsWith("//#ifdef")) {
633                         if (state != 0) {
634                             printError(
635                             "'#ifdef' not allowed inside '#ifdef'");
636
637                             return false;
638                         }
639
640                         state = 1;
641                         removeFrom = -1;
642
643                         String JavaDoc s = lineStripped.substring(8);
644
645                         if ( vSwitchOn.indexOf(s) != -1) {
646                             
647 // if(!comment) {
648
v.remove(i--);
649 // }
650
printMessage(f, i, "Including " + s);
651                             working = true;
652                             switchoff = false;
653                         } else if (vSwitchOff.indexOf(s) != -1) {
654                             printMessage(f, i, "Excluding " + s);
655                             working = true;
656 // if(comment) {
657
// v.insertElementAt("/*", i);
658
// }
659
// else {
660
removeFrom = i;
661 // }
662

663                             switchoff = true;
664                         }
665
666                         if (vSwitches.indexOf(s) == -1) {
667                             vSwitches.addElement(s);
668                         }
669                     } else if (lineStripped.startsWith("//#else")) {
670                         if (state != 1) {
671                             printError("'#else' without '#ifdef'");
672
673                             return false;
674                         }
675
676                         state = 2;
677
678                         if (!working) {}
679                         else if (switchoff) {
680 // if(comment) {
681
// if (v.elementAt(i - 1).equals("")) {
682
// v.insertElementAt("*/", i - 1);
683
//
684
// i++;
685
// } else {
686
// v.insertElementAt("*/", i++);
687
// }
688
// }
689
// else {
690
if(removeFrom != -1) {
691                                     for(int j = i ; j >= removeFrom; j--) {
692                                         v.remove(j);
693                                         i--;
694                                     }
695                                     removeFrom = -1;
696                                 }
697 // }
698

699                             switchoff = false;
700                         } else {
701 // if(comment) {
702
// v.insertElementAt("/*", ++i);
703
// }
704
// else {
705
printMessage(f, i, "Will remove from " + i);
706                                 removeFrom = i;
707 // }
708

709                             switchoff = true;
710                         }
711                     } else if (lineStripped.startsWith("//#endif")) {
712                         if (state == 0) {
713                             printError("'#endif' without '#ifdef'");
714
715                             return false;
716                         }
717
718                         state = 0;
719
720                         if (working) {
721                             if(switchoff) {
722                                 if (v.elementAt(i - 1).equals("")) {
723 // if(comment) {
724
v.insertElementAt("*/", i - 1);
725                                         i++;
726 // }
727
} else {
728 // if(comment) {
729
v.insertElementAt("*/", i++);
730 // }
731
}
732                                 
733                                 if(removeFrom != -1) {
734                                     printMessage(f, removeFrom, "Removing " + ( i - removeFrom) + " lines");
735                                     for(int j = i ; j >= removeFrom; j--) {
736                                         printMessage(f, i, "Removing '" + v.remove(j) + "'");
737                                         i--;
738                                     }
739                                     removeFrom = -1;
740                                 }
741                             }
742                             else {
743 // if(!comment) {
744
v.removeElementAt(i--);
745 // }
746
}
747                         }
748
749                         working = false;
750                         switchoff = false;
751                     } else {}
752                 }
753             }
754
755             if (state != 0) {
756                 printError("'#endif' missing");
757
758                 return false;
759             }
760
761             boolean filechanged = false;
762
763             for (int i = 0; i < v.size(); i++) {
764                 if (!v1.elementAt(i).equals(v.elementAt(i))) {
765                     filechanged = true;
766
767                     break;
768                 }
769             }
770
771             if (!filechanged) {
772                 return true;
773             }
774
775             writeFileLines(v, fnew);
776
777             File JavaDoc fbak = new File JavaDoc(name + ".bak");
778
779             fbak.delete();
780             f.renameTo(fbak);
781
782             File JavaDoc fcopy = new File JavaDoc(name);
783
784             fnew.renameTo(fcopy);
785             fbak.delete();
786
787             return true;
788         } catch (Exception JavaDoc e) {
789             printError(e.getMessage());
790
791             return false;
792         }
793     }
794
795     static Vector JavaDoc getFileLines(File JavaDoc f) throws IOException JavaDoc {
796
797         LineNumberReader JavaDoc read = null ;
798         Vector JavaDoc v = new Vector JavaDoc();
799         try {
800             read = new LineNumberReader JavaDoc(new FileReader JavaDoc(f));
801
802         for (;;) {
803             String JavaDoc line = read.readLine();
804
805             if (line == null) {
806                 break;
807             }
808
809             v.addElement(line);
810         }
811         }
812         finally {
813             if(read != null) {
814                 read.close();
815             }
816         }
817
818         return v;
819     }
820     
821     static String JavaDoc trimBoth(String JavaDoc text) {
822       text = text.trim();
823       int s = text.length();
824       char ch;
825       int i;
826       for(i = 0 ; i < s && Character.isWhitespace((ch = text.charAt(i))); i++);
827       return i < s ? text.substring(i) : text;
828     }
829     
830     static String JavaDoc stripSpaces(String JavaDoc text) {
831       StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
832       int s = text.length();
833       char ch;
834       for(int i = 0 ; i < s; i++) {
835         ch = text.charAt(i);
836         if(!Character.isWhitespace(ch)) {
837           buf.append(ch);
838         }
839       }
840       return buf.toString();
841     }
842
843     static void writeFileLines(Vector JavaDoc v, File JavaDoc f) throws IOException JavaDoc {
844
845         FileWriter JavaDoc write = null;
846         try {
847             write = new FileWriter JavaDoc(f);
848
849         for (int i = 0; i < v.size(); i++) {
850             write.write((String JavaDoc) v.elementAt(i));
851             write.write(ls);
852         }
853
854         write.flush();
855         }
856         finally {
857             if(write != null ) {
858                 write.close();
859                 
860             }
861         }
862     }
863
864     /**
865      * Method declaration
866      *
867      *
868      * @param error
869      */

870     static void printError(String JavaDoc error) {
871         System.out.println("ERROR: " + error);
872     }
873
874     /**
875      * Method declaration
876      *
877      *
878      * @param error
879      */

880     static void printMessage(File JavaDoc f, int line, String JavaDoc message) {
881         if(!quiet)
882             System.out.println("MSG: " + f.getName() + "[" + line + "] " + message);
883     }
884     
885     public static void Xmain(String JavaDoc args[]) {
886         System.out.println(stripSpaces(trimBoth("//#ifdef XTRA")));
887         System.out.println(stripSpaces(trimBoth("\t\t \t//#ifdef XTRA")));
888         System.out.println(stripSpaces(trimBoth("\t\t \t//# ifdef XTRA")));
889         System.out.println(stripSpaces(trimBoth("\t\t \t// # ifdef XTRA")));
890         System.out.println(stripSpaces(trimBoth("//# ifdef XTRA")));
891         System.out.println(stripSpaces(trimBoth("// # ifdef\t \t XTRA")));
892         System.out.println(stripSpaces(trimBoth("// # ifdef XTRA")));
893     }
894 }
895
Popular Tags