WIP: fsctl_pipe_wait
[metze/wireshark/wip.git] / wsutil / wsgetopt.h
1 /*
2    $Id$
3
4    Declarations for getopt.
5    Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2009,2010
6    Free Software Foundation, Inc.
7    This file is part of the GNU C Library.
8
9    The GNU C Library is free software; you can redistribute it and/or
10    modify it under the terms of the GNU Lesser General Public
11    License as published by the Free Software Foundation; either
12    version 2.1 of the License, or (at your option) any later version.
13
14    The GNU C Library is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17    Lesser General Public License for more details.
18
19    You should have received a copy of the GNU Lesser General Public
20    License along with the GNU C Library; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22    */
23
24 #ifndef _GETOPT_H
25
26 #ifndef __need_getopt
27 # define _GETOPT_H 1
28 #endif
29
30 #include "ws_symbol_export.h"
31
32 /* If __GNU_LIBRARY__ is not already defined, either we are being used
33    standalone, or this is the first header included in the source file.
34    If we are being used with glibc, we need to include <features.h>, but
35    that does not exist if we are standalone.  So: if __GNU_LIBRARY__ is
36    not defined, include <ctype.h>, which will pull in <features.h> for us
37    if it's from glibc.  (Why ctype.h?  It's guaranteed to exist and it
38    doesn't flood the namespace with stuff the way some other headers do.)  */
39 #if !defined __GNU_LIBRARY__
40 # include <ctype.h>
41 #endif
42
43 #ifndef __THROW
44 # ifndef __GNUC_PREREQ
45 #  define __GNUC_PREREQ(maj, min) (0)
46 # endif
47 # if defined __cplusplus && __GNUC_PREREQ (2,8)
48 #  define __THROW       throw ()
49 # else
50 #  define __THROW
51 # endif
52 #endif
53
54 #ifdef  __cplusplus
55 extern "C" {
56 #endif
57
58 /* For communication from `getopt' to the caller.
59    When `getopt' finds an option that takes an argument,
60    the argument value is returned here.
61    Also, when `ordering' is RETURN_IN_ORDER,
62    each non-option ARGV-element is returned here.  */
63
64 WS_DLL_PUBLIC char *optarg;
65
66 /* Index in ARGV of the next element to be scanned.
67    This is used for communication to and from the caller
68    and for communication between successive calls to `getopt'.
69
70    On entry to `getopt', zero means this is the first call; initialize.
71
72    When `getopt' returns -1, this is the index of the first of the
73    non-option elements that the caller should itself scan.
74
75    Otherwise, `optind' communicates from one call to the next
76    how much of ARGV has been scanned so far.  */
77
78 WS_DLL_PUBLIC int optind;
79
80 /* Callers store zero here to inhibit the error message `getopt' prints
81    for unrecognized options.  */
82
83 WS_DLL_PUBLIC int opterr;
84
85 /* Set to an option character which was unrecognized.  */
86
87 WS_DLL_PUBLIC int optopt;
88
89 #ifndef __need_getopt
90 /* Describe the long-named options requested by the application.
91    The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
92    of `struct option' terminated by an element containing a name which is
93    zero.
94
95    The field `has_arg' is:
96    no_argument          (or 0) if the option does not take an argument,
97    required_argument    (or 1) if the option requires an argument,
98    optional_argument    (or 2) if the option takes an optional argument.
99
100    If the field `flag' is not NULL, it points to a variable that is set
101    to the value given in the field `val' when the option is found, but
102    left unchanged if the option is not found.
103
104    To have a long-named option do something other than set an `int' to
105    a compiled-in constant, such as set a value from `optarg', set the
106    option's `flag' field to zero and its `val' field to a nonzero
107    value (the equivalent single-letter option character, if there is
108    one).  For long options that have a zero `flag' field, `getopt'
109    returns the contents of the `val' field.  */
110
111 struct option
112 {
113   const char *name;
114   /* has_arg can't be an enum because some compilers complain about
115      type mismatches in all the code that assumes it is an int.  */
116   int has_arg;
117   int *flag;
118   int val;
119 };
120
121 /* Names for the values of the `has_arg' field of `struct option'.  */
122
123 # define no_argument            0
124 # define required_argument      1
125 # define optional_argument      2
126 #endif  /* need getopt */
127
128
129 /* Get definitions and prototypes for functions to process the
130    arguments in ARGV (ARGC of them, minus the program name) for
131    options given in OPTS.
132
133    Return the option character from OPTS just read.  Return -1 when
134    there are no more options.  For unrecognized options, or options
135    missing arguments, `optopt' is set to the option letter, and '?' is
136    returned.
137
138    The OPTS string is a list of characters which are recognized option
139    letters, optionally followed by colons, specifying that that letter
140    takes an argument, to be placed in `optarg'.
141
142    If a letter in OPTS is followed by two colons, its argument is
143    optional.  This behavior is specific to the GNU `getopt'.
144
145    The argument `--' causes premature termination of argument
146    scanning, explicitly telling `getopt' that there are no more
147    options.
148
149    If OPTS begins with `--', then non-option arguments are treated as
150    arguments to the option '\0'.  This behavior is specific to the GNU
151    `getopt'.  */
152
153 #ifdef __GNU_LIBRARY__
154 /* Many other libraries have conflicting prototypes for getopt, with
155    differences in the consts, in stdlib.h.  To avoid compilation
156    errors, only prototype getopt for the GNU C library.  */
157 WS_DLL_PUBLIC int getopt (int ___argc, char *const *___argv, const char *__shortopts)
158        __THROW;
159
160 # if defined __need_getopt && defined __USE_POSIX2 \
161   && !defined __USE_POSIX_IMPLICITLY && !defined __USE_GNU
162 /* The GNU getopt has more functionality than the standard version.  The
163    additional functionality can be disable at runtime.  This redirection
164    helps to also do this at runtime.  */
165 #  ifdef __REDIRECT
166   extern int __REDIRECT_NTH (getopt, (int ___argc, char *const *___argv,
167                                       const char *__shortopts),
168                              __posix_getopt);
169 #  else
170 extern int __posix_getopt (int ___argc, char *const *___argv,
171                            const char *__shortopts) __THROW;
172 #   define getopt __posix_getopt
173 #  endif
174 # endif
175 #else /* not __GNU_LIBRARY__ */
176 WS_DLL_PUBLIC int getopt (int ___argc, char *const *___argv,
177                    const char *__shortopts);
178 #endif /* __GNU_LIBRARY__ */
179
180 #ifndef __need_getopt
181 WS_DLL_PUBLIC int getopt_long (int ___argc, char *const *___argv,
182                         const char *__shortopts,
183                         const struct option *__longopts, int *__longind)
184        __THROW;
185 extern int getopt_long_only (int ___argc, char *const *___argv,
186                              const char *__shortopts,
187                              const struct option *__longopts, int *__longind)
188        __THROW;
189
190 #endif
191
192 #ifdef  __cplusplus
193 }
194 #endif
195
196 /* Make sure we later can get all the definitions and declarations.  */
197 #undef __need_getopt
198
199 #endif /* getopt.h */