makelist revision 1.5
11.1Scgd#!/bin/sh -
21.5Slukem#	$NetBSD: makelist,v 1.5 2000/06/21 03:21:28 lukem 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.5SlukemUSAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh|-m <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.5Slukem
581.5Slukem#	generate foo.h file from foo.c
591.5Slukem#
601.1Scgd-h)
611.2Scgd    set - `echo $FILES | sed -e 's/\\./_/g'`
621.2Scgd    hdr="_h_`basename $1`"
631.1Scgd    cat $FILES | $AWK '
641.1Scgd	BEGIN {
651.1Scgd	    printf("/* Automatically generated file, do not edit */\n");
661.1Scgd	    printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'");
671.1Scgd	}
681.1Scgd	/\(\):/ {
691.1Scgd	    pr = substr($2, 1, 2);
701.1Scgd	    if (pr == "vi" || pr == "em" || pr == "ed") {
711.1Scgd		name = substr($2, 1, length($2) - 3);
721.1Scgd		printf("protected el_action_t\t%-25.25s __P((EditLine *, int));\n", name);
731.1Scgd	    }
741.1Scgd	}
751.1Scgd	END {
761.1Scgd	    printf("#endif /* %s */\n", "'$hdr'");
771.5Slukem	}'
781.5Slukem	;;
791.5Slukem
801.5Slukem#	generate help.c from various .c files
811.5Slukem#
821.1Scgd-bc)
831.1Scgd    cat $FILES | $AWK '
841.1Scgd	BEGIN {
851.1Scgd	    printf("/* Automatically generated file, do not edit */\n");
861.1Scgd	    printf("#include \"sys.h\"\n#include \"el.h\"\n");
871.1Scgd	    printf("private struct el_bindings_t el_func_help[] = {\n");
881.1Scgd	    low = "abcdefghijklmnopqrstuvwxyz_";
891.1Scgd	    high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
901.1Scgd	    for (i = 1; i <= length(low); i++)
911.1Scgd		tr[substr(low, i, 1)] = substr(high, i, 1);
921.1Scgd	}
931.1Scgd	/\(\):/ {
941.1Scgd	    pr = substr($2, 1, 2);
951.1Scgd	    if (pr == "vi" || pr == "em" || pr == "ed") {
961.1Scgd		name = substr($2, 1, length($2) - 3);
971.1Scgd		uname = "";
981.1Scgd		fname = "";
991.1Scgd		for (i = 1; i <= length(name); i++) {
1001.1Scgd		    s = substr(name, i, 1);
1011.1Scgd		    uname = uname tr[s];
1021.1Scgd		    if (s == "_")
1031.1Scgd			s = "-";
1041.1Scgd		    fname = fname s;
1051.1Scgd		}
1061.4Ssimonb
1071.1Scgd		printf("    { %-30.30s %-30.30s\n","\"" fname "\",", uname ",");
1081.4Ssimonb		ok = 1;
1091.1Scgd	    }
1101.1Scgd	}
1111.1Scgd	/^ \*/ {
1121.1Scgd	    if (ok) {
1131.1Scgd		printf("      \"");
1141.1Scgd		for (i = 2; i < NF; i++)
1151.1Scgd		    printf("%s ", $i);
1161.1Scgd		printf("%s\" },\n", $i);
1171.1Scgd		ok = 0;
1181.1Scgd	    }
1191.1Scgd	}
1201.1Scgd	END {
1211.1Scgd	    printf("    { NULL, 0, NULL }\n");
1221.1Scgd	    printf("};\n");
1231.1Scgd	    printf("\nprotected el_bindings_t* help__get()");
1241.1Scgd	    printf("{ return el_func_help; }\n");
1251.5Slukem	}'
1261.5Slukem	;;
1271.5Slukem
1281.5Slukem#	generate help.h from various .c files
1291.5Slukem#
1301.1Scgd-bh)
1311.1Scgd    $AWK '
1321.4Ssimonb	BEGIN {
1331.1Scgd	    printf("/* Automatically generated file, do not edit */\n");
1341.1Scgd	    printf("#ifndef _h_help_c\n#define _h_help_c\n");
1351.1Scgd	    printf("protected el_bindings_t *help__get\t__P((void));\n");
1361.1Scgd	    printf("#endif /* _h_help_c */\n");
1371.5Slukem	}' /dev/null
1381.5Slukem	;;
1391.5Slukem
1401.5Slukem#	generate fcns.h from various .c files
1411.5Slukem#
1421.1Scgd-fh)
1431.1Scgd    cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
1441.1Scgd    sort | tr '[a-z]' '[A-Z]' | $AWK '
1451.4Ssimonb	BEGIN {
1461.1Scgd	    printf("/* Automatically generated file, do not edit */\n");
1471.1Scgd	    printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n");
1481.4Ssimonb	    count = 0;
1491.1Scgd	}
1501.4Ssimonb	{
1511.1Scgd	    printf("#define\t%-30.30s\t%3d\n", $1, count++);
1521.1Scgd	}
1531.1Scgd	END {
1541.1Scgd	    printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
1551.1Scgd
1561.1Scgd	    printf("typedef el_action_t (*el_func_t) __P((EditLine *, int));");
1571.1Scgd	    printf("\nprotected el_func_t* func__get __P((void));\n");
1581.1Scgd	    printf("#endif /* _h_fcns_c */\n");
1591.5Slukem	}'
1601.5Slukem	;;
1611.5Slukem
1621.5Slukem#	generate fcns.c from various .c files
1631.5Slukem#
1641.1Scgd-fc)
1651.1Scgd    cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
1661.1Scgd	BEGIN {
1671.1Scgd	    printf("/* Automatically generated file, do not edit */\n");
1681.1Scgd	    printf("#include \"sys.h\"\n#include \"el.h\"\n");
1691.1Scgd	    printf("private el_func_t el_func[] = {");
1701.1Scgd	    maxlen = 80;
1711.1Scgd	    needn = 1;
1721.1Scgd	    len = 0;
1731.1Scgd	}
1741.1Scgd	{
1751.1Scgd	    clen = 25 + 2;
1761.1Scgd	    len += clen;
1771.4Ssimonb	    if (len >= maxlen)
1781.1Scgd		needn = 1;
1791.1Scgd	    if (needn) {
1801.1Scgd		printf("\n    ");
1811.1Scgd		needn = 0;
1821.1Scgd		len = 4 + clen;
1831.1Scgd	    }
1841.1Scgd	    s = $1 ",";
1851.1Scgd	    printf("%-26.26s ", s);
1861.1Scgd	}
1871.1Scgd	END {
1881.1Scgd	    printf("\n};\n");
1891.1Scgd	    printf("\nprotected el_func_t* func__get() { return el_func; }\n");
1901.5Slukem	}'
1911.5Slukem	;;
1921.5Slukem
1931.5Slukem#	generate editline.c from various .c files
1941.5Slukem#
1951.1Scgd-e)
1961.1Scgd	echo "$FILES" | tr ' ' '\012' | $AWK '
1971.1Scgd	BEGIN {
1981.1Scgd	    printf("/* Automatically generated file, do not edit */\n");
1991.1Scgd	    printf("#define protected static\n");
2001.1Scgd	    printf("#define SCCSID\n");
2011.1Scgd	}
2021.1Scgd	{
2031.1Scgd	    printf("#include \"%s\"\n", $1);
2041.5Slukem	}'
2051.5Slukem	;;
2061.5Slukem
2071.5Slukem#	generate man page fragment from various .c files
2081.5Slukem#
2091.5Slukem-m)
2101.5Slukem    cat $FILES | $AWK '
2111.5Slukem	BEGIN {
2121.5Slukem	    printf(".\\\" Section automatically generated with makelist\n");
2131.5Slukem	    printf(".Bl -tag -width 4n\n");
2141.5Slukem	}
2151.5Slukem	/\(\):/ {
2161.5Slukem	    pr = substr($2, 1, 2);
2171.5Slukem	    if (pr == "vi" || pr == "em" || pr == "ed") {
2181.5Slukem		name = substr($2, 1, length($2) - 3);
2191.5Slukem		fname = "";
2201.5Slukem		for (i = 1; i <= length(name); i++) {
2211.5Slukem		    s = substr(name, i, 1);
2221.5Slukem		    if (s == "_")
2231.5Slukem			s = "-";
2241.5Slukem		    fname = fname s;
2251.5Slukem		}
2261.5Slukem
2271.5Slukem		printf(".It Ic %s\n", fname);
2281.5Slukem		ok = 1;
2291.5Slukem	    }
2301.5Slukem	}
2311.5Slukem	/^ \*/ {
2321.5Slukem	    if (ok) {
2331.5Slukem		for (i = 2; i < NF; i++)
2341.5Slukem		    printf("%s ", $i);
2351.5Slukem		printf("%s.\n", $i);
2361.5Slukem		ok = 0;
2371.5Slukem	    }
2381.5Slukem	}
2391.5Slukem	END {
2401.5Slukem	    printf(".El\n");
2411.5Slukem	    printf(".\\\" End of section automatically generated with makelist\n");
2421.5Slukem	}'
2431.5Slukem	;;
2441.5Slukem
2451.1Scgd*)
2461.1Scgd    echo $USAGE 1>&2
2471.5Slukem    exit 1
2481.5Slukem    ;;
2491.5Slukem
2501.1Scgdesac
251