date and time created 91/03/07 20:27:53 by bostic
[unix-history] / usr / src / bin / sh / mkbuiltins
CommitLineData
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
13temp=/tmp/ka$$
14havejobs=0
15if grep '^#define JOBS[ ]*1' shell.h > /dev/null
16then havejobs=1
17fi
18exec > obj/builtins.c
19cat <<\!
20/*
21 * This file was generated by the mkbuiltins program.
22 */
23
24#include "shell.h"
25#include "builtins.h"
26
27!
28awk '/^[^#]/ {if('$havejobs' || $2 != "-j") print $0}' builtins |
29 sed 's/-j//' > $temp
30awk '{ printf "int %s();\n", $1}' $temp
31echo '
32int (*const builtinfunc[])() = {'
33awk '/^[^#]/ { printf "\t%s,\n", $1}' $temp
34echo '};
35
36const struct builtincmd builtincmd[] = {'
37awk '{ for (i = 2 ; i <= NF ; i++) {
38 printf "\t\"%s\", %d,\n", $i, NR-1
39 }}' $temp
40echo ' NULL, 0
41};'
42
43exec > obj/builtins.h
44cat <<\!
45/*
46 * This file was generated by the mkbuiltins program.
47 */
48
49!
50tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ < $temp |
51 awk '{ printf "#define %s %d\n", $1, NR-1}'
52echo '
53struct builtincmd {
54 char *name;
55 int code;
56};
57
58extern int (*const builtinfunc[])();
59extern const struct builtincmd builtincmd[];'
60rm -f $temp