FileDocCategorySizeDatePackage
Main.javaAPI DocphoneME MR2 API (J2ME)6164Wed May 02 17:59:48 BST 2007mjpp

Main

public class Main extends Object
Java preprocessor -- Preprocess java source files to reduce footprint. See $(JVMWorkSpace)/internal_doc/BuildSystem.html for more information.

Fields Summary
static boolean
do_strip
Constructors Summary
Methods Summary
static java.lang.StringfindSubDir(java.util.Vector roots, java.lang.String file)

        for (int i=0; i<roots.size(); i++) {
            String root = (String)roots.elementAt(i);
            if (file.startsWith(root)) {
                file = file.substring(root.length());
                while (file.startsWith(File.separator)) {
                    file = file.substring(1);
                }
                File f = new File(file);
                return f.getParent();
            }
        }
        throw new RuntimeException("root not known: " + file);
    
public static voidmain(java.lang.String[] args)


           
        Vector roots = new Vector();
        Vector files = new Vector();
        Vector output = new Vector();
        int i;

        String outdir = null;
        for (i=0; i<args.length; ) {
            if (args[i].equals("-srcroot")) {
                roots.addElement(args[i+1]); 
                i+=2;
            } else if (args[i].equals("-outdir")) {
                outdir = args[i+1];
                i+=2;
            } else if (args[i].equals("-n")) {
                do_strip = false;
                i++;
            } else {
                files.addElement(args[i]);
                i++;
            }
        }

        if (outdir == null) {
            System.err.println("-outdir not specified");
            System.exit(-1);
        }
        if (roots.size() == 0) {
            System.err.println("-srcroot not specified");
            System.exit(-1);
        }

        process(outdir, roots, files, output);
        for (i=0; i<output.size(); i++) {
            System.out.print(output.elementAt(i));
            System.out.print(" ");
        }
    
public static voidprocess(java.lang.String outdir, java.util.Vector roots, java.util.Vector files, java.util.Vector output)

        File file = new File(outdir);
        if (!file.exists()) {
            file.mkdirs();
        }
        for (int i=0; i<files.size(); i++) {
            String f = process(outdir, roots, (String)files.elementAt(i));
            output.addElement(f);
        }
    
static java.lang.Stringprocess(java.lang.String outdir, java.util.Vector roots, java.lang.String file)

        String subdir = findSubDir(roots, file);
        File dir = new File(outdir);
        dir = new File(dir, subdir);
        if (!dir.exists()) {
            dir.mkdirs();
        }

        File inf  = new File(file);
        File outf = new File(dir, inf.getName());
        process(inf, outf);

        return outf.toString().replace('\\", '/");
    
static voidprocess(java.io.File inf, java.io.File outf)

        FileInputStream in = new FileInputStream(inf);
        FileOutputStream out = new FileOutputStream(outf);
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(out));
        String s;

        boolean skipping = false;
        String startPrefix = "/* #if";
        String endPrefix   = "/* #endif */";
        int lineno = 0;
        while ((s = reader.readLine()) != null) {
            lineno ++;
            if (do_strip && s.startsWith(startPrefix)) {
                if (skipping) {
                    System.err.println("Error in " + inf + ": " + lineno);
                    System.err.println("/* #ifxxx cannot be nested (yet)! */");
                    writer.close();
                    System.exit(1);
                } else {
                    skipping = true;
                }
                writer.println(s);
            } else if (do_strip && s.startsWith(endPrefix)) {
                if (!skipping) {
                    System.err.println("Error in " + inf + ": " + lineno);
                    System.err.println("unexpected /* #endif */");
                    writer.close();
                    System.exit(1);
                } else {
                    skipping = false;
                }
                writer.println(s);
            } else {
                if (skipping) {
                    writer.print("/// skipped ");
                }
                writer.println(s);
            }
        }
        if (skipping) {
            System.err.println("Error in " + inf + ": " + lineno);
            System.err.println("missing /* #endif */");
            writer.close();
            System.exit(1);
        }

        writer.close();
        reader.close();
    
static voidusage()

        System.out.println("Usage: java -jar buildtool.jar " +
                           "mjpp -srcroot <dir> -outdir <dir> files ...");