Methods Summary |
---|
static java.lang.String | findSubDir(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 void | main(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 void | process(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.String | process(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 void | process(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 void | usage()
System.out.println("Usage: java -jar buildtool.jar " +
"mjpp -srcroot <dir> -outdir <dir> files ...");
|