Module Name: src Committed By: kre Date: Sat Apr 6 14:20:27 UTC 2024
Modified Files: src/bin/sh: mkoptions.sh Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/bin/sh/mkoptions.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/sh/mkoptions.sh diff -u src/bin/sh/mkoptions.sh:1.6 src/bin/sh/mkoptions.sh:1.7 --- src/bin/sh/mkoptions.sh:1.6 Fri Apr 5 22:22:17 2024 +++ src/bin/sh/mkoptions.sh Sat Apr 6 14:20:27 2024 @@ -1,6 +1,6 @@ #! /bin/sh -# $NetBSD: mkoptions.sh,v 1.6 2024/04/05 22:22:17 christos Exp $ +# $NetBSD: mkoptions.sh,v 1.7 2024/04/06 14:20:27 kre Exp $ # # It would be more sensible to generate 2 .h files, one which @@ -18,9 +18,20 @@ export LC_ALL=C # for sort consistency IF="$1" OF="${3+$3/}$2" -E_FILE=$(${MKTEMP:-mktemp} -t MKOXXXXXXXX.E.$$) -O_FILE=$(${MKTEMP:-mktemp} -t MKOXXXXXXXX.O.$$) -trap 'rm -f "${E_FILE}" "${O_FILE}"' EXIT +case $- in +*x*) + E_FILE=$(${MKTEMP:-mktemp} "${TMPDIR:-/tmp}/MKO.E.$$.XXXXXX") || exit 1 + O_FILE=$(${MKTEMP:-mktemp} "${TMPDIR:-/tmp}/MKO.O.$$.XXXXXX") || { + rm -f "${E_FILE}" + exit 1 + } + ;; +*) + E_FILE=$(${MKTEMP:-mktemp}) || exit 1 + O_FILE=$(${MKTEMP:-mktemp}) || { rm -f "${E_FILE}"; exit 1; } + trap 'rm -f "${E_FILE}" "${O_FILE}"' EXIT + ;; +esac exec 5> "${E_FILE}" exec 6> "${O_FILE}" @@ -41,8 +52,8 @@ ${SED:-sed} <"${IF}" \ -e '/^#/d' \ -e '/^[ ]*\//d' \ -e '/^[ ]*\*/d' \ - -e '/^[ ]*;/d' | -sort -b -k2,2f -k2,2 | + -e '/^[ ]*;/d' | +sort -b -k2,2f -k2,2 | while read line do # Look for comments in various styles, and ignore them