Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libcurses Rename the old __waddbytes function to _curses...
details: https://anonhg.NetBSD.org/src/rev/53d9ef58c242
branches: trunk
changeset: 791223:53d9ef58c242
user: blymn <blymn%NetBSD.org@localhost>
date: Sat Nov 09 11:16:59 2013 +0000
description:
Rename the old __waddbytes function to _cursesi_waddbytes and add a
parameter that controls whether or not certain characters in the
string are interpreted or not (things like tab being expanded).
Make __waddbytes a wrapper for _cursesi_waddbytes that passes all
parameters and sets the flag for character interpretation for backward
compatibility.
Fix an incipient bug in _cursesi_waddbytes where garbage would have
been written to the terminal if the terminal TABSIZE was set > 8 and
character interpretation is on.
Convert all internal __waddbytes calls to use _cursesi_waddbytes, fix
the function prototypes and add a new flag that will be used later.
Fix the addchstr family functions so that they call _cursesi_waddbytes
with character interpretation off as per SUSV2.
diffstat:
lib/libcurses/add_wch.c | 6 +-
lib/libcurses/addbytes.c | 335 +++++++++++++++++++++-------------------
lib/libcurses/addch.c | 6 +-
lib/libcurses/addchnstr.c | 13 +-
lib/libcurses/curses_private.h | 9 +-
5 files changed, 198 insertions(+), 171 deletions(-)
diffs (truncated from 600 to 300 lines):
diff -r 3bd444391cde -r 53d9ef58c242 lib/libcurses/add_wch.c
--- a/lib/libcurses/add_wch.c Sat Nov 09 07:52:22 2013 +0000
+++ b/lib/libcurses/add_wch.c Sat Nov 09 11:16:59 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: add_wch.c,v 1.3 2009/07/22 16:57:14 roy Exp $ */
+/* $NetBSD: add_wch.c,v 1.4 2013/11/09 11:16:59 blymn Exp $ */
/*
* Copyright (c) 2005 The NetBSD Foundation Inc.
@@ -36,7 +36,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: add_wch.c,v 1.3 2009/07/22 16:57:14 roy Exp $");
+__RCSID("$NetBSD: add_wch.c,v 1.4 2013/11/09 11:16:59 blymn Exp $");
#endif /* not lint */
#include <stdlib.h>
@@ -119,6 +119,6 @@
__CTRACE(__CTRACE_INPUT, "wadd_wch: win(%p)", win);
#endif
lnp = win->alines[y];
- return _cursesi_addwchar(win, &lnp, &y, &x, wch);
+ return _cursesi_addwchar(win, &lnp, &y, &x, wch, 1);
#endif /* HAVE_WCHAR */
}
diff -r 3bd444391cde -r 53d9ef58c242 lib/libcurses/addbytes.c
--- a/lib/libcurses/addbytes.c Sat Nov 09 07:52:22 2013 +0000
+++ b/lib/libcurses/addbytes.c Sat Nov 09 11:16:59 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: addbytes.c,v 1.40 2013/10/16 19:59:29 roy Exp $ */
+/* $NetBSD: addbytes.c,v 1.41 2013/11/09 11:16:59 blymn Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)addbytes.c 8.4 (Berkeley) 5/4/94";
#else
-__RCSID("$NetBSD: addbytes.c,v 1.40 2013/10/16 19:59:29 roy Exp $");
+__RCSID("$NetBSD: addbytes.c,v 1.41 2013/11/09 11:16:59 blymn Exp $");
#endif
#endif /* not lint */
@@ -60,7 +60,7 @@
int
addbytes(const char *bytes, int count)
{
- return __waddbytes(stdscr, bytes, count, 0);
+ return _cursesi_waddbytes(stdscr, bytes, count, 0, 1);
}
/*
@@ -70,7 +70,7 @@
int
waddbytes(WINDOW *win, const char *bytes, int count)
{
- return __waddbytes(win, bytes, count, 0);
+ return _cursesi_waddbytes(win, bytes, count, 0, 1);
}
/*
@@ -93,19 +93,29 @@
if (wmove(win, y, x) == ERR)
return ERR;
- return __waddbytes(win, bytes, count, 0);
+ return _cursesi_waddbytes(win, bytes, count, 0, 1);
}
#endif
-/*
- * waddbytes --
- * Add the character to the current position in the given window.
- */
int
__waddbytes(WINDOW *win, const char *bytes, int count, attr_t attr)
{
- int x, y, err;
+ return _cursesi_waddbytes(win, bytes, count, attr, 1);
+}
+
+/*
+ * _cursesi_waddbytes --
+ * Add the character to the current position in the given window.
+ * if char_interp is non-zero then character interpretation is done on
+ * the byte (i.e. \n to newline, \r to carriage return, \b to backspace
+ * and so on).
+ */
+int
+_cursesi_waddbytes(WINDOW *win, const char *bytes, int count, attr_t attr,
+ int char_interp)
+{
+ int ox, x, y, err;
__LINE *lp;
#ifdef HAVE_WCHAR
int n;
@@ -128,6 +138,7 @@
err = OK;
SYNCH_IN;
lp = win->alines[y];
+ ox = win->curx;
#ifdef HAVE_WCHAR
(void)memset(&st, 0, sizeof(st));
@@ -139,7 +150,7 @@
__CTRACE(__CTRACE_INPUT, "ADDBYTES('%c', %x) at (%d, %d)\n",
c, attr, y, x);
#endif
- err = _cursesi_addbyte(win, &lp, &y, &x, c, attr);
+ err = _cursesi_addbyte(win, &lp, &y, &x, c, attr, char_interp);
count--;
#else
/*
@@ -169,7 +180,7 @@
cc.vals[0] = wc;
cc.elements = 1;
cc.attributes = attr;
- err = _cursesi_addwchar(win, &lp, &y, &x, &cc);
+ err = _cursesi_addwchar(win, &lp, &y, &x, &cc, char_interp);
bytes += n;
count -= n;
#endif
@@ -190,127 +201,132 @@
* _cursesi_addbyte -
* Internal function to add a byte and update the row and column
* positions as appropriate. This function is only used in the narrow
- * character version of curses.
+ * character version of curses. If update_cursor is non-zero then character
+ * interpretation.
*/
int
_cursesi_addbyte(WINDOW *win, __LINE **lp, int *y, int *x, int c,
- attr_t attr)
+ attr_t attr, int char_interp)
{
- static char blanks[] = " ";
- int newx;
+ static char blank[] = " ";
+ int tabsize;
+ int newx, i;
attr_t attributes;
- int tabsize;
+
+ if (char_interp) {
+ switch (c) {
+ case '\t':
+ tabsize = win->screen->TABSIZE;
+ PSYNCH_OUT;
+ for (i = 0; i < (tabsize - (*x % tabsize)); i++) {
+ if (waddbytes(win, blank, 1) == ERR)
+ return (ERR);
+ }
+ PSYNCH_IN;
+ return (OK);
- switch (c) {
- case '\t':
- tabsize = win->screen->TABSIZE;
- PSYNCH_OUT;
- if (waddbytes(win, blanks, tabsize - (*x % tabsize)) == ERR)
- return (ERR);
- PSYNCH_IN;
- break;
+ case '\n':
+ PSYNCH_OUT;
+ wclrtoeol(win);
+ PSYNCH_IN;
+ (*lp)->flags |= __ISPASTEOL;
+ break;
- default:
+ case '\r':
+ *x = 0;
+ win->curx = *x;
+ return (OK);
+
+ case '\b':
+ if (--(*x) < 0)
+ *x = 0;
+ win->curx = *x;
+ return (OK);
+ }
+ }
+
#ifdef DEBUG
- __CTRACE(__CTRACE_INPUT, "ADDBYTES(%p, %d, %d)\n",
- win, *y, *x);
+ __CTRACE(__CTRACE_INPUT, "ADDBYTES(%p, %d, %d)\n", win, *y, *x);
#endif
- if ((*lp)->flags & __ISPASTEOL) {
- new_line:
- *x = 0;
- (*lp)->flags &= ~__ISPASTEOL;
- if (*y == win->scr_b) {
+ if (char_interp && ((*lp)->flags & __ISPASTEOL)) {
+ *x = 0;
+ (*lp)->flags &= ~__ISPASTEOL;
+ if (*y == win->scr_b) {
#ifdef DEBUG
- __CTRACE(__CTRACE_INPUT,
- "ADDBYTES - on bottom "
- "of scrolling region\n");
-#endif
- if (!(win->flags & __SCROLLOK))
- return ERR;
- PSYNCH_OUT;
- scroll(win);
- PSYNCH_IN;
- } else {
- (*y)++;
- }
- *lp = win->alines[*y];
- if (c == '\n')
- break;
- }
-
- attributes = (win->wattr | attr) &
- (__ATTRIBUTES & ~__COLOR);
- if (attr & __COLOR)
- attributes |= attr & __COLOR;
- else if (win->wattr & __COLOR)
- attributes |= win->wattr & __COLOR;
-#ifdef DEBUG
- __CTRACE(__CTRACE_INPUT,
- "ADDBYTES: 1: y = %d, x = %d, firstch = %d, "
- "lastch = %d\n",
- *y, *x, *win->alines[*y]->firstchp,
- *win->alines[*y]->lastchp);
+ __CTRACE(__CTRACE_INPUT,
+ "ADDBYTES - on bottom "
+ "of scrolling region\n");
#endif
- /*
- * Always update the change pointers. Otherwise,
- * we could end up not displaying 'blank' characters
- * when overlapping windows are displayed.
- */
- newx = *x + win->ch_off;
- (*lp)->flags |= __ISDIRTY;
- /*
- * firstchp/lastchp are shared between
- * parent window and sub-window.
- */
- if (newx < *(*lp)->firstchp)
- *(*lp)->firstchp = newx;
- if (newx > *(*lp)->lastchp)
- *(*lp)->lastchp = newx;
-#ifdef DEBUG
- __CTRACE(__CTRACE_INPUT,
- "ADDBYTES: change gives f/l: %d/%d [%d/%d]\n",
- *(*lp)->firstchp, *(*lp)->lastchp,
- *(*lp)->firstchp - win->ch_off,
- *(*lp)->lastchp - win->ch_off);
-#endif
- if (win->bch != ' ' && c == ' ')
- (*lp)->line[*x].ch = win->bch;
- else
- (*lp)->line[*x].ch = c;
-
- if (attributes & __COLOR)
- (*lp)->line[*x].attr =
- attributes | (win->battr & ~__COLOR);
- else
- (*lp)->line[*x].attr = attributes | win->battr;
-
- if (*x == win->maxx - 1)
- (*lp)->flags |= __ISPASTEOL;
- else
- (*x)++;
-#ifdef DEBUG
- __CTRACE(__CTRACE_INPUT,
- "ADDBYTES: 2: y = %d, x = %d, firstch = %d, "
- "lastch = %d\n",
- *y, *x, *win->alines[*y]->firstchp,
- *win->alines[*y]->lastchp);
-#endif
- break;
- case '\n':
- PSYNCH_OUT;
- wclrtoeol(win);
- PSYNCH_IN;
- goto new_line;
- case '\r':
- *x = 0;
- break;
- case '\b':
- if (--(*x) < 0)
- *x = 0;
- break;
+ if (!(win->flags & __SCROLLOK))
+ return ERR;
+ PSYNCH_OUT;
+ scroll(win);
+ PSYNCH_IN;
+ } else {
+ (*y)++;
+ }
Home |
Main Index |
Thread Index |
Old Index