1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/******************************************************************************
**
** parse_cl.java
**
** Definition of command line parser class
**
** Automatically created by genparse v0.9.1
**
** See http://genparse.sourceforge.net for details and updates
**
******************************************************************************/
import gnu.getopt.LongOpt;
import gnu.getopt.Getopt;
/*----------------------------------------------------------------------------
**
** class Cmdline ()
**
** Command line parser class.
**
**--------------------------------------------------------------------------*/
public class Cmdline implements CmdlineInterface
{
/* parameters */
private boolean _a;
private boolean _h;
private boolean _v;
/* Name of the calling program */
private String _executable;
/* next (non-option) parameter */
private int _optind;
/* Must be constructed with parameters. */
public Cmdline (String[] argv) throws CmdlineEx
{
/* character returned by optind () */
int c;
LongOpt[] longopts = new LongOpt[3];
longopts[0] = new LongOpt ("help", LongOpt.NO_ARGUMENT, null, 'h');
longopts[1] = new LongOpt ("version", LongOpt.NO_ARGUMENT, null, 'v');
_executable = Cmdline.class.getName ();
/* default values */
_a = false;
_h = false;
_v = false;
Getopt g = new Getopt (_executable, argv, "ahv", longopts);
while ((c = g.getopt ()) != -1)
{
switch (c)
{
case 'a':
_a = true;
break;
case 'h':
_h = true;
usage (0, _executable);
break;
case 'v':
_v = true;
break;
default:
usage (-1, _executable);
}
} /* while */
_optind = g.getOptind ();
}
public void usage (int status, String program_name)
{
if (status != 0)
{
System.err.println ("Try `" + program_name + " --help' for more information.");
}
else
{
/* "comment for parameter a" */
System.out.println (
" [ -a ] (type=FLAG)\n" +
" param a line 1");
System.out.println (
" param a line 2\n" +
" [ -h ] [ --help ] (type=FLAG)\n" +
" Display this help and exit.\n" +
" [ -v ] [ --version ] (type=FLAG)\n" +
" Output version information and exit.");
/* "comment for parameter a" */
System.out.println (
" -a param a line 1");
System.out.println (
" param a line 2\n" +
" -h, --help Display this help and exit.\n" +
" -v, --version Output version information and exit.\n" +
"abc");
System.out.println (
"def");
}
System.exit (status);
}
/* return next (non-option) parameter */
public int next_param () { return _optind; }
/* getter functions for command line parameters */
public boolean a () { return _a; }
public boolean h () { return _h; }
public boolean v () { return _v; }
}
|