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