xref: /netbsd-src/bin/sh/mkbuiltins (revision db8f79df3de3b6bd14f20008d75a23677b5d7b5f)
161f28255Scgd#!/bin/sh -
2*db8f79dfSapb#	$NetBSD: mkbuiltins,v 1.22 2009/10/06 19:56:58 apb Exp $
361f28255Scgd#
437ed7877Sjtc# Copyright (c) 1991, 1993
537ed7877Sjtc#	The Regents of the University of California.  All rights reserved.
661f28255Scgd#
761f28255Scgd# This code is derived from software contributed to Berkeley by
861f28255Scgd# Kenneth Almquist.
961f28255Scgd#
1061f28255Scgd# Redistribution and use in source and binary forms, with or without
1161f28255Scgd# modification, are permitted provided that the following conditions
1261f28255Scgd# are met:
1361f28255Scgd# 1. Redistributions of source code must retain the above copyright
1461f28255Scgd#    notice, this list of conditions and the following disclaimer.
1561f28255Scgd# 2. Redistributions in binary form must reproduce the above copyright
1661f28255Scgd#    notice, this list of conditions and the following disclaimer in the
1761f28255Scgd#    documentation and/or other materials provided with the distribution.
183538d265Sagc# 3. Neither the name of the University nor the names of its contributors
1961f28255Scgd#    may be used to endorse or promote products derived from this software
2061f28255Scgd#    without specific prior written permission.
2161f28255Scgd#
2261f28255Scgd# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2361f28255Scgd# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2461f28255Scgd# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2561f28255Scgd# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2661f28255Scgd# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2761f28255Scgd# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2861f28255Scgd# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2961f28255Scgd# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3061f28255Scgd# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3161f28255Scgd# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3261f28255Scgd# SUCH DAMAGE.
3361f28255Scgd#
3407bae7edSchristos#	@(#)mkbuiltins	8.2 (Berkeley) 5/4/95
3561f28255Scgd
36e3c63ad9Scgdhavehist=1
37*db8f79dfSapbif [ x"$1" = x"-h" ]; then
38e3c63ad9Scgd	havehist=0
39e3c63ad9Scgd	shift
40e3c63ad9Scgdfi
41c02b3bbdSchristos
420328c414Schristosshell=$1
430328c414Schristosbuiltins=$2
440328c414Schristosobjdir=$3
450328c414Schristos
460328c414Schristoshavejobs=0
470328c414Schristosif grep '^#define JOBS[	 ]*1' ${shell} > /dev/null
480328c414Schristosthen
490328c414Schristos	havejobs=1
500328c414Schristosfi
510328c414Schristos
52c02b3bbdSchristosexec <$builtins 3> ${objdir}/builtins.c 4> ${objdir}/builtins.h
53c02b3bbdSchristos
546285ef06Sdslecho '/*
5561f28255Scgd * This file was generated by the mkbuiltins program.
5661f28255Scgd */
5761f28255Scgd
5861f28255Scgd#include "shell.h"
5961f28255Scgd#include "builtins.h"
6061f28255Scgd
61c02b3bbdSchristosconst struct builtincmd builtincmd[] = {
626285ef06Sdsl' >&3
6361f28255Scgd
646285ef06Sdslecho '/*
6561f28255Scgd * This file was generated by the mkbuiltins program.
6661f28255Scgd */
6761f28255Scgd
6861f28255Scgd#include <sys/cdefs.h>
69c02b3bbdSchristos
7061f28255Scgdstruct builtincmd {
713d424690Schristos      const char *name;
72c02b3bbdSchristos      int (*builtin)(int, char **);
7361f28255Scgd};
7461f28255Scgd
75c02b3bbdSchristosextern const struct builtincmd builtincmd[];
76c02b3bbdSchristosextern const struct builtincmd splbltincmd[];
77c02b3bbdSchristos
786285ef06Sdsl' >&4
79c02b3bbdSchristos
80c02b3bbdSchristosspecials=
81c02b3bbdSchristos
82c02b3bbdSchristoswhile read line
83c02b3bbdSchristosdo
84c02b3bbdSchristos	set -- $line
85c02b3bbdSchristos	[ -z "$1" ] && continue
8695a73796Schristos	case "$1" in
8795a73796Schristos	\#if*|\#def*|\#end*)
8895a73796Schristos		echo $line >&3
8995a73796Schristos		echo $line >&4
9095a73796Schristos		continue
9195a73796Schristos		;;
92*db8f79dfSapb	\#*)
93*db8f79dfSapb		continue
94*db8f79dfSapb		;;
9595a73796Schristos	esac
9695a73796Schristos
97c02b3bbdSchristos	func=$1
98c02b3bbdSchristos	shift
99c02b3bbdSchristos	[ x"$1" = x'-j' ] && {
100c02b3bbdSchristos		[ $havejobs = 0 ] && continue
101c02b3bbdSchristos		shift
102c02b3bbdSchristos	}
103c02b3bbdSchristos	[ x"$1" = x'-h' ] && {
104c02b3bbdSchristos		[ $havehist = 0 ] && continue
105c02b3bbdSchristos		shift
106c02b3bbdSchristos	}
107c02b3bbdSchristos	echo 'int '"$func"'(int, char **);' >&4
108c02b3bbdSchristos	while
109*db8f79dfSapb		[ $# != 0 ] && [ x"$1" != x'#' ]
110c02b3bbdSchristos	do
111*db8f79dfSapb		[ x"$1" = x'-s' ] && {
112c02b3bbdSchristos			specials="$specials $2 $func"
113c02b3bbdSchristos			shift 2
114c02b3bbdSchristos			continue;
115c02b3bbdSchristos		}
116*db8f79dfSapb		[ x"$1" = x'-u' ] && shift
117c02b3bbdSchristos		echo '	{ "'$1'",	'"$func"' },' >&3
118c02b3bbdSchristos		shift
119c02b3bbdSchristos	done
120c02b3bbdSchristosdone
121c02b3bbdSchristos
122c02b3bbdSchristosecho '	{ 0, 0 },' >&3
123c02b3bbdSchristosecho '};' >&3
124c02b3bbdSchristosecho >&3
125c02b3bbdSchristosecho 'const struct builtincmd splbltincmd[] = {' >&3
126c02b3bbdSchristos
127c02b3bbdSchristosset -- $specials
128c02b3bbdSchristoswhile
129c02b3bbdSchristos	[ $# != 0 ]
130c02b3bbdSchristosdo
131c02b3bbdSchristos	echo '	{ "'$1'",	'"$2"' },' >&3
132c02b3bbdSchristos	shift 2
133c02b3bbdSchristosdone
134c02b3bbdSchristos
135c02b3bbdSchristosecho '	{ 0, 0 },' >&3
136c02b3bbdSchristosecho "};" >&3
137