mkbuiltins revision 50471
1235234Simp#!/bin/sh -
2235234Simp#
3235234Simp# Copyright (c) 1991, 1993
4235234Simp#	The Regents of the University of California.  All rights reserved.
5235234Simp#
6235234Simp# This code is derived from software contributed to Berkeley by
7235234Simp# Kenneth Almquist.
8235234Simp#
9235234Simp# Redistribution and use in source and binary forms, with or without
10235234Simp# modification, are permitted provided that the following conditions
11235234Simp# are met:
12235234Simp# 1. Redistributions of source code must retain the above copyright
13235234Simp#    notice, this list of conditions and the following disclaimer.
14235234Simp# 2. Redistributions in binary form must reproduce the above copyright
15235234Simp#    notice, this list of conditions and the following disclaimer in the
16235234Simp#    documentation and/or other materials provided with the distribution.
17235234Simp# 3. All advertising materials mentioning features or use of this software
18235234Simp#    must display the following acknowledgement:
19235234Simp#	This product includes software developed by the University of
20235234Simp#	California, Berkeley and its contributors.
21235234Simp# 4. Neither the name of the University nor the names of its contributors
22235234Simp#    may be used to endorse or promote products derived from this software
23235234Simp#    without specific prior written permission.
24235234Simp#
25235234Simp# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26235234Simp# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27235234Simp# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28235234Simp# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29235234Simp# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30235234Simp# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31235234Simp# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32235234Simp# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33235234Simp# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34235234Simp# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35235234Simp# SUCH DAMAGE.
36235234Simp#
37235234Simp#	@(#)mkbuiltins	8.2 (Berkeley) 5/4/95
38235234Simp# $FreeBSD: head/bin/sh/mkbuiltins 50471 1999-08-27 23:15:48Z peter $
39235234Simp
40235234Simptemp=/tmp/ka$$
41235234Simphavejobs=0
42235234Simpif grep '^#define JOBS[	 ]*1' shell.h > /dev/null
43235234Simpthen	havejobs=1
44235234Simpfi
45235234Simphavehist=1
46235234Simpif [ "X$1" = "X-h" ]; then
47235234Simp	havehist=0
48235234Simp	shift
49235234Simpfi
50235234Simpobjdir=$1
51235234Simpexec > ${objdir}/builtins.c
52235234Simpcat <<\!
53235234Simp/*
54235234Simp * This file was generated by the mkbuiltins program.
55235234Simp */
56235234Simp
57235234Simp#include "shell.h"
58235234Simp#include "builtins.h"
59235234Simp
60235234Simp!
61235234Simpawk '/^[^#]/ {if(('$havejobs' || $2 != "-j") && ('$havehist' || $2 != "-h")) \
62235234Simp    print $0}' builtins.def | sed 's/-j//' > $temp
63235234Simpawk '{	printf "int %s();\n", $1}' $temp
64235234Simpecho '
65235234Simpint (*const builtinfunc[])() = {'
66235234Simpawk '/^[^#]/ {	printf "\t%s,\n", $1}' $temp
67235234Simpecho '};
68235234Simp
69235234Simpconst struct builtincmd builtincmd[] = {'
70235234Simpawk '{	for (i = 2 ; i <= NF ; i++) {
71235234Simp		printf "\t{ \"%s\", %d },\n",  $i, NR-1
72235234Simp	}}' $temp
73235234Simpecho '	{ NULL, 0 }
74235234Simp};'
75235234Simp
76235234Simpexec > ${objdir}/builtins.h
77235234Simpcat <<\!
78235234Simp/*
79235234Simp * This file was generated by the mkbuiltins program.
80235234Simp */
81235234Simp
82235234Simp#include <sys/cdefs.h>
83235234Simp!
84235234Simptr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ < $temp |
85235234Simp	awk '{	printf "#define %s %d\n", $1, NR-1}'
86235234Simpecho '
87235234Simpstruct builtincmd {
88235234Simp      char *name;
89235234Simp      int code;
90235234Simp};
91235234Simp
92235234Simpextern int (*const builtinfunc[])();
93235234Simpextern const struct builtincmd builtincmd[];'
94235234Simprm -f $temp
95235234Simp