makelist revision 1573
1#!/bin/sh -
2#
3# Copyright (c) 1992, 1993
4#	The Regents of the University of California.  All rights reserved.
5#
6# This code is derived from software contributed to Berkeley by
7# Christos Zoulas of Cornell University.
8#
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# 3. All advertising materials mentioning features or use of this software
18#    must display the following acknowledgement:
19#	This product includes software developed by the University of
20#	California, Berkeley and its contributors.
21# 4. Neither the name of the University nor the names of its contributors
22#    may be used to endorse or promote products derived from this software
23#    without specific prior written permission.
24#
25# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35# SUCH DAMAGE.
36#
37#	@(#)makelist	5.3 (Berkeley) 6/4/93
38
39# makelist.sh: Automatically generate header files...
40
41AWK=/usr/bin/awk
42USAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh <filenames>" 
43
44if [ "x$1" = "x" ]
45then
46    echo $USAGE 1>&2
47    exit 1
48fi
49
50FLAG="$1"
51shift
52
53FILES="$@"
54
55case $FLAG in
56-h)
57    OIFS="$IFS"
58    IFS=".$IFS"
59    set - $FILES
60    IFS="$OIFS"
61    hdr="_h_`basename $1`_$2"
62    cat $FILES | $AWK '
63	BEGIN {
64	    printf("/* Automatically generated file, do not edit */\n");
65	    printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'");
66	}
67	/\(\):/ {
68	    pr = substr($2, 1, 2);
69	    if (pr == "vi" || pr == "em" || pr == "ed") {
70		name = substr($2, 1, length($2) - 3);
71		printf("protected el_action_t\t%-25.25s __P((EditLine *, int));\n", name);
72	    }
73	}
74	END {
75	    printf("#endif /* %s */\n", "'$hdr'");
76	}';;
77-bc)
78    cat $FILES | $AWK '
79	BEGIN {
80	    printf("/* Automatically generated file, do not edit */\n");
81	    printf("#include \"sys.h\"\n#include \"el.h\"\n");
82	    printf("private struct el_bindings_t el_func_help[] = {\n");
83	    low = "abcdefghijklmnopqrstuvwxyz_";
84	    high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
85	    for (i = 1; i <= length(low); i++)
86		tr[substr(low, i, 1)] = substr(high, i, 1);
87	}
88	/\(\):/ {
89	    pr = substr($2, 1, 2);
90	    if (pr == "vi" || pr == "em" || pr == "ed") {
91		name = substr($2, 1, length($2) - 3);
92		uname = "";
93		fname = "";
94		for (i = 1; i <= length(name); i++) {
95		    s = substr(name, i, 1);
96		    uname = uname tr[s];
97		    if (s == "_")
98			s = "-";
99		    fname = fname s;
100		}
101		     
102		printf("    { %-30.30s %-30.30s\n","\"" fname "\",", uname ",");
103		ok = 1; 
104	    }
105	}
106	/^ \*/ {
107	    if (ok) {
108		printf("      \"");
109		for (i = 2; i < NF; i++)
110		    printf("%s ", $i);
111		printf("%s\" },\n", $i);
112		ok = 0;
113	    }
114	}
115	END {
116	    printf("    { NULL, 0, NULL }\n");
117	    printf("};\n");
118	    printf("\nprotected el_bindings_t* help__get()");
119	    printf("{ return el_func_help; }\n");
120	}';;
121-bh)
122    $AWK '
123	BEGIN { 
124	    printf("/* Automatically generated file, do not edit */\n");
125	    printf("#ifndef _h_help_c\n#define _h_help_c\n");
126	    printf("protected el_bindings_t *help__get\t__P((void));\n");
127	    printf("#endif /* _h_help_c */\n");
128	}' /dev/null;;
129-fh)
130    cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
131    sort | tr '[a-z]' '[A-Z]' | $AWK '
132	BEGIN { 
133	    printf("/* Automatically generated file, do not edit */\n");
134	    printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n");
135	    count = 0; 
136	}
137	{ 
138	    printf("#define\t%-30.30s\t%3d\n", $1, count++);
139	}
140	END {
141	    printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
142
143	    printf("typedef el_action_t (*el_func_t) __P((EditLine *, int));");
144	    printf("\nprotected el_func_t* func__get __P((void));\n");
145	    printf("#endif /* _h_fcns_c */\n");
146	}';;
147-fc)
148    cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
149	BEGIN {
150	    printf("/* Automatically generated file, do not edit */\n");
151	    printf("#include \"sys.h\"\n#include \"el.h\"\n");
152	    printf("private el_func_t el_func[] = {");
153	    maxlen = 80;
154	    needn = 1;
155	    len = 0;
156	}
157	{
158	    clen = 25 + 2;
159	    len += clen;
160	    if (len >= maxlen) 
161		needn = 1;
162	    if (needn) {
163		printf("\n    ");
164		needn = 0;
165		len = 4 + clen;
166	    }
167	    s = $1 ",";
168	    printf("%-26.26s ", s);
169	}
170	END {
171	    printf("\n};\n");
172	    printf("\nprotected el_func_t* func__get() { return el_func; }\n");
173	}';;
174-e)
175	echo "$FILES" | tr ' ' '\012' | $AWK '
176	BEGIN {
177	    printf("/* Automatically generated file, do not edit */\n");
178	    printf("#define protected static\n");
179	    printf("#define SCCSID\n");
180	}
181	{
182	    printf("#include \"%s\"\n", $1);
183	}';;
184*)
185    echo $USAGE 1>&2
186    exit 1;;
187esac
188