bloritsch 01/04/04 08:36:29 Modified: proposal/4.0/src/java/org/apache/avalon/cli AbstractParserControl.java CLArgsParser.java CLOption.java CLOptionDescriptor.java CLUtil.java Log: minor formatting Revision Changes Path 1.2 +1 -1 jakarta-avalon/proposal/4.0/src/java/org/apache/avalon/cli/AbstractParserControl.java Index: AbstractParserControl.java =================================================================== RCS file: /home/cvs/jakarta-avalon/proposal/4.0/src/java/org/apache/avalon/cli/AbstractParserControl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AbstractParserControl.java 2001/04/03 23:35:24 1.1 +++ AbstractParserControl.java 2001/04/04 15:36:27 1.2 @@ -13,7 +13,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a> */ -public class AbstractParserControl +public class AbstractParserControl implements ParserControl { public boolean isFinished( int lastOptionCode ) 1.2 +49 -49 jakarta-avalon/proposal/4.0/src/java/org/apache/avalon/cli/CLArgsParser.java Index: CLArgsParser.java =================================================================== RCS file: /home/cvs/jakarta-avalon/proposal/4.0/src/java/org/apache/avalon/cli/CLArgsParser.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CLArgsParser.java 2001/04/03 23:35:24 1.1 +++ CLArgsParser.java 2001/04/04 15:36:27 1.2 @@ -14,7 +14,7 @@ /** * Parser for command line arguments. * - * This parses command lines according to the standard (?) of + * This parses command lines according to the standard (?) of * gnu utilities. * * Note: This is still used in 1.1 libraries so do not add 1.2+ dependancies. @@ -61,13 +61,13 @@ protected final static int TOKEN_STRING = 1; - protected final static char[] ARG2_SEPERATORS = + protected final static char[] ARG2_SEPERATORS = new char[] { (char)0, '=', '-' }; - protected final static char[] ARG_SEPERATORS = + protected final static char[] ARG_SEPERATORS = new char[] { (char)0, '=' }; - protected final static char[] NULL_SEPERATORS = + protected final static char[] NULL_SEPERATORS = new char[] { (char)0 }; protected final CLOptionDescriptor[] m_optionDescriptors; @@ -106,8 +106,8 @@ public Vector getArguments() { //System.out.println( "Arguments: " + m_options ); - return m_options; - } + return m_options; + } /** * Get Descriptor for option id. @@ -145,17 +145,17 @@ } return null; - } + } /** * Retrieve an error message that occured during parsing if one existed. * * @return the error string */ - public String getErrorString() + public String getErrorString() { //System.out.println( "ErrorString: " + m_errorMessage ); - return m_errorMessage; + return m_errorMessage; } /** @@ -167,17 +167,17 @@ private int getStateFor( final CLOptionDescriptor descriptor ) { int flags = descriptor.getFlags(); - if( ( flags & CLOptionDescriptor.ARGUMENTS_REQUIRED_2 ) == + if( ( flags & CLOptionDescriptor.ARGUMENTS_REQUIRED_2 ) == CLOptionDescriptor.ARGUMENTS_REQUIRED_2 ) { return STATE_REQUIRE_2ARGS; } - else if( ( flags & CLOptionDescriptor.ARGUMENT_REQUIRED ) == + else if( ( flags & CLOptionDescriptor.ARGUMENT_REQUIRED ) == CLOptionDescriptor.ARGUMENT_REQUIRED ) { return STATE_REQUIRE_ARG; } - else if( ( flags & CLOptionDescriptor.ARGUMENT_OPTIONAL ) == + else if( ( flags & CLOptionDescriptor.ARGUMENT_OPTIONAL ) == CLOptionDescriptor.ARGUMENT_OPTIONAL ) { return STATE_OPTIONAL_ARG; @@ -186,15 +186,15 @@ { return STATE_NORMAL; } - } + } /** * Create a parser that can deals with options and parses certain args. * - * @param args[] the args + * @param args[] the args * @param optionDescriptors[] the option descriptors */ - public CLArgsParser( final String[] args, + public CLArgsParser( final String[] args, final CLOptionDescriptor[] optionDescriptors, final ParserControl control ) { @@ -203,9 +203,9 @@ m_options = new Vector(); this.args = args; - try + try { - parse(); + parse(); checkIncompatabilities( m_options ); } catch( final ParseException pe ) @@ -218,7 +218,7 @@ } /** - * Check for duplicates of an option. + * Check for duplicates of an option. * It is an error to have duplicates unless appropriate flags is set in descriptor. * * @param arguments the arguments @@ -234,7 +234,7 @@ final int id = option.getId(); final CLOptionDescriptor descriptor = getDescriptorFor( id ); - //this occurs when id == 0 and user has not supplied a descriptor + //this occurs when id == 0 and user has not supplied a descriptor //for arguments if( null == descriptor ) continue; @@ -243,14 +243,14 @@ checkIncompatable( arguments, incompatable, i ); } } - - protected void checkIncompatable( final Vector arguments, + + protected void checkIncompatable( final Vector arguments, final int[] incompatable, final int original ) throws ParseException { final int size = arguments.size(); - + for( int i = 0; i < size; i++ ) { if( original == i ) continue; @@ -258,7 +258,7 @@ final CLOption option = (CLOption)arguments.elementAt( i ); final int id = option.getId(); final CLOptionDescriptor descriptor = getDescriptorFor( id ); - + for( int j = 0; j < incompatable.length; j++ ) { if( id == incompatable[ j ] ) @@ -270,14 +270,14 @@ if( id == originalId ) { - message = + message = "Duplicate options for " + describeDualOption( originalId ) + " found."; } else { - message = "Incompatable options -" + - describeDualOption( id ) + " and " + + message = "Incompatable options -" + + describeDualOption( id ) + " and " + describeDualOption( originalId ) + " found."; } throw new ParseException( message, 0 ); @@ -301,7 +301,7 @@ sb.append( (char)id ); hasCharOption = true; } - + final String longOption = descriptor.getName(); if( null != longOption ) { @@ -311,23 +311,23 @@ } return sb.toString(); - } + } } /** * Create a parser that can deals with options and parses certain args. * - * @param args[] the args + * @param args[] the args * @param optionDescriptors[] the option descriptors */ - public CLArgsParser( final String[] args, + public CLArgsParser( final String[] args, final CLOptionDescriptor[] optionDescriptors ) { this( args, optionDescriptors, null ); } /** - * Create a string array that is subset of input array. + * Create a string array that is subset of input array. * The sub-array should start at array entry indicated by index. That array element * should only include characters from charIndex onwards. * @@ -349,7 +349,7 @@ } result[0] = array[ index ].substring( charIndex - 1 ); - + return result; } @@ -372,7 +372,7 @@ ch = peekAtChar(); if( argIndex >= args.length ) break; - + if( null != m_control && m_control.isFinished( m_lastOptionId ) ) { //this may need mangling due to peeks @@ -383,11 +383,11 @@ //System.out.println( "State=" + m_state ); //System.out.println( "Char=" + (char)ch ); - if( STATE_OPTION_MODE == m_state ) + if( STATE_OPTION_MODE == m_state ) { //if get to an arg barrier then return to normal mode //else continue accumulating options - if( 0 == ch ) + if( 0 == ch ) { getChar(); //strip the null m_state = STATE_NORMAL; @@ -408,7 +408,7 @@ m_state = STATE_NORMAL; addOption( m_option ); } - else + else { parseArguments(); } @@ -423,7 +423,7 @@ else if( STATE_REQUIRE_ARG == m_state ) { final CLOptionDescriptor descriptor = getDescriptorFor( m_option.getId() ); - final String message = + final String message = "Missing argument to option " + getOptionDescription( descriptor ); throw new ParseException( message, 0 ); } @@ -437,7 +437,7 @@ else { final CLOptionDescriptor descriptor = getDescriptorFor( m_option.getId() ); - final String message = + final String message = "Missing argument to option " + getOptionDescription( descriptor ); throw new ParseException( message, 0 ); } @@ -463,7 +463,7 @@ protected final char getChar() { - if( INVALID != m_lastChar ) + if( INVALID != m_lastChar ) { final char result = (char)m_lastChar; m_lastChar = INVALID; @@ -475,7 +475,7 @@ private final char readChar() { if( stringIndex >= stringLength ) - { + { argIndex++; stringIndex = 0; @@ -494,7 +494,7 @@ { ch = getChar(); - if( isSeperator( ch, seperators ) ) + if( isSeperator( ch, seperators ) ) { ch = getChar(); return new Token( TOKEN_SEPERATOR, null ); @@ -529,7 +529,7 @@ m_option = null; } - protected void parseOption( final CLOptionDescriptor descriptor, + protected void parseOption( final CLOptionDescriptor descriptor, final String optionString ) throws ParseException { @@ -537,10 +537,10 @@ { throw new ParseException( "Unknown option " + optionString, 0 ); } - + m_state = getStateFor( descriptor ); m_option = new CLOption( descriptor.getId() ); - + if( STATE_NORMAL == m_state ) addOption( m_option ); } @@ -551,7 +551,7 @@ final CLOptionDescriptor descriptor = getDescriptorFor( (int)ch ); isLong = false; parseOption( descriptor, "-" + ch ); - + if( STATE_NORMAL == m_state ) m_state = STATE_OPTION_MODE; } @@ -577,7 +577,7 @@ if( TOKEN_SEPERATOR == token.getType() ) { final CLOptionDescriptor descriptor = getDescriptorFor( m_option.getId() ); - final String message = + final String message = "Unable to parse first argument for option " + getOptionDescription( descriptor ); throw new ParseException( message, 0 ); @@ -638,15 +638,15 @@ else { ch = peekAtChar(); - + //if it is a short option then parse it else ... if( '-' != ch ) parseShortOption(); else { - getChar(); // strip the - + getChar(); // strip the - //-- sequence .. it can either mean a change of state //to STATE_NO_OPTIONS or else a long option - + if( 0 == peekAtChar() ) { getChar(); 1.2 +15 -15 jakarta-avalon/proposal/4.0/src/java/org/apache/avalon/cli/CLOption.java Index: CLOption.java =================================================================== RCS file: /home/cvs/jakarta-avalon/proposal/4.0/src/java/org/apache/avalon/cli/CLOption.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CLOption.java 2001/04/03 23:35:24 1.1 +++ CLOption.java 2001/04/04 15:36:27 1.2 @@ -28,7 +28,7 @@ { return getArgument( 0 ); } - + /** * Retrieve argument to option if it takes arguments. * @@ -36,23 +36,23 @@ */ public final String getArgument( final int index ) { - if( null == m_arguments || index < 0 || index >= m_arguments.length ) + if( null == m_arguments || index < 0 || index >= m_arguments.length ) { return null; } - else return m_arguments[ index ]; + else return m_arguments[ index ]; } /** - * Retrieve id of option. - * + * Retrieve id of option. + * * The id is eqivelent to character code if it can be a single letter option. * * @return the id */ - public final int getId() + public final int getId() { - return m_id; + return m_id; } /** @@ -60,9 +60,9 @@ * * @param id the new id */ - public CLOption( final int id ) + public CLOption( final int id ) { - m_id = id; + m_id = id; } /** @@ -70,18 +70,18 @@ * * @param argument the argument */ - public CLOption( final String argument ) + public CLOption( final String argument ) { this( 0 ); addArgument( argument ); - } + } /** * Mutator fo Argument property. * * @param argument the argument */ - public final void addArgument( final String argument ) + public final void addArgument( final String argument ) { if( null == m_arguments ) m_arguments = new String[] { argument }; else @@ -91,7 +91,7 @@ arguments[ m_arguments.length ] = argument; m_arguments = arguments; } - } + } public int getArgumentCount() { @@ -117,7 +117,7 @@ } sb.append( " ]" ); - + return sb.toString(); - } + } } 1.2 +26 -26 jakarta-avalon/proposal/4.0/src/java/org/apache/avalon/cli/CLOptionDescriptor.java Index: CLOptionDescriptor.java =================================================================== RCS file: /home/cvs/jakarta-avalon/proposal/4.0/src/java/org/apache/avalon/cli/CLOptionDescriptor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CLOptionDescriptor.java 2001/04/03 23:35:24 1.1 +++ CLOptionDescriptor.java 2001/04/04 15:36:28 1.2 @@ -33,8 +33,8 @@ * @param id the id/character option * @param description description of option usage */ - public CLOptionDescriptor( final String name, - final int flags, + public CLOptionDescriptor( final String name, + final int flags, final int id, final String description ) { @@ -49,8 +49,8 @@ * @param id the id/character option * @param description description of option usage */ - public CLOptionDescriptor( final String name, - final int flags, + public CLOptionDescriptor( final String name, + final int flags, final int id, final String description, final int[] incompatable ) @@ -60,7 +60,7 @@ m_flags = flags; m_description = description; m_incompatable = incompatable; - } + } protected int[] getIncompatble() { @@ -70,44 +70,44 @@ /** * Retrieve textual description. * - * @return the description + * @return the description */ - public final String getDescription() - { - return m_description; + public final String getDescription() + { + return m_description; } - + /** * Retrieve flags about option. * Flags include details such as whether it allows parameters etc. * * @return the flags */ - public final int getFlags() + public final int getFlags() { - return m_flags; + return m_flags; } - + /** * Retrieve the id for option. * The id is also the character if using single character options. * * @return the id */ - public final int getId() - { - return m_id; - } - + public final int getId() + { + return m_id; + } + /** * Retrieve name of option which is also text for long option. * * @return name/long option */ - public final String getName() - { - return m_name; - } + public final String getName() + { + return m_name; + } /** * Convert to String. @@ -116,9 +116,9 @@ */ public String toString() { - return - "[OptionDescriptor " + m_name + - ", " + m_id + ", " + m_flags + + return + "[OptionDescriptor " + m_name + + ", " + m_id + ", " + m_flags + ", " + m_description + " ]"; - } + } } 1.2 +10 -10 jakarta-avalon/proposal/4.0/src/java/org/apache/avalon/cli/CLUtil.java Index: CLUtil.java =================================================================== RCS file: /home/cvs/jakarta-avalon/proposal/4.0/src/java/org/apache/avalon/cli/CLUtil.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CLUtil.java 2001/04/03 23:35:24 1.1 +++ CLUtil.java 2001/04/04 15:36:28 1.2 @@ -31,38 +31,38 @@ final String name = options[i].getName(); String description = options[i].getDescription(); boolean needComma = false; - + sb.append('\t'); - + if( Character.isLetter(ch) ) { sb.append("-"); sb.append(ch); needComma = true; } - + if (null != name) { if( needComma ) sb.append(", "); - + sb.append("--"); sb.append(name); sb.append('\n'); } - + if( null != description ) { while( description.length() > MAX_DESCRIPTION_COLUMN_LENGTH ) { - final String descriptionPart = + final String descriptionPart = description.substring( 0, MAX_DESCRIPTION_COLUMN_LENGTH ); - description = + description = description.substring( MAX_DESCRIPTION_COLUMN_LENGTH ); sb.append( "\t\t" ); sb.append( descriptionPart ); sb.append( '\n' ); } - + sb.append( "\t\t" ); sb.append( description ); sb.append( '\n' ); @@ -75,7 +75,7 @@ * Private Constructor so that no instance can ever be created. * */ - private CLUtil() + private CLUtil() { - } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]