Commit | Line | Data |
---|---|---|
5453d57f KB |
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 | # %sccs.include.redist.sh% | |
10 | # | |
11 | # @(#)mkbuiltins 5.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 | ! | |
50 | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ < $temp | | |
51 | awk '{ printf "#define %s %d\n", $1, NR-1}' | |
52 | echo ' | |
53 | struct builtincmd { | |
54 | char *name; | |
55 | int code; | |
56 | }; | |
57 | ||
58 | extern int (*const builtinfunc[])(); | |
59 | extern const struct builtincmd builtincmd[];' | |
60 | rm -f $temp |