master xplshn/aruu / cmd / posix / sh / options.h
  1/*-
  2 * SPDX-License-Identifier: BSD-3-Clause
  3 *
  4 * Copyright (c) 1991, 1993
  5 *	The Regents of the University of California.  All rights reserved.
  6 *
  7 * This code is derived from software contributed to Berkeley by
  8 * Kenneth Almquist.
  9 *
 10 * Redistribution and use in source and binary forms, with or without
 11 * modification, are permitted provided that the following conditions
 12 * are met:
 13 * 1. Redistributions of source code must retain the above copyright
 14 *    notice, this list of conditions and the following disclaimer.
 15 * 2. Redistributions in binary form must reproduce the above copyright
 16 *    notice, this list of conditions and the following disclaimer in the
 17 *    documentation and/or other materials provided with the distribution.
 18 * 3. Neither the name of the University nor the names of its contributors
 19 *    may be used to endorse or promote products derived from this software
 20 *    without specific prior written permission.
 21 *
 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 25 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 32 * SUCH DAMAGE.
 33 */
 34
 35struct shparam {
 36  int           nparam;  /* # of positional parameters (without $0) */
 37  unsigned char malloc;  /* if parameter list dynamically allocated */
 38  unsigned char reset;   /* if getopts has been reset */
 39  char        **p;       /* parameter list */
 40  char        **optp;    /* parameter list for getopts */
 41  char        **optnext; /* next parameter to be processed by getopts */
 42  char         *optptr;  /* used by getopts */
 43};
 44
 45#define eflag        optval[0]
 46#define fflag        optval[1]
 47#define Iflag        optval[2]
 48#define iflag        optval[3]
 49#define mflag        optval[4]
 50#define nflag        optval[5]
 51#define sflag        optval[6]
 52#define xflag        optval[7]
 53#define vflag        optval[8]
 54#define Vflag        optval[9]
 55#define Eflag        optval[10]
 56#define Cflag        optval[11]
 57#define aflag        optval[12]
 58#define bflag        optval[13]
 59#define uflag        optval[14]
 60#define privileged   optval[15]
 61#define Tflag        optval[16]
 62#define Pflag        optval[17]
 63#define hflag        optval[18]
 64#define nologflag    optval[19]
 65#define pipefailflag optval[20]
 66#define verifyflag   optval[21]
 67
 68#define NSHORTOPTS 19
 69#define NOPTS      22
 70
 71extern char       optval[NOPTS];
 72extern const char optletter[NSHORTOPTS];
 73#ifdef DEFINE_OPTIONS
 74char                       optval[NOPTS];
 75const char                 optletter[NSHORTOPTS] __nonstring = "efIimnsxvVECabupTPh";
 76static const unsigned char optname[]                         = "\007errexit"
 77                                                               "\006noglob"
 78                                                               "\011ignoreeof"
 79                                                               "\013interactive"
 80                                                               "\007monitor"
 81                                                               "\006noexec"
 82                                                               "\005stdin"
 83                                                               "\006xtrace"
 84                                                               "\007verbose"
 85                                                               "\002vi"
 86                                                               "\005emacs"
 87                                                               "\011noclobber"
 88                                                               "\011allexport"
 89                                                               "\006notify"
 90                                                               "\007nounset"
 91                                                               "\012privileged"
 92                                                               "\012trapsasync"
 93                                                               "\010physical"
 94                                                               "\010trackall"
 95                                                               "\005nolog"
 96                                                               "\010pipefail"
 97                                                               "\006verify";
 98#endif
 99
100extern char          *minusc;         /* argument to -c option */
101extern char          *arg0;           /* $0 */
102extern struct shparam shellparam;     /* $@ */
103extern char         **argptr;         /* argument list for builtin commands */
104extern char          *shoptarg;       /* set by nextopt */
105extern char          *nextopt_optptr; /* used by nextopt */
106
107int  procargs(int, char **);
108void optschanged(void);
109void freeparam(struct shparam *);
110int  nextopt(const char *);
111void getoptsreset(const char *);