Explicitly specify `all' as the default target(as it used to be), so as
[dragonfly.git] / lib / libedit / makelist
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 # $DragonFly: src/lib/libedit/makelist,v 1.3 2003/11/12 20:21:29 eirikn Exp $
39
40 # makelist.sh: Automatically generate header files...
41
42 AWK=awk
43 USAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh <filenames>" 
44
45 if [ "x$1" = "x" ]
46 then
47     echo $USAGE 1>&2
48     exit 1
49 fi
50
51 FLAG="$1"
52 shift
53
54 FILES="$@"
55
56 case $FLAG in
57 -h)
58     fn=`basename $FILES`
59     OIFS="$IFS"
60     IFS=".$IFS"
61     set - $fn
62     IFS="$OIFS"
63     hdr="_h_$1_$2"
64     cat $FILES | $AWK '
65         BEGIN {
66             printf("/* Automatically generated file, do not edit */\n");
67             printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'");
68         }
69         /\(\):/ {
70             pr = substr($2, 1, 2);
71             if (pr == "vi" || pr == "em" || pr == "ed") {
72                 name = substr($2, 1, length($2) - 3);
73                 printf("protected el_action_t\t%-25.25s (EditLine *, int);\n", name);
74             }
75         }
76         END {
77             printf("#endif /* %s */\n", "'$hdr'");
78         }';;
79 -bc)
80     cat $FILES | $AWK '
81         BEGIN {
82             printf("/* Automatically generated file, do not edit */\n");
83             printf("#include \"sys.h\"\n#include \"el.h\"\n");
84             printf("private struct el_bindings_t el_func_help[] = {\n");
85             low = "abcdefghijklmnopqrstuvwxyz_";
86             high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
87             for (i = 1; i <= length(low); i++)
88                 tr[substr(low, i, 1)] = substr(high, i, 1);
89         }
90         /\(\):/ {
91             pr = substr($2, 1, 2);
92             if (pr == "vi" || pr == "em" || pr == "ed") {
93                 name = substr($2, 1, length($2) - 3);
94                 uname = "";
95                 fname = "";
96                 for (i = 1; i <= length(name); i++) {
97                     s = substr(name, i, 1);
98                     uname = uname tr[s];
99                     if (s == "_")
100                         s = "-";
101                     fname = fname s;
102                 }
103                      
104                 printf("    { %-30.30s %-30.30s\n","\"" fname "\",", uname ",");
105                 ok = 1; 
106             }
107         }
108         /^ \*/ {
109             if (ok) {
110                 printf("      \"");
111                 for (i = 2; i < NF; i++)
112                     printf("%s ", $i);
113                 printf("%s\" },\n", $i);
114                 ok = 0;
115             }
116         }
117         END {
118             printf("    { NULL, 0, NULL }\n");
119             printf("};\n");
120             printf("\nprotected el_bindings_t* help__get()");
121             printf("{ return el_func_help; }\n");
122         }';;
123 -bh)
124     $AWK '
125         BEGIN { 
126             printf("/* Automatically generated file, do not edit */\n");
127             printf("#ifndef _h_help_c\n#define _h_help_c\n");
128             printf("protected el_bindings_t *help__get\t(void);\n");
129             printf("#endif /* _h_help_c */\n");
130         }' /dev/null;;
131 -fh)
132     cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
133     sort | tr '[a-z]' '[A-Z]' | $AWK '
134         BEGIN { 
135             printf("/* Automatically generated file, do not edit */\n");
136             printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n");
137             count = 0; 
138         }
139         { 
140             printf("#define\t%-30.30s\t%3d\n", $1, count++);
141         }
142         END {
143             printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
144
145             printf("typedef el_action_t (*el_func_t) (EditLine *, int);");
146             printf("\nprotected el_func_t* func__get (void);\n");
147             printf("#endif /* _h_fcns_c */\n");
148         }';;
149 -fc)
150     cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
151         BEGIN {
152             printf("/* Automatically generated file, do not edit */\n");
153             printf("#include \"sys.h\"\n#include \"el.h\"\n");
154             printf("private el_func_t el_func[] = {");
155             maxlen = 80;
156             needn = 1;
157             len = 0;
158         }
159         {
160             clen = 25 + 2;
161             len += clen;
162             if (len >= maxlen) 
163                 needn = 1;
164             if (needn) {
165                 printf("\n    ");
166                 needn = 0;
167                 len = 4 + clen;
168             }
169             s = $1 ",";
170             printf("%-26.26s ", s);
171         }
172         END {
173             printf("\n};\n");
174             printf("\nprotected el_func_t* func__get() { return el_func; }\n");
175         }';;
176 -e)
177         echo "$FILES" | tr ' ' '\012' | $AWK '
178         BEGIN {
179             printf("/* Automatically generated file, do not edit */\n");
180             printf("#define protected static\n");
181             printf("#define SCCSID\n");
182         }
183         {
184             printf("#include \"%s\"\n", $1);
185         }';;
186 *)
187     echo $USAGE 1>&2
188     exit 1;;
189 esac