From 4b107ee47ccf17c9f1ad6db8a59eb142776341c8 Mon Sep 17 00:00:00 2001 From: millert Date: Fri, 10 Mar 2000 01:35:01 +0000 Subject: [PATCH] Update to ncurses-5.0-20000304 --- lib/libcurses/base/lib_color.c | 70 +- lib/libcurses/base/lib_dft_fgbg.c | 33 +- lib/libcurses/base/lib_getch.c | 554 ++++---- lib/libcurses/base/lib_mouse.c | 6 +- lib/libcurses/base/lib_newterm.c | 6 +- lib/libcurses/base/lib_nl.c | 6 +- lib/libcurses/base/lib_pad.c | 5 +- lib/libcurses/base/lib_set_term.c | 6 +- lib/libcurses/base/wresize.c | 219 +-- lib/libcurses/curs_attr.3tbl | 10 +- lib/libcurses/curs_kernel.3 | 11 +- lib/libcurses/curs_outopts.3 | 5 +- lib/libcurses/curses.h | 8 +- lib/libcurses/curses.priv.h | 19 +- lib/libcurses/dft_fgbg.3 | 23 +- lib/libcurses/doc/hackguide.html | 141 +- lib/libcurses/doc/ncurses-intro.html | 268 ++-- lib/libcurses/ncurses_cfg.h | 3 +- lib/libcurses/tinfo/comp_scan.c | 4 +- lib/libcurses/tinfo/lib_napms.c | 6 +- lib/libcurses/tinfo/lib_options.c | 6 +- lib/libcurses/tinfo/lib_raw.c | 6 +- lib/libcurses/tinfo/lib_setup.c | 6 +- lib/libcurses/tinfo/lib_termcap.c | 6 +- lib/libcurses/tinfo/lib_ti.c | 6 +- lib/libcurses/tinfo/lib_tputs.c | 11 +- lib/libcurses/tinfo/parse_entry.c | 6 +- lib/libcurses/tinfo/read_entry.c | 6 +- lib/libcurses/tinfo/read_termcap.c | 6 +- lib/libcurses/tinfo/write_entry.c | 6 +- lib/libcurses/trace/lib_trace.c | 6 +- lib/libcurses/trace/lib_tracebits.c | 6 +- lib/libcurses/tty/lib_mvcur.c | 6 +- lib/libcurses/tty/lib_twait.c | 6 +- lib/libcurses/tty/tty_display.h | 11 +- lib/libcurses/tty/tty_update.c | 1864 ++++++++++++-------------- usr.bin/tic/MKtermsort.sh | 9 +- usr.bin/tic/progs.priv.h | 9 +- usr.bin/tic/tic.c | 109 +- usr.bin/tset/tset.c | 1455 ++++++++++---------- 40 files changed, 2482 insertions(+), 2467 deletions(-) diff --git a/lib/libcurses/base/lib_color.c b/lib/libcurses/base/lib_color.c index f60847d43cd..e917647497b 100644 --- a/lib/libcurses/base/lib_color.c +++ b/lib/libcurses/base/lib_color.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_color.c,v 1.5 2000/01/02 22:06:51 millert Exp $ */ +/* $OpenBSD: lib_color.c,v 1.6 2000/03/10 01:35:02 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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,11 +43,11 @@ #include #include -MODULE_ID("$From: lib_color.c,v 1.42 2000/01/01 16:42:37 tom Exp $") +MODULE_ID("$From: lib_color.c,v 1.45 2000/02/27 00:20:31 tom Exp $") /* * These should be screen structure members. They need to be globals for - * hystorical reasons. So we assign them in start_color() and also in + * historical reasons. So we assign them in start_color() and also in * set_term()'s screen-switching logic. */ int COLOR_PAIRS = 0; @@ -91,13 +91,13 @@ static const color_t hls_palette[] = static int default_fg(void) { - return (SP->_default_fg >= 0) ? SP->_default_fg : COLOR_WHITE; + return (SP->_default_fg != C_MASK) ? SP->_default_fg : COLOR_WHITE; } static int default_bg(void) { - return (SP->_default_bg >= 0) ? SP->_default_bg : COLOR_BLACK; + return (SP->_default_bg != C_MASK) ? SP->_default_bg : COLOR_BLACK; } #else #define default_fg() COLOR_WHITE @@ -420,37 +420,51 @@ _nc_do_color(int pair, bool reverse, int (*outc) (int)) !SP->_default_color || #endif !set_original_colors()) { - set_foreground_color(default_fg(), outc); - set_background_color(default_bg(), outc); + fg = default_fg(); + bg = default_bg(); + } else { + fg = C_MASK; + bg = C_MASK; } } else { if (set_color_pair) { TPUTS_TRACE("set_color_pair"); tputs(tparm(set_color_pair, pair), 1, outc); + return; } else { pair_content(pair, &fg, &bg); - if (reverse) { - short xx = fg; - fg = bg; - bg = xx; +#ifdef NCURSES_EXT_FUNCS + if (SP->_default_color) { + if (fg == C_MASK) + fg = SP->_default_fg; + if (bg == C_MASK) + bg = SP->_default_bg; } +#endif + } + } - T(("setting colors: pair = %d, fg = %d, bg = %d", pair, fg, bg)); - - if (fg == C_MASK || bg == C_MASK) { - if (set_original_colors() != TRUE) { - if (fg == C_MASK) - set_foreground_color(default_fg(), outc); - if (bg == C_MASK) - set_background_color(default_bg(), outc); - } - } - if (fg != C_MASK) { - set_foreground_color(fg, outc); - } - if (bg != C_MASK) { - set_background_color(bg, outc); - } + if (fg == C_MASK || bg == C_MASK) { + if (set_original_colors() != TRUE) { + if (fg == C_MASK) + fg = default_fg(); + if (bg == C_MASK) + bg = default_bg(); } } + + if (reverse) { + short xx = fg; + fg = bg; + bg = xx; + } + + T(("setting colors: pair = %d, fg = %d, bg = %d", pair, fg, bg)); + + if (fg != C_MASK) { + set_foreground_color(fg, outc); + } + if (bg != C_MASK) { + set_background_color(bg, outc); + } } diff --git a/lib/libcurses/base/lib_dft_fgbg.c b/lib/libcurses/base/lib_dft_fgbg.c index 80da38979a6..df007242458 100644 --- a/lib/libcurses/base/lib_dft_fgbg.c +++ b/lib/libcurses/base/lib_dft_fgbg.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_dft_fgbg.c,v 1.2 1999/11/28 17:49:53 millert Exp $ */ +/* $OpenBSD: lib_dft_fgbg.c,v 1.3 2000/03/10 01:35:02 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 * @@ -31,10 +31,11 @@ /**************************************************************************** * Author: Thomas E. Dickey 1997,1999 * ****************************************************************************/ + #include #include -MODULE_ID("$From: lib_dft_fgbg.c,v 1.7 1999/11/14 01:22:11 tom Exp $") +MODULE_ID("$From: lib_dft_fgbg.c,v 1.8 2000/02/19 23:57:40 tom Exp $") /* * Modify the behavior of color-pair 0 so that the library doesn't assume that @@ -43,8 +44,8 @@ MODULE_ID("$From: lib_dft_fgbg.c,v 1.7 1999/11/14 01:22:11 tom Exp $") int use_default_colors(void) { - T((T_CALLED("use_default_colors()"))); - returnCode(assume_default_colors(C_MASK, C_MASK)); + T((T_CALLED("use_default_colors()"))); + returnCode(assume_default_colors(C_MASK, C_MASK)); } /* @@ -54,18 +55,18 @@ use_default_colors(void) int assume_default_colors(int fg, int bg) { - T((T_CALLED("assume_default_colors(%d,%d)"), fg, bg)); + T((T_CALLED("assume_default_colors(%d,%d)"), fg, bg)); - if (!orig_pair && !orig_colors) - returnCode(ERR); + if (!orig_pair && !orig_colors) + returnCode(ERR); - if (initialize_pair) /* don't know how to handle this */ - returnCode(ERR); + if (initialize_pair) /* don't know how to handle this */ + returnCode(ERR); - SP->_default_color = (fg != COLOR_WHITE) || (bg != COLOR_BLACK); - SP->_default_fg = fg; - SP->_default_bg = bg; - if (SP->_color_pairs != 0) - SP->_color_pairs[0] = PAIR_OF(fg, bg); - returnCode(OK); + SP->_default_color = (fg != COLOR_WHITE) || (bg != COLOR_BLACK); + 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) + SP->_color_pairs[0] = PAIR_OF(fg, bg); + returnCode(OK); } diff --git a/lib/libcurses/base/lib_getch.c b/lib/libcurses/base/lib_getch.c index 9c1b5f314a6..3057117c347 100644 --- a/lib/libcurses/base/lib_getch.c +++ b/lib/libcurses/base/lib_getch.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_getch.c,v 1.3 2000/01/23 04:57:41 millert Exp $ */ +/* $OpenBSD: lib_getch.c,v 1.4 2000/03/10 01:35:02 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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,151 +42,154 @@ #include -MODULE_ID("$From: lib_getch.c,v 1.44 2000/01/17 19:58:18 tom Exp $") +MODULE_ID("$From: lib_getch.c,v 1.46 2000/02/20 01:21:33 tom Exp $") #include -int ESCDELAY = 1000; /* max interval betw. chars in funkeys, in millisecs */ +int ESCDELAY = 1000; /* max interval betw. chars in funkeys, in millisecs */ #ifdef USE_EMX_MOUSE # include static int kbd_mouse_read(unsigned char *p) { -fd_set fdset; -int nums = SP->_ifd+1; - - for (;;) { - FD_ZERO(&fdset); - FD_SET(SP->_ifd, &fdset); - if (SP->_checkfd >= 0) { - FD_SET(SP->_checkfd, &fdset); - if (SP->_checkfd >= nums) - nums = SP->_checkfd + 1; - } - if (SP->_mouse_fd >= 0) { - FD_SET(SP->_mouse_fd, &fdset); - if (SP->_mouse_fd >= nums) - nums = SP->_mouse_fd + 1; - } - if (select(nums, &fdset, NULL, NULL, NULL) >= 0) { - int n; - - if (SP->_mouse_fd >= 0 - && FD_ISSET(SP->_mouse_fd, &fdset)) { /* Prefer mouse */ - n = read(SP->_mouse_fd, p, 1); - } else { - n = read(SP->_ifd, p, 1); - } - return n; - } - if (errno != EINTR) { - return -1; - } + fd_set fdset; + int nums = SP->_ifd + 1; + + for (;;) { + FD_ZERO(&fdset); + FD_SET(SP->_ifd, &fdset); + if (SP->_checkfd >= 0) { + FD_SET(SP->_checkfd, &fdset); + if (SP->_checkfd >= nums) + nums = SP->_checkfd + 1; } + if (SP->_mouse_fd >= 0) { + FD_SET(SP->_mouse_fd, &fdset); + if (SP->_mouse_fd >= nums) + nums = SP->_mouse_fd + 1; + } + if (select(nums, &fdset, NULL, NULL, NULL) >= 0) { + int n; + + if (SP->_mouse_fd >= 0 + && FD_ISSET(SP->_mouse_fd, &fdset)) { /* Prefer mouse */ + n = read(SP->_mouse_fd, p, 1); + } else { + n = read(SP->_ifd, p, 1); + } + return n; + } + if (errno != EINTR) { + return -1; + } + } } -#endif /* USE_EMX_MOUSE */ +#endif /* USE_EMX_MOUSE */ -static inline int fifo_peek(void) +static inline int +fifo_peek(void) { - int ch = SP->_fifo[peek]; - T(("peeking at %d", peek)); + int ch = SP->_fifo[peek]; + T(("peeking at %d", peek)); - p_inc(); - return ch; + p_inc(); + return ch; } - -static inline int fifo_pull(void) +static inline int +fifo_pull(void) { -int ch; - ch = SP->_fifo[head]; - T(("pulling %d from %d", ch, head)); + int ch; + ch = SP->_fifo[head]; + T(("pulling %d from %d", ch, head)); - if (peek == head) - { - h_inc(); - peek = head; - } - else - h_inc(); + if (peek == head) { + h_inc(); + peek = head; + } else + h_inc(); #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) _nc_fifo_dump(); + if (_nc_tracing & TRACE_IEVENT) + _nc_fifo_dump(); #endif - return ch; + return ch; } -static inline int fifo_push(void) +static inline int +fifo_push(void) { -int n; -unsigned int ch; + int n; + unsigned int ch; - if (tail == -1) return ERR; + if (tail == -1) + return ERR; #ifdef HIDE_EINTR -again: - errno = 0; + again: + errno = 0; #endif #if USE_GPM_SUPPORT - if ((SP->_mouse_fd >= 0) - && (_nc_timed_wait(3, -1, (int *)0) & 2)) - { - SP->_mouse_event(SP); - ch = KEY_MOUSE; - n = 1; - } else + if ((SP->_mouse_fd >= 0) + && (_nc_timed_wait(3, -1, (int *) 0) & 2)) { + SP->_mouse_event(SP); + ch = KEY_MOUSE; + n = 1; + } else #endif - { - unsigned char c2=0; + { + unsigned char c2 = 0; #ifdef USE_EMX_MOUSE - n = kbd_mouse_read(&c2); + n = kbd_mouse_read(&c2); #else - n = read(SP->_ifd, &c2, 1); + n = read(SP->_ifd, &c2, 1); #endif - ch = c2 & 0xff; - } + ch = c2 & 0xff; + } #ifdef HIDE_EINTR - /* - * Under System V curses with non-restarting signals, getch() returns - * with value ERR when a handled signal keeps it from completing. - * If signals restart system calls, OTOH, the signal is invisible - * except to its handler. - * - * We don't want this difference to show. This piece of code - * tries to make it look like we always have restarting signals. - */ - if (n <= 0 && errno == EINTR) - goto again; + /* + * Under System V curses with non-restarting signals, getch() returns + * with value ERR when a handled signal keeps it from completing. + * If signals restart system calls, OTOH, the signal is invisible + * except to its handler. + * + * We don't want this difference to show. This piece of code + * tries to make it look like we always have restarting signals. + */ + if (n <= 0 && errno == EINTR) + goto again; #endif - if ((n == -1) || (n == 0)) - { - T(("read(%d,&ch,1)=%d, errno=%d", SP->_ifd, n, errno)); - return ERR; - } - T(("read %d characters", n)); - - SP->_fifo[tail] = ch; - SP->_fifohold = 0; - if (head == -1) - head = peek = tail; - t_inc(); - T(("pushed %#x at %d", ch, tail)); + if ((n == -1) || (n == 0)) { + T(("read(%d,&ch,1)=%d, errno=%d", SP->_ifd, n, errno)); + return ERR; + } + T(("read %d characters", n)); + + SP->_fifo[tail] = ch; + SP->_fifohold = 0; + if (head == -1) + head = peek = tail; + t_inc(); + T(("pushed %#x at %d", ch, tail)); #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) _nc_fifo_dump(); + if (_nc_tracing & TRACE_IEVENT) + _nc_fifo_dump(); #endif - return ch; + return ch; } -static inline void fifo_clear(void) +static inline void +fifo_clear(void) { -int i; - for (i = 0; i < FIFO_SIZE; i++) - SP->_fifo[i] = 0; - head = -1; tail = peek = 0; + int i; + for (i = 0; i < FIFO_SIZE; i++) + SP->_fifo[i] = 0; + head = -1; + tail = peek = 0; } static int kgetch(WINDOW *); @@ -198,147 +201,137 @@ static int kgetch(WINDOW *); int wgetch(WINDOW *win) { -int ch; + int ch; - T((T_CALLED("wgetch(%p)"), win)); + T((T_CALLED("wgetch(%p)"), win)); - if (!win) - returnCode(ERR); + if (!win) + returnCode(ERR); - if (cooked_key_in_fifo()) - { - if (wgetch_should_refresh(win)) - wrefresh(win); + if (cooked_key_in_fifo()) { + if (wgetch_should_refresh(win)) + wrefresh(win); - ch = fifo_pull(); - T(("wgetch returning (pre-cooked): %#x = %s", ch, _trace_key(ch));) - returnCode(ch); - } + ch = fifo_pull(); + T(("wgetch returning (pre-cooked): %#x = %s", ch, _trace_key(ch))); + returnCode(ch); + } - /* - * Handle cooked mode. Grab a string from the screen, - * stuff its contents in the FIFO queue, and pop off - * the first character to return it. - */ - if (head == -1 && !SP->_raw && !SP->_cbreak) - { - char buf[MAXCOLUMNS], *sp; + /* + * Handle cooked mode. Grab a string from the screen, + * stuff its contents in the FIFO queue, and pop off + * the first character to return it. + */ + if (head == -1 && !SP->_raw && !SP->_cbreak) { + char buf[MAXCOLUMNS], *sp; - T(("filling queue in cooked mode")); + T(("filling queue in cooked mode")); - wgetnstr(win, buf, MAXCOLUMNS); + wgetnstr(win, buf, MAXCOLUMNS); - /* ungetch in reverse order */ - ungetch('\n'); - for (sp = buf+strlen(buf); sp>buf; sp--) - ungetch(sp[-1]); + /* ungetch in reverse order */ + ungetch('\n'); + for (sp = buf + strlen(buf); sp > buf; sp--) + ungetch(sp[-1]); - returnCode(fifo_pull()); - } + returnCode(fifo_pull()); + } - if (wgetch_should_refresh(win)) - wrefresh(win); + if (wgetch_should_refresh(win)) + wrefresh(win); - if (!win->_notimeout && (win->_delay >= 0 || SP->_cbreak > 1)) - { - int delay; + if (!win->_notimeout && (win->_delay >= 0 || SP->_cbreak > 1)) { + int delay; - T(("timed delay in wgetch()")); - if (SP->_cbreak > 1) - delay = (SP->_cbreak - 1) * 100; - else - delay = win->_delay; + T(("timed delay in wgetch()")); + if (SP->_cbreak > 1) + delay = (SP->_cbreak - 1) * 100; + else + delay = win->_delay; - T(("delay is %d milliseconds", delay)); + T(("delay is %d milliseconds", delay)); - if (head == -1) /* fifo is empty */ - if (!_nc_timed_wait(3, delay, (int *)0)) - returnCode(ERR); - /* else go on to read data available */ - } + if (head == -1) /* fifo is empty */ + if (!_nc_timed_wait(3, delay, (int *) 0)) + returnCode(ERR); + /* else go on to read data available */ + } - if (win->_use_keypad) - { - /* - * This is tricky. We only want to get special-key - * events one at a time. But we want to accumulate - * mouse events until either (a) the mouse logic tells - * us it's picked up a complete gesture, or (b) - * there's a detectable time lapse after one. - * - * Note: if the mouse code starts failing to compose - * press/release events into clicks, you should probably - * increase the wait with mouseinterval(). - */ - int runcount = 0; - - do { - ch = kgetch(win); - if (ch == KEY_MOUSE) - { - ++runcount; - if (SP->_mouse_inline(SP)) - break; - } - } while - (ch == KEY_MOUSE - && (_nc_timed_wait(3, SP->_maxclick, (int *)0) - || !SP->_mouse_parse(runcount))); - if (runcount > 0 && ch != KEY_MOUSE) - { - /* mouse event sequence ended by keystroke, push it */ - ungetch(ch); - ch = KEY_MOUSE; - } - } else { - if (head == -1) - fifo_push(); - ch = fifo_pull(); + if (win->_use_keypad) { + /* + * This is tricky. We only want to get special-key + * events one at a time. But we want to accumulate + * mouse events until either (a) the mouse logic tells + * us it's picked up a complete gesture, or (b) + * there's a detectable time lapse after one. + * + * Note: if the mouse code starts failing to compose + * press/release events into clicks, you should probably + * increase the wait with mouseinterval(). + */ + int runcount = 0; + + do { + ch = kgetch(win); + if (ch == KEY_MOUSE) { + ++runcount; + if (SP->_mouse_inline(SP)) + break; + } + } while + (ch == KEY_MOUSE + && (_nc_timed_wait(3, SP->_maxclick, (int *) 0) + || !SP->_mouse_parse(runcount))); + if (runcount > 0 && ch != KEY_MOUSE) { + /* mouse event sequence ended by keystroke, push it */ + ungetch(ch); + ch = KEY_MOUSE; } + } else { + if (head == -1) + fifo_push(); + ch = fifo_pull(); + } - if (ch == ERR) - { + if (ch == ERR) { #if USE_SIZECHANGE - if(SP->_sig_winch) - { - _nc_update_screensize(); - /* resizeterm can push KEY_RESIZE */ - if(cooked_key_in_fifo()) - { - ch = fifo_pull(); - T(("wgetch returning (pre-cooked): %#x = %s", ch, _trace_key(ch));) - returnCode(ch); - } + if (SP->_sig_winch) { + _nc_update_screensize(); + /* resizeterm can push KEY_RESIZE */ + if (cooked_key_in_fifo()) { + ch = fifo_pull(); + T(("wgetch returning (pre-cooked): %#x = %s", ch, _trace_key(ch))); + returnCode(ch); } -#endif - T(("wgetch returning ERR")); - returnCode(ERR); } - - /* - * Simulate ICRNL mode - */ - if ((ch == '\r') && SP->_nl) - ch = '\n'; - - /* Strip 8th-bit if so desired. We do this only for characters that - * are in the range 128-255, to provide compatibility with terminals - * that display only 7-bit characters. Note that 'ch' may be a - * function key at this point, so we mustn't strip _those_. - */ - if ((ch < KEY_MIN) && (ch & 0x80)) - 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); +#endif + T(("wgetch returning ERR")); + returnCode(ERR); + } + + /* + * Simulate ICRNL mode + */ + if ((ch == '\r') && SP->_nl) + ch = '\n'; + + /* Strip 8th-bit if so desired. We do this only for characters that + * are in the range 128-255, to provide compatibility with terminals + * that display only 7-bit characters. Note that 'ch' may be a + * function key at this point, so we mustn't strip _those_. + */ + if ((ch < KEY_MIN) && (ch & 0x80)) + 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); } - /* ** int ** kgetch() @@ -357,68 +350,63 @@ int ch; static int kgetch(WINDOW *win GCC_UNUSED) { -struct tries *ptr; -int ch = 0; -int timeleft = ESCDELAY; - - TR(TRACE_IEVENT, ("kgetch(%p) called", win)); - - ptr = SP->_keytry; - - for(;;) - { - if (!raw_key_in_fifo()) - { - if(fifo_push() == ERR) - { - peek = head; /* the keys stay uninterpreted */ - return ERR; - } - } - ch = fifo_peek(); - if (ch >= KEY_MIN) - { - peek = head; - /* assume the key is the last in fifo */ - t_dec(); /* remove the key */ - return ch; - } - - TR(TRACE_IEVENT, ("ch: %s", _trace_key((unsigned char)ch))); - while ((ptr != NULL) && (ptr->ch != (unsigned char)ch)) - ptr = ptr->sibling; + struct tries *ptr; + int ch = 0; + int timeleft = ESCDELAY; + + TR(TRACE_IEVENT, ("kgetch(%p) called", win)); + + ptr = SP->_keytry; + + for (;;) { + if (!raw_key_in_fifo()) { + if (fifo_push() == ERR) { + peek = head; /* the keys stay uninterpreted */ + return ERR; + } + } + ch = fifo_peek(); + if (ch >= KEY_MIN) { + peek = head; + /* assume the key is the last in fifo */ + t_dec(); /* remove the key */ + return ch; + } + + TR(TRACE_IEVENT, ("ch: %s", _trace_key((unsigned char) ch))); + while ((ptr != NULL) && (ptr->ch != (unsigned char) ch)) + ptr = ptr->sibling; #ifdef TRACE - if (ptr == NULL) - {TR(TRACE_IEVENT, ("ptr is null"));} - else - TR(TRACE_IEVENT, ("ptr=%p, ch=%d, value=%d", - ptr, ptr->ch, ptr->value)); + if (ptr == NULL) { + TR(TRACE_IEVENT, ("ptr is null")); + } else + TR(TRACE_IEVENT, ("ptr=%p, ch=%d, value=%d", + ptr, ptr->ch, ptr->value)); #endif /* TRACE */ - if (ptr == NULL) - break; - - if (ptr->value != 0) { /* sequence terminated */ - TR(TRACE_IEVENT, ("end of sequence")); - if (peek == tail) - fifo_clear(); - else - head = peek; - return(ptr->value); - } - - ptr = ptr->child; - - if (!raw_key_in_fifo()) - { - TR(TRACE_IEVENT, ("waiting for rest of sequence")); - if (!_nc_timed_wait(3, timeleft, &timeleft)) { - TR(TRACE_IEVENT, ("ran out of time")); - break; - } - } + if (ptr == NULL) + break; + + if (ptr->value != 0) { /* sequence terminated */ + TR(TRACE_IEVENT, ("end of sequence")); + if (peek == tail) + fifo_clear(); + else + head = peek; + return (ptr->value); } - ch = fifo_pull(); - peek = head; - return ch; + + ptr = ptr->child; + + if (!raw_key_in_fifo()) { + TR(TRACE_IEVENT, ("waiting for rest of sequence")); + if (!_nc_timed_wait(3, timeleft, &timeleft)) { + TR(TRACE_IEVENT, ("ran out of time")); + break; + } + } + } + ch = fifo_pull(); + peek = head; + return ch; } diff --git a/lib/libcurses/base/lib_mouse.c b/lib/libcurses/base/lib_mouse.c index 29cec56f17e..2bac96dd2e6 100644 --- a/lib/libcurses/base/lib_mouse.c +++ b/lib/libcurses/base/lib_mouse.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_mouse.c,v 1.7 2000/01/09 05:06:02 millert Exp $ */ +/* $OpenBSD: lib_mouse.c,v 1.8 2000/03/10 01:35:02 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 * @@ -86,7 +86,7 @@ #endif #endif -MODULE_ID("$From: lib_mouse.c,v 1.48 2000/01/08 17:34:43 tom Exp $"); +MODULE_ID("$From: lib_mouse.c,v 1.50 2000/02/13 00:59:39 tom Exp $") #define MY_TRACE TRACE_ICALLS|TRACE_IEVENT diff --git a/lib/libcurses/base/lib_newterm.c b/lib/libcurses/base/lib_newterm.c index 3360ebcd704..73899d4ecc8 100644 --- a/lib/libcurses/base/lib_newterm.c +++ b/lib/libcurses/base/lib_newterm.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_newterm.c,v 1.6 2000/01/02 22:06:51 millert Exp $ */ +/* $OpenBSD: lib_newterm.c,v 1.7 2000/03/10 01:35:02 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 * @@ -49,7 +49,7 @@ #include /* clear_screen, cup & friends, cur_term */ #include -MODULE_ID("$From: lib_newterm.c,v 1.43 2000/01/01 16:56:20 tom Exp $") +MODULE_ID("$From: lib_newterm.c,v 1.44 2000/02/13 00:59:39 tom Exp $") #ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */ #define ONLCR 0 diff --git a/lib/libcurses/base/lib_nl.c b/lib/libcurses/base/lib_nl.c index 5e69c25e300..9e089cb9216 100644 --- a/lib/libcurses/base/lib_nl.c +++ b/lib/libcurses/base/lib_nl.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_nl.c,v 1.3 2000/01/09 05:06:02 millert Exp $ */ +/* $OpenBSD: lib_nl.c,v 1.4 2000/03/10 01:35:02 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 * @@ -44,7 +44,7 @@ #include -MODULE_ID("$From: lib_nl.c,v 1.5 2000/01/08 17:33:30 tom Exp $") +MODULE_ID("$From: lib_nl.c,v 1.6 2000/02/13 00:59:39 tom Exp $") #ifdef __EMX__ #include diff --git a/lib/libcurses/base/lib_pad.c b/lib/libcurses/base/lib_pad.c index c031c018853..4f2ed3e58be 100644 --- a/lib/libcurses/base/lib_pad.c +++ b/lib/libcurses/base/lib_pad.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_pad.c,v 1.1 1999/01/18 19:09:55 millert Exp $ */ +/* $OpenBSD: lib_pad.c,v 1.2 2000/03/10 01:35:02 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -43,7 +43,7 @@ #include -MODULE_ID("$From: lib_pad.c,v 1.27 1998/06/28 00:10:16 tom Exp $") +MODULE_ID("$From: lib_pad.c,v 1.28 2000/03/05 00:21:55 David.Mosberger Exp $") WINDOW *newpad(int l, int c) { @@ -243,6 +243,7 @@ bool wide; newscr->_cury = win->_cury - pminrow + win->_begy + win->_yoffset; newscr->_curx = win->_curx - pmincol + win->_begx; } + newscr->_leaveok = win->_leaveok; win->_flags &= ~_HASMOVED; /* diff --git a/lib/libcurses/base/lib_set_term.c b/lib/libcurses/base/lib_set_term.c index 67d84e53e0d..55f4b205a34 100644 --- a/lib/libcurses/base/lib_set_term.c +++ b/lib/libcurses/base/lib_set_term.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_set_term.c,v 1.6 2000/01/02 22:06:51 millert Exp $ */ +/* $OpenBSD: lib_set_term.c,v 1.7 2000/03/10 01:35:02 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 * @@ -45,7 +45,7 @@ #include /* cur_term */ #include -MODULE_ID("$From: lib_set_term.c,v 1.49 2000/01/01 16:44:29 tom Exp $") +MODULE_ID("$From: lib_set_term.c,v 1.50 2000/02/13 00:59:39 tom Exp $") SCREEN * set_term(SCREEN * screenp) diff --git a/lib/libcurses/base/wresize.c b/lib/libcurses/base/wresize.c index b70f5678231..9eacdbf6a0d 100644 --- a/lib/libcurses/base/wresize.c +++ b/lib/libcurses/base/wresize.c @@ -1,7 +1,7 @@ -/* $OpenBSD: wresize.c,v 1.2 1999/03/02 06:23:28 millert Exp $ */ +/* $OpenBSD: wresize.c,v 1.3 2000/03/10 01:35:03 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 * @@ -34,7 +34,7 @@ #include -MODULE_ID("$From: wresize.c,v 1.12 1999/02/27 18:57:31 tom Exp $") +MODULE_ID("$From: wresize.c,v 1.16 2000/03/05 00:14:35 tom Exp $") /* * Reallocate a curses WINDOW struct to either shrink or grow to the specified @@ -49,120 +49,133 @@ MODULE_ID("$From: wresize.c,v 1.12 1999/02/27 18:57:31 tom Exp $") int wresize(WINDOW *win, int ToLines, int ToCols) { - register int row; - int size_x, size_y; - struct ldat *pline; - chtype blank; + register int row; + int size_x, size_y; + struct ldat *pline; + chtype blank; #ifdef TRACE - T((T_CALLED("wresize(%p,%d,%d)"), win, ToLines, ToCols)); - if (win) { - TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)", - win->_begy, win->_begx, - win->_maxy, win->_maxx, - win->_regtop, win->_regbottom)); - if (_nc_tracing & TRACE_UPDATE) + T((T_CALLED("wresize(%p,%d,%d)"), win, ToLines, ToCols)); + if (win) { + TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)", + win->_begy, win->_begx, + win->_maxy, win->_maxx, + win->_regtop, win->_regbottom)); + if (_nc_tracing & TRACE_UPDATE) _tracedump("...before", win); - } + } #endif - if (!win || --ToLines < 0 || --ToCols < 0) - returnCode(ERR); + if (!win || --ToLines < 0 || --ToCols < 0) + returnCode(ERR); - size_x = win->_maxx; - size_y = win->_maxy; + size_x = win->_maxx; + size_y = win->_maxy; - if (ToLines == size_y - && ToCols == size_x) - returnCode(OK); - - pline = (win->_flags & _SUBWIN) ? win->_parent->_line : 0; + if (ToLines == size_y + && ToCols == size_x) + returnCode(OK); + if ((win->_flags & _SUBWIN)) { /* - * If the number of lines has changed, adjust the size of the overall - * vector: + * Check if the new limits will fit into the parent window's size. If + * not, do not resize. We could adjust the location of the subwindow, + * but the application may not like that. */ - if (ToLines != size_y) { - if (! (win->_flags & _SUBWIN)) { - for (row = ToLines+1; row <= size_y; row++) - free((char *)(win->_line[row].text)); - } - - win->_line = ld_ALLOC(win->_line, ToLines+1); - if (win->_line == 0) - returnCode(ERR); - - for (row = size_y+1; row <= ToLines; row++) { - win->_line[row].text = 0; - win->_line[row].firstchar = 0; - win->_line[row].lastchar = ToCols; - if ((win->_flags & _SUBWIN)) { - win->_line[row].text = - &pline[win->_begy + row].text[win->_begx]; - } - } + if (win->_pary + ToLines > win->_parent->_maxy + || win->_parx + ToCols > win->_parent->_maxx) { + returnCode(ERR); } - - /* - * Adjust the width of the columns: - */ - blank = _nc_background(win); - for (row = 0; row <= ToLines; row++) { - chtype *s = win->_line[row].text; - int begin = (s == 0) ? 0 : size_x + 1; - int end = ToCols; - - if_USE_SCROLL_HINTS(win->_line[row].oldindex = row); - - if (ToCols != size_x || s == 0) { - if (! (win->_flags & _SUBWIN)) { - win->_line[row].text = s = c_ALLOC(s, ToCols+1); - if (win->_line[row].text == 0) - returnCode(ERR); - } else if (s == 0) { - win->_line[row].text = s = - &pline[win->_begy + row].text[win->_begx]; - } - - if (end >= begin) { /* growing */ - if (win->_line[row].firstchar < begin) - win->_line[row].firstchar = begin; - win->_line[row].lastchar = ToCols; - do { - s[end] = blank; - } while (--end >= begin); - } else { /* shrinking */ - win->_line[row].firstchar = 0; - win->_line[row].lastchar = ToCols; - } - } + pline = win->_parent->_line; + } else { + pline = 0; + } + + /* + * If the number of lines has changed, adjust the size of the overall + * vector: + */ + if (ToLines != size_y) { + if (!(win->_flags & _SUBWIN)) { + for (row = ToLines + 1; row <= size_y; row++) + free((char *) (win->_line[row].text)); } - /* - * Finally, adjust the parameters showing screen size and cursor - * position: - */ - win->_maxx = ToCols; - win->_maxy = ToLines; - - if (win->_regtop > win->_maxy) - win->_regtop = win->_maxy; - if (win->_regbottom > win->_maxy - || win->_regbottom == size_y) - win->_regbottom = win->_maxy; - - if (win->_curx > win->_maxx) - win->_curx = win->_maxx; - if (win->_cury > win->_maxy) - win->_cury = win->_maxy; + win->_line = ld_ALLOC(win->_line, ToLines + 1); + if (win->_line == 0) + returnCode(ERR); + + for (row = size_y + 1; row <= ToLines; row++) { + win->_line[row].text = 0; + win->_line[row].firstchar = 0; + win->_line[row].lastchar = ToCols; + if ((win->_flags & _SUBWIN)) { + win->_line[row].text = + &pline[win->_pary + row].text[win->_parx]; + } + } + } + + /* + * Adjust the width of the columns: + */ + blank = _nc_background(win); + for (row = 0; row <= ToLines; row++) { + chtype *s = win->_line[row].text; + int begin = (s == 0) ? 0 : size_x + 1; + int end = ToCols; + + if_USE_SCROLL_HINTS(win->_line[row].oldindex = row); + + if (ToCols != size_x || s == 0) { + if (!(win->_flags & _SUBWIN)) { + win->_line[row].text = s = c_ALLOC(s, ToCols + 1); + if (win->_line[row].text == 0) + returnCode(ERR); + } else if (s == 0) { + win->_line[row].text = s = + &pline[win->_pary + row].text[win->_parx]; + } + + if (end >= begin) { /* growing */ + if (win->_line[row].firstchar < begin) + win->_line[row].firstchar = begin; + win->_line[row].lastchar = ToCols; + do { + s[end] = blank; + } while (--end >= begin); + } else { /* shrinking */ + win->_line[row].firstchar = 0; + win->_line[row].lastchar = ToCols; + } + } + } + + /* + * Finally, adjust the parameters showing screen size and cursor + * position: + */ + win->_maxx = ToCols; + win->_maxy = ToLines; + + if (win->_regtop > win->_maxy) + win->_regtop = win->_maxy; + if (win->_regbottom > win->_maxy + || win->_regbottom == size_y) + win->_regbottom = win->_maxy; + + if (win->_curx > win->_maxx) + win->_curx = win->_maxx; + if (win->_cury > win->_maxy) + win->_cury = win->_maxy; #ifdef TRACE - TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)", - win->_begy, win->_begx, - win->_maxy, win->_maxx, - win->_regtop, win->_regbottom)); - if (_nc_tracing & TRACE_UPDATE) - _tracedump("...after:", win); + TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)", + win->_begy, win->_begx, + win->_maxy, win->_maxx, + win->_regtop, win->_regbottom)); + if (_nc_tracing & TRACE_UPDATE) + _tracedump("...after:", win); #endif - returnCode(OK); + returnCode(OK); } diff --git a/lib/libcurses/curs_attr.3tbl b/lib/libcurses/curs_attr.3tbl index 2e90f33d9fc..9df2dad05ab 100644 --- a/lib/libcurses/curs_attr.3tbl +++ b/lib/libcurses/curs_attr.3tbl @@ -1,8 +1,8 @@ '\" t -.\" $OpenBSD: curs_attr.3tbl,v 1.7 1999/01/18 19:07:11 millert Exp $ +.\" $OpenBSD: curs_attr.3tbl,v 1.8 2000/03/10 01:35:01 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 * @@ -29,7 +29,7 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_attr.3x,v 1.19 1998/12/26 19:25:35 tom Exp $ +.\" $From: curs_attr.3x,v 1.20 2000/02/27 01:46:31 tom Exp $ .TH curs_attr 3 "" .SH NAME \fBattroff\fR, \fBwattroff\fR, \fBattron\fR, \fBwattron\fR, @@ -77,9 +77,9 @@ .br \fBint wattr_on(WINDOW *win, attr_t attrs, void *opts);\fR .br -\fBint attr_set(attr_t attrs, void *opts);\fR +\fBint attr_set(attr_t attrs, short pair, void *opts);\fR .br -\fBint wattr_set(WINDOW *win, attr_t attrs, void *opts);\fR +\fBint wattr_set(WINDOW *win, attr_t attrs, short pair, void *opts);\fR .br \fBint chgat(int n, attr_t attr, short color,\fR \fBconst void *opts)\fR diff --git a/lib/libcurses/curs_kernel.3 b/lib/libcurses/curs_kernel.3 index 9e748741aab..32affd776c9 100644 --- a/lib/libcurses/curs_kernel.3 +++ b/lib/libcurses/curs_kernel.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: curs_kernel.3,v 1.7 1998/09/13 19:16:20 millert Exp $ +.\" $OpenBSD: curs_kernel.3,v 1.8 2000/03/10 01:35:01 millert Exp $ .\" .\"*************************************************************************** .\" Copyright (c) 1998 Free Software Foundation, Inc. * @@ -28,7 +28,7 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_kernel.3x,v 1.11 1998/06/27 21:56:38 tom Exp $ +.\" $From: curs_kernel.3x,v 1.12 2000/02/27 01:37:46 tom Exp $ .TH curs_kernel 3 "" .SH NAME \fBdef_prog_mode\fR, \fBdef_shell_mode\fR, @@ -136,6 +136,13 @@ the variables \fIy\fR and \fIx\fR. Older SVr4 man pages warn that the return value of \fBcurs_set\fR "is currently incorrect". This implementation gets it right, but it may be unwise to count on the correctness of the return value anywhere else. + +Both ncurses and SVr4 will call \fBcurs_set\fR in \fBendwin\fR +if \fBcurs_set\fR +has been called to make the cursor other than normal, i.e., either +visible or very visible. +There is no way for ncurses to determine the initial cursor state to +restore that. .SH PORTABILITY The functions \fBsetsyx\fR and \fBgetsyx\fR are not described in the XSI Curses standard, Issue 4. All other functions are as described in XSI Curses. diff --git a/lib/libcurses/curs_outopts.3 b/lib/libcurses/curs_outopts.3 index b164824f51b..ef68dd1ecb8 100644 --- a/lib/libcurses/curs_outopts.3 +++ b/lib/libcurses/curs_outopts.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: curs_outopts.3,v 1.7 1999/01/18 19:07:14 millert Exp $ +.\" $OpenBSD: curs_outopts.3,v 1.8 2000/03/10 01:35:01 millert Exp $ .\" .\"*************************************************************************** .\" Copyright (c) 1998 Free Software Foundation, Inc. * @@ -28,7 +28,7 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_outopts.3x,v 1.13 1998/12/26 20:02:04 tom Exp $ +.\" $From: curs_outopts.3x,v 1.14 2000/02/27 01:41:58 tom Exp $ .TH curs_outopts 3 "" .SH NAME \fBclearok\fR, \fBidlok\fR, \fBidcok immedok\fR, @@ -153,6 +153,7 @@ time. The XSI Curses standard does not mention that the cursor should be made invisible as a side-effect of \fBleaveok\fR. SVr4 curses documentation does this, but the code does not. +Use \fBcurs_set\fR to make the cursor invisible. .SH NOTES Note that \fBclearok\fR, \fBleaveok\fR, \fBscrollok\fR, \fBidcok\fR, \fBnl\fR, \fBnonl\fR and \fBsetscrreg\fR may be macros. diff --git a/lib/libcurses/curses.h b/lib/libcurses/curses.h index f00fe3a543a..8bac7690346 100644 --- a/lib/libcurses/curses.h +++ b/lib/libcurses/curses.h @@ -1,7 +1,7 @@ -/* $OpenBSD: curses.h,v 1.46 2000/02/06 07:10:50 millert Exp $ */ +/* $OpenBSD: curses.h,v 1.47 2000/03/10 01:35:01 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,7 @@ * and: Eric S. Raymond * ****************************************************************************/ -/* $From: curses.h.in,v 1.89 2000/01/09 01:10:20 tom Exp $ */ +/* $From: curses.h.in,v 1.90 2000/02/19 22:15:43 tom Exp $ */ #ifndef __NCURSES_H #define __NCURSES_H @@ -50,7 +50,7 @@ /* These are defined only in curses.h, and are used for conditional compiles */ #define NCURSES_VERSION_MAJOR 5 #define NCURSES_VERSION_MINOR 0 -#define NCURSES_VERSION_PATCH 20000129 +#define NCURSES_VERSION_PATCH 20000304 /* This is defined in more than one ncurses header, for identification */ #undef NCURSES_VERSION diff --git a/lib/libcurses/curses.priv.h b/lib/libcurses/curses.priv.h index afd0aedefe6..e65f9172291 100644 --- a/lib/libcurses/curses.priv.h +++ b/lib/libcurses/curses.priv.h @@ -1,7 +1,7 @@ -/* $OpenBSD: curses.priv.h,v 1.24 2000/02/06 07:10:50 millert Exp $ */ +/* $OpenBSD: curses.priv.h,v 1.25 2000/03/10 01:35:01 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 * @@ -35,7 +35,7 @@ /* - * $From: curses.priv.h,v 1.151 2000/02/06 01:57:01 tom Exp $ + * $From: curses.priv.h,v 1.153 2000/02/19 23:31:39 tom Exp $ * * curses.priv.h * @@ -621,15 +621,6 @@ extern const char *_nc_visbuf2(int, const char *); vidattr(AttrOf(c)) #endif -/* - * Check whether the given character can be output by clearing commands. This - * includes test for being a space and not including any 'bad' attributes, such - * as A_REVERSE. All attribute flags which don't affect appearance of a space - * or can be output by clearing (A_COLOR in case of bce-terminal) are excluded. - */ -#define can_clear_with(ch) \ - ((ch & ~(NONBLANK_ATTR|(back_color_erase ? A_COLOR:0))) == BLANK) - #ifdef NCURSES_EXPANDED #undef toggle_attr_on @@ -640,10 +631,6 @@ extern void _nc_toggle_attr_on(attr_t *, attr_t); #define toggle_attr_off(S,at) _nc_toggle_attr_off(&(S), at) extern void _nc_toggle_attr_off(attr_t *, attr_t); -#undef can_clear_with -#define can_clear_with(ch) _nc_can_clear_with(ch) -extern int _nc_can_clear_with(chtype); - #undef DelCharCost #define DelCharCost(count) _nc_DelCharCost(count) extern int _nc_DelCharCost(int); diff --git a/lib/libcurses/dft_fgbg.3 b/lib/libcurses/dft_fgbg.3 index 5795ddf26ca..03f0859b347 100644 --- a/lib/libcurses/dft_fgbg.3 +++ b/lib/libcurses/dft_fgbg.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: dft_fgbg.3,v 1.4 1999/11/28 17:53:40 millert Exp $ +.\" $OpenBSD: dft_fgbg.3,v 1.5 2000/03/10 01:35:01 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 * @@ -30,7 +30,7 @@ .\" .\" Author: Thomas E. Dickey 1997,1999 .\" -.\" $From: dft_fgbg.3x,v 1.7 1999/11/14 00:51:50 tom Exp $ +.\" $From: dft_fgbg.3x,v 1.9 2000/02/13 02:28:39 tom Exp $ .TH use_default_colors 3 "" .SH NAME \fBdft_fgbg\fR \- use terminal's default colors @@ -51,7 +51,6 @@ functions are extensions to the curses library. They are used with terminals that support ISO 6429 color, or equivalent. These terminals allow the application to reset color to an unspecified default value (e.g., with SGR 39 or SGR 49). -XSI Curses assumes the default colors are white on black. .PP Applications that paint a colored background over the whole screen do not take advantage of SGR 39 and SGR 49. @@ -59,12 +58,14 @@ Some applications are designed to work with the default background. .PP The first function, .I use_default_colors() -tells the curses library to use the terminal's -\fIorig_pair\fP or \fIorig_colors\fP capability when setting color pair 0. +tells the curses library to assign terminal default +foreground/background colors to color number -1. So init_pair(x,COLOR_RED,-1) +will initialize pair x as red on default background and init_pair(x,-1,COLOR_BLUE) will +initialize pair x as default foreground on blue. .PP The other, .I assume_default_colors() -is a refinement which tells which colors to assume are set for color pair 0. +is a refinement which tells which colors to paint for color pair 0, and -1 means default terminal color. The following are equivalent: .RS .br @@ -73,11 +74,9 @@ The following are equivalent: .I assume_default_colors(-1,-1); .RE .PP -Do this: -.RS -.I assume_default_colors(COLOR_WHITE,COLOR_BLACK); -.RE -to disable default colors. +This is a ncurses extension and for other curses implementations color +number -1 does not mean anything, just as for ncurses before a +successful call of use_default_colors or assume_default_colors. .. .SH RETURN VALUE These functions return the integer \fBERR\fP upon failure and \fBOK\fP on success. diff --git a/lib/libcurses/doc/hackguide.html b/lib/libcurses/doc/hackguide.html index f2e08f16e87..f2c6d0a9cd4 100644 --- a/lib/libcurses/doc/hackguide.html +++ b/lib/libcurses/doc/hackguide.html @@ -1,6 +1,6 @@ @@ -19,18 +19,14 @@ this one.

Contents

@@ -60,24 +53,21 @@ This document is a hacker's tour of the ncurses library and uti It discusses design philosophy, implementation methods, and the conventions used for coding and documentation. It is recommended reading for anyone who is interested in porting, extending or improving the -package.

+package.

Objective of the Package

The objective of the ncurses package is to provide a free software API for character-cell terminals and terminal emulators with the following -characteristics:

+characteristics:

  • Source-compatible with historical curses implementations (including the original BSD curses and System V curses. -

  • Conformant with the XSI Curses standard issued as part of XPG4 by X/Open. -

  • High-quality -- stable and reliable code, wide portability, good packaging, superior documentation. -

  • Featureful -- should eliminate as much of the drudgery of C interface programming as possible, freeing programmers to think at a higher level of design. @@ -86,7 +76,7 @@ characteristics:

    These objectives are in priority order. So, for example, source compatibility with older version must trump featurefulness -- we cannot add features if it means breaking the portion of the API corresponding -to historical curses versions.

    +to historical curses versions.

    Why System V Curses?

    @@ -99,7 +89,7 @@ capture BSD's.

    More importantly for the future, the XSI Curses standard issued by X/Open is explicitly and closely modeled on System V. So conformance with -System V took us most of the way to base-level XSI conformance.

    +System V took us most of the way to base-level XSI conformance.

    How to Design Extensions

    @@ -113,7 +103,7 @@ in or out the code that requires the ncurses extension.

    For example, there is a macro NCURSES_MOUSE_VERSION which XSI Curses does not define, but which is defined in the ncurses library header. -You can use this to condition the calls to the mouse API calls.

    +You can use this to condition the calls to the mouse API calls.

    Portability and Configuration

    @@ -125,12 +115,11 @@ We encourage (but do not require) developers to make the code friendly to less-capable UNIX environments wherever possible.

    We encourage developers to support OS-specific optimizations and methods -not available under POSIX/ANSI, provided only that:

    +not available under POSIX/ANSI, provided only that:

    • All such code is properly conditioned so the build process does not attempt to compile it under a plain ANSI/POSIX environment. -

    • Adding such implementation methods does not introduce incompatibilities in the ncurses API between platforms.
    @@ -138,12 +127,12 @@ not available under POSIX/ANSI, provided only that:

    We use GNU autoconf(1) as a tool to deal with portability issues. The right way to leverage an OS-specific feature is to modify the autoconf specification files (configure.in and aclocal.m4) to set up a new feature -macro, which you then use to condition your code.

    +macro, which you then use to condition your code.

    Documentation Conventions

    There are three kinds of documentation associated with this package. Each -has a different preferred format:

    +has a different preferred format:

    • Package-internal files (README, INSTALL, TO-DO etc.) @@ -151,14 +140,14 @@ has a different preferred format:

    • Everything else (i.e., narrative documentation).
    -Our conventions are simple:

    +Our conventions are simple:

    1. Maintain package-internal files in plain text. The expected viewer for them more(1) or an editor window; there's - no point in elaborate mark-up.

      + no point in elaborate mark-up.

    2. Mark up manual pages in the man macros. These have to be viewable - through traditional man(1) programs.

      + through traditional man(1) programs.

    3. Write everything else in HTML.
    @@ -171,7 +160,7 @@ browsing through viewers that are everywhere; (b) more easily readable as plain text than most other mark-ups, if you don't have a viewer; and (c) carries enough information that you can generate a nice-looking printed version from it. Also, of course, it make exporting things like the -announcement document to WWW pretty trivial.

    +announcement document to WWW pretty trivial.

    How to Report Bugs

    @@ -193,17 +182,17 @@ before contacting us that will help get the bug fixed quickly.

    In order to use our bug-fixing time efficiently, we put people who show us they've taken these steps at the head of our queue. This means that if you don't, you'll probably end up at the tail end and -have to wait a while.

    +have to wait a while.

      -
    1. Develop a recipe to reproduce the bug.

      +

    2. Develop a recipe to reproduce the bug. Bugs we can reproduce are likely to be fixed very quickly, often within days. The most effective single thing you can do to get a quick fix is develop a way we can duplicate the bad behavior -- ideally, by giving us source for a small, portable test program that breaks the library. (Even better is a keystroke recipe using one of -the test programs provided with the distribution.)

      +the test programs provided with the distribution.)

    3. Try to reproduce the bug on a different terminal type.

      @@ -221,7 +210,7 @@ bug reproduces on both.

      If you have xterm available, it is also good to collect xterm reports for different window sizes. This is especially true if you normally use an unusual xterm window size -- a surprising number of the bugs we've seen -are either triggered or masked by these.

      +are either triggered or masked by these.

    4. Generate and examine a trace file for the broken behavior.

      @@ -248,7 +237,7 @@ through.

      Often you'll find terminfo problems at this stage by noticing that the escape sequences put out for various capabilities are wrong. If not, you're likely to learn enough to be able to characterize any bug in -the screen-update logic quite exactly.

      +the screen-update logic quite exactly.

    5. Report details and symptoms, not just interpretations.

      @@ -299,7 +288,7 @@ with hardscroll.

      There's one other interactive tester, tctest, that exercises translation between termcap and terminfo formats. If you have a serious -need to run this, you probably belong on our development team!

      +need to run this, you probably belong on our development team!

      A Tour of the Ncurses Library

      @@ -376,7 +365,8 @@ unlikely to need change, barring bugs or some fundamental reorganization in the underlying data structures.

      These files are used only for debugging support: -

      +
      + lib_trace.c lib_traceatr.c lib_tracebits.c @@ -384,7 +374,8 @@ lib_tracechr.c lib_tracedmp.c lib_tracemse.c trace_buf.c -
      +
      +
      It is rather unlikely you will ever need to change these, unless you want to introduce a new debug trace level for some reasoon.

      @@ -392,7 +383,8 @@ There is another group of files that do direct I/O via tputs(), computations on the terminal capabilities, or queries to the OS environment, but nevertheless have only fairly low complexity. These include: -

      +
      + lib_acs.c lib_beep.c lib_color.c @@ -407,7 +399,8 @@ lib_tparm.c lib_tputs.c lib_vidattr.c read_entry.c. -
      +
      +
      They are likely to need revision only if ncurses is being ported to an environment without an underlying terminfo capability representation.

      @@ -415,13 +408,15 @@ terminfo capability representation.

      These files have serious hooks into the tty driver and signal facilities: -

      +
      + lib_kernel.c lib_baudrate.c lib_raw.c lib_tstp.c lib_twait.c -
      +
      +
      If you run into porting snafus moving the package to another UNIX, the problem is likely to be in one of these files. @@ -429,7 +424,8 @@ The file lib_print.c uses sleep(2) and also falls in this category.

      Almost all of the real work is done in the files -

      +
      + hardscroll.c hashmap.c lib_addch.c @@ -440,7 +436,8 @@ lib_mvcur.c lib_refresh.c lib_setup.c lib_vidattr.c -
      +
      +
      Most of the algorithmic complexity in the library lives in these files. If there is a real bug in ncurses itself, it's probably here. @@ -450,7 +447,8 @@ below (see The Engine Room).

      Finally, there is a group of files that is actually most of the terminfo compiler. The reason this code lives in the ncurses library is to support fallback to /etc/termcap. These files include -

      +
      + alloc_entry.c captoinfo.c comp_captab.c @@ -461,8 +459,9 @@ comp_scan.c parse_entry.c read_termcap.c write_entry.c -
      -We'll discuss these in the compiler tour.

      + +

      +We'll discuss these in the compiler tour.

      The Engine Room

      @@ -487,7 +486,7 @@ Hackers bruised by previous encounters with variant select(2) calls may find the code in lib_twait.c interesting. It deals with the problem that some BSD selects don't return a reliable time-left value. The function timed_wait() effectively -simulates a System V select.

      +simulates a System V select.

      Mouse Events

      @@ -526,7 +525,7 @@ to queue up a series of adjacent mouse reports.

      In either case, _nc_mouse_parse() should be called after the series is accepted to parse the digested mouse reports (low-level -events) into a gesture (a high-level or composite event).

      +events) into a gesture (a high-level or composite event).

      Output and Screen Updating

      @@ -571,7 +570,7 @@ optimization improves efficiency.

      In the trace-enabled version of the library, it is also possible to disable and re-enable various optimizations at runtime by tweaking the variable _nc_optimize_enable. See the file include/curses.h.in -for mask values, near the end.

      +for mask values, near the end.

      The Forms and Menu Libraries

      @@ -586,7 +585,7 @@ System V's, but will settle for BSD regexps if the former isn't available.

      Historical note: the panels code was written primarily to assist in porting u386mon 2.0 (comp.sources.misc v14i001-4) to systems lacking panels support; u386mon 2.10 and beyond use it. This version has been -slightly cleaned up for ncurses.

      +slightly cleaned up for ncurses.

      A Tour of the Terminfo Compiler

      @@ -601,7 +600,7 @@ lexical analyzer (in comp_scan.c). The lexer chooses its mode (termcap or terminfo) based on the first `,' or `:' it finds in each entry. The lexer does all the work of recognizing capability names and values; the grammar above it is trivial, just "parse entries -till you run out of file".

      +till you run out of file".

      Translation of Non-use Capabilities

      @@ -622,7 +621,7 @@ organization is that the hash table can be in shareable text space).

      Thus, adding a new capability is usually pretty trivial, just a matter of adding one line to the include/Caps file. We'll have more to say about this in the section on Source-Form -Translation.

      +Translation.

      Use Capability Resolution

      @@ -672,7 +671,7 @@ Name collisions will still be detected, just not as cleanly. The postdates the time of tic's first call to write_entry(), Thus it will complain about overwriting entries newly made during the tic run, but not about -overwriting ones that predate it.

      +overwriting ones that predate it.

      Source-Form Translation

      @@ -697,7 +696,7 @@ For circumstances where you need to do algorithmic translation, there are functions in parse_entry.c called after the parse of each entry that are specifically intended to encapsulate such translations. This, for example, is where the AIX box1 capability -get translated to an acsc string.

      +get translated to an acsc string.

      Other Utilities

      @@ -709,7 +708,7 @@ capabilities are dumped. This is necessary in order to handle both the ordinary De-compilation case and entry difference reporting.

      The tput and clear utilities just do an entry load -followed by a tputs() of a selected capability.

      +followed by a tputs() of a selected capability.

      Style Tips for Developers

      @@ -739,7 +738,7 @@ data in that file in order to generate the proper table, that's still preferable to ad-hoc code -- that's why the fifth field (flags) is there.

      -Have fun!

      +Have fun!

      Porting Hints

      @@ -751,9 +750,10 @@ the curses internal structures, do all output through other curses calls (not including tputs() and putp()) and do not call any other UNIX routines such as signal(2) or the stdio library. Thus, they should not need to be modified for single-terminal -ports.

      +ports. -

      +
      + lib_addch.c lib_addstr.c lib_bkgd.c @@ -786,39 +786,45 @@ lib_tputs.c lib_unctrl.c lib_window.c panel.c -
      +
      +

      -This module is pure curses, but calls outstr():

      +This module is pure curses, but calls outstr(): -

      +
      + lib_getstr.c -
      +
      +

      These modules are pure curses, except that they use tputs() -and putp():

      +and putp(): -

      +
      + lib_beep.c lib_color.c lib_endwin.c lib_options.c lib_slk.c lib_vidattr.c -
      +
      +

      -This modules assist in POSIX emulation on non-POSIX systems:

      +This modules assist in POSIX emulation on non-POSIX systems:

      sigaction.c
      signal calls
      The following source files will not be needed for a -single-terminal-type port.

      +single-terminal-type port. -

      +
      + alloc_entry.c captoinfo.c clear.c @@ -834,11 +840,12 @@ parse_entry.c read_entry.c tput.c write_entry.c -
      +
      +

      The following modules will use open()/read()/write()/close()/lseek() on files, -but no other OS calls.

      +but no other OS calls.

      lib_screen.c @@ -850,7 +857,7 @@ but no other OS calls.

      Modules that would have to be modified for a port start here:

      The following modules are `pure curses' but contain assumptions inappropriate -for a memory-mapped port.

      +for a memory-mapped port.

      lib_longname.c
      assumes there may be multiple terminals diff --git a/lib/libcurses/doc/ncurses-intro.html b/lib/libcurses/doc/ncurses-intro.html index 9505f819329..12975986fc4 100644 --- a/lib/libcurses/doc/ncurses-intro.html +++ b/lib/libcurses/doc/ncurses-intro.html @@ -1,6 +1,6 @@ @@ -169,7 +169,7 @@ API has the advantage of (a) back-portability to character-cell terminals, and (b) simplicity. For an application that does not require bit-mapped graphics and multiple fonts, an interface implementation using curses will typically be a great deal simpler and less expensive than one using an -X toolkit.

      +X toolkit.

      A Brief History of Curses

      @@ -186,19 +186,19 @@ extensions. Parameterized capabilities strings were introduced, making it possible to describe multiple video attributes, and colors and to handle far more unusual terminals than possible with termcap. In the later AT&T System V releases, curses evolved to use more facilities and offer -more capabilities, going far beyond BSD curses in power and flexibility.

      +more capabilities, going far beyond BSD curses in power and flexibility.

      Scope of This Document

      This document describes ncurses, a free implementation of the System V curses API with some clearly marked extensions. -It includes the following System V curses features:

      +It includes the following System V curses features:

      • Support for multiple screen highlights (BSD curses could only -handle one `standout' highlight, usually reverse-video).

        -

      • Support for line- and box-drawing using forms characters.

        -

      • Recognition of function keys on input.

        -

      • Color support.

        +handle one `standout' highlight, usually reverse-video). +

      • Support for line- and box-drawing using forms characters. +
      • Recognition of function keys on input. +
      • Color support.
      • Support for pads (windows of larger than screen size on which the screen or a subwindow defines a viewport).
      @@ -244,7 +244,7 @@ their visibility in the natural way (handling window overlaps).

      Finally, this document describes in detail the menus and forms extension libraries, also cloned from System V, which support easy construction and sequences of menus and fill-in -forms.

      +forms.

      Terminology

      @@ -257,12 +257,12 @@ consistency:
      A data structure describing a sub-rectangle of the screen (possibly the entire screen). You can write to a window as though it were a miniature -screen, scrolling independently of other windows on the physical screen.

      +screen, scrolling independently of other windows on the physical screen.

      screens
      A subset of windows which are as large as the terminal screen, i.e., they start at the upper left hand corner and encompass the lower right hand corner. One -of these, stdscr, is automatically provided for the programmer.

      +of these, stdscr, is automatically provided for the programmer.

      terminal screen
      The package's idea of what the terminal display currently looks like, i.e., @@ -316,7 +316,7 @@ A given physical screen section may be within the scope of any number of overlapping windows. Also, changes can be made to windows in any order, without regard to motion efficiency. Then, at will, the programmer can effectively say ``make it look like this,'' and let the package implementation -determine the most efficient way to repaint the screen.

      +determine the most efficient way to repaint the screen.

      Standard Windows and Function Naming Conventions

      @@ -368,7 +368,7 @@ can be replaced by Note that the window description pointer (win) comes before the added (y, x) coordinates. If a function requires a window pointer, it is always the first -parameter passed.

      +parameter passed.

      Variables

      @@ -405,7 +405,7 @@ updating, reading, etc. is applied to stdscr. These instructions w work on any window, providing you change the function names and parameters as mentioned above.

      -Here is a sample program to motivate the discussion:

      +Here is a sample program to motivate the discussion:

       #include <curses.h>
      @@ -413,8 +413,11 @@ Here is a sample program to motivate the discussion: 

      static void finish(int sig); +int main(int argc, char *argv[]) { + int num = 0; + /* initialize your non-curses data structures here */ (void) signal(SIGINT, finish); /* arrange interrupts to terminate */ @@ -423,28 +426,32 @@ main(int argc, char *argv[]) keypad(stdscr, TRUE); /* enable keyboard mapping */ (void) nonl(); /* tell curses not to do NL->CR/NL on output */ (void) cbreak(); /* take input chars one at a time, no wait for \n */ - (void) noecho(); /* don't echo input */ + (void) echo(); /* echo input - in color */ if (has_colors()) { start_color(); /* - * Simple color assignment, often all we need. + * Simple color assignment, often all we need. Color pair 0 cannot + * be redefined. This example uses the same value for the color + * pair as for the foreground color, though of course that is not + * necessary: */ - init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); - init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK); - init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK); - init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK); - init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); - init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); - init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); - init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); + init_pair(1, COLOR_RED, COLOR_BLACK); + init_pair(2, COLOR_GREEN, COLOR_BLACK); + init_pair(3, COLOR_YELLOW, COLOR_BLACK); + init_pair(4, COLOR_BLUE, COLOR_BLACK); + init_pair(5, COLOR_CYAN, COLOR_BLACK); + init_pair(6, COLOR_MAGENTA, COLOR_BLACK); + init_pair(7, COLOR_WHITE, COLOR_BLACK); } for (;;) { int c = getch(); /* refresh, accept single keystroke of input */ + attrset(COLOR_PAIR(num % 8)); + num++; /* process the command keystroke */ } @@ -487,7 +494,7 @@ coordinates after updating it.

      You can create new windows of your own using the functions newwin(), derwin(), and subwin(). The routine delwin() will allow you to get rid of old windows. All the options described above can be -applied to any window.

      +applied to any window.

      Output

      @@ -515,7 +522,7 @@ to make it look like the entire window has been changed, thus making If you call wrefresh() with curscr as its argument, it will make the screen look like curscr thinks it looks like. This is useful for implementing a command which would redraw the screen in case it get messed -up.

      +up.

      Input

      @@ -539,7 +546,7 @@ watches the input stream for character sequences that correspond to arrow and function keys. These sequences are returned as pseudo-character values. The #define values returned are listed in the curses.h The mapping from sequences to #define values is determined by -key_ capabilities in the terminal's terminfo entry.

      +key_ capabilities in the terminal's terminfo entry.

      Using Forms Characters

      @@ -552,7 +559,7 @@ the prefix ACS_).

      The most useful of the ACS defines are the forms-drawing characters. You can use these to draw boxes and simple graphs on the screen. If the terminal does not have such characters, curses.h will map them to a -recognizable (though ugly) set of ASCII defaults.

      +recognizable (though ugly) set of ASCII defaults.

      Character Attributes and Color

      @@ -584,7 +591,7 @@ have been used as the first arguments of the init_pair() values.

      init_pair() that creates color-pair N, you can use COLOR_PAIR(N) as a highlight that invokes that particular color combination. Note that COLOR_PAIR(N), for constant N, -is itself a compile-time constant and can be used in initializers.

      +is itself a compile-time constant and can be used in initializers.

      Mouse Interfacing

      @@ -657,7 +664,7 @@ would normally accept from the keyboard. Two of the test games in the code that illustrates how this can be done.

      See the manual page curs_mouse(3X) for full details of the -mouse-interface functions.

      +mouse-interface functions.

      Finishing Up

      @@ -665,7 +672,7 @@ In order to clean up after the ncurses routines, the routine endwin() is provided. It restores tty modes to what they were when initscr() was first called, and moves the cursor down to the lower-left corner. Thus, anytime after the call to initscr, endwin() -should be called before exiting.

      +should be called before exiting.

      Function Descriptions

      @@ -684,14 +691,14 @@ occurs a message is written to standard error and the program exits. Otherwise it returns a pointer to stdscr. A few functions may be called before initscr (slk_init(), filter(), ripofflines(), use_env(), and, if you are using multiple -terminals, newterm().)

      +terminals, newterm().)

      endwin()
      Your program should always call endwin() before exiting or shelling out of the program. This function will restore tty modes, move the cursor to the lower left corner of the screen, reset the terminal into the proper non-visual mode. Calling refresh() or doupdate() after a temporary escape from the program will -restore the ncurses screen from before the escape.

      +restore the ncurses screen from before the escape.

      newterm(type, ofp, ifp)
      A program which outputs to more than one terminal should use newterm() instead of initscr(). newterm() should @@ -701,12 +708,12 @@ terminal. The arguments are the type of the terminal (a string) and FILE pointers for the output and input of the terminal. If type is NULL then the environment variable $TERM is used. endwin() should called once at wrapup time for each terminal -opened using this function.

      +opened using this function.

      set_term(new)
      This function is used to switch to a different terminal previously opened by newterm(). The screen reference for the new terminal is passed as the parameter. The previous terminal is returned by the -function. All other calls affect only the current terminal.

      +function. All other calls affect only the current terminal.

      delscreen(sp)
      The inverse of newterm(); deallocates the data structures associated with a given SCREEN reference. @@ -723,7 +730,7 @@ terminal screen, taking into account what is already there in order to do optimizations. refresh() does a refresh of stdscr(). Unless leaveok() has been enabled, the physical cursor of the terminal is left at the -location of the window's cursor.

      +location of the window's cursor.

      doupdate() and wnoutrefresh(win)
      These two functions allow multiple updates with more efficiency than wrefresh. To use them, it is important to understand how curses @@ -805,13 +812,13 @@ data dumped in them. There is a script called tracemunch included with the ncurses distribution that can alleviate this problem somewhat; it compacts long sequences of similar operations into more succinct single-line pseudo-operations. These pseudo-ops can be -distinguished by the fact that they are named in capital letters.

      +distinguished by the fact that they are named in capital letters.

      Hints, Tips, and Tricks

      The ncurses manual pages are a complete reference for this library. In the remainder of this document, we discuss various useful methods that -may not be obvious from the manual page descriptions.

      +may not be obvious from the manual page descriptions.

      Some Notes of Caution

      @@ -846,7 +853,7 @@ overlapping-windows facilities.

      Try to avoid using the global variables LINES and COLS. Use getmaxyx() on the stdscr context instead. Reason: your code may be ported to run in an environment with window resizes, -in which case several screens could be open with different sizes.

      +in which case several screens could be open with different sizes.

      Temporarily Leaving NCURSES Mode

      @@ -912,7 +919,7 @@ For each call, you will have to specify a terminal type and a pair of file pointers; each call will return a screen reference, and stdscr will be set to the last one allocated. You will switch between screens with the set_term call. Note that you will also have to call -def_shell_mode and def_prog_mode on each tty yourself.

      +def_shell_mode and def_prog_mode on each tty yourself.

      Testing for Terminal Capabilities

      @@ -927,14 +934,14 @@ test whether a given terminal type should be treated as `smart' (cursor-addressable) or `stupid'. The right way to test this is to see if the return value of tigetstr("cup") is non-NULL. Alternatively, you can include the term.h file and test the value of the -macro cursor_address.

      +macro cursor_address.

      Tuning for Speed

      Use the addchstr() family of functions for fast screen-painting of text when you know the text doesn't contain any control characters. Try to make attribute changes infrequent on your -screens. Don't use the immedok() option!

      +screens. Don't use the immedok() option!

      Special Features of NCURSES

      @@ -1012,7 +1019,7 @@ when you want a screen update, you do update_panels(), it will do all the necessary wnoutrfresh() calls for whatever panel stacking order you have defined. Then you can do one doupdate() and there will be a single burst of physical I/O that will do -all your updates.

      +all your updates.

      Background Erase

      @@ -1027,7 +1034,7 @@ is normal unless and until it is modified by the functions bkgdset()wbkgdset().

      This change in behavior conforms ncurses to System V Release 4 and -the XSI Curses standard.

      +the XSI Curses standard.

      XSI Curses Conformance

      @@ -1042,7 +1049,7 @@ One effect of XSI conformance is the change in behavior described under Also, ncurses meets the XSI requirement that every macro entry point have a corresponding function which may be linked (and will be prototype-checked) if the macro definition is disabled with -#undef.

      +#undef.

      The Panels Library

      @@ -1119,7 +1126,7 @@ Typically, you will want to call update_panels() and doupdate() just before accepting command input, once in each cycle of interaction with the user. If you call update_panels() after each and every panel write, you'll generate a lot of unnecessary refresh -activity and screen flicker.

      +activity and screen flicker.

      Panels, Input, and the Standard Screen

      @@ -1137,7 +1144,7 @@ Therefore, before requesting input from a panel window, you need to be sure that the panel is totally unobscured.

      There is presently no way to display changes to one obscured panel without -repainting all panels.

      +repainting all panels.

      Hiding Panels

      @@ -1148,7 +1155,7 @@ tests whether or not a panel is hidden.

      The panel_update code ignores hidden panels. You cannot do top_panel() or bottom_panel on a hidden panel(). -Other panels operations are applicable.

      +Other panels operations are applicable.

      Miscellaneous Other Facilities

      @@ -1160,7 +1167,7 @@ pointer, they return the panel above or below that panel. Handed Every panel has an associated user pointer, not used by the panel code, to which you can attach application data. See the man page documentation of set_panel_userptr() and panel_userptr for -details.

      +details.

      The Menu Library

      @@ -1171,7 +1178,7 @@ uniform but flexible interface.

      The menu library first appeared in AT&T System V. The version documented here is the menu code distributed -with ncurses.

      +with ncurses.

      Compiling With the menu Library

      @@ -1235,12 +1242,12 @@ predicate function. Your menu-processing code can use the function Menu items can be made unselectable using set_item_opts() or item_opts_off() with the O_SELECTABLE argument. This is the only option so far defined for menus, but it -is good practice to code as though other option bits might be on.

      +is good practice to code as though other option bits might be on.

      Menu Display

      The menu library calculates a minimum display size for your window, based -on the following variables:

      +on the following variables:

      • The number and maximum length of the menu items @@ -1280,7 +1287,7 @@ There are other menu display attributes including a select attribute, an attribute for selectable items, an attribute for unselectable items, and a pad character used to separate item name text from description text. These have reasonable defaults which the library allows you to -change (see the menu_attribs(3x) manual page.

        +change (see the menu_attribs(3x) manual page.

        Menu Windows

        @@ -1300,7 +1307,7 @@ functions in menu_win(3x).

        When you call menu_post(), you write the menu to its subwindow. When you call menu_unpost(), you erase the subwindow, However, neither of these actually modifies the screen. To -do that, call wrefresh() or some equivalent.

        +do that, call wrefresh() or some equivalent.

        Processing Menu Input

        @@ -1372,7 +1379,7 @@ wrapup time, and whenever the selected item changes. See Each item, and each menu, has an associated user pointer on which you can hang application data. See mitem_userptr(3x) and -menu_userptr(3x).

        +menu_userptr(3x).

        The Forms Library

        @@ -1381,7 +1388,7 @@ programming of on-screen forms for data entry and program control.

        The form library first appeared in AT&T System V. The version documented here is the form code distributed -with ncurses.

        +with ncurses.

        Compiling With the form Library

        @@ -1395,7 +1402,7 @@ and must be linked explicitly with the forms library using an -lform argument. Note that they must also link the ncurses library with -lncurses. Many linkers are two-pass and will accept either order, but it is still good practice -to put -lform first and -lncurses second.

        +to put -lform first and -lncurses second.

        Overview of Forms

        @@ -1446,11 +1453,11 @@ wherever possible.

        In forms programs, however, the `process user requests' is somewhat more complicated than for menus. Besides menu-like navigation operations, -the menu driver loop has to support field editing and data validation.

        +the menu driver loop has to support field editing and data validation.

        Creating and Freeing Fields and Forms

        -The basic function for creating fields is new_field():

        +The basic function for creating fields is new_field():

         FIELD *new_field(int height, int width,   /* new field size */
        @@ -1482,7 +1489,7 @@ The forms library allocates one working buffer per field; the size of
         each buffer is ((height + offscreen)*width + 1, one character
         for each position in the field plus a NUL terminator.  The sixth
         argument is the number of additional data buffers to allocate for the
        -field; your application can use them for its own purposes. 

        +field; your application can use them for its own purposes.

         FIELD *dup_field(FIELD *field,            /* field to copy */
        @@ -1492,7 +1499,7 @@ FIELD *dup_field(FIELD *field,            /* field to copy */
         The function dup_field() duplicates an existing field at a
         new location.  Size and buffering information are copied; some
         attribute flags and status bits are not (see the
        -form_field_new(3X) for details). 

        +form_field_new(3X) for details).

         FIELD *link_field(FIELD *field,           /* field to copy */
        @@ -1516,7 +1523,7 @@ As you might guess, all these field-allocations return NULL if
         the field allocation is not possible due to an out-of-memory error or
         out-of-bounds arguments. 

        -To connect fields to a form, use

        +To connect fields to a form, use

         FORM *new_form(FIELD **fields);
        @@ -1534,7 +1541,7 @@ note that any given field may only be connected to one form. 

        The functions free_field() and free_form are available to free field and form objects. It is an error to attempt to free a field connected to a form, but not vice-versa; thus, you will generally free -your form objects first.

        +your form objects first.

        Fetching and Changing Field Attributes

        @@ -1549,11 +1556,11 @@ When a field is created, the attributes not specified by the new_field function are copied from an invisible system default field. In attribute-setting and -fetching functions, the argument NULL is taken to mean this field. Changes to it persist -as defaults until your forms application terminates.

        +as defaults until your forms application terminates.

        Fetching Size and Location Data

        -You can retrieve field sizes and locations through:

        +You can retrieve field sizes and locations through:

         int field_info(FIELD *field,              /* field from which to fetch */
        @@ -1565,11 +1572,11 @@ int field_info(FIELD *field,              /* field from which to fetch */
         
         This function is a sort of inverse of new_field(); instead of
         setting size and location attributes of a new field, it fetches them
        -from an existing one.  

        +from an existing one.

        Changing the Field Location

        -It is possible to move a field's location on the screen:

        +It is possible to move a field's location on the screen:

         int move_field(FIELD *field,              /* field to alter */
        @@ -1581,7 +1588,7 @@ You can, of course. query the current location through field_info()
         

        The Justification Attribute

        One-line fields may be unjustified, justified right, justified left, -or centered. Here is how you manipulate this attribute:

        +or centered. Here is how you manipulate this attribute:

         int set_field_just(FIELD *field,          /* field to alter */
        @@ -1592,7 +1599,7 @@ int field_just(FIELD *field);             /* fetch mode of field */
         
         The mode values accepted and returned by this functions are
         preprocessor macros NO_JUSTIFICATION, JUSTIFY_RIGHT,
        -JUSTIFY_LEFT, or JUSTIFY_CENTER. 

        +JUSTIFY_LEFT, or JUSTIFY_CENTER.

        Field Display Attributes

        @@ -1603,7 +1610,7 @@ control pagination of the form.

        This group of four field attributes controls the visual appearance of the field on the screen, without affecting in any way the data -in the field buffer.

        +in the field buffer.

         int set_field_fore(FIELD *field,          /* field to alter */
        @@ -1632,7 +1639,7 @@ The attributes set and returned by the first four functions are normal
         A_BOLD, A_REVERSE etc).
         
         The page bit of a field controls whether it is displayed at the start of
        -a new form screen. 

        +a new form screen.

        Field Option Bits

        @@ -1708,13 +1715,13 @@ A field's options cannot be changed while the field is currently selected. However, options may be changed on posted fields that are not current.

        The option values are bit-masks and can be composed with logical-or in -the obvious way.

        +the obvious way.

        Field Status

        Every field has a status flag, which is set to FALSE when the field is created and TRUE when the value in field buffer 0 changes. This flag can -be queried and set directly:

        +be queried and set directly:

         int set_field_status(FIELD *field,      /* field to alter */
        @@ -1736,7 +1743,7 @@ To guarantee that the returned status value reflects reality, call
         field_status() either (1) in the field's exit validation check
         routine, (2) from the field's or form's initialization or termination
         hooks, or (3) just after a REQ_VALIDATION request has been
        -processed by the forms driver. 

        +processed by the forms driver.

        Field User Pointer

        @@ -1757,7 +1764,7 @@ The (char *) type is retained for System V compatibility.)

        It is valid to set the user pointer of the default field (with a set_field_userptr() call passed a NULL field pointer.) When a new field is created, the default-field user pointer is copied -to initialize the new field's user pointer.

        +to initialize the new field's user pointer.

        Variable-Sized Fields

        @@ -1776,7 +1783,7 @@ dimensioned and located.

        Normally, a dynamic field is allowed to grow without limit. But it is possible to set an upper limit on the size of a dynamic field. You do -it with this function:

        +it with this function:

         int set_max_field(FIELD *field,     /* field to alter (may not be NULL) */
        @@ -1818,7 +1825,7 @@ is changed through a linked field. 

        The form library provides a rich set of pre-defined validation types, and gives you the capability to define custom ones of your own. You can examine and change field validation attributes with the following -functions:

        +functions:

         int set_field_type(FIELD *field,          /* field to alter */
        @@ -1833,12 +1840,12 @@ with other field attributes, Also, doing set_field_type() with a
         NULL field default will change the system default for validation of
         newly-created fields. 

        -Here are the pre-defined validation types:

        +Here are the pre-defined validation types:

        TYPE_ALPHA

        This field type accepts alphabetic data; no blanks, no digits, no special -characters (this is checked at character-entry time). It is set up with:

        +characters (this is checked at character-entry time). It is set up with:

         int set_field_type(FIELD *field,          /* field to alter */
        @@ -1849,12 +1856,12 @@ int set_field_type(FIELD *field,          /* field to alter */
         The width argument sets a minimum width of data.  Typically
         you'll want to set this to the field width; if it's greater than the
         field width, the validation check will always fail.  A minimum width
        -of zero makes field completion optional. 

        +of zero makes field completion optional.

        TYPE_ALNUM

        This field type accepts alphabetic data and digits; no blanks, no special -characters (this is checked at character-entry time). It is set up with:

        +characters (this is checked at character-entry time). It is set up with:

         int set_field_type(FIELD *field,          /* field to alter */
        @@ -1865,13 +1872,13 @@ int set_field_type(FIELD *field,          /* field to alter */
         The width argument sets a minimum width of data.  As with
         TYPE_ALPHA, typically you'll want to set this to the field width; if it's
         greater than the field width, the validation check will always fail.  A
        -minimum width of zero makes field completion optional. 

        +minimum width of zero makes field completion optional.

        TYPE_ENUM

        This type allows you to restrict a field's values to be among a specified set of string values (for example, the two-letter postal codes for U.S. -states). It is set up with:

        +states). It is set up with:

         int set_field_type(FIELD *field,          /* field to alter */
        @@ -1896,11 +1903,11 @@ value.  But the checkunique argument, if true, requires prefix
         matches to be unique in order to be valid. 

        The REQ_NEXT_CHOICE and REQ_PREV_CHOICE input requests -can be particularly useful with these fields.

        +can be particularly useful with these fields.

        TYPE_INTEGER

        -This field type accepts an integer. It is set up as follows:

        +This field type accepts an integer. It is set up as follows:

         int set_field_type(FIELD *field,          /* field to alter */
        @@ -1921,7 +1928,7 @@ with the C library function atoi(3).
         
         

        TYPE_NUMERIC

        -This field type accepts a decimal number. It is set up as follows:

        +This field type accepts a decimal number. It is set up as follows:

         int set_field_type(FIELD *field,              /* field to alter */
        @@ -1945,7 +1952,7 @@ with the C library function atof(3).
         

        TYPE_REGEXP

        This field type accepts data matching a regular expression. It is set up -as follows:

        +as follows:

         int set_field_type(FIELD *field,          /* field to alter */
        @@ -1960,7 +1967,7 @@ The check for regular-expression match is performed on exit.
         
         The chief attribute of a field is its buffer contents.  When a form has
         been completed, your application usually needs to know the state of each
        -field buffer.  You can find this out with: 

        +field buffer. You can find this out with:

         char *field_buffer(FIELD *field,          /* field to query */
        @@ -1993,7 +2000,7 @@ To guarantee that the returned buffer value reflects on-screen reality,
         call field_buffer() either (1) in the field's exit validation
         check routine, (2) from the field's or form's initialization or termination
         hooks, or (3) just after a REQ_VALIDATION request has been processed
        -by the forms driver. 

        +by the forms driver.

        Attributes of Forms

        @@ -2002,7 +2009,7 @@ system default form structure. These defaults can be queried or set by of these functions using a form-pointer argument of NULL.

        The principal attribute of a form is its field list. You can query -and change this list with:

        +and change this list with:

         int set_form_fields(FORM *form,           /* form to alter */
        @@ -2024,7 +2031,7 @@ It may also be null, in which case the old fields are disconnected
         
         The field_count() function simply counts the number of fields
         connected to a given from.  It returns -1 if the form-pointer argument
        -is NULL. 

        +is NULL.

        Control of Form Display

        @@ -2055,7 +2062,7 @@ is where the current form page is actually displayed.

        In order to declare your own frame window for a form, you'll need to know the size of the form's bounding rectangle. You can get this -information with:

        +information with:

         int scale_form(FORM *form,                /* form to query */
        @@ -2084,7 +2091,7 @@ should be done on the frame window, not the form subwindow. 

        It is possible to check from your application whether all of a scrollable field is actually displayed within the menu subwindow. Use -these functions:

        +these functions:

         int data_ahead(FORM *form);               /* form to be queried */
        @@ -2100,21 +2107,21 @@ The function data_behind() returns TRUE if the first (upper
         left hand) character position is off-screen (not being displayed). 

        Finally, there is a function to restore the form window's cursor to the -value expected by the forms driver:

        +value expected by the forms driver:

         int pos_form_cursor(FORM *)               /* form to be queried */
         
        If your application changes the form window cursor, call this function before -handing control back to the forms driver in order to re-synchronize it.

        +handing control back to the forms driver in order to re-synchronize it.

        Input Processing in the Forms Driver

        The function form_driver() handles virtualized input requests for form navigation, editing, and validation requests, just as menu_driver does for menus (see the section on menu input handling).

        +HREF="#minput">menu input handling).

         int form_driver(FORM *form,               /* form to pass input to */
        @@ -2127,12 +2134,12 @@ entered in the currently-selected field), or a forms processing request. 

        The forms driver provides hooks (through input-validation and field-termination functions) with which your application code can check -that the input taken by the driver matched what was expected.

        +that the input taken by the driver matched what was expected.

        Page Navigation Requests

        These requests cause page-level moves through the form, -triggering display of a new form screen.

        +triggering display of a new form screen.

        REQ_NEXT_PAGE @@ -2147,11 +2154,11 @@ triggering display of a new form screen.

        These requests treat the list as cyclic; that is, REQ_NEXT_PAGE from the last page goes to the first, and REQ_PREV_PAGE from -the first page goes to the last.

        +the first page goes to the last.

        Inter-Field Navigation Requests

        -These requests handle navigation between fields on the same page.

        +These requests handle navigation between fields on the same page.

        REQ_NEXT_FIELD @@ -2162,7 +2169,6 @@ These requests handle navigation between fields on the same page.

        Move to the first field.
        REQ_LAST_FIELD
        Move to the last field. -

        REQ_SNEXT_FIELD
        Move to sorted next field.
        REQ_SPREV_FIELD @@ -2171,7 +2177,6 @@ These requests handle navigation between fields on the same page.

        Move to the sorted first field.
        REQ_SLAST_FIELD
        Move to the sorted last field. -

        REQ_LEFT_FIELD
        Move left to field.
        REQ_RIGHT_FIELD @@ -2203,12 +2208,12 @@ For example, suppose you have a multi-line field B, and two single-line fields A and C on the same line with B, with A to the left of B and C to the right of B. A REQ_MOVE_RIGHT from A will go to B only if A, B, and C all share the same first line; -otherwise it will skip over B to C.

        +otherwise it will skip over B to C.

        Intra-Field Navigation Requests

        These requests drive movement of the edit cursor within the currently -selected field.

        +selected field.

        REQ_NEXT_CHAR @@ -2243,7 +2248,7 @@ selected field.

        Each word is separated from the previous and next characters by whitespace. The commands to move to beginning and end of line or field -look for the first or last non-pad character in their ranges.

        +look for the first or last non-pad character in their ranges.

        Scrolling Requests

        @@ -2253,7 +2258,6 @@ multi-line fields scroll vertically. Most scrolling is triggered by editing and intra-field movement (the library scrolls the field to keep the cursor visible). It is possible to explicitly request scrolling with the following requests: -

        REQ_SCR_FLINE @@ -2283,7 +2287,7 @@ following requests:
        For scrolling purposes, a page of a field is the height -of its visible part.

        +of its visible part.

        Editing Requests

        @@ -2293,7 +2297,7 @@ is an insertion or a replacement depends on the field's edit mode (insertion is the default.

        The following requests support editing the field and changing the edit -mode:

        +mode:

        REQ_INS_MODE @@ -2359,13 +2363,13 @@ treated as a REQ_PREV_FIELD.

        If the disabled and the forms driver just returns E_REQUEST_DENIED.

        See Form Options for discussion of how to set -and clear the overload options.

        +and clear the overload options.

        Order Requests

        If the type of your field is ordered, and has associated functions for getting the next and previous values of the type from a given value, -there are requests that can fetch that value into the field buffer:

        +there are requests that can fetch that value into the field buffer:

        REQ_NEXT_CHOICE @@ -2377,19 +2381,19 @@ there are requests that can fetch that value into the field buffer:

        Of the built-in field types, only TYPE_ENUM has built-in successor and predecessor functions. When you define a field type of your own (see Custom Validation Types), you can associate -our own ordering functions.

        +our own ordering functions.

        Application Commands

        Form requests are represented as integers above the curses value greater than KEY_MAX and less than or equal to the constant MAX_COMMAND. If your input-virtualization routine returns a -value above MAX_COMMAND, the forms driver will ignore it.

        +value above MAX_COMMAND, the forms driver will ignore it.

        Field Change Hooks

        It is possible to set function hooks to be executed whenever the -current field or form changes. Here are the functions that support this:

        +current field or form changes. Here are the functions that support this:

         typedef void	(*HOOK)();       /* pointer to function returning void */
        @@ -2418,7 +2422,7 @@ HOOK field_term(FORM *form);     /* form to query */
         These functions allow you to either set or query four different hooks.
         In each of the set functions, the second argument should be the
         address of a hook function.  These functions differ only in the timing
        -of the hook call. 

        +of the hook call.

        form_init @@ -2429,7 +2433,7 @@ each page change operation. each field change
        field_term
        This hook is called just after field validation; that is, just before -the field is altered. It is also called when the form is unposted.

        +the field is altered. It is also called when the form is unposted.

        form_term
        This hook is called when the form is unposted; also, just before each page change operation. @@ -2449,7 +2453,7 @@ You can set a default hook for all fields by passing one of the set functions a NULL first argument.

        You can disable any of these hooks by (re)setting them to NULL, the default -value.

        +value.

        Field Change Commands

        @@ -2457,7 +2461,7 @@ Normally, navigation through the form will be driven by the user's input requests. But sometimes it is useful to be able to move the focus for editing and viewing under control of your application, or ask which field it currently is in. The following functions help you -accomplish this:

        +accomplish this:

         int set_current_field(FORM *form,         /* form to alter */
        @@ -2476,7 +2480,7 @@ in the given form's field array (the array passed to new_form() or
         The initial current field of a form is the first active field on the
         first page. The function set_form_fields() resets this.

        -It is also possible to move around by pages.

        +It is also possible to move around by pages.

         int set_form_page(FORM *form,             /* form to alter */
        @@ -2486,12 +2490,12 @@ int form_page(FORM *form);                /* return form's current page */
         
        The initial page of a newly-created form is 0. The function -set_form_fields() resets this.

        +set_form_fields() resets this.

        Form Options

        Like fields, forms may have control option bits. They can be changed -or queried with these functions:

        +or queried with these functions:

         int set_form_opts(FORM *form,             /* form to alter */
        @@ -2521,7 +2525,7 @@ these have no last line, so the circumstances for triggering a
         
        The option values are bit-masks and can be composed with logical-or in -the obvious way.

        +the obvious way.

        Custom Validation Types

        @@ -2530,12 +2534,12 @@ validation types of your own. Further, the optional additional arguments of set_field_type effectively allow you to parameterize validation types. Most of the complications in the validation-type interface have to do with the handling of the additional arguments within custom validation -functions.

        +functions.

        Union Types

        The simplest way to create a custom data type is to compose it from two -preexisting ones:

        +preexisting ones:

         FIELD *link_fieldtype(FIELDTYPE *type1,
        @@ -2551,19 +2555,19 @@ composite type expects all arguments for the first type, than all arguments
         for the second.  Order functions (see Order Requests)
         associated with the component types will work on the composite; what it does
         is check the validation function for the first type, then for the second, to
        -figure what type the buffer contents should be treated as. 

        +figure what type the buffer contents should be treated as.

        New Field Types

        To create a field type from scratch, you need to specify one or both of the -following things:

        +following things:

        • A character-validation function, to check each character as it is entered.
        • A field-validation function to be applied on exit from the field.
        -Here's how you do that:

        +Here's how you do that:

         typedef int	(*HOOK)();       /* pointer to function returning int */
         
        @@ -2589,7 +2593,7 @@ the operation succeeds; if it returns FALSE, the edit cursor stays in
         the field. 

        A character validator gets the character passed in as a first argument. -It too should return TRUE if the character is valid, FALSE otherwise.

        +It too should return TRUE if the character is valid, FALSE otherwise.

        Validation Function Arguments

        @@ -2606,7 +2610,7 @@ with the type. The forms driver will use these to synthesize a pile from the trailing arguments of each set_field_type() argument, and a pointer to the pile will be passed to the validation functions.

        -Here is how you make the association:

        +Here is how you make the association:

         typedef char	*(*PTRHOOK)();    /* pointer to function returning (char *) */
        @@ -2618,7 +2622,7 @@ int set_fieldtype_arg(FIELDTYPE *type,    /* type to alter */
                               VOIDHOOK free_str); /* free structure storage */
         
        -Here is how the storage-management hooks are used:

        +Here is how the storage-management hooks are used:

        make_str @@ -2639,14 +2643,14 @@ storage of that pile. The make_str and copy_str functions may return NULL to signal allocation failure. The library routines will that call them will return error indication when this happens. Thus, your validation functions -should never see a NULL file pointer and need not check specially for it.

        +should never see a NULL file pointer and need not check specially for it.

        Order Functions For Custom Types

        Some custom field types are simply ordered in the same well-defined way that TYPE_ENUM is. For such types, it is possible to define successor and predecessor functions to support the REQ_NEXT_CHOICE -and REQ_PREV_CHOICE requests. Here's how:

        +and REQ_PREV_CHOICE requests. Here's how:

         typedef int	(*INTHOOK)();     /* pointer to function returning int */
        @@ -2661,7 +2665,7 @@ a field pointer, and a pile pointer (as for the validation functions).  They
         are expected to use the function field_buffer() to read the
         current value, and set_field_buffer() on buffer 0 to set the next
         or previous value.  Either hook may return TRUE to indicate success (a
        -legal next or previous value was set) or FALSE to indicate failure. 

        +legal next or previous value was set) or FALSE to indicate failure.

        Avoiding Problems

        diff --git a/lib/libcurses/ncurses_cfg.h b/lib/libcurses/ncurses_cfg.h index 397919a34b5..825a86ed236 100644 --- a/lib/libcurses/ncurses_cfg.h +++ b/lib/libcurses/ncurses_cfg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ncurses_cfg.h,v 1.17 2000/02/06 07:10:50 millert Exp $ */ +/* $OpenBSD: ncurses_cfg.h,v 1.18 2000/03/10 01:35:01 millert Exp $ */ /* include/ncurses_cfg.h. Generated automatically by configure. */ /**************************************************************************** @@ -73,6 +73,7 @@ #define HAVE_LONG_FILE_NAMES 1 #define HAVE_MEMCCPY 1 #define HAVE_MENU_H 1 +#define HAVE_MKSTEMP 1 #define HAVE_NANOSLEEP 1 #define HAVE_NC_ALLOC_H 1 #define HAVE_PANEL_H 1 diff --git a/lib/libcurses/tinfo/comp_scan.c b/lib/libcurses/tinfo/comp_scan.c index c8784f0aedc..dea4b5cc350 100644 --- a/lib/libcurses/tinfo/comp_scan.c +++ b/lib/libcurses/tinfo/comp_scan.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2000 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 * @@ -49,7 +49,7 @@ #include #include -MODULE_ID("$From: comp_scan.c,v 1.37 2000/01/15 21:52:23 tom Exp $") +MODULE_ID("$From: comp_scan.c,v 1.38 2000/02/13 01:01:26 tom Exp $") /* * Maximum length of string capability we'll accept before raising an error. diff --git a/lib/libcurses/tinfo/lib_napms.c b/lib/libcurses/tinfo/lib_napms.c index 83fc564b71f..90001b03b50 100644 --- a/lib/libcurses/tinfo/lib_napms.c +++ b/lib/libcurses/tinfo/lib_napms.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_napms.c,v 1.4 2000/02/06 07:10:51 millert Exp $ */ +/* $OpenBSD: lib_napms.c,v 1.5 2000/03/10 01:35:03 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 * @@ -58,7 +58,7 @@ #endif #endif -MODULE_ID("$From: lib_napms.c,v 1.7 2000/02/06 01:57:10 tom Exp $") +MODULE_ID("$From: lib_napms.c,v 1.8 2000/02/13 01:01:26 tom Exp $") int napms(int ms) { diff --git a/lib/libcurses/tinfo/lib_options.c b/lib/libcurses/tinfo/lib_options.c index 9cef80e29fb..8641792431a 100644 --- a/lib/libcurses/tinfo/lib_options.c +++ b/lib/libcurses/tinfo/lib_options.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_options.c,v 1.5 2000/01/02 22:06:51 millert Exp $ */ +/* $OpenBSD: lib_options.c,v 1.6 2000/03/10 01:35:04 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 * @@ -44,7 +44,7 @@ #include -MODULE_ID("$From: lib_options.c,v 1.37 2000/01/01 16:59:50 tom Exp $") +MODULE_ID("$From: lib_options.c,v 1.38 2000/02/13 01:01:26 tom Exp $") int idlok(WINDOW *win, bool flag) diff --git a/lib/libcurses/tinfo/lib_raw.c b/lib/libcurses/tinfo/lib_raw.c index 59452bf0517..9af0548698d 100644 --- a/lib/libcurses/tinfo/lib_raw.c +++ b/lib/libcurses/tinfo/lib_raw.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_raw.c,v 1.4 2000/01/09 05:06:02 millert Exp $ */ +/* $OpenBSD: lib_raw.c,v 1.5 2000/03/10 01:35:04 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 * @@ -50,7 +50,7 @@ #include #include /* cur_term */ -MODULE_ID("$From: lib_raw.c,v 1.6 2000/01/08 17:28:48 tom Exp $") +MODULE_ID("$From: lib_raw.c,v 1.7 2000/02/13 01:01:26 tom Exp $") #if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE diff --git a/lib/libcurses/tinfo/lib_setup.c b/lib/libcurses/tinfo/lib_setup.c index 2f722cee697..75758539989 100644 --- a/lib/libcurses/tinfo/lib_setup.c +++ b/lib/libcurses/tinfo/lib_setup.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_setup.c,v 1.8 2000/01/02 22:06:51 millert Exp $ */ +/* $OpenBSD: lib_setup.c,v 1.9 2000/03/10 01:35:04 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 * @@ -50,7 +50,7 @@ #include /* lines, columns, cur_term */ -MODULE_ID("$From: lib_setup.c,v 1.58 2000/01/01 16:46:57 tom Exp $") +MODULE_ID("$From: lib_setup.c,v 1.59 2000/02/13 01:01:26 tom Exp $") /**************************************************************************** * diff --git a/lib/libcurses/tinfo/lib_termcap.c b/lib/libcurses/tinfo/lib_termcap.c index e28706ed02a..2f41572d913 100644 --- a/lib/libcurses/tinfo/lib_termcap.c +++ b/lib/libcurses/tinfo/lib_termcap.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_termcap.c,v 1.5 2000/01/16 01:35:18 millert Exp $ */ +/* $OpenBSD: lib_termcap.c,v 1.6 2000/03/10 01:35:04 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 * @@ -41,7 +41,7 @@ #define __INTERNAL_CAPS_VISIBLE #include -MODULE_ID("$From: lib_termcap.c,v 1.35 2000/01/15 20:47:21 tom Exp $") +MODULE_ID("$From: lib_termcap.c,v 1.36 2000/02/13 01:01:26 tom Exp $") /* some of the code in here was contributed by: diff --git a/lib/libcurses/tinfo/lib_ti.c b/lib/libcurses/tinfo/lib_ti.c index 98fa68f72b8..df4b8a3a5a2 100644 --- a/lib/libcurses/tinfo/lib_ti.c +++ b/lib/libcurses/tinfo/lib_ti.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_ti.c,v 1.4 2000/01/16 01:35:18 millert Exp $ */ +/* $OpenBSD: lib_ti.c,v 1.5 2000/03/10 01:35:04 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 * @@ -38,7 +38,7 @@ #include #include -MODULE_ID("$From: lib_ti.c,v 1.19 2000/01/15 20:47:37 tom Exp $") +MODULE_ID("$From: lib_ti.c,v 1.20 2000/02/13 01:01:26 tom Exp $") int tigetflag(NCURSES_CONST char *str) diff --git a/lib/libcurses/tinfo/lib_tputs.c b/lib/libcurses/tinfo/lib_tputs.c index b6a879fd3ef..7bed4f9cdb8 100644 --- a/lib/libcurses/tinfo/lib_tputs.c +++ b/lib/libcurses/tinfo/lib_tputs.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_tputs.c,v 1.4 2000/01/16 01:35:18 millert Exp $ */ +/* $OpenBSD: lib_tputs.c,v 1.5 2000/03/10 01:35:04 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 * @@ -47,7 +47,7 @@ #include /* ospeed */ #include -MODULE_ID("$From: lib_tputs.c,v 1.43 2000/01/15 20:13:04 tom Exp $") +MODULE_ID("$From: lib_tputs.c,v 1.45 2000/02/27 02:33:24 tom Exp $") char PC = 0; /* used by termcap library */ speed_t ospeed = 0; /* used by termcap library */ @@ -61,9 +61,10 @@ delay_output(int ms) { T((T_CALLED("delay_output(%d)"), ms)); - if (no_pad_char) + if (no_pad_char) { + _nc_flush(); napms(ms); - else { + } else { register int nullcount; nullcount = (ms * _nc_baudrate(ospeed)) / 10000; diff --git a/lib/libcurses/tinfo/parse_entry.c b/lib/libcurses/tinfo/parse_entry.c index cfc70ee2ffc..2293a69d821 100644 --- a/lib/libcurses/tinfo/parse_entry.c +++ b/lib/libcurses/tinfo/parse_entry.c @@ -1,7 +1,7 @@ -/* $OpenBSD: parse_entry.c,v 1.4 2000/01/16 01:35:18 millert Exp $ */ +/* $OpenBSD: parse_entry.c,v 1.5 2000/03/10 01:35:04 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 * @@ -49,7 +49,7 @@ #define __INTERNAL_CAPS_VISIBLE #include -MODULE_ID("$From: parse_entry.c,v 1.41 2000/01/15 22:30:27 tom Exp $") +MODULE_ID("$From: parse_entry.c,v 1.42 2000/02/13 01:01:26 tom Exp $") #ifdef LINT static short const parametrized[] = diff --git a/lib/libcurses/tinfo/read_entry.c b/lib/libcurses/tinfo/read_entry.c index deb6601e8f8..d5de19e42b6 100644 --- a/lib/libcurses/tinfo/read_entry.c +++ b/lib/libcurses/tinfo/read_entry.c @@ -1,7 +1,7 @@ -/* $OpenBSD: read_entry.c,v 1.7 2000/01/09 05:06:02 millert Exp $ */ +/* $OpenBSD: read_entry.c,v 1.8 2000/03/10 01:35:04 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 #include -MODULE_ID("$From: read_entry.c,v 1.65 2000/01/08 18:59:49 tom Exp $") +MODULE_ID("$From: read_entry.c,v 1.66 2000/02/13 01:01:26 tom Exp $") #if !HAVE_TELL #define tell(fd) 0 /* lseek() is POSIX, but not tell() - odd... */ diff --git a/lib/libcurses/tinfo/read_termcap.c b/lib/libcurses/tinfo/read_termcap.c index 9f73a03b77f..07dd5af175e 100644 --- a/lib/libcurses/tinfo/read_termcap.c +++ b/lib/libcurses/tinfo/read_termcap.c @@ -1,7 +1,7 @@ -/* $OpenBSD: read_termcap.c,v 1.4 2000/01/09 05:06:02 millert Exp $ */ +/* $OpenBSD: read_termcap.c,v 1.5 2000/03/10 01:35:04 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 * @@ -57,7 +57,7 @@ #include #include -MODULE_ID("$From: read_termcap.c,v 1.44 2000/01/08 17:27:31 tom Exp $") +MODULE_ID("$From: read_termcap.c,v 1.45 2000/02/13 01:01:26 tom Exp $") #ifndef PURE_TERMINFO diff --git a/lib/libcurses/tinfo/write_entry.c b/lib/libcurses/tinfo/write_entry.c index fa91c603775..f73548f95bd 100644 --- a/lib/libcurses/tinfo/write_entry.c +++ b/lib/libcurses/tinfo/write_entry.c @@ -1,7 +1,7 @@ -/* $OpenBSD: write_entry.c,v 1.6 2000/01/02 22:06:51 millert Exp $ */ +/* $OpenBSD: write_entry.c,v 1.7 2000/03/10 01:35:04 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 * @@ -54,7 +54,7 @@ #define TRACE_OUT(p) /*nothing */ #endif -MODULE_ID("$From: write_entry.c,v 1.50 2000/01/01 16:35:44 tom Exp $") +MODULE_ID("$From: write_entry.c,v 1.51 2000/02/13 01:01:26 tom Exp $") static int total_written; diff --git a/lib/libcurses/trace/lib_trace.c b/lib/libcurses/trace/lib_trace.c index 70ed577b50d..141d7030c19 100644 --- a/lib/libcurses/trace/lib_trace.c +++ b/lib/libcurses/trace/lib_trace.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_trace.c,v 1.3 2000/01/09 05:06:02 millert Exp $ */ +/* $OpenBSD: lib_trace.c,v 1.4 2000/03/10 01:35:05 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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,7 +42,7 @@ #include -MODULE_ID("$From: lib_trace.c,v 1.32 2000/01/08 17:37:04 tom Exp $") +MODULE_ID("$From: lib_trace.c,v 1.33 2000/02/13 01:01:55 tom Exp $") unsigned _nc_tracing = 0; /* always define this */ diff --git a/lib/libcurses/trace/lib_tracebits.c b/lib/libcurses/trace/lib_tracebits.c index 2548638bc71..fe933b0ad71 100644 --- a/lib/libcurses/trace/lib_tracebits.c +++ b/lib/libcurses/trace/lib_tracebits.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_tracebits.c,v 1.4 2000/01/09 05:06:02 millert Exp $ */ +/* $OpenBSD: lib_tracebits.c,v 1.5 2000/03/10 01:35:05 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 * @@ -36,7 +36,7 @@ #include #include /* cur_term */ -MODULE_ID("$From: lib_tracebits.c,v 1.4 2000/01/08 17:41:41 tom Exp $") +MODULE_ID("$From: lib_tracebits.c,v 1.5 2000/02/13 01:01:55 tom Exp $") #if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE diff --git a/lib/libcurses/tty/lib_mvcur.c b/lib/libcurses/tty/lib_mvcur.c index 6c47e5fa408..9fbab4a5108 100644 --- a/lib/libcurses/tty/lib_mvcur.c +++ b/lib/libcurses/tty/lib_mvcur.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_mvcur.c,v 1.5 2000/01/02 22:06:51 millert Exp $ */ +/* $OpenBSD: lib_mvcur.c,v 1.6 2000/03/10 01:35:05 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 * @@ -154,7 +154,7 @@ #include #include -MODULE_ID("$From: lib_mvcur.c,v 1.62 2000/01/01 16:54:37 tom Exp $") +MODULE_ID("$From: lib_mvcur.c,v 1.63 2000/02/13 01:02:34 tom Exp $") #define STRLEN(s) (s != 0) ? strlen(s) : 0 diff --git a/lib/libcurses/tty/lib_twait.c b/lib/libcurses/tty/lib_twait.c index c2e06a4dd55..397be3f908b 100644 --- a/lib/libcurses/tty/lib_twait.c +++ b/lib/libcurses/tty/lib_twait.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_twait.c,v 1.3 2000/02/06 07:10:51 millert Exp $ */ +/* $OpenBSD: lib_twait.c,v 1.4 2000/03/10 01:35:05 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 * @@ -61,7 +61,7 @@ # endif #endif -MODULE_ID("$From: lib_twait.c,v 1.35 2000/02/06 01:57:16 tom Exp $") +MODULE_ID("$From: lib_twait.c,v 1.36 2000/02/13 01:02:34 tom Exp $") static long _nc_gettime(bool first) { diff --git a/lib/libcurses/tty/tty_display.h b/lib/libcurses/tty/tty_display.h index 9aed32d8116..198843f51e6 100644 --- a/lib/libcurses/tty/tty_display.h +++ b/lib/libcurses/tty/tty_display.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tty_display.h,v 1.1 1999/01/18 19:10:27 millert Exp $ */ +/* $OpenBSD: tty_display.h,v 1.2 2000/03/10 01:35:05 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -134,15 +134,6 @@ struct tty_display_data { vidattr(AttrOf(c)); #endif -/* - * Check whether the given character can be output by clearing commands. This - * includes test for being a space and not including any 'bad' attributes, such - * as A_REVERSE. All attribute flags which don't affect appearance of a space - * or can be output by clearing (A_COLOR in case of bce-terminal) are excluded. - */ -#define can_clear_with(ch) \ - ((ch & ~(NONBLANK_ATTR|(back_color_erase ? A_COLOR:0))) == BLANK) - #define XMC_CHANGES(c) ((c) & D->_xmc_suppress) #endif /* TTY_DISPLAY_H */ diff --git a/lib/libcurses/tty/tty_update.c b/lib/libcurses/tty/tty_update.c index b278daaee9a..c0b08f631f5 100644 --- a/lib/libcurses/tty/tty_update.c +++ b/lib/libcurses/tty/tty_update.c @@ -1,7 +1,7 @@ -/* $OpenBSD: tty_update.c,v 1.6 2000/02/06 07:10:51 millert Exp $ */ +/* $OpenBSD: tty_update.c,v 1.7 2000/03/10 01:35:05 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 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 * ****************************************************************************/ - /*----------------------------------------------------------------- * * lib_doupdate.c @@ -73,7 +72,7 @@ #include -MODULE_ID("$From: tty_update.c,v 1.124 2000/02/06 01:57:25 tom Exp $") +MODULE_ID("$From: tty_update.c,v 1.131 2000/02/26 23:22:11 tom Exp $") /* * This define controls the line-breakout optimization. Every once in a @@ -87,6 +86,7 @@ MODULE_ID("$From: tty_update.c,v 1.124 2000/02/06 01:57:25 tom Exp $") #define CHECK_INTERVAL 5 #define FILL_BCE() (SP->_coloron && !SP->_default_color && !back_color_erase) + /* * Enable checking to see if doupdate and friends are tracking the true * cursor position correctly. NOTE: this is a debugging hack which will @@ -94,13 +94,13 @@ MODULE_ID("$From: tty_update.c,v 1.124 2000/02/06 01:57:25 tom Exp $") */ /* #define POSITION_DEBUG */ -static inline chtype ClrBlank ( WINDOW *win ); +static inline chtype ClrBlank(WINDOW *win); static int ClrBottom(int total); -static void ClearScreen( chtype blank ); -static void ClrUpdate( void ); -static void DelChar( int count ); -static void InsStr( chtype *line, int count ); -static void TransformLine( int const lineno ); +static void ClearScreen(chtype blank); +static void ClrUpdate(void); +static void DelChar(int count); +static void InsStr(chtype * line, int count); +static void TransformLine(int const lineno); #ifdef POSITION_DEBUG /**************************************************************************** @@ -109,19 +109,20 @@ static void TransformLine( int const lineno ); * ****************************************************************************/ -static void position_check(int expected_y, int expected_x, char *legend) +static void +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 buf[20]; int y, x; if (!_nc_tracing || (expected_y < 0 && expected_x < 0)) return; memset(buf, '\0', sizeof(buf)); - putp("\033[6n"); /* only works on ANSI-compatibles */ + putp("\033[6n"); /* only works on ANSI-compatibles */ _nc_flush(); - (void) read(0, buf, sizeof(buf)-1); + (void) read(0, buf, sizeof(buf) - 1); _tracef("probe returned %s", _nc_visbuf(buf)); /* try to interpret as a position report */ @@ -135,14 +136,14 @@ static void position_check(int expected_y, int expected_x, char *legend) if (y - 1 != expected_y || x - 1 != expected_x) { beep(); _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); } } } #else -#define position_check(expected_y, expected_x, legend) /* nothing */ +#define position_check(expected_y, expected_x, legend) /* nothing */ #endif /* POSITION_DEBUG */ /**************************************************************************** @@ -151,115 +152,115 @@ static void position_check(int expected_y, int expected_x, char *legend) * ****************************************************************************/ -static inline void GoTo(int const row, int const col) +static inline void +GoTo(int const row, int const col) { - chtype oldattr = SP->_current_attr; + chtype oldattr = SP->_current_attr; - TR(TRACE_MOVE, ("GoTo(%d, %d) from (%d, %d)", - row, col, SP->_cursrow, SP->_curscol)); + TR(TRACE_MOVE, ("GoTo(%d, %d) from (%d, %d)", + row, col, SP->_cursrow, SP->_curscol)); - position_check(SP->_cursrow, SP->_curscol, "GoTo"); + position_check(SP->_cursrow, SP->_curscol, "GoTo"); - /* - * Force restore even if msgr is on when we're in an alternate - * character set -- these have a strong tendency to screw up the - * CR & LF used for local character motions! - */ - if ((oldattr & A_ALTCHARSET) - || (oldattr && !move_standout_mode)) - { - TR(TRACE_CHARPUT, ("turning off (%#lx) %s before move", - oldattr, _traceattr(oldattr))); - vidattr(A_NORMAL); - } + /* + * Force restore even if msgr is on when we're in an alternate + * character set -- these have a strong tendency to screw up the + * CR & LF used for local character motions! + */ + if ((oldattr & A_ALTCHARSET) + || (oldattr && !move_standout_mode)) { + TR(TRACE_CHARPUT, ("turning off (%#lx) %s before move", + oldattr, _traceattr(oldattr))); + vidattr(A_NORMAL); + } - mvcur(SP->_cursrow, SP->_curscol, row, col); - SP->_cursrow = row; - SP->_curscol = col; - position_check(SP->_cursrow, SP->_curscol, "GoTo2"); + mvcur(SP->_cursrow, SP->_curscol, row, col); + SP->_cursrow = row; + SP->_curscol = col; + position_check(SP->_cursrow, SP->_curscol, "GoTo2"); } -static inline void PutAttrChar(chtype ch) +static inline void +PutAttrChar(chtype ch) { - if (tilde_glitch && (TextOf(ch) == '~')) - ch = ('`' | AttrOf(ch)); - - TR(TRACE_CHARPUT, ("PutAttrChar(%s) at (%d, %d)", - _tracechtype(ch), - SP->_cursrow, SP->_curscol)); - UpdateAttrs(ch); - if (SP->_cleanup) { - _nc_outch((int)TextOf(ch)); - } else { - putc((int)TextOf(ch), SP->_ofp); /* macro's fastest... */ + if (tilde_glitch && (TextOf(ch) == '~')) + ch = ('`' | AttrOf(ch)); + + TR(TRACE_CHARPUT, ("PutAttrChar(%s) at (%d, %d)", + _tracechtype(ch), + SP->_cursrow, SP->_curscol)); + UpdateAttrs(ch); + if (SP->_cleanup) { + _nc_outch((int) TextOf(ch)); + } else { + putc((int) TextOf(ch), SP->_ofp); /* macro's fastest... */ #ifdef TRACE - _nc_outchars++; + _nc_outchars++; #endif /* TRACE */ - } - SP->_curscol++; - if (char_padding) { - TPUTS_TRACE("char_padding"); - putp(char_padding); - } + } + SP->_curscol++; + if (char_padding) { + TPUTS_TRACE("char_padding"); + putp(char_padding); + } } -static bool check_pending(void) +static bool +check_pending(void) /* check for pending input */ { - bool have_pending = FALSE; + bool have_pending = FALSE; - /* - * Only carry out this check when the flag is zero, otherwise we'll - * have the refreshing slow down drastically (or stop) if there's an - * unread character available. - */ - if(SP->_fifohold != 0) - return FALSE; + /* + * Only carry out this check when the flag is zero, otherwise we'll + * have the refreshing slow down drastically (or stop) if there's an + * unread character available. + */ + if (SP->_fifohold != 0) + return FALSE; - if (SP->_checkfd >= 0) { + if (SP->_checkfd >= 0) { #if USE_FUNC_POLL - struct pollfd fds[1]; - fds[0].fd = SP->_checkfd; - fds[0].events = POLLIN; - if (poll(fds, 1, 0) > 0) - { - have_pending = TRUE; - } + struct pollfd fds[1]; + fds[0].fd = SP->_checkfd; + fds[0].events = POLLIN; + if (poll(fds, 1, 0) > 0) { + have_pending = TRUE; + } #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. - */ - int n = 0; - int howmany = ioctl(0, 'ichr', &n); - if (howmany >= 0 && n > 0) { - have_pending = TRUE; - } + /* + * 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. + */ + int n = 0; + int howmany = ioctl(0, 'ichr', &n); + if (howmany >= 0 && n > 0) { + have_pending = TRUE; + } #elif HAVE_SELECT - fd_set fdset; - struct timeval ktimeout; + fd_set fdset; + struct timeval ktimeout; - ktimeout.tv_sec = - ktimeout.tv_usec = 0; + ktimeout.tv_sec = + ktimeout.tv_usec = 0; - FD_ZERO(&fdset); - FD_SET(SP->_checkfd, &fdset); - if (select(SP->_checkfd+1, &fdset, NULL, NULL, &ktimeout) != 0) - { - have_pending = TRUE; - } -#endif - } - if (have_pending) { - SP->_fifohold = 5; - _nc_flush(); + FD_ZERO(&fdset); + FD_SET(SP->_checkfd, &fdset); + if (select(SP->_checkfd + 1, &fdset, NULL, NULL, &ktimeout) != 0) { + have_pending = TRUE; } - return FALSE; +#endif + } + if (have_pending) { + SP->_fifohold = 5; + _nc_flush(); + } + return FALSE; } /* @@ -275,15 +276,13 @@ static void callPutChar(chtype const); static inline void PutChar(chtype const ch); /* forward declaration */ /* put char at lower right corner */ -static void PutCharLR(chtype const ch) +static void +PutCharLR(chtype const ch) { - if (!auto_right_margin) - { + if (!auto_right_margin) { /* we can put the char directly */ PutAttrChar(ch); - } - else if (enter_am_mode && exit_am_mode) - { + } else if (enter_am_mode && exit_am_mode) { /* we can suppress automargin */ TPUTS_TRACE("exit_am_mode"); putp(exit_am_mode); @@ -294,21 +293,19 @@ static void 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) - { - GoTo(screen_lines-1,screen_columns-2); + } else if ((enter_insert_mode && exit_insert_mode) + || insert_character || parm_ich) { + GoTo(screen_lines - 1, screen_columns - 2); callPutChar(ch); - GoTo(screen_lines-1,screen_columns-2); - InsStr(newscr->_line[screen_lines-1].text+screen_columns-2,1); + GoTo(screen_lines - 1, screen_columns - 2); + InsStr(newscr->_line[screen_lines - 1].text + screen_columns - 2, 1); } } -static void wrap_cursor(void) +static void +wrap_cursor(void) { - if (eat_newline_glitch) - { + if (eat_newline_glitch) { /* * xenl can manifest two different ways. The vt100 * way is that, when you'd expect the cursor to wrap, @@ -327,23 +324,20 @@ static void wrap_cursor(void) */ SP->_curscol = -1; SP->_cursrow = -1; - } - else if (auto_right_margin) - { + } else if (auto_right_margin) { SP->_curscol = 0; SP->_cursrow++; - } - else - { + } else { SP->_curscol--; } position_check(SP->_cursrow, SP->_curscol, "wrap_cursor"); } -static inline void PutChar(chtype const ch) +static inline void +PutChar(chtype const ch) /* insert character, handling automargin stuff */ { - if (SP->_cursrow == screen_lines-1 && SP->_curscol == screen_columns-1) + if (SP->_cursrow == screen_lines - 1 && SP->_curscol == screen_columns - 1) PutCharLR(ch); else PutAttrChar(ch); @@ -354,6 +348,26 @@ static inline void PutChar(chtype const ch) position_check(SP->_cursrow, SP->_curscol, "PutChar"); } +/* + * Check whether the given character can be output by clearing commands. This + * includes test for being a space and not including any 'bad' attributes, such + * as A_REVERSE. All attribute flags which don't affect appearance of a space + * or can be output by clearing (A_COLOR in case of bce-terminal) are excluded. + */ +static inline bool +can_clear_with(chtype ch) +{ + if (!back_color_erase && SP->_coloron) { + if (ch & A_COLOR) + return FALSE; + if (!SP->_default_color) + return FALSE; + if (SP->_default_fg != C_MASK || SP->_default_bg != C_MASK) + return FALSE; + } + return ((ch & ~(NONBLANK_ATTR | A_COLOR)) == BLANK); +} + /* * Issue a given span of characters from an array. * Must be functionally equivalent to: @@ -366,26 +380,23 @@ static inline void PutChar(chtype const ch) * * This code is optimized using ech and rep. */ -static int EmitRange(const chtype *ntext, int num) +static int +EmitRange(const chtype * ntext, int num) { - int i; + int i; - if (erase_chars || repeat_char) - { - while (num > 0) - { - int runcount; + if (erase_chars || repeat_char) { + while (num > 0) { + int runcount; chtype ntext0; - while (num>1 && ntext[0]!=ntext[1]) - { + while (num > 1 && ntext[0] != ntext[1]) { PutChar(ntext[0]); ntext++; num--; } ntext0 = ntext[0]; - if (num==1) - { + if (num == 1) { PutChar(ntext0); return 0; } @@ -404,8 +415,7 @@ static int EmitRange(const chtype *ntext, int num) */ if (erase_chars && runcount > SP->_ech_cost + SP->_cup_cost - && can_clear_with(ntext0)) - { + && can_clear_with(ntext0)) { UpdateAttrs(ntext0); putp(tparm(erase_chars, runcount)); @@ -418,9 +428,7 @@ static int EmitRange(const chtype *ntext, int num) GoTo(SP->_cursrow, SP->_curscol + runcount); else return 1; /* cursor stays in the middle */ - } - else if (repeat_char && runcount > SP->_rep_cost) - { + } else if (repeat_char && runcount > SP->_rep_cost) { bool wrap_possible = (SP->_curscol + runcount >= screen_columns); int rep_count = runcount; @@ -433,9 +441,7 @@ static int EmitRange(const chtype *ntext, int num) if (wrap_possible) PutChar(ntext0); - } - else - { + } else { for (i = 0; i < runcount; i++) PutChar(ntext[i]); } @@ -458,345 +464,334 @@ static int EmitRange(const chtype *ntext, int num) * * Returns: same as EmitRange */ -static int PutRange( - const chtype *otext, - const chtype *ntext, - int row, - int first, int last) +static int +PutRange( + const chtype * otext, + const chtype * ntext, + int row, + int first, int last) { - int j, run; - int cost = min(SP->_cup_ch_cost, SP->_hpa_ch_cost); - - TR(TRACE_CHARPUT, ("PutRange(%p, %p, %d, %d, %d)", - otext, ntext, row, first, last)); - - if (otext != ntext - && (last-first+1) > cost) { - for (j = first, run = 0; j <= last; j++) { - if (otext[j] == ntext[j]) { - run++; - } else { - if (run > cost) { - int before_run = (j - run); - EmitRange(ntext+first, before_run-first); - GoTo(row, first = j); - } - run = 0; - } + int j, run; + int cost = min(SP->_cup_ch_cost, SP->_hpa_ch_cost); + + TR(TRACE_CHARPUT, ("PutRange(%p, %p, %d, %d, %d)", + otext, ntext, row, first, last)); + + if (otext != ntext + && (last - first + 1) > cost) { + for (j = first, run = 0; j <= last; j++) { + if (otext[j] == ntext[j]) { + run++; + } else { + if (run > cost) { + int before_run = (j - run); + EmitRange(ntext + first, before_run - first); + GoTo(row, first = j); } + run = 0; + } } - return EmitRange(ntext + first, last-first+1); + } + return EmitRange(ntext + first, last - first + 1); } #if CC_HAS_INLINE_FUNCS -static void callPutChar(chtype const ch) +static void +callPutChar(chtype const ch) { - PutChar(ch); + PutChar(ch); } #endif +/* leave unbracketed here so 'indent' works */ #define MARK_NOCHANGE(win,row) \ - { \ win->_line[row].firstchar = _NOCHANGE; \ win->_line[row].lastchar = _NOCHANGE; \ - if_USE_SCROLL_HINTS(win->_line[row].oldindex = row); \ - } + if_USE_SCROLL_HINTS(win->_line[row].oldindex = row) -int doupdate(void) +int +doupdate(void) { -int i; -int nonempty; + int i; + int nonempty; #if USE_TRACE_TIMES -struct tms before, after; + struct tms before, after; #endif /* USE_TRACE_TIMES */ - T((T_CALLED("doupdate()"))); + T((T_CALLED("doupdate()"))); #ifdef TRACE - if (_nc_tracing & TRACE_UPDATE) - { - if (curscr->_clear) - _tracef("curscr is clear"); - else - _tracedump("curscr", curscr); - _tracedump("newscr", newscr); - } + if (_nc_tracing & TRACE_UPDATE) { + if (curscr->_clear) + _tracef("curscr is clear"); + else + _tracedump("curscr", curscr); + _tracedump("newscr", newscr); + } #endif /* TRACE */ - _nc_signal_handler(FALSE); + _nc_signal_handler(FALSE); - if (SP->_fifohold) - SP->_fifohold--; + if (SP->_fifohold) + SP->_fifohold--; #if USE_SIZECHANGE - if (SP->_endwin || SP->_sig_winch) - { - /* - * This is a transparent extension: XSI does not address it, - * and applications need not know that ncurses can do it. - * - * Check if the terminal size has changed while curses was off - * (this can happen in an xterm, for example), and resize the - * ncurses data structures accordingly. - */ - _nc_update_screensize(); - } + if (SP->_endwin || SP->_sig_winch) { + /* + * This is a transparent extension: XSI does not address it, + * and applications need not know that ncurses can do it. + * + * Check if the terminal size has changed while curses was off + * (this can happen in an xterm, for example), and resize the + * ncurses data structures accordingly. + */ + _nc_update_screensize(); + } #endif - if (SP->_endwin) { + if (SP->_endwin) { - T(("coming back from shell mode")); - reset_prog_mode(); + T(("coming back from shell mode")); + reset_prog_mode(); - _nc_mvcur_resume(); - _nc_screen_resume(); - SP->_mouse_resume(SP); - - SP->_endwin = FALSE; - } + _nc_mvcur_resume(); + _nc_screen_resume(); + SP->_mouse_resume(SP); + SP->_endwin = FALSE; + } #if USE_TRACE_TIMES - /* zero the metering machinery */ - _nc_outchars = 0; - (void) times(&before); + /* zero the metering machinery */ + _nc_outchars = 0; + (void) times(&before); #endif /* USE_TRACE_TIMES */ - /* - * This is the support for magic-cookie terminals. The - * theory: we scan the virtual screen looking for attribute - * turnons. Where we find one, check to make sure it's - * realizable by seeing if the required number of - * un-attributed blanks are present before and after the - * attributed range; try to shift the range boundaries over - * blanks (not changing the screen display) so this becomes - * true. If it is, shift the beginning attribute change - * appropriately (the end one, if we've gotten this far, is - * guaranteed room for its cookie). If not, nuke the added - * attributes out of the span. - */ + /* + * This is the support for magic-cookie terminals. The + * theory: we scan the virtual screen looking for attribute + * turnons. Where we find one, check to make sure it's + * realizable by seeing if the required number of + * un-attributed blanks are present before and after the + * attributed range; try to shift the range boundaries over + * blanks (not changing the screen display) so this becomes + * true. If it is, shift the beginning attribute change + * appropriately (the end one, if we've gotten this far, is + * guaranteed room for its cookie). If not, nuke the added + * attributes out of the span. + */ #if USE_XMC_SUPPORT - if (magic_cookie_glitch > 0) { - int j, k; - attr_t rattr = A_NORMAL; - - for (i = 0; i < screen_lines; i++) - for (j = 0; j < screen_columns; j++) - { - bool failed = FALSE; - chtype turnon = AttrOf(newscr->_line[i].text[j]) & ~rattr; - - /* is an attribute turned on here? */ - if (turnon == 0) { - rattr = AttrOf(newscr->_line[i].text[j]); - continue; - } + if (magic_cookie_glitch > 0) { + int j, k; + attr_t rattr = A_NORMAL; - T(("At (%d, %d): from %s...", i, j, _traceattr(rattr))); - T(("...to %s",_traceattr(turnon))); + for (i = 0; i < screen_lines; i++) { + for (j = 0; j < screen_columns; j++) { + bool failed = FALSE; + chtype turnon = AttrOf(newscr->_line[i].text[j]) & ~rattr; - /* - * If the attribute change location is a blank with a - * "safe" attribute, undo the attribute turnon. This may - * ensure there's enough room to set the attribute before - * the first non-blank in the run. - */ -#define SAFE(a) !((a) & (chtype)~NONBLANK_ATTR) - if (TextOf(newscr->_line[i].text[j])==' ' && SAFE(turnon)) - { - newscr->_line[i].text[j] &= ~turnon; - continue; - } + /* is an attribute turned on here? */ + if (turnon == 0) { + rattr = AttrOf(newscr->_line[i].text[j]); + continue; + } - /* check that there's enough room at start of span */ - for (k = 1; k <= magic_cookie_glitch; k++) - if (j-k < 0 - || TextOf(newscr->_line[i].text[j-k]) != ' ' - || !SAFE(AttrOf(newscr->_line[i].text[j-k]))) - failed = TRUE; - if (!failed) - { - bool end_onscreen = FALSE; - int m, n = j; - - /* find end of span, if it's onscreen */ - for (m = i; m < screen_lines; m++) - { - 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)); - goto foundit; - } - } - n = 0; - } - T(("Range attributed with %s ends offscreen", - _traceattr(turnon))); - foundit:; - - if (end_onscreen) - { - chtype *lastline = newscr->_line[m].text; - - /* - * If there are safely-attributed blanks at the - * end of the range, shorten the range. This will - * help ensure that there is enough room at end - * of span. - */ - while (n >= 0 - && TextOf(lastline[n]) == ' ' - && SAFE(AttrOf(lastline[n]))) - lastline[n--] &= ~turnon; - - /* check that there's enough room at end of span */ - for (k = 1; k <= magic_cookie_glitch; k++) - if (n + k >= screen_columns - || TextOf(lastline[n + k]) != ' ' - || !SAFE(AttrOf(lastline[n+k]))) - failed = TRUE; - } - } + T(("At (%d, %d): from %s...", i, j, _traceattr(rattr))); + T(("...to %s", _traceattr(turnon))); + + /* + * If the attribute change location is a blank with a + * "safe" attribute, undo the attribute turnon. This may + * ensure there's enough room to set the attribute before + * the first non-blank in the run. + */ +#define SAFE(a) (!((a) & (chtype)~NONBLANK_ATTR)) + if (TextOf(newscr->_line[i].text[j]) == ' ' && SAFE(turnon)) { + newscr->_line[i].text[j] &= ~turnon; + continue; + } - if (failed) - { - int p, q = j; - - T(("Clearing %s beginning at (%d, %d)", - _traceattr(turnon), i, j)); - - /* turn off new attributes over span */ - for (p = i; p < screen_lines; p++) - { - for ( ; q < screen_columns; q++) - { - if (AttrOf(newscr->_line[p].text[q]) == rattr) - goto foundend; - newscr->_line[p].text[q] &= ~turnon; + /* check that there's enough room at start of span */ + for (k = 1; k <= magic_cookie_glitch; k++) { + if (j - k < 0 + || TextOf(newscr->_line[i].text[j - k]) != ' ' + || !SAFE(AttrOf(newscr->_line[i].text[j - k]))) + failed = TRUE; + } + if (!failed) { + bool end_onscreen = FALSE; + int m, n = j; + + /* find end of span, if it's onscreen */ + for (m = i; m < screen_lines; m++) { + 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)); + goto foundit; } - q = 0; } - foundend:; + n = 0; } - else - { - T(("Cookie space for %s found before (%d, %d)", - _traceattr(turnon), i, j)); + T(("Range attributed with %s ends offscreen", + _traceattr(turnon))); + foundit:; + + if (end_onscreen) { + chtype *lastline = newscr->_line[m].text; /* - * back up the start of range so there's room - * for cookies before the first nonblank character + * If there are safely-attributed blanks at the + * end of the range, shorten the range. This will + * help ensure that there is enough room at end + * of span. */ + while (n >= 0 + && TextOf(lastline[n]) == ' ' + && SAFE(AttrOf(lastline[n]))) + lastline[n--] &= ~turnon; + + /* check that there's enough room at end of span */ for (k = 1; k <= magic_cookie_glitch; k++) - newscr->_line[i].text[j-k] |= turnon; + if (n + k >= screen_columns + || TextOf(lastline[n + k]) != ' ' + || !SAFE(AttrOf(lastline[n + k]))) + failed = TRUE; } + } - rattr = AttrOf(newscr->_line[i].text[j]); + if (failed) { + int p, q = j; + + T(("Clearing %s beginning at (%d, %d)", + _traceattr(turnon), i, j)); + + /* turn off new attributes over span */ + for (p = i; p < screen_lines; p++) { + for (; q < screen_columns; q++) { + if (AttrOf(newscr->_line[p].text[q]) == rattr) + goto foundend; + newscr->_line[p].text[q] &= ~turnon; + } + q = 0; + } + foundend:; + } else { + T(("Cookie space for %s found before (%d, %d)", + _traceattr(turnon), i, j)); + + /* + * back up the start of range so there's room + * for cookies before the first nonblank character + */ + for (k = 1; k <= magic_cookie_glitch; k++) + newscr->_line[i].text[j - k] |= turnon; } -#ifdef TRACE - /* show altered highlights after magic-cookie check */ - if (_nc_tracing & TRACE_UPDATE) - { - _tracef("After magic-cookie check..."); - _tracedump("newscr", newscr); + rattr = AttrOf(newscr->_line[i].text[j]); } -#endif /* TRACE */ } -#endif /* USE_XMC_SUPPORT */ - - nonempty = 0; - if (curscr->_clear || newscr->_clear) { /* force refresh ? */ - T(("clearing and updating from scratch")); - ClrUpdate(); - curscr->_clear = FALSE; /* reset flag */ - newscr->_clear = FALSE; /* reset flag */ - } else { - int changedlines = CHECK_INTERVAL; - if(check_pending()) - goto cleanup; +#ifdef TRACE + /* show altered highlights after magic-cookie check */ + if (_nc_tracing & TRACE_UPDATE) { + _tracef("After magic-cookie check..."); + _tracedump("newscr", newscr); + } +#endif /* TRACE */ + } +#endif /* USE_XMC_SUPPORT */ - nonempty = min(screen_lines, newscr->_maxy+1); + nonempty = 0; + if (curscr->_clear || newscr->_clear) { /* force refresh ? */ + T(("clearing and updating from scratch")); + ClrUpdate(); + curscr->_clear = FALSE; /* reset flag */ + newscr->_clear = FALSE; /* reset flag */ + } else { + int changedlines = CHECK_INTERVAL; - if (SP->_scrolling) { - _nc_scroll_optimize(); - } + if (check_pending()) + goto cleanup; - nonempty = ClrBottom(nonempty); + nonempty = min(screen_lines, newscr->_maxy + 1); - T(("Transforming lines, nonempty %d", nonempty)); - for (i = 0; i < nonempty; i++) { - /* - * Here is our line-breakout optimization. - */ - if (changedlines == CHECK_INTERVAL) - { - if (check_pending()) - goto cleanup; - changedlines = 0; - } + if (SP->_scrolling) { + _nc_scroll_optimize(); + } - /* - * newscr->line[i].firstchar is normally set - * by wnoutrefresh. curscr->line[i].firstchar - * is normally set by _nc_scroll_window in the - * vertical-movement optimization code, - */ - if (newscr->_line[i].firstchar != _NOCHANGE - || curscr->_line[i].firstchar != _NOCHANGE) - { - TransformLine(i); - changedlines++; - } + nonempty = ClrBottom(nonempty); - /* mark line changed successfully */ - if (i <= newscr->_maxy) - MARK_NOCHANGE(newscr,i) - if (i <= curscr->_maxy) - MARK_NOCHANGE(curscr,i) - } + T(("Transforming lines, nonempty %d", nonempty)); + for (i = 0; i < nonempty; i++) { + /* + * Here is our line-breakout optimization. + */ + if (changedlines == CHECK_INTERVAL) { + if (check_pending()) + goto cleanup; + changedlines = 0; + } + + /* + * newscr->line[i].firstchar is normally set + * by wnoutrefresh. curscr->line[i].firstchar + * is normally set by _nc_scroll_window in the + * vertical-movement optimization code, + */ + if (newscr->_line[i].firstchar != _NOCHANGE + || curscr->_line[i].firstchar != _NOCHANGE) { + TransformLine(i); + changedlines++; + } + + /* mark line changed successfully */ + if (i <= newscr->_maxy) { + MARK_NOCHANGE(newscr, i) + } + if (i <= curscr->_maxy) { + MARK_NOCHANGE(curscr, i) + } } + } - /* put everything back in sync */ - for (i = nonempty; i <= newscr->_maxy; i++) - MARK_NOCHANGE(newscr,i) - for (i = nonempty; i <= curscr->_maxy; i++) - MARK_NOCHANGE(curscr,i) + /* put everything back in sync */ + for (i = nonempty; i <= newscr->_maxy; i++) { + MARK_NOCHANGE(newscr, i) + } + for (i = nonempty; i <= curscr->_maxy; i++) { + MARK_NOCHANGE(curscr, i) + } - if (!newscr->_leaveok) - { - curscr->_curx = newscr->_curx; - curscr->_cury = newscr->_cury; + if (!newscr->_leaveok) { + curscr->_curx = newscr->_curx; + curscr->_cury = newscr->_cury; - GoTo(curscr->_cury, curscr->_curx); - } + GoTo(curscr->_cury, curscr->_curx); + } - cleanup: - /* - * Keep the physical screen in normal mode in case we get other - * processes writing to the screen. - */ - UpdateAttrs(A_NORMAL); + cleanup: + /* + * Keep the physical screen in normal mode in case we get other + * processes writing to the screen. + */ + UpdateAttrs(A_NORMAL); - _nc_flush(); - curscr->_attrs = newscr->_attrs; -/* curscr->_bkgd = newscr->_bkgd; */ + _nc_flush(); + curscr->_attrs = newscr->_attrs; #if USE_TRACE_TIMES - (void) times(&after); - TR(TRACE_TIMES, ("Update cost: %ld chars, %ld clocks system time, %ld clocks user time", + (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)); + after.tms_stime - before.tms_stime, + after.tms_utime - before.tms_utime)); #endif /* USE_TRACE_TIMES */ - _nc_signal_handler(TRUE); + _nc_signal_handler(TRUE); - returnCode(OK); + returnCode(OK); } /* @@ -812,12 +807,13 @@ struct tms before, after; #define BCE_ATTRS (A_NORMAL|A_COLOR) #define BCE_BKGD(win) (((win) == curscr ? stdscr : (win))->_bkgd) -static inline chtype ClrBlank (WINDOW *win) +static inline chtype +ClrBlank(WINDOW *win) { -chtype blank = BLANK; - if (back_color_erase) - blank |= (BCE_BKGD(win) & BCE_ATTRS); - return blank; + chtype blank = BLANK; + if (back_color_erase) + blank |= (BCE_BKGD(win) & BCE_ATTRS); + return blank; } /* @@ -827,22 +823,23 @@ chtype blank = BLANK; ** */ -static void ClrUpdate(void) +static void +ClrUpdate(void) { - int i; - chtype blank = ClrBlank(stdscr); - int nonempty = min(screen_lines, newscr->_maxy+1); + int i; + chtype blank = ClrBlank(stdscr); + int nonempty = min(screen_lines, newscr->_maxy + 1); - T(("ClrUpdate() called")); + T(("ClrUpdate() called")); - ClearScreen(blank); + ClearScreen(blank); - T(("updating screen from scratch")); + T(("updating screen from scratch")); - nonempty = ClrBottom(nonempty); + nonempty = ClrBottom(nonempty); - for (i = 0; i < nonempty; i++) - TransformLine(i); + for (i = 0; i < nonempty; i++) + TransformLine(i); } /* @@ -851,39 +848,31 @@ static void ClrUpdate(void) ** Clear to end of current line, starting at the cursor position */ -static void ClrToEOL(chtype blank) +static void +ClrToEOL(chtype blank) { -int j; -bool needclear = FALSE; + int j; + bool needclear = FALSE; - for (j = SP->_curscol; j < screen_columns; j++) - { - chtype *cp = &(curscr->_line[SP->_cursrow].text[j]); + for (j = SP->_curscol; j < screen_columns; j++) { + chtype *cp = &(curscr->_line[SP->_cursrow].text[j]); - if (*cp != blank) - { - *cp = blank; - needclear = TRUE; - } + if (*cp != blank) { + *cp = blank; + needclear = TRUE; } + } - if (needclear) - { - UpdateAttrs(blank); - TPUTS_TRACE("clr_eol"); - if (SP->_el_cost > (screen_columns - SP->_curscol) -#ifdef NCURSES_EXT_FUNCS - || FILL_BCE() -#endif - ) - { - int count = (screen_columns - SP->_curscol); - while (count-- > 0) - PutChar(blank); - } - else - putp(clr_eol); - } + if (needclear) { + UpdateAttrs(blank); + TPUTS_TRACE("clr_eol"); + if (SP->_el_cost > (screen_columns - SP->_curscol)) { + int count = (screen_columns - SP->_curscol); + while (count-- > 0) + PutChar(blank); + } else + putp(clr_eol); + } } /* @@ -892,40 +881,27 @@ bool needclear = FALSE; ** Clear to end of screen, starting at the cursor position */ -static void ClrToEOS(chtype blank) +static void +ClrToEOS(chtype blank) { -int row, col; + int row, col; - row = SP->_cursrow; - col = SP->_curscol; + row = SP->_cursrow; + col = SP->_curscol; -#ifdef NCURSES_EXT_FUNCS - if (FILL_BCE()) { - int i, j, k = col; - for (i = row; i < screen_lines; i++) { - GoTo(i, k); - UpdateAttrs(blank); - for (j = k; j < screen_columns; j++) - PutChar(blank); - k = 0; - } - GoTo(row, col); - } else -#endif - { - UpdateAttrs(blank); - TPUTS_TRACE("clr_eos"); - tputs(clr_eos, screen_lines-row, _nc_outch); - } + { + UpdateAttrs(blank); + TPUTS_TRACE("clr_eos"); + tputs(clr_eos, screen_lines - row, _nc_outch); + } - while (col < screen_columns) - curscr->_line[row].text[col++] = blank; + while (col < screen_columns) + curscr->_line[row].text[col++] = blank; - for (row++; row < screen_lines; row++) - { - for (col = 0; col < screen_columns; col++) - curscr->_line[row].text[col] = blank; - } + for (row++; row < screen_lines; row++) { + for (col = 0; col < screen_columns; col++) + curscr->_line[row].text[col] = blank; + } } /* @@ -935,58 +911,59 @@ int row, col; * screen-update. Do this by scanning backwards through the lines in the * screen, checking if each is blank, and one or more are changed. */ -static int ClrBottom(int total) +static int +ClrBottom(int total) { -static chtype *tstLine; -static size_t lenLine; - -int row, col; -int top = total; -int last = min(screen_columns, newscr->_maxx+1); -size_t length = sizeof(chtype) * last; -chtype blank = newscr->_line[total-1].text[last-1]; /* lower right char */ - - if(!clr_eos || !can_clear_with(blank)) - return total; - - if ((tstLine == 0) || (last > (int)lenLine)) { - tstLine = typeRealloc(chtype, last, tstLine); - if (tstLine != 0) { - lenLine = last; - for (col = 0; col < last; col++) - tstLine[col] = blank; - } - } + static chtype *tstLine; + static size_t lenLine; - if (tstLine != 0) { - for (row = total-1; row >= 0; row--) { - if (memcmp(tstLine, newscr->_line[row].text, length)) - break; - if (memcmp(tstLine, curscr->_line[row].text, length)) - top = row; - } + int row; + size_t col; + int top = total; + int last = min(screen_columns, newscr->_maxx + 1); + size_t length = sizeof(chtype) * last; + chtype blank = newscr->_line[total - 1].text[last - 1]; /* lower right char */ - /* don't use clr_eos for just one line if clr_eol available */ - if (top < total-1 || (top < total && !clr_eol && !clr_bol)) { - GoTo(top,0); - ClrToEOS(blank); - total = top; - if (SP->oldhash && SP->newhash) - { - for (row = top; row < screen_lines; row++) - SP->oldhash[row] = SP->newhash[row]; - } - } + if (!clr_eos || !can_clear_with(blank)) + return total; + + if ((tstLine == 0) || (last > (int) lenLine)) { + tstLine = typeRealloc(chtype, last, tstLine); + if (tstLine == 0) + return total; + lenLine = last; + tstLine[0] = ~blank; /* force the fill below */ + } + if (tstLine[0] != blank) { + for (col = 0; col < lenLine; col++) + tstLine[col] = blank; + } + + for (row = total - 1; row >= 0; row--) { + if (memcmp(tstLine, newscr->_line[row].text, length)) + break; + if (memcmp(tstLine, curscr->_line[row].text, length)) + top = row; + } + + /* don't use clr_eos for just one line if clr_eol available */ + if (top < total - 1 || (top < total && !clr_eol && !clr_bol)) { + GoTo(top, 0); + ClrToEOS(blank); + total = top; + if (SP->oldhash && SP->newhash) { + for (row = top; row < screen_lines; row++) + SP->oldhash[row] = SP->newhash[row]; } + } #if NO_LEAKS - if (tstLine != 0) { - FreeAndNull(tstLine); - } + if (tstLine != 0) { + FreeAndNull(tstLine); + } #endif - return total; + return total; } - /* ** TransformLine(lineno) ** @@ -1005,35 +982,36 @@ chtype blank = newscr->_line[total-1].text[last-1]; /* lower right char */ ** delete oLastChar - nLastChar spaces */ -static void TransformLine(int const lineno) +static void +TransformLine(int const lineno) { -int firstChar, oLastChar, nLastChar; -chtype *newLine = newscr->_line[lineno].text; -chtype *oldLine = curscr->_line[lineno].text; -int n; -bool attrchanged = FALSE; - - T(("TransformLine(%d) called", lineno)); - - /* copy new hash value to old one */ - if (SP->oldhash && SP->newhash) - SP->oldhash[lineno] = SP->newhash[lineno]; - - if(ceol_standout_glitch && clr_eol) { - firstChar = 0; - while(firstChar < screen_columns) { - if(AttrOf(newLine[firstChar]) != AttrOf(oldLine[firstChar])) - attrchanged = TRUE; - firstChar++; - } - } + int firstChar, oLastChar, nLastChar; + chtype *newLine = newscr->_line[lineno].text; + chtype *oldLine = curscr->_line[lineno].text; + int n; + bool attrchanged = FALSE; + + T(("TransformLine(%d) called", lineno)); + + /* copy new hash value to old one */ + if (SP->oldhash && SP->newhash) + SP->oldhash[lineno] = SP->newhash[lineno]; + if (ceol_standout_glitch && clr_eol) { firstChar = 0; + while (firstChar < screen_columns) { + if (AttrOf(newLine[firstChar]) != AttrOf(oldLine[firstChar])) + attrchanged = TRUE; + firstChar++; + } + } - if (attrchanged) { /* we may have to disregard the whole line */ - GoTo(lineno, firstChar); - ClrToEOL(ClrBlank(curscr)); - PutRange(oldLine, newLine, lineno, 0, (screen_columns-1)); + firstChar = 0; + + if (attrchanged) { /* we may have to disregard the whole line */ + GoTo(lineno, firstChar); + ClrToEOL(ClrBlank(curscr)); + PutRange(oldLine, newLine, lineno, 0, (screen_columns - 1)); #if USE_XMC_SUPPORT #define NEW(r,c) newscr->_line[r].text[c] @@ -1051,199 +1029,194 @@ bool attrchanged = FALSE; * will work properly only once, since we may overwrite a cookie in a * following operation. */ - } else if (magic_cookie_glitch > 0) { - GoTo(lineno, firstChar); - for (n = 0; n < screen_columns; n++) { - int m = n + magic_cookie_glitch; - - /* check for turn-on: - * If we are writing an attributed blank, where the - * previous cell is not attributed. - */ - if (TextOf(newLine[n]) == ' ' - && ((n > 0 - && xmc_turn_on(newLine[n-1], newLine[n])) - || (n == 0 - && lineno > 0 - && xmc_turn_on(NEW(lineno-1,screen_columns-1), newLine[n])))) { - n = m; - } + } else if (magic_cookie_glitch > 0) { + GoTo(lineno, firstChar); + for (n = 0; n < screen_columns; n++) { + int m = n + magic_cookie_glitch; + + /* check for turn-on: + * If we are writing an attributed blank, where the + * previous cell is not attributed. + */ + if (TextOf(newLine[n]) == ' ' + && ((n > 0 + && xmc_turn_on(newLine[n - 1], newLine[n])) + || (n == 0 + && lineno > 0 + && xmc_turn_on(NEW(lineno - 1, screen_columns - 1), + newLine[n])))) { + n = m; + } - PutChar(newLine[n]); + PutChar(newLine[n]); - /* check for turn-off: - * If we are writing an attributed non-blank, where the - * next cell is blank, and not attributed. - */ - if (TextOf(newLine[n]) != ' ' - && ((n+1 < screen_columns - && 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))))) { - n = m; - } + /* check for turn-off: + * If we are writing an attributed non-blank, where the + * next cell is blank, and not attributed. + */ + if (TextOf(newLine[n]) != ' ' + && ((n + 1 < screen_columns + && 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))))) { + n = m; + } - } + } #undef NEW #endif - } else { - chtype blank; + } else { + chtype blank; + + /* find the first differing character */ + while (firstChar < screen_columns && + newLine[firstChar] == oldLine[firstChar]) + firstChar++; + + /* if there wasn't one, we're done */ + if (firstChar >= screen_columns) + return; + + /* it may be cheap to clear leading whitespace with clr_bol */ + if (clr_bol && can_clear_with(blank = newLine[0])) { + int oFirstChar, nFirstChar; + + for (oFirstChar = 0; oFirstChar < screen_columns; oFirstChar++) + if (oldLine[oFirstChar] != blank) + break; + for (nFirstChar = 0; nFirstChar < screen_columns; nFirstChar++) + if (newLine[nFirstChar] != blank) + break; + + if (nFirstChar > oFirstChar + SP->_el1_cost) { + if (nFirstChar >= screen_columns && SP->_el_cost <= SP->_el1_cost) { + GoTo(lineno, 0); + UpdateAttrs(blank); + TPUTS_TRACE("clr_eol"); + putp(clr_eol); + } else { + GoTo(lineno, nFirstChar - 1); + UpdateAttrs(blank); + TPUTS_TRACE("clr_bol"); + putp(clr_bol); + } - /* find the first differing character */ - while (firstChar < screen_columns && - newLine[firstChar] == oldLine[firstChar]) - firstChar++; + while (firstChar < nFirstChar) + oldLine[firstChar++] = blank; - /* if there wasn't one, we're done */ if (firstChar >= screen_columns) - return; - - /* it may be cheap to clear leading whitespace with clr_bol */ - if (clr_bol && can_clear_with(blank=newLine[0])) - { - int oFirstChar, nFirstChar; - - for (oFirstChar = 0; oFirstChar < screen_columns; oFirstChar++) - if (oldLine[oFirstChar] != blank) - break; - for (nFirstChar = 0; nFirstChar < screen_columns; nFirstChar++) - if (newLine[nFirstChar] != blank) - break; - - if (nFirstChar > oFirstChar + SP->_el1_cost) - { - if (nFirstChar >= screen_columns && SP->_el_cost <= SP->_el1_cost) - { - GoTo(lineno, 0); - UpdateAttrs(blank); - TPUTS_TRACE("clr_eol"); - putp(clr_eol); - } - else - { - GoTo(lineno, nFirstChar - 1); - UpdateAttrs(blank); - TPUTS_TRACE("clr_bol"); - putp(clr_bol); - } - - while (firstChar < nFirstChar) - oldLine[firstChar++] = blank; - - if (firstChar >= screen_columns) - return; - } - } + return; + } + } - blank = newLine[screen_columns-1]; + blank = newLine[screen_columns - 1]; - if(!can_clear_with(blank)) - { - /* find the last differing character */ - nLastChar = screen_columns - 1; + if (!can_clear_with(blank)) { + /* find the last differing character */ + nLastChar = screen_columns - 1; - while (nLastChar > firstChar - && newLine[nLastChar] == oldLine[nLastChar]) - nLastChar--; + while (nLastChar > firstChar + && 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)); - } - return; - } + if (nLastChar >= firstChar) { + GoTo(lineno, firstChar); + PutRange(oldLine, newLine, lineno, firstChar, nLastChar); + memcpy(oldLine + firstChar, + newLine + firstChar, + (nLastChar - firstChar + 1) * sizeof(chtype)); + } + return; + } - /* find last non-blank character on old line */ - oLastChar = screen_columns - 1; - while (oLastChar > firstChar && oldLine[oLastChar] == blank) - oLastChar--; - - /* find last non-blank character on new line */ - nLastChar = screen_columns - 1; - while (nLastChar > firstChar && newLine[nLastChar] == blank) - nLastChar--; - - if((nLastChar == firstChar) - && (SP->_el_cost < (oLastChar - nLastChar))) { - GoTo(lineno, firstChar); - if(newLine[firstChar] != blank ) - PutChar(newLine[firstChar]); - ClrToEOL(blank); - } else if( (nLastChar != oLastChar) - && (newLine[nLastChar] != oldLine[oLastChar] - || !(_nc_idcok && has_ic())) ) { - GoTo(lineno, firstChar); - if ((oLastChar - nLastChar) > SP->_el_cost) { - if(PutRange(oldLine, newLine, lineno, firstChar, nLastChar)) - GoTo(lineno, nLastChar+1); - ClrToEOL(blank); - } else { - n = max( nLastChar , oLastChar ); - PutRange(oldLine, newLine, lineno, firstChar, n); - } + /* find last non-blank character on old line */ + oLastChar = screen_columns - 1; + while (oLastChar > firstChar && oldLine[oLastChar] == blank) + oLastChar--; + + /* find last non-blank character on new line */ + nLastChar = screen_columns - 1; + while (nLastChar > firstChar && newLine[nLastChar] == blank) + nLastChar--; + + if ((nLastChar == firstChar) + && (SP->_el_cost < (oLastChar - nLastChar))) { + GoTo(lineno, firstChar); + if (newLine[firstChar] != blank) + PutChar(newLine[firstChar]); + ClrToEOL(blank); + } else if ((nLastChar != oLastChar) + && (newLine[nLastChar] != oldLine[oLastChar] + || !(_nc_idcok && has_ic()))) { + GoTo(lineno, firstChar); + if ((oLastChar - nLastChar) > SP->_el_cost) { + if (PutRange(oldLine, newLine, lineno, firstChar, nLastChar)) + GoTo(lineno, nLastChar + 1); + ClrToEOL(blank); + } else { + n = max(nLastChar, oLastChar); + PutRange(oldLine, newLine, lineno, firstChar, n); + } + } else { + int nLastNonblank = nLastChar; + int oLastNonblank = oLastChar; + + /* find the last characters that really differ */ + while (newLine[nLastChar] == oldLine[oLastChar]) { + if (nLastChar != 0 + && oLastChar != 0) { + nLastChar--; + oLastChar--; } else { - int nLastNonblank = nLastChar; - int oLastNonblank = oLastChar; - - /* find the last characters that really differ */ - while (newLine[nLastChar] == oldLine[oLastChar]) { - if (nLastChar != 0 - && oLastChar != 0) { - nLastChar--; - oLastChar--; - } else { - break; - } - } + break; + } + } - n = min(oLastChar, nLastChar); - if (n >= firstChar) { - GoTo(lineno, firstChar); - PutRange(oldLine, newLine, lineno, firstChar, n); - } + n = min(oLastChar, nLastChar); + if (n >= firstChar) { + GoTo(lineno, firstChar); + PutRange(oldLine, newLine, lineno, firstChar, n); + } - if (oLastChar < nLastChar) { - int m = max(nLastNonblank, oLastNonblank); - GoTo(lineno, n+1); - if (InsCharCost(nLastChar - oLastChar) - > (m - n)) { - PutRange(oldLine, newLine, lineno, n+1, m); - } else { - InsStr(&newLine[n+1], nLastChar - oLastChar); - } - } else if (oLastChar > nLastChar ) { - GoTo(lineno, n+1); - if (DelCharCost(oLastChar - nLastChar) - > SP->_el_cost + nLastNonblank - (n+1)) { - if(PutRange(oldLine, newLine, lineno, - n+1, nLastNonblank)) - GoTo(lineno, nLastNonblank+1); - ClrToEOL(blank); - } else { - /* - * The delete-char sequence will - * effectively shift in blanks from the - * right margin of the screen. Ensure - * that they are the right color by - * setting the video attributes from - * the last character on the row. - */ - UpdateAttrs(blank); - DelChar(oLastChar - nLastChar); - } - } + if (oLastChar < nLastChar) { + int m = max(nLastNonblank, oLastNonblank); + GoTo(lineno, n + 1); + if (InsCharCost(nLastChar - oLastChar) + > (m - n)) { + PutRange(oldLine, newLine, lineno, n + 1, m); + } else { + InsStr(&newLine[n + 1], nLastChar - oLastChar); + } + } else if (oLastChar > nLastChar) { + GoTo(lineno, n + 1); + if (DelCharCost(oLastChar - nLastChar) + > SP->_el_cost + nLastNonblank - (n + 1)) { + if (PutRange(oldLine, newLine, lineno, + n + 1, nLastNonblank)) + GoTo(lineno, nLastNonblank + 1); + ClrToEOL(blank); + } else { + /* + * The delete-char sequence will + * effectively shift in blanks from the + * right margin of the screen. Ensure + * that they are the right color by + * setting the video attributes from + * the last character on the row. + */ + UpdateAttrs(blank); + DelChar(oLastChar - nLastChar); } + } } + } - /* update the code's internal representation */ - if (screen_columns > firstChar) - memcpy( oldLine + firstChar, - newLine + firstChar, - (screen_columns - firstChar) * sizeof(chtype)); + /* update the code's internal representation */ + if (screen_columns > firstChar) + memcpy(oldLine + firstChar, + newLine + firstChar, + (screen_columns - firstChar) * sizeof(chtype)); } /* @@ -1253,64 +1226,65 @@ bool attrchanged = FALSE; ** */ -static void ClearScreen(chtype blank) +static void +ClearScreen(chtype blank) { - int i, j; - bool fast_clear = (clear_screen || clr_eos || clr_eol); + int i, j; + bool fast_clear = (clear_screen || clr_eos || clr_eol); - T(("ClearScreen() called")); + T(("ClearScreen() called")); #ifdef NCURSES_EXT_FUNCS - if (SP->_coloron - && !SP->_default_color) { - _nc_do_color(0, FALSE, _nc_outch); - if (!back_color_erase) { - fast_clear = FALSE; - } + if (SP->_coloron + && !SP->_default_color) { + _nc_do_color(0, FALSE, _nc_outch); + if (!back_color_erase) { + fast_clear = FALSE; } + } #endif - if (fast_clear) { - if (clear_screen) { - UpdateAttrs(blank); - TPUTS_TRACE("clear_screen"); - putp(clear_screen); - SP->_cursrow = SP->_curscol = 0; - position_check(SP->_cursrow, SP->_curscol, "ClearScreen"); - } else if (clr_eos) { - SP->_cursrow = SP->_curscol = -1; - GoTo(0,0); - - UpdateAttrs(blank); - TPUTS_TRACE("clr_eos"); - putp(clr_eos); - } else if (clr_eol) { - SP->_cursrow = SP->_curscol = -1; - - for (i = 0; i < screen_lines; i++) { - GoTo(i, 0); - UpdateAttrs(blank); - TPUTS_TRACE("clr_eol"); - putp(clr_eol); - } - GoTo(0,0); - } - } else { - for (i = 0; i < screen_lines; i++) { - GoTo(i, 0); - UpdateAttrs(blank); - for (j = 0; j < screen_columns; j++) - PutChar(blank); - } - GoTo(0,0); - } + if (fast_clear) { + if (clear_screen) { + UpdateAttrs(blank); + TPUTS_TRACE("clear_screen"); + putp(clear_screen); + SP->_cursrow = SP->_curscol = 0; + position_check(SP->_cursrow, SP->_curscol, "ClearScreen"); + } else if (clr_eos) { + SP->_cursrow = SP->_curscol = -1; + GoTo(0, 0); + UpdateAttrs(blank); + TPUTS_TRACE("clr_eos"); + putp(clr_eos); + } else if (clr_eol) { + SP->_cursrow = SP->_curscol = -1; + + for (i = 0; i < screen_lines; i++) { + GoTo(i, 0); + UpdateAttrs(blank); + TPUTS_TRACE("clr_eol"); + putp(clr_eol); + } + GoTo(0, 0); + } + } else { for (i = 0; i < screen_lines; i++) { - for (j = 0; j < screen_columns; j++) - curscr->_line[i].text[j] = blank; + GoTo(i, 0); + UpdateAttrs(blank); + for (j = 0; j < screen_columns; j++) + PutChar(blank); } + GoTo(0, 0); + } - T(("screen cleared")); + for (i = 0; i < screen_lines; i++) { + for (j = 0; j < screen_columns; j++) + curscr->_line[i].text[j] = blank; + } + + T(("screen cleared")); } /* @@ -1320,51 +1294,50 @@ static void ClearScreen(chtype blank) ** */ -static void InsStr(chtype *line, int count) +static void +InsStr(chtype * line, int count) { - T(("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. */ - /* The order must match that of InsCharCost. */ - if (parm_ich) { - TPUTS_TRACE("parm_ich"); - tputs(tparm(parm_ich, count), count, _nc_outch); - while (count) { - PutAttrChar(*line); - line++; - count--; - } - } else if (enter_insert_mode && exit_insert_mode) { - TPUTS_TRACE("enter_insert_mode"); - putp(enter_insert_mode); - while (count) { - PutAttrChar(*line); - if (insert_padding) - { - TPUTS_TRACE("insert_padding"); - putp(insert_padding); - } - line++; - count--; - } - TPUTS_TRACE("exit_insert_mode"); - putp(exit_insert_mode); - } else { - while (count) { - TPUTS_TRACE("insert_character"); - putp(insert_character); - PutAttrChar(*line); - if (insert_padding) - { - TPUTS_TRACE("insert_padding"); - putp(insert_padding); - } - line++; - count--; - } + T(("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. */ + /* The order must match that of InsCharCost. */ + if (parm_ich) { + TPUTS_TRACE("parm_ich"); + tputs(tparm(parm_ich, count), count, _nc_outch); + while (count) { + PutAttrChar(*line); + line++; + count--; + } + } else if (enter_insert_mode && exit_insert_mode) { + TPUTS_TRACE("enter_insert_mode"); + putp(enter_insert_mode); + while (count) { + PutAttrChar(*line); + if (insert_padding) { + TPUTS_TRACE("insert_padding"); + putp(insert_padding); + } + line++; + count--; } - position_check(SP->_cursrow, SP->_curscol, "InsStr"); + TPUTS_TRACE("exit_insert_mode"); + putp(exit_insert_mode); + } else { + while (count) { + TPUTS_TRACE("insert_character"); + putp(insert_character); + PutAttrChar(*line); + if (insert_padding) { + TPUTS_TRACE("insert_padding"); + putp(insert_padding); + } + line++; + count--; + } + } + position_check(SP->_cursrow, SP->_curscol, "InsStr"); } /* @@ -1374,31 +1347,22 @@ static void InsStr(chtype *line, int count) ** */ -static void DelChar(int count) +static void +DelChar(int count) { - int n; + int n; - T(("DelChar(%d) called, position = (%d,%d)", count, newscr->_cury, newscr->_curx)); + T(("DelChar(%d) called, position = (%d,%d)", count, newscr->_cury, newscr->_curx)); - if (parm_dch) { - TPUTS_TRACE("parm_dch"); - tputs(tparm(parm_dch, count), count, _nc_outch); - } else { - for (n = 0; n < count; n++) { - TPUTS_TRACE("delete_character"); - putp(delete_character); - } - } -#ifdef NCURSES_EXT_FUNCS - if (FILL_BCE()) { - chtype blank = ClrBlank(stdscr); - GoTo(SP->_cursrow, screen_columns - count); - UpdateAttrs(blank); - for (n = 0; n < count; n++) { - PutChar(blank); - } + if (parm_dch) { + TPUTS_TRACE("parm_dch"); + tputs(tparm(parm_dch, count), count, _nc_outch); + } else { + for (n = 0; n < count; n++) { + TPUTS_TRACE("delete_character"); + putp(delete_character); } -#endif + } } /* @@ -1407,7 +1371,8 @@ static void DelChar(int count) ** Emit a string without waiting for update. */ -void _nc_outstr(const char *str) +void +_nc_outstr(const char *str) { (void) putp(str); _nc_flush(); @@ -1446,59 +1411,46 @@ void _nc_outstr(const char *str) */ /* Try to scroll up assuming given csr (miny, maxy). Returns ERR on failure */ -static int scroll_csr_forward(int n, int top, int bot, int miny, int maxy, chtype blank) +static int +scroll_csr_forward(int n, int top, int bot, int miny, int maxy, chtype blank) { int i, j; - if (n == 1 && scroll_forward && top == miny && bot == maxy) - { + if (n == 1 && scroll_forward && top == miny && bot == maxy) { GoTo(bot, 0); UpdateAttrs(blank); TPUTS_TRACE("scroll_forward"); tputs(scroll_forward, 0, _nc_outch); - } - else if (n == 1 && delete_line && bot == maxy) - { + } else if (n == 1 && delete_line && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); TPUTS_TRACE("delete_line"); tputs(delete_line, 0, _nc_outch); - } - else if (parm_index && top == miny && bot == maxy) - { + } else if (parm_index && top == miny && bot == maxy) { GoTo(bot, 0); UpdateAttrs(blank); TPUTS_TRACE("parm_index"); tputs(tparm(parm_index, n, 0), n, _nc_outch); - } - else if (parm_delete_line && bot == maxy) - { + } else if (parm_delete_line && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); TPUTS_TRACE("parm_delete_line"); tputs(tparm(parm_delete_line, n, 0), n, _nc_outch); - } - else if (scroll_forward && top == miny && bot == maxy) - { + } else if (scroll_forward && top == miny && bot == maxy) { GoTo(bot, 0); UpdateAttrs(blank); - for (i = 0; i < n; i++) - { + for (i = 0; i < n; i++) { TPUTS_TRACE("scroll_forward"); tputs(scroll_forward, 0, _nc_outch); } - } - else if (delete_line && bot == maxy) - { + } else if (delete_line && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); - for (i = 0; i < n; i++) - { + for (i = 0; i < n; i++) { TPUTS_TRACE("delete_line"); tputs(delete_line, 0, _nc_outch); } - } - else + } else return ERR; #ifdef NCURSES_EXT_FUNCS @@ -1515,59 +1467,46 @@ static int scroll_csr_forward(int n, int top, int bot, int miny, int maxy, chtyp /* Try to scroll down assuming given csr (miny, maxy). Returns ERR on failure */ /* n > 0 */ -static int scroll_csr_backward(int n, int top, int bot, int miny, int maxy, chtype blank) +static int +scroll_csr_backward(int n, int top, int bot, int miny, int maxy, chtype blank) { int i, j; - if (n == 1 && scroll_reverse && top == miny && bot == maxy) - { + if (n == 1 && scroll_reverse && top == miny && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); TPUTS_TRACE("scroll_reverse"); tputs(scroll_reverse, 0, _nc_outch); - } - else if (n == 1 && insert_line && bot == maxy) - { + } else if (n == 1 && insert_line && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); TPUTS_TRACE("insert_line"); tputs(insert_line, 0, _nc_outch); - } - else if (parm_rindex && top == miny && bot == maxy) - { + } else if (parm_rindex && top == miny && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); TPUTS_TRACE("parm_rindex"); tputs(tparm(parm_rindex, n, 0), n, _nc_outch); - } - else if (parm_insert_line && bot == maxy) - { + } else if (parm_insert_line && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); TPUTS_TRACE("parm_insert_line"); tputs(tparm(parm_insert_line, n, 0), n, _nc_outch); - } - else if (scroll_reverse && top == miny && bot == maxy) - { + } else if (scroll_reverse && top == miny && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); - for (i = 0; i < n; i++) - { + for (i = 0; i < n; i++) { TPUTS_TRACE("scroll_reverse"); tputs(scroll_reverse, 0, _nc_outch); } - } - else if (insert_line && bot == maxy) - { + } else if (insert_line && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); - for (i = 0; i < n; i++) - { + for (i = 0; i < n; i++) { TPUTS_TRACE("insert_line"); tputs(insert_line, 0, _nc_outch); } - } - else + } else return ERR; #ifdef NCURSES_EXT_FUNCS @@ -1584,29 +1523,24 @@ static int scroll_csr_backward(int n, int top, int bot, int miny, int maxy, chty /* scroll by using delete_line at del and insert_line at ins */ /* n > 0 */ -static int scroll_idl(int n, int del, int ins, chtype blank) +static int +scroll_idl(int n, int del, int ins, chtype blank) { int i; - if(!((parm_delete_line || delete_line) && (parm_insert_line || insert_line))) + if (!((parm_delete_line || delete_line) && (parm_insert_line || insert_line))) return ERR; GoTo(del, 0); UpdateAttrs(blank); - if (n == 1 && delete_line) - { + if (n == 1 && delete_line) { TPUTS_TRACE("delete_line"); tputs(delete_line, 0, _nc_outch); - } - else if (parm_delete_line) - { + } else if (parm_delete_line) { TPUTS_TRACE("parm_delete_line"); tputs(tparm(parm_delete_line, n, 0), n, _nc_outch); - } - else /* if (delete_line) */ - { - for (i = 0; i < n; i++) - { + } else { /* if (delete_line) */ + for (i = 0; i < n; i++) { TPUTS_TRACE("delete_line"); tputs(delete_line, 0, _nc_outch); } @@ -1614,20 +1548,14 @@ static int scroll_idl(int n, int del, int ins, chtype blank) GoTo(ins, 0); UpdateAttrs(blank); - if (n == 1 && insert_line) - { + if (n == 1 && insert_line) { TPUTS_TRACE("insert_line"); tputs(insert_line, 0, _nc_outch); - } - else if (parm_insert_line) - { + } else if (parm_insert_line) { TPUTS_TRACE("parm_insert_line"); tputs(tparm(parm_insert_line, n, 0), n, _nc_outch); - } - else /* if (insert_line) */ - { - for (i = 0; i < n; i++) - { + } else { /* if (insert_line) */ + for (i = 0; i < n; i++) { TPUTS_TRACE("insert_line"); tputs(insert_line, 0, _nc_outch); } @@ -1636,12 +1564,13 @@ static int scroll_idl(int n, int del, int ins, chtype blank) return OK; } -int _nc_scrolln(int n, int top, int bot, int maxy) +int +_nc_scrolln(int n, int top, int bot, int maxy) /* scroll region from top to bot by n lines */ { - chtype blank=ClrBlank(stdscr); + chtype blank = ClrBlank(stdscr); int i; - bool cursor_saved=FALSE; + bool cursor_saved = FALSE; int res; TR(TRACE_MOVE, ("mvcur_scrolln(%d, %d, %d, %d)", n, top, bot, maxy)); @@ -1655,15 +1584,13 @@ int _nc_scrolln(int n, int top, int bot, int maxy) } #endif - if (n > 0) /* scroll up (forward) */ - { + if (n > 0) { /* scroll up (forward) */ /* * 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++) - { + for (i = 0; i < n; i++) { GoTo(i, 0); ClrToEOL(BLANK); } @@ -1671,25 +1598,20 @@ int _nc_scrolln(int n, int top, int bot, int maxy) 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)) - && save_cursor && restore_cursor) - { - cursor_saved=TRUE; + if (res == ERR && change_scroll_region) { + if ((((n == 1 && scroll_forward) || parm_index) + && (SP->_cursrow == bot || SP->_cursrow == bot - 1)) + && save_cursor && restore_cursor) { + cursor_saved = TRUE; TPUTS_TRACE("save_cursor"); tputs(save_cursor, 0, _nc_outch); } TPUTS_TRACE("change_scroll_region"); tputs(tparm(change_scroll_region, top, bot), 0, _nc_outch); - if (cursor_saved) - { + if (cursor_saved) { TPUTS_TRACE("restore_cursor"); tputs(restore_cursor, 0, _nc_outch); - } - else - { + } else { SP->_cursrow = SP->_curscol = -1; } @@ -1701,25 +1623,18 @@ int _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) */ - { + 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. */ - if (non_dest_scroll_region || (memory_below && bot == maxy)) - { - if (bot == maxy && clr_eos) - { + if (non_dest_scroll_region || (memory_below && bot == maxy)) { + if (bot == maxy && clr_eos) { GoTo(maxy + n, 0); ClrToEOS(BLANK); - } - else if (clr_eol) - { - for (i = 0; i < -n; i++) - { + } else if (clr_eol) { + for (i = 0; i < -n; i++) { GoTo(maxy + n + i, 0); ClrToEOL(BLANK); } @@ -1728,24 +1643,19 @@ int _nc_scrolln(int n, int top, int bot, int maxy) res = scroll_csr_backward(-n, top, bot, 0, maxy, blank); - if (res == ERR && change_scroll_region) - { - if (top != 0 && (SP->_cursrow == top || SP->_cursrow == top-1) - && save_cursor && restore_cursor) - { - cursor_saved=TRUE; + if (res == ERR && change_scroll_region) { + if (top != 0 && (SP->_cursrow == top || SP->_cursrow == top - 1) + && save_cursor && restore_cursor) { + cursor_saved = TRUE; TPUTS_TRACE("save_cursor"); tputs(save_cursor, 0, _nc_outch); } TPUTS_TRACE("change_scroll_region"); tputs(tparm(change_scroll_region, top, bot), 0, _nc_outch); - if (cursor_saved) - { + if (cursor_saved) { TPUTS_TRACE("restore_cursor"); tputs(restore_cursor, 0, _nc_outch); - } - else - { + } else { SP->_cursrow = SP->_curscol = -1; } @@ -1757,22 +1667,22 @@ int _nc_scrolln(int n, int top, int bot, int maxy) } if (res == ERR && _nc_idlok) - res = scroll_idl(-n, bot+n+1, top, blank); + res = scroll_idl(-n, bot + n + 1, top, blank); } if (res == ERR) - return(ERR); + return (ERR); _nc_scroll_window(curscr, n, top, bot, blank); /* shift hash values too - they can be reused */ _nc_scroll_oldhash(n, top, bot); - return(OK); + return (OK); } - -void _nc_screen_resume() +void +_nc_screen_resume(void) { /* make sure terminal is in a sane known state */ SP->_current_attr = A_NORMAL; @@ -1782,8 +1692,7 @@ void _nc_screen_resume() putp(orig_pair); if (exit_attribute_mode) putp(exit_attribute_mode); - else - { + else { /* turn off attributes */ if (exit_alt_charset_mode) putp(exit_alt_charset_mode); @@ -1798,18 +1707,20 @@ void _nc_screen_resume() putp(auto_right_margin ? enter_am_mode : exit_am_mode); } -void _nc_screen_init() +void +_nc_screen_init(void) { _nc_screen_resume(); } /* wrap up screen handling */ -void _nc_screen_wrap() +void +_nc_screen_wrap(void) { UpdateAttrs(A_NORMAL); #ifdef NCURSES_EXT_FUNCS if (SP->_coloron - && !SP->_default_color) { + && !SP->_default_color) { SP->_default_color = TRUE; _nc_do_color(0, FALSE, _nc_outch); SP->_default_color = FALSE; @@ -1818,18 +1729,19 @@ void _nc_screen_wrap() } #if USE_XMC_SUPPORT -void _nc_do_xmc_glitch(attr_t previous) +void +_nc_do_xmc_glitch(attr_t previous) { - attr_t chg = XMC_CHANGES(previous ^ SP->_current_attr); - - while (chg != 0) { - if (chg & 1) { - SP->_curscol += magic_cookie_glitch; - if (SP->_curscol >= SP->_columns) - wrap_cursor(); - T(("bumped to %d,%d after cookie", SP->_cursrow, SP->_curscol)); - } - chg >>= 1; + attr_t chg = XMC_CHANGES(previous ^ SP->_current_attr); + + while (chg != 0) { + if (chg & 1) { + SP->_curscol += magic_cookie_glitch; + if (SP->_curscol >= SP->_columns) + wrap_cursor(); + T(("bumped to %d,%d after cookie", SP->_cursrow, SP->_curscol)); } + chg >>= 1; + } } #endif /* USE_XMC_SUPPORT */ diff --git a/usr.bin/tic/MKtermsort.sh b/usr.bin/tic/MKtermsort.sh index ae594a09bf0..58694bd9a9b 100644 --- a/usr.bin/tic/MKtermsort.sh +++ b/usr.bin/tic/MKtermsort.sh @@ -1,12 +1,17 @@ #!/bin/sh -# $From: MKtermsort.sh,v 1.5 1999/12/04 21:45:35 tom Exp $ +# $OpenBSD: MKtermsort.sh,v 1.4 2000/03/10 01:35:06 millert Exp $ +# $From: MKtermsort.sh,v 1.6 2000/01/25 11:35:36 tom Exp $ # # MKtermsort.sh -- generate indirection vectors for the various sort methods # # The output of this script is C source for nine arrays that list three sort # orders for each of the three different classes of terminfo capabilities. # -# $OpenBSD: MKtermsort.sh,v 1.3 1999/12/06 02:14:33 millert Exp $ +# keep the order independent of locale: +LANGUAGE=C +LC_ALL=C +export LANGUAGE +export LC_ALL # AWK=${1-awk} DATA=${2-../include/Caps} diff --git a/usr.bin/tic/progs.priv.h b/usr.bin/tic/progs.priv.h index 76172dcd199..5520e5ba5c4 100644 --- a/usr.bin/tic/progs.priv.h +++ b/usr.bin/tic/progs.priv.h @@ -1,4 +1,4 @@ -/* $OpenBSD: progs.priv.h,v 1.4 2000/01/02 21:48:13 millert Exp $ */ +/* $OpenBSD: progs.priv.h,v 1.5 2000/03/10 01:35:06 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998-2000 Free Software Foundation, Inc. * @@ -32,7 +32,7 @@ * Author: Thomas E. Dickey 1997,1998 * ****************************************************************************/ /* - * $From: progs.priv.h,v 1.20 2000/01/02 00:56:44 tom Exp $ + * $From: progs.priv.h,v 1.21 2000/03/05 04:32:47 tom Exp $ * * progs.priv.h * @@ -172,3 +172,8 @@ extern int optind; # define isascii(c) 1 /* not really ascii anyway */ # endif #endif + +#if !HAVE_STRDUP +#define strdup _nc_strdup +extern char *_nc_strdup(const char *); +#endif /* not HAVE_STRDUP */ diff --git a/usr.bin/tic/tic.c b/usr.bin/tic/tic.c index 2fb3b3ab033..acc0fde7bd3 100644 --- a/usr.bin/tic/tic.c +++ b/usr.bin/tic/tic.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2000 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,7 +42,7 @@ #include #include -MODULE_ID("$From: tic.c,v 1.57 2000/01/15 21:44:28 tom Exp $") +MODULE_ID("$From: tic.c,v 1.63 2000/03/05 04:33:15 tom Exp $") const char *_nc_progname = "tic"; @@ -378,6 +378,21 @@ matches(const char **needle, const char *haystack) return (code); } +static FILE * +open_tempfile(char *name) +{ + FILE *result = 0; +#if HAVE_MKSTEMP + int fd = mkstemp(name); + if (fd >= 0) + result = fdopen(fd, "w"); +#else + if (tmpnam(name) != 0) + result = fopen(name, "w"); +#endif + return result; +} + int main(int argc, char *argv[]) { @@ -392,7 +407,6 @@ main(int argc, char *argv[]) int outform = F_TERMINFO; /* output format */ int sortmode = S_TERMINFO; /* sort_mode */ - int fd; int width = 60; bool formatted = FALSE; /* reformat complex strings? */ int numbers = 0; /* format "%'char'" to/from "%{number}" */ @@ -562,9 +576,8 @@ main(int argc, char *argv[]) if (access(termcap, F_OK) == 0) { /* file exists */ source_file = termcap; - } else if (strcpy(my_tmpname, "/tmp/tic.XXXXXXXX") - && (fd = mkstemp(my_tmpname)) != -1 - && (tmp_fp = fdopen(fd, "w")) != 0) { + } else if ((tmp_fp = open_tempfile(my_tmpname)) != 0) { + source_file = my_tmpname; fprintf(tmp_fp, "%s\n", termcap); fclose(tmp_fp); tmp_fp = fopen(source_file, "r"); @@ -722,6 +735,56 @@ TERMINAL *cur_term; /* tweak to avoid linking lib_cur_term.c */ #undef CUR #define CUR tp-> +/* + * An sgr string may contain several settings other than the one we're + * interested in, essentially sgr0 + rmacs + whatever. As long as the + * "whatever" is contained in the sgr string, that is close enough for our + * sanity check. + */ +static bool +similar_sgr(char *a, char *b) +{ + while (*b != 0) { + while (*a != *b) { + if (*a == 0) + return FALSE; + a++; + } + a++; + b++; + } + return TRUE; +} + +static void +check_sgr(TERMTYPE * tp, char *zero, int num, char *cap, char *name) +{ + char *test = tparm(set_attributes, + num == 1, + num == 2, + num == 3, + num == 4, + num == 5, + num == 6, + num == 7, + num == 8, + num == 9); + if (test != 0) { + if (PRESENT(cap)) { + if (!similar_sgr(test, cap)) { + _nc_warning("%s differs from sgr(%d): %s", name, num, + _nc_visbuf(test)); + } + } else if (strcmp(test, zero)) { + _nc_warning("sgr(%d) present, but not %s", num, name); + } + } else if (PRESENT(cap)) { + _nc_warning("sgr(%d) missing, but %s present", num, name); + } +} + +#define CHECK_SGR(num,name) check_sgr(tp, zero, num, name, #name) + /* other sanity-checks (things that we don't want in the normal * logic that reads a terminfo entry) */ @@ -778,23 +841,43 @@ check_termtype(TERMTYPE * tp) || (max_colors > max_pairs)) _nc_warning("inconsistent values for max_colors and max_pairs"); - PAIRED(set_foreground, set_background) - PAIRED(set_a_foreground, set_a_background) + PAIRED(set_foreground, set_background); + PAIRED(set_a_foreground, set_a_background); /* * These may be mismatched because the terminal description relies on * restoring the cursor visibility by resetting it. */ - ANDMISSING(cursor_invisible, cursor_normal) - ANDMISSING(cursor_visible, cursor_normal) + ANDMISSING(cursor_invisible, cursor_normal); + ANDMISSING(cursor_visible, cursor_normal); + + if (PRESENT(cursor_visible) && PRESENT(cursor_normal) + && !strcmp(cursor_visible, cursor_normal)) + _nc_warning("cursor_visible is same as cursor_normal"); /* * From XSI & O'Reilly, we gather that sc/rc are required if csr is * given, because the cursor position after the scrolling operation is * performed is undefined. */ - ANDMISSING(change_scroll_region, save_cursor) - ANDMISSING(change_scroll_region, restore_cursor) + ANDMISSING(change_scroll_region, save_cursor); + ANDMISSING(change_scroll_region, restore_cursor); + + if (PRESENT(set_attributes)) { + char *zero = tparm(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, 0); + + zero = strdup(zero); + CHECK_SGR(1, enter_standout_mode); + CHECK_SGR(2, enter_underline_mode); + CHECK_SGR(3, enter_reverse_mode); + CHECK_SGR(4, enter_blink_mode); + CHECK_SGR(5, enter_dim_mode); + CHECK_SGR(6, enter_bold_mode); + CHECK_SGR(7, enter_secure_mode); + CHECK_SGR(8, enter_protected_mode); + CHECK_SGR(9, enter_alt_charset_mode); + free(zero); + } /* * Some standard applications (e.g., vi) and some non-curses @@ -802,7 +885,7 @@ check_termtype(TERMTYPE * tp) * smir/rmir. Let's be nice and warn about that, too, even though * ncurses handles it. */ - if ((PRESENT(enter_insert_mode) || PRESENT(exit_insert_mode)) + if ((PRESENT(enter_insert_mode) || PRESENT(exit_insert_mode)) && (PRESENT(insert_character) || PRESENT(parm_ich))) { _nc_warning("non-curses applications may be confused by ich/ich1 with smir/rmir"); } diff --git a/usr.bin/tset/tset.c b/usr.bin/tset/tset.c index f4d5dfdbb7b..dcbde200dcb 100644 --- a/usr.bin/tset/tset.c +++ b/usr.bin/tset/tset.c @@ -1,5 +1,5 @@ /**************************************************************************** - * 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 * @@ -31,7 +31,6 @@ * and: Eric S. Raymond * ****************************************************************************/ - /* * tset.c - terminal initialization utility * @@ -100,10 +99,10 @@ char *ttyname(int fd); #include #endif -#include /* for bool typedef */ +#include /* for bool typedef */ #include -MODULE_ID("$From: tset.c,v 0.37 1999/03/14 12:30:02 tom Exp $") +MODULE_ID("$From: tset.c,v 0.40 2000/03/05 04:37:53 tom Exp $") extern char **environ; @@ -114,110 +113,105 @@ const char *_nc_progname = "tset"; static TTY mode, oldmode; -static int terasechar = -1; /* new erase character */ -static int intrchar = -1; /* new interrupt character */ -static int isreset; /* invoked as reset */ -static int tkillchar = -1; /* new kill character */ -static int tlines, tcolumns; /* window size */ +static int terasechar = -1; /* new erase character */ +static int intrchar = -1; /* new interrupt character */ +static int isreset; /* invoked as reset */ +static int tkillchar = -1; /* new kill character */ +static int tlines, tcolumns; /* window size */ #define LOWERCASE(c) ((isalpha(c) && isupper(c)) ? tolower(c) : (c)) static int -CaselessCmp(const char *a, const char *b) /* strcasecmp isn't portable */ -{ - while (*a && *b) { - int cmp = LOWERCASE(*a) - LOWERCASE(*b); - if (cmp != 0) - break; - a++, b++; - } - return LOWERCASE(*a) - LOWERCASE(*b); +CaselessCmp(const char *a, const char *b) +{ /* strcasecmp isn't portable */ + while (*a && *b) { + int cmp = LOWERCASE(*a) - LOWERCASE(*b); + if (cmp != 0) + break; + a++, b++; + } + return LOWERCASE(*a) - LOWERCASE(*b); } -#if !HAVE_STRDUP -#define strdup _nc_strdup -extern char *_nc_strdup(const char *); -#endif /* not HAVE_STRDUP */ - static void -err(const char *fmt, ...) +err(const char *fmt,...) { - va_list ap; - va_start(ap, fmt); - (void)fprintf(stderr, "tset: "); - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - (void)fprintf(stderr, "\n"); - exit(EXIT_FAILURE); - /* NOTREACHED */ + va_list ap; + va_start(ap, fmt); + (void) fprintf(stderr, "tset: "); + (void) vfprintf(stderr, fmt, ap); + va_end(ap); + (void) fprintf(stderr, "\n"); + exit(EXIT_FAILURE); + /* NOTREACHED */ } static void failed(const char *msg) { - (void)fputs("tset: ", stderr); - perror(msg); - exit(EXIT_FAILURE); - /* NOTREACHED */ + (void)fputs("tset: ", stderr); + perror(msg); + exit(EXIT_FAILURE); + /* NOTREACHED */ } static void cat(char *file) { - register int fd, nr, nw; - char buf[BUFSIZ]; - - if ((fd = open(file, O_RDONLY, 0)) < 0) - failed(file); - - while ((nr = read(fd, buf, sizeof(buf))) > 0) - if ((nw = write(STDERR_FILENO, buf, (size_t)nr)) == -1) - failed("write to stderr"); - if (nr != 0) - failed(file); - (void)close(fd); + register int fd, nr, nw; + char buf[BUFSIZ]; + + if ((fd = open(file, O_RDONLY, 0)) < 0) + failed(file); + + while ((nr = read(fd, buf, sizeof(buf))) > 0) + if ((nw = write(STDERR_FILENO, buf, (size_t) nr)) == -1) + failed("write to stderr"); + if (nr != 0) + failed(file); + (void) close(fd); } static int outc(int c) { - return putc(c, stderr); + return putc(c, stderr); } /* Prompt the user for a terminal type. */ static const char * askuser(const char *dflt) { - static char answer[256]; - char *p; + static char answer[256]; + char *p; - /* We can get recalled; if so, don't continue uselessly. */ - if (feof(stdin) || ferror(stdin)) { - (void)fprintf(stderr, "\n"); + /* We can get recalled; if so, don't continue uselessly. */ + if (feof(stdin) || ferror(stdin)) { + (void) fprintf(stderr, "\n"); + exit(EXIT_FAILURE); + } + for (;;) { + if (dflt) + (void) fprintf(stderr, "Terminal type? [%s] ", dflt); + else + (void) fprintf(stderr, "Terminal type? "); + (void) fflush(stderr); + + if (fgets(answer, sizeof(answer), stdin) == 0) { + if (dflt == 0) { + (void) fprintf(stderr, "\n"); exit(EXIT_FAILURE); + } + return (dflt); } - for (;;) { - if (dflt) - (void)fprintf(stderr, "Terminal type? [%s] ", dflt); - else - (void)fprintf(stderr, "Terminal type? "); - (void)fflush(stderr); - - if (fgets(answer, sizeof(answer), stdin) == 0) { - if (dflt == 0) { - (void)fprintf(stderr, "\n"); - exit(EXIT_FAILURE); - } - return (dflt); - } - if ((p = strchr(answer, '\n')) != 0) - *p = '\0'; - if (answer[0]) - return (answer); - if (dflt != 0) - return (dflt); - } + if ((p = strchr(answer, '\n')) != 0) + *p = '\0'; + if (answer[0]) + return (answer); + if (dflt != 0) + return (dflt); + } } /************************************************************************** @@ -235,88 +229,89 @@ askuser(const char *dflt) #define LE (LT | EQ) typedef struct map { - struct map *next; /* Linked list of maps. */ - const char *porttype; /* Port type, or "" for any. */ - const char *type; /* Terminal type to select. */ - int conditional; /* Baud rate conditionals bitmask. */ - speed_t speed; /* Baud rate to compare against. */ + struct map *next; /* Linked list of maps. */ + const char *porttype; /* Port type, or "" for any. */ + const char *type; /* Terminal type to select. */ + int conditional; /* Baud rate conditionals bitmask. */ + speed_t speed; /* Baud rate to compare against. */ } MAP; static MAP *cur, *maplist; typedef struct speeds { - const char *string; - int speed; + const char *string; + int speed; } SPEEDS; -static const SPEEDS speeds[] = { - { "0", B0 }, - { "50", B50 }, - { "75", B75 }, - { "110", B110 }, - { "134", B134 }, - { "134.5", B134 }, - { "150", B150 }, - { "200", B200 }, - { "300", B300 }, - { "600", B600 }, - { "1200", B1200 }, - { "1800", B1800 }, - { "2400", B2400 }, - { "4800", B4800 }, - { "9600", B9600 }, - { "19200", B19200 }, - { "38400", B38400 }, - { "19200", B19200 }, - { "38400", B38400 }, +static const SPEEDS speeds[] = +{ + {"0", B0}, + {"50", B50}, + {"75", B75}, + {"110", B110}, + {"134", B134}, + {"134.5", B134}, + {"150", B150}, + {"200", B200}, + {"300", B300}, + {"600", B600}, + {"1200", B1200}, + {"1800", B1800}, + {"2400", B2400}, + {"4800", B4800}, + {"9600", B9600}, + {"19200", B19200}, + {"38400", B38400}, + {"19200", B19200}, + {"38400", B38400}, #ifdef B19200 - { "19200", B19200 }, + {"19200", B19200}, #else #ifdef EXTA - { "19200", EXTA }, + {"19200", EXTA}, #endif #endif #ifdef B38400 - { "38400", B38400 }, + {"38400", B38400}, #else #ifdef EXTB - { "38400", EXTB }, + {"38400", EXTB}, #endif #endif #ifdef B57600 - { "57600", B57600 }, + {"57600", B57600}, #endif #ifdef B115200 - { "115200", B115200 }, + {"115200", B115200}, #endif #ifdef B230400 - { "230400", B230400 }, + {"230400", B230400}, #endif #ifdef B460800 - { "460800", B460800 }, + {"460800", B460800}, #endif - { (char *)0, 0 } + {(char *) 0, 0} }; static int tbaudrate(char *rate) { - const SPEEDS *sp; - int found = FALSE; + const SPEEDS *sp; + int found = FALSE; - /* The baudrate number can be preceded by a 'B', which is ignored. */ - if (*rate == 'B') - ++rate; + /* The baudrate number can be preceded by a 'B', which is ignored. */ + if (*rate == 'B') + ++rate; - for (sp = speeds; sp->string; ++sp) { - if (!CaselessCmp(rate, sp->string)) { - found = TRUE; - break; - } + for (sp = speeds; sp->string; ++sp) { + if (!CaselessCmp(rate, sp->string)) { + found = TRUE; + break; } - if (!found) - err("unknown baud rate %s", rate); - return (sp->speed); + } + if (!found) + err("unknown baud rate %s", rate); + return (sp->speed); } /* @@ -327,110 +322,109 @@ tbaudrate(char *rate) static void add_mapping(const char *port, char *arg) { - MAP *mapp; - char *copy, *p; - const char *termp; - char *base = 0; - - copy = strdup(arg); - mapp = malloc(sizeof(MAP)); - if (copy == 0 || mapp == 0) - failed("malloc"); - mapp->next = 0; - if (maplist == 0) - cur = maplist = mapp; - else { - cur->next = mapp; - cur = mapp; - } - - mapp->porttype = arg; - mapp->conditional = 0; - - arg = strpbrk(arg, "><@=!:"); - - if (arg == 0) { /* [?]term */ - mapp->type = mapp->porttype; - mapp->porttype = 0; - goto done; - } - - if (arg == mapp->porttype) /* [><@=! baud]:term */ - termp = mapp->porttype = 0; - else - termp = base = arg; - - for (;; ++arg) /* Optional conditionals. */ - switch(*arg) { - case '<': - if (mapp->conditional & GT) - goto badmopt; - mapp->conditional |= LT; - break; - case '>': - if (mapp->conditional & LT) - goto badmopt; - mapp->conditional |= GT; - break; - case '@': - case '=': /* Not documented. */ - mapp->conditional |= EQ; - break; - case '!': - mapp->conditional |= NOT; - break; - default: - goto next; - } - -next: if (*arg == ':') { - if (mapp->conditional) - goto badmopt; - ++arg; - } else { /* Optional baudrate. */ - arg = strchr(p = arg, ':'); - if (arg == 0) - goto badmopt; - *arg++ = '\0'; - mapp->speed = tbaudrate(p); - } - - if (arg == (char *)0) /* Non-optional type. */ + MAP *mapp; + char *copy, *p; + const char *termp; + char *base = 0; + + copy = strdup(arg); + mapp = malloc(sizeof(MAP)); + if (copy == 0 || mapp == 0) + failed("malloc"); + mapp->next = 0; + if (maplist == 0) + cur = maplist = mapp; + else { + cur->next = mapp; + cur = mapp; + } + + mapp->porttype = arg; + mapp->conditional = 0; + + arg = strpbrk(arg, "><@=!:"); + + if (arg == 0) { /* [?]term */ + mapp->type = mapp->porttype; + mapp->porttype = 0; + goto done; + } + + if (arg == mapp->porttype) /* [><@=! baud]:term */ + termp = mapp->porttype = 0; + else + termp = base = arg; + + for (;; ++arg) /* Optional conditionals. */ + switch (*arg) { + case '<': + if (mapp->conditional & GT) goto badmopt; - - mapp->type = arg; - - /* Terminate porttype, if specified. */ - if (termp != 0) - *base = '\0'; - - /* If a NOT conditional, reverse the test. */ - if (mapp->conditional & NOT) - mapp->conditional = ~mapp->conditional & (EQ | GT | LT); - - /* If user specified a port with an option flag, set it. */ -done: if (port) { - if (mapp->porttype) -badmopt: err("illegal -m option format: %s", copy); - mapp->porttype = port; + mapp->conditional |= LT; + break; + case '>': + if (mapp->conditional & LT) + goto badmopt; + mapp->conditional |= GT; + break; + case '@': + case '=': /* Not documented. */ + mapp->conditional |= EQ; + break; + case '!': + mapp->conditional |= NOT; + break; + default: + goto next; } + next:if (*arg == ':') { + if (mapp->conditional) + goto badmopt; + ++arg; + } else { /* Optional baudrate. */ + arg = strchr(p = arg, ':'); + if (arg == 0) + goto badmopt; + *arg++ = '\0'; + mapp->speed = tbaudrate(p); + } + + if (arg == (char *) 0) /* Non-optional type. */ + goto badmopt; + + mapp->type = arg; + + /* Terminate porttype, if specified. */ + if (termp != 0) + *base = '\0'; + + /* If a NOT conditional, reverse the test. */ + if (mapp->conditional & NOT) + mapp->conditional = ~mapp->conditional & (EQ | GT | LT); + + /* If user specified a port with an option flag, set it. */ + done:if (port) { + if (mapp->porttype) + badmopt:err("illegal -m option format: %s", copy); + mapp->porttype = port; + } #ifdef MAPDEBUG - (void)printf("port: %s\n", mapp->porttype ? mapp->porttype : "ANY"); - (void)printf("type: %s\n", mapp->type); - (void)printf("conditional: "); - p = ""; - if (mapp->conditional & GT) { - (void)printf("GT"); - p = "/"; - } - if (mapp->conditional & EQ) { - (void)printf("%sEQ", p); - p = "/"; - } - if (mapp->conditional & LT) - (void)printf("%sLT", p); - (void)printf("\nspeed: %d\n", mapp->speed); + (void) printf("port: %s\n", mapp->porttype ? mapp->porttype : "ANY"); + (void) printf("type: %s\n", mapp->type); + (void) printf("conditional: "); + p = ""; + if (mapp->conditional & GT) { + (void) printf("GT"); + p = "/"; + } + if (mapp->conditional & EQ) { + (void) printf("%sEQ", p); + p = "/"; + } + if (mapp->conditional & LT) + (void) printf("%sLT", p); + (void) printf("\nspeed: %d\n", mapp->speed); #endif } @@ -442,38 +436,38 @@ badmopt: err("illegal -m option format: %s", copy); static const char * mapped(const char *type) { - MAP *mapp; - int match; - - for (mapp = maplist; mapp; mapp = mapp->next) - if (mapp->porttype == 0 || !strcmp(mapp->porttype, type)) { - switch (mapp->conditional) { - case 0: /* No test specified. */ - match = TRUE; - break; - case EQ: - match = (ospeed == mapp->speed); - break; - case GE: - match = (ospeed >= mapp->speed); - break; - case GT: - match = (ospeed > mapp->speed); - break; - case LE: - match = (ospeed <= mapp->speed); - break; - case LT: - match = (ospeed < mapp->speed); - break; - default: - match = FALSE; - } - if (match) - return (mapp->type); - } - /* No match found; return given type. */ - return (type); + MAP *mapp; + int match; + + for (mapp = maplist; mapp; mapp = mapp->next) + if (mapp->porttype == 0 || !strcmp(mapp->porttype, type)) { + switch (mapp->conditional) { + case 0: /* No test specified. */ + match = TRUE; + break; + case EQ: + match = (ospeed == mapp->speed); + break; + case GE: + match = (ospeed >= mapp->speed); + break; + case GT: + match = (ospeed > mapp->speed); + break; + case LE: + match = (ospeed <= mapp->speed); + break; + case LT: + match = (ospeed < mapp->speed); + break; + default: + match = FALSE; + } + if (match) + return (mapp->type); + } + /* No match found; return given type. */ + return (type); } /************************************************************************** @@ -489,118 +483,120 @@ mapped(const char *type) static const char * get_termcap_entry(char *userarg) { - int rval, errret; - char *p; - const char *ttype; + int rval, errret; + char *p; + const char *ttype; #if HAVE_GETTTYNAM - struct ttyent *t; + struct ttyent *t; #else - FILE *fp; + FILE *fp; #endif - char *ttypath; + char *ttypath; - if (userarg) { - ttype = userarg; - goto found; - } + if (userarg) { + ttype = userarg; + goto found; + } - /* Try the environment. */ - if ((ttype = getenv("TERM")) != 0) - goto map; + /* Try the environment. */ + if ((ttype = getenv("TERM")) != 0) + goto map; - if ((ttypath = ttyname(STDERR_FILENO)) != 0) { - if ((p = strrchr(ttypath, '/')) != 0) - ++p; - else - p = ttypath; + if ((ttypath = ttyname(STDERR_FILENO)) != 0) { + if ((p = strrchr(ttypath, '/')) != 0) + ++p; + else + p = ttypath; #if HAVE_GETTTYNAM - /* - * We have the 4.3BSD library call getttynam(3); that means - * there's an /etc/ttys to look up device-to-type mappings in. - * Try ttyname(3); check for dialup or other mapping. - */ - if ((t = getttynam(p))) { - ttype = t->ty_type; - goto map; - } + /* + * We have the 4.3BSD library call getttynam(3); that means + * there's an /etc/ttys to look up device-to-type mappings in. + * Try ttyname(3); check for dialup or other mapping. + */ + if ((t = getttynam(p))) { + ttype = t->ty_type; + goto map; + } #else - if ((fp = fopen("/etc/ttytype", "r")) != 0 - || (fp = fopen("/etc/ttys", "r")) != 0) { - char buffer[BUFSIZ]; - char *s, *t, *d; - - while (fgets(buffer, sizeof(buffer)-1, fp) != 0) { - for (s = buffer, t = d = 0; *s; s++) { - if (isspace(*s)) - *s = '\0'; - else if (t == 0) - t = s; - else if (d == 0 && s != buffer && s[-1] == '\0') - d = s; - } - if (t != 0 && d != 0 && !strcmp(d,p)) { - ttype = strdup(t); - fclose(fp); - goto map; - } - } - fclose(fp); + if ((fp = fopen("/etc/ttytype", "r")) != 0 + || (fp = fopen("/etc/ttys", "r")) != 0) { + char buffer[BUFSIZ]; + char *s, *t, *d; + + while (fgets(buffer, sizeof(buffer) - 1, fp) != 0) { + for (s = buffer, t = d = 0; *s; s++) { + if (isspace(*s)) + *s = '\0'; + else if (t == 0) + t = s; + else if (d == 0 && s != buffer && s[-1] == '\0') + d = s; } -#endif /* HAVE_GETTTYNAM */ + if (t != 0 && d != 0 && !strcmp(d, p)) { + ttype = strdup(t); + fclose(fp); + goto map; + } + } + fclose(fp); } +#endif /* HAVE_GETTTYNAM */ + } - /* If still undefined, use "unknown". */ - ttype = "unknown"; + /* If still undefined, use "unknown". */ + ttype = "unknown"; -map: ttype = mapped(ttype); + map:ttype = mapped(ttype); - /* - * If not a path, remove TERMCAP from the environment so we get a - * real entry from /etc/termcap. This prevents us from being fooled - * by out of date stuff in the environment. + /* + * If not a path, remove TERMCAP from the environment so we get a + * real entry from /etc/termcap. This prevents us from being fooled + * by out of date stuff in the environment. + */ + found:if ((p = getenv("TERMCAP")) != 0 && *p != '/') { + /* 'unsetenv("TERMCAP")' is not portable. + * The 'environ' array is better. */ -found: if ((p = getenv("TERMCAP")) != 0 && *p != '/') { - /* 'unsetenv("TERMCAP")' is not portable. - * The 'environ' array is better. - */ - int n; - for (n = 0; environ[n] != 0; n++) { - if (!strncmp("TERMCAP=", environ[n], 8)) { - while ((environ[n] = environ[n+1]) != 0) { - n++; - } - break; - } + int n; + for (n = 0; environ[n] != 0; n++) { + if (!strncmp("TERMCAP=", environ[n], 8)) { + while ((environ[n] = environ[n + 1]) != 0) { + n++; } + break; + } } - - /* - * ttype now contains a pointer to the type of the terminal. - * If the first character is '?', ask the user. - */ - if (ttype[0] == '?') { - if (ttype[1] != '\0') - ttype = askuser(ttype + 1); - else - ttype = askuser(0); - } - /* Find the terminfo entry. If it doesn't exist, ask the user. */ - while ((rval = setupterm((NCURSES_CONST char *)ttype, STDOUT_FILENO, &errret)) != OK) { - if (errret == 0) { - (void)fprintf(stderr, "tset: unknown terminal type %s\n", - ttype); - ttype = 0; - } - else { - (void)fprintf(stderr, "tset: can't initialize terminal type %s (error %d)\n", ttype, errret); - ttype = 0; - } - ttype = askuser(ttype); + } + + /* + * ttype now contains a pointer to the type of the terminal. + * If the first character is '?', ask the user. + */ + if (ttype[0] == '?') { + if (ttype[1] != '\0') + ttype = askuser(ttype + 1); + else + ttype = askuser(0); + } + /* Find the terminfo entry. If it doesn't exist, ask the user. */ + while ((rval = setupterm((NCURSES_CONST char *) ttype, STDOUT_FILENO, + &errret)) != OK) { + if (errret == 0) { + (void) fprintf(stderr, "tset: unknown terminal type %s\n", + ttype); + ttype = 0; + } else { + (void) fprintf(stderr, + "tset: can't initialize terminal type %s (error %d)\n", + ttype, errret); + ttype = 0; } + ttype = askuser(ttype); + } #if BROKEN_LINKER - tgetflag("am"); /* force lib_termcap.o to be linked for 'ospeed' */ + tgetflag("am"); /* force lib_termcap.o to be linked for 'ospeed' */ #endif - return (ttype); + return (ttype); } /************************************************************************** @@ -637,7 +633,7 @@ found: if ((p = getenv("TERMCAP")) != 0 && *p != '/') { #define CHK(val, dft) ((int)val <= 0 ? dft : val) -static bool set_tabs (void); +static bool set_tabs(void); /* * Reset the terminal mode bits to a sensible state. Very useful after @@ -647,115 +643,115 @@ static void reset_mode(void) { #ifdef TERMIOS - tcgetattr(STDERR_FILENO, &mode); + tcgetattr(STDERR_FILENO, &mode); #else - stty(STDERR_FILENO,&mode); + stty(STDERR_FILENO, &mode); #endif #ifdef TERMIOS #if defined(VDISCARD) && defined(CDISCARD) - mode.c_cc[VDISCARD] = CHK(mode.c_cc[VDISCARD], CDISCARD); + mode.c_cc[VDISCARD] = CHK(mode.c_cc[VDISCARD], CDISCARD); #endif - mode.c_cc[VEOF] = CHK(mode.c_cc[VEOF], CEOF); - mode.c_cc[VERASE] = CHK(mode.c_cc[VERASE], CERASE); + mode.c_cc[VEOF] = CHK(mode.c_cc[VEOF], CEOF); + mode.c_cc[VERASE] = CHK(mode.c_cc[VERASE], CERASE); #if defined(VFLUSH) && defined(CFLUSH) - mode.c_cc[VFLUSH] = CHK(mode.c_cc[VFLUSH], CFLUSH); + mode.c_cc[VFLUSH] = CHK(mode.c_cc[VFLUSH], CFLUSH); #endif - mode.c_cc[VINTR] = CHK(mode.c_cc[VINTR], CINTR); - mode.c_cc[VKILL] = CHK(mode.c_cc[VKILL], CKILL); + mode.c_cc[VINTR] = CHK(mode.c_cc[VINTR], CINTR); + mode.c_cc[VKILL] = CHK(mode.c_cc[VKILL], CKILL); #if defined(VLNEXT) && defined(CLNEXT) - mode.c_cc[VLNEXT] = CHK(mode.c_cc[VLNEXT], CLNEXT); + mode.c_cc[VLNEXT] = CHK(mode.c_cc[VLNEXT], CLNEXT); #endif - mode.c_cc[VQUIT] = CHK(mode.c_cc[VQUIT], CQUIT); + mode.c_cc[VQUIT] = CHK(mode.c_cc[VQUIT], CQUIT); #if defined(VREPRINT) && defined(CRPRNT) - mode.c_cc[VREPRINT] = CHK(mode.c_cc[VREPRINT], CRPRNT); + mode.c_cc[VREPRINT] = CHK(mode.c_cc[VREPRINT], CRPRNT); #endif #if defined(VSTART) && defined(CSTART) - mode.c_cc[VSTART] = CHK(mode.c_cc[VSTART], CSTART); + mode.c_cc[VSTART] = CHK(mode.c_cc[VSTART], CSTART); #endif #if defined(VSTOP) && defined(CSTOP) - mode.c_cc[VSTOP] = CHK(mode.c_cc[VSTOP], CSTOP); + mode.c_cc[VSTOP] = CHK(mode.c_cc[VSTOP], CSTOP); #endif #if defined(VSUSP) && defined(CSUSP) - mode.c_cc[VSUSP] = CHK(mode.c_cc[VSUSP], CSUSP); + mode.c_cc[VSUSP] = CHK(mode.c_cc[VSUSP], CSUSP); #endif #if defined(VWERASE) && defined(CWERASE) - mode.c_cc[VWERASE] = CHK(mode.c_cc[VWERASE], CWERASE); + mode.c_cc[VWERASE] = CHK(mode.c_cc[VWERASE], CWERASE); #endif - mode.c_iflag &= ~(IGNBRK | PARMRK | INPCK | ISTRIP | INLCR | IGNCR + mode.c_iflag &= ~(IGNBRK | PARMRK | INPCK | ISTRIP | INLCR | IGNCR #ifdef IUCLC - | IUCLC + | IUCLC #endif #ifdef IXANY - | IXANY + | IXANY #endif - | IXOFF); + | IXOFF); - mode.c_iflag |= (BRKINT | IGNPAR | ICRNL | IXON + mode.c_iflag |= (BRKINT | IGNPAR | ICRNL | IXON #ifdef IMAXBEL - | IMAXBEL + | IMAXBEL #endif - ); + ); - mode.c_oflag &= ~(0 + mode.c_oflag &= ~(0 #ifdef OLCUC - | OLCUC + | OLCUC #endif #ifdef OCRNL - | OCRNL + | OCRNL #endif #ifdef ONOCR - | ONOCR + | ONOCR #endif #ifdef ONLRET - | ONLRET + | ONLRET #endif #ifdef OFILL - | OFILL + | OFILL #endif #ifdef OFDEL - | OFDEL + | OFDEL #endif #ifdef NLDLY - | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY + | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY #endif - ); + ); - mode.c_oflag |= (OPOST + mode.c_oflag |= (OPOST #ifdef ONLCR - | ONLCR + | ONLCR #endif - ); + ); - mode.c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD | CLOCAL); - mode.c_cflag |= (CS8 | CREAD); - mode.c_lflag &= ~(ECHONL | NOFLSH + mode.c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD | CLOCAL); + mode.c_cflag |= (CS8 | CREAD); + mode.c_lflag &= ~(ECHONL | NOFLSH #ifdef TOSTOP - | TOSTOP + | TOSTOP #endif #ifdef ECHOPTR - | ECHOPRT + | ECHOPRT #endif #ifdef XCASE - | XCASE + | XCASE #endif - ); + ); - mode.c_lflag |= (ISIG | ICANON | ECHO | ECHOE | ECHOK + mode.c_lflag |= (ISIG | ICANON | ECHO | ECHOE | ECHOK #ifdef ECHOCTL - | ECHOCTL + | ECHOCTL #endif #ifdef ECHOKE - | ECHOKE + | ECHOKE #endif - ); + ); #endif #ifdef TERMIOS - tcsetattr(STDERR_FILENO, TCSADRAIN, &mode); + tcsetattr(STDERR_FILENO, TCSADRAIN, &mode); #else - stty(STDERR_FILENO, &mode); + stty(STDERR_FILENO, &mode); #endif } @@ -766,16 +762,16 @@ reset_mode(void) static int default_erase(void) { - int result; + int result; - if (over_strike - && key_backspace != 0 - && strlen(key_backspace) == 1) - result = key_backspace[0]; - else - result = CERASE; + if (over_strike + && key_backspace != 0 + && strlen(key_backspace) == 1) + result = key_backspace[0]; + else + result = CERASE; - return result; + return result; } /* @@ -789,14 +785,14 @@ static void set_control_chars(void) { #ifdef TERMIOS - if (mode.c_cc[VERASE] == 0 || terasechar >= 0) - mode.c_cc[VERASE] = terasechar >= 0 ? terasechar : default_erase(); + if (mode.c_cc[VERASE] == 0 || terasechar >= 0) + mode.c_cc[VERASE] = terasechar >= 0 ? terasechar : default_erase(); - if (mode.c_cc[VINTR] == 0 || intrchar >= 0) - mode.c_cc[VINTR] = intrchar >= 0 ? intrchar : CINTR; + if (mode.c_cc[VINTR] == 0 || intrchar >= 0) + mode.c_cc[VINTR] = intrchar >= 0 ? intrchar : CINTR; - if (mode.c_cc[VKILL] == 0 || tkillchar >= 0) - mode.c_cc[VKILL] = tkillchar >= 0 ? tkillchar : CKILL; + if (mode.c_cc[VKILL] == 0 || tkillchar >= 0) + mode.c_cc[VKILL] = tkillchar >= 0 ? tkillchar : CKILL; #endif } @@ -810,62 +806,62 @@ static void set_conversions(void) { #ifdef __OBSOLETE__ - /* - * Conversion logic for some *really* ancient terminal glitches, - * not supported in terminfo. Left here for succeeding generations - * to marvel at. - */ - if (tgetflag("UC")) { + /* + * Conversion logic for some *really* ancient terminal glitches, + * not supported in terminfo. Left here for succeeding generations + * to marvel at. + */ + if (tgetflag("UC")) { #ifdef IUCLC - mode.c_iflag |= IUCLC; - mode.c_oflag |= OLCUC; + mode.c_iflag |= IUCLC; + mode.c_oflag |= OLCUC; #endif - } else if (tgetflag("LC")) { + } else if (tgetflag("LC")) { #ifdef IUCLC - mode.c_iflag &= ~IUCLC; - mode.c_oflag &= ~OLCUC; + mode.c_iflag &= ~IUCLC; + mode.c_oflag &= ~OLCUC; #endif - } - mode.c_iflag &= ~(PARMRK | INPCK); - mode.c_lflag |= ICANON; - if (tgetflag("EP")) { - mode.c_cflag |= PARENB; - mode.c_cflag &= ~PARODD; - } - if (tgetflag("OP")) { - mode.c_cflag |= PARENB; - mode.c_cflag |= PARODD; - } + } + mode.c_iflag &= ~(PARMRK | INPCK); + mode.c_lflag |= ICANON; + if (tgetflag("EP")) { + mode.c_cflag |= PARENB; + mode.c_cflag &= ~PARODD; + } + if (tgetflag("OP")) { + mode.c_cflag |= PARENB; + mode.c_cflag |= PARODD; + } #endif /* __OBSOLETE__ */ #ifdef TERMIOS #ifdef ONLCR - mode.c_oflag |= ONLCR; + mode.c_oflag |= ONLCR; #endif - mode.c_iflag |= ICRNL; - mode.c_lflag |= ECHO; + mode.c_iflag |= ICRNL; + mode.c_lflag |= ECHO; #ifdef OXTABS - mode.c_oflag |= OXTABS; + mode.c_oflag |= OXTABS; #endif /* OXTABS */ - /* test used to be tgetflag("NL") */ - if (newline != (char *)0 && newline[0] == '\n' && !newline[1]) { - /* Newline, not linefeed. */ + /* test used to be tgetflag("NL") */ + if (newline != (char *) 0 && newline[0] == '\n' && !newline[1]) { + /* Newline, not linefeed. */ #ifdef ONLCR - mode.c_oflag &= ~ONLCR; + mode.c_oflag &= ~ONLCR; #endif - mode.c_iflag &= ~ICRNL; - } + mode.c_iflag &= ~ICRNL; + } #ifdef __OBSOLETE__ - if (tgetflag("HD")) /* Half duplex. */ - mode.c_lflag &= ~ECHO; + if (tgetflag("HD")) /* Half duplex. */ + mode.c_lflag &= ~ECHO; #endif /* __OBSOLETE__ */ #ifdef OXTABS - /* test used to be tgetflag("pt") */ - if (has_hardware_tabs) /* Print tabs. */ - mode.c_oflag &= ~OXTABS; + /* test used to be tgetflag("pt") */ + if (has_hardware_tabs) /* Print tabs. */ + mode.c_oflag &= ~OXTABS; #endif /* OXTABS */ - mode.c_lflag |= (ECHOE | ECHOK); + mode.c_lflag |= (ECHOE | ECHOK); #endif } @@ -873,45 +869,45 @@ set_conversions(void) static void set_init(void) { - char *p; - bool settle; + char *p; + bool settle; #ifdef __OBSOLETE__ - if (pad_char != (char *)0) /* Get/set pad character. */ - PC = pad_char[0]; + if (pad_char != (char *) 0) /* Get/set pad character. */ + PC = pad_char[0]; #endif /* OBSOLETE */ #ifdef TAB3 - if (oldmode.c_oflag & (TAB3 | ONLCR | OCRNL | ONLRET)) { - oldmode.c_oflag &= (TAB3 | ONLCR | OCRNL | ONLRET); - tcsetattr(STDERR_FILENO, TCSADRAIN, &oldmode); - } + if (oldmode.c_oflag & (TAB3 | ONLCR | OCRNL | ONLRET)) { + oldmode.c_oflag &= (TAB3 | ONLCR | OCRNL | ONLRET); + tcsetattr(STDERR_FILENO, TCSADRAIN, &oldmode); + } #endif - settle = set_tabs(); + settle = set_tabs(); - if (isreset) { - if ((p = reset_1string) != 0) { - tputs(p, 0, outc); - settle = TRUE; - } - if ((p = reset_2string) != 0) { - tputs(p, 0, outc); - settle = TRUE; - } - /* What about rf, rs3, as per terminfo man page? */ - /* also might be nice to send rmacs, rmul, rmm */ - if ((p = reset_file) != 0 - || (p = init_file) != 0) { - cat(p); - settle = TRUE; - } + if (isreset) { + if ((p = reset_1string) != 0) { + tputs(p, 0, outc); + settle = TRUE; } - - if (settle) { - (void)putc('\r', stderr); - (void)fflush(stderr); - (void)napms(1000); /* Settle the terminal. */ + if ((p = reset_2string) != 0) { + tputs(p, 0, outc); + settle = TRUE; + } + /* What about rf, rs3, as per terminfo man page? */ + /* also might be nice to send rmacs, rmul, rmm */ + if ((p = reset_file) != 0 + || (p = init_file) != 0) { + cat(p); + settle = TRUE; } + } + + if (settle) { + (void) putc('\r', stderr); + (void) fflush(stderr); + (void) napms(1000); /* Settle the terminal. */ + } } /* @@ -923,28 +919,28 @@ set_init(void) static bool set_tabs() { - if (set_tab && clear_all_tabs) { - int c; - - (void)putc('\r', stderr); /* Force to left margin. */ - tputs(clear_all_tabs, 0, outc); - - for (c = 8; c < tcolumns; c += 8) { - /* Get to the right column. In BSD tset, this - * used to try a bunch of half-clever things - * with cup and hpa, for an average saving of - * somewhat less than two character times per - * tab stop, less that .01 sec at 2400cps. We - * lost all this cruft because it seemed to be - * introducing some odd bugs. - * ----------12345678----------- */ - (void)fputs(" ", stderr); - tputs(set_tab, 0, outc); - } - putc('\r', stderr); - return (TRUE); + if (set_tab && clear_all_tabs) { + int c; + + (void) putc('\r', stderr); /* Force to left margin. */ + tputs(clear_all_tabs, 0, outc); + + for (c = 8; c < tcolumns; c += 8) { + /* Get to the right column. In BSD tset, this + * used to try a bunch of half-clever things + * with cup and hpa, for an average saving of + * somewhat less than two character times per + * tab stop, less that .01 sec at 2400cps. We + * lost all this cruft because it seemed to be + * introducing some odd bugs. + * ----------12345678----------- */ + (void) fputs(" ", stderr); + tputs(set_tab, 0, outc); } - return (FALSE); + putc('\r', stderr); + return (TRUE); + } + return (FALSE); } /************************************************************************** @@ -960,32 +956,32 @@ static void report(const char *name, int which, unsigned def) { #ifdef TERMIOS - unsigned older, newer; - char *p; - - newer = mode.c_cc[which]; - older = oldmode.c_cc[which]; - - if (older == newer && older == def) - return; - - (void)fprintf(stderr, "%s %s ", name, older == newer ? "is" : "set to"); - - /* - * Check 'delete' before 'backspace', since the key_backspace value - * is ambiguous. - */ - if (newer == 0177) - (void)fprintf(stderr, "delete.\n"); - else if ((p = key_backspace) != 0 - && newer == (unsigned char)p[0] - && p[1] == '\0') - (void)fprintf(stderr, "backspace.\n"); - else if (newer < 040) { - newer ^= 0100; - (void)fprintf(stderr, "control-%c (^%c).\n", newer, newer); - } else - (void)fprintf(stderr, "%c.\n", newer); + unsigned older, newer; + char *p; + + newer = mode.c_cc[which]; + older = oldmode.c_cc[which]; + + if (older == newer && older == def) + return; + + (void) fprintf(stderr, "%s %s ", name, older == newer ? "is" : "set to"); + + /* + * Check 'delete' before 'backspace', since the key_backspace value + * is ambiguous. + */ + if (newer == 0177) + (void) fprintf(stderr, "delete.\n"); + else if ((p = key_backspace) != 0 + && newer == (unsigned char) p[0] + && p[1] == '\0') + (void) fprintf(stderr, "backspace.\n"); + else if (newer < 040) { + newer ^= 0100; + (void) fprintf(stderr, "control-%c (^%c).\n", newer, newer); + } else + (void) fprintf(stderr, "%c.\n", newer); #endif } @@ -996,261 +992,260 @@ report(const char *name, int which, unsigned def) static void obsolete(char **argv) { - for (; *argv; ++argv) { - char *parm = argv[0]; + for (; *argv; ++argv) { + char *parm = argv[0]; - if (parm[0] == '-' && parm[1] == '\0') - { - argv[0] = strdup("-q"); - continue; - } + if (parm[0] == '-' && parm[1] == '\0') { + argv[0] = strdup("-q"); + continue; + } - if ((parm[0] != '-') - || (argv[1] && argv[1][0] != '-') - || (parm[1] != 'e' && parm[1] != 'i' && parm[1] != 'k') - || (parm[2] != '\0')) - continue; - switch(argv[0][1]) { - case 'e': - argv[0] = strdup("-e^H"); - break; - case 'i': - argv[0] = strdup("-i^C"); - break; - case 'k': - argv[0] = strdup("-k^U"); - break; - } + if ((parm[0] != '-') + || (argv[1] && argv[1][0] != '-') + || (parm[1] != 'e' && parm[1] != 'i' && parm[1] != 'k') + || (parm[2] != '\0')) + continue; + switch (argv[0][1]) { + case 'e': + argv[0] = strdup("-e^H"); + break; + case 'i': + argv[0] = strdup("-i^C"); + break; + case 'k': + argv[0] = strdup("-k^U"); + break; } + } } static void -usage(const char* pname) +usage(const char *pname) { - (void)fprintf(stderr, -"usage: %s [-IQrs] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]\n", pname); - exit(EXIT_FAILURE); + (void) fprintf(stderr, + "usage: %s [-IQrs] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]\n", pname); + exit(EXIT_FAILURE); } -static char arg_to_char(void) +static char +arg_to_char(void) { - return (optarg[0] == '^' && optarg[1] != '\0') - ? ((optarg[1] == '?') ? '\177' : CTRL(optarg[1])) - : optarg[0]; + return (optarg[0] == '^' && optarg[1] != '\0') + ? ((optarg[1] == '?') ? '\177' : CTRL(optarg[1])) + : optarg[0]; } int main(int argc, char **argv) { #if defined(TIOCGWINSZ) && defined(TIOCSWINSZ) - struct winsize win; + struct winsize win; #endif - int ch, noinit, noset, quiet, Sflag, sflag, showterm; - const char *p; - const char *ttype; + int ch, noinit, noset, quiet, Sflag, sflag, showterm; + const char *p; + const char *ttype; #ifdef __OpenBSD__ - char tcapbuf[1024], *t; - int tcgetent(char *, const char *); - void wrtermcap (char *); -#endif + char tcapbuf[1024], *t; + int tcgetent(char *, const char *); + void wrtermcap (char *); +#endif /* __OpenBSD__ */ #ifdef TERMIOS - if (tcgetattr(STDERR_FILENO, &mode) < 0) - failed("standard error"); + if (tcgetattr(STDERR_FILENO, &mode) < 0) + failed("standard error"); - oldmode = mode; - ospeed = cfgetospeed(&mode); + oldmode = mode; + ospeed = cfgetospeed(&mode); #else - if (gtty(STDERR_FILENO, &mode) < 0) - failed("standard error"); + if (gtty(STDERR_FILENO, &mode) < 0) + failed("standard error"); - oldmode = mode; - ospeed = mode.sg_ospeed; + oldmode = mode; + ospeed = mode.sg_ospeed; #endif - if ((p = strrchr(*argv, '/')) != 0) - ++p; - else - p = *argv; - if (!CaselessCmp(p, "reset")) { - isreset = 1; - reset_mode(); + if ((p = strrchr(*argv, '/')) != 0) + ++p; + else + p = *argv; + if (!CaselessCmp(p, "reset")) { + isreset = 1; + reset_mode(); + } + + obsolete(argv); + noinit = noset = quiet = Sflag = sflag = showterm = 0; + while ((ch = getopt(argc, argv, "a:d:e:Ii:k:m:np:qQSrs")) != -1) { + switch (ch) { + case 'q': /* display term only */ + noset = 1; + break; + case 'a': /* OBSOLETE: map identifier to type */ + add_mapping("arpanet", optarg); + break; + case 'd': /* OBSOLETE: map identifier to type */ + add_mapping("dialup", optarg); + break; + case 'e': /* erase character */ + terasechar = arg_to_char(); + break; + case 'I': /* no initialization strings */ + noinit = 1; + break; + case 'i': /* interrupt character */ + intrchar = arg_to_char(); + break; + case 'k': /* kill character */ + tkillchar = arg_to_char(); + break; + case 'm': /* map identifier to type */ + add_mapping(0, optarg); + break; + case 'n': /* OBSOLETE: set new tty driver */ + break; + case 'p': /* OBSOLETE: map identifier to type */ + add_mapping("plugboard", optarg); + break; + case 'Q': /* don't output control key settings */ + quiet = 1; + break; + case 'S': /* OBSOLETE: output TERM & TERMCAP */ + Sflag = 1; + break; + case 'r': /* display term on stderr */ + showterm = 1; + break; + case 's': /* output TERM set command */ + sflag = 1; + break; + case '?': + default: + usage(*argv); } + } + argc -= optind; + argv += optind; - obsolete(argv); - noinit = noset = quiet = Sflag = sflag = showterm = 0; - while ((ch = getopt(argc, argv, "a:d:e:Ii:k:m:np:qQSrs")) != -1) { - switch (ch) { - case 'q': /* display term only */ - noset = 1; - break; - case 'a': /* OBSOLETE: map identifier to type */ - add_mapping("arpanet", optarg); - break; - case 'd': /* OBSOLETE: map identifier to type */ - add_mapping("dialup", optarg); - break; - case 'e': /* erase character */ - terasechar = arg_to_char(); - break; - case 'I': /* no initialization strings */ - noinit = 1; - break; - case 'i': /* interrupt character */ - intrchar = arg_to_char(); - break; - case 'k': /* kill character */ - tkillchar = arg_to_char(); - break; - case 'm': /* map identifier to type */ - add_mapping(0, optarg); - break; - case 'n': /* OBSOLETE: set new tty driver */ - break; - case 'p': /* OBSOLETE: map identifier to type */ - add_mapping("plugboard", optarg); - break; - case 'Q': /* don't output control key settings */ - quiet = 1; - break; - case 'S': /* OBSOLETE: output TERM & TERMCAP */ - Sflag = 1; - break; - case 'r': /* display term on stderr */ - showterm = 1; - break; - case 's': /* output TERM set command */ - sflag = 1; - break; - case '?': - default: - usage(*argv); - } - } - argc -= optind; - argv += optind; + if (argc > 1) + usage(*argv); - if (argc > 1) - usage(*argv); - - ttype = get_termcap_entry(*argv); + ttype = get_termcap_entry(*argv); #ifdef __OpenBSD__ - if (tcgetent(tcapbuf, ttype) < 0) - tcapbuf[0] = '\0'; -#endif + if (tcgetent(tcapbuf, ttype) < 0) + tcapbuf[0] = '\0'; +#endif /* __OpenBSD__ */ - if (!noset) { - tcolumns = columns; - tlines = lines; + if (!noset) { + tcolumns = columns; + tlines = lines; #if defined(TIOCGWINSZ) && defined(TIOCSWINSZ) - /* Set window size */ - (void)ioctl(STDERR_FILENO, TIOCGWINSZ, &win); - if (win.ws_row == 0 && win.ws_col == 0 && - tlines > 0 && tcolumns > 0) { - win.ws_row = tlines; - win.ws_col = tcolumns; - (void)ioctl(STDERR_FILENO, TIOCSWINSZ, &win); - } + /* Set window size */ + (void) ioctl(STDERR_FILENO, TIOCGWINSZ, &win); + if (win.ws_row == 0 && win.ws_col == 0 && + tlines > 0 && tcolumns > 0) { + win.ws_row = tlines; + win.ws_col = tcolumns; + (void) ioctl(STDERR_FILENO, TIOCSWINSZ, &win); + } #endif - set_control_chars(); - set_conversions(); + set_control_chars(); + set_conversions(); - if (!noinit) - set_init(); + if (!noinit) + set_init(); - /* Set the modes if they've changed. */ - if (memcmp(&mode, &oldmode, sizeof(mode))) + /* Set the modes if they've changed. */ + if (memcmp(&mode, &oldmode, sizeof(mode))) #ifdef TERMIOS - tcsetattr(STDERR_FILENO, TCSADRAIN, &mode); + tcsetattr(STDERR_FILENO, TCSADRAIN, &mode); #else - stty(STDERR_FILENO, &mode); + stty(STDERR_FILENO, &mode); #endif - } + } - /* Get the terminal name from the entry. */ - ttype = _nc_first_name(cur_term->type.term_names); - - if (noset) - (void)printf("%s\n", ttype); - else { - if (showterm) - (void)fprintf(stderr, "Terminal type is %s.\n", ttype); - /* - * If erase, kill and interrupt characters could have been - * modified and not -Q, display the changes. - */ - if (!quiet) { - report("Erase", VERASE, CERASE); - report("Kill", VKILL, CINTR); - report("Interrupt", VINTR, CKILL); - } + /* Get the terminal name from the entry. */ + ttype = _nc_first_name(cur_term->type.term_names); + + if (noset) + (void) printf("%s\n", ttype); + else { + if (showterm) + (void) fprintf(stderr, "Terminal type is %s.\n", ttype); + /* + * If erase, kill and interrupt characters could have been + * modified and not -Q, display the changes. + */ + if (!quiet) { + report("Erase", VERASE, CERASE); + report("Kill", VKILL, CINTR); + report("Interrupt", VINTR, CKILL); } + } #ifdef __OpenBSD__ - if (Sflag) { - if (tcapbuf[0]) { - (void) printf("%s ", ttype); - wrtermcap(tcapbuf); - } else - err("No termcap entry for %s, only terminfo.", ttype); - } -#else - if (Sflag) - err("The -S option is not supported under terminfo."); + if (Sflag) { + if (tcapbuf[0]) { + (void) printf("%s ", ttype); + wrtermcap(tcapbuf); + } else + err("No termcap entry for %s, only terminfo.", ttype); + } +#else + if (Sflag) + err("The -S option is not supported under terminfo."); #endif /* __OpenBSD__ */ #ifdef __OpenBSD__ - if (sflag) { - /* - * Figure out what shell we're using. A hack, we look for an - * environmental variable SHELL ending in "csh". - */ - if ((p = getenv("SHELL")) != 0 - && !strcmp(p + strlen(p) - 3, "csh")) { - if (tcapbuf[0]) - p = "set noglob histchars="";\nsetenv TERM %s;\nsetenv TERMCAP "; - else - p = "set noglob histchars="";\nsetenv TERM %s;\n"; - t = "unset noglob histchars;\n"; + if (sflag) { + /* + * Figure out what shell we're using. A hack, we look for an + * environmental variable SHELL ending in "csh". + */ + if ((p = getenv("SHELL")) != 0 && !strcmp(p + strlen(p) - 3, "csh")) { + if (tcapbuf[0]) + p = "set noglob histchars="";\nsetenv TERM %s;\nsetenv TERMCAP "; + else + p = "set noglob histchars="";\nsetenv TERM %s;\n"; + t = "unset noglob histchars;\n"; + } else { + if (tcapbuf) { + p = "TERM=%s;\nTERMCAP="; + t = "export TERMCAP TERM;\n"; + } else { + if (tcapbuf) { + p = "TERM=%s;\nTERMCAP="; + t = "export TERMCAP TERM;\n"; } else { - if (tcapbuf) { - p = "TERM=%s;\nTERMCAP="; - t = "export TERMCAP TERM;\n"; - } else { - if (tcapbuf) { - p = "TERM=%s;\nTERMCAP="; - t = "export TERMCAP TERM;\n"; - } else { - p = "TERM=%s;\n"; - t = "export TERMCAP;\n"; - } - } + p = "TERM=%s;\n"; + t = "export TERMCAP;\n"; } - (void) printf(p, ttype); - if (tcapbuf[0]) { - putchar('\''); - wrtermcap(tcapbuf); - fputs("';\n", stdout); - } - (void)printf(t); + } } -#else - if (sflag) { - /* - * Figure out what shell we're using. A hack, we look for an - * environmental variable SHELL ending in "csh". - */ - if ((p = getenv("SHELL")) != 0 - && !strcmp(p + strlen(p) - 3, "csh")) - p = "set noglob;\nsetenv TERM %s;\nunset noglob;\n"; - else - p = "TERM=%s;\n"; - (void) printf(p, ttype); + (void) printf(p, ttype); + if (tcapbuf[0]) { + putchar('\''); + wrtermcap(tcapbuf); + fputs("';\n", stdout); } + (void)printf(t); + } +#else + if (sflag) { + /* + * Figure out what shell we're using. A hack, we look for an + * environmental variable SHELL ending in "csh". + */ + if ((p = getenv("SHELL")) != 0 + && !strcmp(p + strlen(p) - 3, "csh")) + p = "set noglob;\nsetenv TERM %s;\nunset noglob;\n"; + else + p = "TERM=%s;\n"; + (void) printf(p, ttype); + } #endif /* __OpenBSD__ */ - return EXIT_SUCCESS; + return EXIT_SUCCESS; } /* tset.c ends here */ -- 2.20.1