117721Speter/* Declarations for getopt.
217721Speter   Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
317721Speter
417721Speter   This program is free software; you can redistribute it and/or modify it
517721Speter   under the terms of the GNU General Public License as published by the
617721Speter   Free Software Foundation; either version 2, or (at your option) any
717721Speter   later version.
817721Speter
917721Speter   This program is distributed in the hope that it will be useful,
1017721Speter   but WITHOUT ANY WARRANTY; without even the implied warranty of
1117721Speter   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1225839Speter   GNU General Public License for more details.  */
1317721Speter
1417721Speter#ifndef _GETOPT_H
1517721Speter#define _GETOPT_H 1
1617721Speter
17107484Speter/* CVS - DRP
18107484Speter *
19107484Speter * If the OS defines this, just redefine the names to avoid namespace
20107484Speter * clashes.  In theory, we should be testing the built in functions to
21107484Speter * see if they do what we want and use them if possible, but this is
22107484Speter * easier...
23107484Speter *
24107484Speter * Namely, this was occurring under Mac OS X.  This is a Mac OS X (or
25107484Speter * OS X related) bug.
26107484Speter *
27107484Speter * Oops.  We avoid compiling this with ifdefs because pretty much all of
28107484Speter * getopt.c is switched on the same macros...  this isn't right, but I think
29107484Speter * this isn't our file.  Probably best not to mess with it too much.
30107484Speter */
31107484Speter#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
32107484Speter# ifdef HAVE_GETOPT
33107484Speter#   define getopt		cvs_getopt
34107484Speter#   define optarg		cvs_optarg
35107484Speter#   define opterr		cvs_opterr
36107484Speter#   define optind		cvs_optind
37107484Speter#   define optopt		cvs_optopt
38107484Speter# endif /* HAVE_GETOPT */
39107484Speter#endif	/* _LIBC or not __GNU_LIBRARY__.  */
40107484Speter
4117721Speter#ifdef	__cplusplus
4217721Speterextern "C" {
4317721Speter#endif
4417721Speter
4517721Speter/* For communication from `getopt' to the caller.
4617721Speter   When `getopt' finds an option that takes an argument,
4717721Speter   the argument value is returned here.
4817721Speter   Also, when `ordering' is RETURN_IN_ORDER,
4917721Speter   each non-option ARGV-element is returned here.  */
5017721Speter
5117721Speterextern char *optarg;
5217721Speter
5317721Speter/* Index in ARGV of the next element to be scanned.
5417721Speter   This is used for communication to and from the caller
5517721Speter   and for communication between successive calls to `getopt'.
5617721Speter
5717721Speter   On entry to `getopt', zero means this is the first call; initialize.
5817721Speter
5917721Speter   When `getopt' returns EOF, this is the index of the first of the
6017721Speter   non-option elements that the caller should itself scan.
6117721Speter
6217721Speter   Otherwise, `optind' communicates from one call to the next
6317721Speter   how much of ARGV has been scanned so far.  */
6417721Speter
6517721Speterextern int optind;
6617721Speter
6717721Speter/* Callers store zero here to inhibit the error message `getopt' prints
6817721Speter   for unrecognized options.  */
6917721Speter
7017721Speterextern int opterr;
7117721Speter
7217721Speter/* Set to an option character which was unrecognized.  */
7317721Speter
7417721Speterextern int optopt;
7517721Speter
7617721Speter/* Describe the long-named options requested by the application.
7717721Speter   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
7817721Speter   of `struct option' terminated by an element containing a name which is
7917721Speter   zero.
8017721Speter
8117721Speter   The field `has_arg' is:
8217721Speter   no_argument		(or 0) if the option does not take an argument,
8317721Speter   required_argument	(or 1) if the option requires an argument,
8417721Speter   optional_argument 	(or 2) if the option takes an optional argument.
8517721Speter
8617721Speter   If the field `flag' is not NULL, it points to a variable that is set
8717721Speter   to the value given in the field `val' when the option is found, but
8817721Speter   left unchanged if the option is not found.
8917721Speter
9017721Speter   To have a long-named option do something other than set an `int' to
9117721Speter   a compiled-in constant, such as set a value from `optarg', set the
9217721Speter   option's `flag' field to zero and its `val' field to a nonzero
9317721Speter   value (the equivalent single-letter option character, if there is
9417721Speter   one).  For long options that have a zero `flag' field, `getopt'
9517721Speter   returns the contents of the `val' field.  */
9617721Speter
9717721Speterstruct option
9817721Speter{
9917721Speter#if	__STDC__
10017721Speter  const char *name;
10117721Speter#else
10217721Speter  char *name;
10317721Speter#endif
10417721Speter  /* has_arg can't be an enum because some compilers complain about
10517721Speter     type mismatches in all the code that assumes it is an int.  */
10617721Speter  int has_arg;
10717721Speter  int *flag;
10817721Speter  int val;
10917721Speter};
11017721Speter
11117721Speter/* Names for the values of the `has_arg' field of `struct option'.  */
11217721Speter
11317721Speter#define	no_argument		0
11417721Speter#define required_argument	1
11517721Speter#define optional_argument	2
11617721Speter
11717721Speter#if __STDC__
11817721Speter/* Many other libraries have conflicting prototypes for getopt, with
11954427Speter   differences in the consts, in stdlib.h.  We used to try to prototype
12054427Speter   it if __GNU_LIBRARY__ but that wasn't problem free either (I'm not sure
12154427Speter   exactly why), and there is no particular need to prototype it.
12254427Speter   We really shouldn't be trampling on the system's namespace at all by
12354427Speter   declaring getopt() but that is a bigger issue.  */
12417721Speterextern int getopt ();
12554427Speter
12617721Speterextern int getopt_long (int argc, char *const *argv, const char *shortopts,
12717721Speter		        const struct option *longopts, int *longind);
12817721Speterextern int getopt_long_only (int argc, char *const *argv,
12917721Speter			     const char *shortopts,
13017721Speter		             const struct option *longopts, int *longind);
13117721Speter
13217721Speter/* Internal only.  Users should not call this directly.  */
13317721Speterextern int _getopt_internal (int argc, char *const *argv,
13417721Speter			     const char *shortopts,
13517721Speter		             const struct option *longopts, int *longind,
13617721Speter			     int long_only);
13717721Speter#else /* not __STDC__ */
13817721Speterextern int getopt ();
13917721Speterextern int getopt_long ();
14017721Speterextern int getopt_long_only ();
14117721Speter
14217721Speterextern int _getopt_internal ();
14317721Speter#endif /* not __STDC__ */
14417721Speter
14517721Speter#ifdef	__cplusplus
14617721Speter}
14717721Speter#endif
14817721Speter
14917721Speter#endif /* _GETOPT_H */
150