]> git.saurik.com Git - apple/shell_cmds.git/blobdiff - sh/mkbuiltins
shell_cmds-216.40.4.tar.gz
[apple/shell_cmds.git] / sh / mkbuiltins
index dd0adc8d000e0ea23d376f104a3dc6fb805adc3b..7c2cef1d2109e20c63668b7b12366437eeb2ec8d 100755 (executable)
@@ -15,7 +15,7 @@
 # 2. Redistributions in binary form must reproduce the above copyright
 #    notice, this list of conditions and the following disclaimer in the
 #    documentation and/or other materials provided with the distribution.
-# 4. Neither the name of the University nor the names of its contributors
+# 3. Neither the name of the University nor the names of its contributors
 #    may be used to endorse or promote products derived from this software
 #    without specific prior written permission.
 #
@@ -32,9 +32,9 @@
 # SUCH DAMAGE.
 #
 #      @(#)mkbuiltins  8.2 (Berkeley) 5/4/95
-# $FreeBSD: head/bin/sh/mkbuiltins 293118 2016-01-03 21:30:22Z jilles $
+# $FreeBSD: head/bin/sh/mkbuiltins 328934 2018-02-06 15:41:35Z arichardson $
 
-temp=`/usr/bin/mktemp -t ka`
+temp=`mktemp -t ka`
 havehist=1
 if [ "X$1" = "X-h" ]; then
        havehist=0
@@ -66,6 +66,9 @@ const unsigned char builtincmd[] = {'
 awk '{ for (i = 2 ; i <= NF ; i++) {
                if ($i == "-s") {
                        spc = 1;
+               } else if ($i == "-n") {
+                       # Handled later for builtins.h
+                       continue
                } else {
                        printf "\t\"\\%03o\\%03o%s\"\n", length($i), (spc ? 128 : 0) + NR-1, $i
                        spc = 0;
@@ -90,4 +93,45 @@ extern int (*const builtinfunc[])(int, char **);
 extern const unsigned char builtincmd[];
 '
 awk '{ printf "int %s(int, char **);\n", $1}' $temp
+
+# Build safe_builtin_always()
+cat <<EOF
+
+static inline int
+safe_builtin_always(int idx)
+{
+EOF
+awk '
+BEGIN { printed = 0 }
+{
+       for (i = 2 ; i <= NF ; i++) {
+               if ($i == "-s") {
+                       continue
+               } else if ($i == "-n") {
+                       nofork = 1;
+               } else {
+                       if (nofork == 0) {
+                               continue
+                       }
+                       if (printed == 1) {
+                               printf " || \n\t    "
+                       } else {
+                               printf "\tif ("
+                       }
+                       printf "idx == " toupper($1)
+                       printed = 1
+                       nofork = 0;
+                       # Only need to check each once
+                       break
+               }
+       }
+}' $temp
+
+cat << EOF
+)
+               return (1);
+       return(0);
+}
+EOF
+
 rm -f $temp