11556Srgrimes#!/bin/sh -
2139969Simp
3139969Simp#-
41556Srgrimes# Copyright (c) 1991, 1993
51556Srgrimes#	The Regents of the University of California.  All rights reserved.
61556Srgrimes#
71556Srgrimes# This code is derived from software contributed to Berkeley by
81556Srgrimes# Kenneth Almquist.
91556Srgrimes#
101556Srgrimes# Redistribution and use in source and binary forms, with or without
111556Srgrimes# modification, are permitted provided that the following conditions
121556Srgrimes# are met:
131556Srgrimes# 1. Redistributions of source code must retain the above copyright
141556Srgrimes#    notice, this list of conditions and the following disclaimer.
151556Srgrimes# 2. Redistributions in binary form must reproduce the above copyright
161556Srgrimes#    notice, this list of conditions and the following disclaimer in the
171556Srgrimes#    documentation and/or other materials provided with the distribution.
181556Srgrimes# 4. Neither the name of the University nor the names of its contributors
191556Srgrimes#    may be used to endorse or promote products derived from this software
201556Srgrimes#    without specific prior written permission.
211556Srgrimes#
221556Srgrimes# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231556Srgrimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241556Srgrimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251556Srgrimes# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261556Srgrimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271556Srgrimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281556Srgrimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291556Srgrimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301556Srgrimes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311556Srgrimes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321556Srgrimes# SUCH DAMAGE.
331556Srgrimes#
3417987Speter#	@(#)mkbuiltins	8.2 (Berkeley) 5/4/95
3550471Speter# $FreeBSD$
361556Srgrimes
3769029Skristemp=`/usr/bin/mktemp -t ka`
381556Srgrimeshavejobs=0
39120023Sschweikhif grep '^#define[	 ]*JOBS[	 ]*1' shell.h > /dev/null
401556Srgrimesthen	havejobs=1
411556Srgrimesfi
4217987Speterhavehist=1
4317987Speterif [ "X$1" = "X-h" ]; then
4417987Speter	havehist=0
4517987Speter	shift
467502Sphkfi
4717987Speterobjdir=$1
4817987Speterexec > ${objdir}/builtins.c
491556Srgrimescat <<\!
501556Srgrimes/*
511556Srgrimes * This file was generated by the mkbuiltins program.
521556Srgrimes */
531556Srgrimes
5490832Simp#include <stdlib.h>
551556Srgrimes#include "shell.h"
561556Srgrimes#include "builtins.h"
571556Srgrimes
581556Srgrimes!
5917987Speterawk '/^[^#]/ {if(('$havejobs' || $2 != "-j") && ('$havehist' || $2 != "-h")) \
60105389Stjr    print $0}' builtins.def | sed 's/-[hj]//' > $temp
61223060Sjillesecho 'int (*const builtinfunc[])(int, char **) = {'
621556Srgrimesawk '/^[^#]/ {	printf "\t%s,\n", $1}' $temp
631556Srgrimesecho '};
641556Srgrimes
651556Srgrimesconst struct builtincmd builtincmd[] = {'
661556Srgrimesawk '{	for (i = 2 ; i <= NF ; i++) {
67157413Sstefanf		if ($i == "-s") {
68157413Sstefanf			spc = 1;
69157413Sstefanf		} else {
70157413Sstefanf			printf "\t{ \"%s\", %d, %d },\n",  $i, NR-1, spc
71157413Sstefanf			spc = 0;
72157413Sstefanf		}
731556Srgrimes	}}' $temp
74157413Sstefanfecho '	{ NULL, 0, 0 }
751556Srgrimes};'
761556Srgrimes
7717987Speterexec > ${objdir}/builtins.h
781556Srgrimescat <<\!
791556Srgrimes/*
801556Srgrimes * This file was generated by the mkbuiltins program.
811556Srgrimes */
821556Srgrimes
831556Srgrimes#include <sys/cdefs.h>
841556Srgrimes!
851556Srgrimestr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ < $temp |
861556Srgrimes	awk '{	printf "#define %s %d\n", $1, NR-1}'
871556Srgrimesecho '
881556Srgrimesstruct builtincmd {
89201053Sjilles      const char *name;
901556Srgrimes      int code;
91157413Sstefanf      int special;
921556Srgrimes};
931556Srgrimes
94149015Sstefanfextern int (*const builtinfunc[])(int, char **);
95223060Sjillesextern const struct builtincmd builtincmd[];
96223060Sjilles'
97223060Sjillesawk '{	printf "int %s(int, char **);\n", $1}' $temp
981556Srgrimesrm -f $temp
99