xref: /csrg-svn/lib/libedit/makelist (revision 54731)
1*54731Smarc#!/bin/sh -
2*54731Smarc#
3*54731Smarc# Copyright (c) 1992 The Regents of the University of California.
4*54731Smarc# All rights reserved.
5*54731Smarc#
6*54731Smarc# This code is derived from software contributed to Berkeley by
7*54731Smarc# Christos Zoulas of Cornell University.
8*54731Smarc#
9*54731Smarc# %sccs.include.redist.sh%
10*54731Smarc#
11*54731Smarc#	@(#)makelist	5.1 (Berkeley) 07/06/92
12*54731Smarc
13*54731Smarc# makelist.sh: Automatically generate header files...
14*54731Smarc
15*54731Smarc# On vangogh /usr/bin/awk is broken; christos Fri Jul  3 14:01:03 EDT 1992
16*54731SmarcAWK=/usr/old/bin/awk
17*54731Smarc#AWK=/usr/bin/awk
18*54731SmarcUSAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh <filenames>"
19*54731Smarc
20*54731Smarcif [ "x$1" = "x" ]
21*54731Smarcthen
22*54731Smarc    echo $USAGE 1>&2
23*54731Smarc    exit 1
24*54731Smarcfi
25*54731Smarc
26*54731SmarcFLAG="$1"
27*54731Smarcshift
28*54731Smarc
29*54731SmarcFILES="$@"
30*54731Smarc
31*54731Smarccase $FLAG in
32*54731Smarc-h)
33*54731Smarc    OIFS="$IFS"
34*54731Smarc    IFS=".$IFS"
35*54731Smarc    set - $FILES
36*54731Smarc    IFS="$OIFS"
37*54731Smarc    hdr="_h_`basename $1`_$2"
38*54731Smarc    cat $FILES | $AWK '
39*54731Smarc	BEGIN {
40*54731Smarc	    printf("/* Automatically generated file, do not edit */\n");
41*54731Smarc	    printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'");
42*54731Smarc	}
43*54731Smarc	/\(\):/ {
44*54731Smarc	    pr = substr($2, 1, 2);
45*54731Smarc	    if (pr == "vi" || pr == "em" || pr == "ed") {
46*54731Smarc		name = substr($2, 1, length($2) - 3);
47*54731Smarc		printf("protected el_action_t\t%-25.25s __P((EditLine *, int));\n", name);
48*54731Smarc	    }
49*54731Smarc	}
50*54731Smarc	END {
51*54731Smarc	    printf("#endif /* %s */\n", "'$hdr'");
52*54731Smarc	}';;
53*54731Smarc-bc)
54*54731Smarc    cat $FILES | $AWK '
55*54731Smarc	BEGIN {
56*54731Smarc	    printf("/* Automatically generated file, do not edit */\n");
57*54731Smarc	    printf("#include \"sys.h\"\n#include \"el.h\"\n");
58*54731Smarc	    printf("private struct el_bindings_t el_func_help[] = {\n");
59*54731Smarc	    low = "abcdefghijklmnopqrstuvwxyz_";
60*54731Smarc	    high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
61*54731Smarc	    for (i = 1; i <= length(low); i++)
62*54731Smarc		tr[substr(low, i, 1)] = substr(high, i, 1);
63*54731Smarc	}
64*54731Smarc	/\(\):/ {
65*54731Smarc	    pr = substr($2, 1, 2);
66*54731Smarc	    if (pr == "vi" || pr == "em" || pr == "ed") {
67*54731Smarc		name = substr($2, 1, length($2) - 3);
68*54731Smarc		uname = "";
69*54731Smarc		fname = "";
70*54731Smarc		for (i = 1; i <= length(name); i++) {
71*54731Smarc		    s = substr(name, i, 1);
72*54731Smarc		    uname = uname tr[s];
73*54731Smarc		    if (s == "_")
74*54731Smarc			s = "-";
75*54731Smarc		    fname = fname s;
76*54731Smarc		}
77*54731Smarc
78*54731Smarc		printf("    { %-30.30s %-30.30s\n","\"" fname "\",", uname ",");
79*54731Smarc		ok = 1;
80*54731Smarc	    }
81*54731Smarc	}
82*54731Smarc	/^ \*/ {
83*54731Smarc	    if (ok) {
84*54731Smarc		printf("      \"");
85*54731Smarc		for (i = 2; i < NF; i++)
86*54731Smarc		    printf("%s ", $i);
87*54731Smarc		printf("%s\" },\n", $i);
88*54731Smarc		ok = 0;
89*54731Smarc	    }
90*54731Smarc	}
91*54731Smarc	END {
92*54731Smarc	    printf("    { NULL, 0, NULL }\n");
93*54731Smarc	    printf("};\n");
94*54731Smarc	    printf("\nprotected el_bindings_t* help__get()");
95*54731Smarc	    printf("{ return el_func_help; }\n");
96*54731Smarc	}';;
97*54731Smarc-bh)
98*54731Smarc    $AWK '
99*54731Smarc	BEGIN {
100*54731Smarc	    printf("/* Automatically generated file, do not edit */\n");
101*54731Smarc	    printf("#ifndef _h_help_c\n#define _h_help_c\n");
102*54731Smarc	    printf("protected el_bindings_t *help__get\t__P((void));\n");
103*54731Smarc	    printf("#endif /* _h_help_c */\n");
104*54731Smarc	}' /dev/null;;
105*54731Smarc-fh)
106*54731Smarc    cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
107*54731Smarc    sort | tr '[a-z]' '[A-Z]' | $AWK '
108*54731Smarc	BEGIN {
109*54731Smarc	    printf("/* Automatically generated file, do not edit */\n");
110*54731Smarc	    printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n");
111*54731Smarc	    count = 0;
112*54731Smarc	}
113*54731Smarc	{
114*54731Smarc	    printf("#define\t%-30.30s\t%3d\n", $1, count++);
115*54731Smarc	}
116*54731Smarc	END {
117*54731Smarc	    printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
118*54731Smarc
119*54731Smarc	    printf("typedef el_action_t (*el_func_t) __P((EditLine *, int));");
120*54731Smarc	    printf("\nprotected el_func_t* func__get __P((void));\n");
121*54731Smarc	    printf("#endif /* _h_fcns_c */\n");
122*54731Smarc	}';;
123*54731Smarc-fc)
124*54731Smarc    cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
125*54731Smarc	BEGIN {
126*54731Smarc	    printf("/* Automatically generated file, do not edit */\n");
127*54731Smarc	    printf("#include \"sys.h\"\n#include \"el.h\"\n");
128*54731Smarc	    printf("private el_func_t el_func[] = {");
129*54731Smarc	    maxlen = 80;
130*54731Smarc	    needn = 1;
131*54731Smarc	    len = 0;
132*54731Smarc	}
133*54731Smarc	{
134*54731Smarc	    clen = 25 + 2;
135*54731Smarc	    len += clen;
136*54731Smarc	    if (len >= maxlen)
137*54731Smarc		needn = 1;
138*54731Smarc	    if (needn) {
139*54731Smarc		printf("\n    ");
140*54731Smarc		needn = 0;
141*54731Smarc		len = 4 + clen;
142*54731Smarc	    }
143*54731Smarc	    s = $1 ",";
144*54731Smarc	    printf("%-26.26s ", s);
145*54731Smarc	}
146*54731Smarc	END {
147*54731Smarc	    printf("\n};\n");
148*54731Smarc	    printf("\nprotected el_func_t* func__get() { return el_func; }\n");
149*54731Smarc	}';;
150*54731Smarc-e)
151*54731Smarc	echo "$FILES" | tr ' ' '\012' | $AWK '
152*54731Smarc	BEGIN {
153*54731Smarc	    printf("/* Automatically generated file, do not edit */\n");
154*54731Smarc	    printf("#define protected static\n");
155*54731Smarc	    printf("#define SCCSID\n");
156*54731Smarc	}
157*54731Smarc	{
158*54731Smarc	    printf("#include \"%s\"\n", $1);
159*54731Smarc	}';;
160*54731Smarc*)
161*54731Smarc    echo $USAGE 1>&2
162*54731Smarc    exit 1;;
163*54731Smarcesac
164