makelist revision 95258
125184Sjkh#!/bin/sh - 225184Sjkh# $NetBSD: makelist,v 1.6 2000/09/04 23:45:18 lukem Exp $ 349122Sbrian# $FreeBSD: head/lib/libedit/makelist 95258 2002-04-22 13:44:47Z des $ 425184Sjkh# 525184Sjkh# Copyright (c) 1992, 1993 625184Sjkh# The Regents of the University of California. All rights reserved. 725184Sjkh# 825184Sjkh# This code is derived from software contributed to Berkeley by 925184Sjkh# Christos Zoulas of Cornell University. 1025184Sjkh# 1125184Sjkh# Redistribution and use in source and binary forms, with or without 1225184Sjkh# modification, are permitted provided that the following conditions 1325184Sjkh# are met: 1425184Sjkh# 1. Redistributions of source code must retain the above copyright 1525184Sjkh# notice, this list of conditions and the following disclaimer. 1625184Sjkh# 2. Redistributions in binary form must reproduce the above copyright 1725184Sjkh# notice, this list of conditions and the following disclaimer in the 1825184Sjkh# documentation and/or other materials provided with the distribution. 1925184Sjkh# 3. All advertising materials mentioning features or use of this software 2025184Sjkh# must display the following acknowledgement: 2125184Sjkh# This product includes software developed by the University of 2225184Sjkh# California, Berkeley and its contributors. 2325184Sjkh# 4. Neither the name of the University nor the names of its contributors 2425184Sjkh# may be used to endorse or promote products derived from this software 2525184Sjkh# without specific prior written permission. 2625184Sjkh# 2725184Sjkh# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2840006Sphk# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2940006Sphk# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3040006Sphk# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 3140006Sphk# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3240006Sphk# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3340006Sphk# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3442621Shm# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3542621Shm# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3642621Shm# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3742621Shm# SUCH DAMAGE. 3842621Shm# 3942627Sjoerg# @(#)makelist 5.3 (Berkeley) 6/4/93 4042627Sjoerg 4142627Sjoerg# makelist.sh: Automatically generate header files... 4242627Sjoerg 4342627SjoergAWK=/usr/bin/awk 4442627SjoergUSAGE="usage: $0 -h|-e|-fc|-fh|-bc|-bh|-m <filenames>" 4542627Sjoerg 4642627Sjoergif [ "x$1" = "x" ] 4742627Sjoergthen 4842627Sjoerg echo $USAGE 1>&2 4942627Sjoerg exit 1 5042627Sjoergfi 5142627Sjoerg 5242627SjoergFLAG="$1" 5325184Sjkhshift 5448687Speter 5548687SpeterFILES="$@" 5648687Speter 5748687Spetercase $FLAG in 5848662Speter 5925184Sjkh# generate foo.h file from foo.c 6033682Sbrian# 6148662Speter-h) 6225184Sjkh set - `echo $FILES | sed -e 's/\\./_/g'` 6325184Sjkh hdr="_h_`basename $1`" 6425184Sjkh cat $FILES | $AWK ' 6525184Sjkh BEGIN { 6648842Sjkh printf("/* Automatically generated file, do not edit */\n"); 6748842Sjkh printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'"); 6848842Sjkh } 6948842Sjkh /\(\):/ { 7048842Sjkh pr = substr($2, 1, 2); 7148842Sjkh if (pr == "vi" || pr == "em" || pr == "ed") { 7248662Speter name = substr($2, 1, length($2) - 3); 7325184Sjkh# 7425184Sjkh# XXX: need a space between name and prototype so that -fc and -fh 7525184Sjkh# parsing is much easier 7625184Sjkh# 7725184Sjkh printf("protected el_action_t\t%s (EditLine *, int);\n", name); 7825184Sjkh } 7925184Sjkh } 8025184Sjkh END { 8148662Speter printf("#endif /* %s */\n", "'$hdr'"); 8225184Sjkh }' 8325184Sjkh ;; 8425184Sjkh 8525184Sjkh# generate help.c from various .c files 8625184Sjkh# 8725184Sjkh-bc) 8825184Sjkh cat $FILES | $AWK ' 8925184Sjkh BEGIN { 9025184Sjkh printf("/* Automatically generated file, do not edit */\n"); 9148662Speter printf("#include \"sys.h\"\n#include \"el.h\"\n"); 9225184Sjkh printf("private const struct el_bindings_t el_func_help[] = {\n"); 9348662Speter low = "abcdefghijklmnopqrstuvwxyz_"; 9448662Speter high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; 9548662Speter for (i = 1; i <= length(low); i++) 9648662Speter tr[substr(low, i, 1)] = substr(high, i, 1); 9725184Sjkh } 9829300Sdanny /\(\):/ { 9949122Sbrian pr = substr($2, 1, 2); 10049122Sbrian if (pr == "vi" || pr == "em" || pr == "ed") { 10149122Sbrian name = substr($2, 1, length($2) - 3); 10249122Sbrian uname = ""; 10349122Sbrian fname = ""; 10449122Sbrian for (i = 1; i <= length(name); i++) { 10549122Sbrian s = substr(name, i, 1); 10649122Sbrian uname = uname tr[s]; 10749122Sbrian if (s == "_") 10849122Sbrian s = "-"; 10949122Sbrian fname = fname s; 11049122Sbrian } 11149122Sbrian 11249122Sbrian printf(" { %-30.30s %-30.30s\n","\"" fname "\",", uname ","); 11349122Sbrian ok = 1; 11449122Sbrian } 11549122Sbrian } 11629300Sdanny /^ \*/ { 11729300Sdanny if (ok) { 11829300Sdanny printf(" \""); 11932382Salex for (i = 2; i < NF; i++) 12032382Salex printf("%s ", $i); 12132382Salex printf("%s\" },\n", $i); 12229300Sdanny ok = 0; 12329300Sdanny } 12429300Sdanny } 12529300Sdanny END { 12641077Speter printf(" { NULL, 0, NULL }\n"); 12729300Sdanny printf("};\n"); 12829300Sdanny printf("\nprotected const el_bindings_t* help__get()"); 12929300Sdanny printf("{ return el_func_help; }\n"); 13029300Sdanny }' 13129300Sdanny ;; 13229300Sdanny 13329300Sdanny# generate help.h from various .c files 13429300Sdanny# 13529300Sdanny-bh) 13645542Sdes $AWK ' 13745542Sdes BEGIN { 13845542Sdes printf("/* Automatically generated file, do not edit */\n"); 13945542Sdes printf("#ifndef _h_help_c\n#define _h_help_c\n"); 14045542Sdes printf("protected const el_bindings_t *help__get(void);\n"); 14145622Sbrian printf("#endif /* _h_help_c */\n"); 14244992Sbrian }' /dev/null 14344992Sbrian ;; 14444992Sbrian 14544992Sbrian# generate fcns.h from various .h files 14644992Sbrian# 14744992Sbrian-fh) 14844992Sbrian cat $FILES | $AWK '/el_action_t/ { print $3 }' | \ 14944992Sbrian sort | tr '[a-z]' '[A-Z]' | $AWK ' 15044992Sbrian BEGIN { 15144992Sbrian printf("/* Automatically generated file, do not edit */\n"); 15244992Sbrian printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n"); 15344992Sbrian count = 0; 15429300Sdanny } 15533337Salex { 15633337Salex printf("#define\t%-30.30s\t%3d\n", $1, count++); 15733149Salex } 15833149Salex END { 15933149Salex printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count); 16033149Salex 16129300Sdanny printf("typedef el_action_t (*el_func_t)(EditLine *, int);"); 16225184Sjkh printf("\nprotected const el_func_t* func__get(void);\n"); 16325184Sjkh printf("#endif /* _h_fcns_c */\n"); 16440006Sphk }' 16540006Sphk ;; 16640006Sphk 16740006Sphk# generate fcns.c from various .h files 16840006Sphk# 16929300Sdanny-fc) 17029300Sdanny cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK ' 17125184Sjkh BEGIN { 17225184Sjkh printf("/* Automatically generated file, do not edit */\n"); 17325184Sjkh printf("#include \"sys.h\"\n#include \"el.h\"\n"); 17425184Sjkh printf("private const el_func_t el_func[] = {"); 17525184Sjkh maxlen = 80; 17625184Sjkh needn = 1; 17725184Sjkh len = 0; 17825184Sjkh } 17925184Sjkh { 18025184Sjkh clen = 25 + 2; 18125184Sjkh len += clen; 18225184Sjkh if (len >= maxlen) 18325184Sjkh needn = 1; 18425184Sjkh if (needn) { 18527218Spst printf("\n "); 18627218Spst needn = 0; 18747755Sbde len = 4 + clen; 18827218Spst } 18927218Spst s = $1 ","; 19045096Simp printf("%-26.26s ", s); 19145096Simp } 19247755Sbde END { 19347755Sbde printf("\n};\n"); 19445096Simp printf("\nprotected const el_func_t* func__get() { return el_func; }\n"); 19545096Simp }' 19639267Sjkoshy ;; 19739267Sjkoshy 19847755Sbde# generate editline.c from various .c files 19939267Sjkoshy# 20039267Sjkoshy-e) 20125184Sjkh echo "$FILES" | tr ' ' '\012' | $AWK ' 20225365Sjkh BEGIN { 20347755Sbde printf("/* Automatically generated file, do not edit */\n"); 20425184Sjkh printf("#define protected static\n"); 20525184Sjkh printf("#define SCCSID\n"); 20633439Sguido } 20733439Sguido { 20847755Sbde printf("#include \"%s\"\n", $1); 20933439Sguido }' 21033439Sguido ;; 21133439Sguido 21233439Sguido# generate man page fragment from various .c files 21347755Sbde# 21433439Sguido-m) 21533439Sguido cat $FILES | $AWK ' 21647752Sphk BEGIN { 21747752Sphk printf(".\\\" Section automatically generated with makelist\n"); 21847755Sbde printf(".Bl -tag -width 4n\n"); 21947752Sphk } 22047752Sphk /\(\):/ { 22125184Sjkh pr = substr($2, 1, 2); 22225365Sjkh if (pr == "vi" || pr == "em" || pr == "ed") { 22347755Sbde name = substr($2, 1, length($2) - 3); 22425184Sjkh fname = ""; 22525184Sjkh for (i = 1; i <= length(name); i++) { 22636174Sjkh s = substr(name, i, 1); 22747755Sbde if (s == "_") 22847755Sbde s = "-"; 22936174Sjkh fname = fname s; 23036174Sjkh } 23136174Sjkh 23236174Sjkh printf(".It Ic %s\n", fname); 23336174Sjkh ok = 1; 23436174Sjkh } 23536174Sjkh } 23636174Sjkh /^ \*/ { 23725184Sjkh if (ok) { 23836174Sjkh for (i = 2; i < NF; i++) 23925184Sjkh printf("%s ", $i); 24025184Sjkh printf("%s.\n", $i); 24125765Sjkh ok = 0; 24236174Sjkh } 24336174Sjkh } 24425765Sjkh END { 24536174Sjkh printf(".El\n"); 24634395Sjkh printf(".\\\" End of section automatically generated with makelist\n"); 24734395Sjkh }' 24834395Sjkh ;; 24925184Sjkh 25025184Sjkh*) 25125184Sjkh echo $USAGE 1>&2 25225184Sjkh exit 1 25325184Sjkh ;; 25425184Sjkh 25525184Sjkhesac 25632949Swollman