head	1.13;
access;
symbols
	netbsd-11-0-RC4:1.11.2.1
	netbsd-11-0-RC3:1.11.2.1
	netbsd-11-0-RC2:1.11.2.1
	netbsd-11-0-RC1:1.11.2.1
	perseant-exfatfs-base-20250801:1.11
	netbsd-11:1.11.0.2
	netbsd-11-base:1.11
	netbsd-10-1-RELEASE:1.10
	perseant-exfatfs-base-20240630:1.10
	perseant-exfatfs:1.10.0.4
	perseant-exfatfs-base:1.10
	netbsd-8-3-RELEASE:1.2.2.1
	netbsd-9-4-RELEASE:1.9
	netbsd-10-0-RELEASE:1.10
	netbsd-10-0-RC6:1.10
	netbsd-10-0-RC5:1.10
	netbsd-10-0-RC4:1.10
	netbsd-10-0-RC3:1.10
	netbsd-10-0-RC2:1.10
	netbsd-10-0-RC1:1.10
	netbsd-10:1.10.0.2
	netbsd-10-base:1.10
	netbsd-9-3-RELEASE:1.9
	cjep_sun2x-base1:1.9
	cjep_sun2x:1.9.0.8
	cjep_sun2x-base:1.9
	cjep_staticlib_x-base1:1.9
	netbsd-9-2-RELEASE:1.9
	cjep_staticlib_x:1.9.0.6
	cjep_staticlib_x-base:1.9
	netbsd-9-1-RELEASE:1.9
	phil-wifi-20200421:1.9
	phil-wifi-20200411:1.9
	is-mlppp:1.9.0.4
	is-mlppp-base:1.9
	phil-wifi-20200406:1.9
	netbsd-8-2-RELEASE:1.2.2.1
	netbsd-9-0-RELEASE:1.9
	netbsd-9-0-RC2:1.9
	netbsd-9-0-RC1:1.9
	phil-wifi-20191119:1.9
	netbsd-9:1.9.0.2
	netbsd-9-base:1.9
	phil-wifi-20190609:1.9
	netbsd-8-1-RELEASE:1.2.2.1
	netbsd-8-1-RC1:1.2.2.1
	pgoyette-compat-merge-20190127:1.8.2.1
	pgoyette-compat-20190127:1.9
	pgoyette-compat-20190118:1.9
	pgoyette-compat-1226:1.9
	pgoyette-compat-1126:1.9
	pgoyette-compat-1020:1.8
	pgoyette-compat-0930:1.8
	pgoyette-compat-0906:1.8
	pgoyette-compat-0728:1.8
	netbsd-8-0-RELEASE:1.2.2.1
	phil-wifi:1.8.0.4
	phil-wifi-base:1.8
	pgoyette-compat-0625:1.8
	netbsd-8-0-RC2:1.2.2.1
	pgoyette-compat-0521:1.8
	pgoyette-compat-0502:1.8
	pgoyette-compat-0422:1.8
	netbsd-8-0-RC1:1.2.2.1
	pgoyette-compat-0415:1.8
	pgoyette-compat-0407:1.8
	pgoyette-compat-0330:1.8
	pgoyette-compat-0322:1.8
	pgoyette-compat-0315:1.8
	pgoyette-compat:1.8.0.2
	pgoyette-compat-base:1.8
	matt-nb8-mediatek:1.2.2.1.0.2
	matt-nb8-mediatek-base:1.2.2.1
	perseant-stdc-iso10646:1.5.0.2
	perseant-stdc-iso10646-base:1.5
	netbsd-8:1.2.0.2
	netbsd-8-base:1.2;
locks; strict;
comment	@# @;


1.13
date	2026.03.22.19.18.56;	author kre;	state Exp;
branches;
next	1.12;
commitid	I3yeyNdUEEvnn0zG;

1.12
date	2025.09.10.23.58.21;	author kre;	state Exp;
branches;
next	1.11;
commitid	PeHyZnSwJjuR7eaG;

1.11
date	2024.10.14.08.27.53;	author kre;	state Exp;
branches
	1.11.2.1;
next	1.10;
commitid	FrLo5jmoWecjCBtF;

1.10
date	2022.09.18.06.03.19;	author kre;	state Exp;
branches
	1.10.2.1
	1.10.4.1;
next	1.9;
commitid	CRPUJDYfi7ek9jUD;

1.9
date	2018.11.23.20.40.06;	author kre;	state Exp;
branches
	1.9.2.1;
next	1.8;
commitid	tn0rB8zonrnPP61B;

1.8
date	2017.11.21.03.42.39;	author kre;	state Exp;
branches
	1.8.2.1
	1.8.4.1;
next	1.7;
commitid	Lrp2a7Dve4sz0RfA;

1.7
date	2017.11.19.03.23.01;	author kre;	state Exp;
branches;
next	1.6;
commitid	LupVPv670GYOXAfA;

1.6
date	2017.07.24.14.17.11;	author kre;	state Exp;
branches;
next	1.5;
commitid	u7iXJbDjm8nonu0A;

1.5
date	2017.06.30.23.02.56;	author kre;	state Exp;
branches;
next	1.4;
commitid	6SCzHb9R6jUg3sXz;

1.4
date	2017.06.17.07.50.35;	author kre;	state Exp;
branches;
next	1.3;
commitid	QLKqLx0KFL8uqHVz;

1.3
date	2017.06.07.05.08.32;	author kre;	state Exp;
branches;
next	1.2;
commitid	ovDy4KCysFHNQoUz;

1.2
date	2017.05.28.14.14.22;	author kre;	state Exp;
branches
	1.2.2.1;
next	1.1;
commitid	22WOOofsLxX1caTz;

1.1
date	2017.05.28.00.38.01;	author kre;	state Exp;
branches;
next	;
commitid	4a8VWIzlH9fYF5Tz;

1.11.2.1
date	2025.10.01.15.15.33;	author martin;	state Exp;
branches;
next	;
commitid	MB9bhDBSOoUEyScG;

1.10.2.1
date	2025.10.01.15.21.11;	author martin;	state Exp;
branches;
next	;
commitid	E4BVTl3FIHfBAScG;

1.10.4.1
date	2025.08.02.05.18.26;	author perseant;	state Exp;
branches;
next	;
commitid	23j6GFaDws3O875G;

1.9.2.1
date	2025.10.01.15.27.36;	author martin;	state Exp;
branches;
next	;
commitid	EmxJ4noMS6mNCScG;

1.8.2.1
date	2018.11.26.01.49.54;	author pgoyette;	state Exp;
branches;
next	;
commitid	Zj4q5SspGdKXto1B;

1.8.4.1
date	2019.06.10.21.41.04;	author christos;	state Exp;
branches;
next	1.8.4.2;
commitid	jtc8rnCzWiEEHGqB;

1.8.4.2
date	2020.04.21.18.41.06;	author martin;	state dead;
branches;
next	1.8.4.3;
commitid	86tA4aEmdr3VCh5C;

1.8.4.3
date	2020.04.21.19.37.34;	author martin;	state Exp;
branches;
next	;
commitid	x6IB64bYH9UmWh5C;

1.2.2.1
date	2017.07.23.14.58.14;	author snj;	state Exp;
branches;
next	;
commitid	IcSSefq8ASq6Dm0A;


desc
@@


1.13
log
@Reorder slightly for correctness

The "pipefail" option is now a POSIX standard option, move it
from the extensions section to the standard options section.

The (very fake) "r" option is not a standard option, though it
is a command line only "option" - move it away from -s, -c
the other (but standard) command line only options, and to a
section of its own (our first non-standard command line only option).

NFC - the order of options in this definition file is for human
(those who view this file) purposes only, all is reordered by
mkoptions.sh before being included with the shell sources.
@
text
@/* $NetBSD: option.list,v 1.12 2025/09/10 23:58:21 kre Exp $ */

/*
 * define the shell's settable options
 *
 *	new options can be defined by adding them here,
 *	but they do nothing until code to implement them
 *	is added (using the "var name" field)
 */

/*
 * format is up to 5 columns... (followed by anything)
 * end of line comments can be introduced by ' #' (space/tab hash) to eol.
 *
 * The columns are:
 *	1. internal shell "var name"	(required)
 *	2. option long name
 *		if a single char, then no long name, and remaining
 *		columns shift left (this becomes the short name)
 *	3. option short name (single character name)
 *		if '-' or absent then no short name
 *		if neither long nor short name, line is ignored
 *	4. option set short name (name of option equiv class)
 *		if '-' or absent then no class
 *	5. default value of option
 *		if absent, default is 0
 *		only 0 or 1 possible (0==off 1==on) ("on" and "off" can be used)
 *
 * NB: Use only tabs to separate fields 1..3 (spaces can be used for 4 & 5)
 *
 * Data may be followed by any C preprocessor #if expression (incl the #if..)
 * (including #ifdef #ifndef) to conditionalise output for that option.
 * The #if expression continues until \n or next following '#'
 */

// the POSIX defined options
aflag	allexport	a		# export all variables
eflag	errexit		e		# exit on command error ($? != 0)
mflag	monitor		m		# enable job control
Cflag	noclobber	C		# do not overwrite files when using >
nflag	noexec		n		# do not execue commands
fflag	noglob		f		# no pathname expansion
uflag	nounset		u		# expanding unset var is an error
vflag	verbose		v		# echo commands as read
xflag	xtrace		x		# trace command execution
pipefail	pipefail		# pipe exit status

// the long name (ignoreeof) is standard, the I flag is not
Iflag	ignoreeof	I		# do not exit interactive shell on EOF

// defined but not really implemented by the shell (yet) - they do nothing
bflag	notify		b		# [U] report bg job completion
nolog	nolog				# [U] no func definitions in history
// 'h' is standard, long name (trackall) is not
hflag	trackall	h		# [U] locate cmds in funcs during defn

// 's' is standard for command line, not as 'set' option, nor 'stdin' name
sflag	stdin		s		# read from standard input
// minusc		c		# command line option only.
// --			o		# handled differently...

// non-standard options -- 'i' is just a state, not an option in standard.
iflag	interactive	i		# interactive shell
loginsh	login		l		# a login shell
cdprint	cdprint				# always print result of a cd
usefork	fork		F		# use fork(2) instead of vfork(2)
pflag	nopriv		p		# preserve privs if set[ug]id
posix	posix				# be closer to POSIX compat
qflag	quietprofile	q		# disable -v/-x in startup files
fnline1	local_lineno	L on		# number lines in funcs starting at 1
promptcmds	promptcmds		# allow $( ) in PS1 (et al).
Xflag	xlock		X #ifndef SMALL	# sticky stderr for -x (implies -x)

// --			r		# command line option only.

// editline/history related options ("vi" is standard, 'V' and others are not)
// only one of vi/emacs can be set, hence the "set" definition, value
// of that can be any char (not used for a different set)
Vflag	vi		V V		# enable vi style editing
Eflag	emacs		E V		# enable emacs style editing
tabcomplete	tabcomplete		# make <tab> cause filename expansion

// internal debug option (not usually included in the shell)
debug	debug		#ifdef DEBUG	# enable internal shell debugging
@


1.12
log
@PR bin/59646 option.list wsp consistency

Be consistent with use of tab/space in fields used as
sort keys, so versions of sort which might not behave
exactly as we expect should still produce the same results.

XXX pullup -9 -10 -11
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.11 2024/10/14 08:27:53 kre Exp $ */
d46 1
a59 1
// --			r		# command line option only.
a71 1
pipefail	pipefail		# pipe exit status
d74 2
@


1.11
log
@Add a -r (version) option to sh

This new -r (or +r) option is for command line use only.
When encountered, the shell simply prints its version info
(such as it has, which isn't much) and exits (immediately).

This allows "funny" uses like
	sh -version
the -v and -e options are standard, and processed as normal
(changing nothing, yet, except setting the option).  Then the
'r' option is seen, the version info is printed, and the shell
exits.  Any remaining "options" (there is no "-o n" option) are
ignored, as are any other args given to the shell.

The string printed (currently) is just "NetBSD shell:" followed
by the value of the NETBSD_SHELL variable (which has been established
already by the time options are processed).
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.10 2022/09/18 06:03:19 kre Exp $ */
d29 2
d71 2
a72 2
promptcmds promptcmds			# allow $( ) in PS1 (et al).
pipefail pipefail			# pipe exit status
@


1.11.2.1
log
@Pull up following revision(s) (requested by kre in ticket #37):

	bin/sh/option.list: revision 1.12

PR bin/59646 option.list wsp consistency

Be consistent with use of tab/space in fields used as
sort keys, so versions of sort which might not behave
exactly as we expect should still produce the same results.
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.11 2024/10/14 08:27:53 kre Exp $ */
a28 2
 * NB: Use only tabs to separate fields 1..3 (spaces can be used for 4 & 5)
 *
d69 2
a70 2
promptcmds	promptcmds		# allow $( ) in PS1 (et al).
pipefail	pipefail		# pipe exit status
@


1.10
log
@Add the -l option (aka -o login): be a login shell.   Meaningful only on
the command line (with both - and + forms) - overrides the presence (or
otherwise) of a '-' as argv[0][0].

Since this allows any shell to be a login shell (which simply means that
it runs /etc/profile and ~/.profile at shell startup - there are no other
side effects) add a new, always set at startup, variable NBSH_INVOCATION
which has a char string as its value, where each char has a meaning,
more or less related to how the shell was started.   See sh(1).
This is intended to allow those startup scripts to tailor their behaviour
to the nature of this particular login shell (it is possible to detect
whether a shell is a login shell merely because of -l, or whether it would
have been anyway, before the -l option was added - and more).   The
var could also be used to set different values for $ENV for different
uses of the shell.
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.9 2018/11/23 20:40:06 kre Exp $ */
d57 1
@


1.10.2.1
log
@Pull up following revision(s) (requested by kre in ticket #1165):

	bin/sh/option.list: revision 1.12
	bin/sh/mkoptions.sh: revision 1.6
	bin/sh/mkoptions.sh: revision 1.7
	bin/sh/mkoptions.sh: revision 1.8
	bin/sh/mkoptions.sh: revision 1.9

From Jan-Benedict Glaw:
Fix a redirection and prepare a stable sort for upper-/lowercase
option letters

This script is a mess, I strongly believe that it should be rewritten.
However, I'm not 100% sure why it was invented in the first place
(come on, the generated header file isn't _that_ complicated that
it couldn't be sanely managed by hand!), but let's fix the sorting
order by using LC_ALL=C.

Also add a few 'X' to the `mktemp` template to make non-BSD
implementations happy. As a bonus, actually *use* the initial `sed`
output instead of throwing it away by piping it into `sort` with
also connecting `sort`'s stdin with the original input file...

Redo the mktemp(1) part - some mktemp's (including ours) require the
XXXX's to be at the end of the name (like mk*temp(3)) so however well
it will work with mktemp implementations which allow the X's to be
anywhere in the final component of the name, it will work just as
well on them with the X's at the end.

But we don't normally need all of that mess - knowing which temp
file is which is useful only when debugging the script, and that's
(mostly) long done.   So, in normal uses now just use $(mktemp) and
allow mktemp to pick its own name - we don't need to know what it is.
Every mktemp(1) supports that mode of operation.
Bug when debugging the script (which for current purposes will be
taken to be when the -x flag is passed to the shell running it, to
trace what it does) then we will make the temp files have names we
can recognise (and in that case, also don't delete them when done).

While here, check for mktemp(1) failing, and abort if that
happens (we assume that if it fails it will write an error
message to stderr, so the script does not need to.)

As for the purpose of the script ... of course the header file
generated (or an equivalent elsewhere) could be generated and
maintained by hand, but why would anyone want to do all that
work when software can do it for us, and do it correctly without
human thought?

This also allows the options in the master list (option.list) to be
arranged in a way that is meaningful for them, unrelated to the order
the shell needs to have them in (or rearrange them to be at run time)
and have that order shuffled however is convenient.   Currently all
the posix standard options are first, then the "hybrid" options, and
finally the local ones for this shell.   Currently "pipefail" is in the
final set, but once the next posix version is published, that will
become a standard option, and get moved in the list - the shell won't
even notice as this script puts the options into shell desired order.

Be more explicit with sort fields to produce consistent results with gnu
sort (Jan-Benedict Glaw)

Allow '+' to be specified as the "one char option name" for long options
that don't have a 1 char equivalent, but do want to become a member of
an option set.  The '+' is otherwise ignored.   This is similar to '-'
in that position, except that skips past the option set field, and is
followed directly by the default value, '+' does not do that.
This currently changes nothing, as there are no current options that
use it (or would want to).

PR bin/59646 option.list wsp consistency
Be consistent with use of tab/space in fields used as
sort keys, so versions of sort which might not behave
exactly as we expect should still produce the same results.
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.10 2022/09/18 06:03:19 kre Exp $ */
a28 2
 * NB: Use only tabs to separate fields 1..3 (spaces can be used for 4 & 5)
 *
d68 2
a69 2
promptcmds	promptcmds		# allow $( ) in PS1 (et al).
pipefail	pipefail		# pipe exit status
@


1.10.4.1
log
@Sync with HEAD
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.11 2024/10/14 08:27:53 kre Exp $ */
a56 1
// --			r		# command line option only.
@


1.9
log
@
Avoid long option names that differ only in character case.
Change Xtrace (the name) to xlock instead.  Aside from the different
name, there is no change to functionality.
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.8 2017/11/21 03:42:39 kre Exp $ */
d61 1
@


1.9.2.1
log
@Pull up following revision(s) (requested by kre in ticket #1970):

	bin/sh/option.list: revision 1.12
	bin/sh/mkoptions.sh: revision 1.6
	bin/sh/mkoptions.sh: revision 1.7
	bin/sh/mkoptions.sh: revision 1.8
	bin/sh/mkoptions.sh: revision 1.9

From Jan-Benedict Glaw:
Fix a redirection and prepare a stable sort for upper-/lowercase
option letters

This script is a mess, I strongly believe that it should be rewritten.
However, I'm not 100% sure why it was invented in the first place
(come on, the generated header file isn't _that_ complicated that
it couldn't be sanely managed by hand!), but let's fix the sorting
order by using LC_ALL=C.

Also add a few 'X' to the `mktemp` template to make non-BSD
implementations happy. As a bonus, actually *use* the initial `sed`
output instead of throwing it away by piping it into `sort` with
also connecting `sort`'s stdin with the original input file...

Redo the mktemp(1) part - some mktemp's (including ours) require the
XXXX's to be at the end of the name (like mk*temp(3)) so however well
it will work with mktemp implementations which allow the X's to be
anywhere in the final component of the name, it will work just as
well on them with the X's at the end.

But we don't normally need all of that mess - knowing which temp
file is which is useful only when debugging the script, and that's
(mostly) long done.   So, in normal uses now just use $(mktemp) and
allow mktemp to pick its own name - we don't need to know what it is.
Every mktemp(1) supports that mode of operation.
Bug when debugging the script (which for current purposes will be
taken to be when the -x flag is passed to the shell running it, to
trace what it does) then we will make the temp files have names we
can recognise (and in that case, also don't delete them when done).

While here, check for mktemp(1) failing, and abort if that
happens (we assume that if it fails it will write an error
message to stderr, so the script does not need to.)

As for the purpose of the script ... of course the header file
generated (or an equivalent elsewhere) could be generated and
maintained by hand, but why would anyone want to do all that
work when software can do it for us, and do it correctly without
human thought?

This also allows the options in the master list (option.list) to be
arranged in a way that is meaningful for them, unrelated to the order
the shell needs to have them in (or rearrange them to be at run time)
and have that order shuffled however is convenient.   Currently all
the posix standard options are first, then the "hybrid" options, and
finally the local ones for this shell.   Currently "pipefail" is in the
final set, but once the next posix version is published, that will
become a standard option, and get moved in the list - the shell won't
even notice as this script puts the options into shell desired order.

Be more explicit with sort fields to produce consistent results with gnu
sort (Jan-Benedict Glaw)

Allow '+' to be specified as the "one char option name" for long options
that don't have a 1 char equivalent, but do want to become a member of
an option set.  The '+' is otherwise ignored.   This is similar to '-'
in that position, except that skips past the option set field, and is
followed directly by the default value, '+' does not do that.
This currently changes nothing, as there are no current options that
use it (or would want to).

PR bin/59646 option.list wsp consistency
Be consistent with use of tab/space in fields used as
sort keys, so versions of sort which might not behave
exactly as we expect should still produce the same results.
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.9 2018/11/23 20:40:06 kre Exp $ */
a28 2
 * NB: Use only tabs to separate fields 1..3 (spaces can be used for 4 & 5)
 *
d67 2
a68 2
promptcmds	promptcmds		# allow $( ) in PS1 (et al).
pipefail	pipefail		# pipe exit status
@


1.8
log
@Remove the -X option from SMALL shells (as used on boot floppies,
some other install media, mini-roots, etc.)   It is unlikely that
such a shell will be used for much script debugging (and the old -x
still exists of course) and it adds a little bloat, so, zap...

The ancient unused (unrelated) xioctl() function is gone as well
(from all shells).
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.7 2017/11/19 03:23:01 kre Exp $ */
d69 1
a69 1
Xflag	Xtrace		X #ifndef SMALL	# sticky stderr for -x (implies -x)
@


1.8.4.1
log
@Sync with HEAD
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.9 2018/11/23 20:40:06 kre Exp $ */
d69 1
a69 1
Xflag	xlock		X #ifndef SMALL	# sticky stderr for -x (implies -x)
@


1.8.4.2
log
@Sync with HEAD
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.8.4.1 2019/06/10 21:41:04 christos Exp $ */
@


1.8.4.3
log
@Ooops, restore accidently removed files from merge mishap
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.9 2018/11/23 20:40:06 kre Exp $ */
@


1.8.2.1
log
@Sync with HEAD, resolve a couple of conflicts
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.9 2018/11/23 20:40:06 kre Exp $ */
d69 1
a69 1
Xflag	xlock		X #ifndef SMALL	# sticky stderr for -x (implies -x)
@


1.7
log
@Implement the -X option - an apparent variant of -x which sends all trace
output to the stderr which existed when the -X option was (last) enabled.
It also enables tracing by enabling -x (and when reset, +X, also resets
the 'x' flag (+x)).  Note that it is still -x/+x which actually
enables/disables the trace output.   Hence "apparent variant" - what -X
actually does (aside from setting -x) is just to lock the trace output,
rather than having it follow wherever stderr is later redirected.
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.6 2017/07/24 14:17:11 kre Exp $ */
d69 1
a69 1
Xflag	Xtrace		X		# sticky stderr for -x (implies -x)
@


1.6
log
@Implement the "pipefail" option (same semantics as in other shells)
to cause (when set, which it is not by default) the exit status of a
pipe to be 0 iff all commands in the pipe exited with status 0, and
otherwise, the status of the rightmost command to exit with a non-0
status.

In the doc, while describing this, also reword some of the text about
commands in general, how they are structured, and when they are executed.
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.5 2017/06/30 23:02:56 kre Exp $ */
d69 1
@


1.5
log
@
Implement PS1, PS2 and PS4 expansions (variable expansions, arithmetic
expansions, and if enabled by the promptcmds option, command substitutions.)
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.4 2017/06/17 07:50:35 kre Exp $ */
d68 1
@


1.4
log
@Changed the long name for the -L option from lineno_fn_relative
to local_lineno as the latter seemed to be marginally more popular,
and perhaps more importantly, is the same length as the peviously
existing quietprofile option, which means the man page indentation
for the list of options can return to (about) what it was before...
(That is, less indented, which means more data/line, which means less
lines of man page - a good thing!)
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.3 2017/06/07 05:08:32 kre Exp $ */
d7 1
a7 1
 *	but they do nothing untilcode to implement them
d67 1
@


1.3
log
@A better LINENO implementation.   This version deletes (well, #if 0's out)
the LINENO hack, and uses the LINENO var for both ${LINENO} and $((LINENO)).
(Code to invert the LINENO hack when required, like when de-compiling the
execution tree to provide the "jobs" command strings, is still included,
that can be deleted when the LINENO hack is completely removed - look for
refs to VSLINENO throughout the code.  The var funclinno in parser.c can
also be removed, it is used only for the LINENO hack.)

This version produces accurate results: $((LINENO)) was made as accurate
as the LINENO hack made ${LINENO} which is very good.  That's why the
LINENO hack is not yet completely removed, so it can be easily re-enabled.
If you can tell the difference when it is in use, or not in use, then
something has broken (or I managed to miss a case somewhere.)

The way that LINENO works is documented in its own (new) section in the
man page, so nothing more about that, or the new options, etc, here.

This version introduces the possibility of having a "reference" function
associated with a variable, which gets called whenever the value of the
variable is required (that's what implements LINENO).  There is just
one function pointer however, so any particular variable gets at most
one of the set function (as used for PATH, etc) or the reference function.
The VFUNCREF bit in the var flags indicates which func the variable in
question uses (if any - the func ptr, as before, can be NULL).

I would not call the results of this perfect yet, but it is close.
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.2 2017/05/28 14:14:22 kre Exp $ */
d66 1
a66 1
fnline1	lineno_fn_relative	L on	# number lines in funcs starting at 1
@


1.2
log
@Redo mkoptions.sh .. much better this way, now fully automated
option sorting (no longer required option.list to be manually
sorted by long option name) and properly handles conditional
options.   Cleaner output format as well.

This allows option.list to be reordered to group related options
together ... also added more comments to it.
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.1 2017/05/28 00:38:01 kre Exp $ */
d66 1
@


1.2.2.1
log
@Pull up following revision(s) (requested by kre in ticket #103):
	bin/kill/kill.c: 1.28
	bin/sh/Makefile: 1.111-1.113
	bin/sh/arith_token.c: 1.5
	bin/sh/arith_tokens.h: 1.2
	bin/sh/arithmetic.c: 1.3
	bin/sh/arithmetic.h: 1.2
	bin/sh/bltin/bltin.h: 1.15
	bin/sh/cd.c: 1.49-1.50
	bin/sh/error.c: 1.40
	bin/sh/eval.c: 1.142-1.151
	bin/sh/exec.c: 1.49-1.51
	bin/sh/exec.h: 1.26
	bin/sh/expand.c: 1.113-1.119
	bin/sh/expand.h: 1.23
	bin/sh/histedit.c: 1.49-1.52
	bin/sh/input.c: 1.57-1.60
	bin/sh/input.h: 1.19-1.20
	bin/sh/jobs.c: 1.86-1.87
	bin/sh/main.c: 1.71-1.72
	bin/sh/memalloc.c: 1.30
	bin/sh/memalloc.h: 1.17
	bin/sh/mknodenames.sh: 1.4
	bin/sh/mkoptions.sh: 1.3-1.4
	bin/sh/myhistedit.h: 1.12-1.13
	bin/sh/nodetypes: 1.16-1.18
	bin/sh/option.list: 1.3-1.5
	bin/sh/parser.c: 1.133-1.141
	bin/sh/parser.h: 1.22-1.23
	bin/sh/redir.c: 1.58
	bin/sh/redir.h: 1.24
	bin/sh/sh.1: 1.149-1.159
	bin/sh/shell.h: 1.24
	bin/sh/show.c: 1.43-1.47
	bin/sh/show.h: 1.11
	bin/sh/syntax.c: 1.4
	bin/sh/syntax.h: 1.8
	bin/sh/trap.c: 1.41
	bin/sh/var.c: 1.56-1.65
	bin/sh/var.h: 1.29-1.35
An initial attempt at implementing LINENO to meet the specs.
Aside from one problem (not too hard to fix if it was ever needed) this version
does about as well as most other shell implementations when expanding
$((LINENO)) and better for ${LINENO} as it retains the "LINENO hack" for the
latter, and that is very accurate.
Unfortunately that means that ${LINENO} and $((LINENO)) do not always produce
the same value when used on the same line (a defect that other shells do not
share - aside from the FreeBSD sh as it is today, where only the LINENO hack
exists and so (like for us before this commit) $((LINENO)) is always either
0, or at least whatever value was last set, perhaps by
	LINENO=${LINENO}
which does actually work ... for that one line...)
This could be corrected by simply removing the LINENO hack (look for the string
LINENO in parser.c) in which case ${LINENO} and $((LINENO)) would give the
same (not perfectly accurate) values, as do most other shells.
POSIX requires that LINENO be set before each command, and this implementation
does that fairly literally - except that we only bother before the commands
which actually expand words (for, case and simple commands).   Unfortunately
this forgot that expansions also occur in redirects, and the other compound
commands can also have redirects, so if a redirect on one of the other compound
commands wants to use the value of $((LINENO)) as a part of a generated file
name, then it will get an incorrect value.  This is the "one problem" above.
(Because the LINENO hack is still enabled, using ${LINENO} works.)
This could be fixed, but as this version of the LINENO implementation is just
for reference purposes (it will be superseded within minutes by a better one)
I won't bother.  However should anyone else decide that this is a better choice
(it is probably a smaller implementation, in terms of code & data space then
the replacement, but also I would expect, slower, and definitely less accurate)
this defect is something to bear in mind, and fix.
This version retains the *BSD historical practice that line numbers in functions
(all functions) count from 1 from the start of the function, and elsewhere,
start from 1 from where the shell started reading the input file/stream in
question.  In an "eval" expression the line number starts at the line of the
"eval" (and then increases if the input is a multi-line string).
Note: this version is not documented (beyond as much as LINENO was before)
hence this slightly longer than usual commit message.
A better LINENO implementation.   This version deletes (well, #if 0's out)
the LINENO hack, and uses the LINENO var for both ${LINENO} and $((LINENO)).
(Code to invert the LINENO hack when required, like when de-compiling the
execution tree to provide the "jobs" command strings, is still included,
that can be deleted when the LINENO hack is completely removed - look for
refs to VSLINENO throughout the code.  The var funclinno in parser.c can
also be removed, it is used only for the LINENO hack.)
This version produces accurate results: $((LINENO)) was made as accurate
as the LINENO hack made ${LINENO} which is very good.  That's why the
LINENO hack is not yet completely removed, so it can be easily re-enabled.
If you can tell the difference when it is in use, or not in use, then
something has broken (or I managed to miss a case somewhere.)
The way that LINENO works is documented in its own (new) section in the
man page, so nothing more about that, or the new options, etc, here.
This version introduces the possibility of having a "reference" function
associated with a variable, which gets called whenever the value of the
variable is required (that's what implements LINENO).  There is just
one function pointer however, so any particular variable gets at most
one of the set function (as used for PATH, etc) or the reference function.
The VFUNCREF bit in the var flags indicates which func the variable in
question uses (if any - the func ptr, as before, can be NULL).
I would not call the results of this perfect yet, but it is close.
Unbreak (at least) i386 build .... I have no idea why this built for me on
amd64 (problem was missing prototype for snprintf witout <stdio.h>)
While here, add some (DEBUG mode only) tracing that proved useful in
solving another problem.
Set the line number before expanding args, not after.   As the line_number
would have usually been set earlier, this change is mostly an effective
no-op, but it is better this way (just in case) - not observed to have
caused any problems.
Undo some over agressive fixes for a (pre-commit) bug that did not
need these changes to be fixed - and these cause problems in another
absurd use case.   Either of these issues is unlikely to be seen by
anyone who isn't an idiot masochist...
PR bin/52280
removescapes_nl in expari() even when not quoted,
CRTNONL's appear regardless of quoting (unlike CTLESC).
New sentence, new line. Whitespace.
Improve the (new) LINENO section, markup changes (with thanks to wiz@@ for
assistace) and some better wording in a few placed.
I am an idiot...  revert the previous unintended commit.
Remove some left over baggage from the LINENO v1 implementation that
didn't get removed with v2, and should have.   This would have had
(I think, without having tested it) one very minor effect on the way
LINENO worked in the v2 implementation, but my guess is it would have
taken a long time before anyone noticed...
Correct spelling in comments of DEBUG only code...
(Perhaps) temporary fix to pkgtools (cwrappers) build (configure).
Expanding  `` containing \ \n sequences looks to have been giving
problems.   I don't think this is the correct fix, but it will do
no worse harm than (perhaps) incorrectly calculating LINENO in this
kind of (rare) circumstance.   I'll look and see if there should be
a better fix later.
s/volatile/const/ -- wonderful how opposites attract like this.
NFC (normal use) - DEBUG only change, when showing empty arg list don't
omit terminating \n.
Free stack memory in a couple of obscure cases where it wasn't
being done (one in probably dead code that is never compiled, the other
in a very rare error case.)   Since it is stack memory it wasn't lost
in any case, just held longer than needed.
Many internal memory management type fixes.
PR bin/52302   (core dump with interactive shell, here doc and error
on same line) is fixed.   (An old bug.)
echo "$( echo x; for a in $( seq 1000 ); do printf '%s\n'; done; echo y )"
consistently prints 1002 lines (x, 1000 empty ones, then y) as it should
(And you don't want to know what it did before, or why.) (Another old one.)
(Recently added) Problems with ~ expansion fixed (mem management related).
Proper fix for the cwrappers configure problem (which includes the quick
fix that was done earlier, but extends upon that to be correct). (This was
another newly added problem.)
And the really devious (and rare) old bug - if STACKSTRNUL() needs to
allocate a new buffer in which to store the \0, calculate the size of
the string space remaining correctly, unlike when SPUTC() grows the
buffer, there is no actual data being stored in the STACKSTRNUL()
case - the string space remaining was calculated as one byte too few.
That would be harmless, unless the next buffer also filled, in which
case it was assumed that it was really full, not one byte less, meaning
one junk char (a nul, or anything) was being copied into the next (even
bigger buffer) corrupting the data.
Consistent use of stalloc() to allocate a new block of (stack) memory,
and grabstackstr() to claim a block of (stack) memory that had already
been occupied but not claimed as in use.  Since grabstackstr is implemented
as just a call to stalloc() this is a no-op change in practice, but makes
it much easier to comprehend what is really happening.  Previous code
sometimes used stalloc() when the use case was really for grabstackstr().
Change grabstackstr() to actually use the arg passed to it, instead of
(not much better than) guessing how much space to claim,
More care when using unstalloc()/ungrabstackstr() to return space, and in
particular when the stack must be returned to its previous state, rather than
just returning no-longer needed space, neither of those work.  They also don't
work properly if there have been (really, even might have been) any stack mem
allocations since the last stalloc()/grabstackstr().   (If we know there
cannot have been then the alloc/release sequence is kind of pointless.)
To work correctly in general we must use setstackmark()/popstackmark() so
do that when needed.  Have those also save/restore the top of stack string
space remaining.
	[Aside: for those reading this, the "stack" mentioned is not
	in any way related to the thing used for maintaining the C
	function call state, ie: the "stack segment" of the program,
	but the shell's internal memory management strategy.]
More comments to better explain what is happening in some cases.
Also cleaned up some hopelessly broken DEBUG mode data that were
recently added (no effect on anyone but the poor semi-human attempting
to make sense of it...).
User visible changes:
Proper counting of line numbers when a here document is delimited
by a multi-line end-delimiter, as in
	cat << 'REALLY
	END'
	here doc line 1
	here doc line 2
	REALLY
	END
(which is an obscure case, but nothing says should not work.)  The \n
in the end-delimiter of the here doc (the last one) was not incrementing
the line number, which from that point on in the script would be 1 too
low (or more, for end-delimiters with more than one \n in them.)
With tilde expansion:
	unset HOME; echo ~
changed to return getpwuid(getuid())->pw_home instead of failing (returning ~)
POSIX says this is unspecified, which makes it difficult for a script to
compensate for being run without HOME set (as in env -i sh script), so
while not able to be used portably, this seems like a useful extension
(and is implemented the same way by some other shells).
Further, with
	HOME=; printf %s ~
we now write nothing (which is required by POSIX - which requires ~ to
expand to the value of $HOME if it is set) previously if $HOME (in this
case) or a user's directory in the passwd file (for ~user) were a null
STRING, We failed the ~ expansion and left behind '~' or '~user'.
Changed the long name for the -L option from lineno_fn_relative
to local_lineno as the latter seemed to be marginally more popular,
and perhaps more importantly, is the same length as the peviously
existing quietprofile option, which means the man page indentation
for the list of options can return to (about) what it was before...
(That is, less indented, which means more data/line, which means less
lines of man page - a good thing!)
Cosmetic changes to variable flags - make their values more suited
to my delicate sensibilities...  (NFC).
Arrange not to barf (ever) if some turkey makes _ readonly.  Do this
by adding a VNOERROR flag that causes errors in var setting to be
ignored (intended use is only for internal shell var setting, like of "_").
(nb: invalid var name errors ignore this flag, but those should never
occur on a var set by the shell itself.)
From FreeBSD: don't simply discard memory if a variable is not set for
any reason (including because it is readonly) if the var's value had
been malloc'd.  Free it instead...
NFC - DEBUG changes, update this to new TRACE method.
KNF - white space and comment formatting.
NFC - DEBUG mode only change - convert this to the new TRACE() format.
NFC - DEBUG mode only change - complete a change made earlier (marking
the line number when included in the trace line tag to show whether it
comes from the parser, or the elsewhere as they tend to be quite different).
Initially only one case was changed, while I pondered whether I liked it
or not.  Now it is all done...   Also when there is a line tag at all,
always include the root/sub-shell indicator character, not only when the
pid is included.
NFC: DEBUG related comment change - catch up with reality.
NFC: DEBUG mode only change.  Fix botched cleanup of one TRACE().
"b" more forgiving when sorting options to allow reasonable (and intended)
flexibility in option.list format.   Changes nothing for current option.list.
Now that excessive use of STACKSTRNUL has served its purpose (well, accidental
purpose) in exposing the bug in its implementation, go back to not using
it when not needed for DEBUG TRACE purposes.   This change should have no
practical effect on either a DEBUG shell (where the STACKSTRNUL() calls
remain) or a non DEBUG shell where they are not needed.
Correct the initial line number used for processing -c arg strings.
(It was inheriting the value from end of profile file processing) - I didn't
notice before as I usually test with empty or no profile files to avoid
complications.   Trivial change which should have very limited impact.
Fix from FreeBSD (applied there in July 2008...)
Don't dump core with input like sh -c 'x=; echo >&$x' - that is where
the word after a >& or <& redirect expands to nothing at all.
Another fix from FreeBSD (this one from April 2009).
When processing a string (as in eval, trap, or sh -c) don't allow
trailing \n's to destroy the exit status of the last command executed.
That is:
	sh -c 'false
	'
	echo $?
should produce 1, not 0.
It is amazing what nonsense appears to work sometimes... (all my nonsense too!)
Two bugs here, one benign because of the way the script is used.
The other hidden by NetBSD's sort being stable, and the data not really
requiring sorting at all...
So as it happens these fixes change nothing, but they are needed anyway.
(The contents of the generated file are only used in DEBUG shells, so
this is really even less important than it seems.)
Another ancient (highly improbable) bug bites the dust.   This one
caused by incorrect macro usage (ie: using the wrong one) which has
been in the sources since version 1.1 (ie: forever).
Like the previous (STACKSTRNUL) bug, the probability of this one
actually occurring has been infinitesimal but the LINENO code increases
that to infinitesimal and a smidgen... (or a few, depending upon usage).
Still, apparently that was enough, Kamil Rytarowski discovered that the
zsh configure script (damn competition!) managed to trigger this problem.
source .editrc after we initialize so that commands persist!
Make arg parsing in kill POSIX compatible with POSIX (XBD 2.12) by
parsing the way getopt(3) would, if only it could handle the (required)
-signumber and -signame options.  This adds two "features" to kill,
-ssigname and -lstatus now work (ie: one word with all of the '-', the
option letter, and its value) and "--" also now works (kill -- -pid1 pid2
will not attempt to send the pid1 signal to pid2, but rather SIGTERM
to the pid1 process group and pid2).  It is still the case that (apart
from --) at most 1 option is permitted (-l, -s, -signame, or -signumber.)
Note that we now have an ambiguity, -sname might mean "-s name" or
send the signal "sname" - if one of those turns out to be valid, that
will be accepted, otherwise the error message will indicate that "sname"
is not a valid signal name, not that "name" is not.   Keeping the "-s"
and signal name as separate words avoids this issue.
Also caution: should someone be weird enough to define a new signal
name (as in the part after SIG) which is almost the same name as an
existing name that starts with 'S' by adding an extra 'S' prepended
(eg: adding a SIGSSYS) then the ambiguity problem becomes much worse.
In that case "kill -ssys" will be resolved in favour of the "-s"
flag being used (the more modern syntax) and would send a SIGSYS, rather
that a SIGSSYS.    So don't do that.
While here, switch to using signalname(3) (bye bye NSIG, et. al.), add
some constipation, and show a little pride in formatting the signal names
for "kill -l" (and in the usage when appropriate -- same routine.)   Respect
COLUMNS (POSIX XBD 8.3) as primary specification of the width (terminal width,
not number of columns to print) for kill -l, a very small value for COLUMNS
will cause kill -l output to list signals one per line, a very large
value will cause them all to be listed on one line.) (eg: "COLUMNS=1 kill -l")
TODO: the signal printing for "trap -l" and that for "kill -l"
should be switched to use a common routine (for the sh builtin versions.)
All changes of relevance here are to bin/kill - the (minor) changes to bin/sh
are only to properly expose the builtin version of getenv(3) so the builtin
version of kill can use it (ie: make its prototype available.)
Properly support EDITRC - use it as (naming) the file when setting
up libedit, and re-do the config whenever EDITRC is set.
Get rid of workarounds for ancient groff html backend.
Simplify macro usage.
Make one example more like a real world possibility (it still isn't, but
is closer) - though the actual content is irrelevant to the point being made.
Add literal prompt support this allows one to do:
CA="$(printf '\1')"
PS1="${CA}$(tput bold)${CA}\$${CA}$(tput sgr0)${CA} "
Now libedit supports embedded mode switch sequence, improve sh
support for them (adds PSlit variable to set the magic character).
NFC: DEBUG only change - provide an externally visible (to the DEBUG sh
internals) interface to one of the internal (private to trace code) functions
Include redirections in trace output from "set -x"
Implement PS1, PS2 and PS4 expansions (variable expansions, arithmetic
expansions, and if enabled by the promptcmds option, command substitutions.)
Implement a bunch of new shell environment variables. many mostly useful
in prompts when expanded at prompt time, but all available for general use.
Many of the new ones are not available in SMALL shells (they work as normal
if assigned, but the shell does not set or use them - and there is no magic
in a SMALL shell (usually for install media.))
Omnibus manual update for prompt expansions and new variables.  Throw in
some random cleanups as a bonus.
Correct a markup typo (why did I not see this before the prev commit??)
Sort options (our default is 0..9AaBbZz).
Fix markup problems and a typo.
Make $- list flags in the same order they appear in sh(1)
Do a better job of detecting the error in pkgsrc/devel/libbson-1.6.3's
configure script, ie: $(( which is intended to be a sub-shell in a
command substitution, but is an arith subst instead, it needs to be
written $( ( to do as intended.   Instead of just blindly carrying on to
find the missing )) somewhere, anywhere, give up as soon as we have seen
an unbalanced ')' that isn't immediately followed by another ')' which
in a valid arith subst it always would be.
While here, there has been a comment in the code for quite a while noting a
difference in the standard between the text descr & grammar when it comes to
the syntax of case statements.   Add more comments to explain why parsing it
as we do is in fact definitely the correct way (ie: the grammar wins arguments
like this...).
DEBUG and white space changes only.   Convert TRACE() calls for DEBUg mode
to the new style.   NFC (when not debugging sh).
Mostly DEBUG and white space changes.   Convert DEEBUG TRACE() calls to
the new format.   Also #if 0 a function definition that is used nowhere.
While here, change the function of pushfile() slightly - it now sets
the buf pointer in the top (new) input descriptor to NULL, instead of
simply leaving it - code that needs a buffer always (before and after)
must malloc() one and assign it after the call.  But code which does not
(which will be reading from a string or similar) now does not have to
explicitly set it to NULL (cleaner interface.)   NFC intended (or observed.)
DEBUG changes: convert DEBUG TRACE() calls to new format.
ALso, cause exec failures to always cause the shell to exit with
status 126 or 127, whatever the cause.  127 is intended for lookup
failures (and is used that way), 126 is used for anything else that
goes wrong (as in several other shells.)  We no longer use 2 (more easily
confused with an exit status of the command exec'd) for shell exec failures.
DEBUG only changes.  Convert the TRACE() calls in the remaining files
that still used it to the new format.   NFC.
Fix a reference after free (and consequent nonsense diagnostic for
attempts to set readonly variables) I added in 1.60 by incompletely
copying the FreeBSD fix for the lost memory issue.
@
text
@d1 1
a1 1
/* $NetBSD: option.list,v 1.2 2017/05/28 14:14:22 kre Exp $ */
d7 1
a7 1
 *	but they do nothing until code to implement them
a65 2
fnline1	local_lineno	L on		# number lines in funcs starting at 1
promptcmds promptcmds			# allow $( ) in PS1 (et al).
@


1.1
log
@Arrange for set -o and $- output to be sorted, rather than more
or less random (and becoming worse as more options are added.)
Since the data is known at compile time, sort at compile time,
rather than at run time.
@
text
@d1 1
a1 1
/* $NetBSD$ */
d5 4
a13 1
 * proprocessor directoves can be (kind of) interspersed as required
d25 1
a25 1
 *	5. efault value of option
d27 5
a31 1
 *		only 0 or 1 possible (0==off 1==on)
d34 1
a34 4
/*
 * The order of the lines below gives the order they are listed by set -o
 * Options labelled '[U]' are not (yet, maybe ever) implemented.
 */
a35 2
cdprint	cdprint				# always print result of a cd
Eflag	emacs		E V		# enable emacs style editing
a36 3
usefork	fork		F		# use fork(2) instead of vfork(2)
Iflag	ignoreeof	I		# do not exit interactive shell on EOF
iflag	interactive	i		# interactive shell
d41 9
d51 12
a63 2
bflag	notify		b		# [U] report bg job completion
uflag	nounset		u		# expanding unset var is an error
d66 6
a71 1
sflag	stdin		s		# read from standard input
a72 4
hflag	trackall	h		# [U] locate cmds in funcs during defn
vflag	verbose		v		# echo commands as read
Vflag	vi		V V		# enable vi style editing
xflag	xtrace		x		# trace command execution
d74 2
a75 3
#ifdef DEBUG
debug	debug				# enable internal shell debugging
#endif
@

