Module Name:    src
Committed By:   roy
Date:           Tue Jan 10 10:13:24 UTC 2017

Modified Files:
        src/distrib/sets/lists/comp: mi
        src/lib/libcurses: Makefile curses.h curses_private.h curses_screen.3
            initscr.c resize.c screen.c setterm.c

Log Message:
Implement POSIX curses function ripoffline(3).


To generate a diff of this commit:
cvs rdiff -u -r1.2100 -r1.2101 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.81 -r1.82 src/lib/libcurses/Makefile
cvs rdiff -u -r1.119 -r1.120 src/lib/libcurses/curses.h
cvs rdiff -u -r1.57 -r1.58 src/lib/libcurses/curses_private.h
cvs rdiff -u -r1.21 -r1.22 src/lib/libcurses/curses_screen.3
cvs rdiff -u -r1.30 -r1.31 src/lib/libcurses/initscr.c
cvs rdiff -u -r1.22 -r1.23 src/lib/libcurses/resize.c
cvs rdiff -u -r1.27 -r1.28 src/lib/libcurses/screen.c
cvs rdiff -u -r1.59 -r1.60 src/lib/libcurses/setterm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.2100 src/distrib/sets/lists/comp/mi:1.2101
--- src/distrib/sets/lists/comp/mi:1.2100	Sat Jan  7 04:44:12 2017
+++ src/distrib/sets/lists/comp/mi	Tue Jan 10 10:13:24 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: mi,v 1.2100 2017/01/07 04:44:12 ozaki-r Exp $
+#	$NetBSD: mi,v 1.2101 2017/01/10 10:13:24 roy Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.comp				comp-sys-root
@@ -8689,6 +8689,7 @@
 ./usr/share/man/cat3/rintf.0			comp-c-catman		.cat
 ./usr/share/man/cat3/rintl.0			comp-c-catman		.cat
 ./usr/share/man/cat3/ripemd.0			comp-obsolete		obsolete
+./usr/share/man/cat3/ripoffline.0		comp-c-catman		.cat
 ./usr/share/man/cat3/rmd160.0			comp-c-catman		.cat
 ./usr/share/man/cat3/rmtops.0			comp-c-catman		.cat
 ./usr/share/man/cat3/round.0			comp-c-catman		.cat
@@ -16037,6 +16038,7 @@
 ./usr/share/man/html3/rint.html			comp-c-htmlman		html
 ./usr/share/man/html3/rintf.html		comp-c-htmlman		html
 ./usr/share/man/html3/rintl.html		comp-c-htmlman		html
+./usr/share/man/html3/ripoffline.html		comp-c-htmlman		html
 ./usr/share/man/html3/rmd160.html		comp-c-htmlman		html
 ./usr/share/man/html3/rmtops.html		comp-c-htmlman		html
 ./usr/share/man/html3/round.html		comp-c-htmlman		html
@@ -23384,6 +23386,7 @@
 ./usr/share/man/man3/rintf.3			comp-c-man		.man
 ./usr/share/man/man3/rintl.3			comp-c-man		.man
 ./usr/share/man/man3/ripemd.3			comp-obsolete		obsolete
+./usr/share/man/man3/ripoffline.3		comp-c-man		.man
 ./usr/share/man/man3/rmd160.3			comp-c-man		.man
 ./usr/share/man/man3/rmtops.3			comp-c-man		.man
 ./usr/share/man/man3/round.3			comp-c-man		.man

Index: src/lib/libcurses/Makefile
diff -u src/lib/libcurses/Makefile:1.81 src/lib/libcurses/Makefile:1.82
--- src/lib/libcurses/Makefile:1.81	Thu Jan  5 23:15:43 2017
+++ src/lib/libcurses/Makefile	Tue Jan 10 10:13:24 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.81 2017/01/05 23:15:43 roy Exp $
+#	$NetBSD: Makefile,v 1.82 2017/01/10 10:13:24 roy Exp $
 #	@(#)Makefile	8.2 (Berkeley) 1/2/94
 
 .include <bsd.own.mk>
@@ -143,6 +143,7 @@ MLINKS+= curses_addch.3 addch.3 curses_a
 	 curses_tty.3 reset_prog_mode.3 curses_tty.3 reset_shell_mode.3 \
 	 curses_tty.3 resetty.3 \
 	 curses_screen.3 resizeterm.3 curses_screen.3 resize_term.3 \
+	 curses_screen.3 ripoffline.3 \
 	 curses_tty.3 savetty.3 curses_scanw.3 scanw.3 \
 	 curses_scroll.3 scrl.3 curses_scroll.3 scroll.3 \
 	 curses_scroll.3 scrollok.3 curses_scroll.3 setscrreg.3 \

Index: src/lib/libcurses/curses.h
diff -u src/lib/libcurses/curses.h:1.119 src/lib/libcurses/curses.h:1.120
--- src/lib/libcurses/curses.h:1.119	Fri Jan  6 09:14:07 2017
+++ src/lib/libcurses/curses.h	Tue Jan 10 10:13:24 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: curses.h,v 1.119 2017/01/06 09:14:07 roy Exp $	*/
+/*	$NetBSD: curses.h,v 1.120 2017/01/10 10:13:24 roy Exp $	*/
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -746,6 +746,7 @@ int	 reset_shell_mode(void);
 int	 resetty(void);
 int      resizeterm(int, int);
 int	 resize_term(int, int);
+int	 ripoffline(int, int (*)(WINDOW *, int));
 int	 savetty(void);
 int	 scanw(const char *, ...) __scanflike(1, 2);
 int	 scroll(WINDOW *);

Index: src/lib/libcurses/curses_private.h
diff -u src/lib/libcurses/curses_private.h:1.57 src/lib/libcurses/curses_private.h:1.58
--- src/lib/libcurses/curses_private.h:1.57	Fri Jan  6 09:14:07 2017
+++ src/lib/libcurses/curses_private.h	Tue Jan 10 10:13:24 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: curses_private.h,v 1.57 2017/01/06 09:14:07 roy Exp $	*/
+/*	$NetBSD: curses_private.h,v 1.58 2017/01/10 10:13:24 roy Exp $	*/
 
 /*-
  * Copyright (c) 1998-2000 Brett Lymn
@@ -201,6 +201,8 @@ struct __screen {
 	int      lx, ly;        /* loop parameters for refresh */
 	int	 COLS;		/* Columns on the screen. */
 	int	 LINES;		/* Lines on the screen. */
+	int	 ripped_top;	/* Lines ripped from the top of the screen. */
+	int	 ripped_bottom;	/* Lines ripped from the bottom. */
 	int	 ESCDELAY;	/* Delay between keys in esc seq's. */
 #define	ESCDELAY_DEFAULT	300 /* milliseconds. */
 	int	 TABSIZE;	/* Size of a tab. */

Index: src/lib/libcurses/curses_screen.3
diff -u src/lib/libcurses/curses_screen.3:1.21 src/lib/libcurses/curses_screen.3:1.22
--- src/lib/libcurses/curses_screen.3:1.21	Thu Jan  5 21:25:18 2017
+++ src/lib/libcurses/curses_screen.3	Tue Jan 10 10:13:24 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: curses_screen.3,v 1.21 2017/01/05 21:25:18 roy Exp $
+.\"	$NetBSD: curses_screen.3,v 1.22 2017/01/10 10:13:24 roy Exp $
 .\"
 .\" Copyright (c) 2002
 .\"	Brett Lymn (bl...@netbsd.org, brett_l...@yahoo.com.au)
@@ -30,12 +30,13 @@
 .\" SUCH DAMAGE.
 .\"
 .\"
-.Dd January 5, 2017
+.Dd January 9, 2017
 .Dt CURSES_SCREEN 3
 .Os
 .Sh NAME
 .Nm curses_screen ,
 .Nm filter ,
+.Nm ripoffline ,
 .Nm use_env ,
 .Nm newterm ,
 .Nm set_term ,
@@ -55,6 +56,8 @@
 .In curses.h
 .Ft void
 .Fn filter "void"
+.Ft int
+.Fn ripoffline "int line" "int (*init)(WINDOW *win, int cols)"
 .Ft void
 .Fn use_env "bool value"
 .Ft SCREEN *
@@ -212,6 +215,36 @@ Set lines equal to 1.
 .El
 .Pp
 The
+.Fn ripoffline
+funcion will rip a line from
+.Dv stdscr
+at the top if
+.Fa line
+is positive, or at the bottom if negative.
+When
+.Fn initscr
+or
+.Fn newterm
+is called, a window will be created for each line ripped and passed
+to the
+.Fa init
+function pointer alongwith the number of columns in the window.
+This init function cannot use the
+.Dv LINES
+or
+.Dv COLS
+variables and cannot call
+.Xr wrefresh 3
+or
+.Xr doupdate 3 ,
+but may call
+.Xr wnoutrefresh 3 .
+.Dv LINES
+will be reduced by the total number of lines ripped off.
+.Fn ripoffline
+can be called up to five times.
+.Pp
+The
 .Fn use_env
 function determines whether the environment variables
 .Ev LINES

Index: src/lib/libcurses/initscr.c
diff -u src/lib/libcurses/initscr.c:1.30 src/lib/libcurses/initscr.c:1.31
--- src/lib/libcurses/initscr.c:1.30	Fri Jan  6 13:53:18 2017
+++ src/lib/libcurses/initscr.c	Tue Jan 10 10:13:24 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: initscr.c,v 1.30 2017/01/06 13:53:18 roy Exp $	*/
+/*	$NetBSD: initscr.c,v 1.31 2017/01/10 10:13:24 roy Exp $	*/
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)initscr.c	8.2 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: initscr.c,v 1.30 2017/01/06 13:53:18 roy Exp $");
+__RCSID("$NetBSD: initscr.c,v 1.31 2017/01/10 10:13:24 roy Exp $");
 #endif
 #endif	/* not lint */
 
@@ -73,7 +73,8 @@ initscr(void)
 	__rawmode = _cursesi_screen->rawmode;
 	__noqch = _cursesi_screen->noqch;
 	COLS = _cursesi_screen->COLS;
-	LINES = _cursesi_screen->LINES;
+	LINES = _cursesi_screen->LINES
+	    - _cursesi_screen->ripped_top - _cursesi_screen->ripped_bottom;
 	COLORS = _cursesi_screen->COLORS;
 	COLOR_PAIRS = _cursesi_screen->COLOR_PAIRS;
 	__GT = _cursesi_screen->GT;

Index: src/lib/libcurses/resize.c
diff -u src/lib/libcurses/resize.c:1.22 src/lib/libcurses/resize.c:1.23
--- src/lib/libcurses/resize.c:1.22	Fri Jan  6 13:53:18 2017
+++ src/lib/libcurses/resize.c	Tue Jan 10 10:13:24 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize.c,v 1.22 2017/01/06 13:53:18 roy Exp $	*/
+/*	$NetBSD: resize.c,v 1.23 2017/01/10 10:13:24 roy Exp $	*/
 
 /*
  * Copyright (c) 2001
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)resize.c   blymn 2001/08/26";
 #else
-__RCSID("$NetBSD: resize.c,v 1.22 2017/01/06 13:53:18 roy Exp $");
+__RCSID("$NetBSD: resize.c,v 1.23 2017/01/10 10:13:24 roy Exp $");
 #endif
 #endif				/* not lint */
 
@@ -144,7 +144,10 @@ bool
 is_term_resized(int nlines, int ncols)
 {
 
-	return (nlines > 0 && ncols > 0 && (nlines != LINES || ncols != COLS));
+	return (nlines > 0 && ncols > 0 &&
+	    (nlines != _cursesi_screen->LINES
+	    + _cursesi_screen->ripped_top + _cursesi_screen->ripped_bottom ||
+	    ncols != _cursesi_screen->COLS));
 }
 
 /*
@@ -190,6 +193,7 @@ resize_term(int nlines, int ncols)
 		return ERR;
 	if (__resizeterm(__virtscr, nlines, ncols) == ERR)
 		return ERR;
+	nlines -= _cursesi_screen->ripped_top - _cursesi_screen->ripped_bottom;
 	if (__resizeterm(stdscr, nlines, ncols) == ERR)
 		return ERR;
 

Index: src/lib/libcurses/screen.c
diff -u src/lib/libcurses/screen.c:1.27 src/lib/libcurses/screen.c:1.28
--- src/lib/libcurses/screen.c:1.27	Fri Jan  6 13:53:18 2017
+++ src/lib/libcurses/screen.c	Tue Jan 10 10:13:24 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: screen.c,v 1.27 2017/01/06 13:53:18 roy Exp $	*/
+/*	$NetBSD: screen.c,v 1.28 2017/01/10 10:13:24 roy Exp $	*/
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)screen.c	8.2 (blymn) 11/27/2001";
 #else
-__RCSID("$NetBSD: screen.c,v 1.27 2017/01/06 13:53:18 roy Exp $");
+__RCSID("$NetBSD: screen.c,v 1.28 2017/01/10 10:13:24 roy Exp $");
 #endif
 #endif					/* not lint */
 
@@ -45,6 +45,14 @@ __RCSID("$NetBSD: screen.c,v 1.27 2017/0
 
 static int filtered;
 
+/* List of ripoffline calls */
+#define	NRIPS	5
+static struct ripoff {
+	int	nlines;
+	int	(*init)(WINDOW *, int);
+} ripoffs[NRIPS];
+static int nrips;
+
 /*
  * filter has to be called before either initscr or newterm.
  */
@@ -56,6 +64,24 @@ filter(void)
 }
 
 /*
+ *ripoffline --
+ *	Ripoff a line from the top of bottom of stdscr.
+ *	Must be called before initscr or newterm.
+ */
+int
+ripoffline(int line, int (*init)(WINDOW *, int))
+{
+
+	if (nrips >= NRIPS || init == NULL)
+		return ERR; /* This makes sense, but not standards compliant. */
+	if (line == 0)
+		return OK;
+	ripoffs[nrips].nlines = line < 0 ? -1 : 1;
+	ripoffs[nrips++].init = init;
+	return OK;
+}
+
+/*
  * set_term --
  *      Change the term to the given screen.
  *
@@ -72,7 +98,8 @@ set_term(SCREEN *new)
 		old_screen->rawmode = __rawmode;
 		old_screen->noqch = __noqch;
 		old_screen->COLS = COLS;
-		old_screen->LINES = LINES;
+		old_screen->LINES = LINES
+		    + old_screen->ripped_top + old_screen->ripped_bottom;
 		old_screen->COLORS = COLORS;
 		old_screen->COLOR_PAIRS = COLOR_PAIRS;
 		old_screen->GT = __GT;
@@ -87,7 +114,7 @@ set_term(SCREEN *new)
 	__rawmode = new->rawmode;
 	__noqch = new->noqch;
 	COLS = new->COLS;
-	LINES = new->LINES;
+	LINES = new->LINES - new->ripped_top - new->ripped_bottom;
 	COLORS = new->COLORS;
 	COLOR_PAIRS = new->COLOR_PAIRS;
 	__GT = new->GT;
@@ -124,6 +151,7 @@ newterm(char *type, FILE *outfd, FILE *i
 {
 	SCREEN *new_screen;
 	char *sp;
+	int i;
 
 	sp = type;
 	if (type == NULL && (sp = getenv("TERM")) == NULL)
@@ -158,7 +186,8 @@ newterm(char *type, FILE *outfd, FILE *i
 	new_screen->unget_len = 32;
 
 	if ((new_screen->unget_list =
-	    malloc(sizeof(wchar_t) * new_screen->unget_len)) == NULL) {
+	    malloc(sizeof(wchar_t) * new_screen->unget_len)) == NULL)
+	{
 		goto error_exit;
 	}
 	new_screen->unget_pos = 0;
@@ -180,21 +209,48 @@ newterm(char *type, FILE *outfd, FILE *i
 	    0, 0, 0, FALSE)) == NULL)
 		goto error_exit;
 
-	if ((new_screen->stdscr = __newwin(new_screen, 0,
-	    0, 0, 0, FALSE)) == NULL) {
+	if ((new_screen->__virtscr = __newwin(new_screen, 0,
+	    0, 0, 0, FALSE)) == NULL)
+	{
 		delwin(new_screen->curscr);
 		goto error_exit;
 	}
 
-	clearok(new_screen->stdscr, 1);
+	for (i = 0; i < nrips; i++) {
+		const struct ripoff *r = &ripoffs[i];
+		int nlines = r->nlines < 0 ? -r->nlines : r->nlines;
+		WINDOW *w;
+
+		w = __newwin(new_screen, nlines, 0,
+		    r->nlines < 0 ? LINES + r->nlines : new_screen->ripped_top,
+		    0, FALSE);
+		if (w != NULL) {
+			if (r->nlines < 0)
+				new_screen->ripped_bottom += nlines;
+			else
+				new_screen->ripped_top += nlines;
+			LINES -= nlines;
+		}
+		r->init(w, COLS);
+#ifdef DEBUG
+		if (w != NULL)
+			__CTRACE(__CTRACE_SCREEN,
+			    "newterm: ripped %d lines from the %s\n",
+			    nlines, r->nlines < 0 ? "bottom" : "top");
+#endif
+	}
+	nrips = 0; /* Reset the stack. */
 
-	if ((new_screen->__virtscr = __newwin(new_screen, 0,
-	    0, 0, 0, FALSE)) == NULL) {
+	new_screen->stdscr = __newwin(new_screen, LINES, 0,
+	    new_screen->ripped_top, 0, FALSE);
+	if (new_screen->stdscr == NULL) {
 		delwin(new_screen->curscr);
-		delwin(new_screen->stdscr);
+		delwin(new_screen->__virtscr);
 		goto error_exit;
 	}
 
+	clearok(new_screen->stdscr, 1);
+
 	__init_getch(new_screen);
 	__init_acs(new_screen);
 #ifdef HAVE_WCHAR

Index: src/lib/libcurses/setterm.c
diff -u src/lib/libcurses/setterm.c:1.59 src/lib/libcurses/setterm.c:1.60
--- src/lib/libcurses/setterm.c:1.59	Fri Jan  6 13:53:18 2017
+++ src/lib/libcurses/setterm.c	Tue Jan 10 10:13:24 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: setterm.c,v 1.59 2017/01/06 13:53:18 roy Exp $	*/
+/*	$NetBSD: setterm.c,v 1.60 2017/01/10 10:13:24 roy Exp $	*/
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)setterm.c	8.8 (Berkeley) 10/25/94";
 #else
-__RCSID("$NetBSD: setterm.c,v 1.59 2017/01/06 13:53:18 roy Exp $");
+__RCSID("$NetBSD: setterm.c,v 1.60 2017/01/10 10:13:24 roy Exp $");
 #endif
 #endif /* not lint */
 
@@ -150,7 +150,7 @@ _cursesi_setterm(char *type, SCREEN *scr
 	if (screen->COLS <= 4)
 		return ERR;
 
-	LINES = screen->LINES;
+	LINES = screen->LINES - screen->ripped_top - screen->ripped_bottom;
 	COLS = screen->COLS;
 	ESCDELAY = screen->ESCDELAY;
 	TABSIZE = screen->TABSIZE;
@@ -282,7 +282,7 @@ void
 _cursesi_resetterm(SCREEN *screen)
 {
 
-	LINES = screen->LINES;
+	LINES = screen->LINES - screen->ripped_top - screen->ripped_bottom;
 	COLS = screen->COLS;
 	ESCDELAY = screen->ESCDELAY;
 	TABSIZE = screen->TABSIZE;

Reply via email to