xref: /freebsd/bin/sh/mkbuiltins (revision 90aea514c6249118e880d75972d063362f4bf492)
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.
18fbbd9655SWarner Losh# 3. 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
34fb1df203SAlex Richardsontemp=`mktemp -t ka`
35937b0a99SMarcel Moolenaarsrcdir=$1
36937b0a99SMarcel Moolenaarhavejobs=0
37937b0a99SMarcel Moolenaarif grep '^#define[	 ]*JOBS[	 ]*1' $srcdir/shell.h > /dev/null
38937b0a99SMarcel Moolenaarthen	havejobs=1
39937b0a99SMarcel Moolenaarfi
40937b0a99SMarcel Moolenaarexec > builtins.c
414b88c807SRodney W. Grimescat <<\!
424b88c807SRodney W. Grimes/*
434b88c807SRodney W. Grimes * This file was generated by the mkbuiltins program.
444b88c807SRodney W. Grimes */
454b88c807SRodney W. Grimes
461a243918SWarner Losh#include <stdlib.h>
474b88c807SRodney W. Grimes#include "shell.h"
484b88c807SRodney W. Grimes#include "builtins.h"
494b88c807SRodney W. Grimes
504b88c807SRodney W. Grimes!
51*da06ef25SJilles Tjoelkerawk '/^[^#]/ {if('$havejobs' || $2 != "-j") \
52*da06ef25SJilles Tjoelker    print $0}' $srcdir/builtins.def | sed 's/-j//' > $temp
53454a02b3SJilles Tjoelkerecho 'int (*const builtinfunc[])(int, char **) = {'
544b88c807SRodney W. Grimesawk '/^[^#]/ {	printf "\t%s,\n", $1}' $temp
554b88c807SRodney W. Grimesecho '};
564b88c807SRodney W. Grimes
57d3fa2c78SJilles Tjoelkerconst unsigned char builtincmd[] = {'
584b88c807SRodney W. Grimesawk '{	for (i = 2 ; i <= NF ; i++) {
59905330abSStefan Farfeleder		if ($i == "-s") {
60905330abSStefan Farfeleder			spc = 1;
613ecb77f0SBryan Drewery		} else if ($i == "-n") {
623ecb77f0SBryan Drewery			# Handled later for builtins.h
633ecb77f0SBryan Drewery			continue
64905330abSStefan Farfeleder		} else {
65d3fa2c78SJilles Tjoelker			printf "\t\"\\%03o\\%03o%s\"\n", length($i), (spc ? 128 : 0) + NR-1, $i
66905330abSStefan Farfeleder			spc = 0;
67905330abSStefan Farfeleder		}
684b88c807SRodney W. Grimes	}}' $temp
69d3fa2c78SJilles Tjoelkerecho '};'
704b88c807SRodney W. Grimes
71937b0a99SMarcel Moolenaarexec > builtins.h
724b88c807SRodney W. Grimescat <<\!
734b88c807SRodney W. Grimes/*
744b88c807SRodney W. Grimes * This file was generated by the mkbuiltins program.
754b88c807SRodney W. Grimes */
764b88c807SRodney W. Grimes
774b88c807SRodney W. Grimes#include <sys/cdefs.h>
784b88c807SRodney W. Grimes!
794b88c807SRodney W. Grimestr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ < $temp |
804b88c807SRodney W. Grimes	awk '{	printf "#define %s %d\n", $1, NR-1}'
814b88c807SRodney W. Grimesecho '
82d3fa2c78SJilles Tjoelker#define BUILTIN_SPECIAL 0x80
834b88c807SRodney W. Grimes
84bfce4fe8SStefan Farfelederextern int (*const builtinfunc[])(int, char **);
85d3fa2c78SJilles Tjoelkerextern const unsigned char builtincmd[];
86454a02b3SJilles Tjoelker'
87454a02b3SJilles Tjoelkerawk '{	printf "int %s(int, char **);\n", $1}' $temp
883ecb77f0SBryan Drewery
893ecb77f0SBryan Drewery# Build safe_builtin_always()
903ecb77f0SBryan Drewerycat <<EOF
913ecb77f0SBryan Drewery
923ecb77f0SBryan Drewerystatic inline int
933ecb77f0SBryan Drewerysafe_builtin_always(int idx)
943ecb77f0SBryan Drewery{
953ecb77f0SBryan DreweryEOF
963ecb77f0SBryan Dreweryawk '
973ecb77f0SBryan DreweryBEGIN { printed = 0 }
983ecb77f0SBryan Drewery{
993ecb77f0SBryan Drewery	for (i = 2 ; i <= NF ; i++) {
1003ecb77f0SBryan Drewery		if ($i == "-s") {
1013ecb77f0SBryan Drewery			continue
1023ecb77f0SBryan Drewery		} else if ($i == "-n") {
1033ecb77f0SBryan Drewery			nofork = 1;
1043ecb77f0SBryan Drewery		} else {
1053ecb77f0SBryan Drewery			if (nofork == 0) {
1063ecb77f0SBryan Drewery				continue
1073ecb77f0SBryan Drewery			}
1083ecb77f0SBryan Drewery			if (printed == 1) {
1093ecb77f0SBryan Drewery				printf " || \n\t    "
1103ecb77f0SBryan Drewery			} else {
1113ecb77f0SBryan Drewery				printf "\tif ("
1123ecb77f0SBryan Drewery			}
1133ecb77f0SBryan Drewery			printf "idx == " toupper($1)
1143ecb77f0SBryan Drewery			printed = 1
1153ecb77f0SBryan Drewery			nofork = 0;
1163ecb77f0SBryan Drewery			# Only need to check each once
1173ecb77f0SBryan Drewery			break
1183ecb77f0SBryan Drewery		}
1193ecb77f0SBryan Drewery	}
1203ecb77f0SBryan Drewery}' $temp
1213ecb77f0SBryan Drewery
1223ecb77f0SBryan Drewerycat << EOF
1233ecb77f0SBryan Drewery)
1243ecb77f0SBryan Drewery		return (1);
1253ecb77f0SBryan Drewery	return(0);
1263ecb77f0SBryan Drewery}
1273ecb77f0SBryan DreweryEOF
1283ecb77f0SBryan Drewery
1294b88c807SRodney W. Grimesrm -f $temp
130