Return one argument.
if (optind == (argv.length)) {
done = true;
}
// Do not combine with previous if statement.
if (done) {
return DONE;
}
// Pick off the next command line argument, check if it starts "-".
// If so look it up in the list.
String thisArg = argv[optind++];
if (thisArg.startsWith("-")) {
optarg = null;
for (int i=0; i<pattern.length(); i++) {
char c = pattern.charAt(i);
if (thisArg.equals("-"+c)) { // we found it
// If it needs an option argument, get it.
if (i+1 < pattern.length() &&
pattern.charAt(i+1)==':" &&
optind < argv.length)
optarg = argv[optind++];
return c;
}
}
// Still no match, and not used all args, so must be error.
return '?";
} else {
// Found non-argument non-option word in argv: end of options.
done = true;
return DONE;
}