| 1 | #!/bin/sh -
 | 
|---|
| 2 | #
 | 
|---|
| 3 | # Copyright (c) 1991 The Regents of the University of California.
 | 
|---|
| 4 | # All rights reserved.
 | 
|---|
| 5 | #
 | 
|---|
| 6 | # This code is derived from software contributed to Berkeley by
 | 
|---|
| 7 | # Kenneth Almquist.
 | 
|---|
| 8 | #
 | 
|---|
| 9 | # Redistribution and use in source and binary forms, with or without
 | 
|---|
| 10 | # modification, are permitted provided that the following conditions
 | 
|---|
| 11 | # are met:
 | 
|---|
| 12 | # 1. Redistributions of source code must retain the above copyright
 | 
|---|
| 13 | #    notice, this list of conditions and the following disclaimer.
 | 
|---|
| 14 | # 2. Redistributions in binary form must reproduce the above copyright
 | 
|---|
| 15 | #    notice, this list of conditions and the following disclaimer in the
 | 
|---|
| 16 | #    documentation and/or other materials provided with the distribution.
 | 
|---|
| 17 | # 3. All advertising materials mentioning features or use of this software
 | 
|---|
| 18 | #    must display the following acknowledgement:
 | 
|---|
| 19 | #       This product includes software developed by the University of
 | 
|---|
| 20 | #       California, Berkeley and its contributors.
 | 
|---|
| 21 | # 4. Neither the name of the University nor the names of its contributors
 | 
|---|
| 22 | #    may be used to endorse or promote products derived from this software
 | 
|---|
| 23 | #    without specific prior written permission.
 | 
|---|
| 24 | #
 | 
|---|
| 25 | # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 | 
|---|
| 26 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 | 
|---|
| 27 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 | 
|---|
| 28 | # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 | 
|---|
| 29 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 | 
|---|
| 30 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 | 
|---|
| 31 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 | 
|---|
| 32 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 | 
|---|
| 33 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 | 
|---|
| 34 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 | 
|---|
| 35 | # SUCH DAMAGE.
 | 
|---|
| 36 | #
 | 
|---|
| 37 | #       @(#)mkbuiltins  5.2 (Berkeley) 3/8/91
 | 
|---|
| 38 | 
 | 
|---|
| 39 | # All calls to awk removed, because Minix bawk is deficient.  (kjb)
 | 
|---|
| 40 | 
 | 
|---|
| 41 | if [ $# != 2 ]
 | 
|---|
| 42 | then
 | 
|---|
| 43 |         echo "USAGE: $0 shell.h builtins"
 | 
|---|
| 44 |         exit 1
 | 
|---|
| 45 | fi
 | 
|---|
| 46 | SHL=$1
 | 
|---|
| 47 | BLTINS=$2
 | 
|---|
| 48 | 
 | 
|---|
| 49 | temp=/tmp/ka$$
 | 
|---|
| 50 | exec > builtins.c
 | 
|---|
| 51 | cat <<\!
 | 
|---|
| 52 | /*
 | 
|---|
| 53 |  * This file was generated by the mkbuiltins program.
 | 
|---|
| 54 |  */
 | 
|---|
| 55 | 
 | 
|---|
| 56 | #include "shell.h"
 | 
|---|
| 57 | #include "builtins.h"
 | 
|---|
| 58 | 
 | 
|---|
| 59 | !
 | 
|---|
| 60 | if grep '^#define JOBS[  ]*1' $SHL > /dev/null
 | 
|---|
| 61 | then
 | 
|---|
| 62 |         # Job control.
 | 
|---|
| 63 |         sed -e '/^#/d
 | 
|---|
| 64 |                 s/      / /g
 | 
|---|
| 65 |                 s/ #.*//
 | 
|---|
| 66 |                 /^ *$/d
 | 
|---|
| 67 |                 s/-j//' $BLTINS > $temp
 | 
|---|
| 68 | else
 | 
|---|
| 69 |         # No job control.
 | 
|---|
| 70 |         sed -e '/^#/d
 | 
|---|
| 71 |                 s/      / /g
 | 
|---|
| 72 |                 s/ #.*//
 | 
|---|
| 73 |                 /^ *$/d
 | 
|---|
| 74 |                 /-j/d' $BLTINS > $temp
 | 
|---|
| 75 | fi
 | 
|---|
| 76 | sed -e 's/ .*//
 | 
|---|
| 77 |         s/\(.*\)/int \1();/' $temp
 | 
|---|
| 78 | echo '
 | 
|---|
| 79 | int (*const builtinfunc[])() = {'
 | 
|---|
| 80 | sed -e 's/ .*//
 | 
|---|
| 81 |         s/\(.*\)/       \1,/' $temp
 | 
|---|
| 82 | echo '};
 | 
|---|
| 83 | 
 | 
|---|
| 84 | const struct builtincmd builtincmd[] = {'
 | 
|---|
| 85 | i=0
 | 
|---|
| 86 | while read line
 | 
|---|
| 87 | do
 | 
|---|
| 88 |         set -$- $line
 | 
|---|
| 89 |         shift
 | 
|---|
| 90 |         for fun
 | 
|---|
| 91 |         do
 | 
|---|
| 92 |                 echo "  \"$fun\", $i,"
 | 
|---|
| 93 |         done
 | 
|---|
| 94 |         i=`expr $i + 1`
 | 
|---|
| 95 | done < $temp
 | 
|---|
| 96 | echo '  NULL, 0
 | 
|---|
| 97 | };'
 | 
|---|
| 98 | 
 | 
|---|
| 99 | exec > builtins.h
 | 
|---|
| 100 | cat <<\!
 | 
|---|
| 101 | /*
 | 
|---|
| 102 |  * This file was generated by the mkbuiltins program.
 | 
|---|
| 103 |  */
 | 
|---|
| 104 | 
 | 
|---|
| 105 | #include <sys/cdefs.h>
 | 
|---|
| 106 | !
 | 
|---|
| 107 | i=0
 | 
|---|
| 108 | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ < $temp |
 | 
|---|
| 109 |         while read line
 | 
|---|
| 110 |         do
 | 
|---|
| 111 |                 set -$- $line
 | 
|---|
| 112 |                 echo "#define $1 $i"
 | 
|---|
| 113 |                 i=`expr $i + 1`
 | 
|---|
| 114 |         done
 | 
|---|
| 115 | echo '
 | 
|---|
| 116 | struct builtincmd {
 | 
|---|
| 117 |       char *name;
 | 
|---|
| 118 |       int code;
 | 
|---|
| 119 | };
 | 
|---|
| 120 | 
 | 
|---|
| 121 | extern int (*const builtinfunc[])();
 | 
|---|
| 122 | extern const struct builtincmd builtincmd[];'
 | 
|---|
| 123 | rm -f $temp
 | 
|---|