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