11573Srgrimes#!/bin/sh - 2238624Spfg# $NetBSD: makelist,v 1.11 2005/10/22 16:45:03 christos Exp $ 384260Sobrien# $FreeBSD$ 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 4095258SdesUSAGE="usage: $0 -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# 571573Srgrimes-h) 5884260Sobrien set - `echo $FILES | sed -e 's/\\./_/g'` 5984260Sobrien hdr="_h_`basename $1`" 601573Srgrimes cat $FILES | $AWK ' 611573Srgrimes BEGIN { 621573Srgrimes printf("/* Automatically generated file, do not edit */\n"); 631573Srgrimes printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'"); 641573Srgrimes } 651573Srgrimes /\(\):/ { 661573Srgrimes pr = substr($2, 1, 2); 671573Srgrimes if (pr == "vi" || pr == "em" || pr == "ed") { 681573Srgrimes name = substr($2, 1, length($2) - 3); 6984260Sobrien# 7084260Sobrien# XXX: need a space between name and prototype so that -fc and -fh 7184260Sobrien# parsing is much easier 7284260Sobrien# 7384260Sobrien printf("protected el_action_t\t%s (EditLine *, int);\n", name); 741573Srgrimes } 751573Srgrimes } 761573Srgrimes END { 771573Srgrimes printf("#endif /* %s */\n", "'$hdr'"); 7884260Sobrien }' 7984260Sobrien ;; 8084260Sobrien 8184260Sobrien# generate help.c from various .c files 8284260Sobrien# 831573Srgrimes-bc) 841573Srgrimes cat $FILES | $AWK ' 851573Srgrimes BEGIN { 861573Srgrimes printf("/* Automatically generated file, do not edit */\n"); 871573Srgrimes printf("#include \"sys.h\"\n#include \"el.h\"\n"); 8884260Sobrien printf("private const struct el_bindings_t el_func_help[] = {\n"); 891573Srgrimes low = "abcdefghijklmnopqrstuvwxyz_"; 901573Srgrimes high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; 911573Srgrimes for (i = 1; i <= length(low); i++) 921573Srgrimes tr[substr(low, i, 1)] = substr(high, i, 1); 931573Srgrimes } 941573Srgrimes /\(\):/ { 951573Srgrimes pr = substr($2, 1, 2); 961573Srgrimes if (pr == "vi" || pr == "em" || pr == "ed") { 971573Srgrimes name = substr($2, 1, length($2) - 3); 981573Srgrimes uname = ""; 991573Srgrimes fname = ""; 1001573Srgrimes for (i = 1; i <= length(name); i++) { 1011573Srgrimes s = substr(name, i, 1); 1021573Srgrimes uname = uname tr[s]; 1031573Srgrimes if (s == "_") 1041573Srgrimes s = "-"; 1051573Srgrimes fname = fname s; 1061573Srgrimes } 10784260Sobrien 1081573Srgrimes printf(" { %-30.30s %-30.30s\n","\"" fname "\",", uname ","); 10984260Sobrien ok = 1; 1101573Srgrimes } 1111573Srgrimes } 1121573Srgrimes /^ \*/ { 1131573Srgrimes if (ok) { 1141573Srgrimes printf(" \""); 1151573Srgrimes for (i = 2; i < NF; i++) 1161573Srgrimes printf("%s ", $i); 1171573Srgrimes printf("%s\" },\n", $i); 1181573Srgrimes ok = 0; 1191573Srgrimes } 1201573Srgrimes } 1211573Srgrimes END { 1221573Srgrimes printf("};\n"); 12384260Sobrien printf("\nprotected const el_bindings_t* help__get()"); 1241573Srgrimes printf("{ return el_func_help; }\n"); 12584260Sobrien }' 12684260Sobrien ;; 12784260Sobrien 12884260Sobrien# generate help.h from various .c files 12984260Sobrien# 1301573Srgrimes-bh) 1311573Srgrimes $AWK ' 13284260Sobrien BEGIN { 1331573Srgrimes printf("/* Automatically generated file, do not edit */\n"); 1341573Srgrimes printf("#ifndef _h_help_c\n#define _h_help_c\n"); 13584260Sobrien printf("protected const el_bindings_t *help__get(void);\n"); 1361573Srgrimes printf("#endif /* _h_help_c */\n"); 13784260Sobrien }' /dev/null 13884260Sobrien ;; 13984260Sobrien 14084260Sobrien# generate fcns.h from various .h files 14184260Sobrien# 1421573Srgrimes-fh) 1431573Srgrimes cat $FILES | $AWK '/el_action_t/ { print $3 }' | \ 144238624Spfg sort | LC_ALL=C tr '[:lower:]' '[:upper:]' | $AWK ' 14584260Sobrien BEGIN { 1461573Srgrimes printf("/* Automatically generated file, do not edit */\n"); 1471573Srgrimes printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n"); 14884260Sobrien count = 0; 1491573Srgrimes } 15084260Sobrien { 1511573Srgrimes printf("#define\t%-30.30s\t%3d\n", $1, count++); 1521573Srgrimes } 1531573Srgrimes END { 1541573Srgrimes printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count); 1551573Srgrimes 15684260Sobrien printf("typedef el_action_t (*el_func_t)(EditLine *, int);"); 15784260Sobrien printf("\nprotected const el_func_t* func__get(void);\n"); 1581573Srgrimes printf("#endif /* _h_fcns_c */\n"); 15984260Sobrien }' 16084260Sobrien ;; 16184260Sobrien 16284260Sobrien# generate fcns.c from various .h files 16384260Sobrien# 1641573Srgrimes-fc) 1651573Srgrimes cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK ' 1661573Srgrimes BEGIN { 1671573Srgrimes printf("/* Automatically generated file, do not edit */\n"); 1681573Srgrimes printf("#include \"sys.h\"\n#include \"el.h\"\n"); 16984260Sobrien printf("private const el_func_t el_func[] = {"); 1701573Srgrimes maxlen = 80; 1711573Srgrimes needn = 1; 1721573Srgrimes len = 0; 1731573Srgrimes } 1741573Srgrimes { 1751573Srgrimes clen = 25 + 2; 1761573Srgrimes len += clen; 17784260Sobrien if (len >= maxlen) 1781573Srgrimes needn = 1; 1791573Srgrimes if (needn) { 1801573Srgrimes printf("\n "); 1811573Srgrimes needn = 0; 1821573Srgrimes len = 4 + clen; 1831573Srgrimes } 1841573Srgrimes s = $1 ","; 1851573Srgrimes printf("%-26.26s ", s); 1861573Srgrimes } 1871573Srgrimes END { 1881573Srgrimes printf("\n};\n"); 18984260Sobrien printf("\nprotected const el_func_t* func__get() { return el_func; }\n"); 19084260Sobrien }' 19184260Sobrien ;; 19284260Sobrien 19384260Sobrien# generate editline.c from various .c files 19484260Sobrien# 1951573Srgrimes-e) 1961573Srgrimes echo "$FILES" | tr ' ' '\012' | $AWK ' 1971573Srgrimes BEGIN { 1981573Srgrimes printf("/* Automatically generated file, do not edit */\n"); 1991573Srgrimes printf("#define protected static\n"); 2001573Srgrimes printf("#define SCCSID\n"); 2011573Srgrimes } 2021573Srgrimes { 2031573Srgrimes printf("#include \"%s\"\n", $1); 20484260Sobrien }' 20584260Sobrien ;; 20684260Sobrien 20784260Sobrien# generate man page fragment from various .c files 20884260Sobrien# 20984260Sobrien-m) 21084260Sobrien cat $FILES | $AWK ' 21184260Sobrien BEGIN { 21284260Sobrien printf(".\\\" Section automatically generated with makelist\n"); 21384260Sobrien printf(".Bl -tag -width 4n\n"); 21484260Sobrien } 21584260Sobrien /\(\):/ { 21684260Sobrien pr = substr($2, 1, 2); 21784260Sobrien if (pr == "vi" || pr == "em" || pr == "ed") { 21884260Sobrien name = substr($2, 1, length($2) - 3); 21984260Sobrien fname = ""; 22084260Sobrien for (i = 1; i <= length(name); i++) { 22184260Sobrien s = substr(name, i, 1); 22284260Sobrien if (s == "_") 22384260Sobrien s = "-"; 22484260Sobrien fname = fname s; 22584260Sobrien } 22684260Sobrien 22784260Sobrien printf(".It Ic %s\n", fname); 22884260Sobrien ok = 1; 22984260Sobrien } 23084260Sobrien } 23184260Sobrien /^ \*/ { 23284260Sobrien if (ok) { 23384260Sobrien for (i = 2; i < NF; i++) 23484260Sobrien printf("%s ", $i); 23584260Sobrien printf("%s.\n", $i); 23684260Sobrien ok = 0; 23784260Sobrien } 23884260Sobrien } 23984260Sobrien END { 24084260Sobrien printf(".El\n"); 24184260Sobrien printf(".\\\" End of section automatically generated with makelist\n"); 24284260Sobrien }' 24384260Sobrien ;; 24484260Sobrien 2451573Srgrimes*) 2461573Srgrimes echo $USAGE 1>&2 24784260Sobrien exit 1 24884260Sobrien ;; 24984260Sobrien 2501573Srgrimesesac 251