Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh Add some error checking, and stop assuming what the i...



details:   https://anonhg.NetBSD.org/src/rev/1d4749fd9628
branches:  trunk
changeset: 447622:1d4749fd9628
user:      kre <kre%NetBSD.org@localhost>
date:      Sat Jan 19 13:08:50 2019 +0000

description:
Add some error checking, and stop assuming what the input
will necessarily contain.   Allow defined nodes to use any
intN_t or unintN_t (as well as plain old int) data types
in fields (along with the others that are permitted).

Note: this script is a part of the build procedure for /bin/sh,
the modified version generates the exact same output files
(for the unaltered input specifications) as the previous one
did, hence no visible change is expected (or even possible).

While there is a tiny chance that some host shell will fail
to be able to run this script while building, the script still
uses nothing even slightly exotic, and is much more conservative
than other scripts used during the build process, so there should
be no issues there either.

diffstat:

 bin/sh/mknodes.sh |  32 ++++++++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 4 deletions(-)

diffs (65 lines):

diff -r 58d23ffe25e2 -r 1d4749fd9628 bin/sh/mknodes.sh
--- a/bin/sh/mknodes.sh Sat Jan 19 13:06:50 2019 +0000
+++ b/bin/sh/mknodes.sh Sat Jan 19 13:08:50 2019 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-#      $NetBSD: mknodes.sh,v 1.3 2018/06/22 11:04:55 kre Exp $
+#      $NetBSD: mknodes.sh,v 1.4 2019/01/19 13:08:50 kre Exp $
 
 # Copyright (c) 2003 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -83,11 +83,35 @@
                IFS=' '
                set -- $line
                name=$1
+               case "$name" in
+               type)   if [ -n "$typetype" ] && [ "$typetype" != "$2" ]
+                       then
+                               echo >&2 "Conflicting type fields: node" \
+                                       "$struct has $2, others $typetype"
+                               exit 1
+                       fi
+                       if [ $field -ne 1 ]
+                       then
+                               echo >&2 "Node $struct has type as field" \
+                                       "$field (should only be first)"
+                               exit 1
+                       fi
+                       typetype=$2
+                       ;;
+               *)
+                       if [ $field -eq 1 ]
+                       then
+                               echo >&2 "Node $struct does not have" \
+                                       "type as first field"
+                               exit 1
+                       fi
+                       ;;
+               esac
                case $2 in
                nodeptr ) type="union node *";;
                nodelist ) type="struct nodelist *";;
                string ) type="char *";;
-               int ) type="int ";;
+               int*_t | uint*_t | int ) type="$2 ";;
                * ) name=; shift 2; type="$*";;
                esac
                echo "      $type$name;"
@@ -98,7 +122,7 @@
 echo
 echo
 echo "union node {"
-echo "      int type;"
+echo "      $typetype type;"
 for struct in $struct_list; do
        echo "      struct $struct $struct;"
 done
@@ -200,7 +224,7 @@
                                nodeptr ) fn="copynode(";;
                                nodelist ) fn="copynodelist(";;
                                string ) fn="nodesavestr(";;
-                               int ) fn=;;
+                               int*_t| uint*_t | int ) fn=;;
                                * ) continue;;
                                esac
                                f="$struct.$name"



Home | Main Index | Thread Index | Old Index