195b7b453SJohn Marino /* Internal declarations for getopt. 2*09d4459fSDaniel Fojt Copyright (C) 1989-2020 Free Software Foundation, Inc. 3*09d4459fSDaniel Fojt This file is part of the GNU C Library and is also part of gnulib. 4*09d4459fSDaniel Fojt Patches to this file should be submitted to both projects. 595b7b453SJohn Marino 6*09d4459fSDaniel Fojt The GNU C Library is free software; you can redistribute it and/or 7*09d4459fSDaniel Fojt modify it under the terms of the GNU General Public 8*09d4459fSDaniel Fojt License as published by the Free Software Foundation; either 9*09d4459fSDaniel Fojt version 3 of the License, or (at your option) any later version. 1095b7b453SJohn Marino 11*09d4459fSDaniel Fojt The GNU C Library is distributed in the hope that it will be useful, 1295b7b453SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 13*09d4459fSDaniel Fojt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14*09d4459fSDaniel Fojt General Public License for more details. 1595b7b453SJohn Marino 16*09d4459fSDaniel Fojt You should have received a copy of the GNU General Public 17*09d4459fSDaniel Fojt License along with the GNU C Library; if not, see 18*09d4459fSDaniel Fojt <https://www.gnu.org/licenses/>. */ 1995b7b453SJohn Marino 2095b7b453SJohn Marino #ifndef _GETOPT_INT_H 2195b7b453SJohn Marino #define _GETOPT_INT_H 1 2295b7b453SJohn Marino 2395b7b453SJohn Marino #include <getopt.h> 2495b7b453SJohn Marino 2595b7b453SJohn Marino extern int _getopt_internal (int ___argc, char **___argv, 2695b7b453SJohn Marino const char *__shortopts, 2795b7b453SJohn Marino const struct option *__longopts, int *__longind, 2895b7b453SJohn Marino int __long_only, int __posixly_correct); 2995b7b453SJohn Marino 3095b7b453SJohn Marino 3195b7b453SJohn Marino /* Reentrant versions which can handle parsing multiple argument 3295b7b453SJohn Marino vectors at the same time. */ 3395b7b453SJohn Marino 3495b7b453SJohn Marino /* Describe how to deal with options that follow non-option ARGV-elements. 3595b7b453SJohn Marino 36*09d4459fSDaniel Fojt REQUIRE_ORDER means don't recognize them as options; stop option 37*09d4459fSDaniel Fojt processing when the first non-option is seen. This is what POSIX 38*09d4459fSDaniel Fojt specifies should happen. 3995b7b453SJohn Marino 40*09d4459fSDaniel Fojt PERMUTE means permute the contents of ARGV as we scan, so that 41*09d4459fSDaniel Fojt eventually all the non-options are at the end. This allows options 42*09d4459fSDaniel Fojt to be given in any order, even with programs that were not written 43*09d4459fSDaniel Fojt to expect this. 4495b7b453SJohn Marino 4595b7b453SJohn Marino RETURN_IN_ORDER is an option available to programs that were 4695b7b453SJohn Marino written to expect options and other ARGV-elements in any order 4795b7b453SJohn Marino and that care about the ordering of the two. We describe each 4895b7b453SJohn Marino non-option ARGV-element as if it were the argument of an option 49*09d4459fSDaniel Fojt with character code 1. 5095b7b453SJohn Marino 51cf28ed85SJohn Marino The special argument '--' forces an end of option-scanning regardless 52cf28ed85SJohn Marino of the value of 'ordering'. In the case of RETURN_IN_ORDER, only 53cf28ed85SJohn Marino '--' can cause 'getopt' to return -1 with 'optind' != ARGC. */ 5495b7b453SJohn Marino 5595b7b453SJohn Marino enum __ord 5695b7b453SJohn Marino { 5795b7b453SJohn Marino REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER 5895b7b453SJohn Marino }; 5995b7b453SJohn Marino 6095b7b453SJohn Marino /* Data type for reentrant functions. */ 6195b7b453SJohn Marino struct _getopt_data 6295b7b453SJohn Marino { 6395b7b453SJohn Marino /* These have exactly the same meaning as the corresponding global 6495b7b453SJohn Marino variables, except that they are used for the reentrant 6595b7b453SJohn Marino versions of getopt. */ 6695b7b453SJohn Marino int optind; 6795b7b453SJohn Marino int opterr; 6895b7b453SJohn Marino int optopt; 6995b7b453SJohn Marino char *optarg; 7095b7b453SJohn Marino 7195b7b453SJohn Marino /* Internal members. */ 7295b7b453SJohn Marino 7395b7b453SJohn Marino /* True if the internal members have been initialized. */ 7495b7b453SJohn Marino int __initialized; 7595b7b453SJohn Marino 7695b7b453SJohn Marino /* The next char to be scanned in the option-element 7795b7b453SJohn Marino in which the last option character we returned was found. 7895b7b453SJohn Marino This allows us to pick up the scan where we left off. 7995b7b453SJohn Marino 8095b7b453SJohn Marino If this is zero, or a null string, it means resume the scan 8195b7b453SJohn Marino by advancing to the next ARGV-element. */ 8295b7b453SJohn Marino char *__nextchar; 8395b7b453SJohn Marino 8495b7b453SJohn Marino /* See __ord above. */ 8595b7b453SJohn Marino enum __ord __ordering; 8695b7b453SJohn Marino 8795b7b453SJohn Marino /* Handle permutation of arguments. */ 8895b7b453SJohn Marino 8995b7b453SJohn Marino /* Describe the part of ARGV that contains non-options that have 90cf28ed85SJohn Marino been skipped. 'first_nonopt' is the index in ARGV of the first 91cf28ed85SJohn Marino of them; 'last_nonopt' is the index after the last of them. */ 9295b7b453SJohn Marino 9395b7b453SJohn Marino int __first_nonopt; 9495b7b453SJohn Marino int __last_nonopt; 9595b7b453SJohn Marino }; 9695b7b453SJohn Marino 9795b7b453SJohn Marino /* The initializer is necessary to set OPTIND and OPTERR to their 9895b7b453SJohn Marino default values and to clear the initialization flag. */ 9995b7b453SJohn Marino #define _GETOPT_DATA_INITIALIZER { 1, 1 } 10095b7b453SJohn Marino 10195b7b453SJohn Marino extern int _getopt_internal_r (int ___argc, char **___argv, 10295b7b453SJohn Marino const char *__shortopts, 10395b7b453SJohn Marino const struct option *__longopts, int *__longind, 10495b7b453SJohn Marino int __long_only, struct _getopt_data *__data, 10595b7b453SJohn Marino int __posixly_correct); 10695b7b453SJohn Marino 10795b7b453SJohn Marino extern int _getopt_long_r (int ___argc, char **___argv, 10895b7b453SJohn Marino const char *__shortopts, 10995b7b453SJohn Marino const struct option *__longopts, int *__longind, 11095b7b453SJohn Marino struct _getopt_data *__data); 11195b7b453SJohn Marino 11295b7b453SJohn Marino extern int _getopt_long_only_r (int ___argc, char **___argv, 11395b7b453SJohn Marino const char *__shortopts, 11495b7b453SJohn Marino const struct option *__longopts, 11595b7b453SJohn Marino int *__longind, 11695b7b453SJohn Marino struct _getopt_data *__data); 11795b7b453SJohn Marino 11895b7b453SJohn Marino #endif /* getopt_int.h */ 119