Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh Redo mkoptions.sh .. much better this way, now fully ...
details: https://anonhg.NetBSD.org/src/rev/7c50a5f1259e
branches: trunk
changeset: 353917:7c50a5f1259e
user: kre <kre%NetBSD.org@localhost>
date: Sun May 28 14:14:22 2017 +0000
description:
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.
diffstat:
bin/sh/Makefile | 3 +-
bin/sh/mkoptions.sh | 101 +++++++++++++++++++++++++++++++++++++++------------
bin/sh/option.list | 64 +++++++++++++++++++++-----------
3 files changed, 119 insertions(+), 49 deletions(-)
diffs (truncated from 312 to 300 lines):
diff -r 7ddc34ff43ac -r 7c50a5f1259e bin/sh/Makefile
--- a/bin/sh/Makefile Sun May 28 13:55:07 2017 +0000
+++ b/bin/sh/Makefile Sun May 28 14:14:22 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.108 2017/05/28 00:38:01 kre Exp $
+# $NetBSD: Makefile,v 1.109 2017/05/28 14:14:22 kre Exp $
# @(#)Makefile 8.4 (Berkeley) 5/5/95
.include <bsd.own.mk>
@@ -20,6 +20,7 @@
# Environment for scripts executed during build.
SCRIPT_ENV= \
AWK=${TOOL_AWK:Q} \
+ MKTEMP=${TOOL_MKTEMP:Q} \
SED=${TOOL_SED:Q}
CPPFLAGS+=-DSHELL -I. -I${.CURDIR}
diff -r 7ddc34ff43ac -r 7c50a5f1259e bin/sh/mkoptions.sh
--- a/bin/sh/mkoptions.sh Sun May 28 13:55:07 2017 +0000
+++ b/bin/sh/mkoptions.sh Sun May 28 14:14:22 2017 +0000
@@ -1,6 +1,6 @@
#! /bin/sh
-# $NetBSD: mkoptions.sh,v 1.1 2017/05/28 00:38:01 kre Exp $
+# $NetBSD: mkoptions.sh,v 1.2 2017/05/28 14:14:22 kre Exp $
#
# It would be more sensible to generate 2 .h files, one which
@@ -17,36 +17,53 @@
IF="$1"
OF="${3+$3/}$2"
+E_FILE=$(${MKTEMP:-mktemp} -t MKO.E.$$)
+O_FILE=$(${MKTEMP:-mktemp} -t MKO.O.$$)
+trap 'rm -f "${E_FILE}" "${O_FILE}"' EXIT
+
+exec 5> "${E_FILE}"
+exec 6> "${O_FILE}"
+
{
printf '/*\n * File automatically generated by %s.\n' "$0"
printf ' * Do not edit, do not add to cvs.\n'
printf ' */\n\n'
printf '#ifdef DEFINE_OPTIONS\n'
- printf '#define DEF_OPT(a,b,c,d,e) { a, b, c, d, e },\n'
printf 'struct optent optlist[] = {\n'
- printf '#else\n'
- printf '#define DEF_OPT(a,b,c,d,e)\n'
- printf '#endif\n\n'
} >"${OF}"
FIRST=true
-I=0
+${SED:-sed} <"${IF}" \
+ -e '/^$/d' \
+ -e '/^#/d' \
+ -e '/^[ ]*\//d' \
+ -e '/^[ ]*\*/d' \
+ -e '/^[ ]*;/d' |
+sort -k2,2f -k2,2r < "${IF}" |
while read line
do
# Look for comments in various styles, and ignore them
- # preprocessor statements are simply output verbatim
- # but use them only first or last. one #ifdef/#endif at end is OK
+ # (these should generally be already removed by sed above)
case "${line}" in
'') continue;;
/*) continue;;
\**) continue;;
\;*) continue;;
- \#*) printf '%s\n\n' "${line}" >&4; continue;;
+ \#*) continue;;
esac
+ case "${line}" in
+ *'#if'*)
+ COND="${line#*#}"
+ COND="#${COND%%#*}"
+ ;;
+ *)
+ COND=
+ ;;
+ esac
set -- ${line%%[ ]#*}
var="$1" name="$2"
@@ -59,7 +76,6 @@
esac
case "${name}" in
-# =) name=${var};; # probably not a good idea
?) set -- ${var} '' $name $3 $4; name= ;;
esac
@@ -76,57 +92,90 @@
case "${set}" in
-) set= ;;
- [01]) dflt="${set}"; set= ;;
+ [01] | [Oo][Nn] | [Oo][Ff][Ff]) dflt="${set}"; set= ;;
''|?) ;;
*) printf >&2 'set "%s": Not a character\n' "${set}"; continue;;
esac
+ case "${dflt}" in
+ '') ;;
+ [Oo][Nn]) dflt=1;;
+ [Oo][Ff][Ff]) dflt=0;;
+ [01]) ;;
+ *) printf >&2 'default "%s" invalid, use 0 off 1 on\n'; continue;;
+ esac
+
+ # validation complete, now to generate output
+
+ if [ -n "${COND}" ]
+ then
+ printf '%s\n' "${COND}" >&4
+ printf '%s\n' "${COND}" >&5
+ printf '%s\n' "${COND}" >&6
+ fi
+
+ printf '\t_SH_OPT_%s,\n' "${var}" >&5
if [ -n "${name}" ]
then
- printf ' DEF_OPT("%s", ' "${name}" >&4
+ printf ' { "%s", ' "${name}" >&4
else
- printf ' DEF_OPT(0, ' >&4
+ printf ' { 0, ' >&4
fi
if [ -n "${chr}" ]
then
- printf "'%s', " "${chr}" >&4
+ printf "'%s', " "${chr}" >&4
else
- printf '0, ' >&4
+ chr=
+ printf '0, ' >&4
fi
if [ -n "${set}" ]
then
- printf "'%s', 0, " "${set}" >&4
+ printf "'%s', 0, " "${set}" >&4
else
- printf '0, 0, ' >&4
+ printf '0, 0, ' >&4
fi
if [ -n "${dflt}" ]
then
- printf '%s )\n' "${dflt}" >&4
+ printf '%s },\n' "${dflt}" >&4
else
- printf '0 )\n' >&4
+ printf '0 },\n' >&4
fi
- printf '#define %s optlist[%d].val\n\n' "${var}" "${I}" >&4
- I=$((I + 1))
+ printf '#define %s\toptlist[_SH_OPT_%s].val\n' "${var}" "${var}" >&6
+
+ if [ -n "${COND}" ]
+ then
+ printf '#endif\n' >&4
+ printf '#endif\n' >&5
+ printf '#endif\n' >&6
+ fi
test -z "${chr}" && continue
- printf '%s %d\n' "${chr}" $((I - 1))
+ printf '%s _SH_OPT_%s %s\n' "${chr}" "${var}" "${COND}"
-done < "$IF" 4>>"${OF}" | sort -t' ' -k1,1f -k1,1r | while read chr index
+done 4>>"${OF}" | sort -t' ' -k1,1f -k1,1r | while read chr index COND
do
if $FIRST
then
+ printf ' { 0, 0, 0, 0, 0 }\n};\n'
+ printf '#endif\n\n'
+
+ printf 'enum shell_opt_names {\n'
+ cat "${E_FILE}"
+ printf '};\n\n'
+
printf '#ifdef DEFINE_OPTIONS\n'
- printf ' { 0, 0, 0, 0, 0 }\n};\n\n'
printf 'const unsigned char optorder[] = {\n'
FIRST=false
fi
+ [ -n "${COND}" ] && printf '%s\n' "${COND}"
printf '\t%s,\n' "${index}"
+ [ -n "${COND}" ] && printf '#endif\n'
done >>"${OF}"
@@ -141,7 +190,9 @@
printf 'extern int sizeof_optlist;\n'
printf 'extern const unsigned char optorder[];\n'
printf 'extern const int option_flags;\n'
- printf '\n#endif\n'
+ printf '\n#endif\n\n'
+
+ cat "${O_FILE}"
} >> "${OF}"
exit 0
diff -r 7ddc34ff43ac -r 7c50a5f1259e bin/sh/option.list
--- a/bin/sh/option.list Sun May 28 13:55:07 2017 +0000
+++ b/bin/sh/option.list Sun May 28 14:14:22 2017 +0000
@@ -1,13 +1,16 @@
-/* $NetBSD: option.list,v 1.1 2017/05/28 00:38:01 kre Exp $ */
+/* $NetBSD: option.list,v 1.2 2017/05/28 14:14:22 kre Exp $ */
/*
* define the shell's settable options
+ *
+ * new options can be defined by adding them here,
+ * but they do nothing untilcode 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.
- * proprocessor directoves can be (kind of) interspersed as required
*
* The columns are:
* 1. internal shell "var name" (required)
@@ -19,39 +22,54 @@
* 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. efault value of option
+ * 5. default value of option
* if absent, default is 0
- * only 0 or 1 possible (0==off 1==on)
+ * only 0 or 1 possible (0==off 1==on) ("on" and "off" can be used)
+ *
+ * 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 order of the lines below gives the order they are listed by set -o
- * Options labelled '[U]' are not (yet, maybe ever) implemented.
- */
+// the POSIX defined options
aflag allexport a # export all variables
-cdprint cdprint # always print result of a cd
-Eflag emacs E V # enable emacs style editing
eflag errexit e # exit on command error ($? != 0)
-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
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
+
+// 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
+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
-bflag notify b # [U] report bg job completion
-uflag nounset u # expanding unset var is an error
posix posix # be closer to POSIX compat
qflag quietprofile q # disable -v/-x in startup files
-sflag stdin s # read from standard input
-tabcomplete tabcomplete # make <tab> cause filename expansion
-hflag trackall h # [U] locate cmds in funcs during defn
-vflag verbose v # echo commands as read
+
+// editline/history related options ("vi" is standard, 'V' and others are not)
Home |
Main Index |
Thread Index |
Old Index