boolean numeric_option = false;
boolean errs = false;
String outputFileName = null;
GetOptDesc options[] = {
new GetOptDesc('n", "numeric", false),
new GetOptDesc('o", "output-file", true),
};
GetOpt parser = new GetOpt(options);
Map optionsFound = parser.parseArguments(argv);
Iterator it = optionsFound.keySet().iterator();
while (it.hasNext()) {
String key = (String)it.next();
char c = key.charAt(0);
switch (c) {
case 'n":
numeric_option = true;
break;
case 'o":
outputFileName = (String)optionsFound.get(key);
break;
case '?":
errs = true;
break;
default:
throw new IllegalStateException(
"Unexpected option character: " + c);
}
}
if (errs) {
System.err.println("Usage: GetOptDemo [-n][-o file][file...]");
}
System.out.print("Options: ");
System.out.print("Numeric: " + numeric_option + ' ");
System.out.print("Output: " + outputFileName + "; ");
System.out.print("Input files: ");
Iterator files = parser.getFilenameList().iterator();
while (files.hasNext()) {
System.out.print(files.next());
System.out.print(' ");
}
System.out.println();