xref: /dflybsd-src/contrib/grep/lib/getopt-core.h (revision 91b9ed38d3db6a8a8ac5b66da1d43e6e331e259a)
1*09d4459fSDaniel Fojt /* Declarations for getopt (basic, portable features only).
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.
5*09d4459fSDaniel Fojt 
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.
10*09d4459fSDaniel Fojt 
11*09d4459fSDaniel Fojt    The GNU C Library is distributed in the hope that it will be useful,
12*09d4459fSDaniel Fojt    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.
15*09d4459fSDaniel Fojt 
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/>.  */
19*09d4459fSDaniel Fojt 
20*09d4459fSDaniel Fojt #ifndef _GETOPT_CORE_H
21*09d4459fSDaniel Fojt #define _GETOPT_CORE_H 1
22*09d4459fSDaniel Fojt 
23*09d4459fSDaniel Fojt /* This header should not be used directly; include getopt.h or
24*09d4459fSDaniel Fojt    unistd.h instead.  Unlike most bits headers, it does not have
25*09d4459fSDaniel Fojt    a protective #error, because the guard macro for getopt.h in
26*09d4459fSDaniel Fojt    gnulib is not fixed.  */
27*09d4459fSDaniel Fojt 
28*09d4459fSDaniel Fojt __BEGIN_DECLS
29*09d4459fSDaniel Fojt 
30*09d4459fSDaniel Fojt /* For communication from 'getopt' to the caller.
31*09d4459fSDaniel Fojt    When 'getopt' finds an option that takes an argument,
32*09d4459fSDaniel Fojt    the argument value is returned here.
33*09d4459fSDaniel Fojt    Also, when 'ordering' is RETURN_IN_ORDER,
34*09d4459fSDaniel Fojt    each non-option ARGV-element is returned here.  */
35*09d4459fSDaniel Fojt 
36*09d4459fSDaniel Fojt extern char *optarg;
37*09d4459fSDaniel Fojt 
38*09d4459fSDaniel Fojt /* Index in ARGV of the next element to be scanned.
39*09d4459fSDaniel Fojt    This is used for communication to and from the caller
40*09d4459fSDaniel Fojt    and for communication between successive calls to 'getopt'.
41*09d4459fSDaniel Fojt 
42*09d4459fSDaniel Fojt    On entry to 'getopt', zero means this is the first call; initialize.
43*09d4459fSDaniel Fojt 
44*09d4459fSDaniel Fojt    When 'getopt' returns -1, this is the index of the first of the
45*09d4459fSDaniel Fojt    non-option elements that the caller should itself scan.
46*09d4459fSDaniel Fojt 
47*09d4459fSDaniel Fojt    Otherwise, 'optind' communicates from one call to the next
48*09d4459fSDaniel Fojt    how much of ARGV has been scanned so far.  */
49*09d4459fSDaniel Fojt 
50*09d4459fSDaniel Fojt extern int optind;
51*09d4459fSDaniel Fojt 
52*09d4459fSDaniel Fojt /* Callers store zero here to inhibit the error message 'getopt' prints
53*09d4459fSDaniel Fojt    for unrecognized options.  */
54*09d4459fSDaniel Fojt 
55*09d4459fSDaniel Fojt extern int opterr;
56*09d4459fSDaniel Fojt 
57*09d4459fSDaniel Fojt /* Set to an option character which was unrecognized.  */
58*09d4459fSDaniel Fojt 
59*09d4459fSDaniel Fojt extern int optopt;
60*09d4459fSDaniel Fojt 
61*09d4459fSDaniel Fojt /* Get definitions and prototypes for functions to process the
62*09d4459fSDaniel Fojt    arguments in ARGV (ARGC of them, minus the program name) for
63*09d4459fSDaniel Fojt    options given in OPTS.
64*09d4459fSDaniel Fojt 
65*09d4459fSDaniel Fojt    Return the option character from OPTS just read.  Return -1 when
66*09d4459fSDaniel Fojt    there are no more options.  For unrecognized options, or options
67*09d4459fSDaniel Fojt    missing arguments, 'optopt' is set to the option letter, and '?' is
68*09d4459fSDaniel Fojt    returned.
69*09d4459fSDaniel Fojt 
70*09d4459fSDaniel Fojt    The OPTS string is a list of characters which are recognized option
71*09d4459fSDaniel Fojt    letters, optionally followed by colons, specifying that that letter
72*09d4459fSDaniel Fojt    takes an argument, to be placed in 'optarg'.
73*09d4459fSDaniel Fojt 
74*09d4459fSDaniel Fojt    If a letter in OPTS is followed by two colons, its argument is
75*09d4459fSDaniel Fojt    optional.  This behavior is specific to the GNU 'getopt'.
76*09d4459fSDaniel Fojt 
77*09d4459fSDaniel Fojt    The argument '--' causes premature termination of argument
78*09d4459fSDaniel Fojt    scanning, explicitly telling 'getopt' that there are no more
79*09d4459fSDaniel Fojt    options.
80*09d4459fSDaniel Fojt 
81*09d4459fSDaniel Fojt    If OPTS begins with '-', then non-option arguments are treated as
82*09d4459fSDaniel Fojt    arguments to the option '\1'.  This behavior is specific to the GNU
83*09d4459fSDaniel Fojt    'getopt'.  If OPTS begins with '+', or POSIXLY_CORRECT is set in
84*09d4459fSDaniel Fojt    the environment, then do not permute arguments.
85*09d4459fSDaniel Fojt 
86*09d4459fSDaniel Fojt    For standards compliance, the 'argv' argument has the type
87*09d4459fSDaniel Fojt    char *const *, but this is inaccurate; if argument permutation is
88*09d4459fSDaniel Fojt    enabled, the argv array (not the strings it points to) must be
89*09d4459fSDaniel Fojt    writable.  */
90*09d4459fSDaniel Fojt 
91*09d4459fSDaniel Fojt extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
92*09d4459fSDaniel Fojt        __THROW _GL_ARG_NONNULL ((2, 3));
93*09d4459fSDaniel Fojt 
94*09d4459fSDaniel Fojt __END_DECLS
95*09d4459fSDaniel Fojt 
96*09d4459fSDaniel Fojt #endif /* _GETOPT_CORE_H */
97