tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Add curses_version() in curses(3)



On 29/08/2019 03:45, Thor Lancelot Simon wrote:
On Wed, Aug 28, 2019 at 10:42:13PM -0400, Thor Lancelot Simon wrote:
On Wed, Aug 28, 2019 at 01:54:54AM +0100, Roy Marples wrote:

Where 8.2 is taken from the .so version?

Roy

I think that it would be confused with NetBSD release and it could be
meaningless/confusing for downstream users that just pick the code as is
and can pick different major/minor.

Then I'm against this being added because it adds nothing of value.

I note that PD curses also supports curses_version() with something similar
to my proposal.

The problem with using the solib version is that it may differ on
platforms derived from NetBSD even if the curses API is exactly the same.

This would, for example, have been the case on EQ/OS which I maintained
at Coyote Point - we bumped all the shlib versions at least once because
of a change to libc.

Sorry, hit send a little early and left out the ugliest detail.

The problem then really is that if, let's say, my EQ/OS libcurses had
reported 9.2 for a libcurses that was called 8.2 in NetBSD, when NetBSD
bumps its libcurses to 8.2 for real API-change reasons within libcurses,
my version will look like it has the API change but actually it won't.

You really don't want to use the solib version for this sort of thing
because it will not mean the same thing on different platforms for the
exact same version of the code implementing the API, because it must be
bumped every time the library's *ABI* changes -- and that must be done
every time some library upon which _it_ depends changes, in turn.

A version like __NetBSD_Version should be used.

Attached is a patch which adds __NetBSD_Curses_Version__ to curses.h in the same manner as __NetBSD_Version__ from sys/param.h. Should we document __NetBSD_Curses_Version__ in the curses_version.3 man page?

version.h is generated using a variant of osrelease.sh to extract the version numbers from that.
version.c includes this file and make up a string:
"NetBSD-Curses " CURSES_VERSION " - " __DATE__;

output:
NetBSD-Curses 1.0.0 - Aug 29 2019

I'm unsure if we need the date there or not - Kamil seems to think it's a good idea and it's also done like so in PDCurses. But would this affect our reproducable builds?

Roy
Index: Makefile
===================================================================
RCS file: /cvsroot/src/lib/libcurses/Makefile,v
retrieving revision 1.90
diff -u -p -r1.90 Makefile
--- Makefile	22 Nov 2018 22:00:49 -0000	1.90
+++ Makefile	29 Aug 2019 11:53:45 -0000
@@ -25,7 +25,7 @@ SRCS=	acs.c addbytes.c addch.c addchnstr
 	mvwin.c newwin.c nodelay.c notimeout.c overlay.c overwrite.c pause.c \
 	printw.c putchar.c refresh.c resize.c ripoffline.c scanw.c screen.c \
 	scroll.c scrollok.c setterm.c slk.c standout.c syncok.c timeout.c \
-	toucholap.c touchwin.c tstp.c tty.c unctrl.c underscore.c
+	toucholap.c touchwin.c tstp.c tty.c unctrl.c underscore.c version.c
 
 MAN=	curses.3 curses_addch.3 curses_addchstr.3 curses_addstr.3 \
 	curses_attributes.3 curses_background.3 curses_border.3 \
@@ -37,7 +37,8 @@ MAN=	curses.3 curses_addch.3 curses_addc
 	curses_insdelln.3 curses_keyname.3 curses_line.3 curses_pad.3 \
 	curses_print.3 curses_refresh.3 curses_scanw.3 curses_screen.3 \
 	curses_scroll.3 curses_slk.3 curses_standout.3 curses_termcap.3 \
-	curses_touch.3 curses_tty.3 curses_underscore.3 curses_window.3
+	curses_touch.3 curses_tty.3 curses_underscore.3 curses_version.3 \
+	curses_window.3
 INCS=	curses.h unctrl.h
 INCSDIR=/usr/include
 
@@ -209,5 +210,8 @@ SUBDIR.roff+= PSD.doc
 fileio.h: shlib_version genfileioh.awk
 	${TOOL_AWK} -f ${.CURDIR}/genfileioh.awk < ${.CURDIR}/shlib_version > ${.CURDIR}/fileio.h
 
+version.h: curses.h genversionh.sh
+	${HOST_SH} ${.CURDIR}/genversionh.sh ${.CURDIR}/curses.h > ${.CURDIR}/version.h
+
 .include <bsd.lib.mk>
 .include <bsd.subdir.mk>
Index: curses.3
===================================================================
RCS file: /cvsroot/src/lib/libcurses/curses.3,v
retrieving revision 1.73
diff -u -p -r1.73 curses.3
--- curses.3	25 Oct 2018 10:36:56 -0000	1.73
+++ curses.3	29 Aug 2019 11:53:45 -0000
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)curses.3	8.1 (Berkeley) 6/4/93
 .\"
-.Dd October 25, 2018
+.Dd August 29, 2019
 .Dt CURSES 3
 .Os
 .Sh NAME
@@ -96,6 +96,7 @@ must be called before any of the other r
 .It color_set Ta Xr curses_attributes 3
 .It copywin Ta Xr curses_window 3
 .It curs_set Ta Xr curses_tty 3
+.It curses_version Ta Xr curses_version 3
 .It def_prog_mode Ta Xr curses_tty 3
 .It def_shell_mode Ta Xr curses_tty 3
 .It define_key Ta Xr curses_input 3
Index: curses.h
===================================================================
RCS file: /cvsroot/src/lib/libcurses/curses.h,v
retrieving revision 1.123
diff -u -p -r1.123 curses.h
--- curses.h	30 Sep 2018 10:55:00 -0000	1.123
+++ curses.h	29 Aug 2019 11:53:45 -0000
@@ -48,6 +48,20 @@
 #include <stdbool.h>
 
 /*
+ *	#define __NetBSD_Curses_Version__ MMmmrrpp00
+ *
+ *	M = major version
+ *	m = minor version; a minor number of 99 indicates current
+ *	r = 0 (*)
+ *	p = patchlevel
+ */
+#define	__NetBSD_Curses_Version__	0100000000 /* NetBSD-Curses 1.0.0 */
+
+#define __NetBSD_Curses_Prereq__(M,m,p) (((((M) * 100000000) + \
+    (m) * 1000000) + (p) * 100) <= __NetBSD_Curses_Version__)
+
+
+/*
  * attr_t must be the same size as wchar_t (see <wchar.h>) to avoid padding
  * in __LDATA.
  */
@@ -980,6 +994,9 @@ bool is_keypad(const WINDOW *);
 bool is_leaveok(const WINDOW *);
 bool is_pad(const WINDOW *);
 
+/* ncurses version for compat */
+const char *curses_version(void);
+
 /* Private functions that are needed for user programs prototypes. */
 int	 __cputchar(int);
 int	 __waddbytes(WINDOW *, const char *, int, attr_t);
Index: curses_version.3
===================================================================
RCS file: curses_version.3
diff -N curses_version.3
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ curses_version.3	29 Aug 2019 11:53:45 -0000
@@ -0,0 +1,60 @@
+.\"	$NetBSD: $
+.\"
+.\" Copyright (c) 2019 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Roy Marples.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\"
+.Dd August 29, 2019
+.Dt CURSES_VERSION 3
+.Os
+.Sh NAME
+.Nm curses_version
+.Nd Curses version information
+.Sh LIBRARY
+.Lb libcurses
+.Sh SYNOPSIS
+.In curses.h
+.Ft const char *
+.Fn curses_version "void"
+.Sh DESCRIPTION
+The
+.Fn curses_version
+function returns a read-only string representing the version of the
+.Nx
+curses library.
+This has no relation to the
+.Nx
+release it might have been taken from.
+.Sh SEE ALSO
+.Xr curses 3
+.Sh HISTORY
+The
+.Fn curses_version
+function is a
+.Em ncurses
+extension to the Curses library and was added in
+.Nx 10.0 .
Index: genversionh.sh
===================================================================
RCS file: genversionh.sh
diff -N genversionh.sh
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ genversionh.sh	29 Aug 2019 11:53:45 -0000
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# based on osrelease.sh
+
+# Copyright (c) 1997, 2019 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Luke Mewburn.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+path="$0"
+[ "${path#/*}" = "$path" ] && path="./$path"
+exec < ${path%/*}/curses.h
+
+# Search for line
+# #define __NetBSD_Curses_Version__ <ver_num> /* NetBSD-Curses <ver_text> */
+#
+# <ver_num> and <ver_text> should match!
+
+while
+	read define ver_tag rel_num comment_start NetBSD rel_text rest || exit 1
+do
+	[ "$define" = "#define" ] || continue;
+	[ "$ver_tag" = "__NetBSD_Curses_Version__" ] || continue
+	break
+done
+
+# ${rel_num} is [M]Mmm00pp00
+rel_num=${rel_num%??}
+rel_MMmm=${rel_num%????}
+rel_MM=${rel_MMmm%??}
+rel_mm=${rel_MMmm#${rel_MM}}
+rel_pp=${rel_num#${rel_MMmm}00}
+
+echo '/*'
+echo ' * Do not edit!  Automatically generated file:'
+echo ' *   by  : $NetBSD: $'
+echo ' */'
+echo
+
+echo "#define CURSES_VERSION \"${rel_MM#0}.${rel_mm#0}.${rel_pp#0}\""
Index: version.c
===================================================================
RCS file: version.c
diff -N version.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ version.c	29 Aug 2019 11:53:45 -0000
@@ -0,0 +1,45 @@
+/*	$NetBSD: $	*/
+
+/*-
+ * Copyright (c) 2019 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Roy Marples.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: $");
+#endif
+
+#include "curses.h"
+#include "version.h"
+
+const char *
+curses_version()
+{
+
+	return "NetBSD-Curses " CURSES_VERSION " - " __DATE__;
+}
Index: version.h
===================================================================
RCS file: version.h
diff -N version.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ version.h	29 Aug 2019 11:53:45 -0000
@@ -0,0 +1,6 @@
+/*
+ * Do not edit!  Automatically generated file:
+ *   by  : $NetBSD: $
+ */
+
+#define CURSES_VERSION "1.0.0"


Home | Main Index | Thread Index | Old Index