xref: /minix3/lib/libedit/makelist (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
13e1db26aSLionel Sambuc#!/bin/sh -
23e1db26aSLionel Sambuc#	$NetBSD: makelist,v 1.18 2012/03/21 05:34:54 matt Exp $
33e1db26aSLionel Sambuc#
43e1db26aSLionel Sambuc# Copyright (c) 1992, 1993
53e1db26aSLionel Sambuc#	The Regents of the University of California.  All rights reserved.
63e1db26aSLionel Sambuc#
73e1db26aSLionel Sambuc# This code is derived from software contributed to Berkeley by
83e1db26aSLionel Sambuc# Christos Zoulas of Cornell University.
93e1db26aSLionel Sambuc#
103e1db26aSLionel Sambuc# Redistribution and use in source and binary forms, with or without
113e1db26aSLionel Sambuc# modification, are permitted provided that the following conditions
123e1db26aSLionel Sambuc# are met:
133e1db26aSLionel Sambuc# 1. Redistributions of source code must retain the above copyright
143e1db26aSLionel Sambuc#    notice, this list of conditions and the following disclaimer.
153e1db26aSLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright
163e1db26aSLionel Sambuc#    notice, this list of conditions and the following disclaimer in the
173e1db26aSLionel Sambuc#    documentation and/or other materials provided with the distribution.
183e1db26aSLionel Sambuc# 3. Neither the name of the University nor the names of its contributors
193e1db26aSLionel Sambuc#    may be used to endorse or promote products derived from this software
203e1db26aSLionel Sambuc#    without specific prior written permission.
213e1db26aSLionel Sambuc#
223e1db26aSLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
233e1db26aSLionel Sambuc# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
243e1db26aSLionel Sambuc# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
253e1db26aSLionel Sambuc# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
263e1db26aSLionel Sambuc# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
273e1db26aSLionel Sambuc# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
283e1db26aSLionel Sambuc# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
293e1db26aSLionel Sambuc# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
303e1db26aSLionel Sambuc# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
313e1db26aSLionel Sambuc# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
323e1db26aSLionel Sambuc# SUCH DAMAGE.
333e1db26aSLionel Sambuc#
343e1db26aSLionel Sambuc#	@(#)makelist	5.3 (Berkeley) 6/4/93
353e1db26aSLionel Sambuc
363e1db26aSLionel Sambuc# makelist.sh: Automatically generate header files...
373e1db26aSLionel Sambuc
383e1db26aSLionel SambucAWK=awk
393e1db26aSLionel SambucUSAGE="Usage: $0 -n|-h|-e|-fc|-fh|-bc|-bh|-m <filenames>"
403e1db26aSLionel Sambuc
413e1db26aSLionel Sambucif [ "x$1" = "x" ]
423e1db26aSLionel Sambucthen
433e1db26aSLionel Sambuc    echo $USAGE 1>&2
443e1db26aSLionel Sambuc    exit 1
453e1db26aSLionel Sambucfi
463e1db26aSLionel Sambuc
473e1db26aSLionel SambucFLAG="$1"
483e1db26aSLionel Sambucshift
493e1db26aSLionel Sambuc
503e1db26aSLionel SambucFILES="$@"
513e1db26aSLionel Sambuc
523e1db26aSLionel Sambuccase $FLAG in
533e1db26aSLionel Sambuc
543e1db26aSLionel Sambuc#	generate foo.h file from foo.c
553e1db26aSLionel Sambuc#
563e1db26aSLionel Sambuc-n)
573e1db26aSLionel Sambuc    cat << _EOF
583e1db26aSLionel Sambuc#include "config.h"
593e1db26aSLionel Sambuc#undef WIDECHAR
603e1db26aSLionel Sambuc#define NARROWCHAR
613e1db26aSLionel Sambuc#include "${FILES}"
623e1db26aSLionel Sambuc_EOF
633e1db26aSLionel Sambuc    ;;
643e1db26aSLionel Sambuc
653e1db26aSLionel Sambuc-h)
663e1db26aSLionel Sambuc    set - `echo $FILES | sed -e 's/\\./_/g'`
673e1db26aSLionel Sambuc    hdr="_h_`basename $1`"
683e1db26aSLionel Sambuc    cat $FILES | $AWK '
693e1db26aSLionel Sambuc	BEGIN {
703e1db26aSLionel Sambuc	    printf("/* Automatically generated file, do not edit */\n");
713e1db26aSLionel Sambuc	    printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'");
723e1db26aSLionel Sambuc	}
733e1db26aSLionel Sambuc	/\(\):/ {
743e1db26aSLionel Sambuc	    pr = substr($2, 1, 2);
753e1db26aSLionel Sambuc	    if (pr == "vi" || pr == "em" || pr == "ed") {
763e1db26aSLionel Sambuc		name = substr($2, 1, length($2) - 3);
773e1db26aSLionel Sambuc#
783e1db26aSLionel Sambuc# XXX:	need a space between name and prototype so that -fc and -fh
793e1db26aSLionel Sambuc#	parsing is much easier
803e1db26aSLionel Sambuc#
813e1db26aSLionel Sambuc		printf("protected el_action_t\t%s (EditLine *, Int);\n", name);
823e1db26aSLionel Sambuc	    }
833e1db26aSLionel Sambuc	}
843e1db26aSLionel Sambuc	END {
853e1db26aSLionel Sambuc	    printf("#endif /* %s */\n", "'$hdr'");
863e1db26aSLionel Sambuc	}'
873e1db26aSLionel Sambuc	;;
883e1db26aSLionel Sambuc
893e1db26aSLionel Sambuc#	generate help.c from various .c files
903e1db26aSLionel Sambuc#
913e1db26aSLionel Sambuc-bc)
923e1db26aSLionel Sambuc    cat $FILES | $AWK '
933e1db26aSLionel Sambuc	BEGIN {
943e1db26aSLionel Sambuc	    printf("/* Automatically generated file, do not edit */\n");
953e1db26aSLionel Sambuc	    printf("#include \"config.h\"\n#include \"el.h\"\n");
963e1db26aSLionel Sambuc	    printf("#include \"chartype.h\"\n");
973e1db26aSLionel Sambuc	    printf("private const struct el_bindings_t el_func_help[] = {\n");
983e1db26aSLionel Sambuc	    low = "abcdefghijklmnopqrstuvwxyz_";
993e1db26aSLionel Sambuc	    high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
1003e1db26aSLionel Sambuc	    for (i = 1; i <= length(low); i++)
1013e1db26aSLionel Sambuc		tr[substr(low, i, 1)] = substr(high, i, 1);
1023e1db26aSLionel Sambuc	}
1033e1db26aSLionel Sambuc	/\(\):/ {
1043e1db26aSLionel Sambuc	    pr = substr($2, 1, 2);
1053e1db26aSLionel Sambuc	    if (pr == "vi" || pr == "em" || pr == "ed") {
1063e1db26aSLionel Sambuc		name = substr($2, 1, length($2) - 3);
1073e1db26aSLionel Sambuc		uname = "";
1083e1db26aSLionel Sambuc		fname = "";
1093e1db26aSLionel Sambuc		for (i = 1; i <= length(name); i++) {
1103e1db26aSLionel Sambuc		    s = substr(name, i, 1);
1113e1db26aSLionel Sambuc		    uname = uname tr[s];
1123e1db26aSLionel Sambuc		    if (s == "_")
1133e1db26aSLionel Sambuc			s = "-";
1143e1db26aSLionel Sambuc		    fname = fname s;
1153e1db26aSLionel Sambuc		}
1163e1db26aSLionel Sambuc
1173e1db26aSLionel Sambuc		printf("    { %-30.30s %-30.30s\n","STR(\"" fname "\"),", uname ",");
1183e1db26aSLionel Sambuc		ok = 1;
1193e1db26aSLionel Sambuc	    }
1203e1db26aSLionel Sambuc	}
1213e1db26aSLionel Sambuc	/^ \*/ {
1223e1db26aSLionel Sambuc	    if (ok) {
1233e1db26aSLionel Sambuc		printf("      STR(\"");
1243e1db26aSLionel Sambuc		for (i = 2; i < NF; i++)
1253e1db26aSLionel Sambuc		    printf("%s ", $i);
1263e1db26aSLionel Sambuc		printf("%s\") },\n", $i);
1273e1db26aSLionel Sambuc		ok = 0;
1283e1db26aSLionel Sambuc	    }
1293e1db26aSLionel Sambuc	}
1303e1db26aSLionel Sambuc	END {
1313e1db26aSLionel Sambuc	    printf("};\n");
1323e1db26aSLionel Sambuc	    printf("\nprotected const el_bindings_t* help__get(void)");
1333e1db26aSLionel Sambuc	    printf("{ return el_func_help; }\n");
1343e1db26aSLionel Sambuc	}'
1353e1db26aSLionel Sambuc	;;
1363e1db26aSLionel Sambuc
1373e1db26aSLionel Sambuc#	generate help.h from various .c files
1383e1db26aSLionel Sambuc#
1393e1db26aSLionel Sambuc-bh)
1403e1db26aSLionel Sambuc    $AWK '
1413e1db26aSLionel Sambuc	BEGIN {
1423e1db26aSLionel Sambuc	    printf("/* Automatically generated file, do not edit */\n");
1433e1db26aSLionel Sambuc	    printf("#ifndef _h_help_c\n#define _h_help_c\n");
1443e1db26aSLionel Sambuc	    printf("protected const el_bindings_t *help__get(void);\n");
1453e1db26aSLionel Sambuc	    printf("#endif /* _h_help_c */\n");
1463e1db26aSLionel Sambuc	}' /dev/null
1473e1db26aSLionel Sambuc	;;
1483e1db26aSLionel Sambuc
1493e1db26aSLionel Sambuc#	generate fcns.h from various .h files
1503e1db26aSLionel Sambuc#
1513e1db26aSLionel Sambuc-fh)
1523e1db26aSLionel Sambuc    cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
1533e1db26aSLionel Sambuc    sort | tr '[:lower:]' '[:upper:]' | $AWK '
1543e1db26aSLionel Sambuc	BEGIN {
1553e1db26aSLionel Sambuc	    printf("/* Automatically generated file, do not edit */\n");
1563e1db26aSLionel Sambuc	    printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n");
1573e1db26aSLionel Sambuc	    count = 0;
1583e1db26aSLionel Sambuc	}
1593e1db26aSLionel Sambuc	{
1603e1db26aSLionel Sambuc	    printf("#define\t%-30.30s\t%3d\n", $1, count++);
1613e1db26aSLionel Sambuc	}
1623e1db26aSLionel Sambuc	END {
1633e1db26aSLionel Sambuc	    printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
1643e1db26aSLionel Sambuc
1653e1db26aSLionel Sambuc	    printf("typedef el_action_t (*el_func_t)(EditLine *, Int);");
1663e1db26aSLionel Sambuc	    printf("\nprotected const el_func_t* func__get(void);\n");
1673e1db26aSLionel Sambuc	    printf("#endif /* _h_fcns_c */\n");
1683e1db26aSLionel Sambuc	}'
1693e1db26aSLionel Sambuc	;;
1703e1db26aSLionel Sambuc
1713e1db26aSLionel Sambuc#	generate fcns.c from various .h files
1723e1db26aSLionel Sambuc#
1733e1db26aSLionel Sambuc-fc)
1743e1db26aSLionel Sambuc    cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
1753e1db26aSLionel Sambuc	BEGIN {
1763e1db26aSLionel Sambuc	    printf("/* Automatically generated file, do not edit */\n");
1773e1db26aSLionel Sambuc	    printf("#include \"config.h\"\n#include \"el.h\"\n");
1783e1db26aSLionel Sambuc	    printf("private const el_func_t el_func[] = {");
1793e1db26aSLionel Sambuc	    maxlen = 80;
1803e1db26aSLionel Sambuc	    needn = 1;
1813e1db26aSLionel Sambuc	    len = 0;
1823e1db26aSLionel Sambuc	}
1833e1db26aSLionel Sambuc	{
1843e1db26aSLionel Sambuc	    clen = 25 + 2;
1853e1db26aSLionel Sambuc	    len += clen;
1863e1db26aSLionel Sambuc	    if (len >= maxlen)
1873e1db26aSLionel Sambuc		needn = 1;
1883e1db26aSLionel Sambuc	    if (needn) {
1893e1db26aSLionel Sambuc		printf("\n    ");
1903e1db26aSLionel Sambuc		needn = 0;
1913e1db26aSLionel Sambuc		len = 4 + clen;
1923e1db26aSLionel Sambuc	    }
1933e1db26aSLionel Sambuc	    s = $1 ",";
1943e1db26aSLionel Sambuc	    printf("%-26.26s ", s);
1953e1db26aSLionel Sambuc	}
1963e1db26aSLionel Sambuc	END {
1973e1db26aSLionel Sambuc	    printf("\n};\n");
1983e1db26aSLionel Sambuc	    printf("\nprotected const el_func_t* func__get(void) { return el_func; }\n");
1993e1db26aSLionel Sambuc	}'
2003e1db26aSLionel Sambuc	;;
2013e1db26aSLionel Sambuc
2023e1db26aSLionel Sambuc#	generate editline.c from various .c files
2033e1db26aSLionel Sambuc#
2043e1db26aSLionel Sambuc-e)
2053e1db26aSLionel Sambuc	echo "$FILES" | tr ' ' '\012' | $AWK '
2063e1db26aSLionel Sambuc	BEGIN {
2073e1db26aSLionel Sambuc	    printf("/* Automatically generated file, do not edit */\n");
208*0a6a1f1dSLionel Sambuc	    printf("#define protected static\n");
2093e1db26aSLionel Sambuc	    printf("#define SCCSID\n");
2103e1db26aSLionel Sambuc	}
2113e1db26aSLionel Sambuc	{
2123e1db26aSLionel Sambuc	    printf("#include \"%s\"\n", $1);
2133e1db26aSLionel Sambuc	}'
2143e1db26aSLionel Sambuc	;;
2153e1db26aSLionel Sambuc
2163e1db26aSLionel Sambuc#	generate man page fragment from various .c files
2173e1db26aSLionel Sambuc#
2183e1db26aSLionel Sambuc-m)
2193e1db26aSLionel Sambuc    cat $FILES | $AWK '
2203e1db26aSLionel Sambuc	BEGIN {
2213e1db26aSLionel Sambuc	    printf(".\\\" Section automatically generated with makelist\n");
2223e1db26aSLionel Sambuc	    printf(".Bl -tag -width 4n\n");
2233e1db26aSLionel Sambuc	}
2243e1db26aSLionel Sambuc	/\(\):/ {
2253e1db26aSLionel Sambuc	    pr = substr($2, 1, 2);
2263e1db26aSLionel Sambuc	    if (pr == "vi" || pr == "em" || pr == "ed") {
2273e1db26aSLionel Sambuc		name = substr($2, 1, length($2) - 3);
2283e1db26aSLionel Sambuc		fname = "";
2293e1db26aSLionel Sambuc		for (i = 1; i <= length(name); i++) {
2303e1db26aSLionel Sambuc		    s = substr(name, i, 1);
2313e1db26aSLionel Sambuc		    if (s == "_")
2323e1db26aSLionel Sambuc			s = "-";
2333e1db26aSLionel Sambuc		    fname = fname s;
2343e1db26aSLionel Sambuc		}
2353e1db26aSLionel Sambuc
2363e1db26aSLionel Sambuc		printf(".It Ic %s\n", fname);
2373e1db26aSLionel Sambuc		ok = 1;
2383e1db26aSLionel Sambuc	    }
2393e1db26aSLionel Sambuc	}
2403e1db26aSLionel Sambuc	/^ \*/ {
2413e1db26aSLionel Sambuc	    if (ok) {
2423e1db26aSLionel Sambuc		for (i = 2; i < NF; i++)
2433e1db26aSLionel Sambuc		    printf("%s ", $i);
2443e1db26aSLionel Sambuc		printf("%s.\n", $i);
2453e1db26aSLionel Sambuc		ok = 0;
2463e1db26aSLionel Sambuc	    }
2473e1db26aSLionel Sambuc	}
2483e1db26aSLionel Sambuc	END {
2493e1db26aSLionel Sambuc	    printf(".El\n");
2503e1db26aSLionel Sambuc	    printf(".\\\" End of section automatically generated with makelist\n");
2513e1db26aSLionel Sambuc	}'
2523e1db26aSLionel Sambuc	;;
2533e1db26aSLionel Sambuc
2543e1db26aSLionel Sambuc*)
2553e1db26aSLionel Sambuc    echo $USAGE 1>&2
2563e1db26aSLionel Sambuc    exit 1
2573e1db26aSLionel Sambuc    ;;
2583e1db26aSLionel Sambuc
2593e1db26aSLionel Sambucesac
260