makelist revision 1.12
11.1Scgd#!/bin/sh - 21.12Ssketch# $NetBSD: makelist,v 1.12 2009/02/12 13:39:49 sketch 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.9Slukem# 3. Neither the name of the University nor the names of its contributors 191.1Scgd# may be used to endorse or promote products derived from this software 201.1Scgd# without specific prior written permission. 211.1Scgd# 221.1Scgd# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231.1Scgd# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241.1Scgd# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251.1Scgd# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261.1Scgd# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271.1Scgd# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281.1Scgd# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291.1Scgd# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301.1Scgd# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311.1Scgd# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321.1Scgd# SUCH DAMAGE. 331.1Scgd# 341.1Scgd# @(#)makelist 5.3 (Berkeley) 6/4/93 351.1Scgd 361.1Scgd# makelist.sh: Automatically generate header files... 371.1Scgd 381.8SchristosAWK=awk 391.5SlukemUSAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh|-m <filenames>" 401.1Scgd 411.1Scgdif [ "x$1" = "x" ] 421.1Scgdthen 431.1Scgd echo $USAGE 1>&2 441.1Scgd exit 1 451.1Scgdfi 461.1Scgd 471.1ScgdFLAG="$1" 481.1Scgdshift 491.1Scgd 501.1ScgdFILES="$@" 511.1Scgd 521.1Scgdcase $FLAG in 531.5Slukem 541.5Slukem# generate foo.h file from foo.c 551.5Slukem# 561.1Scgd-h) 571.2Scgd set - `echo $FILES | sed -e 's/\\./_/g'` 581.2Scgd hdr="_h_`basename $1`" 591.1Scgd cat $FILES | $AWK ' 601.1Scgd BEGIN { 611.1Scgd printf("/* Automatically generated file, do not edit */\n"); 621.1Scgd printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'"); 631.1Scgd } 641.1Scgd /\(\):/ { 651.1Scgd pr = substr($2, 1, 2); 661.1Scgd if (pr == "vi" || pr == "em" || pr == "ed") { 671.1Scgd name = substr($2, 1, length($2) - 3); 681.6Slukem# 691.6Slukem# XXX: need a space between name and prototype so that -fc and -fh 701.6Slukem# parsing is much easier 711.6Slukem# 721.6Slukem printf("protected el_action_t\t%s (EditLine *, int);\n", name); 731.1Scgd } 741.1Scgd } 751.1Scgd END { 761.1Scgd printf("#endif /* %s */\n", "'$hdr'"); 771.5Slukem }' 781.5Slukem ;; 791.5Slukem 801.5Slukem# generate help.c from various .c files 811.5Slukem# 821.1Scgd-bc) 831.1Scgd cat $FILES | $AWK ' 841.1Scgd BEGIN { 851.1Scgd printf("/* Automatically generated file, do not edit */\n"); 861.12Ssketch printf("#include \"config.h\"\n#include \"el.h\"\n"); 871.7Sjdolecek printf("private const struct el_bindings_t el_func_help[] = {\n"); 881.1Scgd low = "abcdefghijklmnopqrstuvwxyz_"; 891.1Scgd high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; 901.1Scgd for (i = 1; i <= length(low); i++) 911.1Scgd tr[substr(low, i, 1)] = substr(high, i, 1); 921.1Scgd } 931.1Scgd /\(\):/ { 941.1Scgd pr = substr($2, 1, 2); 951.1Scgd if (pr == "vi" || pr == "em" || pr == "ed") { 961.1Scgd name = substr($2, 1, length($2) - 3); 971.1Scgd uname = ""; 981.1Scgd fname = ""; 991.1Scgd for (i = 1; i <= length(name); i++) { 1001.1Scgd s = substr(name, i, 1); 1011.1Scgd uname = uname tr[s]; 1021.1Scgd if (s == "_") 1031.1Scgd s = "-"; 1041.1Scgd fname = fname s; 1051.1Scgd } 1061.4Ssimonb 1071.1Scgd printf(" { %-30.30s %-30.30s\n","\"" fname "\",", uname ","); 1081.4Ssimonb ok = 1; 1091.1Scgd } 1101.1Scgd } 1111.1Scgd /^ \*/ { 1121.1Scgd if (ok) { 1131.1Scgd printf(" \""); 1141.1Scgd for (i = 2; i < NF; i++) 1151.1Scgd printf("%s ", $i); 1161.1Scgd printf("%s\" },\n", $i); 1171.1Scgd ok = 0; 1181.1Scgd } 1191.1Scgd } 1201.1Scgd END { 1211.1Scgd printf("};\n"); 1221.7Sjdolecek printf("\nprotected const el_bindings_t* help__get()"); 1231.1Scgd printf("{ return el_func_help; }\n"); 1241.5Slukem }' 1251.5Slukem ;; 1261.5Slukem 1271.5Slukem# generate help.h from various .c files 1281.5Slukem# 1291.1Scgd-bh) 1301.1Scgd $AWK ' 1311.4Ssimonb BEGIN { 1321.1Scgd printf("/* Automatically generated file, do not edit */\n"); 1331.1Scgd printf("#ifndef _h_help_c\n#define _h_help_c\n"); 1341.7Sjdolecek printf("protected const el_bindings_t *help__get(void);\n"); 1351.1Scgd printf("#endif /* _h_help_c */\n"); 1361.5Slukem }' /dev/null 1371.5Slukem ;; 1381.5Slukem 1391.6Slukem# generate fcns.h from various .h files 1401.5Slukem# 1411.1Scgd-fh) 1421.1Scgd cat $FILES | $AWK '/el_action_t/ { print $3 }' | \ 1431.11Schristos sort | tr '[:lower:]' '[:upper:]' | $AWK ' 1441.4Ssimonb BEGIN { 1451.1Scgd printf("/* Automatically generated file, do not edit */\n"); 1461.1Scgd printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n"); 1471.4Ssimonb count = 0; 1481.1Scgd } 1491.4Ssimonb { 1501.1Scgd printf("#define\t%-30.30s\t%3d\n", $1, count++); 1511.1Scgd } 1521.1Scgd END { 1531.1Scgd printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count); 1541.1Scgd 1551.6Slukem printf("typedef el_action_t (*el_func_t)(EditLine *, int);"); 1561.7Sjdolecek printf("\nprotected const el_func_t* func__get(void);\n"); 1571.1Scgd printf("#endif /* _h_fcns_c */\n"); 1581.5Slukem }' 1591.5Slukem ;; 1601.5Slukem 1611.6Slukem# generate fcns.c from various .h files 1621.5Slukem# 1631.1Scgd-fc) 1641.1Scgd cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK ' 1651.1Scgd BEGIN { 1661.1Scgd printf("/* Automatically generated file, do not edit */\n"); 1671.12Ssketch printf("#include \"config.h\"\n#include \"el.h\"\n"); 1681.7Sjdolecek printf("private const el_func_t el_func[] = {"); 1691.1Scgd maxlen = 80; 1701.1Scgd needn = 1; 1711.1Scgd len = 0; 1721.1Scgd } 1731.1Scgd { 1741.1Scgd clen = 25 + 2; 1751.1Scgd len += clen; 1761.4Ssimonb if (len >= maxlen) 1771.1Scgd needn = 1; 1781.1Scgd if (needn) { 1791.1Scgd printf("\n "); 1801.1Scgd needn = 0; 1811.1Scgd len = 4 + clen; 1821.1Scgd } 1831.1Scgd s = $1 ","; 1841.1Scgd printf("%-26.26s ", s); 1851.1Scgd } 1861.1Scgd END { 1871.1Scgd printf("\n};\n"); 1881.7Sjdolecek printf("\nprotected const el_func_t* func__get() { return el_func; }\n"); 1891.5Slukem }' 1901.5Slukem ;; 1911.5Slukem 1921.5Slukem# generate editline.c from various .c files 1931.5Slukem# 1941.1Scgd-e) 1951.1Scgd echo "$FILES" | tr ' ' '\012' | $AWK ' 1961.1Scgd BEGIN { 1971.1Scgd printf("/* Automatically generated file, do not edit */\n"); 1981.1Scgd printf("#define protected static\n"); 1991.1Scgd printf("#define SCCSID\n"); 2001.1Scgd } 2011.1Scgd { 2021.1Scgd printf("#include \"%s\"\n", $1); 2031.5Slukem }' 2041.5Slukem ;; 2051.5Slukem 2061.5Slukem# generate man page fragment from various .c files 2071.5Slukem# 2081.5Slukem-m) 2091.5Slukem cat $FILES | $AWK ' 2101.5Slukem BEGIN { 2111.5Slukem printf(".\\\" Section automatically generated with makelist\n"); 2121.5Slukem printf(".Bl -tag -width 4n\n"); 2131.5Slukem } 2141.5Slukem /\(\):/ { 2151.5Slukem pr = substr($2, 1, 2); 2161.5Slukem if (pr == "vi" || pr == "em" || pr == "ed") { 2171.5Slukem name = substr($2, 1, length($2) - 3); 2181.5Slukem fname = ""; 2191.5Slukem for (i = 1; i <= length(name); i++) { 2201.5Slukem s = substr(name, i, 1); 2211.5Slukem if (s == "_") 2221.5Slukem s = "-"; 2231.5Slukem fname = fname s; 2241.5Slukem } 2251.5Slukem 2261.5Slukem printf(".It Ic %s\n", fname); 2271.5Slukem ok = 1; 2281.5Slukem } 2291.5Slukem } 2301.5Slukem /^ \*/ { 2311.5Slukem if (ok) { 2321.5Slukem for (i = 2; i < NF; i++) 2331.5Slukem printf("%s ", $i); 2341.5Slukem printf("%s.\n", $i); 2351.5Slukem ok = 0; 2361.5Slukem } 2371.5Slukem } 2381.5Slukem END { 2391.5Slukem printf(".El\n"); 2401.5Slukem printf(".\\\" End of section automatically generated with makelist\n"); 2411.5Slukem }' 2421.5Slukem ;; 2431.5Slukem 2441.1Scgd*) 2451.1Scgd echo $USAGE 1>&2 2461.5Slukem exit 1 2471.5Slukem ;; 2481.5Slukem 2491.1Scgdesac 250