Update of /cvsroot/squirrel-sql/mavenize/thirdparty-non-maven/ostermiller-syntax/src/main/java/gnu/getopt
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv32334/thirdparty-non-maven/ostermiller-syntax/src/main/java/gnu/getopt
Added Files:
LongOpt.java Getopt.java GetoptDemo.java
Log Message:
Source for thirdparty dependency. Maven central requires a valid source code repository for artifacts that it hosts. This project has none, so we host it here for the time being.
--- NEW FILE: Getopt.java ---
/**************************************************************************
/* Getopt.java -- Java port of GNU getopt from glibc 2.0.6
/*
/* Copyright (c) 1987-1997 Free Software Foundation, Inc.
/* Java Port Copyright (c) 1998 by Aaron M. Renn (ar...@ur...)
/*
/* This program is free software; you can redistribute it and/or modify
/* it under the terms of the GNU Library General Public License as published
/* by the Free Software Foundation; either version 2 of the License or
/* (at your option) any later version.
/*
/* This program is distributed in the hope that it will be useful, but
/* WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/* GNU Library General Public License for more details.
/*
/* You should have received a copy of the GNU Library General Public License
/* along with this program; see the file COPYING.LIB. If not, write to
/* the Free Software Foundation Inc., 59 Temple Place - Suite 330,
[...1254 lines suppressed...]
return(':');
else
return('?');
}
else
{
optarg = argv[optind];
++optind;
}
nextchar = null;
}
}
return(c);
}
} // Class Getopt
--- NEW FILE: LongOpt.java ---
/**************************************************************************
/* LongOpt.java -- Long option object for Getopt
/*
/* Copyright (c) 1998 by Aaron M. Renn (ar...@ur...)
/*
/* This program is free software; you can redistribute it and/or modify
/* it under the terms of the GNU Library General Public License as published
/* by the Free Software Foundation; either version 2 of the License or
/* (at your option) any later version.
/*
/* This program is distributed in the hope that it will be useful, but
/* WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/* GNU Library General Public License for more details.
/*
/* You should have received a copy of the GNU Library General Public License
/* along with this program; see the file COPYING.LIB. If not, write to
/* the Free Software Foundation Inc., 59 Temple Place - Suite 330,
/* Boston, MA 02111-1307 USA
/**************************************************************************/
package gnu.getopt;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.PropertyResourceBundle;
import java.text.MessageFormat;
/**************************************************************************/
/**
* This object represents the definition of a long option in the Java port
* of GNU getopt. An array of LongOpt objects is passed to the Getopt
* object to define the list of valid long options for a given parsing
* session. Refer to the getopt documentation for details on the
* format of long options.
*
* @version 1.0.5
* @author Aaron M. Renn (ar...@ur...)
*
* @see Getopt
*/
public class LongOpt extends Object
{
/**************************************************************************/
/*
* Class Variables
*/
/**
* Constant value used for the "has_arg" constructor argument. This
* value indicates that the option takes no argument.
*/
public static final int NO_ARGUMENT = 0;
/**
* Constant value used for the "has_arg" constructor argument. This
* value indicates that the option takes an argument that is required.
*/
public static final int REQUIRED_ARGUMENT = 1;
/**
* Constant value used for the "has_arg" constructor argument. This
* value indicates that the option takes an argument that is optional.
*/
public static final int OPTIONAL_ARGUMENT = 2;
/**************************************************************************/
/*
* Instance Variables
*/
/**
* The name of the long option
*/
protected String name;
/**
* Indicates whether the option has no argument, a required argument, or
* an optional argument.
*/
protected int has_arg;
/**
* If this variable is not null, then the value stored in "val" is stored
* here when this long option is encountered. If this is null, the value
* stored in "val" is treated as the name of an equivalent short option.
*/
protected StringBuffer flag;
/**
* The value to store in "flag" if flag is not null, otherwise the
* equivalent short option character for this long option.
*/
protected int val;
/**
* Localized strings for error messages
*/
private ResourceBundle _messages = PropertyResourceBundle.getBundle(
"gnu/getopt/MessagesBundle", Locale.getDefault());
/**************************************************************************/
/*
* Constructors
*/
/**
* Create a new LongOpt object with the given parameter values. If the
* value passed as has_arg is not valid, then an exception is thrown.
*
* @param name The long option String.
* @param has_arg Indicates whether the option has no argument (NO_ARGUMENT), a required argument (REQUIRED_ARGUMENT) or an optional argument (OPTIONAL_ARGUMENT).
* @param flag If non-null, this is a location to store the value of "val" when this option is encountered, otherwise "val" is treated as the equivalent short option character.
* @param val The value to return for this long option, or the equivalent single letter option to emulate if flag is null.
*
* @exception IllegalArgumentException If the has_arg param is not one of NO_ARGUMENT, REQUIRED_ARGUMENT or OPTIONAL_ARGUMENT.
*/
public
LongOpt(String name, int has_arg,
StringBuffer flag, int val) throws IllegalArgumentException
{
// Validate has_arg
if ((has_arg != NO_ARGUMENT) && (has_arg != REQUIRED_ARGUMENT)
&& (has_arg != OPTIONAL_ARGUMENT))
{
Object[] msgArgs = { new Integer(has_arg).toString() };
throw new IllegalArgumentException(MessageFormat.format(
_messages.getString("getopt.invalidValue"), msgArgs));
}
// Store off values
this.name = name;
this.has_arg = has_arg;
this.flag = flag;
this.val = val;
}
/**************************************************************************/
/**
* Returns the name of this LongOpt as a String
*
* @return Then name of the long option
*/
public String
getName()
{
return(name);
}
/**************************************************************************/
/**
* Returns the value set for the 'has_arg' field for this long option
*
* @return The value of 'has_arg'
*/
public int
getHasArg()
{
return(has_arg);
}
/**************************************************************************/
/**
* Returns the value of the 'flag' field for this long option
*
* @return The value of 'flag'
*/
public StringBuffer
getFlag()
{
return(flag);
}
/**
* Returns the value of the 'val' field for this long option
*
* @return The value of 'val'
*/
public int
getVal()
{
return(val);
}
/**************************************************************************/
} // Class LongOpt
--- NEW FILE: GetoptDemo.java ---
import gnu.getopt.LongOpt;
import gnu.getopt.Getopt;
/*
* This sample code was written by Aaron M. Renn and is a demonstration
* of how to utilize some of the features of the GNU getopt package. This
* sample code is hereby placed into the public domain by the author and
* may be used without restriction.
*/
public class GetoptDemo
{
public static void
main(String[] argv)
{
int c;
String arg;
LongOpt[] longopts = new LongOpt[3];
//
StringBuffer sb = new StringBuffer();
longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
longopts[1] = new LongOpt("outputdir", LongOpt.REQUIRED_ARGUMENT, sb, 'o');
longopts[2] = new LongOpt("maximum", LongOpt.OPTIONAL_ARGUMENT, null, 2);
//
Getopt g = new Getopt("testprog", argv, "-:bc::d:hW;", longopts);
g.setOpterr(false); // We'll do our own error handling
//
while ((c = g.getopt()) != -1)
switch (c)
{
case 0:
arg = g.getOptarg();
System.out.println("Got long option with value '" +
(char)(new Integer(sb.toString())).intValue()
+ "' with argument " +
((arg != null) ? arg : "null"));
break;
//
case 1:
System.out.println("I see you have return in order set and that " +
"a non-option argv element was just found " +
"with the value '" + g.getOptarg() + "'");
break;
//
case 2:
arg = g.getOptarg();
System.out.println("I know this, but pretend I didn't");
System.out.println("We picked option " +
longopts[g.getLongind()].getName() +
" with value " +
((arg != null) ? arg : "null"));
break;
//
case 'b':
System.out.println("You picked plain old option " + (char)c);
break;
//
case 'c':
case 'd':
arg = g.getOptarg();
System.out.println("You picked option '" + (char)c +
"' with argument " +
((arg != null) ? arg : "null"));
break;
//
case 'h':
System.out.println("I see you asked for help");
break;
//
case 'W':
System.out.println("Hmmm. You tried a -W with an incorrect long " +
"option name");
break;
//
case ':':
System.out.println("Doh! You need an argument for option " +
(char)g.getOptopt());
break;
//
case '?':
System.out.println("The option '" + (char)g.getOptopt() +
"' is not valid");
break;
//
default:
System.out.println("getopt() returned " + c);
break;
}
//
for (int i = g.getOptind(); i < argv.length ; i++)
System.out.println("Non option argv element: " + argv[i] + "\n");
}
} // Class GetoptDemo
|