xref: /original-bsd/lib/libedit/makelist (revision ea3a8ee8)
1#!/bin/sh -
2#
3# Copyright (c) 1992 The Regents of the University of California.
4# All rights reserved.
5#
6# This code is derived from software contributed to Berkeley by
7# Christos Zoulas of Cornell University.
8#
9# %sccs.include.redist.sh%
10#
11#	@(#)makelist	5.2 (Berkeley) 07/15/92
12
13# makelist.sh: Automatically generate header files...
14
15AWK=/usr/bin/awk
16USAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh <filenames>"
17
18if [ "x$1" = "x" ]
19then
20    echo $USAGE 1>&2
21    exit 1
22fi
23
24FLAG="$1"
25shift
26
27FILES="$@"
28
29case $FLAG in
30-h)
31    OIFS="$IFS"
32    IFS=".$IFS"
33    set - $FILES
34    IFS="$OIFS"
35    hdr="_h_`basename $1`_$2"
36    cat $FILES | $AWK '
37	BEGIN {
38	    printf("/* Automatically generated file, do not edit */\n");
39	    printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'");
40	}
41	/\(\):/ {
42	    pr = substr($2, 1, 2);
43	    if (pr == "vi" || pr == "em" || pr == "ed") {
44		name = substr($2, 1, length($2) - 3);
45		printf("protected el_action_t\t%-25.25s __P((EditLine *, int));\n", name);
46	    }
47	}
48	END {
49	    printf("#endif /* %s */\n", "'$hdr'");
50	}';;
51-bc)
52    cat $FILES | $AWK '
53	BEGIN {
54	    printf("/* Automatically generated file, do not edit */\n");
55	    printf("#include \"sys.h\"\n#include \"el.h\"\n");
56	    printf("private struct el_bindings_t el_func_help[] = {\n");
57	    low = "abcdefghijklmnopqrstuvwxyz_";
58	    high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
59	    for (i = 1; i <= length(low); i++)
60		tr[substr(low, i, 1)] = substr(high, i, 1);
61	}
62	/\(\):/ {
63	    pr = substr($2, 1, 2);
64	    if (pr == "vi" || pr == "em" || pr == "ed") {
65		name = substr($2, 1, length($2) - 3);
66		uname = "";
67		fname = "";
68		for (i = 1; i <= length(name); i++) {
69		    s = substr(name, i, 1);
70		    uname = uname tr[s];
71		    if (s == "_")
72			s = "-";
73		    fname = fname s;
74		}
75
76		printf("    { %-30.30s %-30.30s\n","\"" fname "\",", uname ",");
77		ok = 1;
78	    }
79	}
80	/^ \*/ {
81	    if (ok) {
82		printf("      \"");
83		for (i = 2; i < NF; i++)
84		    printf("%s ", $i);
85		printf("%s\" },\n", $i);
86		ok = 0;
87	    }
88	}
89	END {
90	    printf("    { NULL, 0, NULL }\n");
91	    printf("};\n");
92	    printf("\nprotected el_bindings_t* help__get()");
93	    printf("{ return el_func_help; }\n");
94	}';;
95-bh)
96    $AWK '
97	BEGIN {
98	    printf("/* Automatically generated file, do not edit */\n");
99	    printf("#ifndef _h_help_c\n#define _h_help_c\n");
100	    printf("protected el_bindings_t *help__get\t__P((void));\n");
101	    printf("#endif /* _h_help_c */\n");
102	}' /dev/null;;
103-fh)
104    cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
105    sort | tr '[a-z]' '[A-Z]' | $AWK '
106	BEGIN {
107	    printf("/* Automatically generated file, do not edit */\n");
108	    printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n");
109	    count = 0;
110	}
111	{
112	    printf("#define\t%-30.30s\t%3d\n", $1, count++);
113	}
114	END {
115	    printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
116
117	    printf("typedef el_action_t (*el_func_t) __P((EditLine *, int));");
118	    printf("\nprotected el_func_t* func__get __P((void));\n");
119	    printf("#endif /* _h_fcns_c */\n");
120	}';;
121-fc)
122    cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
123	BEGIN {
124	    printf("/* Automatically generated file, do not edit */\n");
125	    printf("#include \"sys.h\"\n#include \"el.h\"\n");
126	    printf("private el_func_t el_func[] = {");
127	    maxlen = 80;
128	    needn = 1;
129	    len = 0;
130	}
131	{
132	    clen = 25 + 2;
133	    len += clen;
134	    if (len >= maxlen)
135		needn = 1;
136	    if (needn) {
137		printf("\n    ");
138		needn = 0;
139		len = 4 + clen;
140	    }
141	    s = $1 ",";
142	    printf("%-26.26s ", s);
143	}
144	END {
145	    printf("\n};\n");
146	    printf("\nprotected el_func_t* func__get() { return el_func; }\n");
147	}';;
148-e)
149	echo "$FILES" | tr ' ' '\012' | $AWK '
150	BEGIN {
151	    printf("/* Automatically generated file, do not edit */\n");
152	    printf("#define protected static\n");
153	    printf("#define SCCSID\n");
154	}
155	{
156	    printf("#include \"%s\"\n", $1);
157	}';;
158*)
159    echo $USAGE 1>&2
160    exit 1;;
161esac
162