options.h revision 201053
1181053Srwatson/*-
2180701Srwatson * Copyright (c) 1991, 1993
3155192Srwatson *	The Regents of the University of California.  All rights reserved.
4155192Srwatson *
5155192Srwatson * This code is derived from software contributed to Berkeley by
6155192Srwatson * Kenneth Almquist.
7155192Srwatson *
8155192Srwatson * Redistribution and use in source and binary forms, with or without
9155192Srwatson * modification, are permitted provided that the following conditions
10155192Srwatson * are met:
11155192Srwatson * 1. Redistributions of source code must retain the above copyright
12155192Srwatson *    notice, this list of conditions and the following disclaimer.
13180701Srwatson * 2. Redistributions in binary form must reproduce the above copyright
14155192Srwatson *    notice, this list of conditions and the following disclaimer in the
15155192Srwatson *    documentation and/or other materials provided with the distribution.
16155192Srwatson * 4. Neither the name of the University nor the names of its contributors
17155192Srwatson *    may be used to endorse or promote products derived from this software
18155192Srwatson *    without specific prior written permission.
19155192Srwatson *
20155192Srwatson * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21155192Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22155192Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23155192Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24155192Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25155192Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26155192Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27155192Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28155192Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29155192Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30155192Srwatson * SUCH DAMAGE.
31155192Srwatson *
32155192Srwatson *	@(#)options.h	8.2 (Berkeley) 5/4/95
33155192Srwatson * $FreeBSD: head/bin/sh/options.h 201053 2009-12-27 18:04:05Z jilles $
34155192Srwatson */
35155192Srwatson
36155192Srwatsonstruct shparam {
37156882Srwatson	int nparam;		/* # of positional parameters (without $0) */
38178617Srwatson	unsigned char malloc;	/* if parameter list dynamically allocated */
39155192Srwatson	unsigned char reset;	/* if getopts has been reset */
40155192Srwatson	char **p;		/* parameter list */
41155192Srwatson	char **optnext;		/* next parameter to be processed by getopts */
42155192Srwatson	char *optptr;		/* used by getopts */
43155192Srwatson};
44155192Srwatson
45155192Srwatson
46155192Srwatson
47155192Srwatson#define eflag optlist[0].val
48155192Srwatson#define fflag optlist[1].val
49155192Srwatson#define Iflag optlist[2].val
50155192Srwatson#define iflag optlist[3].val
51170196Srwatson#define mflag optlist[4].val
52170196Srwatson#define nflag optlist[5].val
53170196Srwatson#define sflag optlist[6].val
54170196Srwatson#define xflag optlist[7].val
55155192Srwatson#define vflag optlist[8].val
56155192Srwatson#define Vflag optlist[9].val
57155192Srwatson#define	Eflag optlist[10].val
58155192Srwatson#define	Cflag optlist[11].val
59155192Srwatson#define	aflag optlist[12].val
60155192Srwatson#define	bflag optlist[13].val
61155192Srwatson#define	uflag optlist[14].val
62155192Srwatson#define	privileged optlist[15].val
63155192Srwatson#define	Tflag optlist[16].val
64155192Srwatson#define	Pflag optlist[17].val
65155192Srwatson
66155192Srwatson#define NOPTS	18
67161970Srwatson
68161970Srwatsonstruct optent {
69161970Srwatson	const char *name;
70161970Srwatson	const char letter;
71161970Srwatson	char val;
72161970Srwatson};
73161970Srwatson
74161970Srwatson#ifdef DEFINE_OPTIONS
75161970Srwatsonstruct optent optlist[NOPTS] = {
76161970Srwatson	{ "errexit",	'e',	0 },
77161970Srwatson	{ "noglob",	'f',	0 },
78161970Srwatson	{ "ignoreeof",	'I',	0 },
79161970Srwatson	{ "interactive",'i',	0 },
80161970Srwatson	{ "monitor",	'm',	0 },
81161970Srwatson	{ "noexec",	'n',	0 },
82161970Srwatson	{ "stdin",	's',	0 },
83161970Srwatson	{ "xtrace",	'x',	0 },
84161970Srwatson	{ "verbose",	'v',	0 },
85161970Srwatson	{ "vi",		'V',	0 },
86161970Srwatson	{ "emacs",	'E',	0 },
87161970Srwatson	{ "noclobber",	'C',	0 },
88161970Srwatson	{ "allexport",	'a',	0 },
89161970Srwatson	{ "notify",	'b',	0 },
90168688Scsjp	{ "nounset",	'u',	0 },
91161970Srwatson	{ "privileged",	'p',	0 },
92161970Srwatson	{ "trapsasync",	'T',	0 },
93161970Srwatson	{ "physical",	'P',	0 },
94161970Srwatson};
95161970Srwatson#else
96161970Srwatsonextern struct optent optlist[NOPTS];
97161970Srwatson#endif
98161970Srwatson
99161970Srwatson
100161970Srwatsonextern char *minusc;		/* argument to -c option */
101161970Srwatsonextern char *arg0;		/* $0 */
102161970Srwatsonextern struct shparam shellparam;  /* $@ */
103161970Srwatsonextern char **argptr;		/* argument list for builtin commands */
104161970Srwatsonextern char *shoptarg;		/* set by nextopt */
105161970Srwatsonextern char *nextopt_optptr;	/* used by nextopt */
106161970Srwatson
107161970Srwatsonvoid procargs(int, char **);
108161970Srwatsonvoid optschanged(void);
109161970Srwatsonvoid setparam(char **);
110161970Srwatsonvoid freeparam(struct shparam *);
111161970Srwatsonint shiftcmd(int, char **);
112161970Srwatsonint setcmd(int, char **);
113155192Srwatsonint getoptscmd(int, char **);
114161813Swsalamonint nextopt(const char *);
115161813Swsalamonvoid getoptsreset(const char *);
116161813Swsalamon