11.1Scgd#!/bin/sh -
21.29Schristos#	$NetBSD: makelist,v 1.29 2016/05/09 21:46:56 christos 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.9Slukem# 3. Neither the name of the University nor the names of its contributors
191.1Scgd#    may be used to endorse or promote products derived from this software
201.1Scgd#    without specific prior written permission.
211.1Scgd#
221.1Scgd# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231.1Scgd# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241.1Scgd# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251.1Scgd# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261.1Scgd# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271.1Scgd# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281.1Scgd# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291.1Scgd# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301.1Scgd# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311.1Scgd# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321.1Scgd# SUCH DAMAGE.
331.1Scgd#
341.1Scgd#	@(#)makelist	5.3 (Berkeley) 6/4/93
351.1Scgd
361.1Scgd# makelist.sh: Automatically generate header files...
371.1Scgd
381.8SchristosAWK=awk
391.28SchristosUSAGE="Usage: $0 -h|-fc|-fh|-bh <filenames>"
401.1Scgd
411.1Scgdif [ "x$1" = "x" ]
421.1Scgdthen
431.1Scgd    echo $USAGE 1>&2
441.1Scgd    exit 1
451.1Scgdfi
461.1Scgd
471.1ScgdFLAG="$1"
481.1Scgdshift
491.1Scgd
501.1ScgdFILES="$@"
511.1Scgd
521.1Scgdcase $FLAG in
531.5Slukem
541.1Scgd-h)
551.2Scgd    set - `echo $FILES | sed -e 's/\\./_/g'`
561.16Schristos    hdr="_h_`basename $1`"
571.1Scgd    cat $FILES | $AWK '
581.1Scgd	BEGIN {
591.1Scgd	    printf("/* Automatically generated file, do not edit */\n");
601.1Scgd	    printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'");
611.1Scgd	}
621.1Scgd	/\(\):/ {
631.1Scgd	    pr = substr($2, 1, 2);
641.1Scgd	    if (pr == "vi" || pr == "em" || pr == "ed") {
651.1Scgd		name = substr($2, 1, length($2) - 3);
661.6Slukem#
671.6Slukem# XXX:	need a space between name and prototype so that -fc and -fh
681.6Slukem#	parsing is much easier
691.6Slukem#
701.29Schristos		printf("libedit_private el_action_t\t%s (EditLine *, wint_t);\n",
711.19Schristos		    name);
721.1Scgd	    }
731.1Scgd	}
741.1Scgd	END {
751.1Scgd	    printf("#endif /* %s */\n", "'$hdr'");
761.5Slukem	}'
771.5Slukem	;;
781.5Slukem
791.28Schristos#	generate help.h from various .c files
801.5Slukem#
811.28Schristos-bh)
821.1Scgd    cat $FILES | $AWK '
831.1Scgd	BEGIN {
841.1Scgd	    printf("/* Automatically generated file, do not edit */\n");
851.27Schristos	    printf("static const struct el_bindings_t el_func_help[] = {\n");
861.1Scgd	    low = "abcdefghijklmnopqrstuvwxyz_";
871.1Scgd	    high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
881.1Scgd	    for (i = 1; i <= length(low); i++)
891.1Scgd		tr[substr(low, i, 1)] = substr(high, i, 1);
901.1Scgd	}
911.1Scgd	/\(\):/ {
921.1Scgd	    pr = substr($2, 1, 2);
931.1Scgd	    if (pr == "vi" || pr == "em" || pr == "ed") {
941.1Scgd		name = substr($2, 1, length($2) - 3);
951.1Scgd		uname = "";
961.1Scgd		fname = "";
971.1Scgd		for (i = 1; i <= length(name); i++) {
981.1Scgd		    s = substr(name, i, 1);
991.1Scgd		    uname = uname tr[s];
1001.1Scgd		    if (s == "_")
1011.1Scgd			s = "-";
1021.1Scgd		    fname = fname s;
1031.1Scgd		}
1041.4Ssimonb
1051.26Schristos		printf("    { %-30.30s %-30.30s\n","L\"" fname "\",", uname ",");
1061.4Ssimonb		ok = 1;
1071.1Scgd	    }
1081.1Scgd	}
1091.1Scgd	/^ \*/ {
1101.1Scgd	    if (ok) {
1111.26Schristos		printf("      L\"");
1121.1Scgd		for (i = 2; i < NF; i++)
1131.1Scgd		    printf("%s ", $i);
1141.26Schristos		printf("%s\" },\n", $i);
1151.1Scgd		ok = 0;
1161.1Scgd	    }
1171.1Scgd	}
1181.1Scgd	END {
1191.1Scgd	    printf("};\n");
1201.5Slukem	}'
1211.5Slukem	;;
1221.5Slukem
1231.6Slukem#	generate fcns.h from various .h files
1241.5Slukem#
1251.1Scgd-fh)
1261.1Scgd    cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
1271.11Schristos    sort | tr '[:lower:]' '[:upper:]' | $AWK '
1281.4Ssimonb	BEGIN {
1291.1Scgd	    printf("/* Automatically generated file, do not edit */\n");
1301.4Ssimonb	    count = 0;
1311.1Scgd	}
1321.4Ssimonb	{
1331.1Scgd	    printf("#define\t%-30.30s\t%3d\n", $1, count++);
1341.1Scgd	}
1351.1Scgd	END {
1361.1Scgd	    printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
1371.5Slukem	}'
1381.5Slukem	;;
1391.5Slukem
1401.28Schristos#	generate func.h from various .h files
1411.5Slukem#
1421.1Scgd-fc)
1431.1Scgd    cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
1441.1Scgd	BEGIN {
1451.1Scgd	    printf("/* Automatically generated file, do not edit */\n");
1461.27Schristos	    printf("static const el_func_t el_func[] = {");
1471.1Scgd	    maxlen = 80;
1481.1Scgd	    needn = 1;
1491.1Scgd	    len = 0;
1501.1Scgd	}
1511.1Scgd	{
1521.1Scgd	    clen = 25 + 2;
1531.1Scgd	    len += clen;
1541.4Ssimonb	    if (len >= maxlen)
1551.1Scgd		needn = 1;
1561.1Scgd	    if (needn) {
1571.1Scgd		printf("\n    ");
1581.1Scgd		needn = 0;
1591.1Scgd		len = 4 + clen;
1601.1Scgd	    }
1611.1Scgd	    s = $1 ",";
1621.1Scgd	    printf("%-26.26s ", s);
1631.1Scgd	}
1641.1Scgd	END {
1651.1Scgd	    printf("\n};\n");
1661.5Slukem	}'
1671.5Slukem	;;
1681.5Slukem
1691.1Scgd*)
1701.1Scgd    echo $USAGE 1>&2
1711.5Slukem    exit 1
1721.5Slukem    ;;
1731.5Slukem
1741.1Scgdesac
175