# Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
# This file is part of ash, which is distributed under the terms specified
# by the Ash General Public License.  See the file named LICENSE.

temp=/tmp/ka$$
havejobs=0
if grep '^#define JOBS[	 ]*1' shell.h > /dev/null
then	havejobs=1
fi
exec > builtins.c
cat <<\!
/*
 * This file was generated by the mkbuiltins program.
 */

#include "shell.h"
#include "builtins.h"

!
awk '/^[^#]/ {if('$havejobs' || $2 != "-j") print $0}' builtins |
	sed 's/-j//' > $temp
awk '{	printf "int %s();\n", $1}' $temp
echo '
int (*const builtinfunc[])() = {'
awk '/^[^#]/ {	printf "\t%s,\n", $1}' $temp
echo '};

const struct builtincmd builtincmd[] = {'
awk '{	for (i = 2 ; i <= NF ; i++) {
		printf "\t\"%s\", %d,\n",  $i, NR-1
	}}' $temp
echo '	NULL, 0
};'

exec > builtins.h
cat <<\!
/*
 * This file was generated by the mkbuiltins program.
 */

!
tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ < $temp |
	awk '{	printf "#define %s %d\n", $1, NR-1}'
echo '
struct builtincmd {
      char *name;
      int code;
};

extern int (*const builtinfunc[])();
extern const struct builtincmd builtincmd[];'
rm -f $temp
