1 /* Declarations for _getopt.
2 
3    Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
4 
5    This file is part of GNU MCSim.
6 
7    GNU MCSim is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License
9    as published by the Free Software Foundation; either version 3
10    of the License, or (at your option) any later version.
11 
12    GNU MCSim is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with GNU MCSim; if not, see <http://www.gnu.org/licenses/>
19 */
20 
21 #ifndef GETOPT_H_DEFINED
22 
23 /* ----------------------------------------------------------------------------
24    For communication from `_getopt' to the caller.
25    When `_getopt' finds an option that takes an argument,
26    the argument value is returned here.
27    Also, when `ordering' is RETURN_IN_ORDER,
28    each non-option ARGV-element is returned here.  */
29 
30 extern char *optarg;
31 
32 /* Index in ARGV of the next element to be scanned.
33    This is used for communication to and from the caller
34    and for communication between successive calls to `_getopt'.
35 
36    On entry to `_getopt', zero means this is the first call; initialize.
37 
38    When `_getopt' returns EOF, this is the index of the first of the
39    non-option elements that the caller should itself scan.
40 
41    Otherwise, `optind' communicates from one call to the next
42    how much of ARGV has been scanned so far.  */
43 
44 extern int optind;
45 
46 /* Callers store zero here to inhibit the error message `_getopt' prints
47    for unrecognized options.  */
48 
49 extern int opterr;
50 
51 /* Describe the long-named options requested by the application.
52    The LONG_OPTIONS argument to _getopt_long or _getopt_long_only is a vector
53    of `struct option' terminated by an element containing a name which is
54    zero.
55 
56    The field `has_arg' is:
57    no_argument		(or 0) if the option does not take an argument,
58    required_argument	(or 1) if the option requires an argument,
59    optional_argument 	(or 2) if the option takes an optional argument.
60 
61    If the field `flag' is not NULL, it points to a variable that is set
62    to the value given in the field `val' when the option is found, but
63    left unchanged if the option is not found.
64 
65    To have a long-named option do something other than set an `int' to
66    a compiled-in constant, such as set a value from `optarg', set the
67    option's `flag' field to zero and its `val' field to a nonzero
68    value (the equivalent single-letter option character, if there is
69    one).  For long options that have a zero `flag' field, `_getopt'
70    returns the contents of the `val' field.  */
71 
72 struct option
73 {
74   const char *name;
75 
76   /* has_arg can't be an enum because some compilers complain about
77      type mismatches in all the code that assumes it is an int.  */
78   int has_arg;
79   int *flag;
80   int val;
81 };
82 
83 /* Names for the values of the `has_arg' field of `struct option'.  */
84 
85 enum _argtype
86 {
87   no_argument,
88   required_argument,
89   optional_argument
90 };
91 
92 int _getopt (int argc, char *const *argv, const char *shortopts);
93 extern int _getopt_long (int argc, char *const *argv, const char *shortopts,
94 		        const struct option *longopts, int *longind);
95 extern int _getopt_long_only (int argc, char *const *argv,
96 			     const char *shortopts,
97 		             const struct option *longopts, int *longind);
98 
99 /* Internal only.  Users should not call this directly.  */
100 extern int _getopt_internal (int argc, char *const *argv,
101 			     const char *shortopts,
102 		             const struct option *longopts, int *longind,
103 			     int long_only);
104 
105 #define GETOPT_H_DEFINED
106 #endif  /* GETOPT_H_DEFINED */
107 
108 /* end */
109 
110