2014-08-03 23:10:41 +02:00
|
|
|
/* $NetBSD: options.h,v 1.20 2011/06/18 21:18:46 christos Exp $ */
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*-
|
2006-05-23 14:59:34 +02:00
|
|
|
* Copyright (c) 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Kenneth Almquist.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2014-08-03 23:10:41 +02:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2005-04-21 16:53:53 +02:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
2006-05-23 14:59:34 +02:00
|
|
|
* @(#)options.h 8.2 (Berkeley) 5/4/95
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct shparam {
|
2006-05-23 14:59:34 +02:00
|
|
|
int nparam; /* # of positional parameters (without $0) */
|
|
|
|
unsigned char malloc; /* if parameter list dynamically allocated */
|
|
|
|
unsigned char reset; /* if getopts has been reset */
|
2005-04-21 16:53:53 +02:00
|
|
|
char **p; /* parameter list */
|
2006-05-23 14:59:34 +02:00
|
|
|
char **optnext; /* next parameter to be processed by getopts */
|
|
|
|
char *optptr; /* used by getopts */
|
2005-04-21 16:53:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-03 23:10:41 +02:00
|
|
|
struct optent {
|
|
|
|
const char *name; /* for set -o <name> */
|
|
|
|
const char letter; /* set [+/-]<letter> and $- */
|
|
|
|
const char opt_set; /* mutually exclusive option set */
|
|
|
|
unsigned char val; /* value of <letter>flag */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Those marked [U] are required by posix, but have no effect! */
|
|
|
|
|
|
|
|
#ifdef DEFINE_OPTIONS
|
|
|
|
#define DEF_OPTS(name, letter, opt_set) {name, letter, opt_set, 0},
|
|
|
|
struct optent optlist[] = {
|
|
|
|
#else
|
|
|
|
#define DEF_OPTS(name, letter, opt_set)
|
|
|
|
#endif
|
|
|
|
#define DEF_OPT(name,letter) DEF_OPTS(name, letter, 0)
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2014-08-03 23:10:41 +02:00
|
|
|
DEF_OPT( "errexit", 'e' ) /* exit on error */
|
2006-05-23 14:59:34 +02:00
|
|
|
#define eflag optlist[0].val
|
2014-08-03 23:10:41 +02:00
|
|
|
DEF_OPT( "noglob", 'f' ) /* no pathname expansion */
|
2006-05-23 14:59:34 +02:00
|
|
|
#define fflag optlist[1].val
|
2014-08-03 23:10:41 +02:00
|
|
|
DEF_OPT( "ignoreeof", 'I' ) /* do not exit on EOF */
|
2006-05-23 14:59:34 +02:00
|
|
|
#define Iflag optlist[2].val
|
2014-08-03 23:10:41 +02:00
|
|
|
DEF_OPT( "interactive",'i' ) /* interactive shell */
|
2006-05-23 14:59:34 +02:00
|
|
|
#define iflag optlist[3].val
|
2014-08-03 23:10:41 +02:00
|
|
|
DEF_OPT( "monitor", 'm' ) /* job control */
|
2006-05-23 14:59:34 +02:00
|
|
|
#define mflag optlist[4].val
|
2014-08-03 23:10:41 +02:00
|
|
|
DEF_OPT( "noexec", 'n' ) /* [U] do not exec commands */
|
2006-05-23 14:59:34 +02:00
|
|
|
#define nflag optlist[5].val
|
2014-08-03 23:10:41 +02:00
|
|
|
DEF_OPT( "stdin", 's' ) /* read from stdin */
|
2006-05-23 14:59:34 +02:00
|
|
|
#define sflag optlist[6].val
|
2014-08-03 23:10:41 +02:00
|
|
|
DEF_OPT( "xtrace", 'x' ) /* trace after expansion */
|
2006-05-23 14:59:34 +02:00
|
|
|
#define xflag optlist[7].val
|
2014-08-03 23:10:41 +02:00
|
|
|
DEF_OPT( "verbose", 'v' ) /* trace read input */
|
2006-05-23 14:59:34 +02:00
|
|
|
#define vflag optlist[8].val
|
2014-08-03 23:10:41 +02:00
|
|
|
DEF_OPTS( "vi", 'V', 'V' ) /* vi style editing */
|
2006-05-23 14:59:34 +02:00
|
|
|
#define Vflag optlist[9].val
|
2014-08-03 23:10:41 +02:00
|
|
|
DEF_OPTS( "emacs", 'E', 'V' ) /* emacs style editing */
|
2006-05-23 14:59:34 +02:00
|
|
|
#define Eflag optlist[10].val
|
2014-08-03 23:10:41 +02:00
|
|
|
DEF_OPT( "noclobber", 'C' ) /* do not overwrite files with > */
|
2006-05-23 14:59:34 +02:00
|
|
|
#define Cflag optlist[11].val
|
2014-08-03 23:10:41 +02:00
|
|
|
DEF_OPT( "allexport", 'a' ) /* export all variables */
|
2006-05-23 14:59:34 +02:00
|
|
|
#define aflag optlist[12].val
|
2014-08-03 23:10:41 +02:00
|
|
|
DEF_OPT( "notify", 'b' ) /* [U] report completion of background jobs */
|
2006-05-23 14:59:34 +02:00
|
|
|
#define bflag optlist[13].val
|
2014-08-03 23:10:41 +02:00
|
|
|
DEF_OPT( "nounset", 'u' ) /* error expansion of unset variables */
|
2006-05-23 14:59:34 +02:00
|
|
|
#define uflag optlist[14].val
|
2014-08-03 23:10:41 +02:00
|
|
|
DEF_OPT( "quietprofile", 'q' )
|
|
|
|
#define qflag optlist[15].val
|
|
|
|
DEF_OPT( "nolog", 0 ) /* [U] no functon defs in command history */
|
|
|
|
#define nolog optlist[16].val
|
|
|
|
DEF_OPT( "cdprint", 0 ) /* always print result of cd */
|
|
|
|
#define cdprint optlist[17].val
|
|
|
|
DEF_OPT( "tabcomplete", 0 ) /* <tab> causes filename expansion */
|
|
|
|
#define tabcomplete optlist[18].val
|
|
|
|
#ifdef DEBUG
|
|
|
|
DEF_OPT( "debug", 0 ) /* enable debug prints */
|
|
|
|
#define debug optlist[19].val
|
|
|
|
#endif
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
#ifdef DEFINE_OPTIONS
|
2014-08-03 23:10:41 +02:00
|
|
|
{ 0, 0, 0, 0 },
|
2006-05-23 14:59:34 +02:00
|
|
|
};
|
2014-08-03 23:10:41 +02:00
|
|
|
#define NOPTS (sizeof optlist / sizeof optlist[0] - 1)
|
|
|
|
int sizeof_optlist = sizeof optlist;
|
2005-04-21 16:53:53 +02:00
|
|
|
#else
|
2014-08-03 23:10:41 +02:00
|
|
|
extern struct optent optlist[];
|
|
|
|
extern int sizeof_optlist;
|
2005-04-21 16:53:53 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
extern char *minusc; /* argument to -c option */
|
|
|
|
extern char *arg0; /* $0 */
|
|
|
|
extern struct shparam shellparam; /* $@ */
|
|
|
|
extern char **argptr; /* argument list for builtin commands */
|
2014-08-03 23:10:41 +02:00
|
|
|
extern char *optionarg; /* set by nextopt */
|
2005-04-21 16:53:53 +02:00
|
|
|
extern char *optptr; /* used by nextopt */
|
|
|
|
|
|
|
|
void procargs(int, char **);
|
2006-05-23 14:59:34 +02:00
|
|
|
void optschanged(void);
|
2005-04-21 16:53:53 +02:00
|
|
|
void setparam(char **);
|
2014-08-03 23:10:41 +02:00
|
|
|
void freeparam(volatile struct shparam *);
|
|
|
|
int nextopt(const char *);
|
2006-05-23 14:59:34 +02:00
|
|
|
void getoptsreset(const char *);
|