/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: GetOpt.java,v 1.2.4.1 2005/08/31 11:46:04 pvedula Exp $
*/
/**
* GetOpt is a Java equivalent to the C getopt() library function
* discussed in man page getopt(3C). It provides command line
* parsing for Java applications. It supports the most rules of the
* command line standard (see man page intro(1)) including stacked
* options such as '-sxm' (which is equivalent to -s -x -m); it
* handles special '--' option that signifies the end of options.
* Additionally this implementation of getopt will check for
* mandatory arguments to options such as in the case of
* '-d <file>' it will throw a MissingOptArgException if the
* option argument '<file>' is not included on the commandline.
* getopt(3C) does not check for this.
* @author G Todd Miller
*/
public class GetOpt{
theOptions = new ArrayList();
int currOptIndex = 0;
theCmdArgs = new ArrayList();
// fill in the options list
break; // end of options
}
// simple option token such as '-s' found
}
// stacked options found, such as '-shm'
// iterate thru the tokens after the dash and
// add them to theOptions list
for(int j=1; j<tokenLength; j++){
}
}
// case 1- there are not options stored yet therefore
// this must be an command argument, not an option argument
currOptIndex = i;
break; // stop processing options
}
else {
// case 2-
// there are options stored, check to see if
// this arg belong to the last arg stored
int indexoflast=0;
}
else{
// case 3 -
// the last option stored does not take
// an argument, so again, this argument
// must be a command argument, not
// an option argument
currOptIndex = i;
break; // end of options
}
}
}// end option does not start with "-"
} // end for args loop
// attach an iterator to list of options
// options are done, now fill out cmd arg list with remaining args
}
}
/**
* debugging routine to print out all options collected
*/
public void printOptions(){
}
}
}
/**
* gets the next option found in the commandline. Distinguishes
* between two bad cases, one case is when an illegal option
* is found, and then other case is when an option takes an
* argument but no argument was found for that option.
* If the option found was not declared in the optString, then
* an IllegalArgumentException will be thrown (case 1).
* If the next option found has been declared to take an argument,
* and no such argument exists, then a MissingOptArgException
* is thrown (case 2).
* @param none
* @return int - the next option found.
* @throws IllegalArgumentException, MissingOptArgException.
*/
{
int retval = -1;
if(theOptionsIterator.hasNext()){
char c = theCurrentOption.getArgLetter();
if(!theOptionMatcher.match(c)) {
new Character(c));
}
new Character(c));
}
retval = c;
}
return retval;
}
/**
* gets the argument for the current parsed option. For example,
* in case of '-d <file>', if current option parsed is 'd' then
* getOptionArg() would return '<file>'.
* @return String - argument for current parsed option.
* @param none
*/
char c = theCurrentOption.getArgLetter();
if(theOptionMatcher.hasArg(c)){
}
return retval;
}
/**
* gets list of the commandline arguments. For example, in command
* such as 'cmd -s -d file file2 file3 file4' with the usage
* 'cmd [-s] [-d <file>] <file>...', getCmdArgs() would return
* the list {file2, file3, file4}.
* @return String[] - list of command arguments that may appear
* after options and option arguments.
* @params none
*/
int i=0;
}
return retval;
}
///////////////////////////////////////////////////////////
//
// Inner Classes
//
///////////////////////////////////////////////////////////
// inner class to model an option
class Option{
private char theArgLetter;
theArgument = arg;
}
} // end class Option
// inner class to query optString for a possible option match,
// and whether or not a given legal option takes an argument.
//
class OptionMatcher{
}
public boolean match(char c){
boolean retval = false;
retval = true;
}
return retval;
}
public boolean hasArg(char c){
boolean retval = false;
// reached end of theOptString
retval = false;
}
retval = true;
}
return retval;
}
} // end class OptionMatcher
}// end class GetOpt