diff options
Diffstat (limited to 'lib/libcurses/base')
-rw-r--r-- | lib/libcurses/base/lib_addch.c | 355 | ||||
-rw-r--r-- | lib/libcurses/base/lib_addstr.c | 90 | ||||
-rw-r--r-- | lib/libcurses/base/lib_box.c | 139 | ||||
-rw-r--r-- | lib/libcurses/base/lib_clrbot.c | 49 | ||||
-rw-r--r-- | lib/libcurses/base/lib_clreol.c | 80 | ||||
-rw-r--r-- | lib/libcurses/base/lib_color.c | 16 | ||||
-rw-r--r-- | lib/libcurses/base/lib_dft_fgbg.c | 6 | ||||
-rw-r--r-- | lib/libcurses/base/lib_getch.c | 31 | ||||
-rw-r--r-- | lib/libcurses/base/lib_hline.c | 51 | ||||
-rw-r--r-- | lib/libcurses/base/lib_insstr.c | 58 | ||||
-rw-r--r-- | lib/libcurses/base/lib_move.c | 34 | ||||
-rw-r--r-- | lib/libcurses/base/lib_newterm.c | 20 | ||||
-rw-r--r-- | lib/libcurses/base/lib_newwin.c | 397 | ||||
-rw-r--r-- | lib/libcurses/base/lib_pad.c | 411 | ||||
-rw-r--r-- | lib/libcurses/base/lib_refresh.c | 238 | ||||
-rw-r--r-- | lib/libcurses/base/lib_scroll.c | 126 | ||||
-rw-r--r-- | lib/libcurses/base/lib_scrreg.c | 36 | ||||
-rw-r--r-- | lib/libcurses/base/lib_set_term.c | 16 | ||||
-rw-r--r-- | lib/libcurses/base/lib_vline.c | 57 |
19 files changed, 1149 insertions, 1061 deletions
diff --git a/lib/libcurses/base/lib_addch.c b/lib/libcurses/base/lib_addch.c index 5238783668e..43dc5aca13b 100644 --- a/lib/libcurses/base/lib_addch.c +++ b/lib/libcurses/base/lib_addch.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_addch.c,v 1.2 1999/08/15 11:40:55 millert Exp $ */ +/* $OpenBSD: lib_addch.c,v 1.3 2000/06/19 03:53:38 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -43,7 +43,7 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$From: lib_addch.c,v 1.42 1999/07/24 20:01:05 tom Exp $") +MODULE_ID("$From: lib_addch.c,v 1.44 2000/05/20 21:13:11 tom Exp $") /* * Ugly microtweaking alert. Everything from here to end of module is @@ -58,40 +58,40 @@ MODULE_ID("$From: lib_addch.c,v 1.42 1999/07/24 20:01:05 tom Exp $") /* Return bit mask for clearing color pair number if given ch has color */ #define COLOR_MASK(ch) (~(chtype)((ch)&A_COLOR?A_COLOR:0)) -static inline chtype render_char(WINDOW *win, chtype ch) +static inline chtype +render_char(WINDOW *win, chtype ch) /* compute a rendition of the given char correct for the current context */ { - chtype a = win->_attrs; - - if (ch == ' ') - { - /* color in attrs has precedence over bkgd */ - ch = a | (win->_bkgd & COLOR_MASK(a)); - } - else - { - /* color in attrs has precedence over bkgd */ - a |= (win->_bkgd & A_ATTRIBUTES) & COLOR_MASK(a); - /* color in ch has precedence */ - ch |= (a & COLOR_MASK(ch)); - } - - TR(TRACE_VIRTPUT, ("bkg = %lx, attrs = %lx -> ch = %lx", win->_bkgd, - win->_attrs, ch)); - - return(ch); + chtype a = win->_attrs; + + if (ch == ' ') { + /* color in attrs has precedence over bkgd */ + ch = a | (win->_bkgd & COLOR_MASK(a)); + } else { + /* color in attrs has precedence over bkgd */ + a |= (win->_bkgd & A_ATTRIBUTES) & COLOR_MASK(a); + /* color in ch has precedence */ + ch |= (a & COLOR_MASK(ch)); + } + + TR(TRACE_VIRTPUT, ("bkg = %lx, attrs = %lx -> ch = %lx", win->_bkgd, + win->_attrs, ch)); + + return (ch); } -chtype _nc_background(WINDOW *win) +chtype +_nc_background(WINDOW *win) /* make render_char() visible while still allowing us to inline it below */ { - return (win->_bkgd); + return (win->_bkgd); } -chtype _nc_render(WINDOW *win, chtype ch) +chtype +_nc_render(WINDOW *win, chtype ch) /* make render_char() visible while still allowing us to inline it below */ { - return render_char(win, ch); + return render_char(win, ch); } /* check if position is legal; if not, return error */ @@ -107,149 +107,152 @@ chtype _nc_render(WINDOW *win, chtype ch) return(ERR); \ } #else -#define CHECK_POSITION(win, x, y) /* nothing */ +#define CHECK_POSITION(win, x, y) /* nothing */ #endif -static inline -int waddch_literal(WINDOW *win, chtype ch) +static inline int +waddch_literal(WINDOW *win, chtype ch) { - int x; - struct ldat *line; + int x; + struct ldat *line; + + x = win->_curx; + + CHECK_POSITION(win, x, win->_cury); + + /* + * If we're trying to add a character at the lower-right corner more + * than once, fail. (Moving the cursor will clear the flag). + */ +#if 0 /* Solaris 2.6 allows updating the corner more than once */ + if (win->_flags & _WRAPPED) { + if (x >= win->_maxx) + return (ERR); + win->_flags &= ~_WRAPPED; + } +#endif + + ch = render_char(win, ch); + TR(TRACE_VIRTPUT, ("win attr = %s", _traceattr(win->_attrs))); - x = win->_curx; + line = win->_line + win->_cury; - CHECK_POSITION(win, x, win->_cury); + CHANGED_CELL(line, x); + line->text[x++] = ch; + + TR(TRACE_VIRTPUT, ("(%d, %d) = %s", win->_cury, x, _tracechtype(ch))); + if (x > win->_maxx) { /* - * If we're trying to add a character at the lower-right corner more - * than once, fail. (Moving the cursor will clear the flag). + * The _WRAPPED flag is useful only for telling an application that + * we've just wrapped the cursor. We don't do anything with this flag + * except set it when wrapping, and clear it whenever we move the + * cursor. If we try to wrap at the lower-right corner of a window, we + * cannot move the cursor (since that wouldn't be legal). So we return + * an error (which is what SVr4 does). Unlike SVr4, we can + * successfully add a character to the lower-right corner (Solaris 2.6 + * does this also, however). */ - if (win->_flags & _WRAPPED) { - if (x >= win->_maxx) - return (ERR); - win->_flags &= ~_WRAPPED; - } - - ch = render_char(win, ch); - TR(TRACE_VIRTPUT, ("win attr = %s", _traceattr(win->_attrs))); - - line = win->_line+win->_cury; - - CHANGED_CELL(line,x); - - line->text[x++] = ch; - - TR(TRACE_VIRTPUT, ("(%d, %d) = %s", win->_cury, x, _tracechtype(ch))); - if (x > win->_maxx) { - /* - * The _WRAPPED flag is useful only for telling an application - * that we've just wrapped the cursor. We don't do anything - * with this flag except set it when wrapping, and clear it - * whenever we move the cursor. If we try to wrap at the - * lower-right corner of a window, we cannot move the cursor - * (since that wouldn't be legal). So we return an error - * (which is what SVr4 does). Unlike SVr4, we can successfully - * add a character to the lower-right corner. - */ - win->_flags |= _WRAPPED; - if (++win->_cury > win->_regbottom) { - win->_cury = win->_regbottom; - win->_curx = win->_maxx; - if (!win->_scroll) - return (ERR); - scroll(win); - } - win->_curx = 0; - return (OK); + win->_flags |= _WRAPPED; + if (++win->_cury > win->_regbottom) { + win->_cury = win->_regbottom; + win->_curx = win->_maxx; + if (!win->_scroll) + return (ERR); + scroll(win); } - win->_curx = x; - return OK; + win->_curx = 0; + return (OK); + } + win->_curx = x; + return OK; } -static inline -int waddch_nosync(WINDOW *win, const chtype ch) +static inline int +waddch_nosync(WINDOW *win, const chtype ch) /* the workhorse function -- add a character to the given window */ { - int x, y; - int t = 0; - const char *s = 0; - - if ((ch & A_ALTCHARSET) - || ((t = TextOf(ch)) > 127) - || ((s = unctrl(t))[1] == 0)) - return waddch_literal(win, ch); - - x = win->_curx; - y = win->_cury; - - switch (t) { - case '\t': - x += (TABSIZE-(x%TABSIZE)); - - /* - * Space-fill the tab on the bottom line so that we'll get the - * "correct" cursor position. - */ - if ((! win->_scroll && (y == win->_regbottom)) - || (x <= win->_maxx)) { - chtype blank = (' ' | AttrOf(ch)); - while (win->_curx < x) { - if (waddch_literal(win, blank) == ERR) - return(ERR); - } - break; - } else { - wclrtoeol(win); - win->_flags |= _WRAPPED; - if (++y > win->_regbottom) { - x = win->_maxx; - y--; - if (win->_scroll) { - scroll(win); - x = 0; - } - } else { - x = 0; - } - } - break; - case '\n': - wclrtoeol(win); - if (++y > win->_regbottom) { - y--; - if (win->_scroll) - scroll(win); - else - return (ERR); + int x, y; + int t = 0; + const char *s = 0; + + if ((ch & A_ALTCHARSET) + || ((t = TextOf(ch)) > 127) + || ((s = unctrl(t))[1] == 0)) + return waddch_literal(win, ch); + + x = win->_curx; + y = win->_cury; + + switch (t) { + case '\t': + x += (TABSIZE - (x % TABSIZE)); + + /* + * Space-fill the tab on the bottom line so that we'll get the + * "correct" cursor position. + */ + if ((!win->_scroll && (y == win->_regbottom)) + || (x <= win->_maxx)) { + chtype blank = (' ' | AttrOf(ch)); + while (win->_curx < x) { + if (waddch_literal(win, blank) == ERR) + return (ERR); + } + break; + } else { + wclrtoeol(win); + win->_flags |= _WRAPPED; + if (++y > win->_regbottom) { + x = win->_maxx; + y--; + if (win->_scroll) { + scroll(win); + x = 0; } - /* FALLTHRU */ - case '\r': + } else { x = 0; - win->_flags &= ~_WRAPPED; - break; - case '\b': - if (x == 0) - return (OK); - x--; - win->_flags &= ~_WRAPPED; - break; - default: - while (*s) - if (waddch_literal(win, (*s++)|AttrOf(ch)) == ERR) - return ERR; - return(OK); + } } - - win->_curx = x; - win->_cury = y; - - return(OK); + break; + case '\n': + wclrtoeol(win); + if (++y > win->_regbottom) { + y--; + if (win->_scroll) + scroll(win); + else + return (ERR); + } + /* FALLTHRU */ + case '\r': + x = 0; + win->_flags &= ~_WRAPPED; + break; + case '\b': + if (x == 0) + return (OK); + x--; + win->_flags &= ~_WRAPPED; + break; + default: + while (*s) + if (waddch_literal(win, (*s++) | AttrOf(ch)) == ERR) + return ERR; + return (OK); + } + + win->_curx = x; + win->_cury = y; + + return (OK); } -int _nc_waddch_nosync(WINDOW *win, const chtype c) +int +_nc_waddch_nosync(WINDOW *win, const chtype c) /* export copy of waddch_nosync() so the string-put functions can use it */ { - return(waddch_nosync(win, c)); + return (waddch_nosync(win, c)); } /* @@ -260,36 +263,38 @@ int _nc_waddch_nosync(WINDOW *win, const chtype c) /* These are actual entry points */ -int waddch(WINDOW *win, const chtype ch) +int +waddch(WINDOW *win, const chtype ch) { - int code = ERR; + int code = ERR; - TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_CALLED("waddch(%p, %s)"), win, _tracechtype(ch))); + TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("waddch(%p, %s)"), win, + _tracechtype(ch))); - if (win && (waddch_nosync(win, ch) != ERR)) - { - _nc_synchook(win); - code = OK; - } + if (win && (waddch_nosync(win, ch) != ERR)) { + _nc_synchook(win); + code = OK; + } - TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_RETURN("%d"), code)); - return(code); + TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code)); + return (code); } -int wechochar(WINDOW *win, const chtype ch) +int +wechochar(WINDOW *win, const chtype ch) { - int code = ERR; - - TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"), win, _tracechtype(ch))); - - if (win && (waddch_nosync(win, ch) != ERR)) - { - bool save_immed = win->_immed; - win->_immed = TRUE; - _nc_synchook(win); - win->_immed = save_immed; - code = OK; - } - TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_RETURN("%d"), code)); - return(code); + int code = ERR; + + TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"), win, + _tracechtype(ch))); + + if (win && (waddch_nosync(win, ch) != ERR)) { + bool save_immed = win->_immed; + win->_immed = TRUE; + _nc_synchook(win); + win->_immed = save_immed; + code = OK; + } + TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code)); + return (code); } diff --git a/lib/libcurses/base/lib_addstr.c b/lib/libcurses/base/lib_addstr.c index 2514981ce62..32d5fbb116f 100644 --- a/lib/libcurses/base/lib_addstr.c +++ b/lib/libcurses/base/lib_addstr.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_addstr.c,v 1.1 1999/01/18 19:09:35 millert Exp $ */ +/* $OpenBSD: lib_addstr.c,v 1.2 2000/06/19 03:53:38 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,64 +42,64 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_addstr.c,v 1.16 1998/06/28 00:38:29 tom Exp $") +MODULE_ID("$From: lib_addstr.c,v 1.17 2000/04/29 21:15:55 tom Exp $") int waddnstr(WINDOW *win, const char *const astr, int n) { -unsigned const char *str = (unsigned const char *)astr; -int code = ERR; + unsigned const char *str = (unsigned const char *) astr; + int code = ERR; - T((T_CALLED("waddnstr(%p,%s,%d)"), win, _nc_visbuf(astr), n)); - - if (win && (str != 0)) { - T(("... current %s", _traceattr(win->_attrs))); - TR(TRACE_VIRTPUT, ("str is not null")); - code = OK; - if (n < 0) - n = (int)strlen(astr); - - while((n-- > 0) && (*str != '\0')) { + T((T_CALLED("waddnstr(%p,%s,%d)"), win, _nc_visbuf(astr), n)); + + if (win && (str != 0)) { + T(("... current %s", _traceattr(win->_attrs))); + TR(TRACE_VIRTPUT, ("str is not null")); + code = OK; + if (n < 0) + n = (int) strlen(astr); + + while ((n-- > 0) && (*str != '\0')) { TR(TRACE_VIRTPUT, ("*str = %#x", *str)); - if (_nc_waddch_nosync(win, (chtype)*str++) == ERR) { - code = ERR; - break; + if (_nc_waddch_nosync(win, (chtype) * str++) == ERR) { + code = ERR; + break; } - } - _nc_synchook(win); } - TR(TRACE_VIRTPUT, ("waddnstr returns %d", code)); - returnCode(code); + _nc_synchook(win); + } + TR(TRACE_VIRTPUT, ("waddnstr returns %d", code)); + returnCode(code); } int -waddchnstr(WINDOW *win, const chtype *const astr, int n) +waddchnstr(WINDOW *win, const chtype * const astr, int n) { -short y = win->_cury; -short x = win->_curx; -int code = OK; -struct ldat *line; + NCURSES_SIZE_T y = win->_cury; + NCURSES_SIZE_T x = win->_curx; + int code = OK; + struct ldat *line; - T((T_CALLED("waddchnstr(%p,%p,%d)"), win, astr, n)); + T((T_CALLED("waddchnstr(%p,%p,%d)"), win, astr, n)); - if (!win) - returnCode(ERR); + if (!win) + returnCode(ERR); - if (n < 0) { - const chtype *str; - n = 0; - for (str=(const chtype *)astr; *str!=0; str++) - n++; - } - if (n > win->_maxx - x + 1) - n = win->_maxx - x + 1; - if (n == 0) - returnCode(code); + if (n < 0) { + const chtype *str; + n = 0; + for (str = (const chtype *) astr; *str != 0; str++) + n++; + } + if (n > win->_maxx - x + 1) + n = win->_maxx - x + 1; + if (n == 0) + returnCode(code); - line = &(win->_line[y]); - memcpy(line->text+x, astr, n*sizeof(*astr)); - CHANGED_RANGE(line, x, x+n-1); + line = &(win->_line[y]); + memcpy(line->text + x, astr, n * sizeof(*astr)); + CHANGED_RANGE(line, x, x + n - 1); - _nc_synchook(win); - returnCode(code); + _nc_synchook(win); + returnCode(code); } diff --git a/lib/libcurses/base/lib_box.c b/lib/libcurses/base/lib_box.c index 29918f229bc..0593b769e4e 100644 --- a/lib/libcurses/base/lib_box.c +++ b/lib/libcurses/base/lib_box.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_box.c,v 1.1 1999/01/18 19:09:37 millert Exp $ */ +/* $OpenBSD: lib_box.c,v 1.2 2000/06/19 03:53:39 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998,2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,8 +33,6 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - - /* ** lib_box.c ** @@ -44,69 +42,80 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_box.c,v 1.10 1998/02/11 12:13:56 tom Exp $") +MODULE_ID("$From: lib_box.c,v 1.11 2000/04/29 21:12:37 tom Exp $") -int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, - chtype bs, chtype tl, chtype tr, chtype bl, chtype br) +int +wborder(WINDOW *win, + chtype ls, chtype rs, chtype ts, chtype bs, + chtype tl, chtype tr, chtype bl, chtype br) { -short i; -short endx, endy; + NCURSES_SIZE_T i; + NCURSES_SIZE_T endx, endy; T((T_CALLED("wborder(%p,%s,%s,%s,%s,%s,%s,%s,%s)"), - win, - _tracechtype2(1,ls), - _tracechtype2(2,rs), - _tracechtype2(3,ts), - _tracechtype2(4,bs), - _tracechtype2(5,tl), - _tracechtype2(6,tr), - _tracechtype2(7,bl), - _tracechtype2(8,br))); - - if (!win) - returnCode(ERR); - - if (ls == 0) ls = ACS_VLINE; - if (rs == 0) rs = ACS_VLINE; - if (ts == 0) ts = ACS_HLINE; - if (bs == 0) bs = ACS_HLINE; - if (tl == 0) tl = ACS_ULCORNER; - if (tr == 0) tr = ACS_URCORNER; - if (bl == 0) bl = ACS_LLCORNER; - if (br == 0) br = ACS_LRCORNER; - - ls = _nc_render(win, ls); - rs = _nc_render(win, rs); - ts = _nc_render(win, ts); - bs = _nc_render(win, bs); - tl = _nc_render(win, tl); - tr = _nc_render(win, tr); - bl = _nc_render(win, bl); - br = _nc_render(win, br); - - T(("using %#lx, %#lx, %#lx, %#lx, %#lx, %#lx, %#lx, %#lx", ls, rs, ts, bs, tl, tr, bl, br)); - - endx = win->_maxx; - endy = win->_maxy; - - for (i = 0; i <= endx; i++) { - win->_line[0].text[i] = ts; - win->_line[endy].text[i] = bs; - } - win->_line[endy].firstchar = win->_line[0].firstchar = 0; - win->_line[endy].lastchar = win->_line[0].lastchar = endx; - - for (i = 0; i <= endy; i++) { - win->_line[i].text[0] = ls; - win->_line[i].text[endx] = rs; - win->_line[i].firstchar = 0; - win->_line[i].lastchar = endx; - } - win->_line[0].text[0] = tl; - win->_line[0].text[endx] = tr; - win->_line[endy].text[0] = bl; - win->_line[endy].text[endx] = br; - - _nc_synchook(win); - returnCode(OK); + win, + _tracechtype2(1, ls), + _tracechtype2(2, rs), + _tracechtype2(3, ts), + _tracechtype2(4, bs), + _tracechtype2(5, tl), + _tracechtype2(6, tr), + _tracechtype2(7, bl), + _tracechtype2(8, br))); + + if (!win) + returnCode(ERR); + + if (ls == 0) + ls = ACS_VLINE; + if (rs == 0) + rs = ACS_VLINE; + if (ts == 0) + ts = ACS_HLINE; + if (bs == 0) + bs = ACS_HLINE; + if (tl == 0) + tl = ACS_ULCORNER; + if (tr == 0) + tr = ACS_URCORNER; + if (bl == 0) + bl = ACS_LLCORNER; + if (br == 0) + br = ACS_LRCORNER; + + ls = _nc_render(win, ls); + rs = _nc_render(win, rs); + ts = _nc_render(win, ts); + bs = _nc_render(win, bs); + tl = _nc_render(win, tl); + tr = _nc_render(win, tr); + bl = _nc_render(win, bl); + br = _nc_render(win, br); + + T(("using %#lx, %#lx, %#lx, %#lx, %#lx, %#lx, %#lx, %#lx", + ls, rs, ts, bs, tl, tr, bl, br)); + + endx = win->_maxx; + endy = win->_maxy; + + for (i = 0; i <= endx; i++) { + win->_line[0].text[i] = ts; + win->_line[endy].text[i] = bs; + } + win->_line[endy].firstchar = win->_line[0].firstchar = 0; + win->_line[endy].lastchar = win->_line[0].lastchar = endx; + + for (i = 0; i <= endy; i++) { + win->_line[i].text[0] = ls; + win->_line[i].text[endx] = rs; + win->_line[i].firstchar = 0; + win->_line[i].lastchar = endx; + } + win->_line[0].text[0] = tl; + win->_line[0].text[endx] = tr; + win->_line[endy].text[0] = bl; + win->_line[endy].text[endx] = br; + + _nc_synchook(win); + returnCode(OK); } diff --git a/lib/libcurses/base/lib_clrbot.c b/lib/libcurses/base/lib_clrbot.c index ba68bd574e7..683b4f923d6 100644 --- a/lib/libcurses/base/lib_clrbot.c +++ b/lib/libcurses/base/lib_clrbot.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_clrbot.c,v 1.1 1999/01/18 19:09:38 millert Exp $ */ +/* $OpenBSD: lib_clrbot.c,v 1.2 2000/06/19 03:53:39 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,36 +42,37 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_clrbot.c,v 1.14 1998/06/28 00:36:26 tom Exp $") +MODULE_ID("$From: lib_clrbot.c,v 1.15 2000/04/29 21:15:26 tom Exp $") -int wclrtobot(WINDOW *win) +int +wclrtobot(WINDOW *win) { -int code = ERR; + int code = ERR; - T((T_CALLED("wclrtobot(%p)"), win)); + T((T_CALLED("wclrtobot(%p)"), win)); - if (win) { - short y; - short startx = win->_curx; - chtype blank = _nc_background(win); + if (win) { + NCURSES_SIZE_T y; + NCURSES_SIZE_T startx = win->_curx; + chtype blank = _nc_background(win); - T(("clearing from y = %d to y = %d with maxx = %d", win->_cury, win->_maxy, win->_maxx)); + T(("clearing from y = %d to y = %d with maxx = %d", + win->_cury, win->_maxy, win->_maxx)); - for (y = win->_cury; y <= win->_maxy; y++) { - struct ldat *line = &(win->_line[y]); - chtype *ptr = &(line->text[startx]); - chtype *end = &(line->text[win->_maxx]); + for (y = win->_cury; y <= win->_maxy; y++) { + struct ldat *line = &(win->_line[y]); + chtype *ptr = &(line->text[startx]); + chtype *end = &(line->text[win->_maxx]); - CHANGED_TO_EOL(line, startx, win->_maxx); + CHANGED_TO_EOL(line, startx, win->_maxx); - while (ptr <= end) - *ptr++ = blank; + while (ptr <= end) + *ptr++ = blank; - startx = 0; - } - _nc_synchook(win); - code = OK; + startx = 0; } - returnCode(code); + _nc_synchook(win); + code = OK; + } + returnCode(code); } - diff --git a/lib/libcurses/base/lib_clreol.c b/lib/libcurses/base/lib_clreol.c index 163bd2d06ff..29c417f5ed3 100644 --- a/lib/libcurses/base/lib_clreol.c +++ b/lib/libcurses/base/lib_clreol.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_clreol.c,v 1.1 1999/01/18 19:09:39 millert Exp $ */ +/* $OpenBSD: lib_clreol.c,v 1.2 2000/06/19 03:53:40 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,7 +33,6 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - /* ** lib_clreol.c ** @@ -43,51 +42,52 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_clreol.c,v 1.15 1998/06/28 00:32:20 tom Exp $") +MODULE_ID("$From: lib_clreol.c,v 1.16 2000/04/29 21:14:54 tom Exp $") -int wclrtoeol(WINDOW *win) +int +wclrtoeol(WINDOW *win) { -int code = ERR; + int code = ERR; - T((T_CALLED("wclrtoeol(%p)"), win)); + T((T_CALLED("wclrtoeol(%p)"), win)); - if (win) { - chtype blank; - chtype *ptr, *end; - struct ldat *line; - short y = win->_cury; - short x = win->_curx; + if (win) { + chtype blank; + chtype *ptr, *end; + struct ldat *line; + NCURSES_SIZE_T y = win->_cury; + NCURSES_SIZE_T x = win->_curx; - /* - * If we have just wrapped the cursor, the clear applies to the - * new line, unless we are at the lower right corner. - */ - if (win->_flags & _WRAPPED - && y < win->_maxy) { - win->_flags &= ~_WRAPPED; - } + /* + * If we have just wrapped the cursor, the clear applies to the + * new line, unless we are at the lower right corner. + */ + if (win->_flags & _WRAPPED + && y < win->_maxy) { + win->_flags &= ~_WRAPPED; + } - /* - * There's no point in clearing if we're not on a legal - * position, either. - */ - if (win->_flags & _WRAPPED - || y > win->_maxy - || x > win->_maxx) - returnCode(ERR); + /* + * There's no point in clearing if we're not on a legal + * position, either. + */ + if (win->_flags & _WRAPPED + || y > win->_maxy + || x > win->_maxx) + returnCode(ERR); - blank = _nc_background(win); - line = &win->_line[y]; - CHANGED_TO_EOL(line, x, win->_maxx); + blank = _nc_background(win); + line = &win->_line[y]; + CHANGED_TO_EOL(line, x, win->_maxx); - ptr = &(line->text[x]); - end = &(line->text[win->_maxx]); + ptr = &(line->text[x]); + end = &(line->text[win->_maxx]); - while (ptr <= end) - *ptr++ = blank; + while (ptr <= end) + *ptr++ = blank; - _nc_synchook(win); - code = OK; - } - returnCode(code); + _nc_synchook(win); + code = OK; + } + returnCode(code); } diff --git a/lib/libcurses/base/lib_color.c b/lib/libcurses/base/lib_color.c index 7d246bd05ee..a1a195453c4 100644 --- a/lib/libcurses/base/lib_color.c +++ b/lib/libcurses/base/lib_color.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_color.c,v 1.7 2000/03/26 16:45:03 millert Exp $ */ +/* $OpenBSD: lib_color.c,v 1.8 2000/06/19 03:53:40 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * @@ -43,7 +43,7 @@ #include <term.h> #include <tic.h> -MODULE_ID("$From: lib_color.c,v 1.49 2000/03/26 03:12:12 tom Exp $") +MODULE_ID("$From: lib_color.c,v 1.51 2000/05/20 20:09:22 tom Exp $") /* * These should be screen structure members. They need to be globals for @@ -314,7 +314,7 @@ init_pair(short pair, short f, short b) } } SP->_color_pairs[pair] = result; - if ((int)(SP->_current_attr & A_COLOR) == COLOR_PAIR(pair)) + if ((int) (SP->_current_attr & A_COLOR) == COLOR_PAIR(pair)) SP->_current_attr |= A_COLOR; /* force attribute update */ if (initialize_pair) { @@ -421,10 +421,12 @@ pair_content(short pair, short *f, short *b) void _nc_do_color(int old_pair, int pair, bool reverse, int (*outc) (int)) { - short fg = C_MASK, bg = C_MASK; - short old_fg, old_bg; + NCURSES_COLOR_T fg = C_MASK, bg = C_MASK; + NCURSES_COLOR_T old_fg, old_bg; - if (pair != 0) { + if (pair < 0 || pair >= COLOR_PAIRS) { + return; + } else if (pair != 0) { if (set_color_pair) { TPUTS_TRACE("set_color_pair"); tputs(tparm(set_color_pair, pair), 1, outc); @@ -466,7 +468,7 @@ _nc_do_color(int old_pair, int pair, bool reverse, int (*outc) (int)) #endif if (reverse) { - short xx = fg; + NCURSES_COLOR_T xx = fg; fg = bg; bg = xx; } diff --git a/lib/libcurses/base/lib_dft_fgbg.c b/lib/libcurses/base/lib_dft_fgbg.c index b695b6d7f1e..bad566299e4 100644 --- a/lib/libcurses/base/lib_dft_fgbg.c +++ b/lib/libcurses/base/lib_dft_fgbg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_dft_fgbg.c,v 1.4 2000/03/26 16:45:03 millert Exp $ */ +/* $OpenBSD: lib_dft_fgbg.c,v 1.5 2000/06/19 03:53:41 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * @@ -35,7 +35,7 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("$From: lib_dft_fgbg.c,v 1.10 2000/03/26 03:08:53 Alexander.V.Lukyanov Exp $") +MODULE_ID("$From: lib_dft_fgbg.c,v 1.11 2000/05/07 01:26:06 tom Exp $") /* * Modify the behavior of color-pair 0 so that the library doesn't assume that @@ -64,7 +64,7 @@ assume_default_colors(int fg, int bg) returnCode(ERR); SP->_default_color = (fg != COLOR_WHITE) || (bg != COLOR_BLACK); - SP->_has_sgr_39_49 = tigetflag("AX"); + SP->_has_sgr_39_49 = (tigetflag("AX") == TRUE); SP->_default_fg = (fg >= 0) ? (fg & C_MASK) : C_MASK; SP->_default_bg = (bg >= 0) ? (bg & C_MASK) : C_MASK; if (SP->_color_pairs != 0) diff --git a/lib/libcurses/base/lib_getch.c b/lib/libcurses/base/lib_getch.c index 3057117c347..f7b6de9490f 100644 --- a/lib/libcurses/base/lib_getch.c +++ b/lib/libcurses/base/lib_getch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_getch.c,v 1.4 2000/03/10 01:35:02 millert Exp $ */ +/* $OpenBSD: lib_getch.c,v 1.5 2000/06/19 03:53:41 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_getch.c,v 1.46 2000/02/20 01:21:33 tom Exp $") +MODULE_ID("$From: lib_getch.c,v 1.47 2000/05/28 01:12:51 tom Exp $") #include <fifo_defs.h> @@ -310,6 +310,30 @@ wgetch(WINDOW *win) } /* + * If echo() is in effect, display the printable version of the + * key on the screen. Carriage return and backspace are treated + * specially by Solaris curses: + * + * If carriage return is defined as a function key in the + * terminfo, e.g., kent, then Solaris may return either ^J (or ^M + * if nonl() is set) or KEY_ENTER depending on the echo() mode. + * We echo before translating carriage return based on nonl(), + * since the visual result simply moves the cursor to column 0. + * + * Backspace is a different matter. Solaris curses does not + * translate it to KEY_BACKSPACE if kbs=^H. This does not depend + * on the stty modes, but appears to be a hardcoded special case. + * This is a difference from ncurses, which uses the terminfo entry. + * However, we provide the same visual result as Solaris, moving the + * cursor to the left. + */ + if (SP->_echo && !(win->_flags & _ISPAD)) { + chtype backup = (ch == KEY_BACKSPACE) ? '\b' : ch; + if (backup < KEY_MIN) + wechochar(win, backup); + } + + /* * Simulate ICRNL mode */ if ((ch == '\r') && SP->_nl) @@ -324,9 +348,6 @@ wgetch(WINDOW *win) if (!SP->_use_meta) ch &= 0x7f; - if (SP->_echo && ch < KEY_MIN && !(win->_flags & _ISPAD)) - wechochar(win, (chtype) ch); - T(("wgetch returning : %#x = %s", ch, _trace_key(ch))); returnCode(ch); diff --git a/lib/libcurses/base/lib_hline.c b/lib/libcurses/base/lib_hline.c index a9c7d8d2d13..9fec35b52df 100644 --- a/lib/libcurses/base/lib_hline.c +++ b/lib/libcurses/base/lib_hline.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_hline.c,v 1.1 1999/01/18 19:09:46 millert Exp $ */ +/* $OpenBSD: lib_hline.c,v 1.2 2000/06/19 03:53:42 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,8 +33,6 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - - /* ** lib_hline.c ** @@ -44,35 +42,36 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_hline.c,v 1.4 1998/06/28 00:11:01 tom Exp $") +MODULE_ID("$From: lib_hline.c,v 1.5 2000/04/29 21:14:30 tom Exp $") -int whline(WINDOW *win, chtype ch, int n) +int +whline(WINDOW *win, chtype ch, int n) { -int code = ERR; -short start; -short end; + int code = ERR; + NCURSES_SIZE_T start; + NCURSES_SIZE_T end; - T((T_CALLED("whline(%p,%s,%d)"), win, _tracechtype(ch), n)); + T((T_CALLED("whline(%p,%s,%d)"), win, _tracechtype(ch), n)); - if (win) { - struct ldat *line = &(win->_line[win->_cury]); + if (win) { + struct ldat *line = &(win->_line[win->_cury]); - start = win->_curx; - end = start + n - 1; - if (end > win->_maxx) - end = win->_maxx; + start = win->_curx; + end = start + n - 1; + if (end > win->_maxx) + end = win->_maxx; - CHANGED_RANGE(line, start, end); + CHANGED_RANGE(line, start, end); - if (ch == 0) - ch = ACS_HLINE; - ch = _nc_render(win, ch); + if (ch == 0) + ch = ACS_HLINE; + ch = _nc_render(win, ch); - while ( end >= start) { - line->text[end] = ch; - end--; - } - code = OK; + while (end >= start) { + line->text[end] = ch; + end--; } - returnCode(code); + code = OK; + } + returnCode(code); } diff --git a/lib/libcurses/base/lib_insstr.c b/lib/libcurses/base/lib_insstr.c index db41e072158..69b1777f172 100644 --- a/lib/libcurses/base/lib_insstr.c +++ b/lib/libcurses/base/lib_insstr.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_insstr.c,v 1.2 1999/03/14 03:10:32 millert Exp $ */ +/* $OpenBSD: lib_insstr.c,v 1.3 2000/06/19 03:53:42 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,8 +33,6 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - - /* ** lib_insstr.c ** @@ -45,39 +43,41 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$From: lib_insstr.c,v 1.13 1999/03/14 00:27:21 tom Exp $") +MODULE_ID("$From: lib_insstr.c,v 1.14 2000/04/29 21:16:41 tom Exp $") -int winsnstr(WINDOW *win, const char *s, int n) +int +winsnstr(WINDOW *win, const char *s, int n) { -int code = ERR; -short oy; -short ox ; -const unsigned char *str = (const unsigned char *)s; -const unsigned char *cp; + int code = ERR; + NCURSES_SIZE_T oy; + NCURSES_SIZE_T ox; + const unsigned char *str = (const unsigned char *) s; + const unsigned char *cp; - T((T_CALLED("winsnstr(%p,%s,%d)"), win, _nc_visbuf(s), n)); + T((T_CALLED("winsnstr(%p,%s,%d)"), win, _nc_visbuf(s), n)); - if (win && str) { - oy = win->_cury; ox = win->_curx; - for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) { + if (win && str) { + oy = win->_cury; + ox = win->_curx; + for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) { if (*cp == '\n' || *cp == '\r' || *cp == '\t' || *cp == '\b') - _nc_waddch_nosync(win, (chtype)(*cp)); + _nc_waddch_nosync(win, (chtype) (*cp)); else if (is7bits(*cp) && iscntrl(*cp)) { - winsch(win, ' ' + (chtype)(*cp)); - winsch(win, '^'); - win->_curx += 2; + winsch(win, ' ' + (chtype) (*cp)); + winsch(win, '^'); + win->_curx += 2; } else { - winsch(win, (chtype)(*cp)); - win->_curx++; + winsch(win, (chtype) (*cp)); + win->_curx++; } if (win->_curx > win->_maxx) - win->_curx = win->_maxx; - } - - win->_curx = ox; - win->_cury = oy; - _nc_synchook(win); - code = OK; + win->_curx = win->_maxx; } - returnCode(code); + + win->_curx = ox; + win->_cury = oy; + _nc_synchook(win); + code = OK; + } + returnCode(code); } diff --git a/lib/libcurses/base/lib_move.c b/lib/libcurses/base/lib_move.c index 96b93998838..ce700863e59 100644 --- a/lib/libcurses/base/lib_move.c +++ b/lib/libcurses/base/lib_move.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_move.c,v 1.1 1999/01/18 19:09:52 millert Exp $ */ +/* $OpenBSD: lib_move.c,v 1.2 2000/06/19 03:53:43 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998,2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,7 +33,6 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - /* ** lib_move.c ** @@ -43,23 +42,22 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_move.c,v 1.8 1998/02/11 12:13:53 tom Exp $") +MODULE_ID("$From: lib_move.c,v 1.9 2000/04/29 21:11:19 tom Exp $") int wmove(WINDOW *win, int y, int x) { - T((T_CALLED("wmove(%p,%d,%d)"), win, y, x)); - - if (win && - x >= 0 && x <= win->_maxx && - y >= 0 && y <= win->_maxy) - { - win->_curx = (short)x; - win->_cury = (short)y; - - win->_flags &= ~_WRAPPED; - win->_flags |= _HASMOVED; - returnCode(OK); - } else - returnCode(ERR); + T((T_CALLED("wmove(%p,%d,%d)"), win, y, x)); + + if (win && + x >= 0 && x <= win->_maxx && + y >= 0 && y <= win->_maxy) { + win->_curx = (NCURSES_SIZE_T) x; + win->_cury = (NCURSES_SIZE_T) y; + + win->_flags &= ~_WRAPPED; + win->_flags |= _HASMOVED; + returnCode(OK); + } else + returnCode(ERR); } diff --git a/lib/libcurses/base/lib_newterm.c b/lib/libcurses/base/lib_newterm.c index 73899d4ecc8..b9f274bf7d3 100644 --- a/lib/libcurses/base/lib_newterm.c +++ b/lib/libcurses/base/lib_newterm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_newterm.c,v 1.7 2000/03/10 01:35:02 millert Exp $ */ +/* $OpenBSD: lib_newterm.c,v 1.8 2000/06/19 03:53:43 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * @@ -49,7 +49,7 @@ #include <term.h> /* clear_screen, cup & friends, cur_term */ #include <tic.h> -MODULE_ID("$From: lib_newterm.c,v 1.44 2000/02/13 00:59:39 tom Exp $") +MODULE_ID("$From: lib_newterm.c,v 1.45 2000/05/20 23:45:57 tom Exp $"); #ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */ #define ONLCR 0 @@ -193,6 +193,22 @@ newterm(NCURSES_CONST char *name, FILE * ofp, FILE * ifp) SP->_use_rmso = SGR0_TEST(exit_standout_mode); SP->_use_rmul = SGR0_TEST(exit_underline_mode); +#ifdef USE_WIDEC_SUPPORT + /* + * XFree86 xterm can be configured to support UTF-8 based on environment + * variable settings. + */ + { + char *s; + if (((s = getenv("LC_ALL")) != 0 + || (s = getenv("LC_CTYPE")) != 0 + || (s = getenv("LANG")) != 0) + && strstr(s, "UTF-8") != 0) { + SP->_outch = _nc_utf8_outch; + } + } +#endif + /* compute movement costs so we can do better move optimization */ _nc_mvcur_init(); diff --git a/lib/libcurses/base/lib_newwin.c b/lib/libcurses/base/lib_newwin.c index 66f2facd537..e7d2def4ebf 100644 --- a/lib/libcurses/base/lib_newwin.c +++ b/lib/libcurses/base/lib_newwin.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_newwin.c,v 1.2 1999/11/28 17:49:53 millert Exp $ */ +/* $OpenBSD: lib_newwin.c,v 1.3 2000/06/19 03:53:43 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,8 +33,6 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - - /* ** lib_newwin.c ** @@ -44,230 +42,247 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_newwin.c,v 1.22 1999/11/25 13:48:24 juergen Exp $") +MODULE_ID("$From: lib_newwin.c,v 1.24 2000/04/29 18:49:51 tom Exp $") -void _nc_freewin(WINDOW *win) +void +_nc_freewin(WINDOW *win) { -WINDOWLIST *p, *q; -int i; - - if (win != 0) { - for (p = _nc_windows, q = 0; p != 0; q = p, p = p->next) { - if (p->win == win) { - if (q == 0) - _nc_windows = p->next; - else - q->next = p->next; - free(p); - - if (! (win->_flags & _SUBWIN)) { - for (i = 0; i <= win->_maxy; i++) - FreeIfNeeded(win->_line[i].text); - } - free(win->_line); - free(win); - - if (win == curscr) curscr = 0; - if (win == stdscr) stdscr = 0; - if (win == newscr) newscr = 0; - - T(("...deleted win=%p", win)); - break; - } + WINDOWLIST *p, *q; + int i; + + if (win != 0) { + for (p = _nc_windows, q = 0; p != 0; q = p, p = p->next) { + if (p->win == win) { + if (q == 0) + _nc_windows = p->next; + else + q->next = p->next; + free(p); + + if (!(win->_flags & _SUBWIN)) { + for (i = 0; i <= win->_maxy; i++) + FreeIfNeeded(win->_line[i].text); } + free(win->_line); + free(win); + + if (win == curscr) + curscr = 0; + if (win == stdscr) + stdscr = 0; + if (win == newscr) + newscr = 0; + + T(("...deleted win=%p", win)); + break; + } } + } } -WINDOW * newwin(int num_lines, int num_columns, int begy, int begx) +WINDOW * +newwin(int num_lines, int num_columns, int begy, int begx) { -WINDOW *win; -chtype *ptr; -int i; + WINDOW *win; + chtype *ptr; + int i; - T((T_CALLED("newwin(%d,%d,%d,%d)"), num_lines, num_columns, begy, begx)); + T((T_CALLED("newwin(%d,%d,%d,%d)"), num_lines, num_columns, begy, begx)); - if (begy < 0 || begx < 0 || num_lines < 0 || num_columns < 0) - returnWin(0); + if (begy < 0 || begx < 0 || num_lines < 0 || num_columns < 0) + returnWin(0); - if (num_lines == 0) - num_lines = SP->_lines_avail - begy; - if (num_columns == 0) - num_columns = screen_columns - begx; + if (num_lines == 0) + num_lines = SP->_lines_avail - begy; + if (num_columns == 0) + num_columns = screen_columns - begx; - if (num_columns + begx > SP->_columns || num_lines + begy > SP->_lines_avail) - returnWin(0); + if (num_columns + begx > SP->_columns || num_lines + begy > SP->_lines_avail) + returnWin(0); - if ((win = _nc_makenew(num_lines, num_columns, begy, begx, 0)) == 0) - returnWin(0); + if ((win = _nc_makenew(num_lines, num_columns, begy, begx, 0)) == 0) + returnWin(0); - for (i = 0; i < num_lines; i++) { - if ((win->_line[i].text = typeCalloc(chtype, (unsigned)num_columns)) == 0) { - _nc_freewin(win); - returnWin(0); - } - for (ptr = win->_line[i].text; ptr < win->_line[i].text + num_columns; ) - *ptr++ = ' '; + for (i = 0; i < num_lines; i++) { + win->_line[i].text = typeCalloc(chtype, (unsigned) num_columns); + if (win->_line[i].text == 0) { + _nc_freewin(win); + returnWin(0); } + for (ptr = win->_line[i].text; ptr < win->_line[i].text + + num_columns;) + *ptr++ = ' '; + } - T(("newwin: returned window is %p", win)); + T(("newwin: returned window is %p", win)); - returnWin(win); + returnWin(win); } -WINDOW * derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx) +WINDOW * +derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx) { -WINDOW *win; -int i; -int flags = _SUBWIN; + WINDOW *win; + int i; + int flags = _SUBWIN; - T((T_CALLED("derwin(%p,%d,%d,%d,%d)"), orig, num_lines, num_columns, begy, begx)); + T((T_CALLED("derwin(%p,%d,%d,%d,%d)"), orig, num_lines, num_columns, + begy, begx)); - /* - ** make sure window fits inside the original one - */ - if ( begy < 0 || begx < 0 || orig == 0 || num_lines < 0 || num_columns < 0) - returnWin(0); - if ( begy + num_lines > orig->_maxy + 1 - || begx + num_columns > orig->_maxx + 1) - returnWin(0); + /* + ** make sure window fits inside the original one + */ + if (begy < 0 || begx < 0 || orig == 0 || num_lines < 0 || num_columns < 0) + returnWin(0); + if (begy + num_lines > orig->_maxy + 1 + || begx + num_columns > orig->_maxx + 1) + returnWin(0); - if (num_lines == 0) - num_lines = orig->_maxy + 1 - begy; + if (num_lines == 0) + num_lines = orig->_maxy + 1 - begy; - if (num_columns == 0) - num_columns = orig->_maxx + 1 - begx; + if (num_columns == 0) + num_columns = orig->_maxx + 1 - begx; - if (orig->_flags & _ISPAD) - flags |= _ISPAD; + if (orig->_flags & _ISPAD) + flags |= _ISPAD; - if ((win = _nc_makenew(num_lines, num_columns, orig->_begy + begy, orig->_begx + begx, flags)) == 0) - returnWin(0); + if ((win = _nc_makenew(num_lines, num_columns, orig->_begy + begy, + orig->_begx + begx, flags)) == 0) + returnWin(0); - win->_pary = begy; - win->_parx = begx; - win->_attrs = orig->_attrs; - win->_bkgd = orig->_bkgd; + win->_pary = begy; + win->_parx = begx; + win->_attrs = orig->_attrs; + win->_bkgd = orig->_bkgd; - for (i = 0; i < num_lines; i++) - win->_line[i].text = &orig->_line[begy++].text[begx]; + for (i = 0; i < num_lines; i++) + win->_line[i].text = &orig->_line[begy++].text[begx]; - win->_parent = orig; + win->_parent = orig; - T(("derwin: returned window is %p", win)); + T(("derwin: returned window is %p", win)); - returnWin(win); + returnWin(win); } - -WINDOW *subwin(WINDOW *w, int l, int c, int y, int x) +WINDOW * +subwin(WINDOW *w, int l, int c, int y, int x) { - T((T_CALLED("subwin(%p, %d, %d, %d, %d)"), w, l, c, y, x)); - T(("parent has begy = %d, begx = %d", w->_begy, w->_begx)); + T((T_CALLED("subwin(%p, %d, %d, %d, %d)"), w, l, c, y, x)); + T(("parent has begy = %d, begx = %d", w->_begy, w->_begx)); + + returnWin(derwin(w, l, c, y - w->_begy, x - w->_begx)); +} - returnWin(derwin(w, l, c, y - w->_begy, x - w->_begx)); +static bool +dimension_limit(int value) +{ + NCURSES_SIZE_T test = value; + return (test == value && value > 0); } WINDOW * _nc_makenew(int num_lines, int num_columns, int begy, int begx, int flags) { -int i; -WINDOWLIST *wp; -WINDOW *win; -bool is_pad = (flags & _ISPAD); - - T(("_nc_makenew(%d,%d,%d,%d)", num_lines, num_columns, begy, begx)); - - if (num_lines <= 0 || num_columns <= 0) - return 0; - - if ((wp = typeCalloc(WINDOWLIST, 1)) == 0) - return 0; - - if ((win = typeCalloc(WINDOW, 1)) == 0) - return 0; - - if ((win->_line = typeCalloc(struct ldat, ((unsigned)num_lines))) == 0) { - free(win); - return 0; - } - - win->_curx = 0; - win->_cury = 0; - win->_maxy = num_lines - 1; - win->_maxx = num_columns - 1; - win->_begy = begy; - win->_begx = begx; - win->_yoffset = SP->_topstolen; - - win->_flags = flags; - win->_attrs = A_NORMAL; - win->_bkgd = BLANK; - - win->_clear = is_pad ? FALSE : (num_lines == screen_lines && num_columns == screen_columns); - win->_idlok = FALSE; - win->_idcok = TRUE; - win->_scroll = FALSE; - win->_leaveok = FALSE; - win->_use_keypad = FALSE; - win->_delay = -1; - win->_immed = FALSE; - win->_sync = 0; - win->_parx = -1; - win->_pary = -1; - win->_parent = 0; - - win->_regtop = 0; - win->_regbottom = num_lines - 1; - - win->_pad._pad_y = -1; - win->_pad._pad_x = -1; - win->_pad._pad_top = -1; - win->_pad._pad_bottom = -1; - win->_pad._pad_left = -1; - win->_pad._pad_right = -1; - - for (i = 0; i < num_lines; i++) - { - /* - * This used to do - * - * win->_line[i].firstchar = win->_line[i].lastchar = _NOCHANGE; - * - * which marks the whole window unchanged. That's how - * SVr1 curses did it, but SVr4 curses marks the whole new - * window changed. - * - * With the old SVr1-like code, say you have stdscr full of - * characters, then create a new window with newwin(), - * then do a printw(win, "foo ");, the trailing spaces are - * completely ignored by the following refreshes. So, you - * get "foojunkjunk" on the screen instead of "foo " as - * you actually intended. - * - * SVr4 doesn't do this. Instead the spaces are actually written. - * So that's how we want ncurses to behave. - */ - win->_line[i].firstchar = 0; - win->_line[i].lastchar = num_columns-1; - - if_USE_SCROLL_HINTS(win->_line[i].oldindex = i); - } - - if (!is_pad && (begx + num_columns == screen_columns)) { - win->_flags |= _ENDLINE; - - if (begx == 0 && num_lines == screen_lines && begy == 0) - win->_flags |= _FULLWIN; - - if (begy + num_lines == screen_lines) - win->_flags |= _SCROLLWIN; - } - - wp->next = _nc_windows; - wp->win = win; - _nc_windows = wp; - - T((T_CREATE("window %p"), win)); - - return(win); + int i; + WINDOWLIST *wp; + WINDOW *win; + bool is_pad = (flags & _ISPAD); + + T(("_nc_makenew(%d,%d,%d,%d)", num_lines, num_columns, begy, begx)); + + if (!dimension_limit(num_lines) || !dimension_limit(num_columns)) + return 0; + + if ((wp = typeCalloc(WINDOWLIST, 1)) == 0) + return 0; + + if ((win = typeCalloc(WINDOW, 1)) == 0) + return 0; + + if ((win->_line = typeCalloc(struct ldat, ((unsigned) num_lines))) == 0) { + free(win); + return 0; + } + + win->_curx = 0; + win->_cury = 0; + win->_maxy = num_lines - 1; + win->_maxx = num_columns - 1; + win->_begy = begy; + win->_begx = begx; + win->_yoffset = SP->_topstolen; + + win->_flags = flags; + win->_attrs = A_NORMAL; + win->_bkgd = BLANK; + + win->_clear = is_pad ? FALSE : (num_lines == screen_lines && num_columns + == screen_columns); + win->_idlok = FALSE; + win->_idcok = TRUE; + win->_scroll = FALSE; + win->_leaveok = FALSE; + win->_use_keypad = FALSE; + win->_delay = -1; + win->_immed = FALSE; + win->_sync = 0; + win->_parx = -1; + win->_pary = -1; + win->_parent = 0; + + win->_regtop = 0; + win->_regbottom = num_lines - 1; + + win->_pad._pad_y = -1; + win->_pad._pad_x = -1; + win->_pad._pad_top = -1; + win->_pad._pad_bottom = -1; + win->_pad._pad_left = -1; + win->_pad._pad_right = -1; + + for (i = 0; i < num_lines; i++) { + /* + * This used to do + * + * win->_line[i].firstchar = win->_line[i].lastchar = _NOCHANGE; + * + * which marks the whole window unchanged. That's how + * SVr1 curses did it, but SVr4 curses marks the whole new + * window changed. + * + * With the old SVr1-like code, say you have stdscr full of + * characters, then create a new window with newwin(), + * then do a printw(win, "foo ");, the trailing spaces are + * completely ignored by the following refreshes. So, you + * get "foojunkjunk" on the screen instead of "foo " as + * you actually intended. + * + * SVr4 doesn't do this. Instead the spaces are actually written. + * So that's how we want ncurses to behave. + */ + win->_line[i].firstchar = 0; + win->_line[i].lastchar = num_columns - 1; + + if_USE_SCROLL_HINTS(win->_line[i].oldindex = i); + } + + if (!is_pad && (begx + num_columns == screen_columns)) { + win->_flags |= _ENDLINE; + + if (begx == 0 && num_lines == screen_lines && begy == 0) + win->_flags |= _FULLWIN; + + if (begy + num_lines == screen_lines) + win->_flags |= _SCROLLWIN; + } + + wp->next = _nc_windows; + wp->win = win; + _nc_windows = wp; + + T((T_CREATE("window %p"), win)); + + return (win); } diff --git a/lib/libcurses/base/lib_pad.c b/lib/libcurses/base/lib_pad.c index 4f2ed3e58be..5289ef67cc5 100644 --- a/lib/libcurses/base/lib_pad.c +++ b/lib/libcurses/base/lib_pad.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_pad.c,v 1.2 2000/03/10 01:35:02 millert Exp $ */ +/* $OpenBSD: lib_pad.c,v 1.3 2000/06/19 03:53:44 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998,2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,7 +33,6 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - /* * lib_pad.c * newpad -- create a new pad @@ -43,241 +42,253 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_pad.c,v 1.28 2000/03/05 00:21:55 David.Mosberger Exp $") +MODULE_ID("$From: lib_pad.c,v 1.29 2000/04/29 21:19:44 tom Exp $") -WINDOW *newpad(int l, int c) +WINDOW * +newpad(int l, int c) { -WINDOW *win; -chtype *ptr; -int i; + WINDOW *win; + chtype *ptr; + int i; - T((T_CALLED("newpad(%d, %d)"), l, c)); + T((T_CALLED("newpad(%d, %d)"), l, c)); - if (l <= 0 || c <= 0) - returnWin(0); + if (l <= 0 || c <= 0) + returnWin(0); - if ((win = _nc_makenew(l,c,0,0,_ISPAD)) == NULL) - returnWin(0); + if ((win = _nc_makenew(l, c, 0, 0, _ISPAD)) == NULL) + returnWin(0); - for (i = 0; i < l; i++) { - if_USE_SCROLL_HINTS(win->_line[i].oldindex = _NEWINDEX); - if ((win->_line[i].text = typeCalloc(chtype, ((size_t)c))) == 0) { - _nc_freewin(win); - returnWin(0); - } - for (ptr = win->_line[i].text; ptr < win->_line[i].text + c; ) - *ptr++ = ' '; + for (i = 0; i < l; i++) { + if_USE_SCROLL_HINTS(win->_line[i].oldindex = _NEWINDEX); + if ((win->_line[i].text = typeCalloc(chtype, ((size_t) c))) == 0) { + _nc_freewin(win); + returnWin(0); } + for (ptr = win->_line[i].text; ptr < win->_line[i].text + c;) + *ptr++ = ' '; + } - returnWin(win); + returnWin(win); } -WINDOW *subpad(WINDOW *orig, int l, int c, int begy, int begx) +WINDOW * +subpad(WINDOW *orig, int l, int c, int begy, int begx) { -WINDOW *win = (WINDOW *)0; + WINDOW *win = (WINDOW *) 0; - T((T_CALLED("subpad(%d, %d)"), l, c)); + T((T_CALLED("subpad(%d, %d)"), l, c)); - if (orig) { - if (!(orig->_flags & _ISPAD) || ((win = derwin(orig, l, c, begy, begx)) == NULL)) + if (orig) { + if (!(orig->_flags & _ISPAD) + || ((win = derwin(orig, l, c, begy, begx)) == NULL)) returnWin(0); - } - returnWin(win); + } + returnWin(win); } -int prefresh(WINDOW *win, int pminrow, int pmincol, - int sminrow, int smincol, int smaxrow, int smaxcol) +int +prefresh(WINDOW *win, int pminrow, int pmincol, + int sminrow, int smincol, int smaxrow, int smaxcol) { - T((T_CALLED("prefresh()"))); - if (pnoutrefresh(win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol) != ERR - && doupdate() != ERR) { - returnCode(OK); - } - returnCode(ERR); + T((T_CALLED("prefresh()"))); + if (pnoutrefresh(win, pminrow, pmincol, sminrow, smincol, smaxrow, + smaxcol) != ERR + && doupdate() != ERR) { + returnCode(OK); + } + returnCode(ERR); } -int pnoutrefresh(WINDOW *win, int pminrow, int pmincol, - int sminrow, int smincol, int smaxrow, int smaxcol) +int +pnoutrefresh(WINDOW *win, int pminrow, int pmincol, + int sminrow, int smincol, int smaxrow, int smaxcol) { -const int my_len = 2; /* parameterize the threshold for hardscroll */ -short i, j; -short m, n; -short pmaxrow; -short pmaxcol; -short displaced; -bool wide; - - T((T_CALLED("pnoutrefresh(%p, %d, %d, %d, %d, %d, %d)"), - win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)); - - if (win == 0) - returnCode(ERR); - - if (!(win->_flags & _ISPAD)) - returnCode(ERR); + const int my_len = 2; /* parameterize the threshold for hardscroll */ + NCURSES_SIZE_T i, j; + NCURSES_SIZE_T m, n; + NCURSES_SIZE_T pmaxrow; + NCURSES_SIZE_T pmaxcol; + NCURSES_SIZE_T displaced; + bool wide; + + T((T_CALLED("pnoutrefresh(%p, %d, %d, %d, %d, %d, %d)"), + win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)); + + if (win == 0) + returnCode(ERR); - /* negative values are interpreted as zero */ - if (pminrow < 0) pminrow = 0; - if (pmincol < 0) pmincol = 0; - if (sminrow < 0) sminrow = 0; - if (smincol < 0) smincol = 0; + if (!(win->_flags & _ISPAD)) + returnCode(ERR); + /* negative values are interpreted as zero */ + if (pminrow < 0) + pminrow = 0; + if (pmincol < 0) + pmincol = 0; + if (sminrow < 0) + sminrow = 0; + if (smincol < 0) + smincol = 0; + + pmaxrow = pminrow + smaxrow - sminrow; + pmaxcol = pmincol + smaxcol - smincol; + + T((" pminrow + smaxrow - sminrow %d, win->_maxy %d", pmaxrow, win->_maxy)); + T((" pmincol + smaxcol - smincol %d, win->_maxx %d", pmaxcol, win->_maxx)); + + /* + * Trim the caller's screen size back to the actual limits. + */ + if (pmaxrow > win->_maxy) { + smaxrow -= (pmaxrow - win->_maxy); pmaxrow = pminrow + smaxrow - sminrow; + } + if (pmaxcol > win->_maxx) { + smaxcol -= (pmaxcol - win->_maxx); pmaxcol = pmincol + smaxcol - smincol; + } - T((" pminrow + smaxrow - sminrow %d, win->_maxy %d", pmaxrow, win->_maxy)); - T((" pmincol + smaxcol - smincol %d, win->_maxx %d", pmaxcol, win->_maxx)); + if (smaxrow > screen_lines + || smaxcol > screen_columns + || sminrow > smaxrow + || smincol > smaxcol) + returnCode(ERR); - /* - * Trim the caller's screen size back to the actual limits. - */ - if (pmaxrow > win->_maxy) { - smaxrow -= (pmaxrow - win->_maxy); - pmaxrow = pminrow + smaxrow - sminrow; - } - if (pmaxcol > win->_maxx) { - smaxcol -= (pmaxcol - win->_maxx); - pmaxcol = pmincol + smaxcol - smincol; + T(("pad being refreshed")); + + if (win->_pad._pad_y >= 0) { + displaced = pminrow - win->_pad._pad_y + - (sminrow - win->_pad._pad_top); + T(("pad being shifted by %d line(s)", displaced)); + } else + displaced = 0; + + /* + * For pure efficiency, we'd want to transfer scrolling information + * from the pad to newscr whenever the window is wide enough that + * its update will dominate the cost of the update for the horizontal + * band of newscr that it occupies. Unfortunately, this threshold + * tends to be complex to estimate, and in any case scrolling the + * whole band and rewriting the parts outside win's image would look + * really ugly. So. What we do is consider the pad "wide" if it + * either (a) occupies the whole width of newscr, or (b) occupies + * all but at most one column on either vertical edge of the screen + * (this caters to fussy people who put boxes around full-screen + * windows). Note that changing this formula will not break any code, + * merely change the costs of various update cases. + */ + wide = (smincol < my_len && smaxcol > (newscr->_maxx - my_len)); + + for (i = pminrow, m = sminrow + win->_yoffset; + i <= pmaxrow && m <= newscr->_maxy; + i++, m++) { + register struct ldat *nline = &newscr->_line[m]; + register struct ldat *oline = &win->_line[i]; + + for (j = pmincol, n = smincol; j <= pmaxcol; j++, n++) { + if (oline->text[j] != nline->text[n]) { + nline->text[n] = oline->text[j]; + CHANGED_CELL(nline, n); + } } - if (smaxrow > screen_lines - || smaxcol > screen_columns - || sminrow > smaxrow - || smincol > smaxcol) - returnCode(ERR); - - T(("pad being refreshed")); - - if (win->_pad._pad_y >= 0) { - displaced = pminrow - win->_pad._pad_y - -(sminrow - win->_pad._pad_top); - T(("pad being shifted by %d line(s)", displaced)); - } else - displaced = 0; - - /* - * For pure efficiency, we'd want to transfer scrolling information - * from the pad to newscr whenever the window is wide enough that - * its update will dominate the cost of the update for the horizontal - * band of newscr that it occupies. Unfortunately, this threshold - * tends to be complex to estimate, and in any case scrolling the - * whole band and rewriting the parts outside win's image would look - * really ugly. So. What we do is consider the pad "wide" if it - * either (a) occupies the whole width of newscr, or (b) occupies - * all but at most one column on either vertical edge of the screen - * (this caters to fussy people who put boxes around full-screen - * windows). Note that changing this formula will not break any code, - * merely change the costs of various update cases. - */ - wide = (smincol < my_len && smaxcol > (newscr->_maxx - my_len)); - - for (i = pminrow, m = sminrow + win->_yoffset; - i <= pmaxrow && m <= newscr->_maxy; - i++, m++) { - register struct ldat *nline = &newscr->_line[m]; - register struct ldat *oline = &win->_line[i]; - - for (j = pmincol, n = smincol; j <= pmaxcol; j++, n++) { - if (oline->text[j] != nline->text[n]) { - nline->text[n] = oline->text[j]; - CHANGED_CELL(nline,n); - } - } - #if USE_SCROLL_HINTS - if (wide) { - int nind = m + displaced; - if (oline->oldindex < 0 - || nind < sminrow - || nind > smaxrow) { + if (wide) { + int nind = m + displaced; + if (oline->oldindex < 0 + || nind < sminrow + || nind > smaxrow) { + nind = _NEWINDEX; + } else if (displaced) { + register struct ldat *pline = &curscr->_line[nind]; + for (j = 0; j <= my_len; j++) { + int k = newscr->_maxx - j; + if (pline->text[j] != nline->text[j] + || pline->text[k] != nline->text[k]) { nind = _NEWINDEX; - } else if (displaced) { - register struct ldat *pline = &curscr->_line[nind]; - for (j = 0; j <= my_len; j++) { - int k = newscr->_maxx - j; - if (pline->text[j] != nline->text[j] - || pline->text[k] != nline->text[k]) { - nind = _NEWINDEX; - break; - } - } + break; } - - nline->oldindex = nind; } -#endif /* USE_SCROLL_HINTS */ - oline->firstchar = oline->lastchar = _NOCHANGE; - if_USE_SCROLL_HINTS(oline->oldindex = i); - } + } - /* - * Clean up debris from scrolling or resizing the pad, so we do not - * accidentally pick up the index value during the next call to this - * procedure. The only rows that should have an index value are those - * that are displayed during this cycle. - */ + nline->oldindex = nind; + } +#endif /* USE_SCROLL_HINTS */ + oline->firstchar = oline->lastchar = _NOCHANGE; + if_USE_SCROLL_HINTS(oline->oldindex = i); + } + + /* + * Clean up debris from scrolling or resizing the pad, so we do not + * accidentally pick up the index value during the next call to this + * procedure. The only rows that should have an index value are those + * that are displayed during this cycle. + */ #if USE_SCROLL_HINTS - for (i = pminrow-1; (i >= 0) && (win->_line[i].oldindex >= 0); i--) - win->_line[i].oldindex = _NEWINDEX; - for (i = pmaxrow+1; (i <= win->_maxy) && (win->_line[i].oldindex >= 0); i++) - win->_line[i].oldindex = _NEWINDEX; + for (i = pminrow - 1; (i >= 0) && (win->_line[i].oldindex >= 0); i--) + win->_line[i].oldindex = _NEWINDEX; + for (i = pmaxrow + 1; (i <= win->_maxy) + && (win->_line[i].oldindex >= 0); i++) + win->_line[i].oldindex = _NEWINDEX; #endif - win->_begx = smincol; - win->_begy = sminrow; + win->_begx = smincol; + win->_begy = sminrow; + + if (win->_clear) { + win->_clear = FALSE; + newscr->_clear = TRUE; + } + + /* + * Use the pad's current position, if it will be visible. + * If not, don't do anything; it's not an error. + */ + if (win->_leaveok == FALSE + && win->_cury >= pminrow + && win->_curx >= pmincol + && win->_cury <= pmaxrow + && win->_curx <= pmaxcol) { + newscr->_cury = win->_cury - pminrow + win->_begy + win->_yoffset; + newscr->_curx = win->_curx - pmincol + win->_begx; + } + newscr->_leaveok = win->_leaveok; + win->_flags &= ~_HASMOVED; + + /* + * Update our cache of the line-numbers that we displayed from the pad. + * We will use this on subsequent calls to this function to derive + * values to stuff into 'oldindex[]' -- for scrolling optimization. + */ + win->_pad._pad_y = pminrow; + win->_pad._pad_x = pmincol; + win->_pad._pad_top = sminrow; + win->_pad._pad_left = smincol; + win->_pad._pad_bottom = smaxrow; + win->_pad._pad_right = smaxcol; + + returnCode(OK); +} - if (win->_clear) { - win->_clear = FALSE; - newscr->_clear = TRUE; - } +int +pechochar(WINDOW *pad, const chtype ch) +{ + T((T_CALLED("pechochar(%p, %s)"), pad, _tracechtype(ch))); - /* - * Use the pad's current position, if it will be visible. - * If not, don't do anything; it's not an error. - */ - if (win->_leaveok == FALSE - && win->_cury >= pminrow - && win->_curx >= pmincol - && win->_cury <= pmaxrow - && win->_curx <= pmaxcol) { - newscr->_cury = win->_cury - pminrow + win->_begy + win->_yoffset; - newscr->_curx = win->_curx - pmincol + win->_begx; - } - newscr->_leaveok = win->_leaveok; - win->_flags &= ~_HASMOVED; - - /* - * Update our cache of the line-numbers that we displayed from the pad. - * We will use this on subsequent calls to this function to derive - * values to stuff into 'oldindex[]' -- for scrolling optimization. - */ - win->_pad._pad_y = pminrow; - win->_pad._pad_x = pmincol; - win->_pad._pad_top = sminrow; - win->_pad._pad_left = smincol; - win->_pad._pad_bottom = smaxrow; - win->_pad._pad_right = smaxcol; + if (pad == 0) + returnCode(ERR); - returnCode(OK); -} + if (!(pad->_flags & _ISPAD)) + returnCode(wechochar(pad, ch)); -int pechochar(WINDOW *pad, const chtype ch) -{ - T((T_CALLED("pechochar(%p, %s)"), pad, _tracechtype(ch))); - - if (pad == 0) - returnCode(ERR); - - if (!(pad->_flags & _ISPAD)) - returnCode(wechochar(pad,ch)); - - waddch(pad, ch); - prefresh(pad, pad->_pad._pad_y, - pad->_pad._pad_x, - pad->_pad._pad_top, - pad->_pad._pad_left, - pad->_pad._pad_bottom, - pad->_pad._pad_right); - - returnCode(OK); + waddch(pad, ch); + prefresh(pad, pad->_pad._pad_y, + pad->_pad._pad_x, + pad->_pad._pad_top, + pad->_pad._pad_left, + pad->_pad._pad_bottom, + pad->_pad._pad_right); + + returnCode(OK); } diff --git a/lib/libcurses/base/lib_refresh.c b/lib/libcurses/base/lib_refresh.c index 4d1b98cb968..4ae172db5f7 100644 --- a/lib/libcurses/base/lib_refresh.c +++ b/lib/libcurses/base/lib_refresh.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_refresh.c,v 1.2 1999/08/15 11:40:55 millert Exp $ */ +/* $OpenBSD: lib_refresh.c,v 1.3 2000/06/19 03:53:44 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,8 +33,6 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - - /* * lib_refresh.c * @@ -44,142 +42,144 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_refresh.c,v 1.24 1999/07/31 11:36:37 juergen Exp $") +MODULE_ID("$From: lib_refresh.c,v 1.25 2000/04/29 21:17:08 tom Exp $") -int wrefresh(WINDOW *win) +int +wrefresh(WINDOW *win) { -int code; - - T((T_CALLED("wrefresh(%p)"), win)); - - if (win == curscr) { - curscr->_clear = TRUE; - code = doupdate(); - } else if ((code = wnoutrefresh(win)) == OK) { - if (win->_clear) - newscr->_clear = TRUE; - code = doupdate(); - /* - * Reset the clearok() flag in case it was set for the special - * case in hardscroll.c (if we don't reset it here, we'll get 2 - * refreshes because the flag is copied from stdscr to newscr). - * Resetting the flag shouldn't do any harm, anyway. - */ - win->_clear = FALSE; - } - returnCode(code); -} - -int wnoutrefresh(WINDOW *win) -{ -short limit_x; -short i, j; -short begx; -short begy; -short m, n; -bool wide; - - T((T_CALLED("wnoutrefresh(%p)"), win)); -#ifdef TRACE - if (_nc_tracing & TRACE_UPDATE) - _tracedump("...win", win); -#endif /* TRACE */ - - /* - * This function will break badly if we try to refresh a pad. - */ - if ((win == 0) - || (win->_flags & _ISPAD)) - returnCode(ERR); + int code; - /* put them here so "win == 0" won't break our code */ - begx = win->_begx; - begy = win->_begy; - - newscr->_bkgd = win->_bkgd; - newscr->_attrs = win->_attrs; - - /* merge in change information from all subwindows of this window */ - wsyncdown(win); + T((T_CALLED("wrefresh(%p)"), win)); + if (win == curscr) { + curscr->_clear = TRUE; + code = doupdate(); + } else if ((code = wnoutrefresh(win)) == OK) { + if (win->_clear) + newscr->_clear = TRUE; + code = doupdate(); /* - * For pure efficiency, we'd want to transfer scrolling information - * from the window to newscr whenever the window is wide enough that - * its update will dominate the cost of the update for the horizontal - * band of newscr that it occupies. Unfortunately, this threshold - * tends to be complex to estimate, and in any case scrolling the - * whole band and rewriting the parts outside win's image would look - * really ugly. So. What we do is consider the window "wide" if it - * either (a) occupies the whole width of newscr, or (b) occupies - * all but at most one column on either vertical edge of the screen - * (this caters to fussy people who put boxes around full-screen - * windows). Note that changing this formula will not break any code, - * merely change the costs of various update cases. + * Reset the clearok() flag in case it was set for the special + * case in hardscroll.c (if we don't reset it here, we'll get 2 + * refreshes because the flag is copied from stdscr to newscr). + * Resetting the flag shouldn't do any harm, anyway. */ - wide = (begx <= 1 && win->_maxx >= (newscr->_maxx - 1)); - - win->_flags &= ~_HASMOVED; + win->_clear = FALSE; + } + returnCode(code); +} - /* - * Microtweaking alert! This double loop is one of the genuine - * hot spots in the code. Even gcc doesn't seem to do enough - * common-subexpression chunking to make it really tense, - * so we'll force the issue. - */ +int +wnoutrefresh(WINDOW *win) +{ + NCURSES_SIZE_T limit_x; + NCURSES_SIZE_T i, j; + NCURSES_SIZE_T begx; + NCURSES_SIZE_T begy; + NCURSES_SIZE_T m, n; + bool wide; + + T((T_CALLED("wnoutrefresh(%p)"), win)); +#ifdef TRACE + if (_nc_tracing & TRACE_UPDATE) + _tracedump("...win", win); +#endif /* TRACE */ - /* limit(n) */ + /* + * This function will break badly if we try to refresh a pad. + */ + if ((win == 0) + || (win->_flags & _ISPAD)) + returnCode(ERR); + + /* put them here so "win == 0" won't break our code */ + begx = win->_begx; + begy = win->_begy; + + newscr->_bkgd = win->_bkgd; + newscr->_attrs = win->_attrs; + + /* merge in change information from all subwindows of this window */ + wsyncdown(win); + + /* + * For pure efficiency, we'd want to transfer scrolling information + * from the window to newscr whenever the window is wide enough that + * its update will dominate the cost of the update for the horizontal + * band of newscr that it occupies. Unfortunately, this threshold + * tends to be complex to estimate, and in any case scrolling the + * whole band and rewriting the parts outside win's image would look + * really ugly. So. What we do is consider the window "wide" if it + * either (a) occupies the whole width of newscr, or (b) occupies + * all but at most one column on either vertical edge of the screen + * (this caters to fussy people who put boxes around full-screen + * windows). Note that changing this formula will not break any code, + * merely change the costs of various update cases. + */ + wide = (begx <= 1 && win->_maxx >= (newscr->_maxx - 1)); + + win->_flags &= ~_HASMOVED; + + /* + * Microtweaking alert! This double loop is one of the genuine + * hot spots in the code. Even gcc doesn't seem to do enough + * common-subexpression chunking to make it really tense, + * so we'll force the issue. + */ + + /* limit(n) */ + limit_x = win->_maxx; + /* limit(j) */ + if (limit_x > win->_maxx) limit_x = win->_maxx; - /* limit(j) */ - if (limit_x > win->_maxx) - limit_x = win->_maxx; - - for (i = 0, m = begy + win->_yoffset; - i <= win->_maxy && m <= newscr->_maxy; - i++, m++) { - register struct ldat *nline = &newscr->_line[m]; - register struct ldat *oline = &win->_line[i]; - if (oline->firstchar != _NOCHANGE) { - int last = oline->lastchar; + for (i = 0, m = begy + win->_yoffset; + i <= win->_maxy && m <= newscr->_maxy; + i++, m++) { + register struct ldat *nline = &newscr->_line[m]; + register struct ldat *oline = &win->_line[i]; - if (last > limit_x) - last = limit_x; + if (oline->firstchar != _NOCHANGE) { + int last = oline->lastchar; - for (j = oline->firstchar, n = j + begx; j <= last; j++, n++) { - if (oline->text[j] != nline->text[n]) { - nline->text[n] = oline->text[j]; - CHANGED_CELL(nline, n); - } - } + if (last > limit_x) + last = limit_x; + for (j = oline->firstchar, n = j + begx; j <= last; j++, n++) { + if (oline->text[j] != nline->text[n]) { + nline->text[n] = oline->text[j]; + CHANGED_CELL(nline, n); } + } + } #if USE_SCROLL_HINTS - if (wide) { - int oind = oline->oldindex; + if (wide) { + int oind = oline->oldindex; - nline->oldindex = (oind == _NEWINDEX) ? _NEWINDEX : begy + oind + win->_yoffset; - } + nline->oldindex = (oind == _NEWINDEX) ? _NEWINDEX : begy + oind + + win->_yoffset; + } #endif /* USE_SCROLL_HINTS */ - oline->firstchar = oline->lastchar = _NOCHANGE; - if_USE_SCROLL_HINTS(oline->oldindex = i); - } + oline->firstchar = oline->lastchar = _NOCHANGE; + if_USE_SCROLL_HINTS(oline->oldindex = i); + } - if (win->_clear) { - win->_clear = FALSE; - newscr->_clear = TRUE; - } + if (win->_clear) { + win->_clear = FALSE; + newscr->_clear = TRUE; + } + + if (!win->_leaveok) { + newscr->_cury = win->_cury + win->_begy + win->_yoffset; + newscr->_curx = win->_curx + win->_begx; + } + newscr->_leaveok = win->_leaveok; - if (! win->_leaveok) { - newscr->_cury = win->_cury + win->_begy + win->_yoffset; - newscr->_curx = win->_curx + win->_begx; - } - newscr->_leaveok = win->_leaveok; - #ifdef TRACE - if (_nc_tracing & TRACE_UPDATE) - _tracedump("newscr", newscr); + if (_nc_tracing & TRACE_UPDATE) + _tracedump("newscr", newscr); #endif /* TRACE */ - returnCode(OK); + returnCode(OK); } diff --git a/lib/libcurses/base/lib_scroll.c b/lib/libcurses/base/lib_scroll.c index 2742c911734..511ca93850a 100644 --- a/lib/libcurses/base/lib_scroll.c +++ b/lib/libcurses/base/lib_scroll.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_scroll.c,v 1.1 1999/01/18 19:09:58 millert Exp $ */ +/* $OpenBSD: lib_scroll.c,v 1.2 2000/06/19 03:53:45 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998,2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,8 +33,6 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - - /* ** lib_scroll.c ** @@ -46,75 +44,79 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_scroll.c,v 1.16 1998/02/11 12:13:55 tom Exp $") +MODULE_ID("$From: lib_scroll.c,v 1.17 2000/04/29 21:10:51 tom Exp $") -void _nc_scroll_window(WINDOW *win, int const n, short const top, short const bottom, chtype blank) +void +_nc_scroll_window(WINDOW *win, int const n, NCURSES_SIZE_T const top, + NCURSES_SIZE_T const bottom, chtype blank) { -int line, j; -size_t to_copy = (size_t)(sizeof(chtype) * (win->_maxx + 1)); - - TR(TRACE_MOVE, ("_nc_scroll_window(%p, %d, %d, %d)", win, n, top,bottom)); - - /* - * This used to do a line-text pointer-shuffle instead of text copies. - * That (a) doesn't work when the window is derived and doesn't have - * its own storage, (b) doesn't save you a lot on modern machines - * anyway. Your typical memcpy implementations are coded in - * assembler using a tight BLT loop; for the size of copies we're - * talking here, the total execution time is dominated by the one-time - * setup cost. So there is no point in trying to be excessively - * clever -- esr. - */ - - /* shift n lines downwards */ - if (n < 0) { - for (line = bottom; line >= top-n; line--) { - memcpy(win->_line[line].text, - win->_line[line+n].text, - to_copy); - if_USE_SCROLL_HINTS(win->_line[line].oldindex = win->_line[line+n].oldindex); - } - for (line = top; line < top-n; line++) { - for (j = 0; j <= win->_maxx; j ++) - win->_line[line].text[j] = blank; - if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX); - } - } - - /* shift n lines upwards */ - if (n > 0) { - for (line = top; line <= bottom-n; line++) { - memcpy(win->_line[line].text, - win->_line[line+n].text, - to_copy); - if_USE_SCROLL_HINTS(win->_line[line].oldindex = win->_line[line+n].oldindex); - } - for (line = bottom; line > bottom-n; line--) { - for (j = 0; j <= win->_maxx; j ++) - win->_line[line].text[j] = blank; - if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX); - } + int line, j; + size_t to_copy = (size_t) (sizeof(chtype) * (win->_maxx + 1)); + + TR(TRACE_MOVE, ("_nc_scroll_window(%p, %d, %d, %d)", win, n, top, bottom)); + + /* + * This used to do a line-text pointer-shuffle instead of text copies. + * That (a) doesn't work when the window is derived and doesn't have + * its own storage, (b) doesn't save you a lot on modern machines + * anyway. Your typical memcpy implementations are coded in + * assembler using a tight BLT loop; for the size of copies we're + * talking here, the total execution time is dominated by the one-time + * setup cost. So there is no point in trying to be excessively + * clever -- esr. + */ + + /* shift n lines downwards */ + if (n < 0) { + for (line = bottom; line >= top - n; line--) { + memcpy(win->_line[line].text, + win->_line[line + n].text, + to_copy); + if_USE_SCROLL_HINTS(win->_line[line].oldindex = win->_line[line + + n].oldindex); + } + for (line = top; line < top - n; line++) { + for (j = 0; j <= win->_maxx; j++) + win->_line[line].text[j] = blank; + if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX); + } + } + + /* shift n lines upwards */ + if (n > 0) { + for (line = top; line <= bottom - n; line++) { + memcpy(win->_line[line].text, + win->_line[line + n].text, + to_copy); + if_USE_SCROLL_HINTS(win->_line[line].oldindex = win->_line[line + + n].oldindex); + } + for (line = bottom; line > bottom - n; line--) { + for (j = 0; j <= win->_maxx; j++) + win->_line[line].text[j] = blank; + if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX); } - touchline(win, top, bottom-top+1); + } + touchline(win, top, bottom - top + 1); } int wscrl(WINDOW *win, int n) { - T((T_CALLED("wscrl(%p,%d)"), win, n)); + T((T_CALLED("wscrl(%p,%d)"), win, n)); - if (!win || !win->_scroll) - returnCode(ERR); + if (!win || !win->_scroll) + returnCode(ERR); - if (n == 0) - returnCode(OK); + if (n == 0) + returnCode(OK); - if ((n > (win->_regbottom - win->_regtop)) || - (-n > (win->_regbottom - win->_regtop))) - returnCode(ERR); + if ((n > (win->_regbottom - win->_regtop)) || + (-n > (win->_regbottom - win->_regtop))) + returnCode(ERR); - _nc_scroll_window(win, n, win->_regtop, win->_regbottom, _nc_background(win)); + _nc_scroll_window(win, n, win->_regtop, win->_regbottom, _nc_background(win)); - _nc_synchook(win); - returnCode(OK); + _nc_synchook(win); + returnCode(OK); } diff --git a/lib/libcurses/base/lib_scrreg.c b/lib/libcurses/base/lib_scrreg.c index 42a822b5a0d..0ee5b425137 100644 --- a/lib/libcurses/base/lib_scrreg.c +++ b/lib/libcurses/base/lib_scrreg.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_scrreg.c,v 1.1 1999/01/18 19:09:58 millert Exp $ */ +/* $OpenBSD: lib_scrreg.c,v 1.2 2000/06/19 03:53:45 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998,2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,8 +33,6 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - - /* ** lib_scrreg.c ** @@ -44,21 +42,21 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_scrreg.c,v 1.7 1998/02/11 12:13:53 tom Exp $") +MODULE_ID("$From: lib_scrreg.c,v 1.8 2000/04/29 21:13:04 tom Exp $") -int wsetscrreg(WINDOW *win, int top, int bottom) +int +wsetscrreg(WINDOW *win, int top, int bottom) { - T((T_CALLED("wsetscrreg(%p,%d,%d)"), win, top, bottom)); - - if (win && - top >= 0 && top <= win->_maxy && - bottom >= 0 && bottom <= win->_maxy && - bottom > top) - { - win->_regtop = (short)top; - win->_regbottom = (short)bottom; - - returnCode(OK); - } else - returnCode(ERR); + T((T_CALLED("wsetscrreg(%p,%d,%d)"), win, top, bottom)); + + if (win && + top >= 0 && top <= win->_maxy && + bottom >= 0 && bottom <= win->_maxy && + bottom > top) { + win->_regtop = (NCURSES_SIZE_T) top; + win->_regbottom = (NCURSES_SIZE_T) bottom; + + returnCode(OK); + } else + returnCode(ERR); } diff --git a/lib/libcurses/base/lib_set_term.c b/lib/libcurses/base/lib_set_term.c index 014e43a85f3..1faa7d53fd1 100644 --- a/lib/libcurses/base/lib_set_term.c +++ b/lib/libcurses/base/lib_set_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_set_term.c,v 1.8 2000/03/26 16:45:03 millert Exp $ */ +/* $OpenBSD: lib_set_term.c,v 1.9 2000/06/19 03:53:46 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * @@ -45,7 +45,7 @@ #include <term.h> /* cur_term */ #include <tic.h> -MODULE_ID("$From: lib_set_term.c,v 1.51 2000/03/26 01:03:36 tom Exp $") +MODULE_ID("$From: lib_set_term.c,v 1.52 2000/05/27 23:22:36 tom Exp $"); SCREEN * set_term(SCREEN * screenp) @@ -111,6 +111,18 @@ delscreen(SCREEN * sp) del_curterm(sp->_term); + /* + * If the associated output stream has been closed, we can discard the + * set-buffer. Limit the error check to EBADF, since fflush may fail + * for other reasons than trying to operate upon a closed stream. + */ + if (sp->_ofp != 0 + && sp->_setbuf != 0 + && fflush(sp->_ofp) != 0 + && errno == EBADF) { + free(sp->_setbuf); + } + free(sp); /* diff --git a/lib/libcurses/base/lib_vline.c b/lib/libcurses/base/lib_vline.c index a36969418d0..7f1a9a09bb2 100644 --- a/lib/libcurses/base/lib_vline.c +++ b/lib/libcurses/base/lib_vline.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_vline.c,v 1.1 1999/01/18 19:10:05 millert Exp $ */ +/* $OpenBSD: lib_vline.c,v 1.2 2000/06/19 03:53:46 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,8 +33,6 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ - - /* ** lib_vline.c ** @@ -44,36 +42,37 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_vline.c,v 1.4 1998/06/28 00:10:12 tom Exp $") +MODULE_ID("$From: lib_vline.c,v 1.5 2000/04/29 21:14:11 tom Exp $") -int wvline(WINDOW *win, chtype ch, int n) +int +wvline(WINDOW *win, chtype ch, int n) { -int code = ERR; -short row, col; -short end; + int code = ERR; + NCURSES_SIZE_T row, col; + NCURSES_SIZE_T end; - T((T_CALLED("wvline(%p,%s,%d)"), win, _tracechtype(ch), n)); + T((T_CALLED("wvline(%p,%s,%d)"), win, _tracechtype(ch), n)); - if (win) { - row = win->_cury; - col = win->_curx; - end = row + n - 1; - if (end > win->_maxy) - end = win->_maxy; + if (win) { + row = win->_cury; + col = win->_curx; + end = row + n - 1; + if (end > win->_maxy) + end = win->_maxy; - if (ch == 0) - ch = ACS_VLINE; - ch = _nc_render(win, ch); + if (ch == 0) + ch = ACS_VLINE; + ch = _nc_render(win, ch); - while(end >= row) { - struct ldat *line = &(win->_line[end]); - line->text[col] = ch; - CHANGED_CELL(line, col); - end--; - } - - _nc_synchook(win); - code = OK; + while (end >= row) { + struct ldat *line = &(win->_line[end]); + line->text[col] = ch; + CHANGED_CELL(line, col); + end--; } - returnCode(code); + + _nc_synchook(win); + code = OK; + } + returnCode(code); } |