154731Smarc#!/bin/sh - 254731Smarc# 3*61279Sbostic# Copyright (c) 1992, 1993 4*61279Sbostic# The Regents of the University of California. All rights reserved. 554731Smarc# 654731Smarc# This code is derived from software contributed to Berkeley by 754731Smarc# Christos Zoulas of Cornell University. 854731Smarc# 954731Smarc# %sccs.include.redist.sh% 1054731Smarc# 11*61279Sbostic# @(#)makelist 5.3 (Berkeley) 06/04/93 1254731Smarc 1354731Smarc# makelist.sh: Automatically generate header files... 1454731Smarc 1555253SmarcAWK=/usr/bin/awk 1654731SmarcUSAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh <filenames>" 1754731Smarc 1854731Smarcif [ "x$1" = "x" ] 1954731Smarcthen 2054731Smarc echo $USAGE 1>&2 2154731Smarc exit 1 2254731Smarcfi 2354731Smarc 2454731SmarcFLAG="$1" 2554731Smarcshift 2654731Smarc 2754731SmarcFILES="$@" 2854731Smarc 2954731Smarccase $FLAG in 3054731Smarc-h) 3154731Smarc OIFS="$IFS" 3254731Smarc IFS=".$IFS" 3354731Smarc set - $FILES 3454731Smarc IFS="$OIFS" 3554731Smarc hdr="_h_`basename $1`_$2" 3654731Smarc cat $FILES | $AWK ' 3754731Smarc BEGIN { 3854731Smarc printf("/* Automatically generated file, do not edit */\n"); 3954731Smarc printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'"); 4054731Smarc } 4154731Smarc /\(\):/ { 4254731Smarc pr = substr($2, 1, 2); 4354731Smarc if (pr == "vi" || pr == "em" || pr == "ed") { 4454731Smarc name = substr($2, 1, length($2) - 3); 4554731Smarc printf("protected el_action_t\t%-25.25s __P((EditLine *, int));\n", name); 4654731Smarc } 4754731Smarc } 4854731Smarc END { 4954731Smarc printf("#endif /* %s */\n", "'$hdr'"); 5054731Smarc }';; 5154731Smarc-bc) 5254731Smarc cat $FILES | $AWK ' 5354731Smarc BEGIN { 5454731Smarc printf("/* Automatically generated file, do not edit */\n"); 5554731Smarc printf("#include \"sys.h\"\n#include \"el.h\"\n"); 5654731Smarc printf("private struct el_bindings_t el_func_help[] = {\n"); 5754731Smarc low = "abcdefghijklmnopqrstuvwxyz_"; 5854731Smarc high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; 5954731Smarc for (i = 1; i <= length(low); i++) 6054731Smarc tr[substr(low, i, 1)] = substr(high, i, 1); 6154731Smarc } 6254731Smarc /\(\):/ { 6354731Smarc pr = substr($2, 1, 2); 6454731Smarc if (pr == "vi" || pr == "em" || pr == "ed") { 6554731Smarc name = substr($2, 1, length($2) - 3); 6654731Smarc uname = ""; 6754731Smarc fname = ""; 6854731Smarc for (i = 1; i <= length(name); i++) { 6954731Smarc s = substr(name, i, 1); 7054731Smarc uname = uname tr[s]; 7154731Smarc if (s == "_") 7254731Smarc s = "-"; 7354731Smarc fname = fname s; 7454731Smarc } 7554731Smarc 7654731Smarc printf(" { %-30.30s %-30.30s\n","\"" fname "\",", uname ","); 7754731Smarc ok = 1; 7854731Smarc } 7954731Smarc } 8054731Smarc /^ \*/ { 8154731Smarc if (ok) { 8254731Smarc printf(" \""); 8354731Smarc for (i = 2; i < NF; i++) 8454731Smarc printf("%s ", $i); 8554731Smarc printf("%s\" },\n", $i); 8654731Smarc ok = 0; 8754731Smarc } 8854731Smarc } 8954731Smarc END { 9054731Smarc printf(" { NULL, 0, NULL }\n"); 9154731Smarc printf("};\n"); 9254731Smarc printf("\nprotected el_bindings_t* help__get()"); 9354731Smarc printf("{ return el_func_help; }\n"); 9454731Smarc }';; 9554731Smarc-bh) 9654731Smarc $AWK ' 9754731Smarc BEGIN { 9854731Smarc printf("/* Automatically generated file, do not edit */\n"); 9954731Smarc printf("#ifndef _h_help_c\n#define _h_help_c\n"); 10054731Smarc printf("protected el_bindings_t *help__get\t__P((void));\n"); 10154731Smarc printf("#endif /* _h_help_c */\n"); 10254731Smarc }' /dev/null;; 10354731Smarc-fh) 10454731Smarc cat $FILES | $AWK '/el_action_t/ { print $3 }' | \ 10554731Smarc sort | tr '[a-z]' '[A-Z]' | $AWK ' 10654731Smarc BEGIN { 10754731Smarc printf("/* Automatically generated file, do not edit */\n"); 10854731Smarc printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n"); 10954731Smarc count = 0; 11054731Smarc } 11154731Smarc { 11254731Smarc printf("#define\t%-30.30s\t%3d\n", $1, count++); 11354731Smarc } 11454731Smarc END { 11554731Smarc printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count); 11654731Smarc 11754731Smarc printf("typedef el_action_t (*el_func_t) __P((EditLine *, int));"); 11854731Smarc printf("\nprotected el_func_t* func__get __P((void));\n"); 11954731Smarc printf("#endif /* _h_fcns_c */\n"); 12054731Smarc }';; 12154731Smarc-fc) 12254731Smarc cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK ' 12354731Smarc BEGIN { 12454731Smarc printf("/* Automatically generated file, do not edit */\n"); 12554731Smarc printf("#include \"sys.h\"\n#include \"el.h\"\n"); 12654731Smarc printf("private el_func_t el_func[] = {"); 12754731Smarc maxlen = 80; 12854731Smarc needn = 1; 12954731Smarc len = 0; 13054731Smarc } 13154731Smarc { 13254731Smarc clen = 25 + 2; 13354731Smarc len += clen; 13454731Smarc if (len >= maxlen) 13554731Smarc needn = 1; 13654731Smarc if (needn) { 13754731Smarc printf("\n "); 13854731Smarc needn = 0; 13954731Smarc len = 4 + clen; 14054731Smarc } 14154731Smarc s = $1 ","; 14254731Smarc printf("%-26.26s ", s); 14354731Smarc } 14454731Smarc END { 14554731Smarc printf("\n};\n"); 14654731Smarc printf("\nprotected el_func_t* func__get() { return el_func; }\n"); 14754731Smarc }';; 14854731Smarc-e) 14954731Smarc echo "$FILES" | tr ' ' '\012' | $AWK ' 15054731Smarc BEGIN { 15154731Smarc printf("/* Automatically generated file, do not edit */\n"); 15254731Smarc printf("#define protected static\n"); 15354731Smarc printf("#define SCCSID\n"); 15454731Smarc } 15554731Smarc { 15654731Smarc printf("#include \"%s\"\n", $1); 15754731Smarc }';; 15854731Smarc*) 15954731Smarc echo $USAGE 1>&2 16054731Smarc exit 1;; 16154731Smarcesac 162