Skip to content

Commit b3aaff6

Browse files
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.
1 parent d517ce6 commit b3aaff6

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

bin/sh/mkoptions.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /bin/sh
22

3-
# $NetBSD: mkoptions.sh,v 1.5 2017/11/15 09:21:19 kre Exp $
3+
# $NetBSD: mkoptions.sh,v 1.5.6.1 2025/10/01 15:27:36 martin Exp $
44

55
#
66
# It would be more sensible to generate 2 .h files, one which
@@ -13,13 +13,25 @@
1313

1414
set -f
1515
IFS=' ' # blank, tab (no newline)
16+
export LC_ALL=C # for sort consistency
1617

1718
IF="$1"
1819
OF="${3+$3/}$2"
1920

20-
E_FILE=$(${MKTEMP:-mktemp} -t MKO.E.$$)
21-
O_FILE=$(${MKTEMP:-mktemp} -t MKO.O.$$)
22-
trap 'rm -f "${E_FILE}" "${O_FILE}"' EXIT
21+
case $- in
22+
*x*)
23+
E_FILE=$(${MKTEMP:-mktemp} "${TMPDIR:-/tmp}/MKO.E.$$.XXXXXX") || exit 1
24+
O_FILE=$(${MKTEMP:-mktemp} "${TMPDIR:-/tmp}/MKO.O.$$.XXXXXX") || {
25+
rm -f "${E_FILE}"
26+
exit 1
27+
}
28+
;;
29+
*)
30+
E_FILE=$(${MKTEMP:-mktemp}) || exit 1
31+
O_FILE=$(${MKTEMP:-mktemp}) || { rm -f "${E_FILE}"; exit 1; }
32+
trap 'rm -f "${E_FILE}" "${O_FILE}"' EXIT
33+
;;
34+
esac
2335

2436
exec 5> "${E_FILE}"
2537
exec 6> "${O_FILE}"
@@ -40,8 +52,8 @@ ${SED:-sed} <"${IF}" \
4052
-e '/^#/d' \
4153
-e '/^[ ]*\//d' \
4254
-e '/^[ ]*\*/d' \
43-
-e '/^[ ]*;/d' |
44-
sort -b -k2,2f -k2,2 < "${IF}" |
55+
-e '/^[ ]*;/d' |
56+
sort -k2b,2f -k2b,2 |
4557
while read line
4658
do
4759
# Look for comments in various styles, and ignore them
@@ -83,6 +95,7 @@ do
8395

8496
case "${chr}" in
8597
-) chr= set= dflt="$4";;
98+
+) chr= ;;
8699
''|?) ;;
87100
*) printf >&2 'flag "%s": Not a character\n' "${chr}"; continue;;
88101
esac

bin/sh/option.list

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: option.list,v 1.9 2018/11/23 20:40:06 kre Exp $ */
1+
/* $NetBSD: option.list,v 1.9.2.1 2025/10/01 15:27:36 martin Exp $ */
22

33
/*
44
* define the shell's settable options
@@ -26,6 +26,8 @@
2626
* if absent, default is 0
2727
* only 0 or 1 possible (0==off 1==on) ("on" and "off" can be used)
2828
*
29+
* NB: Use only tabs to separate fields 1..3 (spaces can be used for 4 & 5)
30+
*
2931
* Data may be followed by any C preprocessor #if expression (incl the #if..)
3032
* (including #ifdef #ifndef) to conditionalise output for that option.
3133
* The #if expression continues until \n or next following '#'
@@ -64,8 +66,8 @@ pflag nopriv p # preserve privs if set[ug]id
6466
posix posix # be closer to POSIX compat
6567
qflag quietprofile q # disable -v/-x in startup files
6668
fnline1 local_lineno L on # number lines in funcs starting at 1
67-
promptcmds promptcmds # allow $( ) in PS1 (et al).
68-
pipefail pipefail # pipe exit status
69+
promptcmds promptcmds # allow $( ) in PS1 (et al).
70+
pipefail pipefail # pipe exit status
6971
Xflag xlock X #ifndef SMALL # sticky stderr for -x (implies -x)
7072

7173
// editline/history related options ("vi" is standard, 'V' and others are not)

0 commit comments

Comments
 (0)