init version.
[bush.git] / builtins / getopt.h
blob33886328b8964b9af274a70f4730d4dfea4e95c9
1 /* getopt.h - declarations for getopt. */
3 /* Copyright (C) 1989-2020 Free Software Foundation, Inc.
5 This file is part of GNU Bush, the Bourne Again SHell.
7 Bush is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 Bush is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bush. If not, see <http://www.gnu.org/licenses/>.
21 /* XXX THIS HAS BEEN MODIFIED FOR INCORPORATION INTO BUSH XXX */
23 #ifndef _SH_GETOPT_H
24 #define _SH_GETOPT_H 1
26 #include "stdc.h"
28 /* For communication from `getopt' to the caller.
29 When `getopt' finds an option that takes an argument,
30 the argument value is returned here.
31 Also, when `ordering' is RETURN_IN_ORDER,
32 each non-option ARGV-element is returned here. */
34 extern char *sh_optarg;
36 /* Index in ARGV of the next element to be scanned.
37 This is used for communication to and from the caller
38 and for communication between successive calls to `getopt'.
40 On entry to `getopt', zero means this is the first call; initialize.
42 When `getopt' returns EOF, this is the index of the first of the
43 non-option elements that the caller should itself scan.
45 Otherwise, `sh_optind' communicates from one call to the next
46 how much of ARGV has been scanned so far. */
48 extern int sh_optind;
50 /* Callers store zero here to inhibit the error message `getopt' prints
51 for unrecognized options. */
53 extern int sh_opterr;
55 /* Set to an option character which was unrecognized. */
57 extern int sh_optopt;
59 /* Set to 1 when an unrecognized option is encountered. */
60 extern int sh_badopt;
62 extern int sh_getopt PARAMS((int, char *const *, const char *));
64 typedef struct sh_getopt_state
66 char *gs_optarg;
67 int gs_optind;
68 int gs_curopt;
69 char *gs_nextchar;
70 int gs_charindex;
71 int gs_flags;
72 } sh_getopt_state_t;
74 extern void sh_getopt_restore_state PARAMS((char **));
76 extern sh_getopt_state_t *sh_getopt_alloc_istate PARAMS((void));
77 extern void sh_getopt_dispose_istate PARAMS((sh_getopt_state_t *));
79 extern sh_getopt_state_t *sh_getopt_save_istate PARAMS((void));
80 extern void sh_getopt_restore_istate PARAMS((sh_getopt_state_t *));
82 #endif /* _SH_GETOPT_H */