]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libedit/makelist
Remove spurious newline
[FreeBSD/FreeBSD.git] / lib / libedit / makelist
1 #!/bin/sh -
2 # $FreeBSD$
3 #       $NetBSD: makelist,v 1.18 2012/03/21 05:34:54 matt Exp $
4 #
5 # Copyright (c) 1992, 1993
6 #       The Regents of the University of California.  All rights reserved.
7 #
8 # This code is derived from software contributed to Berkeley by
9 # Christos Zoulas of Cornell University.
10 #
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
13 # are met:
14 # 1. Redistributions of source code must retain the above copyright
15 #    notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 #    notice, this list of conditions and the following disclaimer in the
18 #    documentation and/or other materials provided with the distribution.
19 # 3. Neither the name of the University nor the names of its contributors
20 #    may be used to endorse or promote products derived from this software
21 #    without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 # SUCH DAMAGE.
34 #
35 #       @(#)makelist    5.3 (Berkeley) 6/4/93
36
37 # makelist.sh: Automatically generate header files...
38
39 AWK=awk
40 USAGE="Usage: $0 -n|-h|-e|-fc|-fh|-bc|-bh|-m <filenames>"
41
42 if [ "x$1" = "x" ]
43 then
44     echo $USAGE 1>&2
45     exit 1
46 fi
47
48 FLAG="$1"
49 shift
50
51 FILES="$@"
52
53 case $FLAG in
54
55 #       generate foo.h file from foo.c
56 #
57 -n)
58     cat << _EOF
59 #include "config.h"
60 #undef WIDECHAR
61 #define NARROWCHAR
62 #include "${FILES}"
63 _EOF
64     ;;
65
66 -h)
67     set - `echo $FILES | sed -e 's/\\./_/g'`
68     hdr="_h_`basename $1`"
69     cat $FILES | $AWK '
70         BEGIN {
71             printf("/* Automatically generated file, do not edit */\n");
72             printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'");
73         }
74         /\(\):/ {
75             pr = substr($2, 1, 2);
76             if (pr == "vi" || pr == "em" || pr == "ed") {
77                 name = substr($2, 1, length($2) - 3);
78 #
79 # XXX:  need a space between name and prototype so that -fc and -fh
80 #       parsing is much easier
81 #
82                 printf("protected el_action_t\t%s (EditLine *, wint_t);\n",
83                     name);
84             }
85         }
86         END {
87             printf("#endif /* %s */\n", "'$hdr'");
88         }'
89         ;;
90
91 #       generate help.c from various .c files
92 #
93 -bc)
94     cat $FILES | $AWK '
95         BEGIN {
96             printf("/* Automatically generated file, do not edit */\n");
97             printf("#include \"config.h\"\n#include \"el.h\"\n");
98             printf("#include \"help.h\"\n");
99             printf("private const struct el_bindings_t el_func_help[] = {\n");
100             low = "abcdefghijklmnopqrstuvwxyz_";
101             high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
102             for (i = 1; i <= length(low); i++)
103                 tr[substr(low, i, 1)] = substr(high, i, 1);
104         }
105         /\(\):/ {
106             pr = substr($2, 1, 2);
107             if (pr == "vi" || pr == "em" || pr == "ed") {
108                 name = substr($2, 1, length($2) - 3);
109                 uname = "";
110                 fname = "";
111                 for (i = 1; i <= length(name); i++) {
112                     s = substr(name, i, 1);
113                     uname = uname tr[s];
114                     if (s == "_")
115                         s = "-";
116                     fname = fname s;
117                 }
118
119                 printf("    { %-30.30s %-30.30s\n","STR(\"" fname "\"),", uname ",");
120                 ok = 1;
121             }
122         }
123         /^ \*/ {
124             if (ok) {
125                 printf("      STR(\"");
126                 for (i = 2; i < NF; i++)
127                     printf("%s ", $i);
128                 printf("%s\") },\n", $i);
129                 ok = 0;
130             }
131         }
132         END {
133             printf("};\n");
134             printf("\nprotected const el_bindings_t* help__get(void)");
135             printf("{ return el_func_help; }\n");
136         }'
137         ;;
138
139 #       generate help.h from various .c files
140 #
141 -bh)
142     $AWK '
143         BEGIN {
144             printf("/* Automatically generated file, do not edit */\n");
145             printf("#ifndef _h_help_c\n#define _h_help_c\n");
146             printf("protected const el_bindings_t *help__get(void);\n");
147             printf("#endif /* _h_help_c */\n");
148         }' /dev/null
149         ;;
150
151 #       generate fcns.h from various .h files
152 #
153 -fh)
154     cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
155     sort | tr '[:lower:]' '[:upper:]' | $AWK '
156         BEGIN {
157             printf("/* Automatically generated file, do not edit */\n");
158             printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n");
159             count = 0;
160         }
161         {
162             printf("#define\t%-30.30s\t%3d\n", $1, count++);
163         }
164         END {
165             printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
166
167             printf("typedef el_action_t (*el_func_t)(EditLine *, wint_t);");
168             printf("\nprotected const el_func_t* func__get(void);\n");
169             printf("#endif /* _h_fcns_c */\n");
170         }'
171         ;;
172
173 #       generate fcns.c from various .h files
174 #
175 -fc)
176     cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
177         BEGIN {
178             printf("/* Automatically generated file, do not edit */\n");
179             printf("#include \"config.h\"\n#include \"el.h\"\n");
180             printf("#include \"common.h\"\n");
181             printf("#include \"emacs.h\"\n");
182             printf("#include \"vi.h\"\n");
183             printf("private const el_func_t el_func[] = {");
184             maxlen = 80;
185             needn = 1;
186             len = 0;
187         }
188         {
189             clen = 25 + 2;
190             len += clen;
191             if (len >= maxlen)
192                 needn = 1;
193             if (needn) {
194                 printf("\n    ");
195                 needn = 0;
196                 len = 4 + clen;
197             }
198             s = $1 ",";
199             printf("%-26.26s ", s);
200         }
201         END {
202             printf("\n};\n");
203             printf("\nprotected const el_func_t* func__get(void) { return el_func; }\n");
204         }'
205         ;;
206
207 #       generate editline.c from various .c files
208 #
209 -e)
210         echo "$FILES" | tr ' ' '\012' | $AWK '
211         BEGIN {
212             printf("/* Automatically generated file, do not edit */\n");
213             printf("#define protected static\n");
214             printf("#define SCCSID\n");
215         }
216         {
217             printf("#include \"%s\"\n", $1);
218         }'
219         ;;
220
221 #       generate man page fragment from various .c files
222 #
223 -m)
224     cat $FILES | $AWK '
225         BEGIN {
226             printf(".\\\" Section automatically generated with makelist\n");
227             printf(".Bl -tag -width 4n\n");
228         }
229         /\(\):/ {
230             pr = substr($2, 1, 2);
231             if (pr == "vi" || pr == "em" || pr == "ed") {
232                 name = substr($2, 1, length($2) - 3);
233                 fname = "";
234                 for (i = 1; i <= length(name); i++) {
235                     s = substr(name, i, 1);
236                     if (s == "_")
237                         s = "-";
238                     fname = fname s;
239                 }
240
241                 printf(".It Ic %s\n", fname);
242                 ok = 1;
243             }
244         }
245         /^ \*/ {
246             if (ok) {
247                 for (i = 2; i < NF; i++)
248                     printf("%s ", $i);
249                 printf("%s.\n", $i);
250                 ok = 0;
251             }
252         }
253         END {
254             printf(".El\n");
255             printf(".\\\" End of section automatically generated with makelist\n");
256         }'
257         ;;
258
259 *)
260     echo $USAGE 1>&2
261     exit 1
262     ;;
263
264 esac