Home | History | Annotate | Line # | Download | only in sh
options.h revision 1.25.6.1
      1  1.25.6.1  pgoyette /*	$NetBSD: options.h,v 1.25.6.1 2017/05/19 00:22:51 pgoyette 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.25.6.1  pgoyette /*
     47  1.25.6.1  pgoyette  * Note that option default values can be changed at shell startup
     48  1.25.6.1  pgoyette  * depending upon the environment in which the shell is running.
     49  1.25.6.1  pgoyette  */
     50      1.15  christos struct optent {
     51      1.15  christos 	const char *name;		/* for set -o <name> */
     52      1.15  christos 	const char letter;		/* set [+/-]<letter> and $- */
     53      1.15  christos 	const char opt_set;		/* mutually exclusive option set */
     54      1.19       dsl 	unsigned char val;		/* value of <letter>flag */
     55  1.25.6.1  pgoyette 	unsigned char dflt;		/* default value of 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.25.6.1  pgoyette #define DEF_OPTS_D(name,letter,opt_set,dflt) {name, letter, opt_set, 0, dflt },
     62      1.15  christos struct optent optlist[] = {
     63      1.15  christos #else
     64  1.25.6.1  pgoyette #define DEF_OPTS_D(name,letter,opt_set,dflt)
     65      1.15  christos #endif
     66  1.25.6.1  pgoyette #define DEF_OPTS(name,letter,opt_set)	DEF_OPTS_D(name, letter, opt_set, 0)
     67  1.25.6.1  pgoyette #define DEF_OPT(name,letter)		DEF_OPTS_D(name, letter, 0, 0)
     68  1.25.6.1  pgoyette #define DEF_OPT_D(name,letter,dflt)	DEF_OPTS_D(name, letter, 0, dflt)
     69       1.1       cgd 
     70      1.15  christos DEF_OPT( "errexit",	'e' )	/* exit on error */
     71       1.5       jtc #define eflag optlist[0].val
     72      1.15  christos DEF_OPT( "noglob",	'f' )	/* no pathname expansion */
     73       1.5       jtc #define fflag optlist[1].val
     74      1.15  christos DEF_OPT( "ignoreeof",	'I' )	/* do not exit on EOF */
     75       1.5       jtc #define Iflag optlist[2].val
     76      1.15  christos DEF_OPT( "interactive",'i' )	/* interactive shell */
     77       1.5       jtc #define iflag optlist[3].val
     78      1.15  christos DEF_OPT( "monitor",	'm' )	/* job control */
     79       1.5       jtc #define mflag optlist[4].val
     80      1.23  christos DEF_OPT( "noexec",	'n' )	/* do not exec commands */
     81       1.5       jtc #define nflag optlist[5].val
     82      1.15  christos DEF_OPT( "stdin",	's' )	/* read from stdin */
     83       1.5       jtc #define sflag optlist[6].val
     84      1.15  christos DEF_OPT( "xtrace",	'x' )	/* trace after expansion */
     85       1.5       jtc #define xflag optlist[7].val
     86      1.15  christos DEF_OPT( "verbose",	'v' )	/* trace read input */
     87       1.5       jtc #define vflag optlist[8].val
     88      1.15  christos DEF_OPTS( "vi",		'V', 'V' )	/* vi style editing */
     89       1.5       jtc #define Vflag optlist[9].val
     90      1.15  christos DEF_OPTS( "emacs",	'E', 'V' )	/* emacs style editing */
     91       1.5       jtc #define	Eflag optlist[10].val
     92      1.15  christos DEF_OPT( "noclobber",	'C' )	/* do not overwrite files with > */
     93       1.5       jtc #define	Cflag optlist[11].val
     94      1.15  christos DEF_OPT( "allexport",	'a' )	/* export all variables */
     95       1.5       jtc #define	aflag optlist[12].val
     96      1.15  christos DEF_OPT( "notify",	'b' )	/* [U] report completion of background jobs */
     97       1.5       jtc #define	bflag optlist[13].val
     98      1.15  christos DEF_OPT( "nounset",	'u' )	/* error expansion of unset variables */
     99       1.5       jtc #define	uflag optlist[14].val
    100      1.15  christos DEF_OPT( "quietprofile", 'q' )
    101      1.12       cjs #define	qflag optlist[15].val
    102      1.15  christos DEF_OPT( "nolog",	0 )	/* [U] no functon defs in command history */
    103      1.15  christos #define	nolog optlist[16].val
    104      1.16       dsl DEF_OPT( "cdprint",	0 )	/* always print result of cd */
    105      1.16       dsl #define	cdprint optlist[17].val
    106      1.18       dsl DEF_OPT( "tabcomplete",	0 )	/* <tab> causes filename expansion */
    107      1.18       dsl #define	tabcomplete optlist[18].val
    108      1.21  christos DEF_OPT( "fork",	'F' )	/* use fork(2) instead of vfork(2) */
    109      1.21  christos #define	usefork optlist[19].val
    110      1.22  christos DEF_OPT( "nopriv",	'p' )	/* preserve privs even if set{u,g}id */
    111      1.23  christos #define	pflag optlist[20].val
    112      1.24  christos DEF_OPT( "trackall",	'h' )	/* [U] locate cmds in funcs when defined */
    113      1.23  christos #define	hflag optlist[21].val
    114      1.25  christos DEF_OPT( "posix",	0  )	/* operate in posix mode */
    115      1.25  christos #define	posix optlist[22].val
    116      1.15  christos #ifdef DEBUG
    117      1.16       dsl DEF_OPT( "debug",	0 )	/* enable debug prints */
    118      1.25  christos #define	debug optlist[23].val
    119      1.15  christos #endif
    120       1.1       cgd 
    121       1.1       cgd #ifdef DEFINE_OPTIONS
    122  1.25.6.1  pgoyette 	{ 0, 0, 0, 0, 0 },
    123       1.5       jtc };
    124      1.15  christos #define NOPTS (sizeof optlist / sizeof optlist[0] - 1)
    125      1.15  christos int sizeof_optlist = sizeof optlist;
    126       1.1       cgd #else
    127      1.15  christos extern struct optent optlist[];
    128      1.15  christos extern int sizeof_optlist;
    129       1.1       cgd #endif
    130       1.1       cgd 
    131       1.1       cgd 
    132       1.1       cgd extern char *minusc;		/* argument to -c option */
    133       1.1       cgd extern char *arg0;		/* $0 */
    134       1.1       cgd extern struct shparam shellparam;  /* $@ */
    135       1.1       cgd extern char **argptr;		/* argument list for builtin commands */
    136      1.14  christos extern char *optionarg;		/* set by nextopt */
    137       1.1       cgd extern char *optptr;		/* used by nextopt */
    138       1.1       cgd 
    139      1.15  christos void procargs(int, char **);
    140      1.15  christos void optschanged(void);
    141      1.15  christos void setparam(char **);
    142      1.15  christos void freeparam(volatile struct shparam *);
    143      1.15  christos int nextopt(const char *);
    144      1.15  christos void getoptsreset(const char *);
    145