public class GetOpt extends Object
GetOpt interprets command arguments in accordance with the standard Unix conventions: option arguments of a command are introduced by "-" followed by a key character, and a non-option argument terminates the processing of options. GetOpt's option interpretation is controlled by its parameter optString, which specifies what characters designate legal options and which of them require associated values.
The getopt method returns the next, moving left to right, option letter in the command line arguments that matches a letter in optString. optString must contain the option letters the command using getopt will recognize. For example, getopt("ab") specifies that the command line should contain no options, only "-a", only "-b", or both "-a" and "-b" in either order. (The command line can also contain non-option arguments after any option arguments.) Multiple options per argument are allowed, e.g., "-ab" for the last case above.
If a letter in optString is followed by a colon, the option is expected to have an argument. The argument may or may not be separated by whitespace from the option letter. For example, getopt("w:") allows either "-w 80" or "-w80". The variable optArg is set to the option argument, e.g., "80" in either of the previous examples. Conversion functions such as Integer.parseInt(), etc., can then be applied to optArg.
getopt places in the variable optIndex the index of the next command line argument to be processed; optIndex is automatically initialized to 1 before the first call to getopt.
When all options have been processed (that is, up to the first non-option argument), getopt returns optEOF (-1). getopt recognizes the command line argument "--" (i.e., two dashes) to delimit the end of the options; getopt returns optEOF and skips "--". Subsequent, non-option arguments can be retrieved using the String array passed to main(), beginning with argument number optIndex.
Modifier and Type | Method and Description |
---|---|
int |
getopt() |
static void |
main(String[] args) |
String |
optArgGet() |
int |
optIndexGet() |
void |
optIndexSet(int i) |
boolean |
processArg(String arg,
boolean b) |
double |
processArg(String arg,
double d) |
float |
processArg(String arg,
float f) |
int |
processArg(String arg,
int n) |
long |
processArg(String arg,
long n) |
boolean |
tryArg(int k,
boolean b) |
double |
tryArg(int k,
double d) |
float |
tryArg(int k,
float f) |
int |
tryArg(int k,
int n) |
long |
tryArg(int k,
long n) |
String |
tryArg(int k,
String s) |
public boolean optErr
public static final int optEOF
public int processArg(String arg, int n)
public int tryArg(int k, int n)
public long processArg(String arg, long n)
public long tryArg(int k, long n)
public double processArg(String arg, double d)
public double tryArg(int k, double d)
public float processArg(String arg, float f)
public float tryArg(int k, float f)
public boolean processArg(String arg, boolean b)
public boolean tryArg(int k, boolean b)
public int optIndexGet()
public void optIndexSet(int i)
public String optArgGet()
public int getopt()
public static void main(String[] args)
Copyright © 2016. All rights reserved.