From 2c7347666572e6cde8404ec5029567bb96d68a0d Mon Sep 17 00:00:00 2001 From: tholo Date: Mon, 16 Dec 1996 08:43:21 +0000 Subject: [PATCH] Generate library versions of macro implementations as well --- lib/libcurses/MKlib_gen.sh | 118 ++++++++++++++++++++++++++++++++++++ lib/libcurses/Makefile | 9 ++- lib/libcurses/shlib_version | 2 +- 3 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 lib/libcurses/MKlib_gen.sh diff --git a/lib/libcurses/MKlib_gen.sh b/lib/libcurses/MKlib_gen.sh new file mode 100644 index 00000000000..e384cde2185 --- /dev/null +++ b/lib/libcurses/MKlib_gen.sh @@ -0,0 +1,118 @@ +#!/bin/sh +# +# MKlib_gen.sh -- generate sources from curses.h macro definitions +# +# ($Id: MKlib_gen.sh,v 1.1 1996/12/16 08:43:21 tholo Exp $) +# +# The XSI Curses standard requires all curses entry points to exist as +# functions, even though many definitions would normally be shadowed +# by macros. Rather than hand-hack all that code, we actually +# generate functions from the macros. +# +# This script accepts a file of prototypes on standard input. It discards +# any that don't have a `generated' comment attached. It then parses each +# prototype (relying on the fact that none of the macros take function +# pointer or array arguments) and generates C source from it. +# +# Here is what the pipeline stages are doing: +# +# 1. sed: extract prototypes of generated functions +# 2. sed: decorate prototypes with generated arguments a1. a2,...z +# 3. awk: generate the calls with args matching the formals +# 4. sed: prefix function names in prototypes so the preprocessor won't expand +# them. +# 5. cpp: macroexpand the file so the macro calls turn into C calls +# 6. awk: strip the expansion junk off the front and add the new header +# 7. sed: squeeze spaces, strip off gen_ prefix, create needed #undef +# + +preprocessor="$1 -I../include" +AWK="$2" +TMP=gen$$.c +trap "rm -f $TMP" 0 1 2 5 15 + +(cat <$TMP + $preprocessor $TMP 2>/dev/null \ +| $AWK ' +BEGIN { + print "/*" + print " * DO NOT EDIT THIS FILE BY HAND!" + print " * It is generated by MKlib_gen.sh." + print " *" + print " * This is a file of trivial functions generated from macro" + print " * definitions in curses.h in order to satisfy the XSI Curses" + print " * requirement that every macro also exist as a callable" + print " * function." + print " *" + print " * It will neever be linked unless you call one of the entry" + print " * points with its normal macro definition disabled. In that" + print " * case, if you have no shared libraries, it will indirectly" + print " * pull most of the rest of the library into your link image." + print " * Cope with it." + print " */" + print "#include \"curses.h\"" + print "" + } +/^DECLARATIONS/ {start = 1; next;} + {if (start) print $0;} +' \ +| sed \ + -e 's/ */ /g' \ + -e 's/ */ /g' \ + -e 's/ gen_/ /' \ + -e 's/^M_/#undef /' \ + -e '/^%%/s// /' + diff --git a/lib/libcurses/Makefile b/lib/libcurses/Makefile index 5cc9cfabfd8..ca22e03611f 100644 --- a/lib/libcurses/Makefile +++ b/lib/libcurses/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.8 1996/12/08 15:22:26 downsj Exp $ +# $OpenBSD: Makefile,v 1.9 1996/12/16 08:43:22 tholo Exp $ LIB= curses SRCS= hardscroll.c lib_acs.c lib_delch.c lib_insstr.c lib_options.c \ @@ -11,7 +11,7 @@ SRCS= hardscroll.c lib_acs.c lib_delch.c lib_insstr.c lib_options.c \ lib_vidattr.c lib_clrbot.c lib_inchstr.c lib_mvcur.c lib_scanw.c \ lib_window.c lib_clreol.c lib_initscr.c lib_mvwin.c lib_screen.c \ lib_color.c lib_insch.c lib_newterm.c lib_scroll.c lib_data.c \ - lib_insdel.c lib_keyname.c lib_newwin.c lib_scrreg.c + lib_insdel.c lib_keyname.c lib_newwin.c lib_scrreg.c lib_gen.c CFLAGS+= -I. -I${.CURDIR} -DTERMIOS -DEXTERN_TERMINFO LDADD+= -ltermlib MAN= curs_addch.3 curs_addchstr.3 curs_addstr.3 curs_attr.3 curs_beep.3 \ @@ -23,7 +23,7 @@ MAN= curs_addch.3 curs_addchstr.3 curs_addstr.3 curs_attr.3 curs_beep.3 \ curs_scanw.3 curs_scr_dmp.3 curs_scroll.3 curs_slk.3 curs_termattrs.3 \ curs_touch.3 curs_util.3 curs_window.3 curses.3 MLINKS+=curses.3 ncurses.3 -CLEANFILES+= lib_keyname.c keys.tries +CLEANFILES+= lib_gen.c lib_keyname.c keys.tries beforedepend: keys.tries @@ -42,6 +42,9 @@ keys.tries: ${.CURDIR}/keys.list ${.CURDIR}/MKkeys.awk lib_keyname.c: ${.CURDIR}/keys.list ${.CURDIR}/MKkeyname.awk awk -f ${.CURDIR}/MKkeyname.awk ${.CURDIR}/keys.list > lib_keyname.c +lib_gen.c: ${.CURDIR}/curses.h ${.CURDIR}/MKlib_gen.sh + sh ${.CURDIR}/MKlib_gen.sh "${CPP}" "awk" < ${.CURDIR}/curses.h > lib_gen.c + .include lib_options.o lib_options.so lib_options.po lib_options.ln: keys.tries diff --git a/lib/libcurses/shlib_version b/lib/libcurses/shlib_version index 012c14171d3..3f0196ebf4a 100644 --- a/lib/libcurses/shlib_version +++ b/lib/libcurses/shlib_version @@ -1,2 +1,2 @@ major=3 -minor=0 +minor=1 -- 2.20.1