makelist revision 1.13
11.1Scgd#!/bin/sh - 21.13Schristos# $NetBSD: makelist,v 1.13 2009/12/30 22:37:40 christos 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.13SchristosUSAGE="Usage: $0 -t <def>|-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.13Schristos-t) 571.13Schristos cat << _EOF 581.13Schristos#define ${FILES} 591.13Schristos#include "tokenizer.c" 601.13Schristos_EOF 611.13Schristos ;; 621.13Schristos 631.1Scgd-h) 641.2Scgd set - `echo $FILES | sed -e 's/\\./_/g'` 651.13Schristos hdr="_h_$(basename $1)" 661.1Scgd cat $FILES | $AWK ' 671.1Scgd BEGIN { 681.1Scgd printf("/* Automatically generated file, do not edit */\n"); 691.1Scgd printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'"); 701.1Scgd } 711.1Scgd /\(\):/ { 721.1Scgd pr = substr($2, 1, 2); 731.1Scgd if (pr == "vi" || pr == "em" || pr == "ed") { 741.1Scgd name = substr($2, 1, length($2) - 3); 751.6Slukem# 761.6Slukem# XXX: need a space between name and prototype so that -fc and -fh 771.6Slukem# parsing is much easier 781.6Slukem# 791.13Schristos printf("protected el_action_t\t%s (EditLine *, wint_t);\n", name); 801.1Scgd } 811.1Scgd } 821.1Scgd END { 831.1Scgd printf("#endif /* %s */\n", "'$hdr'"); 841.5Slukem }' 851.5Slukem ;; 861.5Slukem 871.5Slukem# generate help.c from various .c files 881.5Slukem# 891.1Scgd-bc) 901.1Scgd cat $FILES | $AWK ' 911.1Scgd BEGIN { 921.1Scgd printf("/* Automatically generated file, do not edit */\n"); 931.12Ssketch printf("#include \"config.h\"\n#include \"el.h\"\n"); 941.13Schristos printf("#include \"chartype.h\"\n"); 951.7Sjdolecek printf("private const struct el_bindings_t el_func_help[] = {\n"); 961.1Scgd low = "abcdefghijklmnopqrstuvwxyz_"; 971.1Scgd high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; 981.1Scgd for (i = 1; i <= length(low); i++) 991.1Scgd tr[substr(low, i, 1)] = substr(high, i, 1); 1001.1Scgd } 1011.1Scgd /\(\):/ { 1021.1Scgd pr = substr($2, 1, 2); 1031.1Scgd if (pr == "vi" || pr == "em" || pr == "ed") { 1041.1Scgd name = substr($2, 1, length($2) - 3); 1051.1Scgd uname = ""; 1061.1Scgd fname = ""; 1071.1Scgd for (i = 1; i <= length(name); i++) { 1081.1Scgd s = substr(name, i, 1); 1091.1Scgd uname = uname tr[s]; 1101.1Scgd if (s == "_") 1111.1Scgd s = "-"; 1121.1Scgd fname = fname s; 1131.1Scgd } 1141.4Ssimonb 1151.13Schristos printf(" { %-30.30s %-30.30s\n","STR(\"" fname "\"),", uname ","); 1161.4Ssimonb ok = 1; 1171.1Scgd } 1181.1Scgd } 1191.1Scgd /^ \*/ { 1201.1Scgd if (ok) { 1211.13Schristos printf(" STR(\""); 1221.1Scgd for (i = 2; i < NF; i++) 1231.1Scgd printf("%s ", $i); 1241.13Schristos printf("%s\") },\n", $i); 1251.1Scgd ok = 0; 1261.1Scgd } 1271.1Scgd } 1281.1Scgd END { 1291.1Scgd printf("};\n"); 1301.7Sjdolecek printf("\nprotected const el_bindings_t* help__get()"); 1311.1Scgd printf("{ return el_func_help; }\n"); 1321.5Slukem }' 1331.5Slukem ;; 1341.5Slukem 1351.5Slukem# generate help.h from various .c files 1361.5Slukem# 1371.1Scgd-bh) 1381.1Scgd $AWK ' 1391.4Ssimonb BEGIN { 1401.1Scgd printf("/* Automatically generated file, do not edit */\n"); 1411.1Scgd printf("#ifndef _h_help_c\n#define _h_help_c\n"); 1421.7Sjdolecek printf("protected const el_bindings_t *help__get(void);\n"); 1431.1Scgd printf("#endif /* _h_help_c */\n"); 1441.5Slukem }' /dev/null 1451.5Slukem ;; 1461.5Slukem 1471.6Slukem# generate fcns.h from various .h files 1481.5Slukem# 1491.1Scgd-fh) 1501.1Scgd cat $FILES | $AWK '/el_action_t/ { print $3 }' | \ 1511.11Schristos sort | tr '[:lower:]' '[:upper:]' | $AWK ' 1521.4Ssimonb BEGIN { 1531.1Scgd printf("/* Automatically generated file, do not edit */\n"); 1541.1Scgd printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n"); 1551.4Ssimonb count = 0; 1561.1Scgd } 1571.4Ssimonb { 1581.1Scgd printf("#define\t%-30.30s\t%3d\n", $1, count++); 1591.1Scgd } 1601.1Scgd END { 1611.1Scgd printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count); 1621.1Scgd 1631.13Schristos printf("typedef el_action_t (*el_func_t)(EditLine *, wint_t);"); 1641.7Sjdolecek printf("\nprotected const el_func_t* func__get(void);\n"); 1651.1Scgd printf("#endif /* _h_fcns_c */\n"); 1661.5Slukem }' 1671.5Slukem ;; 1681.5Slukem 1691.6Slukem# generate fcns.c from various .h files 1701.5Slukem# 1711.1Scgd-fc) 1721.1Scgd cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK ' 1731.1Scgd BEGIN { 1741.1Scgd printf("/* Automatically generated file, do not edit */\n"); 1751.12Ssketch printf("#include \"config.h\"\n#include \"el.h\"\n"); 1761.7Sjdolecek printf("private const el_func_t el_func[] = {"); 1771.1Scgd maxlen = 80; 1781.1Scgd needn = 1; 1791.1Scgd len = 0; 1801.1Scgd } 1811.1Scgd { 1821.1Scgd clen = 25 + 2; 1831.1Scgd len += clen; 1841.4Ssimonb if (len >= maxlen) 1851.1Scgd needn = 1; 1861.1Scgd if (needn) { 1871.1Scgd printf("\n "); 1881.1Scgd needn = 0; 1891.1Scgd len = 4 + clen; 1901.1Scgd } 1911.1Scgd s = $1 ","; 1921.1Scgd printf("%-26.26s ", s); 1931.1Scgd } 1941.1Scgd END { 1951.1Scgd printf("\n};\n"); 1961.7Sjdolecek printf("\nprotected const el_func_t* func__get() { return el_func; }\n"); 1971.5Slukem }' 1981.5Slukem ;; 1991.5Slukem 2001.5Slukem# generate editline.c from various .c files 2011.5Slukem# 2021.1Scgd-e) 2031.1Scgd echo "$FILES" | tr ' ' '\012' | $AWK ' 2041.1Scgd BEGIN { 2051.1Scgd printf("/* Automatically generated file, do not edit */\n"); 2061.1Scgd printf("#define protected static\n"); 2071.1Scgd printf("#define SCCSID\n"); 2081.1Scgd } 2091.1Scgd { 2101.1Scgd printf("#include \"%s\"\n", $1); 2111.5Slukem }' 2121.5Slukem ;; 2131.5Slukem 2141.5Slukem# generate man page fragment from various .c files 2151.5Slukem# 2161.5Slukem-m) 2171.5Slukem cat $FILES | $AWK ' 2181.5Slukem BEGIN { 2191.5Slukem printf(".\\\" Section automatically generated with makelist\n"); 2201.5Slukem printf(".Bl -tag -width 4n\n"); 2211.5Slukem } 2221.5Slukem /\(\):/ { 2231.5Slukem pr = substr($2, 1, 2); 2241.5Slukem if (pr == "vi" || pr == "em" || pr == "ed") { 2251.5Slukem name = substr($2, 1, length($2) - 3); 2261.5Slukem fname = ""; 2271.5Slukem for (i = 1; i <= length(name); i++) { 2281.5Slukem s = substr(name, i, 1); 2291.5Slukem if (s == "_") 2301.5Slukem s = "-"; 2311.5Slukem fname = fname s; 2321.5Slukem } 2331.5Slukem 2341.5Slukem printf(".It Ic %s\n", fname); 2351.5Slukem ok = 1; 2361.5Slukem } 2371.5Slukem } 2381.5Slukem /^ \*/ { 2391.5Slukem if (ok) { 2401.5Slukem for (i = 2; i < NF; i++) 2411.5Slukem printf("%s ", $i); 2421.5Slukem printf("%s.\n", $i); 2431.5Slukem ok = 0; 2441.5Slukem } 2451.5Slukem } 2461.5Slukem END { 2471.5Slukem printf(".El\n"); 2481.5Slukem printf(".\\\" End of section automatically generated with makelist\n"); 2491.5Slukem }' 2501.5Slukem ;; 2511.5Slukem 2521.1Scgd*) 2531.1Scgd echo $USAGE 1>&2 2541.5Slukem exit 1 2551.5Slukem ;; 2561.5Slukem 2571.1Scgdesac 258