11573Srgrimes#!/bin/sh - 284260Sobrien# $FreeBSD: releng/11.0/lib/libedit/makelist 296435 2016-03-06 21:32:54Z pfg $ 3276881Sbapt# $NetBSD: makelist,v 1.18 2012/03/21 05:34:54 matt Exp $ 41573Srgrimes# 51573Srgrimes# Copyright (c) 1992, 1993 61573Srgrimes# The Regents of the University of California. All rights reserved. 71573Srgrimes# 81573Srgrimes# This code is derived from software contributed to Berkeley by 91573Srgrimes# Christos Zoulas of Cornell University. 101573Srgrimes# 111573Srgrimes# Redistribution and use in source and binary forms, with or without 121573Srgrimes# modification, are permitted provided that the following conditions 131573Srgrimes# are met: 141573Srgrimes# 1. Redistributions of source code must retain the above copyright 151573Srgrimes# notice, this list of conditions and the following disclaimer. 161573Srgrimes# 2. Redistributions in binary form must reproduce the above copyright 171573Srgrimes# notice, this list of conditions and the following disclaimer in the 181573Srgrimes# documentation and/or other materials provided with the distribution. 19148834Sstefanf# 3. Neither the name of the University nor the names of its contributors 201573Srgrimes# may be used to endorse or promote products derived from this software 211573Srgrimes# without specific prior written permission. 221573Srgrimes# 231573Srgrimes# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 241573Srgrimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 251573Srgrimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 261573Srgrimes# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 271573Srgrimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 281573Srgrimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 291573Srgrimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 301573Srgrimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 311573Srgrimes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 321573Srgrimes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 331573Srgrimes# SUCH DAMAGE. 341573Srgrimes# 351573Srgrimes# @(#)makelist 5.3 (Berkeley) 6/4/93 361573Srgrimes 371573Srgrimes# makelist.sh: Automatically generate header files... 381573Srgrimes 39148834SstefanfAWK=awk 40276881SbaptUSAGE="Usage: $0 -n|-h|-e|-fc|-fh|-bc|-bh|-m <filenames>" 411573Srgrimes 421573Srgrimesif [ "x$1" = "x" ] 431573Srgrimesthen 441573Srgrimes echo $USAGE 1>&2 451573Srgrimes exit 1 461573Srgrimesfi 471573Srgrimes 481573SrgrimesFLAG="$1" 491573Srgrimesshift 501573Srgrimes 511573SrgrimesFILES="$@" 521573Srgrimes 531573Srgrimescase $FLAG in 5484260Sobrien 5584260Sobrien# generate foo.h file from foo.c 5684260Sobrien# 57276881Sbapt-n) 58276881Sbapt cat << _EOF 59276881Sbapt#include "config.h" 60276881Sbapt#undef WIDECHAR 61276881Sbapt#define NARROWCHAR 62276881Sbapt#include "${FILES}" 63276881Sbapt_EOF 64276881Sbapt ;; 65296435Spfg 661573Srgrimes-h) 6784260Sobrien set - `echo $FILES | sed -e 's/\\./_/g'` 6884260Sobrien hdr="_h_`basename $1`" 691573Srgrimes cat $FILES | $AWK ' 701573Srgrimes BEGIN { 711573Srgrimes printf("/* Automatically generated file, do not edit */\n"); 721573Srgrimes printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'"); 731573Srgrimes } 741573Srgrimes /\(\):/ { 751573Srgrimes pr = substr($2, 1, 2); 761573Srgrimes if (pr == "vi" || pr == "em" || pr == "ed") { 771573Srgrimes name = substr($2, 1, length($2) - 3); 7884260Sobrien# 7984260Sobrien# XXX: need a space between name and prototype so that -fc and -fh 8084260Sobrien# parsing is much easier 8184260Sobrien# 82296435Spfg printf("protected el_action_t\t%s (EditLine *, Int);\n", name); 831573Srgrimes } 841573Srgrimes } 851573Srgrimes END { 861573Srgrimes printf("#endif /* %s */\n", "'$hdr'"); 8784260Sobrien }' 8884260Sobrien ;; 8984260Sobrien 9084260Sobrien# generate help.c from various .c files 9184260Sobrien# 921573Srgrimes-bc) 931573Srgrimes cat $FILES | $AWK ' 941573Srgrimes BEGIN { 951573Srgrimes printf("/* Automatically generated file, do not edit */\n"); 96276881Sbapt printf("#include \"config.h\"\n#include \"el.h\"\n"); 97296435Spfg printf("#include \"chartype.h\"\n"); 9884260Sobrien printf("private const struct el_bindings_t el_func_help[] = {\n"); 991573Srgrimes low = "abcdefghijklmnopqrstuvwxyz_"; 1001573Srgrimes high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; 1011573Srgrimes for (i = 1; i <= length(low); i++) 1021573Srgrimes tr[substr(low, i, 1)] = substr(high, i, 1); 1031573Srgrimes } 1041573Srgrimes /\(\):/ { 1051573Srgrimes pr = substr($2, 1, 2); 1061573Srgrimes if (pr == "vi" || pr == "em" || pr == "ed") { 1071573Srgrimes name = substr($2, 1, length($2) - 3); 1081573Srgrimes uname = ""; 1091573Srgrimes fname = ""; 1101573Srgrimes for (i = 1; i <= length(name); i++) { 1111573Srgrimes s = substr(name, i, 1); 1121573Srgrimes uname = uname tr[s]; 1131573Srgrimes if (s == "_") 1141573Srgrimes s = "-"; 1151573Srgrimes fname = fname s; 1161573Srgrimes } 11784260Sobrien 118276881Sbapt printf(" { %-30.30s %-30.30s\n","STR(\"" fname "\"),", uname ","); 11984260Sobrien ok = 1; 1201573Srgrimes } 1211573Srgrimes } 1221573Srgrimes /^ \*/ { 1231573Srgrimes if (ok) { 124276881Sbapt printf(" STR(\""); 1251573Srgrimes for (i = 2; i < NF; i++) 1261573Srgrimes printf("%s ", $i); 127276881Sbapt printf("%s\") },\n", $i); 1281573Srgrimes ok = 0; 1291573Srgrimes } 1301573Srgrimes } 1311573Srgrimes END { 1321573Srgrimes printf("};\n"); 133276881Sbapt printf("\nprotected const el_bindings_t* help__get(void)"); 1341573Srgrimes printf("{ return el_func_help; }\n"); 13584260Sobrien }' 13684260Sobrien ;; 13784260Sobrien 13884260Sobrien# generate help.h from various .c files 13984260Sobrien# 1401573Srgrimes-bh) 1411573Srgrimes $AWK ' 14284260Sobrien BEGIN { 1431573Srgrimes printf("/* Automatically generated file, do not edit */\n"); 1441573Srgrimes printf("#ifndef _h_help_c\n#define _h_help_c\n"); 14584260Sobrien printf("protected const el_bindings_t *help__get(void);\n"); 1461573Srgrimes printf("#endif /* _h_help_c */\n"); 14784260Sobrien }' /dev/null 14884260Sobrien ;; 14984260Sobrien 15084260Sobrien# generate fcns.h from various .h files 15184260Sobrien# 1521573Srgrimes-fh) 1531573Srgrimes cat $FILES | $AWK '/el_action_t/ { print $3 }' | \ 154276881Sbapt sort | tr '[:lower:]' '[:upper:]' | $AWK ' 15584260Sobrien BEGIN { 1561573Srgrimes printf("/* Automatically generated file, do not edit */\n"); 1571573Srgrimes printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n"); 15884260Sobrien count = 0; 1591573Srgrimes } 16084260Sobrien { 1611573Srgrimes printf("#define\t%-30.30s\t%3d\n", $1, count++); 1621573Srgrimes } 1631573Srgrimes END { 1641573Srgrimes printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count); 1651573Srgrimes 166296435Spfg printf("typedef el_action_t (*el_func_t)(EditLine *, Int);"); 16784260Sobrien printf("\nprotected const el_func_t* func__get(void);\n"); 1681573Srgrimes printf("#endif /* _h_fcns_c */\n"); 16984260Sobrien }' 17084260Sobrien ;; 17184260Sobrien 17284260Sobrien# generate fcns.c from various .h files 17384260Sobrien# 1741573Srgrimes-fc) 1751573Srgrimes cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK ' 1761573Srgrimes BEGIN { 1771573Srgrimes printf("/* Automatically generated file, do not edit */\n"); 178276881Sbapt printf("#include \"config.h\"\n#include \"el.h\"\n"); 17984260Sobrien printf("private const el_func_t el_func[] = {"); 1801573Srgrimes maxlen = 80; 1811573Srgrimes needn = 1; 1821573Srgrimes len = 0; 1831573Srgrimes } 1841573Srgrimes { 1851573Srgrimes clen = 25 + 2; 1861573Srgrimes len += clen; 18784260Sobrien if (len >= maxlen) 1881573Srgrimes needn = 1; 1891573Srgrimes if (needn) { 1901573Srgrimes printf("\n "); 1911573Srgrimes needn = 0; 1921573Srgrimes len = 4 + clen; 1931573Srgrimes } 1941573Srgrimes s = $1 ","; 1951573Srgrimes printf("%-26.26s ", s); 1961573Srgrimes } 1971573Srgrimes END { 1981573Srgrimes printf("\n};\n"); 199276881Sbapt printf("\nprotected const el_func_t* func__get(void) { return el_func; }\n"); 20084260Sobrien }' 20184260Sobrien ;; 20284260Sobrien 20384260Sobrien# generate editline.c from various .c files 20484260Sobrien# 2051573Srgrimes-e) 2061573Srgrimes echo "$FILES" | tr ' ' '\012' | $AWK ' 2071573Srgrimes BEGIN { 2081573Srgrimes printf("/* Automatically generated file, do not edit */\n"); 2091573Srgrimes printf("#define protected static\n"); 2101573Srgrimes printf("#define SCCSID\n"); 2111573Srgrimes } 2121573Srgrimes { 2131573Srgrimes printf("#include \"%s\"\n", $1); 21484260Sobrien }' 21584260Sobrien ;; 21684260Sobrien 21784260Sobrien# generate man page fragment from various .c files 21884260Sobrien# 21984260Sobrien-m) 22084260Sobrien cat $FILES | $AWK ' 22184260Sobrien BEGIN { 22284260Sobrien printf(".\\\" Section automatically generated with makelist\n"); 22384260Sobrien printf(".Bl -tag -width 4n\n"); 22484260Sobrien } 22584260Sobrien /\(\):/ { 22684260Sobrien pr = substr($2, 1, 2); 22784260Sobrien if (pr == "vi" || pr == "em" || pr == "ed") { 22884260Sobrien name = substr($2, 1, length($2) - 3); 22984260Sobrien fname = ""; 23084260Sobrien for (i = 1; i <= length(name); i++) { 23184260Sobrien s = substr(name, i, 1); 23284260Sobrien if (s == "_") 23384260Sobrien s = "-"; 23484260Sobrien fname = fname s; 23584260Sobrien } 23684260Sobrien 23784260Sobrien printf(".It Ic %s\n", fname); 23884260Sobrien ok = 1; 23984260Sobrien } 24084260Sobrien } 24184260Sobrien /^ \*/ { 24284260Sobrien if (ok) { 24384260Sobrien for (i = 2; i < NF; i++) 24484260Sobrien printf("%s ", $i); 24584260Sobrien printf("%s.\n", $i); 24684260Sobrien ok = 0; 24784260Sobrien } 24884260Sobrien } 24984260Sobrien END { 25084260Sobrien printf(".El\n"); 25184260Sobrien printf(".\\\" End of section automatically generated with makelist\n"); 25284260Sobrien }' 25384260Sobrien ;; 25484260Sobrien 2551573Srgrimes*) 2561573Srgrimes echo $USAGE 1>&2 25784260Sobrien exit 1 25884260Sobrien ;; 25984260Sobrien 2601573Srgrimesesac 261