File indexing completed on 2025-02-02 04:10:07

0001 /* Declarations for getopt.
0002    Copyright (C) 1989,90,91,92,93,94,96,97,98,99 Free Software Foundation, Inc.
0003    This file is part of the GNU C Library.
0004 
0005    The GNU C Library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public License as
0007    published by the Free Software Foundation; either version 2 of the
0008    License, or (at your option) any later version.
0009 
0010    The GNU C Library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public
0016    License along with the GNU C Library; see the file COPYING.LIB.  If not,
0017    write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.  */
0019 
0020 #ifndef _GETOPT_H
0021 
0022 #ifndef __need_getopt
0023 # define _GETOPT_H 1
0024 #endif
0025 
0026 /* If __GNU_LIBRARY__ is not already defined, either we are being used
0027    standalone, or this is the first header included in the source file.
0028    If we are being used with glibc, we need to include <features.h>, but
0029    that does not exist if we are standalone.  So: if __GNU_LIBRARY__ is
0030    not defined, include <ctype.h>, which will pull in <features.h> for us
0031    if it's from glibc.  (Why ctype.h?  It's guaranteed to exist and it
0032    doesn't flood the namespace with stuff the way some other headers do.)  */
0033 #if !defined __GNU_LIBRARY__
0034 # include <ctype.h>
0035 #endif
0036 
0037 #ifdef  __cplusplus
0038 extern "C" {
0039 #endif
0040 
0041 /* For communication from `getopt' to the caller.
0042    When `getopt' finds an option that takes an argument,
0043    the argument value is returned here.
0044    Also, when `ordering' is RETURN_IN_ORDER,
0045    each non-option ARGV-element is returned here.  */
0046 
0047 extern char *optarg;
0048 
0049 /* Index in ARGV of the next element to be scanned.
0050    This is used for communication to and from the caller
0051    and for communication between successive calls to `getopt'.
0052 
0053    On entry to `getopt', zero means this is the first call; initialize.
0054 
0055    When `getopt' returns -1, this is the index of the first of the
0056    non-option elements that the caller should itself scan.
0057 
0058    Otherwise, `optind' communicates from one call to the next
0059    how much of ARGV has been scanned so far.  */
0060 
0061 extern int optind;
0062 
0063 /* Callers store zero here to inhibit the error message `getopt' prints
0064    for unrecognized options.  */
0065 
0066 extern int opterr;
0067 
0068 /* Set to an option character which was unrecognized.  */
0069 
0070 extern int optopt;
0071 
0072 #ifndef __need_getopt
0073 /* Describe the long-named options requested by the application.
0074    The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
0075    of `struct option' terminated by an element containing a name which is
0076    zero.
0077 
0078    The field `has_arg' is:
0079    no_argument      (or 0) if the option does not take an argument,
0080    required_argument    (or 1) if the option requires an argument,
0081    optional_argument    (or 2) if the option takes an optional argument.
0082 
0083    If the field `flag' is not NULL, it points to a variable that is set
0084    to the value given in the field `val' when the option is found, but
0085    left unchanged if the option is not found.
0086 
0087    To have a long-named option do something other than set an `int' to
0088    a compiled-in constant, such as set a value from `optarg', set the
0089    option's `flag' field to zero and its `val' field to a nonzero
0090    value (the equivalent single-letter option character, if there is
0091    one).  For long options that have a zero `flag' field, `getopt'
0092    returns the contents of the `val' field.  */
0093 
0094 struct option
0095 {
0096 # if defined __STDC__ && __STDC__
0097   const char *name;
0098 # else
0099   char *name;
0100 # endif
0101   /* has_arg can't be an enum because some compilers complain about
0102      type mismatches in all the code that assumes it is an int.  */
0103   int has_arg;
0104   int *flag;
0105   int val;
0106 };
0107 
0108 /* Names for the values of the `has_arg' field of `struct option'.  */
0109 
0110 # define no_argument        0
0111 # define required_argument  1
0112 # define optional_argument  2
0113 #endif  /* need getopt */
0114 
0115 
0116 /* Get definitions and prototypes for functions to process the
0117    arguments in ARGV (ARGC of them, minus the program name) for
0118    options given in OPTS.
0119 
0120    Return the option character from OPTS just read.  Return -1 when
0121    there are no more options.  For unrecognized options, or options
0122    missing arguments, `optopt' is set to the option letter, and '?' is
0123    returned.
0124 
0125    The OPTS string is a list of characters which are recognized option
0126    letters, optionally followed by colons, specifying that that letter
0127    takes an argument, to be placed in `optarg'.
0128 
0129    If a letter in OPTS is followed by two colons, its argument is
0130    optional.  This behavior is specific to the GNU `getopt'.
0131 
0132    The argument `--' causes premature termination of argument
0133    scanning, explicitly telling `getopt' that there are no more
0134    options.
0135 
0136    If OPTS begins with `--', then non-option arguments are treated as
0137    arguments to the option '\0'.  This behavior is specific to the GNU
0138    `getopt'.  */
0139 
0140 #if defined __STDC__ && __STDC__
0141 # ifdef __GNU_LIBRARY__
0142 /* Many other libraries have conflicting prototypes for getopt, with
0143    differences in the consts, in stdlib.h.  To avoid compilation
0144    errors, only prototype getopt for the GNU C library.  */
0145 extern int getopt (int argc, char *const *argv, const char *shortopts);
0146 # else /* not __GNU_LIBRARY__ */
0147 extern int getopt ();
0148 # endif /* __GNU_LIBRARY__ */
0149 
0150 # ifndef __need_getopt
0151 extern int getopt_long (int argc, char *const *argv, const char *shortopts,
0152                 const struct option *longopts, int *longind);
0153 extern int getopt_long_only (int argc, char *const *argv,
0154                  const char *shortopts,
0155                      const struct option *longopts, int *longind);
0156 
0157 /* Internal only.  Users should not call this directly.  */
0158 extern int _getopt_internal (int argc, char *const *argv,
0159                  const char *shortopts,
0160                      const struct option *longopts, int *longind,
0161                  int long_only);
0162 # endif
0163 #else /* not __STDC__ */
0164 extern int getopt ();
0165 # ifndef __need_getopt
0166 extern int getopt_long ();
0167 extern int getopt_long_only ();
0168 
0169 extern int _getopt_internal ();
0170 # endif
0171 #endif /* __STDC__ */
0172 
0173 #ifdef  __cplusplus
0174 }
0175 #endif
0176 
0177 /* Make sure we later can get all the definitions and declarations.  */
0178 #undef __need_getopt
0179 
0180 #endif /* getopt.h */