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