14b88c807SRodney W. Grimes /*- 28a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 38a16b7a1SPedro F. Giffuni * 44b88c807SRodney W. Grimes * Copyright (c) 1991, 1993 54b88c807SRodney W. Grimes * The Regents of the University of California. All rights reserved. 64b88c807SRodney W. Grimes * 74b88c807SRodney W. Grimes * This code is derived from software contributed to Berkeley by 84b88c807SRodney W. Grimes * Kenneth Almquist. 94b88c807SRodney W. Grimes * 104b88c807SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 114b88c807SRodney W. Grimes * modification, are permitted provided that the following conditions 124b88c807SRodney W. Grimes * are met: 134b88c807SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 144b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 154b88c807SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 164b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 174b88c807SRodney W. Grimes * documentation and/or other materials provided with the distribution. 18fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 194b88c807SRodney W. Grimes * may be used to endorse or promote products derived from this software 204b88c807SRodney W. Grimes * without specific prior written permission. 214b88c807SRodney W. Grimes * 224b88c807SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 234b88c807SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 244b88c807SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 254b88c807SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 264b88c807SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 274b88c807SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 284b88c807SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 294b88c807SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 304b88c807SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 314b88c807SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 324b88c807SRodney W. Grimes * SUCH DAMAGE. 334b88c807SRodney W. Grimes */ 344b88c807SRodney W. Grimes 354b88c807SRodney W. Grimes struct shparam { 36ab0a2172SSteve Price int nparam; /* # of positional parameters (without $0) */ 37ab0a2172SSteve Price unsigned char malloc; /* if parameter list dynamically allocated */ 38ab0a2172SSteve Price unsigned char reset; /* if getopts has been reset */ 394b88c807SRodney W. Grimes char **p; /* parameter list */ 401bc2fdfaSJilles Tjoelker char **optp; /* parameter list for getopts */ 414b88c807SRodney W. Grimes char **optnext; /* next parameter to be processed by getopts */ 424b88c807SRodney W. Grimes char *optptr; /* used by getopts */ 434b88c807SRodney W. Grimes }; 444b88c807SRodney W. Grimes 454b88c807SRodney W. Grimes 464b88c807SRodney W. Grimes 473da40d4aSJilles Tjoelker #define eflag optval[0] 483da40d4aSJilles Tjoelker #define fflag optval[1] 493da40d4aSJilles Tjoelker #define Iflag optval[2] 503da40d4aSJilles Tjoelker #define iflag optval[3] 513da40d4aSJilles Tjoelker #define mflag optval[4] 523da40d4aSJilles Tjoelker #define nflag optval[5] 533da40d4aSJilles Tjoelker #define sflag optval[6] 543da40d4aSJilles Tjoelker #define xflag optval[7] 553da40d4aSJilles Tjoelker #define vflag optval[8] 563da40d4aSJilles Tjoelker #define Vflag optval[9] 573da40d4aSJilles Tjoelker #define Eflag optval[10] 583da40d4aSJilles Tjoelker #define Cflag optval[11] 593da40d4aSJilles Tjoelker #define aflag optval[12] 603da40d4aSJilles Tjoelker #define bflag optval[13] 613da40d4aSJilles Tjoelker #define uflag optval[14] 623da40d4aSJilles Tjoelker #define privileged optval[15] 633da40d4aSJilles Tjoelker #define Tflag optval[16] 643da40d4aSJilles Tjoelker #define Pflag optval[17] 653da40d4aSJilles Tjoelker #define hflag optval[18] 663da40d4aSJilles Tjoelker #define nologflag optval[19] 67484160a9SJilles Tjoelker #define pipefailflag optval[20] 68d2c23317SStephane Rochoy #define verifyflag optval[21] 694b88c807SRodney W. Grimes 7062c37116SJilles Tjoelker #define NSHORTOPTS 19 71d2c23317SStephane Rochoy #define NOPTS 22 724b88c807SRodney W. Grimes 733da40d4aSJilles Tjoelker extern char optval[NOPTS]; 743da40d4aSJilles Tjoelker extern const char optletter[NSHORTOPTS]; 754b88c807SRodney W. Grimes #ifdef DEFINE_OPTIONS 763da40d4aSJilles Tjoelker char optval[NOPTS]; 773da40d4aSJilles Tjoelker const char optletter[NSHORTOPTS] = "efIimnsxvVECabupTPh"; 783da40d4aSJilles Tjoelker static const unsigned char optname[] = 793da40d4aSJilles Tjoelker "\007errexit" 803da40d4aSJilles Tjoelker "\006noglob" 813da40d4aSJilles Tjoelker "\011ignoreeof" 823da40d4aSJilles Tjoelker "\013interactive" 833da40d4aSJilles Tjoelker "\007monitor" 843da40d4aSJilles Tjoelker "\006noexec" 853da40d4aSJilles Tjoelker "\005stdin" 863da40d4aSJilles Tjoelker "\006xtrace" 873da40d4aSJilles Tjoelker "\007verbose" 883da40d4aSJilles Tjoelker "\002vi" 893da40d4aSJilles Tjoelker "\005emacs" 903da40d4aSJilles Tjoelker "\011noclobber" 913da40d4aSJilles Tjoelker "\011allexport" 923da40d4aSJilles Tjoelker "\006notify" 933da40d4aSJilles Tjoelker "\007nounset" 943da40d4aSJilles Tjoelker "\012privileged" 953da40d4aSJilles Tjoelker "\012trapsasync" 963da40d4aSJilles Tjoelker "\010physical" 973da40d4aSJilles Tjoelker "\010trackall" 983da40d4aSJilles Tjoelker "\005nolog" 99484160a9SJilles Tjoelker "\010pipefail" 100d2c23317SStephane Rochoy "\006verify" 1013da40d4aSJilles Tjoelker ; 1024b88c807SRodney W. Grimes #endif 1034b88c807SRodney W. Grimes 1044b88c807SRodney W. Grimes 1054b88c807SRodney W. Grimes extern char *minusc; /* argument to -c option */ 1064b88c807SRodney W. Grimes extern char *arg0; /* $0 */ 1074b88c807SRodney W. Grimes extern struct shparam shellparam; /* $@ */ 1084b88c807SRodney W. Grimes extern char **argptr; /* argument list for builtin commands */ 109f01e3d0cSMartin Cracauer extern char *shoptarg; /* set by nextopt */ 110384aedabSJilles Tjoelker extern char *nextopt_optptr; /* used by nextopt */ 1114b88c807SRodney W. Grimes 112*65f5dd42SBaptiste Daroussin int procargs(int, char **); 1135134c3f7SWarner Losh void optschanged(void); 1145134c3f7SWarner Losh void freeparam(struct shparam *); 1152cac6e36SJilles Tjoelker int nextopt(const char *); 1165134c3f7SWarner Losh void getoptsreset(const char *); 117