132fe07f8SJohn Marino#!/bin/sh - 212db70c8Szrj# $NetBSD: makelist,v 1.29 2016/05/09 21:46:56 christos Exp $ 332fe07f8SJohn Marino# 432fe07f8SJohn Marino# Copyright (c) 1992, 1993 532fe07f8SJohn Marino# The Regents of the University of California. All rights reserved. 632fe07f8SJohn Marino# 732fe07f8SJohn Marino# This code is derived from software contributed to Berkeley by 832fe07f8SJohn Marino# Christos Zoulas of Cornell University. 932fe07f8SJohn Marino# 1032fe07f8SJohn Marino# Redistribution and use in source and binary forms, with or without 1132fe07f8SJohn Marino# modification, are permitted provided that the following conditions 1232fe07f8SJohn Marino# are met: 1332fe07f8SJohn Marino# 1. Redistributions of source code must retain the above copyright 1432fe07f8SJohn Marino# notice, this list of conditions and the following disclaimer. 1532fe07f8SJohn Marino# 2. Redistributions in binary form must reproduce the above copyright 1632fe07f8SJohn Marino# notice, this list of conditions and the following disclaimer in the 1732fe07f8SJohn Marino# documentation and/or other materials provided with the distribution. 1832fe07f8SJohn Marino# 3. Neither the name of the University nor the names of its contributors 1932fe07f8SJohn Marino# may be used to endorse or promote products derived from this software 2032fe07f8SJohn Marino# without specific prior written permission. 2132fe07f8SJohn Marino# 2232fe07f8SJohn Marino# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2332fe07f8SJohn Marino# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2432fe07f8SJohn Marino# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2532fe07f8SJohn Marino# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2632fe07f8SJohn Marino# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2732fe07f8SJohn Marino# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2832fe07f8SJohn Marino# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2932fe07f8SJohn Marino# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3032fe07f8SJohn Marino# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3132fe07f8SJohn Marino# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3232fe07f8SJohn Marino# SUCH DAMAGE. 3332fe07f8SJohn Marino# 3432fe07f8SJohn Marino# @(#)makelist 5.3 (Berkeley) 6/4/93 3532fe07f8SJohn Marino 3632fe07f8SJohn Marino# makelist.sh: Automatically generate header files... 3732fe07f8SJohn Marino 38*cdf8408cSAntonio Huete JimenezLC_ALL=C 39*cdf8408cSAntonio Huete JimenezLANG=C 40*cdf8408cSAntonio Huete Jimenezexport LC_ALL LANG 41*cdf8408cSAntonio Huete Jimenez 42*cdf8408cSAntonio Huete Jimenezif [ "x$AWK" = "x" ] 43*cdf8408cSAntonio Huete Jimenezthen 4412db70c8Szrj AWK=awk 45*cdf8408cSAntonio Huete Jimenezfi 46*cdf8408cSAntonio Huete Jimenez 4712db70c8SzrjUSAGE="Usage: $0 -h|-fc|-fh|-bh <filenames>" 4832fe07f8SJohn Marino 4932fe07f8SJohn Marinoif [ "x$1" = "x" ] 5032fe07f8SJohn Marinothen 5132fe07f8SJohn Marino echo $USAGE 1>&2 5232fe07f8SJohn Marino exit 1 5332fe07f8SJohn Marinofi 5432fe07f8SJohn Marino 5532fe07f8SJohn MarinoFLAG="$1" 5632fe07f8SJohn Marinoshift 5732fe07f8SJohn Marino 5832fe07f8SJohn MarinoFILES="$@" 5932fe07f8SJohn Marino 6032fe07f8SJohn Marinocase $FLAG in 6132fe07f8SJohn Marino 6232fe07f8SJohn Marino-h) 6332fe07f8SJohn Marino set - `echo $FILES | sed -e 's/\\./_/g'` 6432fe07f8SJohn Marino hdr="_h_`basename $1`" 6532fe07f8SJohn Marino cat $FILES | $AWK ' 6632fe07f8SJohn Marino BEGIN { 6732fe07f8SJohn Marino printf("/* Automatically generated file, do not edit */\n"); 6832fe07f8SJohn Marino printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'"); 6932fe07f8SJohn Marino } 7032fe07f8SJohn Marino /\(\):/ { 7132fe07f8SJohn Marino pr = substr($2, 1, 2); 7232fe07f8SJohn Marino if (pr == "vi" || pr == "em" || pr == "ed") { 7332fe07f8SJohn Marino name = substr($2, 1, length($2) - 3); 7432fe07f8SJohn Marino# 7532fe07f8SJohn Marino# XXX: need a space between name and prototype so that -fc and -fh 7632fe07f8SJohn Marino# parsing is much easier 7732fe07f8SJohn Marino# 7812db70c8Szrj printf("libedit_private el_action_t\t%s (EditLine *, wint_t);\n", 7912db70c8Szrj name); 8032fe07f8SJohn Marino } 8132fe07f8SJohn Marino } 8232fe07f8SJohn Marino END { 8332fe07f8SJohn Marino printf("#endif /* %s */\n", "'$hdr'"); 8432fe07f8SJohn Marino }' 8532fe07f8SJohn Marino ;; 8632fe07f8SJohn Marino 8712db70c8Szrj# generate help.h from various .c files 8832fe07f8SJohn Marino# 8912db70c8Szrj-bh) 9032fe07f8SJohn Marino cat $FILES | $AWK ' 9132fe07f8SJohn Marino BEGIN { 9232fe07f8SJohn Marino printf("/* Automatically generated file, do not edit */\n"); 9312db70c8Szrj printf("static const struct el_bindings_t el_func_help[] = {\n"); 9432fe07f8SJohn Marino low = "abcdefghijklmnopqrstuvwxyz_"; 9532fe07f8SJohn Marino high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; 9632fe07f8SJohn Marino for (i = 1; i <= length(low); i++) 9732fe07f8SJohn Marino tr[substr(low, i, 1)] = substr(high, i, 1); 9832fe07f8SJohn Marino } 9932fe07f8SJohn Marino /\(\):/ { 10032fe07f8SJohn Marino pr = substr($2, 1, 2); 10132fe07f8SJohn Marino if (pr == "vi" || pr == "em" || pr == "ed") { 10232fe07f8SJohn Marino name = substr($2, 1, length($2) - 3); 10332fe07f8SJohn Marino uname = ""; 10432fe07f8SJohn Marino fname = ""; 10532fe07f8SJohn Marino for (i = 1; i <= length(name); i++) { 10632fe07f8SJohn Marino s = substr(name, i, 1); 10732fe07f8SJohn Marino uname = uname tr[s]; 10832fe07f8SJohn Marino if (s == "_") 10932fe07f8SJohn Marino s = "-"; 11032fe07f8SJohn Marino fname = fname s; 11132fe07f8SJohn Marino } 11232fe07f8SJohn Marino 11312db70c8Szrj printf(" { %-30.30s %-30.30s\n","L\"" fname "\",", uname ","); 11432fe07f8SJohn Marino ok = 1; 11532fe07f8SJohn Marino } 11632fe07f8SJohn Marino } 11732fe07f8SJohn Marino /^ \*/ { 11832fe07f8SJohn Marino if (ok) { 11912db70c8Szrj printf(" L\""); 12032fe07f8SJohn Marino for (i = 2; i < NF; i++) 12132fe07f8SJohn Marino printf("%s ", $i); 12212db70c8Szrj printf("%s\" },\n", $i); 12332fe07f8SJohn Marino ok = 0; 12432fe07f8SJohn Marino } 12532fe07f8SJohn Marino } 12632fe07f8SJohn Marino END { 12732fe07f8SJohn Marino printf("};\n"); 12832fe07f8SJohn Marino }' 12932fe07f8SJohn Marino ;; 13032fe07f8SJohn Marino 13132fe07f8SJohn Marino# generate fcns.h from various .h files 13232fe07f8SJohn Marino# 13332fe07f8SJohn Marino-fh) 13432fe07f8SJohn Marino cat $FILES | $AWK '/el_action_t/ { print $3 }' | \ 135ae19eda8Szrj sort | tr '[:lower:]' '[:upper:]' | $AWK ' 13632fe07f8SJohn Marino BEGIN { 13732fe07f8SJohn Marino printf("/* Automatically generated file, do not edit */\n"); 13832fe07f8SJohn Marino count = 0; 13932fe07f8SJohn Marino } 14032fe07f8SJohn Marino { 14132fe07f8SJohn Marino printf("#define\t%-30.30s\t%3d\n", $1, count++); 14232fe07f8SJohn Marino } 14332fe07f8SJohn Marino END { 14432fe07f8SJohn Marino printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count); 14532fe07f8SJohn Marino }' 14632fe07f8SJohn Marino ;; 14732fe07f8SJohn Marino 14812db70c8Szrj# generate func.h from various .h files 14932fe07f8SJohn Marino# 15032fe07f8SJohn Marino-fc) 15132fe07f8SJohn Marino cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK ' 15232fe07f8SJohn Marino BEGIN { 15332fe07f8SJohn Marino printf("/* Automatically generated file, do not edit */\n"); 15412db70c8Szrj printf("static const el_func_t el_func[] = {"); 15532fe07f8SJohn Marino maxlen = 80; 15632fe07f8SJohn Marino needn = 1; 15732fe07f8SJohn Marino len = 0; 15832fe07f8SJohn Marino } 15932fe07f8SJohn Marino { 16032fe07f8SJohn Marino clen = 25 + 2; 16132fe07f8SJohn Marino len += clen; 16232fe07f8SJohn Marino if (len >= maxlen) 16332fe07f8SJohn Marino needn = 1; 16432fe07f8SJohn Marino if (needn) { 16532fe07f8SJohn Marino printf("\n "); 16632fe07f8SJohn Marino needn = 0; 16732fe07f8SJohn Marino len = 4 + clen; 16832fe07f8SJohn Marino } 16932fe07f8SJohn Marino s = $1 ","; 17032fe07f8SJohn Marino printf("%-26.26s ", s); 17132fe07f8SJohn Marino } 17232fe07f8SJohn Marino END { 17332fe07f8SJohn Marino printf("\n};\n"); 17432fe07f8SJohn Marino }' 17532fe07f8SJohn Marino ;; 17632fe07f8SJohn Marino 17732fe07f8SJohn Marino*) 17832fe07f8SJohn Marino echo $USAGE 1>&2 17932fe07f8SJohn Marino exit 1 18032fe07f8SJohn Marino ;; 18132fe07f8SJohn Marino 18232fe07f8SJohn Marinoesac 183