summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThorsten Lockert <tholo@cvs.openbsd.org>1996-12-16 08:43:23 +0000
committerThorsten Lockert <tholo@cvs.openbsd.org>1996-12-16 08:43:23 +0000
commitcf3e766ba4e8338eda81a17c42b951261e98d8da (patch)
tree019a6d62d4423e961eeccf0ba589d0ed8019cdf1 /lib
parent7b2f102aaf665edd55d56f884bb9201faa31f2d0 (diff)
Generate library versions of macro implementations as well
Diffstat (limited to 'lib')
-rw-r--r--lib/libcurses/MKlib_gen.sh118
-rw-r--r--lib/libcurses/Makefile9
-rw-r--r--lib/libcurses/shlib_version2
3 files changed, 125 insertions, 4 deletions
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 <<EOF
+#include "curses.h"
+
+DECLARATIONS
+
+EOF
+sed -n -e "/^extern.*generated/s/^extern \([^;]*\);.*/\1/p" \
+| sed \
+ -e "/(/s// (/" \
+ -e "/(void)/b nc" \
+ -e "s/,/ a1% /" \
+ -e "s/,/ a2% /" \
+ -e "s/,/ a3% /" \
+ -e "s/,/ a4% /" \
+ -e "s/,/ a5% /" \
+ -e "s/,/ a6% /" \
+ -e "s/,/ a7% /" \
+ -e "s/,/ a8% /" \
+ -e "s/,/ a9% /" \
+ -e "s/,/ a10% /" \
+ -e "s/,/ a11% /" \
+ -e "s/,/ a12% /" \
+ -e "s/,/ a13% /" \
+ -e "s/,/ a14% /" \
+ -e "s/,/ a15% /" \
+ -e "s/%/,/g" \
+ -e "s/)/ z)/" \
+ -e ":nc" \
+| $AWK '{
+ print "\n"
+ print "M_" $2
+ print $0;
+ print "{";
+ for (i = argcount = 0; i < length($0); i++)
+ if (substr($0, i, 1) == ",")
+ argcount++;
+ ++argcount;
+ if (match($0, "^void"))
+ call = "%%"
+ else
+ call = "%%return ";
+ call = call $2 "(";
+ for (i = 1; i < argcount; i++)
+ call = call " a" i ", ";
+ if (match($0, "\\(void\\)"))
+ call = call ");";
+ else
+ call = call "z);";
+ print call
+ print "}";
+}
+' ) \
+| sed \
+ -e '/^\([a-z_][a-z_]*\) /s//\1 gen_/' >$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 <bsd.lib.mk>
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