sub_arctic.contrib
Class Getopt

java.lang.Object
  |
  +--sub_arctic.contrib.Getopt

public class Getopt
extends java.lang.Object


Constructor Summary
Getopt(java.lang.String[] argv, java.lang.String optstring)
          Initialize a Getopt instance.
 
Method Summary
 boolean hasMoreOptions()
          Test to see if more options are available.
static void main(java.lang.String[] argv)
          The sample main() program shown in this document is provided.
 char nextOption()
          nextOption() cranks the option parser.
 java.lang.String optarg()
          Reset after each call to nextOption(), optarg() returns the argument to the option, if one was provided, and if Getopt is "expecting" an argument as specified by the optstring (using the colon notation).
 boolean opterr()
          Returns the current state of the opterr flag.
 void opterr(boolean b)
          Set the value of the opterr flag.
 char optflag()
          Reset after each call to nextOption(), optflag() returns the current option flag (letter).
 int optind()
          Possibly reset after each call to nextOption(), optind() returns the index of the next argument to be processed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Getopt

public Getopt(java.lang.String[] argv,
              java.lang.String optstring)
Initialize a Getopt instance. Pass in the argument array and your option string.
Parameters:
String - argv[] An array of strings representing command-line arguments.
String - optstring A string containing valid option characters. If an option character is followed by a colon (":") an argument is expected following the option on the command line.
Method Detail

hasMoreOptions

public boolean hasMoreOptions()
Test to see if more options are available. Returns true if more options are waiting to be processed, false otherwise.

nextOption

public char nextOption()
nextOption() cranks the option parser. If you have not tested whether more options are available via hasMoreOptions(), you will likely get a runtime exception from this method. This method returns the next option flag (letter), or a '?' if an unrecognized option is encountered.

optflag

public char optflag()
Reset after each call to nextOption(), optflag() returns the current option flag (letter).

optarg

public java.lang.String optarg()
Reset after each call to nextOption(), optarg() returns the argument to the option, if one was provided, and if Getopt is "expecting" an argument as specified by the optstring (using the colon notation). Returns null if there is no argument.

optind

public int optind()
Possibly reset after each call to nextOption(), optind() returns the index of the next argument to be processed.

opterr

public boolean opterr()
Returns the current state of the opterr flag. Opterr controls whether automatic error reporting will be done.

opterr

public void opterr(boolean b)
Set the value of the opterr flag. If set to true, Getopt will perform automatic error reporting when it encounters bogus options. If set to false, Getopt works silently.

main

public static void main(java.lang.String[] argv)
The sample main() program shown in this document is provided. It understands a and b to be mutually-exclusive options. c is a non-exclusive option. o is a non-exclusive option that takes an argument.