11.1Scgd#!/bin/sh -
21.22Sapb#	$NetBSD: mkbuiltins,v 1.22 2009/10/06 19:56:58 apb Exp $
31.1Scgd#
41.6Sjtc# Copyright (c) 1991, 1993
51.6Sjtc#	The Regents of the University of California.  All rights reserved.
61.1Scgd#
71.1Scgd# This code is derived from software contributed to Berkeley by
81.1Scgd# Kenneth Almquist.
91.1Scgd#
101.1Scgd# Redistribution and use in source and binary forms, with or without
111.1Scgd# modification, are permitted provided that the following conditions
121.1Scgd# are met:
131.1Scgd# 1. Redistributions of source code must retain the above copyright
141.1Scgd#    notice, this list of conditions and the following disclaimer.
151.1Scgd# 2. Redistributions in binary form must reproduce the above copyright
161.1Scgd#    notice, this list of conditions and the following disclaimer in the
171.1Scgd#    documentation and/or other materials provided with the distribution.
181.20Sagc# 3. Neither the name of the University nor the names of its contributors
191.1Scgd#    may be used to endorse or promote products derived from this software
201.1Scgd#    without specific prior written permission.
211.1Scgd#
221.1Scgd# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231.1Scgd# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241.1Scgd# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251.1Scgd# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261.1Scgd# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271.1Scgd# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281.1Scgd# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291.1Scgd# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301.1Scgd# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311.1Scgd# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321.1Scgd# SUCH DAMAGE.
331.1Scgd#
341.12Schristos#	@(#)mkbuiltins	8.2 (Berkeley) 5/4/95
351.1Scgd
361.7Scgdhavehist=1
371.22Sapbif [ x"$1" = x"-h" ]; then
381.7Scgd	havehist=0
391.7Scgd	shift
401.7Scgdfi
411.17Schristos
421.14Schristosshell=$1
431.14Schristosbuiltins=$2
441.14Schristosobjdir=$3
451.14Schristos
461.14Schristoshavejobs=0
471.14Schristosif grep '^#define JOBS[	 ]*1' ${shell} > /dev/null
481.14Schristosthen
491.14Schristos	havejobs=1
501.14Schristosfi
511.14Schristos
521.17Schristosexec <$builtins 3> ${objdir}/builtins.c 4> ${objdir}/builtins.h
531.17Schristos
541.19Sdslecho '/*
551.1Scgd * This file was generated by the mkbuiltins program.
561.1Scgd */
571.1Scgd
581.1Scgd#include "shell.h"
591.1Scgd#include "builtins.h"
601.1Scgd
611.17Schristosconst struct builtincmd builtincmd[] = {
621.19Sdsl' >&3
631.1Scgd
641.19Sdslecho '/*
651.1Scgd * This file was generated by the mkbuiltins program.
661.1Scgd */
671.1Scgd
681.1Scgd#include <sys/cdefs.h>
691.17Schristos
701.1Scgdstruct builtincmd {
711.15Schristos      const char *name;
721.17Schristos      int (*builtin)(int, char **);
731.1Scgd};
741.1Scgd
751.17Schristosextern const struct builtincmd builtincmd[];
761.17Schristosextern const struct builtincmd splbltincmd[];
771.17Schristos
781.19Sdsl' >&4
791.17Schristos
801.17Schristosspecials=
811.17Schristos
821.17Schristoswhile read line
831.17Schristosdo
841.17Schristos	set -- $line
851.17Schristos	[ -z "$1" ] && continue
861.21Schristos	case "$1" in
871.21Schristos	\#if*|\#def*|\#end*)
881.21Schristos		echo $line >&3
891.21Schristos		echo $line >&4
901.21Schristos		continue
911.21Schristos		;;
921.22Sapb	\#*)
931.22Sapb		continue
941.22Sapb		;;
951.21Schristos	esac
961.21Schristos
971.17Schristos	func=$1
981.17Schristos	shift
991.17Schristos	[ x"$1" = x'-j' ] && {
1001.17Schristos		[ $havejobs = 0 ] && continue
1011.17Schristos		shift
1021.17Schristos	}
1031.17Schristos	[ x"$1" = x'-h' ] && {
1041.17Schristos		[ $havehist = 0 ] && continue
1051.17Schristos		shift
1061.17Schristos	}
1071.17Schristos	echo 'int '"$func"'(int, char **);' >&4
1081.17Schristos	while
1091.22Sapb		[ $# != 0 ] && [ x"$1" != x'#' ]
1101.17Schristos	do
1111.22Sapb		[ x"$1" = x'-s' ] && {
1121.17Schristos			specials="$specials $2 $func"
1131.17Schristos			shift 2
1141.17Schristos			continue;
1151.17Schristos		}
1161.22Sapb		[ x"$1" = x'-u' ] && shift
1171.17Schristos		echo '	{ "'$1'",	'"$func"' },' >&3
1181.17Schristos		shift
1191.17Schristos	done
1201.17Schristosdone
1211.17Schristos
1221.17Schristosecho '	{ 0, 0 },' >&3
1231.17Schristosecho '};' >&3
1241.17Schristosecho >&3
1251.17Schristosecho 'const struct builtincmd splbltincmd[] = {' >&3
1261.17Schristos
1271.17Schristosset -- $specials
1281.17Schristoswhile
1291.17Schristos	[ $# != 0 ]
1301.17Schristosdo
1311.17Schristos	echo '	{ "'$1'",	'"$2"' },' >&3
1321.17Schristos	shift 2
1331.17Schristosdone
1341.17Schristos
1351.17Schristosecho '	{ 0, 0 },' >&3
1361.17Schristosecho "};" >&3
137