makelist revision 1.24
11.1Scgd#!/bin/sh - 21.24Schristos# $NetBSD: makelist,v 1.24 2016/02/17 19:47:49 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.14SchristosUSAGE="Usage: $0 -n|-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.14Schristos-n) 571.13Schristos cat << _EOF 581.17Schristos#include "config.h" 591.14Schristos#undef WIDECHAR 601.14Schristos#define NARROWCHAR 611.14Schristos#include "${FILES}" 621.13Schristos_EOF 631.13Schristos ;; 641.24Schristos 651.1Scgd-h) 661.2Scgd set - `echo $FILES | sed -e 's/\\./_/g'` 671.16Schristos hdr="_h_`basename $1`" 681.1Scgd cat $FILES | $AWK ' 691.1Scgd BEGIN { 701.1Scgd printf("/* Automatically generated file, do not edit */\n"); 711.1Scgd printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'"); 721.1Scgd } 731.1Scgd /\(\):/ { 741.1Scgd pr = substr($2, 1, 2); 751.1Scgd if (pr == "vi" || pr == "em" || pr == "ed") { 761.1Scgd name = substr($2, 1, length($2) - 3); 771.6Slukem# 781.6Slukem# XXX: need a space between name and prototype so that -fc and -fh 791.6Slukem# parsing is much easier 801.6Slukem# 811.19Schristos printf("protected el_action_t\t%s (EditLine *, wint_t);\n", 821.19Schristos name); 831.1Scgd } 841.1Scgd } 851.1Scgd END { 861.1Scgd printf("#endif /* %s */\n", "'$hdr'"); 871.5Slukem }' 881.5Slukem ;; 891.5Slukem 901.5Slukem# generate help.c from various .c files 911.5Slukem# 921.1Scgd-bc) 931.1Scgd cat $FILES | $AWK ' 941.1Scgd BEGIN { 951.1Scgd printf("/* Automatically generated file, do not edit */\n"); 961.22Schristos printf("#include \"config.h\"\n#include \"el.h\"\n"); 971.23Schristos printf("#include \"help.h\"\n"); 981.7Sjdolecek printf("private const struct el_bindings_t el_func_help[] = {\n"); 991.1Scgd low = "abcdefghijklmnopqrstuvwxyz_"; 1001.1Scgd high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; 1011.1Scgd for (i = 1; i <= length(low); i++) 1021.1Scgd tr[substr(low, i, 1)] = substr(high, i, 1); 1031.1Scgd } 1041.1Scgd /\(\):/ { 1051.1Scgd pr = substr($2, 1, 2); 1061.1Scgd if (pr == "vi" || pr == "em" || pr == "ed") { 1071.1Scgd name = substr($2, 1, length($2) - 3); 1081.1Scgd uname = ""; 1091.1Scgd fname = ""; 1101.1Scgd for (i = 1; i <= length(name); i++) { 1111.1Scgd s = substr(name, i, 1); 1121.1Scgd uname = uname tr[s]; 1131.1Scgd if (s == "_") 1141.1Scgd s = "-"; 1151.1Scgd fname = fname s; 1161.1Scgd } 1171.4Ssimonb 1181.13Schristos printf(" { %-30.30s %-30.30s\n","STR(\"" fname "\"),", uname ","); 1191.4Ssimonb ok = 1; 1201.1Scgd } 1211.1Scgd } 1221.1Scgd /^ \*/ { 1231.1Scgd if (ok) { 1241.13Schristos printf(" STR(\""); 1251.1Scgd for (i = 2; i < NF; i++) 1261.1Scgd printf("%s ", $i); 1271.13Schristos printf("%s\") },\n", $i); 1281.1Scgd ok = 0; 1291.1Scgd } 1301.1Scgd } 1311.1Scgd END { 1321.1Scgd printf("};\n"); 1331.18Smatt printf("\nprotected const el_bindings_t* help__get(void)"); 1341.1Scgd printf("{ return el_func_help; }\n"); 1351.5Slukem }' 1361.5Slukem ;; 1371.5Slukem 1381.5Slukem# generate help.h from various .c files 1391.5Slukem# 1401.1Scgd-bh) 1411.1Scgd $AWK ' 1421.4Ssimonb BEGIN { 1431.1Scgd printf("/* Automatically generated file, do not edit */\n"); 1441.1Scgd printf("#ifndef _h_help_c\n#define _h_help_c\n"); 1451.7Sjdolecek printf("protected const el_bindings_t *help__get(void);\n"); 1461.1Scgd printf("#endif /* _h_help_c */\n"); 1471.5Slukem }' /dev/null 1481.5Slukem ;; 1491.5Slukem 1501.6Slukem# generate fcns.h from various .h files 1511.5Slukem# 1521.1Scgd-fh) 1531.1Scgd cat $FILES | $AWK '/el_action_t/ { print $3 }' | \ 1541.11Schristos sort | tr '[:lower:]' '[:upper:]' | $AWK ' 1551.4Ssimonb BEGIN { 1561.1Scgd printf("/* Automatically generated file, do not edit */\n"); 1571.1Scgd printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n"); 1581.4Ssimonb count = 0; 1591.1Scgd } 1601.4Ssimonb { 1611.1Scgd printf("#define\t%-30.30s\t%3d\n", $1, count++); 1621.1Scgd } 1631.1Scgd END { 1641.1Scgd printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count); 1651.1Scgd 1661.19Schristos printf("typedef el_action_t (*el_func_t)(EditLine *, wint_t);"); 1671.7Sjdolecek printf("\nprotected const el_func_t* func__get(void);\n"); 1681.1Scgd printf("#endif /* _h_fcns_c */\n"); 1691.5Slukem }' 1701.5Slukem ;; 1711.5Slukem 1721.6Slukem# generate fcns.c from various .h files 1731.5Slukem# 1741.1Scgd-fc) 1751.1Scgd cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK ' 1761.1Scgd BEGIN { 1771.1Scgd printf("/* Automatically generated file, do not edit */\n"); 1781.22Schristos printf("#include \"config.h\"\n#include \"el.h\"\n"); 1791.23Schristos printf("#include \"common.h\"\n"); 1801.23Schristos printf("#include \"emacs.h\"\n"); 1811.23Schristos printf("#include \"vi.h\"\n"); 1821.7Sjdolecek printf("private const el_func_t el_func[] = {"); 1831.1Scgd maxlen = 80; 1841.1Scgd needn = 1; 1851.1Scgd len = 0; 1861.1Scgd } 1871.1Scgd { 1881.1Scgd clen = 25 + 2; 1891.1Scgd len += clen; 1901.4Ssimonb if (len >= maxlen) 1911.1Scgd needn = 1; 1921.1Scgd if (needn) { 1931.1Scgd printf("\n "); 1941.1Scgd needn = 0; 1951.1Scgd len = 4 + clen; 1961.1Scgd } 1971.1Scgd s = $1 ","; 1981.1Scgd printf("%-26.26s ", s); 1991.1Scgd } 2001.1Scgd END { 2011.1Scgd printf("\n};\n"); 2021.18Smatt printf("\nprotected const el_func_t* func__get(void) { return el_func; }\n"); 2031.5Slukem }' 2041.5Slukem ;; 2051.5Slukem 2061.5Slukem# generate editline.c from various .c files 2071.5Slukem# 2081.1Scgd-e) 2091.1Scgd echo "$FILES" | tr ' ' '\012' | $AWK ' 2101.1Scgd BEGIN { 2111.1Scgd printf("/* Automatically generated file, do not edit */\n"); 2121.1Scgd printf("#define protected static\n"); 2131.1Scgd printf("#define SCCSID\n"); 2141.1Scgd } 2151.1Scgd { 2161.1Scgd printf("#include \"%s\"\n", $1); 2171.5Slukem }' 2181.5Slukem ;; 2191.5Slukem 2201.5Slukem# generate man page fragment from various .c files 2211.5Slukem# 2221.5Slukem-m) 2231.5Slukem cat $FILES | $AWK ' 2241.5Slukem BEGIN { 2251.5Slukem printf(".\\\" Section automatically generated with makelist\n"); 2261.5Slukem printf(".Bl -tag -width 4n\n"); 2271.5Slukem } 2281.5Slukem /\(\):/ { 2291.5Slukem pr = substr($2, 1, 2); 2301.5Slukem if (pr == "vi" || pr == "em" || pr == "ed") { 2311.5Slukem name = substr($2, 1, length($2) - 3); 2321.5Slukem fname = ""; 2331.5Slukem for (i = 1; i <= length(name); i++) { 2341.5Slukem s = substr(name, i, 1); 2351.5Slukem if (s == "_") 2361.5Slukem s = "-"; 2371.5Slukem fname = fname s; 2381.5Slukem } 2391.5Slukem 2401.5Slukem printf(".It Ic %s\n", fname); 2411.5Slukem ok = 1; 2421.5Slukem } 2431.5Slukem } 2441.5Slukem /^ \*/ { 2451.5Slukem if (ok) { 2461.5Slukem for (i = 2; i < NF; i++) 2471.5Slukem printf("%s ", $i); 2481.5Slukem printf("%s.\n", $i); 2491.5Slukem ok = 0; 2501.5Slukem } 2511.5Slukem } 2521.5Slukem END { 2531.5Slukem printf(".El\n"); 2541.5Slukem printf(".\\\" End of section automatically generated with makelist\n"); 2551.5Slukem }' 2561.5Slukem ;; 2571.5Slukem 2581.1Scgd*) 2591.1Scgd echo $USAGE 1>&2 2601.5Slukem exit 1 2611.5Slukem ;; 2621.5Slukem 2631.1Scgdesac 264