getopt.c.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | OptionScanner.
Class representing an argument of the long type, where the whole program argument represents one option, e.g. "--help" or "-version". |
| Modifier and Type | Field and Description |
|---|---|
| private int | argIndex
Index in argv of the arg currently being processed (or about to be started). |
| private String[] | args
Original argv passed at reset |
| pack-priv static final char | ARGUMENT
Return to indicate the next argument is a free-standing argument. |
| pack-priv static final char | DONE
Return to indicate argument processing is over. |
| pack-priv static final char | ERROR
Return to indicate option was not recognised. |
| private final OptionScanner. | |
| private String | |
| private String | optarg
Option argument (where present for returned option). |
| private int | optIndex
Character index within the current element of argv (of the next option to process). |
| private final String | programOpts
Valid options. |
| Access | Constructor and Description |
|---|---|
| pack-priv | OptionScanner(String[]
command-line arguments (which must not change during scanning) args, String the one-letter options (with : indicating an option argument programOpts, OptionScanner.table of long options (like --help) longSpecCreate the scanner from command-line arguments, and information about the valid options. |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv int | |
| pack-priv char | |
| pack-priv String | |
| pack-priv char | Returns: next option from command line: the actual character or a code.Get the next option (as a character), or return a code designating successful or erroneous completion. |
| pack-priv String | |
| pack-priv String | getWholeArgument()
Get a whole argument (not the argument of an option), for use after |
| pack-priv String | peekWholeArgument()
Peek at a whole argument (not the argument of an option), for use after |
| argIndex | back to summary |
|---|---|
| private int argIndex Index in argv of the arg currently being processed (or about to be started). | |
| args | back to summary |
|---|---|
| private String[] args Original argv passed at reset | |
| ARGUMENT | back to summary |
|---|---|
| pack-priv static final char ARGUMENT Return to indicate the next argument is a free-standing argument. | |
| DONE | back to summary |
|---|---|
| pack-priv static final char DONE Return to indicate argument processing is over. | |
| ERROR | back to summary |
|---|---|
| pack-priv static final char ERROR Return to indicate option was not recognised. | |
| longSpec | back to summary |
|---|---|
| private final OptionScanner. | |
| message | back to summary |
|---|---|
| private String message Error message (after returning | |
| optarg | back to summary |
|---|---|
| private String optarg Option argument (where present for returned option). | |
| optIndex | back to summary |
|---|---|
| private int optIndex Character index within the current element of argv (of the next option to process). | |
| programOpts | back to summary |
|---|---|
| private final String programOpts Valid options. ':' means expect an argument following. | |
| OptionScanner | back to summary |
|---|---|
| pack-priv OptionScanner(String[] args, String programOpts, OptionScanner. Create the scanner from command-line arguments, and information about the valid options.
| |
| countRemainingArguments | back to summary |
|---|---|
| pack-priv int countRemainingArguments() Number of arguments that remain unprocessed from the original array. | |
| error | back to summary |
|---|---|
| pack-priv char error(String message, Object... args) Set the error message as | |
| getMessage | back to summary |
|---|---|
| pack-priv String getMessage() Get the error message (when we previously returned | |
| getOption | back to summary |
|---|---|
| pack-priv char getOption() Get the next option (as a character), or return a code designating successful or erroneous completion.
| |
| getOptionArgument | back to summary |
|---|---|
| pack-priv String getOptionArgument() Get the argument of the previously returned option or | |
| getWholeArgument | back to summary |
|---|---|
| pack-priv String getWholeArgument() Get a whole argument (not the argument of an option), for use after | |
| peekWholeArgument | back to summary |
|---|---|
| pack-priv String peekWholeArgument() Peek at a whole argument (not the argument of an option), for use after | |
LongSpec objects to the constructor to define the valid cases.
Long options are recognised before single-letter options are looked for. Note that "-" itself
is treated as a long option (even though it is quite short), returning
OptionScanner#ERROR if not explicitly defined as a LongSpec.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final boolean | |
| pack-priv final String | |
| pack-priv final char |
| Access | Constructor and Description |
|---|---|
| public | LongSpec(String
to match key, char to return when that matches returnValue, boolean an argument to the option is expected to follow hasArgument)Define that the long argument should return a given char value in calls to
|
| public |
| hasArgument | back to summary |
|---|---|
| pack-priv final boolean hasArgument | |
| key | back to summary |
|---|---|
| pack-priv final String key | |
| returnValue | back to summary |
|---|---|
| pack-priv final char returnValue | |
| LongSpec | back to summary |
|---|---|
| public LongSpec(String key, char returnValue, boolean hasArgument) Define that the long argument should return a given char value in calls to
| |
| LongSpec | back to summary |
|---|---|
| public LongSpec(String key, char returnValue) The same as | |