|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--GetOpt
Java version of GNU getopt.
Copyright © 2002 by Marvin Solomon. All rights reserved.
Field Summary | |
private String |
arg
The flags argument currently in use. |
private String[] |
argv
The arguments to main (note that argv[0] is the first arg, not the class name. |
int |
longind
Index in longopts of a long-named option found. |
private boolean |
longonly
Flag to indicate that only long options should be recognized. |
private LongOption[] |
longopts
Table of long options |
private int |
nextchar
The index in arg of the next option flag to be examined. |
String |
optarg
For communicatino from nextOpt() to the caller. |
boolean |
opterr
If set to false, to not print messages to System.err for unrecognized options. |
int |
optind
Index in argv of the next element to be scanned. |
char |
optopt
Set to an option character which was unrecognized. |
private String |
progname
The "program" (class) name (counterpart of argv[0] in Unix) |
private String |
shortopts
Short option flags |
Constructor Summary | |
GetOpt(String progname,
String[] argv,
String shortopts)
Create a new option parser. |
|
GetOpt(String progname,
String[] argv,
String shortopts,
LongOption[] longopts)
Create a new option parser. |
|
GetOpt(String progname,
String[] argv,
String shortopts,
LongOption[] longopts,
boolean longonly)
Create a new option parser. |
Method Summary | |
static void |
main(String[] ignore)
Main program for testing. |
int |
nextOpt()
Return the next option. |
private void |
printErr(String a,
String b,
String c)
A convenience routine to print an error to System.err if opterr is true. |
private static String[] |
tokenize(String str)
Helper procedure for main. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private String progname
private String[] argv
private String arg
optind
private String shortopts
private LongOption[] longopts
private boolean longonly
public int optind
private int nextchar
public int longind
public String optarg
public boolean opterr
public char optopt
Constructor Detail |
public GetOpt(String progname, String[] argv, String shortopts, LongOption[] longopts, boolean longonly)
progname
- the name of the program (for error messages)argv
- an array of command-line argumentsshortopts
- a string of short option flags. A single colon
following a flag indicates it has a mandatory argument; a double colon
indicates an optional argument.longopts
- a table of long option descriptorslongonly
- if true, indicates athat -flag should be treated as a
long flag, like --flag, rather than four short flags.public GetOpt(String progname, String[] argv, String shortopts)
progname
- the name of the program (for error messages)argv
- an array of command-line argumentsshortopts
- a string of short option flags. A single colon
following a flag indicates it has a mandatory argument; a double colon
indicates an optional argument.public GetOpt(String progname, String[] argv, String shortopts, LongOption[] longopts)
progname
- the name of the program (for error messages)argv
- an array of command-line argumentsshortopts
- a string of short option flags. A single colon
following a flag indicates it has a mandatory argument; a double colon
indicates an optional argument.longopts
- a table of long option descriptorsMethod Detail |
public int nextOpt()
private void printErr(String a, String b, String c)
a
- the first part of the messageb
- the middle part of the messagec
- the last part of the messagepublic static void main(String[] ignore)
ignore
- ignoredprivate static String[] tokenize(String str)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |