xref: /csrg-svn/bin/sh/mkbuiltins (revision 47166)
147104Sbostic#!/bin/sh -
247104Sbostic#
347104Sbostic# Copyright (c) 1991 The Regents of the University of California.
447104Sbostic# All rights reserved.
547104Sbostic#
647104Sbostic# This code is derived from software contributed to Berkeley by
747104Sbostic# Kenneth Almquist.
847104Sbostic#
947104Sbostic# %sccs.include.redist.sh%
1047104Sbostic#
11*47166Sbostic#	@(#)mkbuiltins	5.2 (Berkeley) 03/08/91
1247104Sbostic
1347104Sbostictemp=/tmp/ka$$
1447104Sbostichavejobs=0
1547104Sbosticif grep '^#define JOBS[	 ]*1' shell.h > /dev/null
1647104Sbosticthen	havejobs=1
1747104Sbosticfi
1847104Sbosticexec > obj/builtins.c
1947104Sbosticcat <<\!
2047104Sbostic/*
2147104Sbostic * This file was generated by the mkbuiltins program.
2247104Sbostic */
2347104Sbostic
2447104Sbostic#include "shell.h"
2547104Sbostic#include "builtins.h"
2647104Sbostic
2747104Sbostic!
2847104Sbosticawk '/^[^#]/ {if('$havejobs' || $2 != "-j") print $0}' builtins |
2947104Sbostic	sed 's/-j//' > $temp
3047104Sbosticawk '{	printf "int %s();\n", $1}' $temp
3147104Sbosticecho '
3247104Sbosticint (*const builtinfunc[])() = {'
3347104Sbosticawk '/^[^#]/ {	printf "\t%s,\n", $1}' $temp
3447104Sbosticecho '};
3547104Sbostic
3647104Sbosticconst struct builtincmd builtincmd[] = {'
3747104Sbosticawk '{	for (i = 2 ; i <= NF ; i++) {
3847104Sbostic		printf "\t\"%s\", %d,\n",  $i, NR-1
3947104Sbostic	}}' $temp
4047104Sbosticecho '	NULL, 0
4147104Sbostic};'
4247104Sbostic
4347104Sbosticexec > obj/builtins.h
4447104Sbosticcat <<\!
4547104Sbostic/*
4647104Sbostic * This file was generated by the mkbuiltins program.
4747104Sbostic */
4847104Sbostic
49*47166Sbostic#include <sys/cdefs.h>
5047104Sbostic!
5147104Sbostictr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ < $temp |
5247104Sbostic	awk '{	printf "#define %s %d\n", $1, NR-1}'
5347104Sbosticecho '
5447104Sbosticstruct builtincmd {
5547104Sbostic      char *name;
5647104Sbostic      int code;
5747104Sbostic};
5847104Sbostic
5947104Sbosticextern int (*const builtinfunc[])();
6047104Sbosticextern const struct builtincmd builtincmd[];'
6147104Sbosticrm -f $temp
62