summaryrefslogtreecommitdiff
path: root/lib/libcurses/tty
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libcurses/tty')
-rw-r--r--lib/libcurses/tty/MKexpanded.sh12
-rw-r--r--lib/libcurses/tty/lib_mvcur.c253
-rw-r--r--lib/libcurses/tty/lib_tstp.c344
-rw-r--r--lib/libcurses/tty/lib_twait.c286
-rw-r--r--lib/libcurses/tty/lib_vidattr.c95
-rw-r--r--lib/libcurses/tty/tty_update.c177
6 files changed, 581 insertions, 586 deletions
diff --git a/lib/libcurses/tty/MKexpanded.sh b/lib/libcurses/tty/MKexpanded.sh
index 11e9fc16878..2c4ef80d427 100644
--- a/lib/libcurses/tty/MKexpanded.sh
+++ b/lib/libcurses/tty/MKexpanded.sh
@@ -1,6 +1,6 @@
#! /bin/sh
##############################################################################
-# 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 "Software"), #
@@ -29,8 +29,8 @@
#
# Author: Thomas E. Dickey <dickey@clark.net> 1997
#
-# $OpenBSD: MKexpanded.sh,v 1.1 1999/01/18 19:10:25 millert Exp $
-# $From: MKexpanded.sh,v 1.7 1998/11/11 20:15:39 Alexander.V.Lukyanov Exp $
+# $OpenBSD: MKexpanded.sh,v 1.2 2000/10/08 22:47:04 millert Exp $
+# $From: MKexpanded.sh,v 1.9 2000/09/02 22:55:21 tom Exp $
#
# Script to generate 'expanded.c', a dummy source that contains functions
# corresponding to complex macros used in this library. By making functions,
@@ -55,7 +55,7 @@ cat <<EOF
/* generated by MKexpanded.sh */
#include <curses.priv.h>
#include <term.h>
-#ifdef NCURSES_EXPANDED
+#if NCURSES_EXPANDED
EOF
cat >$TMP <<EOF
@@ -77,10 +77,6 @@ void _nc_toggle_attr_off(attr_t *S, attr_t at)
{
toggle_attr_off(*S,at);
}
-int _nc_can_clear_with(chtype ch)
-{
- return can_clear_with(ch);
-}
int _nc_DelCharCost(int count)
{
return DelCharCost(count);
diff --git a/lib/libcurses/tty/lib_mvcur.c b/lib/libcurses/tty/lib_mvcur.c
index 7672c928963..0c72f2b5c96 100644
--- a/lib/libcurses/tty/lib_mvcur.c
+++ b/lib/libcurses/tty/lib_mvcur.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lib_mvcur.c,v 1.8 2000/07/10 03:06:16 millert Exp $ */
+/* $OpenBSD: lib_mvcur.c,v 1.9 2000/10/08 22:47:04 millert Exp $ */
/****************************************************************************
* Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
@@ -154,9 +154,7 @@
#include <term.h>
#include <ctype.h>
-MODULE_ID("$From: lib_mvcur.c,v 1.67 2000/06/24 21:13:51 tom Exp $")
-
-#define STRLEN(s) (s != 0) ? strlen(s) : 0
+MODULE_ID("$From: lib_mvcur.c,v 1.72 2000/10/08 00:58:25 tom Exp $")
#define CURRENT_ROW SP->_cursrow /* phys cursor row */
#define CURRENT_COLUMN SP->_curscol /* phys cursor column */
@@ -176,25 +174,6 @@ static float diff;
static int normalized_cost(const char *const cap, int affcnt);
-#if !HAVE_STRSTR
-char *
-_nc_strstr(const char *haystack, const char *needle)
-{
- size_t len1 = strlen(haystack);
- size_t len2 = strlen(needle);
- char *result = 0;
-
- while ((len1 != 0) && (len1-- >= len2)) {
- if (!strncmp(haystack, needle, len2)) {
- result = haystack;
- break;
- }
- haystack++;
- }
- return result;
-}
-#endif
-
/****************************************************************************
*
* Initialization/wrapup (including cost pre-computation)
@@ -207,7 +186,7 @@ trace_cost_of(const char *capname, const char *cap, int affcnt)
{
int result = _nc_msec_cost(cap, affcnt);
TR(TRACE_CHARPUT | TRACE_MOVE,
- ("CostOf %s %d %s", capname, result, _nc_visbuf(cap)));
+ ("CostOf %s %d %s", capname, result, _nc_visbuf(cap)));
return result;
}
#define CostOf(cap,affcnt) trace_cost_of(#cap,cap,affcnt);
@@ -217,7 +196,7 @@ trace_normalized_cost(const char *capname, const char *cap, int affcnt)
{
int result = normalized_cost(cap, affcnt);
TR(TRACE_CHARPUT | TRACE_MOVE,
- ("NormalizedCost %s %d %s", capname, result, _nc_visbuf(cap)));
+ ("NormalizedCost %s %d %s", capname, result, _nc_visbuf(cap)));
return result;
}
#define NormalizedCost(cap,affcnt) trace_normalized_cost(#cap,cap,affcnt);
@@ -237,12 +216,12 @@ _nc_msec_cost(const char *const cap, int affcnt)
return (INFINITY);
else {
const char *cp;
- float cum_cost = 0;
+ float cum_cost = 0.0;
for (cp = cap; *cp; cp++) {
/* extract padding, either mandatory or required */
if (cp[0] == '$' && cp[1] == '<' && strchr(cp, '>')) {
- float number = 0;
+ float number = 0.0;
for (cp += 2; *cp != '>'; cp++) {
if (isdigit(*cp))
@@ -253,7 +232,7 @@ _nc_msec_cost(const char *const cap, int affcnt)
number += (*cp - '0') / 10.0;
}
-#ifdef NCURSES_NO_PADDING
+#if NCURSES_NO_PADDING
if (!(SP->_no_padding))
#endif
cum_cost += number * 10;
@@ -404,13 +383,8 @@ _nc_mvcur_init(void)
SP->_hpa_ch_cost = NormalizedCost(tparm(column_address, 23), 1);
SP->_cuf_ch_cost = NormalizedCost(tparm(parm_right_cursor, 23), 1);
SP->_inline_cost = min(SP->_cup_ch_cost,
- min(SP->_hpa_ch_cost,
- SP->_cuf_ch_cost));
-
- /* pre-compute some capability lengths */
- SP->_carriage_return_length = STRLEN(carriage_return);
- SP->_cursor_home_length = STRLEN(cursor_home);
- SP->_cursor_to_ll_length = STRLEN(cursor_to_ll);
+ min(SP->_hpa_ch_cost,
+ SP->_cuf_ch_cost));
/*
* If save_cursor is used within enter_ca_mode, we should not use it for
@@ -470,18 +444,17 @@ _nc_mvcur_wrap(void)
* Perform repeated-append, returning cost
*/
static inline int
-repeated_append(int total, int num, int repeat, char *dst, const char *src)
+repeated_append(string_desc * target, int total, int num, int repeat, const char *src)
{
- register size_t src_len = strlen(src);
- register size_t dst_len = STRLEN(dst);
-
- if ((dst_len + repeat * src_len) < OPT_SIZE - 1) {
- total += (num * repeat);
- if (dst) {
- dst += dst_len;
- while (repeat-- > 0) {
- (void) strcpy(dst, src);
- dst += src_len;
+ size_t need = repeat * strlen(src);
+
+ if (need < target->s_size) {
+ while (repeat-- > 0) {
+ if (_nc_safe_strcat(target, src)) {
+ total += num;
+ } else {
+ total = INFINITY;
+ break;
}
}
} else {
@@ -499,53 +472,51 @@ repeated_append(int total, int num, int repeat, char *dst, const char *src)
*/
#define LASTTAB(fr) ((fr > 0) ? ((fr - 1) / init_tabs) * init_tabs : -1)
-/* Note: we'd like to inline this for speed, but GNU C barfs on the attempt. */
-
static int
-relative_move(char *result, int from_y, int from_x, int to_y, int to_x, bool ovw)
+relative_move(string_desc * target, int from_y, int from_x, int to_y, int
+ to_x, bool ovw)
/* move via local motions (cuu/cuu1/cud/cud1/cub1/cub/cuf1/cuf/vpa/hpa) */
{
+ string_desc save;
int n, vcost = 0, hcost = 0;
- if (result)
- result[0] = '\0';
+ (void) _nc_str_copy(&save, target);
if (to_y != from_y) {
vcost = INFINITY;
- if (row_address) {
- if (result)
- (void) strcpy(result, tparm(row_address, to_y));
+ if (row_address != 0
+ && _nc_safe_strcat(target, tparm(row_address, to_y))) {
vcost = SP->_vpa_cost;
}
if (to_y > from_y) {
n = (to_y - from_y);
- if (parm_down_cursor && SP->_cud_cost < vcost) {
- if (result)
- (void) strcpy(result, tparm(parm_down_cursor, n));
+ if (parm_down_cursor
+ && SP->_cud_cost < vcost
+ && _nc_safe_strcat(_nc_str_copy(target, &save),
+ tparm(parm_down_cursor, n))) {
vcost = SP->_cud_cost;
}
if (cursor_down && (n * SP->_cud1_cost < vcost)) {
- if (result)
- result[0] = '\0';
- vcost = repeated_append(0, SP->_cud1_cost, n, result, cursor_down);
+ vcost = repeated_append(_nc_str_copy(target, &save), 0,
+ SP->_cud1_cost, n, cursor_down);
}
} else { /* (to_y < from_y) */
n = (from_y - to_y);
- if (parm_up_cursor && SP->_cup_cost < vcost) {
- if (result)
- (void) strcpy(result, tparm(parm_up_cursor, n));
+ if (parm_up_cursor
+ && SP->_cup_cost < vcost
+ && _nc_safe_strcat(_nc_str_copy(target, &save),
+ tparm(parm_up_cursor, n))) {
vcost = SP->_cup_cost;
}
if (cursor_up && (n * SP->_cuu1_cost < vcost)) {
- if (result)
- result[0] = '\0';
- vcost = repeated_append(0, SP->_cuu1_cost, n, result, cursor_up);
+ vcost = repeated_append(_nc_str_copy(target, &save), 0,
+ SP->_cuu1_cost, n, cursor_up);
}
}
@@ -553,33 +524,34 @@ relative_move(char *result, int from_y, int from_x, int to_y, int to_x, bool ovw
return (INFINITY);
}
- if (result)
- result += strlen(result);
+ save = *target;
if (to_x != from_x) {
char str[OPT_SIZE];
+ string_desc check;
hcost = INFINITY;
- if (column_address) {
- if (result)
- (void) strcpy(result, tparm(column_address, to_x));
+ if (column_address
+ && _nc_safe_strcat(_nc_str_copy(target, &save),
+ tparm(column_address, to_x))) {
hcost = SP->_hpa_cost;
}
if (to_x > from_x) {
n = to_x - from_x;
- if (parm_right_cursor && SP->_cuf_cost < hcost) {
- if (result)
- (void) strcpy(result, tparm(parm_right_cursor, n));
+ if (parm_right_cursor
+ && SP->_cuf_cost < hcost
+ && _nc_safe_strcat(_nc_str_copy(target, &save),
+ tparm(parm_right_cursor, n))) {
hcost = SP->_cuf_cost;
}
if (cursor_right) {
int lhcost = 0;
- str[0] = '\0';
+ (void) _nc_str_init(&check, str, sizeof(str));
#if USE_HARD_TABS
/* use hard tabs, if we have them, to do as much as possible */
@@ -587,8 +559,8 @@ relative_move(char *result, int from_y, int from_x, int to_y, int to_x, bool ovw
int nxt, fr;
for (fr = from_x; (nxt = NEXTTAB(fr)) <= to_x; fr = nxt) {
- lhcost = repeated_append(lhcost, SP->_ht_cost, 1,
- str, tab);
+ lhcost = repeated_append(&check, lhcost,
+ SP->_ht_cost, 1, tab);
if (lhcost == INFINITY)
break;
}
@@ -599,7 +571,7 @@ relative_move(char *result, int from_y, int from_x, int to_y, int to_x, bool ovw
#endif /* USE_HARD_TABS */
#if defined(REAL_ATTR) && defined(WANT_CHAR)
-#ifdef BSD_TPUTS
+#if BSD_TPUTS
/*
* If we're allowing BSD-style padding in tputs, don't generate
* a string with a leading digit. Otherwise, that will be
@@ -608,6 +580,7 @@ relative_move(char *result, int from_y, int from_x, int to_y, int to_x, bool ovw
*/
if (ovw
&& n > 0
+ && n < (int) check.s_size
&& vcost == 0
&& str[0] == '\0'
&& isdigit(TextOf(WANT_CHAR(to_y, from_x))))
@@ -631,48 +604,47 @@ relative_move(char *result, int from_y, int from_x, int to_y, int to_x, bool ovw
}
}
if (ovw) {
- char *sp;
int i;
- sp = str + strlen(str);
-
for (i = 0; i < n; i++)
- *sp++ = WANT_CHAR(to_y, from_x + i);
- *sp = '\0';
+ *check.s_tail++ = WANT_CHAR(to_y, from_x + i);
+ *check.s_tail = '\0';
+ check.s_size -= n;
lhcost += n * SP->_char_padding;
} else
#endif /* defined(REAL_ATTR) && defined(WANT_CHAR) */
{
- lhcost = repeated_append(lhcost, SP->_cuf1_cost, n, str, cursor_right);
+ lhcost = repeated_append(&check, lhcost, SP->_cuf1_cost,
+ n, cursor_right);
}
- if (lhcost < hcost) {
- if (result)
- (void) strcpy(result, str);
+ if (lhcost < hcost
+ && _nc_safe_strcat(_nc_str_copy(target, &save), str)) {
hcost = lhcost;
}
}
} else { /* (to_x < from_x) */
n = from_x - to_x;
- if (parm_left_cursor && SP->_cub_cost < hcost) {
- if (result)
- (void) strcpy(result, tparm(parm_left_cursor, n));
+ if (parm_left_cursor
+ && SP->_cub_cost < hcost
+ && _nc_safe_strcat(_nc_str_copy(target, &save),
+ tparm(parm_left_cursor, n))) {
hcost = SP->_cub_cost;
}
if (cursor_left) {
int lhcost = 0;
- str[0] = '\0';
+ (void) _nc_str_init(&check, str, sizeof(str));
#if USE_HARD_TABS
if (init_tabs > 0 && back_tab) {
int nxt, fr;
for (fr = from_x; (nxt = LASTTAB(fr)) >= to_x; fr = nxt) {
- lhcost = repeated_append(lhcost, SP->_cbt_cost, 1,
- str, back_tab);
+ lhcost = repeated_append(&check, lhcost,
+ SP->_cbt_cost, 1, back_tab);
if (lhcost == INFINITY)
break;
}
@@ -681,11 +653,10 @@ relative_move(char *result, int from_y, int from_x, int to_y, int to_x, bool ovw
}
#endif /* USE_HARD_TABS */
- lhcost = repeated_append(lhcost, SP->_cub1_cost, n, str, cursor_left);
+ lhcost = repeated_append(&check, lhcost, SP->_cub1_cost, n, cursor_left);
- if (lhcost < hcost) {
- if (result)
- (void) strcpy(result, str);
+ if (lhcost < hcost
+ && _nc_safe_strcat(_nc_str_copy(target, &save), str)) {
hcost = lhcost;
}
}
@@ -714,7 +685,8 @@ static inline int
onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
/* onscreen move from (yold, xold) to (ynew, xnew) */
{
- char use[OPT_SIZE], *sp;
+ string_desc result;
+ char buffer[OPT_SIZE];
int tactic = 0, newcost, usecost = INFINITY;
int t5_cr_cost;
@@ -724,11 +696,12 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
gettimeofday(&before, NULL);
#endif /* MAIN */
+#define NullResult _nc_str_null(&result, sizeof(buffer))
+#define InitResult _nc_str_init(&result, buffer, sizeof(buffer))
+
/* tactic #0: use direct cursor addressing */
- sp = tparm(SP->_address_cursor, ynew, xnew);
- if (sp) {
+ if (_nc_safe_strcpy(InitResult, tparm(SP->_address_cursor, ynew, xnew))) {
tactic = 0;
- (void) strcpy(use, sp);
usecost = SP->_cup_cost;
#if defined(TRACE) || defined(NCURSES_TEST)
@@ -758,7 +731,8 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
#ifndef NO_OPTIMIZE
/* tactic #1: use local movement */
if (yold != -1 && xold != -1
- && ((newcost = relative_move(NULL, yold, xold, ynew, xnew, ovw)) != INFINITY)
+ && ((newcost = relative_move(NullResult, yold, xold, ynew, xnew,
+ ovw)) != INFINITY)
&& newcost < usecost) {
tactic = 1;
usecost = newcost;
@@ -766,7 +740,8 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
/* tactic #2: use carriage-return + local movement */
if (yold != -1 && carriage_return
- && ((newcost = relative_move(NULL, yold, 0, ynew, xnew, ovw)) != INFINITY)
+ && ((newcost = relative_move(NullResult, yold, 0, ynew, xnew, ovw))
+ != INFINITY)
&& SP->_cr_cost + newcost < usecost) {
tactic = 2;
usecost = SP->_cr_cost + newcost;
@@ -774,7 +749,7 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
/* tactic #3: use home-cursor + local movement */
if (cursor_home
- && ((newcost = relative_move(NULL, 0, 0, ynew, xnew, ovw)) != INFINITY)
+ && ((newcost = relative_move(NullResult, 0, 0, ynew, xnew, ovw)) != INFINITY)
&& SP->_home_cost + newcost < usecost) {
tactic = 3;
usecost = SP->_home_cost + newcost;
@@ -782,8 +757,8 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
/* tactic #4: use home-down + local movement */
if (cursor_to_ll
- && ((newcost = relative_move(NULL, screen_lines - 1, 0, ynew, xnew,
- ovw)) != INFINITY)
+ && ((newcost = relative_move(NullResult, screen_lines - 1, 0, ynew,
+ xnew, ovw)) != INFINITY)
&& SP->_ll_cost + newcost < usecost) {
tactic = 4;
usecost = SP->_ll_cost + newcost;
@@ -796,8 +771,8 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
t5_cr_cost = (xold > 0 ? SP->_cr_cost : 0);
if (auto_left_margin && !eat_newline_glitch
&& yold > 0 && cursor_left
- && ((newcost = relative_move(NULL, yold - 1, screen_columns - 1,
- ynew, xnew, ovw)) != INFINITY)
+ && ((newcost = relative_move(NullResult, yold - 1, screen_columns -
+ 1, ynew, xnew, ovw)) != INFINITY)
&& t5_cr_cost + SP->_cub1_cost + newcost < usecost) {
tactic = 5;
usecost = t5_cr_cost + SP->_cub1_cost + newcost;
@@ -806,32 +781,30 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
/*
* These cases are ordered by estimated relative frequency.
*/
+ if (tactic)
+ InitResult;
switch (tactic) {
case 1:
- (void) relative_move(use, yold, xold, ynew, xnew, ovw);
+ (void) relative_move(&result, yold, xold, ynew, xnew, ovw);
break;
case 2:
- (void) strcpy(use, carriage_return);
- (void) relative_move(use + SP->_carriage_return_length,
- yold, 0, ynew, xnew, ovw);
+ (void) _nc_safe_strcpy(&result, carriage_return);
+ (void) relative_move(&result, yold, 0, ynew, xnew, ovw);
break;
case 3:
- (void) strcpy(use, cursor_home);
- (void) relative_move(use + SP->_cursor_home_length,
- 0, 0, ynew, xnew, ovw);
+ (void) _nc_safe_strcpy(&result, cursor_home);
+ (void) relative_move(&result, 0, 0, ynew, xnew, ovw);
break;
case 4:
- (void) strcpy(use, cursor_to_ll);
- (void) relative_move(use + SP->_cursor_to_ll_length,
- screen_lines - 1, 0, ynew, xnew, ovw);
+ (void) _nc_safe_strcpy(&result, cursor_to_ll);
+ (void) relative_move(&result, screen_lines - 1, 0, ynew, xnew, ovw);
break;
case 5:
- use[0] = '\0';
if (xold > 0)
- (void) strcat(use, carriage_return);
- (void) strcat(use, cursor_left);
- (void) relative_move(use + strlen(use),
- yold - 1, screen_columns - 1, ynew, xnew, ovw);
+ (void) _nc_safe_strcat(&result, carriage_return);
+ (void) _nc_safe_strcat(&result, cursor_left);
+ (void) relative_move(&result, yold - 1, screen_columns - 1, ynew,
+ xnew, ovw);
break;
}
#endif /* !NO_OPTIMIZE */
@@ -842,14 +815,14 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
+ (after.tv_sec - before.tv_sec) * 1000000;
if (!profiling)
(void) fprintf(stderr,
- "onscreen: %d msec, %f 28.8Kbps char-equivalents\n",
- (int) diff, diff / 288);
+ "onscreen: %d msec, %f 28.8Kbps char-equivalents\n",
+ (int) diff, diff / 288);
#endif /* MAIN */
nonlocal:
if (usecost != INFINITY) {
TPUTS_TRACE("mvcur");
- tputs(use, 1, _nc_outch);
+ tputs(buffer, 1, _nc_outch);
return (OK);
} else
return (ERR);
@@ -953,7 +926,7 @@ _nc_outch(int ch)
}
char PC = 0; /* used by termcap library */
-speed_t ospeed = 0; /* used by termcap library */
+short ospeed = 0; /* used by termcap library */
int _nc_nulls_sent = 0; /* used by 'tack' program */
int
@@ -1011,7 +984,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
(void) puts("s[croll] n t b m -- display scrolling sequence");
(void)
printf("r[eload] -- reload terminal info for %s\n",
- termname());
+ termname());
(void)
puts("l[oad] <term> -- load terminal info for type <term>");
(void) puts("d[elete] <cap> -- delete named capability");
@@ -1032,8 +1005,9 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
gettimeofday(&after, NULL);
printf("\" (%ld msec)\n",
- (long) (after.tv_usec - before.tv_usec + (after.tv_sec -
- before.tv_sec) * 1000000));
+ (long) (after.tv_usec - before.tv_usec
+ + (after.tv_sec - before.tv_sec)
+ * 1000000));
} else if (sscanf(buf, "s %d %d %d %d", &fy, &fx, &ty, &tx) == 4) {
struct timeval before, after;
@@ -1044,8 +1018,9 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
gettimeofday(&after, NULL);
printf("\" (%ld msec)\n",
- (long) (after.tv_usec - before.tv_usec + (after.tv_sec -
- before.tv_sec) * 1000000));
+ (long) (after.tv_usec - before.tv_usec + (after.tv_sec -
+ before.tv_sec)
+ * 1000000));
} else if (buf[0] == 'r') {
(void) strcpy(tname, termname());
load_term();
@@ -1053,7 +1028,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
load_term();
} else if (sscanf(buf, "d %s", capname) == 1) {
struct name_table_entry const *np = _nc_find_entry(capname,
- _nc_info_hash_table);
+ _nc_info_hash_table);
if (np == NULL)
(void) printf("No such capability as \"%s\"\n", capname);
@@ -1063,19 +1038,19 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
cur_term->type.Booleans[np->nte_index] = FALSE;
(void)
printf("Boolean capability `%s' (%d) turned off.\n",
- np->nte_name, np->nte_index);
+ np->nte_name, np->nte_index);
break;
case NUMBER:
cur_term->type.Numbers[np->nte_index] = ABSENT_NUMERIC;
(void) printf("Number capability `%s' (%d) set to -1.\n",
- np->nte_name, np->nte_index);
+ np->nte_name, np->nte_index);
break;
case STRING:
cur_term->type.Strings[np->nte_index] = ABSENT_STRING;
(void) printf("String capability `%s' (%d) deleted.\n",
- np->nte_name, np->nte_index);
+ np->nte_name, np->nte_index);
break;
}
}
@@ -1112,7 +1087,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
* is winning.
*/
else if (sscanf(buf, "t %d", &n) == 1) {
- float cumtime = 0, perchar;
+ float cumtime = 0.0, perchar;
int speeds[] =
{2400, 9600, 14400, 19200, 28800, 38400, 0};
@@ -1150,7 +1125,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
perchar = cumtime / n;
(void) printf("%d moves (%ld chars) in %d msec, %f msec each:\n",
- n, xmits, (int) cumtime, perchar);
+ n, xmits, (int) cumtime, perchar);
for (i = 0; speeds[i]; i++) {
/*
@@ -1169,7 +1144,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
(void)
printf("%6d bps: %3.2f char-xmits overhead; total estimated time %15.2f\n",
- speeds[i], overhead, totalest);
+ speeds[i], overhead, totalest);
}
} else if (buf[0] == 'c') {
(void) printf("char padding: %d\n", SP->_char_padding);
diff --git a/lib/libcurses/tty/lib_tstp.c b/lib/libcurses/tty/lib_tstp.c
index 08c6fec917a..e3f0e36e372 100644
--- a/lib/libcurses/tty/lib_tstp.c
+++ b/lib/libcurses/tty/lib_tstp.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: lib_tstp.c,v 1.6 2000/06/19 03:53:54 millert Exp $ */
+/* $OpenBSD: lib_tstp.c,v 1.7 2000/10/08 22:47:05 millert Exp $ */
/****************************************************************************
- * Copyright (c) 1998,1999 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_tstp.c
**
@@ -46,11 +45,11 @@
#include <signal.h>
#include <SigAction.h>
-#if defined(SVR4_ACTION) && !defined(_POSIX_SOURCE)
+#if SVR4_ACTION && !defined(_POSIX_SOURCE)
#define _POSIX_SOURCE
#endif
-MODULE_ID("$From: lib_tstp.c,v 1.21 2000/05/20 23:28:56 tom Exp $")
+MODULE_ID("$From: lib_tstp.c,v 1.22 2000/09/02 18:33:17 tom Exp $")
#if defined(SIGTSTP) && (HAVE_SIGACTION || HAVE_SIGVEC)
#define USE_SIGTSTP 1
@@ -102,151 +101,152 @@ MODULE_ID("$From: lib_tstp.c,v 1.21 2000/05/20 23:28:56 tom Exp $")
*/
#if USE_SIGTSTP
-static void tstp(int dummy GCC_UNUSED)
+static void
+tstp(int dummy GCC_UNUSED)
{
- sigset_t mask, omask;
- sigaction_t act, oact;
+ sigset_t mask, omask;
+ sigaction_t act, oact;
#ifdef SIGTTOU
- int sigttou_blocked;
+ int sigttou_blocked;
#endif
- T(("tstp() called"));
-
- /*
- * The user may have changed the prog_mode tty bits, so save them.
- *
- * But first try to detect whether we still are in the foreground
- * process group - if not, an interactive shell may already have
- * taken ownership of the tty and modified the settings when our
- * parent was stopped before us, and we would likely pick up the
- * settings already modified by the shell.
- */
- if (SP != 0 && !SP->_endwin) /* don't do this if we're not in curses */
+ T(("tstp() called"));
+
+ /*
+ * The user may have changed the prog_mode tty bits, so save them.
+ *
+ * But first try to detect whether we still are in the foreground
+ * process group - if not, an interactive shell may already have
+ * taken ownership of the tty and modified the settings when our
+ * parent was stopped before us, and we would likely pick up the
+ * settings already modified by the shell.
+ */
+ if (SP != 0 && !SP->_endwin) /* don't do this if we're not in curses */
#if HAVE_TCGETPGRP
if (tcgetpgrp(STDIN_FILENO) == getpgrp())
#endif
def_prog_mode();
- /*
- * Block window change and timer signals. The latter
- * is because applications use timers to decide when
- * to repaint the screen.
- */
- (void)sigemptyset(&mask);
- (void)sigaddset(&mask, SIGALRM);
+ /*
+ * Block window change and timer signals. The latter
+ * is because applications use timers to decide when
+ * to repaint the screen.
+ */
+ (void) sigemptyset(&mask);
+ (void) sigaddset(&mask, SIGALRM);
#if USE_SIGWINCH
- (void)sigaddset(&mask, SIGWINCH);
+ (void) sigaddset(&mask, SIGWINCH);
#endif
- (void)sigprocmask(SIG_BLOCK, &mask, &omask);
+ (void) sigprocmask(SIG_BLOCK, &mask, &omask);
#ifdef SIGTTOU
- sigttou_blocked = sigismember(&omask, SIGTTOU);
- if (!sigttou_blocked) {
- (void)sigemptyset(&mask);
- (void)sigaddset(&mask, SIGTTOU);
- (void)sigprocmask(SIG_BLOCK, &mask, NULL);
- }
+ sigttou_blocked = sigismember(&omask, SIGTTOU);
+ if (!sigttou_blocked) {
+ (void) sigemptyset(&mask);
+ (void) sigaddset(&mask, SIGTTOU);
+ (void) sigprocmask(SIG_BLOCK, &mask, NULL);
+ }
#endif
- /*
- * End window mode, which also resets the terminal state to the
- * original (pre-curses) modes.
- */
- endwin();
+ /*
+ * End window mode, which also resets the terminal state to the
+ * original (pre-curses) modes.
+ */
+ endwin();
- /* Unblock SIGTSTP. */
- (void)sigemptyset(&mask);
- (void)sigaddset(&mask, SIGTSTP);
+ /* Unblock SIGTSTP. */
+ (void) sigemptyset(&mask);
+ (void) sigaddset(&mask, SIGTSTP);
#ifdef SIGTTOU
- if (!sigttou_blocked) {
- /* Unblock this too if it wasn't blocked on entry */
- (void)sigaddset(&mask, SIGTTOU);
- }
+ if (!sigttou_blocked) {
+ /* Unblock this too if it wasn't blocked on entry */
+ (void) sigaddset(&mask, SIGTTOU);
+ }
#endif
- (void)sigprocmask(SIG_UNBLOCK, &mask, NULL);
+ (void) sigprocmask(SIG_UNBLOCK, &mask, NULL);
- /* Now we want to resend SIGSTP to this process and suspend it */
- act.sa_handler = SIG_DFL;
- sigemptyset(&act.sa_mask);
- act.sa_flags = 0;
+ /* Now we want to resend SIGSTP to this process and suspend it */
+ act.sa_handler = SIG_DFL;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = 0;
#ifdef SA_RESTART
- act.sa_flags |= SA_RESTART;
+ act.sa_flags |= SA_RESTART;
#endif /* SA_RESTART */
- sigaction(SIGTSTP, &act, &oact);
- kill(getpid(), SIGTSTP);
+ sigaction(SIGTSTP, &act, &oact);
+ kill(getpid(), SIGTSTP);
- /* Process gets suspended...time passes...process resumes */
+ /* Process gets suspended...time passes...process resumes */
- T(("SIGCONT received"));
- sigaction(SIGTSTP, &oact, NULL);
- flushinp();
+ T(("SIGCONT received"));
+ sigaction(SIGTSTP, &oact, NULL);
+ flushinp();
- /*
- * If the user modified the tty state while suspended, he wants
- * those changes to stick. So save the new "default" terminal state.
- */
- def_shell_mode();
+ /*
+ * If the user modified the tty state while suspended, he wants
+ * those changes to stick. So save the new "default" terminal state.
+ */
+ def_shell_mode();
- /*
- * This relies on the fact that doupdate() will restore the
- * program-mode tty state, and issue enter_ca_mode if need be.
- */
- doupdate();
+ /*
+ * This relies on the fact that doupdate() will restore the
+ * program-mode tty state, and issue enter_ca_mode if need be.
+ */
+ doupdate();
- /* Reset the signals. */
- (void)sigprocmask(SIG_SETMASK, &omask, NULL);
+ /* Reset the signals. */
+ (void) sigprocmask(SIG_SETMASK, &omask, NULL);
}
-#endif /* USE_SIGTSTP */
+#endif /* USE_SIGTSTP */
-static void cleanup(int sig)
+static void
+cleanup(int sig)
{
- static int nested;
-
- /*
- * Actually, doing any sort of I/O from within an signal handler is
- * "unsafe". But we'll _try_ to clean up the screen and terminal
- * settings on the way out.
- */
- if (!nested++
- && (sig == SIGINT
- || sig == SIGQUIT)) {
+ static int nested;
+
+ /*
+ * Actually, doing any sort of I/O from within an signal handler is
+ * "unsafe". But we'll _try_ to clean up the screen and terminal
+ * settings on the way out.
+ */
+ if (!nested++
+ && (sig == SIGINT
+ || sig == SIGQUIT)) {
#if HAVE_SIGACTION || HAVE_SIGVEC
- sigaction_t act;
- sigemptyset(&act.sa_mask);
- act.sa_flags = 0;
- act.sa_handler = SIG_IGN;
- if (sigaction(sig, &act, (sigaction_t *)0) == 0)
+ sigaction_t act;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = 0;
+ act.sa_handler = SIG_IGN;
+ if (sigaction(sig, &act, (sigaction_t *) 0) == 0)
#else
- if (signal(sig, SIG_IGN) != SIG_ERR)
+ if (signal(sig, SIG_IGN) != SIG_ERR)
#endif
- {
- SCREEN *scan = _nc_screen_chain;
- while(scan)
- {
- if (SP != 0
- && SP->_ofp != 0
- && isatty(fileno(SP->_ofp))) {
- SP->_cleanup = TRUE;
- SP->_outch = _nc_outch;
- }
- set_term(scan);
- endwin();
- if (SP)
- SP->_endwin = FALSE; /* in case we have an atexit! */
- scan = scan->_next_screen;
- }
+ {
+ SCREEN *scan = _nc_screen_chain;
+ while (scan) {
+ if (SP != 0
+ && SP->_ofp != 0
+ && isatty(fileno(SP->_ofp))) {
+ SP->_cleanup = TRUE;
+ SP->_outch = _nc_outch;
}
+ set_term(scan);
+ endwin();
+ if (SP)
+ SP->_endwin = FALSE; /* in case we have an atexit! */
+ scan = scan->_next_screen;
+ }
}
- exit(EXIT_FAILURE);
+ }
+ exit(EXIT_FAILURE);
}
#if USE_SIGWINCH
-static void sigwinch(int sig GCC_UNUSED)
+static void
+sigwinch(int sig GCC_UNUSED)
{
SCREEN *scan = _nc_screen_chain;
- while(scan)
- {
+ while (scan) {
scan->_sig_winch = TRUE;
scan = scan->_next_screen;
}
@@ -258,38 +258,40 @@ static void sigwinch(int sig GCC_UNUSED)
* handler.
*/
#if HAVE_SIGACTION || HAVE_SIGVEC
-static int CatchIfDefault(int sig, sigaction_t *act)
+static int
+CatchIfDefault(int sig, sigaction_t * act)
{
- sigaction_t old_act;
+ sigaction_t old_act;
- if (sigaction(sig, (sigaction_t *)0, &old_act) == 0
- && (old_act.sa_handler == SIG_DFL
+ if (sigaction(sig, (sigaction_t *) 0, &old_act) == 0
+ && (old_act.sa_handler == SIG_DFL
#if USE_SIGWINCH
|| (sig == SIGWINCH && old_act.sa_handler == SIG_IGN)
#endif
- )) {
- (void)sigaction(sig, act, (sigaction_t *)0);
- return TRUE;
- }
- return FALSE;
+ )) {
+ (void) sigaction(sig, act, (sigaction_t *) 0);
+ return TRUE;
+ }
+ return FALSE;
}
#else
-static int CatchIfDefault(int sig, RETSIGTYPE (*handler)(int))
+static int
+CatchIfDefault(int sig, RETSIGTYPE(*handler) (int))
{
- void (*ohandler)(int);
+ void (*ohandler) (int);
- ohandler = signal(sig, SIG_IGN);
- if (ohandler == SIG_DFL
+ ohandler = signal(sig, SIG_IGN);
+ if (ohandler == SIG_DFL
#if USE_SIGWINCH
- || (sig == SIGWINCH && ohandler == SIG_IGN)
+ || (sig == SIGWINCH && ohandler == SIG_IGN)
#endif
) {
- signal(sig, handler);
- return TRUE;
- } else {
- signal(sig, ohandler);
- return FALSE;
- }
+ signal(sig, handler);
+ return TRUE;
+ } else {
+ signal(sig, ohandler);
+ return FALSE;
+ }
}
#endif
@@ -304,69 +306,63 @@ static int CatchIfDefault(int sig, RETSIGTYPE (*handler)(int))
* The XSI document implies that we shouldn't keep the SIGTSTP handler if
* the caller later changes its mind, but that doesn't seem correct.
*/
-void _nc_signal_handler(bool enable)
+void
+_nc_signal_handler(bool enable)
{
-#if USE_SIGTSTP /* Xenix 2.x doesn't have SIGTSTP, for example */
-static sigaction_t act, oact;
-static int ignore;
-
- if (!ignore)
- {
- if (!enable)
- {
- act.sa_handler = SIG_IGN;
- sigaction(SIGTSTP, &act, &oact);
- }
- else if (act.sa_handler)
- {
- sigaction(SIGTSTP, &oact, NULL);
- }
- else /*initialize */
- {
- sigemptyset(&act.sa_mask);
- act.sa_flags = 0;
+#if USE_SIGTSTP /* Xenix 2.x doesn't have SIGTSTP, for example */
+ static sigaction_t act, oact;
+ static int ignore;
+
+ if (!ignore) {
+ if (!enable) {
+ act.sa_handler = SIG_IGN;
+ sigaction(SIGTSTP, &act, &oact);
+ } else if (act.sa_handler) {
+ sigaction(SIGTSTP, &oact, NULL);
+ } else { /*initialize */
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = 0;
#if USE_SIGWINCH
- act.sa_handler = sigwinch;
- CatchIfDefault(SIGWINCH, &act);
+ act.sa_handler = sigwinch;
+ CatchIfDefault(SIGWINCH, &act);
#endif
#ifdef SA_RESTART
- act.sa_flags |= SA_RESTART;
+ act.sa_flags |= SA_RESTART;
#endif /* SA_RESTART */
- act.sa_handler = cleanup;
- CatchIfDefault(SIGINT, &act);
- CatchIfDefault(SIGTERM, &act);
+ act.sa_handler = cleanup;
+ CatchIfDefault(SIGINT, &act);
+ CatchIfDefault(SIGTERM, &act);
- act.sa_handler = tstp;
- if (!CatchIfDefault(SIGTSTP, &act))
- ignore = TRUE;
- }
+ act.sa_handler = tstp;
+ if (!CatchIfDefault(SIGTSTP, &act))
+ ignore = TRUE;
}
+ }
#else /* !USE_SIGTSTP */
- if (enable)
- {
+ if (enable) {
#if HAVE_SIGACTION || HAVE_SIGVEC
- static sigaction_t act;
- sigemptyset(&act.sa_mask);
+ static sigaction_t act;
+ sigemptyset(&act.sa_mask);
#if USE_SIGWINCH
- act.sa_handler = sigwinch;
- CatchIfDefault(SIGWINCH, &act);
+ act.sa_handler = sigwinch;
+ CatchIfDefault(SIGWINCH, &act);
#endif
#ifdef SA_RESTART
- act.sa_flags |= SA_RESTART;
+ act.sa_flags |= SA_RESTART;
#endif /* SA_RESTART */
- act.sa_handler = cleanup;
- CatchIfDefault(SIGINT, &act);
- CatchIfDefault(SIGTERM, &act);
+ act.sa_handler = cleanup;
+ CatchIfDefault(SIGINT, &act);
+ CatchIfDefault(SIGTERM, &act);
#else /* !(HAVE_SIGACTION || HAVE_SIGVEC) */
- CatchIfDefault(SIGINT, cleanup);
- CatchIfDefault(SIGTERM, cleanup);
+ CatchIfDefault(SIGINT, cleanup);
+ CatchIfDefault(SIGTERM, cleanup);
#if USE_SIGWINCH
- CatchIfDefault(SIGWINCH, sigwinch);
+ CatchIfDefault(SIGWINCH, sigwinch);
#endif
#endif /* !(HAVE_SIGACTION || HAVE_SIGVEC) */
- }
+ }
#endif /* !USE_SIGTSTP */
}
diff --git a/lib/libcurses/tty/lib_twait.c b/lib/libcurses/tty/lib_twait.c
index 93aff6a4edf..5c038bd91df 100644
--- a/lib/libcurses/tty/lib_twait.c
+++ b/lib/libcurses/tty/lib_twait.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lib_twait.c,v 1.5 2000/07/10 03:06:16 millert Exp $ */
+/* $OpenBSD: lib_twait.c,v 1.6 2000/10/08 22:47:05 millert Exp $ */
/****************************************************************************
* Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
@@ -61,33 +61,34 @@
# endif
#endif
-MODULE_ID("$From: lib_twait.c,v 1.37 2000/06/29 23:03:09 tom Exp $")
+MODULE_ID("$From: lib_twait.c,v 1.39 2000/08/26 19:34:15 tom Exp $")
-static long _nc_gettime(bool first)
+static long
+_nc_gettime(bool first)
{
- long res;
+ long res;
#if HAVE_GETTIMEOFDAY
# define PRECISE_GETTIME 1
- static struct timeval t0;
- struct timeval t1;
- gettimeofday(&t1, (struct timezone *)0);
- if (first) {
- t0 = t1;
- }
- res = (t1.tv_sec - t0.tv_sec) * 1000
- + (t1.tv_usec - t0.tv_usec) / 1000;
+ static struct timeval t0;
+ struct timeval t1;
+ gettimeofday(&t1, (struct timezone *) 0);
+ if (first) {
+ t0 = t1;
+ }
+ res = (t1.tv_sec - t0.tv_sec) * 1000
+ + (t1.tv_usec - t0.tv_usec) / 1000;
#else
# define PRECISE_GETTIME 0
- static time_t t0;
- time_t t1 = time((time_t*)0);
- if (first) {
- t0 = t1;
- }
- res = (t1 - t0) * 1000;
+ static time_t t0;
+ time_t t1 = time((time_t *) 0);
+ if (first) {
+ t0 = t1;
+ }
+ res = (t1 - t0) * 1000;
#endif
- T(("%s time: %ld msec", first ? "get" : "elapsed", res));
- return res;
+ T(("%s time: %ld msec", first ? "get" : "elapsed", res));
+ return res;
}
/*
@@ -103,163 +104,164 @@ static long _nc_gettime(bool first)
* If the milliseconds given are -1, the wait blocks until activity on the
* descriptors.
*/
-int _nc_timed_wait(int mode, int milliseconds, int *timeleft)
+int
+_nc_timed_wait(int mode, int milliseconds, int *timeleft)
{
-int fd;
-int count;
+ int fd;
+ int count;
-int result;
+ int result;
#if USE_FUNC_POLL
-struct pollfd fds[2];
+ struct pollfd fds[2];
#elif defined(__BEOS__)
#elif HAVE_SELECT
-static fd_set set;
+ static fd_set set;
#endif
-long starttime, returntime;
+ long starttime, returntime;
- T(("start twait: %d milliseconds, mode: %d", milliseconds, mode));
+ T(("start twait: %d milliseconds, mode: %d", milliseconds, mode));
#if PRECISE_GETTIME
-retry:
+ retry:
#endif
- starttime = _nc_gettime(TRUE);
+ starttime = _nc_gettime(TRUE);
- count = 0;
+ count = 0;
#if USE_FUNC_POLL
- if (mode & 1) {
- fds[count].fd = SP->_ifd;
- fds[count].events = POLLIN;
- count++;
- }
- if ((mode & 2)
- && (fd = SP->_mouse_fd) >= 0) {
- fds[count].fd = fd;
- fds[count].events = POLLIN;
- count++;
- }
- result = poll(fds, count, milliseconds);
+ memset(fds, 0, sizeof(fds));
+ if (mode & 1) {
+ fds[count].fd = SP->_ifd;
+ fds[count].events = POLLIN;
+ count++;
+ }
+ if ((mode & 2)
+ && (fd = SP->_mouse_fd) >= 0) {
+ fds[count].fd = fd;
+ fds[count].events = POLLIN;
+ count++;
+ }
+ result = poll(fds, count, milliseconds);
#elif defined(__BEOS__)
- /*
- * BeOS's select() is declared in socket.h, so the configure script does
- * not see it. That's just as well, since that function works only for
- * sockets. This (using snooze and ioctl) was distilled from Be's patch
- * for ncurses which uses a separate thread to simulate select().
- *
- * FIXME: the return values from the ioctl aren't very clear if we get
- * interrupted.
- */
- result = 0;
- if (mode & 1) {
- bigtime_t d;
- bigtime_t useconds = milliseconds * 1000;
- int n, howmany;
+ /*
+ * BeOS's select() is declared in socket.h, so the configure script does
+ * not see it. That's just as well, since that function works only for
+ * sockets. This (using snooze and ioctl) was distilled from Be's patch
+ * for ncurses which uses a separate thread to simulate select().
+ *
+ * FIXME: the return values from the ioctl aren't very clear if we get
+ * interrupted.
+ */
+ result = 0;
+ if (mode & 1) {
+ bigtime_t d;
+ bigtime_t useconds = milliseconds * 1000;
+ int n, howmany;
- if (useconds == 0) /* we're here to go _through_ the loop */
- useconds = 1;
+ if (useconds == 0) /* we're here to go _through_ the loop */
+ useconds = 1;
- for (d = 0; d < useconds; d += 5000) {
- n = 0;
- howmany = ioctl(0, 'ichr', &n);
- if (howmany >= 0 && n > 0) {
- result = 1;
- break;
- }
- if (useconds > 1)
- snooze(5000);
- milliseconds -= 5;
- }
- } else if (milliseconds > 0) {
- snooze(milliseconds * 1000);
- milliseconds = 0;
+ for (d = 0; d < useconds; d += 5000) {
+ n = 0;
+ howmany = ioctl(0, 'ichr', &n);
+ if (howmany >= 0 && n > 0) {
+ result = 1;
+ break;
+ }
+ if (useconds > 1)
+ snooze(5000);
+ milliseconds -= 5;
}
+ } else if (milliseconds > 0) {
+ snooze(milliseconds * 1000);
+ milliseconds = 0;
+ }
#elif HAVE_SELECT
- /*
- * select() modifies the fd_set arguments; do this in the
- * loop.
- */
- FD_ZERO(&set);
+ /*
+ * select() modifies the fd_set arguments; do this in the
+ * loop.
+ */
+ FD_ZERO(&set);
- if (mode & 1) {
- FD_SET(SP->_ifd, &set);
- count = SP->_ifd + 1;
- }
- if ((mode & 2)
- && (fd = SP->_mouse_fd) >= 0) {
- FD_SET(fd, &set);
- count = max(fd, count) + 1;
- }
+ if (mode & 1) {
+ FD_SET(SP->_ifd, &set);
+ count = SP->_ifd + 1;
+ }
+ if ((mode & 2)
+ && (fd = SP->_mouse_fd) >= 0) {
+ FD_SET(fd, &set);
+ count = max(fd, count) + 1;
+ }
- if (milliseconds >= 0) {
- struct timeval ntimeout;
- ntimeout.tv_sec = milliseconds / 1000;
- ntimeout.tv_usec = (milliseconds % 1000) * 1000;
- result = select(count, &set, NULL, NULL, &ntimeout);
- } else {
- result = select(count, &set, NULL, NULL, NULL);
- }
+ if (milliseconds >= 0) {
+ struct timeval ntimeout;
+ ntimeout.tv_sec = milliseconds / 1000;
+ ntimeout.tv_usec = (milliseconds % 1000) * 1000;
+ result = select(count, &set, NULL, NULL, &ntimeout);
+ } else {
+ result = select(count, &set, NULL, NULL, NULL);
+ }
#endif
- returntime = _nc_gettime(FALSE);
+ returntime = _nc_gettime(FALSE);
- if (milliseconds >= 0)
- milliseconds -= (returntime - starttime);
+ if (milliseconds >= 0)
+ milliseconds -= (returntime - starttime);
#if PRECISE_GETTIME
- /*
- * If the timeout hasn't expired, and we've gotten no data,
- * this is probably a system where 'select()' needs to be left
- * alone so that it can complete. Make this process sleep,
- * then come back for more.
- */
- if (result == 0 && milliseconds > 100) {
- napms(100);
- milliseconds -= 100;
- goto retry;
- }
+ /*
+ * If the timeout hasn't expired, and we've gotten no data,
+ * this is probably a system where 'select()' needs to be left
+ * alone so that it can complete. Make this process sleep,
+ * then come back for more.
+ */
+ if (result == 0 && milliseconds > 100) {
+ napms(100);
+ milliseconds -= 100;
+ goto retry;
+ }
#endif
- /* return approximate time left in milliseconds */
- if (timeleft)
- *timeleft = milliseconds;
+ /* return approximate time left in milliseconds */
+ if (timeleft)
+ *timeleft = milliseconds;
- T(("end twait: returned %d (%d), remaining time %d msec",
- result, errno, milliseconds));
+ T(("end twait: returned %d (%d), remaining time %d msec",
+ result, errno, milliseconds));
- /*
- * Both 'poll()' and 'select()' return the number of file descriptors
- * that are active. Translate this back to the mask that denotes which
- * file-descriptors, so that we don't need all of this system-specific
- * code everywhere.
- */
- if (result != 0) {
- if (result > 0) {
- result = 0;
+ /*
+ * Both 'poll()' and 'select()' return the number of file descriptors
+ * that are active. Translate this back to the mask that denotes which
+ * file-descriptors, so that we don't need all of this system-specific
+ * code everywhere.
+ */
+ if (result != 0) {
+ if (result > 0) {
+ result = 0;
#if USE_FUNC_POLL
- for (count = 0; count < 2; count++) {
- if ((mode & (1 << count))
- && (fds[count].revents & POLLIN)) {
- result |= (1 << count);
- }
- }
+ for (count = 0; count < 2; count++) {
+ if ((mode & (1 << count))
+ && (fds[count].revents & POLLIN)) {
+ result |= (1 << count);
+ }
+ }
#elif defined(__BEOS__)
- result = 1; /* redundant, but simple */
+ result = 1; /* redundant, but simple */
#elif HAVE_SELECT
- if ((mode & 2)
- && (fd = SP->_mouse_fd) >= 0
- && FD_ISSET(fd, &set))
- result |= 2;
- if ((mode & 1)
- && FD_ISSET(SP->_ifd, &set))
- result |= 1;
+ if ((mode & 2)
+ && (fd = SP->_mouse_fd) >= 0
+ && FD_ISSET(fd, &set))
+ result |= 2;
+ if ((mode & 1)
+ && FD_ISSET(SP->_ifd, &set))
+ result |= 1;
#endif
- }
- else
- result = 0;
- }
+ } else
+ result = 0;
+ }
- return (result);
+ return (result);
}
diff --git a/lib/libcurses/tty/lib_vidattr.c b/lib/libcurses/tty/lib_vidattr.c
index 9584b26b108..9f8476c760c 100644
--- a/lib/libcurses/tty/lib_vidattr.c
+++ b/lib/libcurses/tty/lib_vidattr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lib_vidattr.c,v 1.5 2000/06/19 03:53:54 millert Exp $ */
+/* $OpenBSD: lib_vidattr.c,v 1.6 2000/10/08 22:47:05 millert Exp $ */
/****************************************************************************
* Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
@@ -66,7 +66,7 @@
#include <curses.priv.h>
#include <term.h>
-MODULE_ID("$From: lib_vidattr.c,v 1.27 2000/04/29 23:25:27 tom Exp $")
+MODULE_ID("$From: lib_vidattr.c,v 1.32 2000/09/17 00:15:23 tom Exp $")
#define doPut(mode) TPUTS_TRACE(#mode); tputs(mode, 1, outc)
@@ -80,7 +80,7 @@ MODULE_ID("$From: lib_vidattr.c,v 1.27 2000/04/29 23:25:27 tom Exp $")
#define SetColorsIf(why,old_attr) \
if (can_color && (why)) { \
int old_pair = PAIR_NUMBER(old_attr); \
- T(("old pair = %d -- new pair = %d", old_pair, pair)); \
+ TR(TRACE_ATTRS, ("old pair = %d -- new pair = %d", old_pair, pair)); \
if ((pair != old_pair) \
|| (fix_pair0 && (pair == 0)) \
|| (reverse ^ ((old_attr & A_REVERSE) != 0))) { \
@@ -97,7 +97,7 @@ vidputs(attr_t newmode, int (*outc) (int))
bool reverse = FALSE;
bool used_ncv = FALSE;
bool can_color = (SP == 0 || SP->_coloron);
-#ifdef NCURSES_EXT_FUNCS
+#if NCURSES_EXT_FUNCS
bool fix_pair0 = (SP != 0 && SP->_coloron && !SP->_default_color);
#else
#define fix_pair0 FALSE
@@ -109,7 +109,7 @@ vidputs(attr_t newmode, int (*outc) (int))
if (SP)
previous_attr = SP->_current_attr;
- T(("previous attribute was %s", _traceattr(previous_attr)));
+ TR(TRACE_ATTRS, ("previous attribute was %s", _traceattr(previous_attr)));
#if !USE_XMC_SUPPORT
if ((SP != 0)
@@ -122,36 +122,29 @@ vidputs(attr_t newmode, int (*outc) (int))
* attributes, use the colors in preference.
*/
if (((newmode & A_COLOR) != 0
- || fix_pair0)
+ || fix_pair0)
&& (no_color_video > 0)) {
- /* *INDENT-OFF* */
- static const struct {
- attr_t video;
- unsigned bit;
- } table[] = {
- { A_STANDOUT, 1 },
- { A_UNDERLINE, 2 },
- { A_REVERSE, 4 },
- { A_BLINK, 8 },
- { A_DIM, 16 },
- { A_BOLD, 32 },
- { A_INVIS, 64 },
- { A_PROTECT, 128 },
- { A_ALTCHARSET, 256 },
- };
- /* *INDENT-ON* */
-
- size_t n;
- for (n = 0; n < SIZEOF(table); n++) {
- if ((table[n].bit & no_color_video)
- && (table[n].video & newmode)) {
- used_ncv = TRUE;
- if (table[n].video == A_REVERSE)
- reverse = TRUE;
- else
- newmode &= ~table[n].video;
- }
+ /*
+ * If we had chosen the A_xxx definitions to correspond to the
+ * no_color_video mask, we could simply shift it up and mask off the
+ * attributes. But we did not (actually copied Solaris' definitions).
+ * However, this is still simpler/faster than a lookup table.
+ *
+ * The 63 corresponds to A_STANDOUT, A_UNDERLINE, A_REVERSE, A_BLINK,
+ * A_DIM, A_BOLD which are 1:1 with no_color_video. The bits that
+ * correspond to A_INVIS, A_PROTECT (192) must be shifted up 1 and
+ * A_ALTCHARSET (256) down 2 to line up. We use the NCURSES_BITS
+ * macro so this will work properly for the wide-character layout.
+ */
+ attr_t mask = NCURSES_BITS((no_color_video & 63)
+ | ((no_color_video & 192) << 1)
+ | ((no_color_video & 256) >> 2), 8);
+
+ if (mask & A_REVERSE) {
+ reverse = TRUE;
+ mask &= ~A_REVERSE;
}
+ newmode &= ~mask;
}
if (newmode == previous_attr)
@@ -174,7 +167,16 @@ vidputs(attr_t newmode, int (*outc) (int))
previous_attr &= ~A_ALTCHARSET;
}
if (previous_attr) {
- doPut(exit_attribute_mode);
+ if (exit_attribute_mode) {
+ doPut(exit_attribute_mode);
+ } else {
+ if (!SP || SP->_use_rmul) {
+ TurnOff(A_UNDERLINE, exit_underline_mode);
+ }
+ if (!SP || SP->_use_rmso) {
+ TurnOff(A_STANDOUT, exit_standout_mode);
+ }
+ }
previous_attr &= ~A_COLOR;
}
@@ -183,21 +185,21 @@ vidputs(attr_t newmode, int (*outc) (int))
if (turn_on || turn_off) {
TPUTS_TRACE("set_attributes");
tputs(tparm(set_attributes,
- (newmode & A_STANDOUT) != 0,
- (newmode & A_UNDERLINE) != 0,
- (newmode & A_REVERSE) != 0,
- (newmode & A_BLINK) != 0,
- (newmode & A_DIM) != 0,
- (newmode & A_BOLD) != 0,
- (newmode & A_INVIS) != 0,
- (newmode & A_PROTECT) != 0,
- (newmode & A_ALTCHARSET) != 0), 1, outc);
+ (newmode & A_STANDOUT) != 0,
+ (newmode & A_UNDERLINE) != 0,
+ (newmode & A_REVERSE) != 0,
+ (newmode & A_BLINK) != 0,
+ (newmode & A_DIM) != 0,
+ (newmode & A_BOLD) != 0,
+ (newmode & A_INVIS) != 0,
+ (newmode & A_PROTECT) != 0,
+ (newmode & A_ALTCHARSET) != 0), 1, outc);
previous_attr &= ~A_COLOR;
}
SetColorsIf((pair != 0) || fix_pair0, previous_attr);
} else {
- T(("turning %s off", _traceattr(turn_off)));
+ TR(TRACE_ATTRS, ("turning %s off", _traceattr(turn_off)));
TurnOff(A_ALTCHARSET, exit_alt_charset_mode);
@@ -216,7 +218,7 @@ vidputs(attr_t newmode, int (*outc) (int))
}
SetColorsIf((pair != 0) || fix_pair0, previous_attr);
- T(("turning %s on", _traceattr(turn_on)));
+ TR(TRACE_ATTRS, ("turning %s on", _traceattr(turn_on)));
/* *INDENT-OFF* */
TurnOn(A_ALTCHARSET, enter_alt_charset_mode);
TurnOn(A_BLINK, enter_blink_mode);
@@ -261,6 +263,7 @@ termattrs(void)
{
chtype attrs = A_NORMAL;
+ T((T_CALLED("termattrs()")));
if (enter_alt_charset_mode)
attrs |= A_ALTCHARSET;
@@ -291,5 +294,5 @@ termattrs(void)
if (SP->_coloron)
attrs |= A_COLOR;
- return (attrs);
+ returnChar(attrs);
}
diff --git a/lib/libcurses/tty/tty_update.c b/lib/libcurses/tty/tty_update.c
index dfb983a61cc..ef52d7f7a11 100644
--- a/lib/libcurses/tty/tty_update.c
+++ b/lib/libcurses/tty/tty_update.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty_update.c,v 1.11 2000/07/24 04:06:11 millert Exp $ */
+/* $OpenBSD: tty_update.c,v 1.12 2000/10/08 22:47:05 millert Exp $ */
/****************************************************************************
* Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
@@ -72,7 +72,7 @@
#include <term.h>
-MODULE_ID("$From: tty_update.c,v 1.142 2000/07/23 01:41:17 tom Exp $")
+MODULE_ID("$From: tty_update.c,v 1.146 2000/10/07 01:11:44 tom Exp $")
/*
* This define controls the line-breakout optimization. Every once in a
@@ -114,15 +114,24 @@ position_check(int expected_y, int expected_x, char *legend)
/* check to see if the real cursor position matches the virtual */
{
char buf[20];
+ char *s;
int y, x;
if (!_nc_tracing || (expected_y < 0 && expected_x < 0))
return;
+ _nc_flush();
memset(buf, '\0', sizeof(buf));
putp("\033[6n"); /* only works on ANSI-compatibles */
_nc_flush();
- (void) read(0, buf, sizeof(buf) - 1);
+ *(s = buf) = 0;
+ do {
+ int ask = sizeof(buf) - 1 - (s - buf);
+ int got = read(0, s, ask);
+ if (got == 0)
+ break;
+ s += got;
+ } while (strchr(buf, 'R') == 0);
_tracef("probe returned %s", _nc_visbuf(buf));
/* try to interpret as a position report */
@@ -135,8 +144,9 @@ position_check(int expected_y, int expected_x, char *legend)
expected_y = y - 1;
if (y - 1 != expected_y || x - 1 != expected_x) {
beep();
+ tputs(tparm("\033[%d;%dH", expected_y + 1, expected_x + 1), 1, _nc_outch);
_tracef("position seen (%d, %d) doesn't match expected one (%d, %d) in %s",
- y - 1, x - 1, expected_y, expected_x, legend);
+ y - 1, x - 1, expected_y, expected_x, legend);
} else {
_tracef("position matches OK in %s", legend);
}
@@ -158,7 +168,7 @@ GoTo(int const row, int const col)
chtype oldattr = SP->_current_attr;
TR(TRACE_MOVE, ("GoTo(%d, %d) from (%d, %d)",
- row, col, SP->_cursrow, SP->_curscol));
+ row, col, SP->_cursrow, SP->_curscol));
position_check(SP->_cursrow, SP->_curscol, "GoTo");
@@ -170,7 +180,7 @@ GoTo(int const row, int const col)
if ((oldattr & A_ALTCHARSET)
|| (oldattr && !move_standout_mode)) {
TR(TRACE_CHARPUT, ("turning off (%#lx) %s before move",
- oldattr, _traceattr(oldattr)));
+ oldattr, _traceattr(oldattr)));
vidattr(A_NORMAL);
}
@@ -189,8 +199,8 @@ PutAttrChar(chtype ch)
ch = ('`' | AttrOf(ch));
TR(TRACE_CHARPUT, ("PutAttrChar(%s) at (%d, %d)",
- _tracechtype(ch),
- SP->_cursrow, SP->_curscol));
+ _tracechtype(ch),
+ SP->_cursrow, SP->_curscol));
UpdateAttrs(ch);
data = TextOf(ch);
if (SP->_outch != 0) {
@@ -297,7 +307,7 @@ PutCharLR(chtype const ch)
TPUTS_TRACE("enter_am_mode");
putp(enter_am_mode);
} else if ((enter_insert_mode && exit_insert_mode)
- || insert_character || parm_ich) {
+ || insert_character || parm_ich) {
GoTo(screen_lines - 1, screen_columns - 2);
callPutChar(ch);
GoTo(screen_lines - 1, screen_columns - 2);
@@ -363,7 +373,7 @@ can_clear_with(chtype ch)
if (!back_color_erase && SP->_coloron) {
if (ch & A_COLOR)
return FALSE;
-#ifdef NCURSES_EXT_FUNCS
+#if NCURSES_EXT_FUNCS
if (!SP->_default_color)
return FALSE;
if (SP->_default_fg != C_MASK || SP->_default_bg != C_MASK)
@@ -429,10 +439,11 @@ EmitRange(const chtype * ntext, int num)
* don't bother moving cursor, since it can be the
* last update on the line.
*/
- if (runcount < num)
+ if (runcount < num) {
GoTo(SP->_cursrow, SP->_curscol + runcount);
- else
+ } else {
return 1; /* cursor stays in the middle */
+ }
} else if (repeat_char && runcount > SP->_rep_cost) {
bool wrap_possible = (SP->_curscol + runcount >= screen_columns);
int rep_count = runcount;
@@ -471,15 +482,15 @@ EmitRange(const chtype * ntext, int num)
*/
static int
PutRange(
- const chtype * otext,
- const chtype * ntext,
- int row,
- int first, int last)
+ const chtype * otext,
+ const chtype * ntext,
+ int row,
+ int first, int last)
{
int j, run;
TR(TRACE_CHARPUT, ("PutRange(%p, %p, %d, %d, %d)",
- otext, ntext, row, first, last));
+ otext, ntext, row, first, last));
if (otext != ntext
&& (last - first + 1) > SP->_inline_cost) {
@@ -599,8 +610,8 @@ doupdate(void)
continue;
}
- T(("At (%d, %d): from %s...", i, j, _traceattr(rattr)));
- T(("...to %s", _traceattr(turnon)));
+ TR(TRACE_ATTRS, ("At (%d, %d): from %s...", i, j, _traceattr(rattr)));
+ TR(TRACE_ATTRS, ("...to %s", _traceattr(turnon)));
/*
* If the attribute change location is a blank with a
@@ -630,15 +641,17 @@ doupdate(void)
for (; n < screen_columns; n++) {
if (AttrOf(newscr->_line[m].text[n]) == rattr) {
end_onscreen = TRUE;
- T(("Range attributed with %s ends at (%d, %d)",
- _traceattr(turnon), m, n));
+ TR(TRACE_ATTRS,
+ ("Range attributed with %s ends at (%d, %d)",
+ _traceattr(turnon), m, n));
goto foundit;
}
}
n = 0;
}
- T(("Range attributed with %s ends offscreen",
- _traceattr(turnon)));
+ TR(TRACE_ATTRS,
+ ("Range attributed with %s ends offscreen",
+ _traceattr(turnon)));
foundit:;
if (end_onscreen) {
@@ -651,8 +664,8 @@ doupdate(void)
* of span.
*/
while (n >= 0
- && TextOf(lastline[n]) == ' '
- && SAFE(AttrOf(lastline[n])))
+ && TextOf(lastline[n]) == ' '
+ && SAFE(AttrOf(lastline[n])))
lastline[n--] &= ~turnon;
/* check that there's enough room at end of span */
@@ -667,8 +680,9 @@ doupdate(void)
if (failed) {
int p, q = j;
- T(("Clearing %s beginning at (%d, %d)",
- _traceattr(turnon), i, j));
+ TR(TRACE_ATTRS,
+ ("Clearing %s beginning at (%d, %d)",
+ _traceattr(turnon), i, j));
/* turn off new attributes over span */
for (p = i; p < screen_lines; p++) {
@@ -681,8 +695,9 @@ doupdate(void)
}
foundend:;
} else {
- T(("Cookie space for %s found before (%d, %d)",
- _traceattr(turnon), i, j));
+ TR(TRACE_ATTRS,
+ ("Cookie space for %s found before (%d, %d)",
+ _traceattr(turnon), i, j));
/*
* back up the start of range so there's room
@@ -708,7 +723,7 @@ doupdate(void)
nonempty = 0;
if (curscr->_clear || newscr->_clear) { /* force refresh ? */
- T(("clearing and updating from scratch"));
+ TR(TRACE_UPDATE, ("clearing and updating from scratch"));
ClrUpdate();
curscr->_clear = FALSE; /* reset flag */
newscr->_clear = FALSE; /* reset flag */
@@ -726,7 +741,7 @@ doupdate(void)
nonempty = ClrBottom(nonempty);
- T(("Transforming lines, nonempty %d", nonempty));
+ TR(TRACE_UPDATE, ("Transforming lines, nonempty %d", nonempty));
for (i = 0; i < nonempty; i++) {
/*
* Here is our line-breakout optimization.
@@ -787,10 +802,10 @@ doupdate(void)
#if USE_TRACE_TIMES
(void) times(&after);
TR(TRACE_TIMES,
- ("Update cost: %ld chars, %ld clocks system time, %ld clocks user time",
- _nc_outchars,
- after.tms_stime - before.tms_stime,
- after.tms_utime - before.tms_utime));
+ ("Update cost: %ld chars, %ld clocks system time, %ld clocks user time",
+ _nc_outchars,
+ after.tms_stime - before.tms_stime,
+ after.tms_utime - before.tms_utime));
#endif /* USE_TRACE_TIMES */
_nc_signal_handler(TRUE);
@@ -834,11 +849,11 @@ ClrUpdate(void)
chtype blank = ClrBlank(stdscr);
int nonempty = min(screen_lines, newscr->_maxy + 1);
- T(("ClrUpdate() called"));
+ TR(TRACE_UPDATE, ("ClrUpdate() called"));
ClearScreen(blank);
- T(("updating screen from scratch"));
+ TR(TRACE_UPDATE, ("updating screen from scratch"));
nonempty = ClrBottom(nonempty);
@@ -936,12 +951,14 @@ ClrBottom(int total)
for (col = 0, ok = TRUE; ok && col < last; col++) {
ok = (newscr->_line[row].text[col] == blank);
}
- if (!ok) break;
+ if (!ok)
+ break;
for (col = 0; ok && col < last; col++) {
ok = (curscr->_line[row].text[col] == blank);
}
- if (!ok) top = row;
+ if (!ok)
+ top = row;
}
/* don't use clr_eos for just one line if clr_eol available */
@@ -985,7 +1002,7 @@ TransformLine(int const lineno)
int n;
bool attrchanged = FALSE;
- T(("TransformLine(%d) called", lineno));
+ TR(TRACE_UPDATE, ("TransformLine(%d) called", lineno));
/* copy new hash value to old one */
if (SP->oldhash && SP->newhash)
@@ -1067,11 +1084,11 @@ TransformLine(int const lineno)
*/
if (TextOf(newLine[n]) == ' '
&& ((n > 0
- && xmc_turn_on(newLine[n - 1], newLine[n]))
+ && xmc_turn_on(newLine[n - 1], newLine[n]))
|| (n == 0
&& lineno > 0
&& xmc_turn_on(NEW(lineno - 1, screen_columns - 1),
- newLine[n])))) {
+ newLine[n])))) {
n = m;
}
@@ -1083,7 +1100,7 @@ TransformLine(int const lineno)
*/
if (TextOf(newLine[n]) != ' '
&& ((n + 1 < screen_columns
- && xmc_turn_off(newLine[n], newLine[n + 1]))
+ && xmc_turn_off(newLine[n], newLine[n + 1]))
|| (n + 1 >= screen_columns
&& lineno + 1 < screen_lines
&& xmc_turn_off(newLine[n], NEW(lineno + 1, 0))))) {
@@ -1098,7 +1115,7 @@ TransformLine(int const lineno)
/* find the first differing character */
while (firstChar < screen_columns &&
- newLine[firstChar] == oldLine[firstChar])
+ newLine[firstChar] == oldLine[firstChar])
firstChar++;
/* if there wasn't one, we're done */
@@ -1144,15 +1161,15 @@ TransformLine(int const lineno)
nLastChar = screen_columns - 1;
while (nLastChar > firstChar
- && newLine[nLastChar] == oldLine[nLastChar])
+ && newLine[nLastChar] == oldLine[nLastChar])
nLastChar--;
if (nLastChar >= firstChar) {
GoTo(lineno, firstChar);
PutRange(oldLine, newLine, lineno, firstChar, nLastChar);
memcpy(oldLine + firstChar,
- newLine + firstChar,
- (nLastChar - firstChar + 1) * sizeof(chtype));
+ newLine + firstChar,
+ (nLastChar - firstChar + 1) * sizeof(chtype));
}
return;
}
@@ -1174,8 +1191,8 @@ TransformLine(int const lineno)
PutChar(newLine[firstChar]);
ClrToEOL(blank, FALSE);
} else if ((nLastChar != oLastChar)
- && (newLine[nLastChar] != oldLine[oLastChar]
- || !(_nc_idcok && has_ic()))) {
+ && (newLine[nLastChar] != oldLine[oLastChar]
+ || !(_nc_idcok && has_ic()))) {
GoTo(lineno, firstChar);
if ((oLastChar - nLastChar) > SP->_el_cost) {
if (PutRange(oldLine, newLine, lineno, firstChar, nLastChar))
@@ -1220,7 +1237,7 @@ TransformLine(int const lineno)
if (DelCharCost(oLastChar - nLastChar)
> SP->_el_cost + nLastNonblank - (n + 1)) {
if (PutRange(oldLine, newLine, lineno,
- n + 1, nLastNonblank))
+ n + 1, nLastNonblank))
GoTo(lineno, nLastNonblank + 1);
ClrToEOL(blank, FALSE);
} else {
@@ -1242,8 +1259,8 @@ TransformLine(int const lineno)
/* update the code's internal representation */
if (screen_columns > firstChar)
memcpy(oldLine + firstChar,
- newLine + firstChar,
- (screen_columns - firstChar) * sizeof(chtype));
+ newLine + firstChar,
+ (screen_columns - firstChar) * sizeof(chtype));
}
/*
@@ -1259,9 +1276,9 @@ ClearScreen(chtype blank)
int i, j;
bool fast_clear = (clear_screen || clr_eos || clr_eol);
- T(("ClearScreen() called"));
+ TR(TRACE_UPDATE, ("ClearScreen() called"));
-#ifdef NCURSES_EXT_FUNCS
+#if NCURSES_EXT_FUNCS
if (SP->_coloron
&& !SP->_default_color) {
_nc_do_color(COLOR_PAIR(SP->_current_attr), 0, FALSE, _nc_outch);
@@ -1311,7 +1328,7 @@ ClearScreen(chtype blank)
curscr->_line[i].text[j] = blank;
}
- T(("screen cleared"));
+ TR(TRACE_UPDATE, ("screen cleared"));
}
/*
@@ -1324,7 +1341,7 @@ ClearScreen(chtype blank)
static void
InsStr(chtype * line, int count)
{
- T(("InsStr(%p,%d) called", line, count));
+ TR(TRACE_UPDATE, ("InsStr(%p,%d) called", line, count));
/* Prefer parm_ich as it has the smallest cost - no need to shift
* the whole line on each character. */
@@ -1379,7 +1396,8 @@ DelChar(int count)
{
int n;
- T(("DelChar(%d) called, position = (%d,%d)", count, newscr->_cury, newscr->_curx));
+ TR(TRACE_UPDATE, ("DelChar(%d) called, position = (%d,%d)", count,
+ newscr->_cury, newscr->_curx));
if (parm_dch) {
TPUTS_TRACE("parm_dch");
@@ -1480,7 +1498,7 @@ scroll_csr_forward(int n, int top, int bot, int miny, int maxy, chtype blank)
} else
return ERR;
-#ifdef NCURSES_EXT_FUNCS
+#if NCURSES_EXT_FUNCS
if (FILL_BCE()) {
for (i = 0; i < n; i++) {
GoTo(bot - i, 0);
@@ -1536,7 +1554,7 @@ scroll_csr_backward(int n, int top, int bot, int miny, int maxy, chtype blank)
} else
return ERR;
-#ifdef NCURSES_EXT_FUNCS
+#if NCURSES_EXT_FUNCS
if (FILL_BCE()) {
for (i = 0; i < n; i++) {
GoTo(top + i, 0);
@@ -1616,18 +1634,11 @@ _nc_scrolln(int n, int top, int bot, int maxy)
* Explicitly clear if stuff pushed off top of region might
* be saved by the terminal.
*/
- if (non_dest_scroll_region || (memory_above && top == 0)) {
- for (i = 0; i < n; i++) {
- GoTo(i, 0);
- ClrToEOL(BLANK, FALSE);
- }
- }
-
res = scroll_csr_forward(n, top, bot, 0, maxy, blank);
if (res == ERR && change_scroll_region) {
if ((((n == 1 && scroll_forward) || parm_index)
- && (SP->_cursrow == bot || SP->_cursrow == bot - 1))
+ && (SP->_cursrow == bot || SP->_cursrow == bot - 1))
&& save_cursor && restore_cursor) {
cursor_saved = TRUE;
TPUTS_TRACE("save_cursor");
@@ -1651,23 +1662,24 @@ _nc_scrolln(int n, int top, int bot, int maxy)
if (res == ERR && _nc_idlok)
res = scroll_idl(n, top, bot - n + 1, blank);
- } else { /* (n < 0) - scroll down (backward) */
+
/*
- * Do explicit clear to end of region if it's possible that the
- * terminal might hold on to stuff we push off the end.
+ * Clear the newly shifted-in text.
*/
- if (non_dest_scroll_region || (memory_below && bot == maxy)) {
+ if (res != ERR
+ && (non_dest_scroll_region || (memory_below && bot == maxy))) {
if (bot == maxy && clr_eos) {
- GoTo(maxy + n, 0);
+ GoTo(bot - n, 0);
ClrToEOS(BLANK);
- } else if (clr_eol) {
- for (i = 0; i < -n; i++) {
- GoTo(maxy + n + i, 0);
+ } else {
+ for (i = 0; i < n; i++) {
+ GoTo(bot - i, 0);
ClrToEOL(BLANK, FALSE);
}
}
}
+ } else { /* (n < 0) - scroll down (backward) */
res = scroll_csr_backward(-n, top, bot, 0, maxy, blank);
if (res == ERR && change_scroll_region) {
@@ -1695,6 +1707,17 @@ _nc_scrolln(int n, int top, int bot, int maxy)
if (res == ERR && _nc_idlok)
res = scroll_idl(-n, bot + n + 1, top, blank);
+
+ /*
+ * Clear the newly shifted-in text.
+ */
+ if (res != ERR
+ && (non_dest_scroll_region || (memory_above && top == 0))) {
+ for (i = 0; i < -n; i++) {
+ GoTo(i + top, 0);
+ ClrToEOL(BLANK, FALSE);
+ }
+ }
}
if (res == ERR)
@@ -1745,7 +1768,7 @@ void
_nc_screen_wrap(void)
{
UpdateAttrs(A_NORMAL);
-#ifdef NCURSES_EXT_FUNCS
+#if NCURSES_EXT_FUNCS
if (SP->_coloron
&& !SP->_default_color) {
SP->_default_color = TRUE;
@@ -1772,7 +1795,7 @@ _nc_do_xmc_glitch(attr_t previous)
SP->_curscol += magic_cookie_glitch;
if (SP->_curscol >= SP->_columns)
wrap_cursor();
- T(("bumped to %d,%d after cookie", SP->_cursrow, SP->_curscol));
+ TR(TRACE_UPDATE, ("bumped to %d,%d after cookie", SP->_cursrow, SP->_curscol));
}
chg >>= 1;
}