makelist revision 1.4
11.1Scgd#!/bin/sh -
21.4Ssimonb#	$NetBSD: makelist,v 1.4 1999/07/02 15:21:26 simonb Exp $
31.1Scgd#
41.1Scgd# Copyright (c) 1992, 1993
51.1Scgd#	The Regents of the University of California.  All rights reserved.
61.1Scgd#
71.1Scgd# This code is derived from software contributed to Berkeley by
81.1Scgd# Christos Zoulas of Cornell University.
91.1Scgd#
101.1Scgd# Redistribution and use in source and binary forms, with or without
111.1Scgd# modification, are permitted provided that the following conditions
121.1Scgd# are met:
131.1Scgd# 1. Redistributions of source code must retain the above copyright
141.1Scgd#    notice, this list of conditions and the following disclaimer.
151.1Scgd# 2. Redistributions in binary form must reproduce the above copyright
161.1Scgd#    notice, this list of conditions and the following disclaimer in the
171.1Scgd#    documentation and/or other materials provided with the distribution.
181.1Scgd# 3. All advertising materials mentioning features or use of this software
191.1Scgd#    must display the following acknowledgement:
201.1Scgd#	This product includes software developed by the University of
211.1Scgd#	California, Berkeley and its contributors.
221.1Scgd# 4. Neither the name of the University nor the names of its contributors
231.1Scgd#    may be used to endorse or promote products derived from this software
241.1Scgd#    without specific prior written permission.
251.1Scgd#
261.1Scgd# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
271.1Scgd# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281.1Scgd# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
291.1Scgd# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
301.1Scgd# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
311.1Scgd# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
321.1Scgd# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
331.1Scgd# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
341.1Scgd# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
351.1Scgd# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
361.1Scgd# SUCH DAMAGE.
371.1Scgd#
381.1Scgd#	@(#)makelist	5.3 (Berkeley) 6/4/93
391.1Scgd
401.1Scgd# makelist.sh: Automatically generate header files...
411.1Scgd
421.1ScgdAWK=/usr/bin/awk
431.4SsimonbUSAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh <filenames>"
441.1Scgd
451.1Scgdif [ "x$1" = "x" ]
461.1Scgdthen
471.1Scgd    echo $USAGE 1>&2
481.1Scgd    exit 1
491.1Scgdfi
501.1Scgd
511.1ScgdFLAG="$1"
521.1Scgdshift
531.1Scgd
541.1ScgdFILES="$@"
551.1Scgd
561.1Scgdcase $FLAG in
571.1Scgd-h)
581.2Scgd    set - `echo $FILES | sed -e 's/\\./_/g'`
591.2Scgd    hdr="_h_`basename $1`"
601.1Scgd    cat $FILES | $AWK '
611.1Scgd	BEGIN {
621.1Scgd	    printf("/* Automatically generated file, do not edit */\n");
631.1Scgd	    printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'");
641.1Scgd	}
651.1Scgd	/\(\):/ {
661.1Scgd	    pr = substr($2, 1, 2);
671.1Scgd	    if (pr == "vi" || pr == "em" || pr == "ed") {
681.1Scgd		name = substr($2, 1, length($2) - 3);
691.1Scgd		printf("protected el_action_t\t%-25.25s __P((EditLine *, int));\n", name);
701.1Scgd	    }
711.1Scgd	}
721.1Scgd	END {
731.1Scgd	    printf("#endif /* %s */\n", "'$hdr'");
741.1Scgd	}';;
751.1Scgd-bc)
761.1Scgd    cat $FILES | $AWK '
771.1Scgd	BEGIN {
781.1Scgd	    printf("/* Automatically generated file, do not edit */\n");
791.1Scgd	    printf("#include \"sys.h\"\n#include \"el.h\"\n");
801.1Scgd	    printf("private struct el_bindings_t el_func_help[] = {\n");
811.1Scgd	    low = "abcdefghijklmnopqrstuvwxyz_";
821.1Scgd	    high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
831.1Scgd	    for (i = 1; i <= length(low); i++)
841.1Scgd		tr[substr(low, i, 1)] = substr(high, i, 1);
851.1Scgd	}
861.1Scgd	/\(\):/ {
871.1Scgd	    pr = substr($2, 1, 2);
881.1Scgd	    if (pr == "vi" || pr == "em" || pr == "ed") {
891.1Scgd		name = substr($2, 1, length($2) - 3);
901.1Scgd		uname = "";
911.1Scgd		fname = "";
921.1Scgd		for (i = 1; i <= length(name); i++) {
931.1Scgd		    s = substr(name, i, 1);
941.1Scgd		    uname = uname tr[s];
951.1Scgd		    if (s == "_")
961.1Scgd			s = "-";
971.1Scgd		    fname = fname s;
981.1Scgd		}
991.4Ssimonb
1001.1Scgd		printf("    { %-30.30s %-30.30s\n","\"" fname "\",", uname ",");
1011.4Ssimonb		ok = 1;
1021.1Scgd	    }
1031.1Scgd	}
1041.1Scgd	/^ \*/ {
1051.1Scgd	    if (ok) {
1061.1Scgd		printf("      \"");
1071.1Scgd		for (i = 2; i < NF; i++)
1081.1Scgd		    printf("%s ", $i);
1091.1Scgd		printf("%s\" },\n", $i);
1101.1Scgd		ok = 0;
1111.1Scgd	    }
1121.1Scgd	}
1131.1Scgd	END {
1141.1Scgd	    printf("    { NULL, 0, NULL }\n");
1151.1Scgd	    printf("};\n");
1161.1Scgd	    printf("\nprotected el_bindings_t* help__get()");
1171.1Scgd	    printf("{ return el_func_help; }\n");
1181.1Scgd	}';;
1191.1Scgd-bh)
1201.1Scgd    $AWK '
1211.4Ssimonb	BEGIN {
1221.1Scgd	    printf("/* Automatically generated file, do not edit */\n");
1231.1Scgd	    printf("#ifndef _h_help_c\n#define _h_help_c\n");
1241.1Scgd	    printf("protected el_bindings_t *help__get\t__P((void));\n");
1251.1Scgd	    printf("#endif /* _h_help_c */\n");
1261.1Scgd	}' /dev/null;;
1271.1Scgd-fh)
1281.1Scgd    cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
1291.1Scgd    sort | tr '[a-z]' '[A-Z]' | $AWK '
1301.4Ssimonb	BEGIN {
1311.1Scgd	    printf("/* Automatically generated file, do not edit */\n");
1321.1Scgd	    printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n");
1331.4Ssimonb	    count = 0;
1341.1Scgd	}
1351.4Ssimonb	{
1361.1Scgd	    printf("#define\t%-30.30s\t%3d\n", $1, count++);
1371.1Scgd	}
1381.1Scgd	END {
1391.1Scgd	    printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
1401.1Scgd
1411.1Scgd	    printf("typedef el_action_t (*el_func_t) __P((EditLine *, int));");
1421.1Scgd	    printf("\nprotected el_func_t* func__get __P((void));\n");
1431.1Scgd	    printf("#endif /* _h_fcns_c */\n");
1441.1Scgd	}';;
1451.1Scgd-fc)
1461.1Scgd    cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
1471.1Scgd	BEGIN {
1481.1Scgd	    printf("/* Automatically generated file, do not edit */\n");
1491.1Scgd	    printf("#include \"sys.h\"\n#include \"el.h\"\n");
1501.1Scgd	    printf("private el_func_t el_func[] = {");
1511.1Scgd	    maxlen = 80;
1521.1Scgd	    needn = 1;
1531.1Scgd	    len = 0;
1541.1Scgd	}
1551.1Scgd	{
1561.1Scgd	    clen = 25 + 2;
1571.1Scgd	    len += clen;
1581.4Ssimonb	    if (len >= maxlen)
1591.1Scgd		needn = 1;
1601.1Scgd	    if (needn) {
1611.1Scgd		printf("\n    ");
1621.1Scgd		needn = 0;
1631.1Scgd		len = 4 + clen;
1641.1Scgd	    }
1651.1Scgd	    s = $1 ",";
1661.1Scgd	    printf("%-26.26s ", s);
1671.1Scgd	}
1681.1Scgd	END {
1691.1Scgd	    printf("\n};\n");
1701.1Scgd	    printf("\nprotected el_func_t* func__get() { return el_func; }\n");
1711.1Scgd	}';;
1721.1Scgd-e)
1731.1Scgd	echo "$FILES" | tr ' ' '\012' | $AWK '
1741.1Scgd	BEGIN {
1751.1Scgd	    printf("/* Automatically generated file, do not edit */\n");
1761.1Scgd	    printf("#define protected static\n");
1771.1Scgd	    printf("#define SCCSID\n");
1781.1Scgd	}
1791.1Scgd	{
1801.1Scgd	    printf("#include \"%s\"\n", $1);
1811.1Scgd	}';;
1821.1Scgd*)
1831.1Scgd    echo $USAGE 1>&2
1841.1Scgd    exit 1;;
1851.1Scgdesac
186