Source Code Cross Referenced for Main.java in  » 6.0-JDK-Modules » j2me » mjpp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » mjpp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *   
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:
027:        package mjpp;
028:
029:        import java.io.*;
030:        import java.util.*;
031:        import util.*;
032:
033:        /**
034:         * Java preprocessor --
035:         * Preprocess java source files to reduce footprint.
036:         *
037:         * See $(JVMWorkSpace)/internal_doc/BuildSystem.html for more
038:         * information.
039:         */
040:        public class Main {
041:            static void usage() {
042:                System.out.println("Usage: java -jar buildtool.jar "
043:                        + "mjpp -srcroot <dir> -outdir <dir> files ...");
044:            }
045:
046:            static boolean do_strip = true;
047:
048:            public static void main(String args[]) throws Throwable {
049:                Vector roots = new Vector();
050:                Vector files = new Vector();
051:                Vector output = new Vector();
052:                int i;
053:
054:                String outdir = null;
055:                for (i = 0; i < args.length;) {
056:                    if (args[i].equals("-srcroot")) {
057:                        roots.addElement(args[i + 1]);
058:                        i += 2;
059:                    } else if (args[i].equals("-outdir")) {
060:                        outdir = args[i + 1];
061:                        i += 2;
062:                    } else if (args[i].equals("-n")) {
063:                        do_strip = false;
064:                        i++;
065:                    } else {
066:                        files.addElement(args[i]);
067:                        i++;
068:                    }
069:                }
070:
071:                if (outdir == null) {
072:                    System.err.println("-outdir not specified");
073:                    System.exit(-1);
074:                }
075:                if (roots.size() == 0) {
076:                    System.err.println("-srcroot not specified");
077:                    System.exit(-1);
078:                }
079:
080:                process(outdir, roots, files, output);
081:                for (i = 0; i < output.size(); i++) {
082:                    System.out.print(output.elementAt(i));
083:                    System.out.print(" ");
084:                }
085:            }
086:
087:            public static void process(String outdir, Vector roots,
088:                    Vector files, Vector output) throws Throwable {
089:                File file = new File(outdir);
090:                if (!file.exists()) {
091:                    file.mkdirs();
092:                }
093:                for (int i = 0; i < files.size(); i++) {
094:                    String f = process(outdir, roots, (String) files
095:                            .elementAt(i));
096:                    output.addElement(f);
097:                }
098:            }
099:
100:            static String process(String outdir, Vector roots, String file)
101:                    throws IOException {
102:                String subdir = findSubDir(roots, file);
103:                File dir = new File(outdir);
104:                dir = new File(dir, subdir);
105:                if (!dir.exists()) {
106:                    dir.mkdirs();
107:                }
108:
109:                File inf = new File(file);
110:                File outf = new File(dir, inf.getName());
111:                process(inf, outf);
112:
113:                return outf.toString().replace('\\', '/');
114:            }
115:
116:            /*
117:             * IMPL_NOTE: currently the preprocessor doesn't look at the 
118:             * parameter of the #{if,ifdef,ifndef} directive. It just
119:             * blindly removes everything between #if ... #endif
120:             */
121:            static void process(File inf, File outf) throws IOException {
122:                FileInputStream in = new FileInputStream(inf);
123:                FileOutputStream out = new FileOutputStream(outf);
124:                BufferedReader reader = new BufferedReader(
125:                        new InputStreamReader(in));
126:                PrintWriter writer = new PrintWriter(
127:                        new OutputStreamWriter(out));
128:                String s;
129:
130:                boolean skipping = false;
131:                String startPrefix = "/* #if";
132:                String endPrefix = "/* #endif */";
133:                int lineno = 0;
134:                while ((s = reader.readLine()) != null) {
135:                    lineno++;
136:                    if (do_strip && s.startsWith(startPrefix)) {
137:                        if (skipping) {
138:                            System.err.println("Error in " + inf + ": "
139:                                    + lineno);
140:                            System.err
141:                                    .println("/* #ifxxx cannot be nested (yet)! */");
142:                            writer.close();
143:                            System.exit(1);
144:                        } else {
145:                            skipping = true;
146:                        }
147:                        writer.println(s);
148:                    } else if (do_strip && s.startsWith(endPrefix)) {
149:                        if (!skipping) {
150:                            System.err.println("Error in " + inf + ": "
151:                                    + lineno);
152:                            System.err.println("unexpected /* #endif */");
153:                            writer.close();
154:                            System.exit(1);
155:                        } else {
156:                            skipping = false;
157:                        }
158:                        writer.println(s);
159:                    } else {
160:                        if (skipping) {
161:                            writer.print("/// skipped ");
162:                        }
163:                        writer.println(s);
164:                    }
165:                }
166:                if (skipping) {
167:                    System.err.println("Error in " + inf + ": " + lineno);
168:                    System.err.println("missing /* #endif */");
169:                    writer.close();
170:                    System.exit(1);
171:                }
172:
173:                writer.close();
174:                reader.close();
175:            }
176:
177:            static String findSubDir(Vector roots, String file) {
178:                for (int i = 0; i < roots.size(); i++) {
179:                    String root = (String) roots.elementAt(i);
180:                    if (file.startsWith(root)) {
181:                        file = file.substring(root.length());
182:                        while (file.startsWith(File.separator)) {
183:                            file = file.substring(1);
184:                        }
185:                        File f = new File(file);
186:                        return f.getParent();
187:                    }
188:                }
189:                throw new RuntimeException("root not known: " + file);
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.