118334Speter/*-
290075Sobrien * Copyright (c) 1991, 1993
3169689Skan *	The Regents of the University of California.  All rights reserved.
418334Speter *
590075Sobrien * This code is derived from software contributed to Berkeley by
618334Speter * Kenneth Almquist.
790075Sobrien *
890075Sobrien * Redistribution and use in source and binary forms, with or without
990075Sobrien * modification, are permitted provided that the following conditions
1090075Sobrien * are met:
1118334Speter * 1. Redistributions of source code must retain the above copyright
1290075Sobrien *    notice, this list of conditions and the following disclaimer.
1390075Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1490075Sobrien *    notice, this list of conditions and the following disclaimer in the
1590075Sobrien *    documentation and/or other materials provided with the distribution.
1618334Speter * 4. Neither the name of the University nor the names of its contributors
1718334Speter *    may be used to endorse or promote products derived from this software
1890075Sobrien *    without specific prior written permission.
19169689Skan *
20169689Skan * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2118334Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22132718Skan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23132718Skan * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24132718Skan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25169689Skan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26169689Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27169689Skan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28117395Skan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2918334Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3018334Speter * SUCH DAMAGE.
3118334Speter *
3218334Speter *	@(#)options.h	8.2 (Berkeley) 5/4/95
3318334Speter * $FreeBSD$
3418334Speter */
3518334Speter
3618334Speterstruct shparam {
3718334Speter	int nparam;		/* # of positional parameters (without $0) */
3818334Speter	unsigned char malloc;	/* if parameter list dynamically allocated */
3918334Speter	unsigned char reset;	/* if getopts has been reset */
4018334Speter	char **p;		/* parameter list */
41117395Skan	char **optnext;		/* next parameter to be processed by getopts */
4218334Speter	char *optptr;		/* used by getopts */
4318334Speter};
44117395Skan
45117395Skan
4618334Speter
4718334Speter#define eflag optlist[0].val
4818334Speter#define fflag optlist[1].val
4918334Speter#define Iflag optlist[2].val
5018334Speter#define iflag optlist[3].val
5118334Speter#define mflag optlist[4].val
5218334Speter#define nflag optlist[5].val
5318334Speter#define sflag optlist[6].val
5418334Speter#define xflag optlist[7].val
5518334Speter#define vflag optlist[8].val
5618334Speter#define Vflag optlist[9].val
5718334Speter#define	Eflag optlist[10].val
5818334Speter#define	Cflag optlist[11].val
59117395Skan#define	aflag optlist[12].val
6090075Sobrien#define	bflag optlist[13].val
6190075Sobrien#define	uflag optlist[14].val
6290075Sobrien#define	privileged optlist[15].val
6390075Sobrien#define	Tflag optlist[16].val
6490075Sobrien#define	Pflag optlist[17].val
6590075Sobrien#define	hflag optlist[18].val
6690075Sobrien
6790075Sobrien#define NOPTS	19
6890075Sobrien
6990075Sobrienstruct optent {
70132718Skan	const char *name;
71169689Skan	const char letter;
72169689Skan	char val;
7390075Sobrien};
7490075Sobrien
7590075Sobrien#ifdef DEFINE_OPTIONS
7690075Sobrienstruct optent optlist[NOPTS] = {
7790075Sobrien	{ "errexit",	'e',	0 },
7890075Sobrien	{ "noglob",	'f',	0 },
7990075Sobrien	{ "ignoreeof",	'I',	0 },
8090075Sobrien	{ "interactive",'i',	0 },
8190075Sobrien	{ "monitor",	'm',	0 },
8290075Sobrien	{ "noexec",	'n',	0 },
8390075Sobrien	{ "stdin",	's',	0 },
8490075Sobrien	{ "xtrace",	'x',	0 },
8590075Sobrien	{ "verbose",	'v',	0 },
86132718Skan	{ "vi",		'V',	0 },
8790075Sobrien	{ "emacs",	'E',	0 },
88132718Skan	{ "noclobber",	'C',	0 },
8990075Sobrien	{ "allexport",	'a',	0 },
9090075Sobrien	{ "notify",	'b',	0 },
9190075Sobrien	{ "nounset",	'u',	0 },
9290075Sobrien	{ "privileged",	'p',	0 },
9390075Sobrien	{ "trapsasync",	'T',	0 },
9490075Sobrien	{ "physical",	'P',	0 },
9590075Sobrien	{ "trackall",	'h',	0 },
9690075Sobrien};
9790075Sobrien#else
9890075Sobrienextern struct optent optlist[NOPTS];
99132718Skan#endif
100117395Skan
10190075Sobrien
10290075Sobrienextern char *minusc;		/* argument to -c option */
103169689Skanextern char *arg0;		/* $0 */
104132718Skanextern struct shparam shellparam;  /* $@ */
10590075Sobrienextern char **argptr;		/* argument list for builtin commands */
10690075Sobrienextern char *shoptarg;		/* set by nextopt */
10790075Sobrienextern char *nextopt_optptr;	/* used by nextopt */
10890075Sobrien
10990075Sobrienvoid procargs(int, char **);
11090075Sobrienvoid optschanged(void);
11190075Sobrienvoid setparam(char **);
11290075Sobrienvoid freeparam(struct shparam *);
11390075Sobrienint nextopt(const char *);
114117395Skanvoid getoptsreset(const char *);
11590075Sobrien