makelist revision 1.7
11.1Scgd#!/bin/sh - 21.7Sjdolecek# $NetBSD: makelist,v 1.7 2001/01/09 19:22:31 jdolecek Exp $ 31.1Scgd# 41.1Scgd# Copyright (c) 1992, 1993 51.1Scgd# The Regents of the University of California. All rights reserved. 61.1Scgd# 71.1Scgd# This code is derived from software contributed to Berkeley by 81.1Scgd# Christos Zoulas of Cornell University. 91.1Scgd# 101.1Scgd# Redistribution and use in source and binary forms, with or without 111.1Scgd# modification, are permitted provided that the following conditions 121.1Scgd# are met: 131.1Scgd# 1. Redistributions of source code must retain the above copyright 141.1Scgd# notice, this list of conditions and the following disclaimer. 151.1Scgd# 2. Redistributions in binary form must reproduce the above copyright 161.1Scgd# notice, this list of conditions and the following disclaimer in the 171.1Scgd# documentation and/or other materials provided with the distribution. 181.1Scgd# 3. All advertising materials mentioning features or use of this software 191.1Scgd# must display the following acknowledgement: 201.1Scgd# This product includes software developed by the University of 211.1Scgd# California, Berkeley and its contributors. 221.1Scgd# 4. Neither the name of the University nor the names of its contributors 231.1Scgd# may be used to endorse or promote products derived from this software 241.1Scgd# without specific prior written permission. 251.1Scgd# 261.1Scgd# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 271.1Scgd# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 281.1Scgd# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 291.1Scgd# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 301.1Scgd# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 311.1Scgd# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 321.1Scgd# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 331.1Scgd# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 341.1Scgd# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 351.1Scgd# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 361.1Scgd# SUCH DAMAGE. 371.1Scgd# 381.1Scgd# @(#)makelist 5.3 (Berkeley) 6/4/93 391.1Scgd 401.1Scgd# makelist.sh: Automatically generate header files... 411.1Scgd 421.1ScgdAWK=/usr/bin/awk 431.5SlukemUSAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh|-m <filenames>" 441.1Scgd 451.1Scgdif [ "x$1" = "x" ] 461.1Scgdthen 471.1Scgd echo $USAGE 1>&2 481.1Scgd exit 1 491.1Scgdfi 501.1Scgd 511.1ScgdFLAG="$1" 521.1Scgdshift 531.1Scgd 541.1ScgdFILES="$@" 551.1Scgd 561.1Scgdcase $FLAG in 571.5Slukem 581.5Slukem# generate foo.h file from foo.c 591.5Slukem# 601.1Scgd-h) 611.2Scgd set - `echo $FILES | sed -e 's/\\./_/g'` 621.2Scgd hdr="_h_`basename $1`" 631.1Scgd cat $FILES | $AWK ' 641.1Scgd BEGIN { 651.1Scgd printf("/* Automatically generated file, do not edit */\n"); 661.1Scgd printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'"); 671.1Scgd } 681.1Scgd /\(\):/ { 691.1Scgd pr = substr($2, 1, 2); 701.1Scgd if (pr == "vi" || pr == "em" || pr == "ed") { 711.1Scgd name = substr($2, 1, length($2) - 3); 721.6Slukem# 731.6Slukem# XXX: need a space between name and prototype so that -fc and -fh 741.6Slukem# parsing is much easier 751.6Slukem# 761.6Slukem printf("protected el_action_t\t%s (EditLine *, int);\n", name); 771.1Scgd } 781.1Scgd } 791.1Scgd END { 801.1Scgd printf("#endif /* %s */\n", "'$hdr'"); 811.5Slukem }' 821.5Slukem ;; 831.5Slukem 841.5Slukem# generate help.c from various .c files 851.5Slukem# 861.1Scgd-bc) 871.1Scgd cat $FILES | $AWK ' 881.1Scgd BEGIN { 891.1Scgd printf("/* Automatically generated file, do not edit */\n"); 901.1Scgd printf("#include \"sys.h\"\n#include \"el.h\"\n"); 911.7Sjdolecek printf("private const struct el_bindings_t el_func_help[] = {\n"); 921.1Scgd low = "abcdefghijklmnopqrstuvwxyz_"; 931.1Scgd high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; 941.1Scgd for (i = 1; i <= length(low); i++) 951.1Scgd tr[substr(low, i, 1)] = substr(high, i, 1); 961.1Scgd } 971.1Scgd /\(\):/ { 981.1Scgd pr = substr($2, 1, 2); 991.1Scgd if (pr == "vi" || pr == "em" || pr == "ed") { 1001.1Scgd name = substr($2, 1, length($2) - 3); 1011.1Scgd uname = ""; 1021.1Scgd fname = ""; 1031.1Scgd for (i = 1; i <= length(name); i++) { 1041.1Scgd s = substr(name, i, 1); 1051.1Scgd uname = uname tr[s]; 1061.1Scgd if (s == "_") 1071.1Scgd s = "-"; 1081.1Scgd fname = fname s; 1091.1Scgd } 1101.4Ssimonb 1111.1Scgd printf(" { %-30.30s %-30.30s\n","\"" fname "\",", uname ","); 1121.4Ssimonb ok = 1; 1131.1Scgd } 1141.1Scgd } 1151.1Scgd /^ \*/ { 1161.1Scgd if (ok) { 1171.1Scgd printf(" \""); 1181.1Scgd for (i = 2; i < NF; i++) 1191.1Scgd printf("%s ", $i); 1201.1Scgd printf("%s\" },\n", $i); 1211.1Scgd ok = 0; 1221.1Scgd } 1231.1Scgd } 1241.1Scgd END { 1251.1Scgd printf(" { NULL, 0, NULL }\n"); 1261.1Scgd printf("};\n"); 1271.7Sjdolecek printf("\nprotected const el_bindings_t* help__get()"); 1281.1Scgd printf("{ return el_func_help; }\n"); 1291.5Slukem }' 1301.5Slukem ;; 1311.5Slukem 1321.5Slukem# generate help.h from various .c files 1331.5Slukem# 1341.1Scgd-bh) 1351.1Scgd $AWK ' 1361.4Ssimonb BEGIN { 1371.1Scgd printf("/* Automatically generated file, do not edit */\n"); 1381.1Scgd printf("#ifndef _h_help_c\n#define _h_help_c\n"); 1391.7Sjdolecek printf("protected const el_bindings_t *help__get(void);\n"); 1401.1Scgd printf("#endif /* _h_help_c */\n"); 1411.5Slukem }' /dev/null 1421.5Slukem ;; 1431.5Slukem 1441.6Slukem# generate fcns.h from various .h files 1451.5Slukem# 1461.1Scgd-fh) 1471.1Scgd cat $FILES | $AWK '/el_action_t/ { print $3 }' | \ 1481.1Scgd sort | tr '[a-z]' '[A-Z]' | $AWK ' 1491.4Ssimonb BEGIN { 1501.1Scgd printf("/* Automatically generated file, do not edit */\n"); 1511.1Scgd printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n"); 1521.4Ssimonb count = 0; 1531.1Scgd } 1541.4Ssimonb { 1551.1Scgd printf("#define\t%-30.30s\t%3d\n", $1, count++); 1561.1Scgd } 1571.1Scgd END { 1581.1Scgd printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count); 1591.1Scgd 1601.6Slukem printf("typedef el_action_t (*el_func_t)(EditLine *, int);"); 1611.7Sjdolecek printf("\nprotected const el_func_t* func__get(void);\n"); 1621.1Scgd printf("#endif /* _h_fcns_c */\n"); 1631.5Slukem }' 1641.5Slukem ;; 1651.5Slukem 1661.6Slukem# generate fcns.c from various .h files 1671.5Slukem# 1681.1Scgd-fc) 1691.1Scgd cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK ' 1701.1Scgd BEGIN { 1711.1Scgd printf("/* Automatically generated file, do not edit */\n"); 1721.1Scgd printf("#include \"sys.h\"\n#include \"el.h\"\n"); 1731.7Sjdolecek printf("private const el_func_t el_func[] = {"); 1741.1Scgd maxlen = 80; 1751.1Scgd needn = 1; 1761.1Scgd len = 0; 1771.1Scgd } 1781.1Scgd { 1791.1Scgd clen = 25 + 2; 1801.1Scgd len += clen; 1811.4Ssimonb if (len >= maxlen) 1821.1Scgd needn = 1; 1831.1Scgd if (needn) { 1841.1Scgd printf("\n "); 1851.1Scgd needn = 0; 1861.1Scgd len = 4 + clen; 1871.1Scgd } 1881.1Scgd s = $1 ","; 1891.1Scgd printf("%-26.26s ", s); 1901.1Scgd } 1911.1Scgd END { 1921.1Scgd printf("\n};\n"); 1931.7Sjdolecek printf("\nprotected const el_func_t* func__get() { return el_func; }\n"); 1941.5Slukem }' 1951.5Slukem ;; 1961.5Slukem 1971.5Slukem# generate editline.c from various .c files 1981.5Slukem# 1991.1Scgd-e) 2001.1Scgd echo "$FILES" | tr ' ' '\012' | $AWK ' 2011.1Scgd BEGIN { 2021.1Scgd printf("/* Automatically generated file, do not edit */\n"); 2031.1Scgd printf("#define protected static\n"); 2041.1Scgd printf("#define SCCSID\n"); 2051.1Scgd } 2061.1Scgd { 2071.1Scgd printf("#include \"%s\"\n", $1); 2081.5Slukem }' 2091.5Slukem ;; 2101.5Slukem 2111.5Slukem# generate man page fragment from various .c files 2121.5Slukem# 2131.5Slukem-m) 2141.5Slukem cat $FILES | $AWK ' 2151.5Slukem BEGIN { 2161.5Slukem printf(".\\\" Section automatically generated with makelist\n"); 2171.5Slukem printf(".Bl -tag -width 4n\n"); 2181.5Slukem } 2191.5Slukem /\(\):/ { 2201.5Slukem pr = substr($2, 1, 2); 2211.5Slukem if (pr == "vi" || pr == "em" || pr == "ed") { 2221.5Slukem name = substr($2, 1, length($2) - 3); 2231.5Slukem fname = ""; 2241.5Slukem for (i = 1; i <= length(name); i++) { 2251.5Slukem s = substr(name, i, 1); 2261.5Slukem if (s == "_") 2271.5Slukem s = "-"; 2281.5Slukem fname = fname s; 2291.5Slukem } 2301.5Slukem 2311.5Slukem printf(".It Ic %s\n", fname); 2321.5Slukem ok = 1; 2331.5Slukem } 2341.5Slukem } 2351.5Slukem /^ \*/ { 2361.5Slukem if (ok) { 2371.5Slukem for (i = 2; i < NF; i++) 2381.5Slukem printf("%s ", $i); 2391.5Slukem printf("%s.\n", $i); 2401.5Slukem ok = 0; 2411.5Slukem } 2421.5Slukem } 2431.5Slukem END { 2441.5Slukem printf(".El\n"); 2451.5Slukem printf(".\\\" End of section automatically generated with makelist\n"); 2461.5Slukem }' 2471.5Slukem ;; 2481.5Slukem 2491.1Scgd*) 2501.1Scgd echo $USAGE 1>&2 2511.5Slukem exit 1 2521.5Slukem ;; 2531.5Slukem 2541.1Scgdesac 255