2017-05-28 03:38:01 +03:00
|
|
|
/* $NetBSD: options.h,v 1.27 2017/05/28 00:38:01 kre Exp $ */
|
1995-03-21 12:01:59 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
1994-05-11 21:09:42 +04:00
|
|
|
* Copyright (c) 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03: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.
|
2003-08-07 13:05:01 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
*
|
1995-05-12 01:28:33 +04:00
|
|
|
* @(#)options.h 8.2 (Berkeley) 5/4/95
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct shparam {
|
1996-11-06 04:17:10 +03:00
|
|
|
int nparam; /* # of positional parameters (without $0) */
|
|
|
|
unsigned char malloc; /* if parameter list dynamically allocated */
|
|
|
|
unsigned char reset; /* if getopts has been reset */
|
1993-03-21 12:45:37 +03:00
|
|
|
char **p; /* parameter list */
|
1996-11-06 04:17:10 +03:00
|
|
|
char **optnext; /* next parameter to be processed by getopts */
|
|
|
|
char *optptr; /* used by getopts */
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
Command line, and "set" command options processing cleanup.
sh +c "command string" no longer works (it must be -c)
sh +o and sh -o no longer work (if you could call what they did
before working.) nb: this is without an option name.
-ooo Opt1 Opt2 Opt3 no longer works (set & cmd line), this should be
-o Opt1 -o Opt2 -o Opt3 (same with +ooo of course).
-oOpt is now supported - option value (name of option in
this case) immediately following -o (or +o).
(as with other commands that use std opt parsing)
Both set comamnd and command line.
In addition, the output from "set +o" has shrunk dramatically, by borrowing
a trick from ksh93 (but implemented in a more traditional syntax).
"set +o" is required to produce a command (or commands) which when executed
later, will return all options to the state they were in when "set +o"
was done. Previously that was done by generating a set command, with
every option listed (set -o opt +o other-opt ...) to set them all back
to their current setings. Now we have a new "magic option" ("default")
which sets all options to their default values, so now set +o output
need only be "set -o default -o changed-opt ..." (only the options that
have been changed from their default values need be explicitly mentioned.)
The definition of "default value" for this is the value the shell set the
option to, after startup, after processing the command line (with any
flags, or -o option type settings), but before beginning processing any
user input (incuding startup files, like $ENV etc).
Anyone can execute "set -o default" of course, but only from a "set"
command (it makes no sense at all as a -o option to sh). This also
causes "set +o" to be slightly more useful as a general command, as
ignoring the "set -o default" part of the result, it lists just those
options that have been altered after sh startup. There is no +o default.
There isn't an option called "default" at all...
This causes some of the commented out text from sh.1 to become uncommented.
2017-05-18 16:53:18 +03:00
|
|
|
/*
|
|
|
|
* Note that option default values can be changed at shell startup
|
|
|
|
* depending upon the environment in which the shell is running.
|
|
|
|
*/
|
2002-11-25 01:35:38 +03:00
|
|
|
struct optent {
|
|
|
|
const char *name; /* for set -o <name> */
|
|
|
|
const char letter; /* set [+/-]<letter> and $- */
|
|
|
|
const char opt_set; /* mutually exclusive option set */
|
2005-12-13 20:44:18 +03:00
|
|
|
unsigned char val; /* value of <letter>flag */
|
Command line, and "set" command options processing cleanup.
sh +c "command string" no longer works (it must be -c)
sh +o and sh -o no longer work (if you could call what they did
before working.) nb: this is without an option name.
-ooo Opt1 Opt2 Opt3 no longer works (set & cmd line), this should be
-o Opt1 -o Opt2 -o Opt3 (same with +ooo of course).
-oOpt is now supported - option value (name of option in
this case) immediately following -o (or +o).
(as with other commands that use std opt parsing)
Both set comamnd and command line.
In addition, the output from "set +o" has shrunk dramatically, by borrowing
a trick from ksh93 (but implemented in a more traditional syntax).
"set +o" is required to produce a command (or commands) which when executed
later, will return all options to the state they were in when "set +o"
was done. Previously that was done by generating a set command, with
every option listed (set -o opt +o other-opt ...) to set them all back
to their current setings. Now we have a new "magic option" ("default")
which sets all options to their default values, so now set +o output
need only be "set -o default -o changed-opt ..." (only the options that
have been changed from their default values need be explicitly mentioned.)
The definition of "default value" for this is the value the shell set the
option to, after startup, after processing the command line (with any
flags, or -o option type settings), but before beginning processing any
user input (incuding startup files, like $ENV etc).
Anyone can execute "set -o default" of course, but only from a "set"
command (it makes no sense at all as a -o option to sh). This also
causes "set +o" to be slightly more useful as a general command, as
ignoring the "set -o default" part of the result, it lists just those
options that have been altered after sh startup. There is no +o default.
There isn't an option called "default" at all...
This causes some of the commented out text from sh.1 to become uncommented.
2017-05-18 16:53:18 +03:00
|
|
|
unsigned char dflt; /* default value of flag */
|
2002-11-25 01:35:38 +03:00
|
|
|
};
|
|
|
|
|
2017-05-28 03:38:01 +03:00
|
|
|
#include "optinit.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
extern char *minusc; /* argument to -c option */
|
|
|
|
extern char *arg0; /* $0 */
|
|
|
|
extern struct shparam shellparam; /* $@ */
|
|
|
|
extern char **argptr; /* argument list for builtin commands */
|
2001-02-04 22:52:06 +03:00
|
|
|
extern char *optionarg; /* set by nextopt */
|
1993-03-21 12:45:37 +03:00
|
|
|
extern char *optptr; /* used by nextopt */
|
|
|
|
|
2002-11-25 01:35:38 +03:00
|
|
|
void procargs(int, char **);
|
|
|
|
void optschanged(void);
|
|
|
|
void setparam(char **);
|
|
|
|
void freeparam(volatile struct shparam *);
|
|
|
|
int nextopt(const char *);
|
|
|
|
void getoptsreset(const char *);
|