1aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o/* Declarations for getopt.
2aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc.
3aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   This file is part of the GNU C Library.
4aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
5aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   The GNU C Library is free software; you can redistribute it and/or
6aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   modify it under the terms of the GNU Library General Public License as
7aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   published by the Free Software Foundation; either version 2 of the
8aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   License, or (at your option) any later version.
9aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
10aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   The GNU C Library is distributed in the hope that it will be useful,
11aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   but WITHOUT ANY WARRANTY; without even the implied warranty of
12aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   Library General Public License for more details.
14aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
15aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   You should have received a copy of the GNU Library General Public
16aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   License along with the GNU C Library; see the file COPYING.LIB.  If not,
17aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   Boston, MA 02111-1307, USA.  */
19aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
20aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#ifndef _GETOPT_H
21aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#define _GETOPT_H 1
22aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
23aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#ifdef	__cplusplus
24aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'oextern "C" {
25aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#endif
26aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
27aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#ifndef GETOPT_VARIABLE
28aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#define GETOPT_VARIABLE
29aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#endif
30aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
31aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o/* For communication from `getopt' to the caller.
32aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   When `getopt' finds an option that takes an argument,
33aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   the argument value is returned here.
34aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   Also, when `ordering' is RETURN_IN_ORDER,
35aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   each non-option ARGV-element is returned here.  */
36aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
37aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'oextern GETOPT_VARIABLE char *optarg;
38aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
39aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o/* Index in ARGV of the next element to be scanned.
40aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   This is used for communication to and from the caller
41aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   and for communication between successive calls to `getopt'.
42aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
43aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   On entry to `getopt', zero means this is the first call; initialize.
44aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
45aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   When `getopt' returns -1, this is the index of the first of the
46aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   non-option elements that the caller should itself scan.
47aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
48aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   Otherwise, `optind' communicates from one call to the next
49aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   how much of ARGV has been scanned so far.  */
50aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
51aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'oextern GETOPT_VARIABLE int optind;
52aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
53aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o/* Callers store zero here to inhibit the error message `getopt' prints
54aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   for unrecognized options.  */
55aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
56aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'oextern GETOPT_VARIABLE int opterr;
57aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
58aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o/* Set to an option character which was unrecognized.  */
59aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
60aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'oextern GETOPT_VARIABLE int optopt;
61aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
62aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o/* Describe the long-named options requested by the application.
63aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
64aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   of `struct option' terminated by an element containing a name which is
65aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   zero.
66aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
67aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   The field `has_arg' is:
68aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   no_argument		(or 0) if the option does not take an argument,
69aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   required_argument	(or 1) if the option requires an argument,
70aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   optional_argument 	(or 2) if the option takes an optional argument.
71aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
72aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   If the field `flag' is not NULL, it points to a variable that is set
73aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   to the value given in the field `val' when the option is found, but
74aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   left unchanged if the option is not found.
75aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
76aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   To have a long-named option do something other than set an `int' to
77aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   a compiled-in constant, such as set a value from `optarg', set the
78aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   option's `flag' field to zero and its `val' field to a nonzero
79aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   value (the equivalent single-letter option character, if there is
80aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   one).  For long options that have a zero `flag' field, `getopt'
81aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   returns the contents of the `val' field.  */
82aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
83aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'ostruct option
84aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o{
85aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#if defined (__STDC__) && __STDC__
86aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o  const char *name;
87aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#else
88aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o  char *name;
89aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#endif
90aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o  /* has_arg can't be an enum because some compilers complain about
91aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o     type mismatches in all the code that assumes it is an int.  */
92aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o  int has_arg;
93aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o  int *flag;
94aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o  int val;
95aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o};
96aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
97aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o/* Names for the values of the `has_arg' field of `struct option'.  */
98aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
99aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#define	no_argument		0
100aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#define required_argument	1
101aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#define optional_argument	2
102aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
103aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#if defined (__STDC__) && __STDC__
104aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#ifdef __GNU_LIBRARY__
105aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o/* Many other libraries have conflicting prototypes for getopt, with
106aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   differences in the consts, in stdlib.h.  To avoid compilation
107aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o   errors, only prototype getopt for the GNU C library.  */
108aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'oextern int getopt (int argc, char *const *argv, const char *shortopts);
109aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#else /* not __GNU_LIBRARY__ */
110aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'oextern int getopt ();
111aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#endif /* __GNU_LIBRARY__ */
112aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'oextern int getopt_long (int argc, char *const *argv, const char *shortopts,
113aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o		        const struct option *longopts, int *longind);
114aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'oextern int getopt_long_only (int argc, char *const *argv,
115aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o			     const char *shortopts,
116aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o		             const struct option *longopts, int *longind);
117aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
118aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o/* Internal only.  Users should not call this directly.  */
119aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'oextern int _getopt_internal (int argc, char *const *argv,
120aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o			     const char *shortopts,
121aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o		             const struct option *longopts, int *longind,
122aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o			     int long_only);
123aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#else /* not __STDC__ */
124aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'oextern int getopt ();
125aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'oextern int getopt_long ();
126aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'oextern int getopt_long_only ();
127aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
128aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'oextern int _getopt_internal ();
129aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#endif /* __STDC__ */
130aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
131aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#ifdef	__cplusplus
132aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o}
133aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#endif
134aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o
135aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o#endif /* _GETOPT_H */
136