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