xref: /freebsd/bin/sh/options.h (revision 2f9966ff63d65bd474478888c9088eeae3f9c669)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1991, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Kenneth Almquist.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 
35 struct shparam {
36 	int nparam;		/* # of positional parameters (without $0) */
37 	unsigned char malloc;	/* if parameter list dynamically allocated */
38 	unsigned char reset;	/* if getopts has been reset */
39 	char **p;		/* parameter list */
40 	char **optp;		/* parameter list for getopts */
41 	char **optnext;		/* next parameter to be processed by getopts */
42 	char *optptr;		/* used by getopts */
43 };
44 
45 
46 
47 #define eflag optval[0]
48 #define fflag optval[1]
49 #define Iflag optval[2]
50 #define iflag optval[3]
51 #define mflag optval[4]
52 #define nflag optval[5]
53 #define sflag optval[6]
54 #define xflag optval[7]
55 #define vflag optval[8]
56 #define Vflag optval[9]
57 #define	Eflag optval[10]
58 #define	Cflag optval[11]
59 #define	aflag optval[12]
60 #define	bflag optval[13]
61 #define	uflag optval[14]
62 #define	privileged optval[15]
63 #define	Tflag optval[16]
64 #define	Pflag optval[17]
65 #define	hflag optval[18]
66 #define	nologflag optval[19]
67 #define	pipefailflag optval[20]
68 #define	verifyflag optval[21]
69 
70 #define NSHORTOPTS	19
71 #define NOPTS		22
72 
73 extern char optval[NOPTS];
74 extern const char optletter[NSHORTOPTS];
75 #ifdef DEFINE_OPTIONS
76 char optval[NOPTS];
77 const char optletter[NSHORTOPTS] = "efIimnsxvVECabupTPh";
78 static const unsigned char optname[] =
79 	"\007errexit"
80 	"\006noglob"
81 	"\011ignoreeof"
82 	"\013interactive"
83 	"\007monitor"
84 	"\006noexec"
85 	"\005stdin"
86 	"\006xtrace"
87 	"\007verbose"
88 	"\002vi"
89 	"\005emacs"
90 	"\011noclobber"
91 	"\011allexport"
92 	"\006notify"
93 	"\007nounset"
94 	"\012privileged"
95 	"\012trapsasync"
96 	"\010physical"
97 	"\010trackall"
98 	"\005nolog"
99 	"\010pipefail"
100 	"\006verify"
101 ;
102 #endif
103 
104 
105 extern char *minusc;		/* argument to -c option */
106 extern char *arg0;		/* $0 */
107 extern struct shparam shellparam;  /* $@ */
108 extern char **argptr;		/* argument list for builtin commands */
109 extern char *shoptarg;		/* set by nextopt */
110 extern char *nextopt_optptr;	/* used by nextopt */
111 
112 void procargs(int, char **);
113 void optschanged(void);
114 void freeparam(struct shparam *);
115 int nextopt(const char *);
116 void getoptsreset(const char *);
117