All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class net.strandberg.util.Options

java.lang.Object
   |
   +----net.strandberg.util.Options

public final class Options
extends Object
Class Options is used to get options and arguments from an argument array. It supports all the rules of the unix command syntax standard for SunOS 5.4 (see intro(1)). Class Options has the same syntax* and behaviour as getopt(3C) of SunOS 5.4.

(*) the syntax is a rather straight translation (javaified) version of the syntax of getopt(3C).

As neither intro(1) nor getopt(3C) clearly specifies the behaviour of getopt, class Options has been made implementation-compliant with getopt(3C). This means that Options are MT-unsafe just like getopt(3C).

Although the revision of this file is not a high one, it has been extensively tested.

Version:
$Revision: 0.0 $
Author:
Mats Strandberg

Constructor Index

 o Options(String, String[], String)
Constructs a new Options which can later be used to parse the argument array given as parameter.
 o Options(String, String[], String, boolean)
Constructs a new Options which can later be used to parse the argument array given as parameter.

Method Index

 o getopt()
Gets the next option from the argument array.
 o main(String[])
The main method is used for testing the behaviour of the Options class.
 o optarg()
Gets the option argument for the latest option parsed from the argument array.
 o optind()
Gets the index of the next argument to be parsed from the argument array.
 o optopt()
Gets the latest option parsed from the argument array.

Constructors

 o Options
 public Options(String name,
                String args[],
                String opts,
                boolean opterr)
Constructs a new Options which can later be used to parse the argument array given as parameter. Options given in the opts parameter that are followed by a ':' are options that must have an argument. E.g use "abo:" for a program with usage: program [-a][-b][-o optionarg].

Parameters:
name - the name of the calling program to be used in error messages.
args - the argument array to be parsed
opts - the allowed options.
opterr - if true, error messages will be written on stderr
 o Options
 public Options(String name,
                String args[],
                String opts)
Constructs a new Options which can later be used to parse the argument array given as parameter. Options given in the opts parameter that are followed by a ':' are options that must have an argument. E.g use "abo:" for a program with usage: program [-a][-b][-o optionarg]. Encountered errors will be written on stderr.

Parameters:
name - the name of the calling program to be used in error messages.
args - the argument array to be parsed
opts - the allowed options.

Methods

 o main
 public static void main(String args[])
The main method is used for testing the behaviour of the Options class. The usage is java Options [argument1..argumentN]. The main method of Options will print out the result of checking the input arguments against the option string abo:, i.e. it will behave as a program having usage: program [-a][-b][-o optionarg].

Parameters:
args - command line arguments as described above.
 o getopt
 public final char getopt()
Gets the next option from the argument array.

Returns:
the option read. '\0' is returned if there are no more options. '?' is returned if there is a syntax violation.
 o optopt
 public final char optopt()
Gets the latest option parsed from the argument array.

Returns:
the latest option
 o optarg
 public final String optarg()
Gets the option argument for the latest option parsed from the argument array.

Returns:
the option argument
 o optind
 public final int optind()
Gets the index of the next argument to be parsed from the argument array.

Returns:
the index (in the args array)

All Packages  Class Hierarchy  This Package  Previous  Next  Index