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