org.gjt.universe
Class CommandLine

java.lang.Object
  |
  +--org.gjt.universe.CommandLine

public final class CommandLine
extends java.lang.Object

Parses the command line options and sets the appropriate flags in the class. In a (perhaps misguided) effort to increase the generality of the code, this class has been rewritten to use a Hashtable to store the command line options.

Currently, the parseArgs function interprets an array of String options by checking if each element in the array has a dash '-' as its first non-whitespace character, and storing it as a key in a Hashtable if it does. The key for this option is the contents of the String after the initial dashes up to any equals '=' sign in string. The value of this option will be any substring after an equals '=' sign, or otherwise any following options not starting with a dash. If there is neither an equals sign in the option nor any parameters following, the value stored is the string "true".

Examples:
The option --example would have the key example and the value true.
The option --example=one would have the key example and the value one.
The options --example and two would have the key example and the value two.

Further, if there are several options with the same name, or if the value expression is a list separated by commas, semicolons or colons, the value string will be a list of the values, separated by NUL (&backsl;u0000). The values can be copied to Config with copyOptionValues(), and read with getStringArray() in that class.

The primary advantage of this rewritten form is that it is now possible to write code to take advantage of a new command line option without rewriting CommandLine.java. The code dependant on a particular option being given now needs only check the return value of getCLOState(option).

Version:
$Id: CommandLine.java,v 1.4 2001/06/04 07:26:22 jjweston Exp $
Author:
Dave Butler, Bjorn Sandberg

Field Summary
private static float HASH_LOAD_FACTOR
          Value for the loadFactor parameter for the Hashtable.
private static int HASH_SIZE_FACTOR
          Value to multiply the number of command line options by in order to derive the initialCapacity value for the Hashtable.
private static java.lang.String OPTION_DELIMS
          Characters that can delimit values in an option of the form "-option=val1,val2,....
private static java.util.Hashtable options
           
 
Constructor Summary
CommandLine()
           
 
Method Summary
static void copyOptionValues()
          Transfers the values from the command line to the Config.
static boolean getAlpha()
          Deprecated. Should use getCLOState("alpha") instead.
static boolean getCLOState(java.lang.String key)
          Checks if key is contained in the Hashtable.
static java.lang.String getCLOValue(java.lang.String key)
          Returns the value associated with key.
static boolean getDebug()
          Deprecated. Should use getCLOState("debug") instead.
static boolean getOne()
          Deprecated. Should use getCLOState("one") instead.
static boolean getQuick()
          Deprecated. Should use getCLOState("quick") instead.
static boolean getText()
          Deprecated. Should use getCLOState("text") instead.
static void parseArgs(java.lang.String[] args)
          Parses the the command line arguments and inserts them in a Hashtable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPTION_DELIMS

private static final java.lang.String OPTION_DELIMS
Characters that can delimit values in an option of the form "-option=val1,val2,.... Currently, these are the colon (:), the semi-colon (;), and the comma (.).

Since:
1.3
See Also:
Constant Field Values

options

private static java.util.Hashtable options
Since:
1.2

HASH_SIZE_FACTOR

private static final int HASH_SIZE_FACTOR
Value to multiply the number of command line options by in order to derive the initialCapacity value for the Hashtable.

Since:
1.2
See Also:
Hashtable, Constant Field Values

HASH_LOAD_FACTOR

private static final float HASH_LOAD_FACTOR
Value for the loadFactor parameter for the Hashtable.

Since:
1.2
See Also:
Hashtable, Constant Field Values
Constructor Detail

CommandLine

public CommandLine()
Method Detail

parseArgs

public static void parseArgs(java.lang.String[] args)
Parses the the command line arguments and inserts them in a Hashtable. Any such options should be of the form '-option'; the function will generate an error for, and otherwise ignore, any options not in this form.


getCLOState

public static final boolean getCLOState(java.lang.String key)
Checks if key is contained in the Hashtable.

Parameters:
key - Option to look for in the options table. By definition, the key for a particular command line option is that option, stripped of any leading dashes. (E.g., the key for the -debug command line option would be debug.)
Returns:
true if the requested key is contained in the Hashtable, and false if it does not. If, for some reason, the actual value associated with the key is required, you should call getCLOValue(key).
Since:
1.2

getCLOValue

public static final java.lang.String getCLOValue(java.lang.String key)
Returns the value associated with key.

Parameters:
key - Option to look for in the options table. By definition, the key for a particular command line option is that option, stripped of any leading dashes. (E.g., the key for the -debug command line option would be debug.)
Returns:
A String representation of the value associated with the supplied key if key is contained in the Hashtable, and null otherwise.
Since:
1.2

copyOptionValues

public static final void copyOptionValues()
Transfers the values from the command line to the Config. The keys text, one and jfc are translated into the name of the GUIFactory class to be instantiated. All other values are copied literally.

Since:
1.4

getText

public static final boolean getText()
Deprecated. Should use getCLOState("text") instead.

Returns true if the "-text" command line option was used.


getAlpha

public static final boolean getAlpha()
Deprecated. Should use getCLOState("alpha") instead.

Returns true if the "-alpha" command line option was used.


getDebug

public static final boolean getDebug()
Deprecated. Should use getCLOState("debug") instead.

Returns true if the "-debug" command line option was used.


getOne

public static final boolean getOne()
Deprecated. Should use getCLOState("one") instead.

Returns true if the "-one" command line option was used.


getQuick

public static final boolean getQuick()
Deprecated. Should use getCLOState("quick") instead.

Returns true if the "-quick" command line option was used.



Copyright © 2001 Universe Dev Team All Rights Reserved.