xref: /freebsd/bin/sh/mkbuiltins (revision 9ddb49cbe45441fa3f3a10f6dd355e9956480b5f)
14b88c807SRodney W. Grimes#!/bin/sh -
29ddb49cbSWarner Losh
39ddb49cbSWarner Losh#-
44b88c807SRodney W. Grimes# Copyright (c) 1991, 1993
54b88c807SRodney W. Grimes#	The Regents of the University of California.  All rights reserved.
64b88c807SRodney W. Grimes#
74b88c807SRodney W. Grimes# This code is derived from software contributed to Berkeley by
84b88c807SRodney W. Grimes# Kenneth Almquist.
94b88c807SRodney W. Grimes#
104b88c807SRodney W. Grimes# Redistribution and use in source and binary forms, with or without
114b88c807SRodney W. Grimes# modification, are permitted provided that the following conditions
124b88c807SRodney W. Grimes# are met:
134b88c807SRodney W. Grimes# 1. Redistributions of source code must retain the above copyright
144b88c807SRodney W. Grimes#    notice, this list of conditions and the following disclaimer.
154b88c807SRodney W. Grimes# 2. Redistributions in binary form must reproduce the above copyright
164b88c807SRodney W. Grimes#    notice, this list of conditions and the following disclaimer in the
174b88c807SRodney W. Grimes#    documentation and/or other materials provided with the distribution.
184b88c807SRodney W. Grimes# 4. Neither the name of the University nor the names of its contributors
194b88c807SRodney W. Grimes#    may be used to endorse or promote products derived from this software
204b88c807SRodney W. Grimes#    without specific prior written permission.
214b88c807SRodney W. Grimes#
224b88c807SRodney W. Grimes# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
234b88c807SRodney W. Grimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
244b88c807SRodney W. Grimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
254b88c807SRodney W. Grimes# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
264b88c807SRodney W. Grimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
274b88c807SRodney W. Grimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
284b88c807SRodney W. Grimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
294b88c807SRodney W. Grimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
304b88c807SRodney W. Grimes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
314b88c807SRodney W. Grimes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
324b88c807SRodney W. Grimes# SUCH DAMAGE.
334b88c807SRodney W. Grimes#
34aa9caaf6SPeter Wemm#	@(#)mkbuiltins	8.2 (Berkeley) 5/4/95
352a456239SPeter Wemm# $FreeBSD$
364b88c807SRodney W. Grimes
37c8b46b3eSKris Kennawaytemp=`/usr/bin/mktemp -t ka`
384b88c807SRodney W. Grimeshavejobs=0
399e4656f7SJens Schweikhardtif grep '^#define[	 ]*JOBS[	 ]*1' shell.h > /dev/null
404b88c807SRodney W. Grimesthen	havejobs=1
414b88c807SRodney W. Grimesfi
42aa9caaf6SPeter Wemmhavehist=1
43aa9caaf6SPeter Wemmif [ "X$1" = "X-h" ]; then
44aa9caaf6SPeter Wemm	havehist=0
45aa9caaf6SPeter Wemm	shift
46295a3379SPoul-Henning Kampfi
47aa9caaf6SPeter Wemmobjdir=$1
48aa9caaf6SPeter Wemmexec > ${objdir}/builtins.c
494b88c807SRodney W. Grimescat <<\!
504b88c807SRodney W. Grimes/*
514b88c807SRodney W. Grimes * This file was generated by the mkbuiltins program.
524b88c807SRodney W. Grimes */
534b88c807SRodney W. Grimes
541a243918SWarner Losh#include <stdlib.h>
554b88c807SRodney W. Grimes#include "shell.h"
564b88c807SRodney W. Grimes#include "builtins.h"
574b88c807SRodney W. Grimes
584b88c807SRodney W. Grimes!
59aa9caaf6SPeter Wemmawk '/^[^#]/ {if(('$havejobs' || $2 != "-j") && ('$havehist' || $2 != "-h")) \
60728b72c2STim J. Robbins    print $0}' builtins.def | sed 's/-[hj]//' > $temp
614b88c807SRodney W. Grimesawk '{	printf "int %s();\n", $1}' $temp
624b88c807SRodney W. Grimesecho '
634b88c807SRodney W. Grimesint (*const builtinfunc[])() = {'
644b88c807SRodney W. Grimesawk '/^[^#]/ {	printf "\t%s,\n", $1}' $temp
654b88c807SRodney W. Grimesecho '};
664b88c807SRodney W. Grimes
674b88c807SRodney W. Grimesconst struct builtincmd builtincmd[] = {'
684b88c807SRodney W. Grimesawk '{	for (i = 2 ; i <= NF ; i++) {
69aa9caaf6SPeter Wemm		printf "\t{ \"%s\", %d },\n",  $i, NR-1
704b88c807SRodney W. Grimes	}}' $temp
71aa9caaf6SPeter Wemmecho '	{ NULL, 0 }
724b88c807SRodney W. Grimes};'
734b88c807SRodney W. Grimes
74aa9caaf6SPeter Wemmexec > ${objdir}/builtins.h
754b88c807SRodney W. Grimescat <<\!
764b88c807SRodney W. Grimes/*
774b88c807SRodney W. Grimes * This file was generated by the mkbuiltins program.
784b88c807SRodney W. Grimes */
794b88c807SRodney W. Grimes
804b88c807SRodney W. Grimes#include <sys/cdefs.h>
814b88c807SRodney W. Grimes!
824b88c807SRodney W. Grimestr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ < $temp |
834b88c807SRodney W. Grimes	awk '{	printf "#define %s %d\n", $1, NR-1}'
844b88c807SRodney W. Grimesecho '
854b88c807SRodney W. Grimesstruct builtincmd {
864b88c807SRodney W. Grimes      char *name;
874b88c807SRodney W. Grimes      int code;
884b88c807SRodney W. Grimes};
894b88c807SRodney W. Grimes
904b88c807SRodney W. Grimesextern int (*const builtinfunc[])();
914b88c807SRodney W. Grimesextern const struct builtincmd builtincmd[];'
924b88c807SRodney W. Grimesrm -f $temp
93