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