options.h revision 1.16 1 1.16 dsl /* $NetBSD: options.h,v 1.16 2003/01/22 20:36:04 dsl Exp $ */
2 1.7 cgd
3 1.1 cgd /*-
4 1.5 jtc * Copyright (c) 1991, 1993
5 1.5 jtc * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * This code is derived from software contributed to Berkeley by
8 1.1 cgd * Kenneth Almquist.
9 1.1 cgd *
10 1.1 cgd * Redistribution and use in source and binary forms, with or without
11 1.1 cgd * modification, are permitted provided that the following conditions
12 1.1 cgd * are met:
13 1.1 cgd * 1. Redistributions of source code must retain the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer.
15 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 cgd * notice, this list of conditions and the following disclaimer in the
17 1.1 cgd * documentation and/or other materials provided with the distribution.
18 1.1 cgd * 3. All advertising materials mentioning features or use of this software
19 1.1 cgd * must display the following acknowledgement:
20 1.1 cgd * This product includes software developed by the University of
21 1.1 cgd * California, Berkeley and its contributors.
22 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
23 1.1 cgd * may be used to endorse or promote products derived from this software
24 1.1 cgd * without specific prior written permission.
25 1.1 cgd *
26 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 cgd * SUCH DAMAGE.
37 1.1 cgd *
38 1.8 christos * @(#)options.h 8.2 (Berkeley) 5/4/95
39 1.1 cgd */
40 1.1 cgd
41 1.1 cgd struct shparam {
42 1.11 christos int nparam; /* # of positional parameters (without $0) */
43 1.11 christos unsigned char malloc; /* if parameter list dynamically allocated */
44 1.11 christos unsigned char reset; /* if getopts has been reset */
45 1.1 cgd char **p; /* parameter list */
46 1.11 christos char **optnext; /* next parameter to be processed by getopts */
47 1.11 christos char *optptr; /* used by getopts */
48 1.1 cgd };
49 1.1 cgd
50 1.1 cgd
51 1.15 christos struct optent {
52 1.15 christos const char *name; /* for set -o <name> */
53 1.15 christos const char letter; /* set [+/-]<letter> and $- */
54 1.15 christos const char opt_set; /* mutually exclusive option set */
55 1.15 christos char val; /* value of <letter>flag */
56 1.15 christos };
57 1.15 christos
58 1.15 christos /* Those marked [U] are required by posix, but have no effect! */
59 1.15 christos
60 1.15 christos #ifdef DEFINE_OPTIONS
61 1.15 christos #define DEF_OPTS(name, letter, opt_set) {name, letter, opt_set, 0},
62 1.15 christos struct optent optlist[] = {
63 1.15 christos #else
64 1.15 christos #define DEF_OPTS(name, letter, opt_set)
65 1.15 christos #endif
66 1.15 christos #define DEF_OPT(name,letter) DEF_OPTS(name, letter, 0)
67 1.1 cgd
68 1.15 christos DEF_OPT( "errexit", 'e' ) /* exit on error */
69 1.5 jtc #define eflag optlist[0].val
70 1.15 christos DEF_OPT( "noglob", 'f' ) /* no pathname expansion */
71 1.5 jtc #define fflag optlist[1].val
72 1.15 christos DEF_OPT( "ignoreeof", 'I' ) /* do not exit on EOF */
73 1.5 jtc #define Iflag optlist[2].val
74 1.15 christos DEF_OPT( "interactive",'i' ) /* interactive shell */
75 1.5 jtc #define iflag optlist[3].val
76 1.15 christos DEF_OPT( "monitor", 'm' ) /* job control */
77 1.5 jtc #define mflag optlist[4].val
78 1.15 christos DEF_OPT( "noexec", 'n' ) /* [U] do not exec commands */
79 1.5 jtc #define nflag optlist[5].val
80 1.15 christos DEF_OPT( "stdin", 's' ) /* read from stdin */
81 1.5 jtc #define sflag optlist[6].val
82 1.15 christos DEF_OPT( "xtrace", 'x' ) /* trace after expansion */
83 1.5 jtc #define xflag optlist[7].val
84 1.15 christos DEF_OPT( "verbose", 'v' ) /* trace read input */
85 1.5 jtc #define vflag optlist[8].val
86 1.15 christos DEF_OPTS( "vi", 'V', 'V' ) /* vi style editing */
87 1.5 jtc #define Vflag optlist[9].val
88 1.15 christos DEF_OPTS( "emacs", 'E', 'V' ) /* emacs style editing */
89 1.5 jtc #define Eflag optlist[10].val
90 1.15 christos DEF_OPT( "noclobber", 'C' ) /* do not overwrite files with > */
91 1.5 jtc #define Cflag optlist[11].val
92 1.15 christos DEF_OPT( "allexport", 'a' ) /* export all variables */
93 1.5 jtc #define aflag optlist[12].val
94 1.15 christos DEF_OPT( "notify", 'b' ) /* [U] report completion of background jobs */
95 1.5 jtc #define bflag optlist[13].val
96 1.15 christos DEF_OPT( "nounset", 'u' ) /* error expansion of unset variables */
97 1.5 jtc #define uflag optlist[14].val
98 1.15 christos DEF_OPT( "quietprofile", 'q' )
99 1.12 cjs #define qflag optlist[15].val
100 1.15 christos DEF_OPT( "nolog", 0 ) /* [U] no functon defs in command history */
101 1.15 christos #define nolog optlist[16].val
102 1.16 dsl DEF_OPT( "cdprint", 0 ) /* always print result of cd */
103 1.16 dsl #define cdprint optlist[17].val
104 1.15 christos #ifdef DEBUG
105 1.16 dsl DEF_OPT( "debug", 0 ) /* enable debug prints */
106 1.16 dsl #define debug optlist[18].val
107 1.15 christos #endif
108 1.1 cgd
109 1.1 cgd #ifdef DEFINE_OPTIONS
110 1.15 christos { 0, 0, 0, 0 },
111 1.5 jtc };
112 1.15 christos #define NOPTS (sizeof optlist / sizeof optlist[0] - 1)
113 1.15 christos int sizeof_optlist = sizeof optlist;
114 1.1 cgd #else
115 1.15 christos extern struct optent optlist[];
116 1.15 christos extern int sizeof_optlist;
117 1.1 cgd #endif
118 1.1 cgd
119 1.1 cgd
120 1.1 cgd extern char *minusc; /* argument to -c option */
121 1.1 cgd extern char *arg0; /* $0 */
122 1.1 cgd extern struct shparam shellparam; /* $@ */
123 1.1 cgd extern char **argptr; /* argument list for builtin commands */
124 1.14 christos extern char *optionarg; /* set by nextopt */
125 1.1 cgd extern char *optptr; /* used by nextopt */
126 1.1 cgd
127 1.15 christos void procargs(int, char **);
128 1.15 christos void optschanged(void);
129 1.15 christos void setparam(char **);
130 1.15 christos void freeparam(volatile struct shparam *);
131 1.15 christos int shiftcmd(int, char **);
132 1.15 christos int setcmd(int, char **);
133 1.15 christos int getoptscmd(int, char **);
134 1.15 christos int nextopt(const char *);
135 1.15 christos void getoptsreset(const char *);
136