unstack, sort: cleanup and improvement
[minix.git] / commands / ash / mkbuiltins
blob73109ad70c0bbaf67fcc919eadb3418601b3e484
1 #!/bin/sh -
3 # Copyright (c) 1991, 1993
4 # The Regents of the University of California. All rights reserved.
6 # This code is derived from software contributed to Berkeley by
7 # Kenneth Almquist.
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
17 # 4. Neither the name of the University nor the names of its contributors
18 # may be used to endorse or promote products derived from this software
19 # without specific prior written permission.
21 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 # SUCH DAMAGE.
33 # @(#)mkbuiltins 8.2 (Berkeley) 5/4/95
34 # $FreeBSD: src/bin/sh/mkbuiltins,v 1.13 2004/04/06 20:06:51 markm Exp $
36 #temp=`/usr/bin/mktemp -t ka`
37 temp=/tmp/mkb$$
38 havehist=1
39 if [ "X$1" = "X-h" ]; then
40 havehist=0
41 shift
43 havejobs=0
44 if [ "X$1" = "X-j" ]; then
45 havejobs=0
46 shift
47 elif grep '^#define[ ]*JOBS[ ]*1' $2 > /dev/null
48 then havejobs=1
50 objdir=$1
51 exec > ${objdir}/builtins.c
52 cat <<\!
54 * This file was generated by the mkbuiltins program.
57 #include <stdlib.h>
58 #include "shell.h"
59 #include "builtins.h"
62 awk '/^[^#]/ {if(('$havejobs' || $2 != "-j") && ('$havehist' || $2 != "-h")) \
63 print $0}' $3 | sed 's/-[hj]//' > $temp
64 #awk '{ printf "int %s();\n", $1}' $temp
65 echo '
66 int (*const builtinfunc[]) (int, char **) = {'
67 awk '/^[^#]/ { printf "\t%s,\n", $1}' $temp
68 echo '};
70 const struct builtincmd builtincmd[] = {'
71 awk '{ for (i = 2 ; i <= NF ; i++) {
72 printf "\t{ \"%s\", %d },\n", $i, NR-1
73 }}' $temp
74 echo ' { NULL, 0 }
75 };'
77 exec > ${objdir}/builtins.h
78 cat <<\!
80 * This file was generated by the mkbuiltins program.
84 tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ < $temp |
85 awk '{ printf "#define %s %d\n", $1, NR-1}'
86 echo '
87 struct builtincmd {
88 char *name;
89 int code;
92 extern int (*const builtinfunc[]) (int, char **);
93 extern const struct builtincmd builtincmd[];'
94 awk '{ printf "int %s (int, char **);\n", $1 }' < $temp
95 rm -f $temp
98 # $PchId: mkbuiltins,v 1.6 2006/05/22 12:42:58 philip Exp $