138494Sobrien/*-
2310490Scy * SPDX-License-Identifier: BSD-3-Clause
338494Sobrien *
438494Sobrien * Copyright (c) 1991, 1993
538494Sobrien *	The Regents of the University of California.  All rights reserved.
638494Sobrien *
738494Sobrien * This code is derived from software contributed to Berkeley by
838494Sobrien * Kenneth Almquist.
938494Sobrien *
1038494Sobrien * Redistribution and use in source and binary forms, with or without
1138494Sobrien * modification, are permitted provided that the following conditions
1238494Sobrien * are met:
1338494Sobrien * 1. Redistributions of source code must retain the above copyright
1438494Sobrien *    notice, this list of conditions and the following disclaimer.
1538494Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1638494Sobrien *    notice, this list of conditions and the following disclaimer in the
1738494Sobrien *    documentation and/or other materials provided with the distribution.
1838494Sobrien * 3. Neither the name of the University nor the names of its contributors
19310490Scy *    may be used to endorse or promote products derived from this software
2038494Sobrien *    without specific prior written permission.
2138494Sobrien *
2238494Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2338494Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2438494Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2538494Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2638494Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2738494Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2838494Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2938494Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3038494Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3138494Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3238494Sobrien * SUCH DAMAGE.
3338494Sobrien */
3438494Sobrien
3538494Sobrienstruct shparam {
36174313Sobrien	int nparam;		/* # of positional parameters (without $0) */
3738494Sobrien	unsigned char malloc;	/* if parameter list dynamically allocated */
3838494Sobrien	unsigned char reset;	/* if getopts has been reset */
3938494Sobrien	char **p;		/* parameter list */
4038494Sobrien	char **optp;		/* parameter list for getopts */
4138494Sobrien	char **optnext;		/* next parameter to be processed by getopts */
4238494Sobrien	char *optptr;		/* used by getopts */
4338494Sobrien};
4438494Sobrien
4538494Sobrien
4638494Sobrien
4738494Sobrien#define eflag optval[0]
4838494Sobrien#define fflag optval[1]
4938494Sobrien#define Iflag optval[2]
5038494Sobrien#define iflag optval[3]
5138494Sobrien#define mflag optval[4]
5238494Sobrien#define nflag optval[5]
5338494Sobrien#define sflag optval[6]
5438494Sobrien#define xflag optval[7]
5538494Sobrien#define vflag optval[8]
5638494Sobrien#define Vflag optval[9]
5738494Sobrien#define	Eflag optval[10]
5838494Sobrien#define	Cflag optval[11]
5938494Sobrien#define	aflag optval[12]
6038494Sobrien#define	bflag optval[13]
6138494Sobrien#define	uflag optval[14]
6238494Sobrien#define	privileged optval[15]
6338494Sobrien#define	Tflag optval[16]
64174313Sobrien#define	Pflag optval[17]
65119682Smbr#define	hflag optval[18]
66119682Smbr#define	nologflag optval[19]
6738494Sobrien#define	pipefailflag optval[20]
6838494Sobrien#define	verifyflag optval[21]
6938494Sobrien
7038494Sobrien#define NSHORTOPTS	19
7138494Sobrien#define NOPTS		22
7238494Sobrien
7338494Sobrienextern char optval[NOPTS];
7438494Sobrienextern const char optletter[NSHORTOPTS];
7538494Sobrien#ifdef DEFINE_OPTIONS
7638494Sobrienchar optval[NOPTS];
7738494Sobrienconst char optletter[NSHORTOPTS] = "efIimnsxvVECabupTPh";
7838494Sobrienstatic const unsigned char optname[] =
79119682Smbr	"\007errexit"
8038494Sobrien	"\006noglob"
8138494Sobrien	"\011ignoreeof"
8238494Sobrien	"\013interactive"
8338494Sobrien	"\007monitor"
8438494Sobrien	"\006noexec"
8538494Sobrien	"\005stdin"
86119682Smbr	"\006xtrace"
8738494Sobrien	"\007verbose"
8838494Sobrien	"\002vi"
8938494Sobrien	"\005emacs"
9038494Sobrien	"\011noclobber"
9138494Sobrien	"\011allexport"
9238494Sobrien	"\006notify"
9338494Sobrien	"\007nounset"
9438494Sobrien	"\012privileged"
9538494Sobrien	"\012trapsasync"
9638494Sobrien	"\010physical"
97119682Smbr	"\010trackall"
98174313Sobrien	"\005nolog"
99119682Smbr	"\010pipefail"
100174313Sobrien	"\006verify"
10138494Sobrien;
10238494Sobrien#endif
10338494Sobrien
10438494Sobrien
10538494Sobrienextern char *minusc;		/* argument to -c option */
10638494Sobrienextern char *arg0;		/* $0 */
10738494Sobrienextern struct shparam shellparam;  /* $@ */
10838494Sobrienextern char **argptr;		/* argument list for builtin commands */
109119682Smbrextern char *shoptarg;		/* set by nextopt */
11038494Sobrienextern char *nextopt_optptr;	/* used by nextopt */
111119682Smbr
11238494Sobrienvoid procargs(int, char **);
11338494Sobrienvoid optschanged(void);
11438494Sobrienvoid freeparam(struct shparam *);
11538494Sobrienint nextopt(const char *);
11638494Sobrienvoid getoptsreset(const char *);
11738494Sobrien