| 1 | #!/bin/sh - |
| 2 | # |
| 3 | # Copyright (c) 1991, 1993 |
| 4 | # The Regents of the University of California. All rights reserved. |
| 5 | # |
| 6 | # This code is derived from software contributed to Berkeley by |
| 7 | # Kenneth Almquist. |
| 8 | # |
| 9 | # %sccs.include.redist.sh% |
| 10 | # |
| 11 | # @(#)mkbuiltins 8.1 (Berkeley) %G% |
| 12 | |
| 13 | temp=/tmp/ka$$ |
| 14 | havejobs=0 |
| 15 | if grep '^#define JOBS[ ]*1' shell.h > /dev/null |
| 16 | then havejobs=1 |
| 17 | fi |
| 18 | exec > obj/builtins.c |
| 19 | cat <<\! |
| 20 | /* |
| 21 | * This file was generated by the mkbuiltins program. |
| 22 | */ |
| 23 | |
| 24 | #include "shell.h" |
| 25 | #include "builtins.h" |
| 26 | |
| 27 | ! |
| 28 | awk '/^[^#]/ {if('$havejobs' || $2 != "-j") print $0}' builtins | |
| 29 | sed 's/-j//' > $temp |
| 30 | awk '{ printf "int %s();\n", $1}' $temp |
| 31 | echo ' |
| 32 | int (*const builtinfunc[])() = {' |
| 33 | awk '/^[^#]/ { printf "\t%s,\n", $1}' $temp |
| 34 | echo '}; |
| 35 | |
| 36 | const struct builtincmd builtincmd[] = {' |
| 37 | awk '{ for (i = 2 ; i <= NF ; i++) { |
| 38 | printf "\t\"%s\", %d,\n", $i, NR-1 |
| 39 | }}' $temp |
| 40 | echo ' NULL, 0 |
| 41 | };' |
| 42 | |
| 43 | exec > obj/builtins.h |
| 44 | cat <<\! |
| 45 | /* |
| 46 | * This file was generated by the mkbuiltins program. |
| 47 | */ |
| 48 | |
| 49 | #include <sys/cdefs.h> |
| 50 | ! |
| 51 | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ < $temp | |
| 52 | awk '{ printf "#define %s %d\n", $1, NR-1}' |
| 53 | echo ' |
| 54 | struct builtincmd { |
| 55 | char *name; |
| 56 | int code; |
| 57 | }; |
| 58 | |
| 59 | extern int (*const builtinfunc[])(); |
| 60 | extern const struct builtincmd builtincmd[];' |
| 61 | rm -f $temp |