|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.uni_hamburg.eggink.autojar.Getopt
Handles program arguments like Unix getopt(). Example:
void main(String[] argv)
{
int opt;
boolean x = false;
Getopt getopt = new Getopt(argv, "a:hx");
String argA = "";
// get Options
while ((opt = getopt.getOption()) != -1)
{
switch (opt)
{
case 'a': argA = getopt.getOptarg();
break;
case 'h': help();
break;
case 'x': x = true;
break;
default: System.out.println("wrong option: " + getOptopt());
}
}
// handle non-option parameters
String[] files = getopt.getParms();
for (int i = 0; i < files.length; ++i)
doSomethingWith(files[i]);
}
Legal calls:
java Mainclass -hx file1 file2
java Mainclass -xa blurp -h -- file3
Illegal calls:
java Mainclass -y f
java Mainclass -a
The special argument -- denotes the end of the options. All Arguments
after this will be considered as non-options, even if starting with -.
If any command line argument is of the form "@filename", this file
is read and each line is considered a program parameter.
| Constructor Summary | |
Getopt(java.lang.String[] argv,
java.lang.String opts)
Like Getopt(argv, opts, true). |
|
Getopt(java.lang.String[] argv,
java.lang.String opts,
boolean opterr)
Constructs a Getopt object using the main() parameter list. |
|
Getopt(java.lang.String filename,
java.lang.String opts)
Like Getopt(filename, opts, true) |
|
Getopt(java.lang.String filename,
java.lang.String opts,
boolean opterr)
Constructs a Getopt object by reading all arguments from a file. |
|
| Method Summary | |
java.lang.String |
getOptarg()
Returns the current argument or null. |
int |
getOption()
Returns the next option as int value, -1 if no more options are available, '?' if the option is illegal. |
char |
getOptopt()
Returns the unrecognized option character. |
java.lang.String[] |
getParms()
Returns parameters not handled by getOption() as array of Strings. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Getopt(java.lang.String filename,
java.lang.String opts,
boolean opterr)
throws java.io.IOException
filename - Name of the file to read.opts - The possible options.opterr - If true, an error message will be printed if an illegal option character
is found.
public Getopt(java.lang.String filename,
java.lang.String opts)
throws java.io.IOException
public Getopt(java.lang.String[] argv,
java.lang.String opts,
boolean opterr)
throws java.io.IOException
argv - The arguments of main()opts - The possible options. Each option is a single character.
If followed by a colon, the option given in the command line
must be followed by an argument.opterr - If true, an error message will be printed if an illegal option character
is encountered.
public Getopt(java.lang.String[] argv,
java.lang.String opts)
throws java.io.IOException
| Method Detail |
public java.lang.String getOptarg()
public int getOption()
public char getOptopt()
public java.lang.String[] getParms()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||