|
kusano |
7d535a |
/* Declarations for getopt.
|
|
kusano |
7d535a |
Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
This program is free software; you can redistribute it and/or modify it
|
|
kusano |
7d535a |
under the terms of the GNU General Public License as published by the
|
|
kusano |
7d535a |
Free Software Foundation; either version 2, or (at your option) any
|
|
kusano |
7d535a |
later version.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
This program is distributed in the hope that it will be useful,
|
|
kusano |
7d535a |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
kusano |
7d535a |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
kusano |
7d535a |
GNU General Public License for more details.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
You should have received a copy of the GNU General Public License
|
|
kusano |
7d535a |
along with this program; if not, write to the Free Software
|
|
kusano |
7d535a |
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifndef __MFX_GETOPT_H
|
|
kusano |
7d535a |
#define __MFX_GETOPT_H 1
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifdef __cplusplus
|
|
kusano |
7d535a |
/* extern "C" { */
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* For communication from `getopt' to the caller.
|
|
kusano |
7d535a |
When `getopt' finds an option that takes an argument,
|
|
kusano |
7d535a |
the argument value is returned here.
|
|
kusano |
7d535a |
Also, when `ordering' is RETURN_IN_ORDER,
|
|
kusano |
7d535a |
each non-option ARGV-element is returned here. */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
extern char *mfx_optarg;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Index in ARGV of the next element to be scanned.
|
|
kusano |
7d535a |
This is used for communication to and from the caller
|
|
kusano |
7d535a |
and for communication between successive calls to `getopt'.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
On entry to `getopt', zero means this is the first call; initialize.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
When `getopt' returns EOF, this is the index of the first of the
|
|
kusano |
7d535a |
non-option elements that the caller should itself scan.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Otherwise, `optind' communicates from one call to the next
|
|
kusano |
7d535a |
how much of ARGV has been scanned so far. */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
extern int mfx_optind;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Callers store zero here to inhibit the error message `getopt' prints
|
|
kusano |
7d535a |
for unrecognized options. */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
extern int mfx_opterr;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Set to an option character which was unrecognized. */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
extern int mfx_optopt;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Describe the long-named options requested by the application.
|
|
kusano |
7d535a |
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
|
|
kusano |
7d535a |
of `struct option' terminated by an element containing a name which is
|
|
kusano |
7d535a |
zero.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
The field `has_arg' is:
|
|
kusano |
7d535a |
no_argument (or 0) if the option does not take an argument,
|
|
kusano |
7d535a |
required_argument (or 1) if the option requires an argument,
|
|
kusano |
7d535a |
optional_argument (or 2) if the option takes an optional argument.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
If the field `flag' is not NULL, it points to a variable that is set
|
|
kusano |
7d535a |
to the value given in the field `val' when the option is found, but
|
|
kusano |
7d535a |
left unchanged if the option is not found.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
To have a long-named option do something other than set an `int' to
|
|
kusano |
7d535a |
a compiled-in constant, such as set a value from `optarg', set the
|
|
kusano |
7d535a |
option's `flag' field to zero and its `val' field to a nonzero
|
|
kusano |
7d535a |
value (the equivalent single-letter option character, if there is
|
|
kusano |
7d535a |
one). For long options that have a zero `flag' field, `getopt'
|
|
kusano |
7d535a |
returns the contents of the `val' field. */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
struct mfx_option
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
const char *name;
|
|
kusano |
7d535a |
/* has_arg can't be an enum because some compilers complain about
|
|
kusano |
7d535a |
type mismatches in all the code that assumes it is an int. */
|
|
kusano |
7d535a |
int has_arg;
|
|
kusano |
7d535a |
int *flag;
|
|
kusano |
7d535a |
int val;
|
|
kusano |
7d535a |
};
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Names for the values of the `has_arg' field of `struct option'. */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#define mfx_no_argument 0
|
|
kusano |
7d535a |
#define mfx_required_argument 1
|
|
kusano |
7d535a |
#define mfx_optional_argument 2
|
|
kusano |
7d535a |
#define mfx_exact_argument 0x10 /* no abbrev. */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
int mfx_getopt(int argc, char **argv, const char *shortopts);
|
|
kusano |
7d535a |
int mfx_getopt_long(int argc, char **argv, const char *shortopts,
|
|
kusano |
7d535a |
const struct mfx_option *longopts, int *longind);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifdef __cplusplus
|
|
kusano |
7d535a |
/* } */
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#endif /* __MFX_GETOPT_H */
|