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