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