Home | History | Annotate | Download | only in lib
      1 /* Internal declarations for getopt.
      2    Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2004, 2009-2012 Free Software
      3    Foundation, Inc.
      4    This file is part of the GNU C Library.
      5 
      6    This program is free software: you can redistribute it and/or modify
      7    it under the terms of the GNU General Public License as published by
      8    the Free Software Foundation; either version 3 of the License, or
      9    (at your option) any later version.
     10 
     11    This program is distributed in the hope that it will be useful,
     12    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14    GNU General Public License for more details.
     15 
     16    You should have received a copy of the GNU General Public License
     17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     18 
     19 #ifndef _GETOPT_INT_H
     20 #define _GETOPT_INT_H   1
     21 
     22 #include <getopt.h>
     23 
     24 extern int _getopt_internal (int ___argc, char **___argv,
     25                              const char *__shortopts,
     26                              const struct option *__longopts, int *__longind,
     27                              int __long_only, int __posixly_correct);
     28 
     29 
     30 /* Reentrant versions which can handle parsing multiple argument
     32    vectors at the same time.  */
     33 
     34 /* Describe how to deal with options that follow non-option ARGV-elements.
     35 
     36    If the caller did not specify anything,
     37    the default is REQUIRE_ORDER if the environment variable
     38    POSIXLY_CORRECT is defined, PERMUTE otherwise.
     39 
     40    REQUIRE_ORDER means don't recognize them as options;
     41    stop option processing when the first non-option is seen.
     42    This is what Unix does.
     43    This mode of operation is selected by either setting the environment
     44    variable POSIXLY_CORRECT, or using '+' as the first character
     45    of the list of option characters, or by calling getopt.
     46 
     47    PERMUTE is the default.  We permute the contents of ARGV as we
     48    scan, so that eventually all the non-options are at the end.
     49    This allows options to be given in any order, even with programs
     50    that were not written to expect this.
     51 
     52    RETURN_IN_ORDER is an option available to programs that were
     53    written to expect options and other ARGV-elements in any order
     54    and that care about the ordering of the two.  We describe each
     55    non-option ARGV-element as if it were the argument of an option
     56    with character code 1.  Using '-' as the first character of the
     57    list of option characters selects this mode of operation.
     58 
     59    The special argument '--' forces an end of option-scanning regardless
     60    of the value of 'ordering'.  In the case of RETURN_IN_ORDER, only
     61    '--' can cause 'getopt' to return -1 with 'optind' != ARGC.  */
     62 
     63 enum __ord
     64   {
     65     REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
     66   };
     67 
     68 /* Data type for reentrant functions.  */
     69 struct _getopt_data
     70 {
     71   /* These have exactly the same meaning as the corresponding global
     72      variables, except that they are used for the reentrant
     73      versions of getopt.  */
     74   int optind;
     75   int opterr;
     76   int optopt;
     77   char *optarg;
     78 
     79   /* Internal members.  */
     80 
     81   /* True if the internal members have been initialized.  */
     82   int __initialized;
     83 
     84   /* The next char to be scanned in the option-element
     85      in which the last option character we returned was found.
     86      This allows us to pick up the scan where we left off.
     87 
     88      If this is zero, or a null string, it means resume the scan
     89      by advancing to the next ARGV-element.  */
     90   char *__nextchar;
     91 
     92   /* See __ord above.  */
     93   enum __ord __ordering;
     94 
     95   /* If the POSIXLY_CORRECT environment variable is set
     96      or getopt was called.  */
     97   int __posixly_correct;
     98 
     99 
    100   /* Handle permutation of arguments.  */
    101 
    102   /* Describe the part of ARGV that contains non-options that have
    103      been skipped.  'first_nonopt' is the index in ARGV of the first
    104      of them; 'last_nonopt' is the index after the last of them.  */
    105 
    106   int __first_nonopt;
    107   int __last_nonopt;
    108 
    109 #if defined _LIBC && defined USE_NONOPTION_FLAGS
    110   int __nonoption_flags_max_len;
    111   int __nonoption_flags_len;
    112 #endif
    113 };
    114 
    115 /* The initializer is necessary to set OPTIND and OPTERR to their
    116    default values and to clear the initialization flag.  */
    117 #define _GETOPT_DATA_INITIALIZER        { 1, 1 }
    118 
    119 extern int _getopt_internal_r (int ___argc, char **___argv,
    120                                const char *__shortopts,
    121                                const struct option *__longopts, int *__longind,
    122                                int __long_only, struct _getopt_data *__data,
    123                                int __posixly_correct);
    124 
    125 extern int _getopt_long_r (int ___argc, char **___argv,
    126                            const char *__shortopts,
    127                            const struct option *__longopts, int *__longind,
    128                            struct _getopt_data *__data);
    129 
    130 extern int _getopt_long_only_r (int ___argc, char **___argv,
    131                                 const char *__shortopts,
    132                                 const struct option *__longopts,
    133                                 int *__longind,
    134                                 struct _getopt_data *__data);
    135 
    136 #endif /* getopt_int.h */
    137