diff options
Diffstat (limited to 'lib/libcurses')
48 files changed, 3324 insertions, 2111 deletions
diff --git a/lib/libcurses/Makefile b/lib/libcurses/Makefile index 1a1538da63e0..74baf7974571 100644 --- a/lib/libcurses/Makefile +++ b/lib/libcurses/Makefile @@ -1,16 +1,19 @@ -# @(#)Makefile 5.10 (Berkeley) 6/24/90 +# @(#)Makefile 8.2 (Berkeley) 1/2/94 LIB= curses -SRCS= addbytes.c addch.c addstr.c box.c clear.c clrtobot.c clrtoeol.c \ - cr_put.c cr_tty.c curses.c delch.c deleteln.c delwin.c endwin.c \ - erase.c fullname.c getch.c getstr.c idlok.c id_subwins.c initscr.c \ - insch.c insertln.c longname.c move.c mvprintw.c mvscanw.c mvwin.c \ - newwin.c overlay.c overwrite.c printw.c putchar.c refresh.c scanw.c \ - scroll.c toucholap.c standout.c touchwin.c tstp.c unctrl.c +SRCS= addbytes.c addch.c addnstr.c box.c clear.c clrtobot.c clrtoeol.c \ + cr_put.c ctrace.c cur_hash.c curses.c delch.c deleteln.c delwin.c \ + erase.c fullname.c getch.c getstr.c id_subwins.c idlok.c initscr.c \ + insch.c insertln.c longname.c move.c mvwin.c newwin.c overlay.c \ + overwrite.c printw.c putchar.c refresh.c scanw.c scroll.c setterm.c \ + standout.c toucholap.c touchwin.c tscroll.c tstp.c tty.c unctrl.c MAN3= curses.3 +CFLAGS+=-D_CURSES_PRIVATE -I${.CURDIR} + beforeinstall: - -cd ${.CURDIR}; cmp -s curses.h ${DESTDIR}/usr/include/curses.h || \ + -cd ${.CURDIR}; cmp -s curses.h ${DESTDIR}/usr/include/curses.h > \ + /dev/null 2>&1 || \ install -c -o ${BINOWN} -g ${BINGRP} -m 444 curses.h \ ${DESTDIR}/usr/include diff --git a/lib/libcurses/addbytes.c b/lib/libcurses/addbytes.c index 3d47b326acf4..dc754830636d 100644 --- a/lib/libcurses/addbytes.c +++ b/lib/libcurses/addbytes.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1987 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1987, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,117 +32,127 @@ */ #ifndef lint -static char sccsid[] = "@(#)addbytes.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)addbytes.c 8.2 (Berkeley) 1/9/94"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> -waddbytes(win, bytes, count) -reg WINDOW *win; -reg char *bytes; -int count; -{ - chtype c; - reg int i; - - for (i = 0; i < count; i++) { - c = (unsigned char) *bytes++; - if (_waddbytes(win, &c, 1) == ERR) - return ERR; - } - return OK; -} +#define SYNCH_IN {y = win->cury; x = win->curx;} +#define SYNCH_OUT {win->cury = y; win->curx = x;} /* - * This routine adds the character to the current position - * + * waddbytes -- + * Add the character to the current position in the given window. */ -_waddbytes(win, bytes, count) -reg WINDOW *win; -reg chtype *bytes; -reg int count; +int +__waddbytes(win, bytes, count, so) + register WINDOW *win; + register const char *bytes; + register int count; + int so; { -#define SYNCH_OUT() {win->_cury = y; win->_curx = x;} -#define SYNCH_IN() {y = win->_cury; x = win->_curx;} - reg int x, y; - reg int newx; + static char blanks[] = " "; + register int c, newx, x, y; + char stand; + __LINE *lp; - SYNCH_IN(); - while (count--) { - register chtype c; - static chtype blanks[] = {' ',' ',' ',' ',' ',' ',' ',' '}; + SYNCH_IN; - c = *bytes++; - switch (c) { - case '\t': - SYNCH_OUT(); - if (_waddbytes(win, blanks, 8-(x%8)) == ERR) { - return ERR; - } - SYNCH_IN(); - break; +#ifdef DEBUG + __CTRACE("ADDBYTES('%c') at (%d, %d)\n", c, y, x); +#endif + while (count--) { + c = *bytes++; + switch (c) { + case '\t': + SYNCH_OUT; + if (waddbytes(win, blanks, 8 - (x % 8)) == ERR) + return (ERR); + SYNCH_IN; + break; - default: -# ifdef FULLDEBUG - fprintf(outf, "ADDBYTES: 1: y = %d, x = %d, firstch = %d, lastch = %d\n", y, x, win->_firstch[y], win->_lastch[y]); -# endif - if (win->_flags & _STANDOUT) - c |= _STANDOUT; - { -# ifdef FULLDEBUG - fprintf(outf, "ADDBYTES(%0.2o, %d, %d)\n", win, y, x); -# endif - if (win->_y[y][x] != c) { - newx = x + win->_ch_off; - if (win->_firstch[y] == _NOCHANGE) { - win->_firstch[y] = - win->_lastch[y] = newx; - } else if (newx < win->_firstch[y]) - win->_firstch[y] = newx; - else if (newx > win->_lastch[y]) - win->_lastch[y] = newx; -# ifdef FULLDEBUG - fprintf(outf, "ADDBYTES: change gives f/l: %d/%d [%d/%d]\n", - win->_firstch[y], win->_lastch[y], - win->_firstch[y] - win->_ch_off, - win->_lastch[y] - win->_ch_off); -# endif - } - } - win->_y[y][x++] = c; - if (x >= win->_maxx) { - x = 0; - newline: - if (++y >= win->_maxy) - if (win->_scroll) { - --y; - SYNCH_OUT(); - scroll(win); - SYNCH_IN(); - } - else - return ERR; - } -# ifdef FULLDEBUG - fprintf(outf, "ADDBYTES: 2: y = %d, x = %d, firstch = %d, lastch = %d\n", y, x, win->_firstch[y], win->_lastch[y]); -# endif - break; - case '\n': - SYNCH_OUT(); - wclrtoeol(win); - SYNCH_IN(); - if (!NONL) - x = 0; - goto newline; - case '\r': - x = 0; - break; - case '\b': - if (--x < 0) - x = 0; - break; - } - } - SYNCH_OUT(); - return OK; + default: +#ifdef DEBUG + __CTRACE("ADDBYTES(%0.2o, %d, %d)\n", win, y, x); +#endif + + lp = win->lines[y]; + if (lp->flags & __ISPASTEOL) { + lp->flags &= ~__ISPASTEOL; +newline: if (y == win->maxy - 1) { + if (win->flags & __SCROLLOK) { + SYNCH_OUT; + scroll(win); + SYNCH_IN; + lp = win->lines[y]; + x = 0; + } + else + return ERR; + } else { + y++; + lp = win->lines[y]; + x = 0; + } + if (c == '\n') + break; + } + + stand = '\0'; + if (win->flags & __WSTANDOUT || so) + stand |= __STANDOUT; +#ifdef DEBUG + __CTRACE("ADDBYTES: 1: y = %d, x = %d, firstch = %d, lastch = %d\n", + y, x, *win->lines[y]->firstchp, *win->lines[y]->lastchp); +#endif + if (lp->line[x].ch != c || + !(lp->line[x].attr & stand)) { + newx = x + win->ch_off; + if (!(lp->flags & __ISDIRTY)) { + lp->flags |= __ISDIRTY; + *lp->firstchp = *lp->lastchp = newx; + } + else if (newx < *lp->firstchp) + *lp->firstchp = newx; + else if (newx > *lp->lastchp) + *lp->lastchp = newx; +#ifdef DEBUG + __CTRACE("ADDBYTES: change gives f/l: %d/%d [%d/%d]\n", + *lp->firstchp, *lp->lastchp, + *lp->firstchp - win->ch_off, + *lp->lastchp - win->ch_off); +#endif + } + lp->line[x].ch = c; + if (stand) + lp->line[x].attr |= __STANDOUT; + else + lp->line[x].attr &= ~__STANDOUT; + if (x == win->maxx - 1) + lp->flags |= __ISPASTEOL; + else + x++; +#ifdef DEBUG + __CTRACE("ADDBYTES: 2: y = %d, x = %d, firstch = %d, lastch = %d\n", + y, x, *win->lines[y]->firstchp, *win->lines[y]->lastchp); +#endif + break; + case '\n': + SYNCH_OUT; + wclrtoeol(win); + SYNCH_IN; + if (!NONL) + x = 0; + goto newline; + case '\r': + x = 0; + break; + case '\b': + if (--x < 0) + x = 0; + break; + } + } + SYNCH_OUT; + return (OK); } diff --git a/lib/libcurses/addch.c b/lib/libcurses/addch.c index 027c4bf94476..d1408c21fe92 100644 --- a/lib/libcurses/addch.c +++ b/lib/libcurses/addch.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,19 +32,31 @@ */ #ifndef lint -static char sccsid[] = "@(#)addch.c 5.5 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)addch.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> /* - * This routine adds the character to the current position + * waddch -- + * Add the character to the current position in the given window. * */ -waddch(win, c) -WINDOW *win; -char c; +int +waddch(WINDOW *win, char ch) { - chtype ch = (unsigned char) c; - return _waddbytes(win, &ch, 1); + __LDATA buf; + + buf.ch = ch; + buf.attr = 0; + return (__waddch(win, &buf)); +} + +int +__waddch(WINDOW *win, __LDATA *dp) +{ + char buf[2]; + + buf[0] = dp->ch; + return (__waddbytes(win, buf, 1, dp->attr & __STANDOUT)); } diff --git a/lib/libcurses/endwin.c b/lib/libcurses/addnstr.c index aa740e6135bf..bf607a07a1f0 100644 --- a/lib/libcurses/endwin.c +++ b/lib/libcurses/addnstr.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,26 +32,30 @@ */ #ifndef lint -static char sccsid[] = "@(#)endwin.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)addnstr.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ + +#include <curses.h> +#include <string.h> /* - * Clean things up before exiting - * + * waddnstr -- + * Add a string (at most n characters) to the given window + * starting at (_cury, _curx). If n is negative, add the + * entire string. */ - -# include "curses.ext" - -endwin() +int +waddnstr(win, s, n) + WINDOW *win; + const char *s; + int n; { - resetty(); - _puts(VE); - _puts(TE); - if (curscr) { - if (curscr->_flags & _STANDOUT) { - _puts(SE); - curscr->_flags &= ~_STANDOUT; - } - _endwin = TRUE; - } + size_t len; + const char *p; + + if (n > 0) + for (p = s, len = 0; n-- && *p++; ++len); + else + len = strlen(s); + return (waddbytes(win, s, len)); } diff --git a/lib/libcurses/box.c b/lib/libcurses/box.c index 983ed66621ca..4f165b330692 100644 --- a/lib/libcurses/box.c +++ b/lib/libcurses/box.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,34 +32,45 @@ */ #ifndef lint -static char sccsid[] = "@(#)box.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)box.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> /* - * This routine draws a box around the given window with "vert" - * as the vertical delimiting char, and "hor", as the horizontal one. - * + * box -- + * Draw a box around the given window with "vert" as the vertical + * delimiting char, and "hor", as the horizontal one. */ -box(win, vert, hor) -reg WINDOW *win; -char vert, hor; { - - reg int i; - reg int endy, endx; - reg chtype *fp, *lp; +int +box(register WINDOW *win, char vert, char hor) +{ + register int endy, endx, i; + register __LDATA *fp, *lp; - endx = win->_maxx; - endy = win->_maxy - 1; - fp = win->_y[0]; - lp = win->_y[endy]; - for (i = 0; i < endx; i++) - fp[i] = lp[i] = (unsigned char) hor; + endx = win->maxx; + endy = win->maxy - 1; + fp = win->lines[0]->line; + lp = win->lines[endy]->line; + for (i = 0; i < endx; i++) { + fp[i].ch = lp[i].ch = hor; + fp[i].attr &= ~__STANDOUT; + lp[i].attr &= ~__STANDOUT; + } endx--; - for (i = 0; i <= endy; i++) - win->_y[i][0] = (win->_y[i][endx] = (unsigned char) vert); - if (!win->_scroll && (win->_flags&_SCROLLWIN)) - fp[0] = fp[endx] = lp[0] = lp[endx] = ' '; - touchwin(win); + for (i = 0; i <= endy; i++) { + win->lines[i]->line[0].ch = vert; + win->lines[i]->line[endx].ch = vert; + win->lines[i]->line[0].attr &= ~__STANDOUT; + win->lines[i]->line[endx].attr &= ~__STANDOUT; + } + if (!(win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN)) { + fp[0].ch = fp[endx].ch = lp[0].ch = lp[endx].ch = ' '; + fp[0].attr &= ~__STANDOUT; + fp[endx].attr &= ~__STANDOUT; + lp[0].attr &= ~__STANDOUT; + lp[endx].attr &= ~__STANDOUT; + } + __touchwin(win); + return (OK); } diff --git a/lib/libcurses/clear.c b/lib/libcurses/clear.c index a5884cbc4b11..89891e234975 100644 --- a/lib/libcurses/clear.c +++ b/lib/libcurses/clear.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,19 +32,22 @@ */ #ifndef lint -static char sccsid[] = "@(#)clear.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)clear.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> /* - * This routine clears the window. - * + * wclear -- + * Clear the window. */ +int wclear(win) -reg WINDOW *win; { - - werase(win); - win->_clear = TRUE; - return OK; + register WINDOW *win; +{ + if (werase(win) == OK) { + win->flags |= __CLEAROK; + return (OK); + } + return (ERR); } diff --git a/lib/libcurses/clrtobot.c b/lib/libcurses/clrtobot.c index 86324389956f..0e73ef88eb85 100644 --- a/lib/libcurses/clrtobot.c +++ b/lib/libcurses/clrtobot.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,35 +32,44 @@ */ #ifndef lint -static char sccsid[] = "@(#)clrtobot.c 5.5 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)clrtobot.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> /* - * This routine erases everything on the window. - * + * wclrtobot -- + * Erase everything on the window. */ +int wclrtobot(win) -reg WINDOW *win; { - - reg int y; - reg chtype *sp, *end, *maxx; - reg int startx, minx; + register WINDOW *win; +{ + register int minx, startx, starty, y; + register __LDATA *sp, *end, *maxx; - startx = win->_curx; - for (y = win->_cury; y < win->_maxy; y++) { - minx = _NOCHANGE; - end = &win->_y[y][win->_maxx]; - for (sp = &win->_y[y][startx]; sp < end; sp++) - if (*sp != ' ') { + if (win->lines[win->cury]->flags & __ISPASTEOL) { + starty = win->cury + 1; + startx = 0; + } else { + starty = win->cury; + startx = win->curx; + } + for (y = starty; y < win->maxy; y++) { + minx = -1; + end = &win->lines[y]->line[win->maxx]; + for (sp = &win->lines[y]->line[startx]; sp < end; sp++) + if (sp->ch != ' ' || sp->attr != 0) { maxx = sp; - if (minx == _NOCHANGE) - minx = sp - win->_y[y]; - *sp = ' '; + if (minx == -1) + minx = sp - win->lines[y]->line; + sp->ch = ' '; + sp->attr = 0; } - if (minx != _NOCHANGE) - touchline(win, y, minx, maxx - &win->_y[y][0]); + if (minx != -1) + __touchline(win, y, minx, maxx - win->lines[y]->line, + 0); startx = 0; } + return (OK); } diff --git a/lib/libcurses/clrtoeol.c b/lib/libcurses/clrtoeol.c index 6af2bfcededf..6fa63b420615 100644 --- a/lib/libcurses/clrtoeol.c +++ b/lib/libcurses/clrtoeol.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,40 +32,52 @@ */ #ifndef lint -static char sccsid[] = "@(#)clrtoeol.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)clrtoeol.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> /* - * This routine clears up to the end of line - * + * wclrtoeol -- + * Clear up to the end of line. */ +int wclrtoeol(win) -reg WINDOW *win; { - - reg chtype *sp, *end; - reg int y, x; - reg chtype *maxx; - reg int minx; + register WINDOW *win; +{ + register int minx, x, y; + register __LDATA *end, *maxx, *sp; - y = win->_cury; - x = win->_curx; - end = &win->_y[y][win->_maxx]; - minx = _NOCHANGE; - maxx = &win->_y[y][x]; + y = win->cury; + x = win->curx; + if (win->lines[y]->flags & __ISPASTEOL) { + if (y < win->maxy - 1) { + y++; + x = 0; + } else + return (OK); + } + end = &win->lines[y]->line[win->maxx]; + minx = -1; + maxx = &win->lines[y]->line[x]; for (sp = maxx; sp < end; sp++) - if (*sp != ' ') { + if (sp->ch != ' ' || sp->attr != 0) { maxx = sp; - if (minx == _NOCHANGE) - minx = sp - win->_y[y]; - *sp = ' '; + if (minx == -1) + minx = sp - win->lines[y]->line; + sp->ch = ' '; + sp->attr = 0; } - /* - * update firstch and lastch for the line - */ - touchline(win, y, win->_curx, win->_maxx - 1); -# ifdef DEBUG - fprintf(outf, "CLRTOEOL: minx = %d, maxx = %d, firstch = %d, lastch = %d\n", minx, maxx - win->_y[y], win->_firstch[y], win->_lastch[y]); -# endif +#ifdef DEBUG + __CTRACE("CLRTOEOL: minx = %d, maxx = %d, firstch = %d, lastch = %d\n", + minx, maxx - win->lines[y]->line, *win->lines[y]->firstchp, + *win->lines[y]->lastchp); +#endif + /* Update firstch and lastch for the line. */ + return (__touchline(win, y, x, win->maxx - 1, 0)); } + + + + + diff --git a/lib/libcurses/cr_put.c b/lib/libcurses/cr_put.c index c9d0e79134f1..b50875c91211 100644 --- a/lib/libcurses/cr_put.c +++ b/lib/libcurses/cr_put.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,51 +32,62 @@ */ #ifndef lint -static char sccsid[] = "@(#)cr_put.c 5.5 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)cr_put.c 8.2 (Berkeley) 1/9/94"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> +#include <string.h> -# define HARDTABS 8 - -extern char *tgoto(); -int plodput(); +#define HARDTABS 8 /* - * Terminal driving and line formatting routines. - * Basic motion optimizations are done here as well - * as formatting of lines (printing of control characters, + * Terminal driving and line formatting routines. Basic motion optimizations + * are done here as well as formatting lines (printing of control characters, * line numbering and the like). */ -/* - * Sync the position of the output cursor. - * Most work here is rounding for terminal boundaries getting the - * column position implied by wraparound or the lack thereof and - * rolling up the screen to get destline on the screen. - */ - -static int outcol, outline, destcol, destline; +/* Stub function for the users. */ +int +mvcur(ly, lx, y, x) + int ly, lx, y, x; +{ + return (__mvcur(ly, lx, y, x, 0)); +} -WINDOW *_win; +static void fgoto __P((int)); +static int plod __P((int, int)); +static void plodput __P((int)); +static int tabcol __P((int, int)); -mvcur(ly, lx, y, x) -int ly, lx, y, x; { +static int outcol, outline, destcol, destline; +/* + * Sync the position of the output cursor. Most work here is rounding for + * terminal boundaries getting the column position implied by wraparound or + * the lack thereof and rolling up the screen to get destline on the screen. + */ +int +__mvcur(ly, lx, y, x, in_refresh) + int ly, lx, y, x, in_refresh; +{ #ifdef DEBUG - fprintf(outf, "MVCUR: moving cursor from (%d,%d) to (%d,%d)\n", ly, lx, y, x); + __CTRACE("mvcur: moving cursor from (%d, %d) to (%d, %d)\n", + ly, lx, y, x); #endif destcol = x; destline = y; outcol = lx; outline = ly; - fgoto(); -} - -fgoto() + fgoto(in_refresh); + return (OK); +} + +static void +fgoto(in_refresh) + int in_refresh; { - reg char *cgp; - reg int l, c; + register int c, l; + register char *cgp; if (destcol >= COLS) { destline += destcol / COLS; @@ -88,15 +99,15 @@ fgoto() outcol %= COLS; if (AM == 0) { while (l > 0) { - if (_pfast) + if (__pfast) if (CR) - _puts(CR); + tputs(CR, 0, __cputchar); else - _putchar('\r'); + putchar('\r'); if (NL) - _puts(NL); + tputs(NL, 0, __cputchar); else - _putchar('\n'); + putchar('\n'); l--; } outcol = 0; @@ -111,36 +122,35 @@ fgoto() destline = LINES - 1; if (outline < LINES - 1) { c = destcol; - if (_pfast == 0 && !CA) + if (__pfast == 0 && !CA) destcol = 0; - fgoto(); + fgoto(in_refresh); destcol = c; } while (l >= LINES) { - /* - * The following linefeed (or simulation thereof) - * is supposed to scroll up the screen, since we - * are on the bottom line. We make the assumption - * that linefeed will scroll. If ns is in the - * capability list this won't work. We should - * probably have an sc capability but sf will - * generally take the place if it works. - * - * Superbee glitch: in the middle of the screen we - * have to use esc B (down) because linefeed screws up - * in "Efficient Paging" (what a joke) mode (which is - * essential in some SB's because CRLF mode puts garbage - * in at end of memory), but you must use linefeed to - * scroll since down arrow won't go past memory end. - * I turned this off after recieving Paul Eggert's - * Superbee description which wins better. + /* The following linefeed (or simulation thereof) is + * supposed to scroll up the screen, since we are on + * the bottom line. We make the assumption that + * linefeed will scroll. If ns is in the capability + * list this won't work. We should probably have an + * sc capability but sf will generally take the place + * if it works. + * + * Superbee glitch: in the middle of the screen have + * to use esc B (down) because linefeed screws up in + * "Efficient Paging" (what a joke) mode (which is + * essential in some SB's because CRLF mode puts + * garbage in at end of memory), but you must use + * linefeed to scroll since down arrow won't go past + * memory end. I turned this off after recieving Paul + * Eggert's Superbee description which wins better. */ - if (NL /* && !XB */ && _pfast) - _puts(NL); + if (NL /* && !XB */ && __pfast) + tputs(NL, 0, __cputchar); else - _putchar('\n'); + putchar('\n'); l--; - if (_pfast == 0) + if (__pfast == 0) outcol = 0; } } @@ -148,17 +158,20 @@ fgoto() destline = outline; if (CA) { cgp = tgoto(CM, destcol, destline); - if (plod(strlen(cgp)) > 0) - plod(0); - else - tputs(cgp, 0, _putchar); - } - else - plod(0); + + /* + * Need this condition due to inconsistent behavior + * of backspace on the last column. + */ + if (outcol != COLS - 1 && plod(strlen(cgp), in_refresh) > 0) + plod(0, in_refresh); + else + tputs(cgp, 0, __cputchar); + } else + plod(0, in_refresh); outline = destline; outcol = destcol; } - /* * Move (slowly) to destination. * Hard thing here is using home cursor on really deficient terminals. @@ -168,63 +181,63 @@ fgoto() static int plodcnt, plodflg; +static void plodput(c) + int c; { if (plodflg) - plodcnt--; + --plodcnt; else - _putchar(c); + putchar(c); } -plod(cnt) +static int +plod(cnt, in_refresh) + int cnt, in_refresh; { - register int i, j, k; - register int soutcol, soutline; - chtype ch; + register int i, j, k, soutcol, soutline; plodcnt = plodflg = cnt; soutcol = outcol; soutline = outline; /* - * Consider homing and moving down/right from there, vs moving + * Consider homing and moving down/right from there, vs. moving * directly with local motions to the right spot. */ if (HO) { /* - * i is the cost to home and tab/space to the right to - * get to the proper column. This assumes ND space costs - * 1 char. So i+destcol is cost of motion with home. + * i is the cost to home and tab/space to the right to get to + * the proper column. This assumes ND space costs 1 char. So + * i + destcol is cost of motion with home. */ if (GT) i = (destcol / HARDTABS) + (destcol % HARDTABS); else i = destcol; - /* - * j is cost to move locally without homing - */ + + /* j is cost to move locally without homing. */ if (destcol >= outcol) { /* if motion is to the right */ j = destcol / HARDTABS - outcol / HARDTABS; if (GT && j) j += destcol % HARDTABS; else j = destcol - outcol; - } - else + } else /* leftward motion only works if we can backspace. */ if (outcol - destcol <= i && (BS || BC)) - i = j = outcol - destcol; /* cheaper to backspace */ + /* Cheaper to backspace. */ + i = j = outcol - destcol; else - j = i + 1; /* impossibly expensive */ + /* Impossibly expensive. */ + j = i + 1; - /* k is the absolute value of vertical distance */ + /* k is the absolute value of vertical distance. */ k = outline - destline; if (k < 0) k = -k; j += k; - /* - * Decision. We may not have a choice if no UP. - */ + /* Decision. We may not have a choice if no UP. */ if (i + destline < j || (!UP && destline < outline)) { /* * Cheaper to home. Do it now and pretend it's a @@ -232,32 +245,29 @@ plod(cnt) */ tputs(HO, 0, plodput); outcol = outline = 0; - } - else if (LL) { + } else if (LL) { /* * Quickly consider homing down and moving from there. * Assume cost of LL is 2. */ k = (LINES - 1) - destline; - if (i + k + 2 < j && (k<=0 || UP)) { + if (i + k + 2 < j && (k <= 0 || UP)) { tputs(LL, 0, plodput); outcol = 0; outline = LINES - 1; } } - } - else - /* - * No home and no up means it's impossible. - */ + } else + /* No home and no up means it's impossible. */ if (!UP && destline < outline) - return -1; + return (-1); if (GT) i = destcol % HARDTABS + destcol / HARDTABS; else i = destcol; -/* - if (BT && outcol > destcol && (j = (((outcol+7) & ~7) - destcol - 1) >> 3)) { +#ifdef notdef + if (BT && outcol > destcol && + (j = (((outcol+7) & ~7) - destcol - 1) >> 3)) { j *= (k = strlen(BT)); if ((k += (destcol&7)) > 4) j += 8 - (destcol&7); @@ -265,28 +275,31 @@ plod(cnt) j += k; } else -*/ +#endif j = outcol - destcol; + /* - * If we will later need a \n which will turn into a \r\n by - * the system or the terminal, then don't bother to try to \r. + * If we will later need a \n which will turn into a \r\n by the + * system or the terminal, then don't bother to try to \r. */ - if ((NONL || !_pfast) && outline < destline) + if ((NONL || !__pfast) && outline < destline) goto dontcr; + /* - * If the terminal will do a \r\n and there isn't room for it, - * then we can't afford a \r. + * If the terminal will do a \r\n and there isn't room for it, then + * we can't afford a \r. */ if (NC && outline >= destline) goto dontcr; + /* - * If it will be cheaper, or if we can't back up, then send - * a return preliminarily. + * If it will be cheaper, or if we can't back up, then send a return + * preliminarily. */ if (j > i + 1 || outcol > destcol && !BS && !BC) { /* - * BUG: this doesn't take the (possibly long) length - * of CR into account. + * BUG: this doesn't take the (possibly long) length of CR + * into account. */ if (CR) tputs(CR, 0, plodput); @@ -301,8 +314,8 @@ plod(cnt) } outcol = 0; } -dontcr: - while (outline < destline) { + +dontcr: while (outline < destline) { outline++; if (NL) tputs(NL, 0, plodput); @@ -310,7 +323,7 @@ dontcr: plodput('\n'); if (plodcnt < 0) goto out; - if (NONL || _pfast == 0) + if (NONL || __pfast == 0) outcol = 0; } if (BT) @@ -318,14 +331,14 @@ dontcr: while (outcol > destcol) { if (plodcnt < 0) goto out; -/* +#ifdef notdef if (BT && outcol - destcol > k + 4) { tputs(BT, 0, plodput); outcol--; outcol &= ~7; continue; } -*/ +#endif outcol--; if (BC) tputs(BC, 0, plodput); @@ -366,36 +379,36 @@ dontcr: } while (outcol < destcol) { /* - * move one char to the right. We don't use ND space - * because it's better to just print the char we are - * moving over. + * Move one char to the right. We don't use ND space because + * it's better to just print the char we are moving over. */ - if (_win != NULL) - if (plodflg) /* avoid a complex calculation */ + if (in_refresh) + if (plodflg) /* Avoid a complex calculation. */ plodcnt--; else { - ch = curscr->_y[outline][outcol]; - if ((ch&_STANDOUT) == (curscr->_flags&_STANDOUT)) - _putchar(ch); + i = curscr->lines[outline]->line[outcol].ch; + if ((curscr->lines[outline]->line[outcol].attr + & __STANDOUT) == + (curscr->flags & __WSTANDOUT)) + putchar(i); else goto nondes; } else -nondes: - if (ND) - tputs(ND, 0, plodput); - else - plodput(' '); +nondes: if (ND) + tputs(ND, 0, plodput); + else + plodput(' '); outcol++; if (plodcnt < 0) goto out; } -out: - if (plodflg) { + +out: if (plodflg) { outcol = soutcol; outline = soutline; } - return(plodcnt); + return (plodcnt); } /* @@ -403,16 +416,16 @@ out: * hitting a tab, where tabs are set every ts columns. Work right for * the case where col > COLS, even if ts does not divide COLS. */ +static int tabcol(col, ts) -int col, ts; + int col, ts; { - int offset, result; + int offset; if (col >= COLS) { offset = COLS * (col / COLS); col -= offset; - } - else + } else offset = 0; - return col + ts - (col % ts) + offset; + return (col + ts - (col % ts) + offset); } diff --git a/lib/libcurses/cr_tty.c b/lib/libcurses/cr_tty.c deleted file mode 100644 index c67b0765ce2b..000000000000 --- a/lib/libcurses/cr_tty.c +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static char sccsid[] = "@(#)cr_tty.c 5.8 (Berkeley) 6/1/90"; -#endif /* not lint */ - -/* - * Terminal initialization routines. - * - */ - -# include "curses.ext" - -static bool *sflags[] = { - &AM, &BS, &DA, &DB, &EO, &HC, &HZ, &IN, &MI, - &MS, &NC, &NS, &OS, &UL, &XB, &XN, &XT, &XS, - &XX - }; - -static char *_PC, - **sstrs[] = { - &AL, &BC, &BT, &CD, &CE, &CL, &CM, &CR, &CS, - &DC, &DL, &DM, &DO, &ED, &EI, &K0, &K1, &K2, - &K3, &K4, &K5, &K6, &K7, &K8, &K9, &HO, &IC, - &IM, &IP, &KD, &KE, &KH, &KL, &KR, &KS, &KU, - &LL, &MA, &ND, &NL, &_PC, &RC, &SC, &SE, &SF, - &SO, &SR, &TA, &TE, &TI, &UC, &UE, &UP, &US, - &VB, &VS, &VE, &AL_PARM, &DL_PARM, &UP_PARM, - &DOWN_PARM, &LEFT_PARM, &RIGHT_PARM, - }; - -extern char *tgoto(); - -char _tspace[2048]; /* Space for capability strings */ - -static char *aoftspace; /* Address of _tspace for relocation */ - -static int destcol, destline; - -/* - * This routine does terminal type initialization routines, and - * calculation of flags at entry. It is almost entirely stolen from - * Bill Joy's ex version 2.6. - */ -short ospeed = -1; - -gettmode() { - - if (ioctl(_tty_ch, TIOCGETP, &_tty) < 0) - return; - savetty(); - if (ioctl(_tty_ch, TIOCSETP, &_tty) < 0) - _tty.sg_flags = _res_flg; - ospeed = _tty.sg_ospeed; - _res_flg = _tty.sg_flags; - UPPERCASE = (_tty.sg_flags & LCASE) != 0; - GT = ((_tty.sg_flags & XTABS) == 0); - NONL = ((_tty.sg_flags & CRMOD) == 0); - _tty.sg_flags &= ~XTABS; - ioctl(_tty_ch, TIOCSETP, &_tty); -# ifdef DEBUG - fprintf(outf, "GETTMODE: UPPERCASE = %s\n", UPPERCASE ? "TRUE":"FALSE"); - fprintf(outf, "GETTMODE: GT = %s\n", GT ? "TRUE" : "FALSE"); - fprintf(outf, "GETTMODE: NONL = %s\n", NONL ? "TRUE" : "FALSE"); - fprintf(outf, "GETTMODE: ospeed = %d\n", ospeed); -# endif -} - -setterm(type) -reg char *type; { - - reg int unknown; - static char genbuf[1024]; -# ifdef TIOCGWINSZ - struct winsize win; -# endif - -# ifdef DEBUG - fprintf(outf, "SETTERM(\"%s\")\n", type); - fprintf(outf, "SETTERM: LINES = %d, COLS = %d\n", LINES, COLS); -# endif - if (type[0] == '\0') - type = "xx"; - unknown = FALSE; - if (tgetent(genbuf, type) != 1) { - unknown++; - strcpy(genbuf, "xx|dumb:"); - } -# ifdef DEBUG - fprintf(outf, "SETTERM: tty = %s\n", type); -# endif -# ifdef TIOCGWINSZ - if (ioctl(_tty_ch, TIOCGWINSZ, &win) >= 0) { - if (LINES == 0) - LINES = win.ws_row; - if (COLS == 0) - COLS = win.ws_col; - } -# endif - - if (LINES == 0) - LINES = tgetnum("li"); - if (LINES <= 5) - LINES = 24; - - if (COLS == 0) - COLS = tgetnum("co"); - if (COLS <= 4) - COLS = 80; - -# ifdef DEBUG - fprintf(outf, "SETTERM: LINES = %d, COLS = %d\n", LINES, COLS); -# endif - aoftspace = _tspace; - zap(); /* get terminal description */ - - /* - * Handle funny termcap capabilities - */ - if (CS && SC && RC) AL=DL=""; - if (AL_PARM && AL==NULL) AL=""; - if (DL_PARM && DL==NULL) DL=""; - if (IC && IM==NULL) IM=""; - if (IC && EI==NULL) EI=""; - if (!GT) BT=NULL; /* If we can't tab, we can't backtab either */ - - if (tgoto(CM, destcol, destline)[0] == 'O') - CA = FALSE, CM = 0; - else - CA = TRUE; - - PC = _PC ? _PC[0] : FALSE; - aoftspace = _tspace; - { - /* xtype should be the same size as genbuf for longname(). */ - static char xtype[1024]; - - (void)strcpy(xtype,type); - strncpy(ttytype, longname(genbuf, xtype), sizeof(ttytype) - 1); - } - ttytype[sizeof(ttytype) - 1] = '\0'; - if (unknown) - return ERR; - return OK; -} - -/* - * This routine gets all the terminal flags from the termcap database - */ - -zap() -{ - register char *namp; - register bool **fp; - register char ***sp; -#ifdef DEBUG - register char *cp; -#endif - extern char *tgetstr(); - - namp = "ambsdadbeohchzinmimsncnsosulxbxnxtxsxx"; - fp = sflags; - do { - *(*fp++) = tgetflag(namp); -#ifdef DEBUG - fprintf(outf, "%2.2s = %s\n", namp, *fp[-1] ? "TRUE" : "FALSE"); -#endif - namp += 2; - } while (*namp); - namp = "albcbtcdceclcmcrcsdcdldmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullmandnlpcrcscsesfsosrtatetiucueupusvbvsveALDLUPDOLERI"; - sp = sstrs; - do { - *(*sp++) = tgetstr(namp, &aoftspace); -#ifdef DEBUG - fprintf(outf, "%2.2s = %s", namp, *sp[-1] == NULL ? "NULL\n" : "\""); - if (*sp[-1] != NULL) { - for (cp = *sp[-1]; *cp; cp++) - fprintf(outf, "%s", unctrl(*cp)); - fprintf(outf, "\"\n"); - } -#endif - namp += 2; - } while (*namp); - if (XS) - SO = SE = NULL; - else { - if (tgetnum("sg") > 0) - SO = NULL; - if (tgetnum("ug") > 0) - US = NULL; - if (!SO && US) { - SO = US; - SE = UE; - } - } -} - -/* - * return a capability from termcap - */ -char * -getcap(name) -char *name; -{ - char *tgetstr(); - - return tgetstr(name, &aoftspace); -} diff --git a/lib/libcurses/curses.ext b/lib/libcurses/ctrace.c index ff362297661a..4f53906cc5ee 100644 --- a/lib/libcurses/curses.ext +++ b/lib/libcurses/ctrace.c @@ -1,6 +1,6 @@ /*- - * Copyright (c) 1981 The Regents of the University of California. - * All rights reserved. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,30 +29,48 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * @(#)curses.ext 5.6 (Berkeley) 4/19/91 - */ - -/* - * External variables for the curses library */ -/* LINTLIBRARY */ - -# include "curses.h" - -extern bool _echoit, _rawmode, My_term, _endwin; - -extern char ttytype[50], *_unctrl[]; +#ifndef lint +static char sccsid[] = "@(#)ctrace.c 8.2 (Berkeley) 10/5/93"; +#endif /* not lint */ -extern int _tty_ch, LINES, COLS; +#ifdef DEBUG +#include <stdio.h> -extern SGTTY _tty; +#ifdef __STDC__ +#include <stdarg.h> +#else +#include <varargs.h> +#endif -char _putchar(); +#ifndef TFILE +#define TFILE "__curses.out" +#endif -#ifdef DEBUG -# define outf _outf +static FILE *tracefp; /* Curses debugging file descriptor. */ -FILE *outf; +void +#ifdef __STDC__ +__CTRACE(const char *fmt, ...) +#else +__CTRACE(fmt, va_alist) + char *fmt; + va_dcl +#endif +{ + va_list ap; +#ifdef __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + if (tracefp == NULL) + tracefp = fopen(TFILE, "w"); + if (tracefp == NULL) + return; + (void)vfprintf(tracefp, fmt, ap); + va_end(ap); + (void)fflush(tracefp); +} #endif diff --git a/lib/libcurses/addstr.c b/lib/libcurses/cur_hash.c index 025fd43d4a08..3aaaa925bd93 100644 --- a/lib/libcurses/addstr.c +++ b/lib/libcurses/cur_hash.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,28 +32,31 @@ */ #ifndef lint -static char sccsid[] = "@(#)addstr.c 5.5 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)cur_hash.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ + +#include <sys/types.h> -# include "curses.ext" /* - * This routine adds a string starting at (_cury,_curx) - * + * __hash() is "hashpjw" from the Dragon Book, Aho, Sethi & Ullman, p.436. */ -waddstr(win,str) -reg WINDOW *win; -char *str; +u_int +__hash(s, len) + char *s; + int len; { - chtype c; - reg char *s; -# ifdef DEBUG - fprintf(outf, "WADDSTR(\"%s\")\n", str); -# endif - for (s = str; *s;) { - c = (unsigned char) *s++; - if (_waddbytes(win, &c, 1) == ERR) - return ERR; + register u_int h, g, i; + + h = 0; + i = 0; + while (i < len) { + h = (h << 4) + (s[i] & 0xff); + if (g = h & 0xf0000000) { + h = h ^ (g >> 24); + h = h ^ g; + } + i++; } - return OK; + return h; } diff --git a/lib/libcurses/curses.3 b/lib/libcurses/curses.3 index 37b79419f947..cd3a18f152a4 100644 --- a/lib/libcurses/curses.3 +++ b/lib/libcurses/curses.3 @@ -1,5 +1,5 @@ -.\" Copyright (c) 1985, 1991 The Regents of the University of California. -.\" All rights reserved. +.\" Copyright (c) 1985, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -29,9 +29,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)curses.3 6.6 (Berkeley) 4/19/91 +.\" @(#)curses.3 8.1 (Berkeley) 6/4/93 .\" -.Dd April 19, 1991 +.Dd June 4, 1993 .Dt CURSES 3 .Os BSD 4 .Sh NAME diff --git a/lib/libcurses/curses.c b/lib/libcurses/curses.c index 3943595ca561..6a152772c750 100644 --- a/lib/libcurses/curses.c +++ b/lib/libcurses/curses.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,49 +32,47 @@ */ #ifndef lint -static char sccsid[] = "@(#)curses.c 5.7 (Berkeley) 6/1/90"; +static char sccsid[] = "@(#)curses.c 8.2 (Berkeley) 1/2/94"; #endif /* not lint */ -/* - * Define global variables - * - */ -# include "curses.h" - -bool _echoit = TRUE, /* set if stty indicates ECHO */ - _rawmode = FALSE,/* set if stty indicates RAW mode */ - My_term = FALSE,/* set if user specifies terminal type */ - _endwin = FALSE;/* set if endwin has been called */ - -char ttytype[50], /* long name of tty */ - *Def_term = "unknown"; /* default terminal type */ - -int _tty_ch = 0, /* file channel which is a tty */ - LINES, /* number of lines allowed on screen */ - COLS, /* number of columns allowed on screen */ - _res_flg; /* sgtty flags for reseting later */ - -WINDOW *stdscr = NULL, - *curscr = NULL; - -# ifdef DEBUG -FILE *outf; /* debug output file */ -# endif - -SGTTY _tty; /* tty modes */ - -bool AM, BS, CA, DA, DB, EO, HC, HZ, IN, MI, MS, NC, NS, OS, UL, XB, XN, - XT, XS, XX; -char *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL, *DM, - *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6, *K7, *K8, - *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL, *KR, *KS, *KU, - *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF, *SO, *SR, *TA, *TE, - *TI, *UC, *UE, *UP, *US, *VB, *VS, *VE, *AL_PARM, *DL_PARM, - *UP_PARM, *DOWN_PARM, *LEFT_PARM, *RIGHT_PARM; -char PC; +#include <curses.h> +/* Private. */ +int __echoit = 1; /* If stty indicates ECHO. */ +int __pfast; +int __rawmode = 0; /* If stty indicates RAW mode. */ +int __noqch = 0; /* + * If terminal doesn't have + * insert/delete line capabilities + * for quick change on refresh. + */ +int __usecs = 0; /* + * Use change scroll region, if + * no insert/delete capabilities + */ +char AM, BS, CA, DA, EO, HC, IN, MI, MS, NC, NS, OS, PC, + UL, XB, XN, XT, XS, XX; +char *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL, + *DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6, + *K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL, + *KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF, + *SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS, + *VE, *al, *dl, *sf, *sr, + *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, *LEFT_PARM, + *RIGHT_PARM; /* - * From the tty modes... + * Public. + * + * XXX + * UPPERCASE isn't used by libcurses, and is left for backward + * compatibility only. */ - -bool GT, NONL, UPPERCASE, normtty, _pfast; +WINDOW *curscr; /* Current screen. */ +WINDOW *stdscr; /* Standard screen. */ +int COLS; /* Columns on the screen. */ +int LINES; /* Lines on the screen. */ +int My_term = 0; /* Use Def_term regardless. */ +char *Def_term = "unknown"; /* Default terminal type. */ +char GT; /* Gtty indicates tabs. */ +char NONL; /* Term can't hack LF doing a CR. */ +char UPPERCASE; /* Terminal is uppercase only. */ diff --git a/lib/libcurses/curses.h b/lib/libcurses/curses.h index e845bb22878c..14e82deac58a 100644 --- a/lib/libcurses/curses.h +++ b/lib/libcurses/curses.h @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,190 +30,361 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)curses.h 5.9 (Berkeley) 7/1/90 + * @(#)curses.h 8.2 (Berkeley) 1/2/94 */ -#ifndef WINDOW +#ifndef _CURSES_H_ +#define _CURSES_H_ + +#include <sys/types.h> +#include <sys/cdefs.h> + +#include <stdio.h> + +#ifndef _BSD_VA_LIST_ +#define _BSD_VA_LIST_ char * +#endif + +/* + * The following #defines and #includes are present for backward + * compatibility only. They should not be used in future code. + * + * START BACKWARD COMPATIBILITY ONLY. + */ +#ifndef _CURSES_PRIVATE -#include <stdio.h> - -#define USE_OLD_TTY -#include <sys/ioctl.h> #undef USE_OLD_TTY +#undef B0 +#undef B50 +#undef B75 +#undef B110 +#undef B134 +#undef B150 +#undef B200 +#undef B300 +#undef B600 +#undef B1200 +#undef B1800 +#undef B2400 +#undef B4800 +#undef B9600 +#undef EXTA +#undef EXTB +#undef B57600 +#undef B115200 + +#include <termios.h> +#include <sys/ioctl.h> +#include <sys/ioctl_compat.h> /* For sgttyb and related */ #define bool char #define reg register -typedef unsigned short chtype; - +#ifndef TRUE #define TRUE (1) +#endif +#ifndef FALSE #define FALSE (0) -#define ERR (0) -#define OK (1) +#endif -#define _ENDLINE 001 -#define _FULLWIN 002 -#define _SCROLLWIN 004 -#define _FLUSH 010 -#define _FULLLINE 020 -#define _IDLINE 040 -#define _STANDOUT 0400 -#define _NOCHANGE -1 +#define _puts(s) tputs(s, 0, _putchar) -#define _puts(s) tputs(s, 0, _putchar) +/* Old-style terminal modes access. */ +#define baudrate() (cfgetospeed(&__baset)) +#define crmode() cbreak() +#define erasechar() (__baset.c_cc[VERASE]) +#define killchar() (__baset.c_cc[VKILL]) +#define nocrmode() nocbreak() +#define ospeed (cfgetospeed(&__baset)) -typedef struct sgttyb SGTTY; +/* WINDOW structure members name compatibility */ +#define _curx curx +#define _cury cury +#define _begx begx +#define _begy begy +#define _maxx maxx +#define _maxy maxy -/* - * Capabilities from termcap - */ +#define _tty __baset + +#endif /* _CURSES_PRIVATE */ -extern bool AM, BS, CA, DA, DB, EO, HC, HZ, IN, MI, MS, NC, NS, OS, UL, - XB, XN, XT, XS, XX; +extern char GT; /* Gtty indicates tabs. */ +extern char NONL; /* Term can't hack LF doing a CR. */ +extern char UPPERCASE; /* Terminal is uppercase only. */ + +extern int My_term; /* Use Def_term regardless. */ +extern char *Def_term; /* Default terminal type. */ + +/* Termcap capabilities. */ +extern char AM, BS, CA, DA, EO, HC, IN, MI, MS, NC, NS, OS, + PC, UL, XB, XN, XT, XS, XX; extern char *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL, *DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6, *K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL, *KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF, *SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS, - *VE, *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, - *LEFT_PARM, *RIGHT_PARM; -extern char PC; + *VE, *al, *dl, *sf, *sr, + *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, *LEFT_PARM, + *RIGHT_PARM; + +/* END BACKWARD COMPATIBILITY ONLY. */ + +/* 8-bit ASCII characters. */ +#define unctrl(c) __unctrl[(c) & 0xff] +#define unctrllen(ch) __unctrllen[(ch) & 0xff] + +extern char *__unctrl[256]; /* Control strings. */ +extern char __unctrllen[256]; /* Control strings length. */ /* - * From the tty modes... + * A window an array of __LINE structures pointed to by the 'lines' pointer. + * A line is an array of __LDATA structures pointed to by the 'line' pointer. + * + * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new + * fields are added -- padding fields with *constant values* should ensure + * that the compiler will not generate any padding when storing an array of + * __LDATA structures. This is to enable consistent use of memcmp, and memcpy + * for comparing and copying arrays. */ +typedef struct { + char ch; /* the actual character */ -extern bool GT, NONL, UPPERCASE, normtty, _pfast; +#define __STANDOUT 0x01 /* Added characters are standout. */ + char attr; /* attributes of character */ +} __LDATA; -struct _win_st { - short _cury, _curx; - short _maxy, _maxx; - short _begy, _begx; - short _flags; - short _ch_off; - bool _clear; - bool _leave; - bool _scroll; - chtype **_y; - short *_firstch; - short *_lastch; - struct _win_st *_nextp, *_orig; -}; +#define __LDATASIZE (sizeof(__LDATA)) -#define WINDOW struct _win_st +typedef struct { +#define __ISDIRTY 0x01 /* Line is dirty. */ +#define __ISPASTEOL 0x02 /* Cursor is past end of line */ +#define __FORCEPAINT 0x04 /* Force a repaint of the line */ + u_int flags; + u_int hash; /* Hash value for the line. */ + size_t *firstchp, *lastchp; /* First and last chngd columns ptrs */ + size_t firstch, lastch; /* First and last changed columns. */ + __LDATA *line; /* Pointer to the line text. */ +} __LINE; -extern bool My_term, _echoit, _rawmode, _endwin; +typedef struct __window { /* Window structure. */ + struct __window *nextp, *orig; /* Subwindows list and parent. */ + size_t begy, begx; /* Window home. */ + size_t cury, curx; /* Current x, y coordinates. */ + size_t maxy, maxx; /* Maximum values for curx, cury. */ + short ch_off; /* x offset for firstch/lastch. */ + __LINE **lines; /* Array of pointers to the lines */ + __LINE *lspace; /* line space (for cleanup) */ + __LDATA *wspace; /* window space (for cleanup) */ -extern char *Def_term, ttytype[]; +#define __ENDLINE 0x001 /* End of screen. */ +#define __FLUSH 0x002 /* Fflush(stdout) after refresh. */ +#define __FULLLINE 0x004 /* Line width = terminal width. */ +#define __FULLWIN 0x008 /* Window is a screen. */ +#define __IDLINE 0x010 /* Insert/delete sequences. */ +#define __SCROLLWIN 0x020 /* Last char will scroll window. */ +#define __SCROLLOK 0x040 /* Scrolling ok. */ +#define __CLEAROK 0x080 /* Clear on next refresh. */ +#define __WSTANDOUT 0x100 /* Standout window */ +#define __LEAVEOK 0x200 /* If curser left */ + u_int flags; +} WINDOW; -extern int LINES, COLS, _tty_ch, _res_flg; +/* Curses external declarations. */ +extern WINDOW *curscr; /* Current screen. */ +extern WINDOW *stdscr; /* Standard screen. */ -extern SGTTY _tty; +typedef struct termios SGTTY; -extern WINDOW *stdscr, *curscr; +extern SGTTY __orig_termios; /* Terminal state before curses */ +extern SGTTY __baset; /* Our base terminal state */ +extern int __tcaction; /* If terminal hardware set. */ -/* - * Define VOID to stop lint from generating "null effect" - * comments. - */ -#ifdef lint -int __void__; -#define VOID(x) (__void__ = (int) (x)) -#else -#define VOID(x) (x) -#endif +extern int COLS; /* Columns on the screen. */ +extern int LINES; /* Lines on the screen. */ -/* - * psuedo functions for standard screen - */ -#define addch(ch) VOID(waddch(stdscr, ch)) -#define getch() VOID(wgetch(stdscr)) -#define addbytes(da,co) VOID(waddbytes(stdscr, da,co)) -#define addstr(str) VOID(waddstr(stdscr, str)) -#define getstr(str) VOID(wgetstr(stdscr, str)) -#define move(y, x) VOID(wmove(stdscr, y, x)) -#define clear() VOID(wclear(stdscr)) -#define erase() VOID(werase(stdscr)) -#define clrtobot() VOID(wclrtobot(stdscr)) -#define clrtoeol() VOID(wclrtoeol(stdscr)) -#define insertln() VOID(winsertln(stdscr)) -#define deleteln() VOID(wdeleteln(stdscr)) -#define refresh() VOID(wrefresh(stdscr)) -#define inch() VOID(winch(stdscr)) -#define insch(c) VOID(winsch(stdscr,c)) -#define delch() VOID(wdelch(stdscr)) -#define standout() VOID(wstandout(stdscr)) -#define standend() VOID(wstandend(stdscr)) +extern char *ttytype; /* Full name of current terminal. */ -/* - * mv functions - */ -#define mvwaddch(win,y,x,ch) VOID(wmove(win,y,x)==ERR?ERR:waddch(win,ch)) -#define mvwgetch(win,y,x) VOID(wmove(win,y,x)==ERR?ERR:wgetch(win)) -#define mvwaddbytes(win,y,x,da,co) \ - VOID(wmove(win,y,x)==ERR?ERR:waddbytes(win,da,co)) -#define mvwaddstr(win,y,x,str) \ - VOID(wmove(win,y,x)==ERR?ERR:waddstr(win,str)) -#define mvwgetstr(win,y,x,str) VOID(wmove(win,y,x)==ERR?ERR:wgetstr(win,str)) -#define mvwinch(win,y,x) VOID(wmove(win,y,x) == ERR ? ERR : winch(win)) -#define mvwdelch(win,y,x) VOID(wmove(win,y,x) == ERR ? ERR : wdelch(win)) -#define mvwinsch(win,y,x,c) VOID(wmove(win,y,x) == ERR ? ERR:winsch(win,c)) -#define mvaddch(y,x,ch) mvwaddch(stdscr,y,x,ch) -#define mvgetch(y,x) mvwgetch(stdscr,y,x) -#define mvaddbytes(y,x,da,co) mvwaddbytes(stdscr,y,x,da,co) -#define mvaddstr(y,x,str) mvwaddstr(stdscr,y,x,str) -#define mvgetstr(y,x,str) mvwgetstr(stdscr,y,x,str) -#define mvinch(y,x) mvwinch(stdscr,y,x) -#define mvdelch(y,x) mvwdelch(stdscr,y,x) -#define mvinsch(y,x,c) mvwinsch(stdscr,y,x,c) +#define ERR (0) /* Error return. */ +#define OK (1) /* Success return. */ -/* - * psuedo functions - */ +/* Standard screen pseudo functions. */ +#define addbytes(s, n) __waddbytes(stdscr, s, n, 0) +#define addch(ch) waddch(stdscr, ch) +#define addnstr(s, n) waddnstr(stdscr, s, n) +#define addstr(s) __waddbytes(stdscr, s, strlen(s), 0) +#define clear() wclear(stdscr) +#define clrtobot() wclrtobot(stdscr) +#define clrtoeol() wclrtoeol(stdscr) +#define delch() wdelch(stdscr) +#define deleteln() wdeleteln(stdscr) +#define erase() werase(stdscr) +#define getch() wgetch(stdscr) +#define getstr(s) wgetstr(stdscr, s) +#define inch() winch(stdscr) +#define insch(ch) winsch(stdscr, ch) +#define insertln() winsertln(stdscr) +#define move(y, x) wmove(stdscr, y, x) +#define refresh() wrefresh(stdscr) +#define standend() wstandend(stdscr) +#define standout() wstandout(stdscr) +#define waddbytes(w, s, n) __waddbytes(w, s, n, 0) +#define waddstr(w, s) __waddbytes(w, s, strlen(s), 0) -#define clearok(win,bf) (win->_clear = bf) -#define leaveok(win,bf) (win->_leave = bf) -#define scrollok(win,bf) (win->_scroll = bf) -#define flushok(win,bf) (bf ? (win->_flags |= _FLUSH):(win->_flags &= ~_FLUSH)) -#define getyx(win,y,x) y = win->_cury, x = win->_curx -#define winch(win) (win->_y[win->_cury][win->_curx] & 0xFF) - -#define raw() (_tty.sg_flags|=RAW, _pfast=_rawmode=TRUE, \ - ioctl(_tty_ch, TIOCSETP, &_tty)) -#define noraw() (_tty.sg_flags&=~RAW,_rawmode=FALSE,\ - _pfast=!(_tty.sg_flags&CRMOD),ioctl(_tty_ch, TIOCSETP, &_tty)) -#define cbreak() (_tty.sg_flags |= CBREAK, _rawmode = TRUE, \ - ioctl(_tty_ch, TIOCSETP, &_tty)) -#define nocbreak() (_tty.sg_flags &= ~CBREAK,_rawmode=FALSE, \ - ioctl(_tty_ch, TIOCSETP, &_tty)) -#define crmode() cbreak() /* backwards compatability */ -#define nocrmode() nocbreak() /* backwards compatability */ -#define echo() (_tty.sg_flags |= ECHO, _echoit = TRUE, \ - ioctl(_tty_ch, TIOCSETP, &_tty)) -#define noecho() (_tty.sg_flags &= ~ECHO, _echoit = FALSE, \ - ioctl(_tty_ch, TIOCSETP, &_tty)) -#define nl() (_tty.sg_flags |= CRMOD,_pfast = _rawmode, \ - ioctl(_tty_ch, TIOCSETP, &_tty)) -#define nonl() (_tty.sg_flags &= ~CRMOD, _pfast = TRUE, \ - ioctl(_tty_ch, TIOCSETP, &_tty)) -#define savetty() ((void) ioctl(_tty_ch, TIOCGETP, &_tty), \ - _res_flg = _tty.sg_flags) -#define resetty() (_tty.sg_flags = _res_flg, \ - _echoit = ((_res_flg & ECHO) == ECHO), \ - _rawmode = ((_res_flg & (CBREAK|RAW)) != 0), \ - _pfast = ((_res_flg & CRMOD) ? _rawmode : TRUE), \ - (void) ioctl(_tty_ch, TIOCSETP, &_tty)) - -#define erasechar() (_tty.sg_erase) -#define killchar() (_tty.sg_kill) -#define baudrate() (_tty.sg_ospeed) - -WINDOW *initscr(), *newwin(), *subwin(); -char *longname(), *getcap(); +/* Standard screen plus movement pseudo functions. */ +#define mvaddbytes(y, x, s, n) mvwaddbytes(stdscr, y, x, s, n) +#define mvaddch(y, x, ch) mvwaddch(stdscr, y, x, ch) +#define mvaddnstr(y, x, s, n) mvwaddnstr(stdscr, y, x, s, n) +#define mvaddstr(y, x, s) mvwaddstr(stdscr, y, x, s) +#define mvdelch(y, x) mvwdelch(stdscr, y, x) +#define mvgetch(y, x) mvwgetch(stdscr, y, x) +#define mvgetstr(y, x, s) mvwgetstr(stdscr, y, x, s) +#define mvinch(y, x) mvwinch(stdscr, y, x) +#define mvinsch(y, x, c) mvwinsch(stdscr, y, x, c) +#define mvwaddbytes(w, y, x, s, n) \ + (wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, n, 0)) +#define mvwaddch(w, y, x, ch) \ + (wmove(w, y, x) == ERR ? ERR : waddch(w, ch)) +#define mvwaddnstr(w, y, x, s, n) \ + (wmove(w, y, x) == ERR ? ERR : waddnstr(w, s, n)) +#define mvwaddstr(w, y, x, s) \ + (wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, strlen(s), 0)) +#define mvwdelch(w, y, x) \ + (wmove(w, y, x) == ERR ? ERR : wdelch(w)) +#define mvwgetch(w, y, x) \ + (wmove(w, y, x) == ERR ? ERR : wgetch(w)) +#define mvwgetstr(w, y, x, s) \ + (wmove(w, y, x) == ERR ? ERR : wgetstr(w, s)) +#define mvwinch(w, y, x) \ + (wmove(w, y, x) == ERR ? ERR : winch(w)) +#define mvwinsch(w, y, x, c) \ + (wmove(w, y, x) == ERR ? ERR : winsch(w, c)) + +/* Psuedo functions. */ +#define clearok(w, bf) \ + ((bf) ? ((w)->flags |= __CLEAROK) : ((w)->flags &= ~__CLEAROK)) +#define flushok(w, bf) \ + ((bf) ? ((w)->flags |= __FLUSH) : ((w)->flags &= ~__FLUSH)) +#define getyx(w, y, x) \ + (y) = (w)->cury, (x) = (w)->curx +#define leaveok(w, bf) \ + ((bf) ? ((w)->flags |= __LEAVEOK) : ((w)->flags &= ~__LEAVEOK)) +#define scrollok(w, bf) \ + ((bf) ? ((w)->flags |= __SCROLLOK) : ((w)->flags &= ~__SCROLLOK)) +#define winch(w) \ + ((w)->lines[(w)->cury]->line[(w)->curx].ch & 0xff) + +/* Public function prototypes. */ +int box __P((WINDOW *, char, char)); +int cbreak __P((void)); +int delwin __P((WINDOW *)); +int echo __P((void)); +int endwin __P((void)); +char *fullname __P((char *, char *)); +char *getcap __P((char *)); +int gettmode __P((void)); +void idlok __P((WINDOW *, int)); +WINDOW *initscr __P((void)); +char *longname __P((char *, char *)); +int mvcur __P((int, int, int, int)); +int mvprintw __P((int, int, const char *, ...)); +int mvscanw __P((int, int, const char *, ...)); +int mvwin __P((WINDOW *, int, int)); +int mvwprintw __P((WINDOW *, int, int, const char *, ...)); +int mvwscanw __P((WINDOW *, int, int, const char *, ...)); +WINDOW *newwin __P((int, int, int, int)); +int nl __P((void)); +int nocbreak __P((void)); +int noecho __P((void)); +int nonl __P((void)); +int noraw __P((void)); +int overlay __P((WINDOW *, WINDOW *)); +int overwrite __P((WINDOW *, WINDOW *)); +int printw __P((const char *, ...)); +int raw __P((void)); +int resetty __P((void)); +int savetty __P((void)); +int scanw __P((const char *, ...)); +int scroll __P((WINDOW *)); +int setterm __P((char *)); +int sscans __P((WINDOW *, const char *, ...)); +WINDOW *subwin __P((WINDOW *, int, int, int, int)); +int suspendwin __P((void)); +int touchline __P((WINDOW *, int, int, int)); +int touchoverlap __P((WINDOW *, WINDOW *)); +int touchwin __P((WINDOW *)); +int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_)); +int vwscanw __P((WINDOW *, const char *, _BSD_VA_LIST_)); +int waddch __P((WINDOW *, char)); +int waddnstr __P((WINDOW *, const char *, int)); +int wclear __P((WINDOW *)); +int wclrtobot __P((WINDOW *)); +int wclrtoeol __P((WINDOW *)); +int wdelch __P((WINDOW *)); +int wdeleteln __P((WINDOW *)); +int werase __P((WINDOW *)); +int wgetch __P((WINDOW *)); +int wgetstr __P((WINDOW *, char *)); +int winsch __P((WINDOW *, char)); +int winsertln __P((WINDOW *)); +int wmove __P((WINDOW *, int, int)); +int wprintw __P((WINDOW *, const char *, ...)); +int wrefresh __P((WINDOW *)); +int wscanw __P((WINDOW *, const char *, ...)); +int wstandend __P((WINDOW *)); +int wstandout __P((WINDOW *)); +int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_)); + +/* Private functions that are needed for user programs prototypes. */ +int __waddbytes __P((WINDOW *, const char *, int, int)); + +/* Private functions. */ +#ifdef _CURSES_PRIVATE + +#define __cputchar _putchar +void _putchar __P((int)); + +void __CTRACE __P((const char *, ...)); +u_int __hash __P((char *, int)); +void __id_subwins __P((WINDOW *)); +int __mvcur __P((int, int, int, int, int)); +void __restore_stophandler __P((void)); +void __set_stophandler __P((void)); +void __set_subwin __P((WINDOW *, WINDOW *)); +void __set_scroll_region __P((int, int)); +void __startwin __P((void)); +void __stop_signal_handler __P((int)); +void __swflags __P((WINDOW *)); +int __touchline __P((WINDOW *, int, int, int, int)); +int __touchwin __P((WINDOW *)); +char *__tscroll __P((const char *, int)); +int __waddch __P((WINDOW *, __LDATA *)); + +/* Private #defines. */ +#define min(a,b) (a < b ? a : b) +#define max(a,b) (a > b ? a : b) + +/* Private externs. */ +extern int __echoit; +extern int __endwin; +extern int __pfast; +extern int __rawmode; +extern int __noqch; +extern int __usecs; + +int tputs __P((char *, int, void (*)(int))); + +#else + +int tputs __P((char *, int, int (*)(int))); -/* - * Used to be in unctrl.h. - */ -#define unctrl(c) _unctrl[(c) & 0177] -extern char *_unctrl[]; #endif + +/* Termcap functions. */ +int tgetent __P((char *, char *)); +int tgetnum __P((char *)); +int tgetflag __P((char *)); +char *tgetstr __P((char *, char **)); +char *tgoto __P((char *, int, int)); + +#endif /* !_CURSES_H_ */ diff --git a/lib/libcurses/delch.c b/lib/libcurses/delch.c index 23499eb55490..ad7d3526eeb1 100644 --- a/lib/libcurses/delch.c +++ b/lib/libcurses/delch.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,28 +32,31 @@ */ #ifndef lint -static char sccsid[] = "@(#)delch.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)delch.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> +#include <string.h> /* - * This routine performs an insert-char on the line, leaving - * (_cury,_curx) unchanged. - * + * wdelch -- + * Do an insert-char on the line, leaving (cury, curx) unchanged. */ +int wdelch(win) -reg WINDOW *win; { - - reg chtype *temp1, *temp2; - reg chtype *end; + register WINDOW *win; +{ + register __LDATA *end, *temp1, *temp2; - end = &win->_y[win->_cury][win->_maxx - 1]; - temp1 = &win->_y[win->_cury][win->_curx]; + end = &win->lines[win->cury]->line[win->maxx - 1]; + temp1 = &win->lines[win->cury]->line[win->curx]; temp2 = temp1 + 1; - while (temp1 < end) - *temp1++ = *temp2++; - *temp1 = ' '; - touchline(win, win->_cury, win->_curx, win->_maxx - 1); - return OK; + while (temp1 < end) { + (void)memcpy(temp1, temp2, sizeof(__LDATA)); + temp1++, temp2++; + } + temp1->ch = ' '; + temp1->attr = 0; + __touchline(win, win->cury, win->curx, win->maxx - 1, 0); + return (OK); } diff --git a/lib/libcurses/deleteln.c b/lib/libcurses/deleteln.c index ba5d4819743e..6c4688acb5e7 100644 --- a/lib/libcurses/deleteln.c +++ b/lib/libcurses/deleteln.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,43 +32,50 @@ */ #ifndef lint -static char sccsid[] = "@(#)deleteln.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)deleteln.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> +#include <string.h> /* - * This routine deletes a line from the screen. It leaves - * (_cury,_curx) unchanged. - * + * wdeleteln -- + * Delete a line from the screen. It leaves (cury, curx) unchanged. */ +int wdeleteln(win) -reg WINDOW *win; + register WINDOW *win; { - reg chtype *temp; - reg int y; - reg chtype *end; - reg int x; + register int y, i; + register __LINE *temp; -# ifdef DEBUG - fprintf(outf, "DELETELN(%0.2o)\n", win); -# endif - temp = win->_y[win->_cury]; - for (y = win->_cury; y < win->_maxy - 1; y++) { - if (win->_orig == NULL) - win->_y[y] = win->_y[y + 1]; +#ifdef DEBUG + __CTRACE("deleteln: (%0.2o)\n", win); +#endif + temp = win->lines[win->cury]; + for (y = win->cury; y < win->maxy - 1; y++) { + win->lines[y]->flags &= ~__ISPASTEOL; + win->lines[y + 1]->flags &= ~__ISPASTEOL; + if (win->orig == NULL) + win->lines[y] = win->lines[y + 1]; else - bcopy(win->_y[y + 1], win->_y[y], win->_maxx * sizeof(chtype)); - touchline(win, y, 0, win->_maxx - 1); + (void) memcpy(win->lines[y]->line, + win->lines[y + 1]->line, + win->maxx * __LDATASIZE); + __touchline(win, y, 0, win->maxx - 1, 0); } - if (win->_orig == NULL) - win->_y[y] = temp; + + if (win->orig == NULL) + win->lines[y] = temp; else - temp = win->_y[y]; - for (end = &temp[win->_maxx]; temp < end; ) - *temp++ = ' '; - touchline(win, y, 0, win->_maxx - 1); - if (win->_orig == NULL) - _id_subwins(win); - return OK; + temp = win->lines[y]; + + for(i = 0; i < win->maxx; i++) { + temp->line[i].ch = ' '; + temp->line[i].attr = 0; + } + __touchline(win, y, 0, win->maxx - 1, 0); + if (win->orig == NULL) + __id_subwins(win); + return (OK); } diff --git a/lib/libcurses/delwin.c b/lib/libcurses/delwin.c index 6935f87550f1..3f6848a56b62 100644 --- a/lib/libcurses/delwin.c +++ b/lib/libcurses/delwin.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,48 +32,48 @@ */ #ifndef lint -static char sccsid[] = "@(#)delwin.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)delwin.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> +#include <stdlib.h> /* - * This routine deletes a window and releases it back to the system. - * + * delwin -- + * Delete a window and release it back to the system. */ +int delwin(win) -reg WINDOW *win; { + register WINDOW *win; +{ - reg int i; - reg WINDOW *wp, *np; + register WINDOW *wp, *np; - if (win->_orig == NULL) { + if (win->orig == NULL) { /* - * If we are the original window, delete the space for - * all the subwindows, and the array of space as well. + * If we are the original window, delete the space for all + * the subwindows, the line space and the window space. */ - for (i = 0; i < win->_maxy && win->_y[i]; i++) - free(win->_y[i]); - free(win->_firstch); - free(win->_lastch); - wp = win->_nextp; + free(win->lspace); + free(win->wspace); + free(win->lines); + wp = win->nextp; while (wp != win) { - np = wp->_nextp; + np = wp->nextp; delwin(wp); wp = np; } - } - else { + } else { /* - * If we are a subwindow, take ourselves out of the - * list. NOTE: if we are a subwindow, the minimum list - * is orig followed by this subwindow, so there are - * always at least two windows in the list. + * If we are a subwindow, take ourselves out of the list. + * NOTE: if we are a subwindow, the minimum list is orig + * followed by this subwindow, so there are always at least + * two windows in the list. */ - for (wp = win->_nextp; wp->_nextp != win; wp = wp->_nextp) + for (wp = win->nextp; wp->nextp != win; wp = wp->nextp) continue; - wp->_nextp = win->_nextp; + wp->nextp = win->nextp; } - free(win->_y); free(win); + return (OK); } diff --git a/lib/libcurses/erase.c b/lib/libcurses/erase.c index 9cbd79e7fd46..b19e15b3fc42 100644 --- a/lib/libcurses/erase.c +++ b/lib/libcurses/erase.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,38 +32,41 @@ */ #ifndef lint -static char sccsid[] = "@(#)erase.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)erase.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> /* - * This routine erases everything on the window. - * + * werase -- + * Erases everything on the window. */ +int werase(win) -reg WINDOW *win; { + register WINDOW *win; +{ - reg int y; - reg chtype *sp, *end, *start, *maxx; - reg int minx; + register int minx, y; + register __LDATA *sp, *end, *start, *maxx; -# ifdef DEBUG - fprintf(outf, "WERASE(%0.2o)\n", win); -# endif - for (y = 0; y < win->_maxy; y++) { - minx = _NOCHANGE; - start = win->_y[y]; - end = &start[win->_maxx]; +#ifdef DEBUG + __CTRACE("werase: (%0.2o)\n", win); +#endif + for (y = 0; y < win->maxy; y++) { + minx = -1; + start = win->lines[y]->line; + end = &start[win->maxx]; for (sp = start; sp < end; sp++) - if (*sp != ' ') { - maxx = sp; - if (minx == _NOCHANGE) + if (sp->ch != ' ' || sp->attr != 0) { + maxx = sp; + if (minx == -1) minx = sp - start; - *sp = ' '; + sp->ch = ' '; + sp->attr = 0; } - if (minx != _NOCHANGE) - touchline(win, y, minx, maxx - win->_y[y]); + if (minx != -1) + __touchline(win, y, minx, maxx - win->lines[y]->line, + 0); } - win->_curx = win->_cury = 0; + return (OK); } diff --git a/lib/libcurses/fullname.c b/lib/libcurses/fullname.c index 11cf4cbe5408..3d05e5d6ef81 100644 --- a/lib/libcurses/fullname.c +++ b/lib/libcurses/fullname.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,34 +32,29 @@ */ #ifndef lint -static char sccsid[] = "@(#)fullname.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ - -# define reg register +static char sccsid[] = "@(#)fullname.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ /* + * fullname -- * This routine fills in "def" with the full name of the terminal. - * This is assumed to be the last name in the list of aliases. - * + * This is assumed to be the last name in the list of aliases. */ char * fullname(bp, def) -reg char *bp, *def; + register char *bp, *def; { + register char *cp; - reg char *cp; - - *def = 0; /* in case no name */ + *def = '\0'; /* In case no name. */ while (*bp && *bp != ':') { - cp = def; /* start of answer */ - while (*bp && *bp != ':' && *bp != '|') { - *cp++ = *bp++; /* copy name over */ - } - *cp = 0; /* zero end of name */ - if (*bp == '|') { - bp++; /* skip over '|' if that is case */ - } + cp = def; /* Start of answer. */ + while (*bp && *bp != ':' && *bp != '|') + *cp++ = *bp++; /* Copy name over. */ + *cp = '\0'; /* Zero end of name. */ + if (*bp == '|') + bp++; /* Skip over '|' if that is case. */ } - return(def); + return (def); } diff --git a/lib/libcurses/getch.c b/lib/libcurses/getch.c index d3e04d08f667..d260db11bc51 100644 --- a/lib/libcurses/getch.c +++ b/lib/libcurses/getch.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,43 +32,46 @@ */ #ifndef lint -static char sccsid[] = "@(#)getch.c 5.6 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)getch.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> /* - * This routine reads in a character from the window. - * + * wgetch -- + * Read in a character from the window. */ +int wgetch(win) -reg WINDOW *win; { - - reg bool weset = FALSE; - reg int inp; + register WINDOW *win; +{ + register int inp, weset; - if (!win->_scroll && (win->_flags&_FULLWIN) - && win->_curx == win->_maxx - 1 && win->_cury == win->_maxy - 1) - return ERR; -# ifdef DEBUG - fprintf(outf, "WGETCH: _echoit = %c, _rawmode = %c\n", _echoit ? 'T' : 'F', _rawmode ? 'T' : 'F'); -# endif - if (_echoit && !_rawmode) { + if (!(win->flags & __SCROLLOK) && (win->flags & __FULLWIN) + && win->curx == win->maxx - 1 && win->cury == win->maxy - 1) + return (ERR); +#ifdef DEBUG + __CTRACE("wgetch: __echoit = %d, __rawmode = %d\n", + __echoit, __rawmode); +#endif + if (__echoit && !__rawmode) { cbreak(); - weset++; - } + weset = 1; + } else + weset = 0; + inp = getchar(); if (inp != EOF) { -# ifdef DEBUG - fprintf(outf,"WGETCH got '%s'\n",unctrl(inp)); -# endif - if (_echoit) { - mvwaddch(curscr, win->_cury + win->_begy, - win->_curx + win->_begx, (unsigned char) inp); - waddch(win, (unsigned char) inp); +#ifdef DEBUG + __CTRACE("wgetch got '%s'\n", unctrl(inp)); +#endif + if (__echoit) { + mvwaddch(curscr, + win->cury + win->begy, win->curx + win->begx, inp); + waddch(win, inp); } } if (weset) nocbreak(); - return inp; + return (inp); } diff --git a/lib/libcurses/getstr.c b/lib/libcurses/getstr.c index ec3af26fe7ae..97305b807110 100644 --- a/lib/libcurses/getstr.c +++ b/lib/libcurses/getstr.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,24 +32,26 @@ */ #ifndef lint -static char sccsid[] = "@(#)getstr.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)getstr.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> /* - * This routine gets a string starting at (_cury,_curx) - * + * wgetstr -- + * Get a string starting at (cury, curx). */ -wgetstr(win,str) -reg WINDOW *win; -reg char *str; { +int +wgetstr(win, str) + register WINDOW *win; + register char *str; +{ int c; while ((c = wgetch(win)) != ERR && c != EOF && c != '\n') *str++ = c; - *str = '\0'; + *str = '\0'; if (c == ERR) - return ERR; - return OK; + return (ERR); + return (OK); } diff --git a/lib/libcurses/id_subwins.c b/lib/libcurses/id_subwins.c index 9bbc3bc16a85..6dc715c2572f 100644 --- a/lib/libcurses/id_subwins.c +++ b/lib/libcurses/id_subwins.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,34 +32,34 @@ */ #ifndef lint -static char sccsid[] = "@(#)id_subwins.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)id_subwins.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> /* - * _id_subwins: - * Re-sync the pointers to _y for all the subwindows. - * + * __id_subwins -- + * Re-sync the pointers to lines for all the subwindows. */ -_id_subwins(orig) -register WINDOW *orig; +void +__id_subwins(orig) + register WINDOW *orig; { - register WINDOW *win; - register int realy; - register int y, oy, x; + register WINDOW *win; + register int oy, realy, y; - realy = orig->_begy + orig->_cury; - for (win = orig->_nextp; win != orig; win = win->_nextp) { + realy = orig->begy + orig->cury; + for (win = orig->nextp; win != orig; win = win->nextp) { /* - * If the window ends before our current position, - * don't need to do anything. + * If the window ends before our current position, don't need + * to do anything. */ - if (win->_begy + win->_maxy <= realy) + if (win->begy + win->maxy <= realy) continue; - oy = orig->_cury; - for (y = realy - win->_begy; y < win->_maxy; y++, oy++) - win->_y[y] = &orig->_y[oy][win->_ch_off]; + oy = orig->cury; + for (y = realy - win->begy; y < win->maxy; y++, oy++) + win->lines[y]->line = + &orig->lines[oy]->line[win->ch_off]; } } diff --git a/lib/libcurses/idlok.c b/lib/libcurses/idlok.c index 92566b20b35c..ef0a1e20d8ba 100644 --- a/lib/libcurses/idlok.c +++ b/lib/libcurses/idlok.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,23 +32,23 @@ */ #ifndef lint -static char sccsid[] = "@(#)idlok.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)idlok.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> /* - * idlok: - * Turn on and off using insert/deleteln sequences for the given - * window. - * + * idlok -- + * Turn on and off using insert/deleteln sequences for the + * given window. */ +void idlok(win, bf) -register WINDOW *win; -bool bf; + WINDOW *win; + int bf; { if (bf) - win->_flags |= _IDLINE; + win->flags |= __IDLINE; else - win->_flags &= ~_IDLINE; + win->flags &= ~__IDLINE; } diff --git a/lib/libcurses/initscr.c b/lib/libcurses/initscr.c index 5dd97e8b2255..8ed0f9f769a1 100644 --- a/lib/libcurses/initscr.c +++ b/lib/libcurses/initscr.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,62 +32,63 @@ */ #ifndef lint -static char sccsid[] = "@(#)initscr.c 5.6 (Berkeley) 3/3/91"; -#endif /* not lint */ +static char sccsid[] = "@(#)initscr.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" -# include <signal.h> - -extern char *getenv(); +#include <curses.h> +#include <signal.h> +#include <stdlib.h> /* - * This routine initializes the current and standard screen. - * + * initscr -- + * Initialize the current and standard screen. */ WINDOW * -initscr() { +initscr() +{ + register char *sp; - reg char *sp; - void tstp(); +#ifdef DEBUG + __CTRACE("initscr\n"); +#endif + __echoit = 1; + __pfast = __rawmode = __noqch = 0; -# ifdef DEBUG - fprintf(outf, "INITSCR()\n"); -# endif - if (My_term) - setterm(Def_term); - else { - gettmode(); - if ((sp = getenv("TERM")) == NULL) - sp = Def_term; - setterm(sp); -# ifdef DEBUG - fprintf(outf, "INITSCR: term = %s\n", sp); -# endif - } - _puts(TI); - _puts(VS); -# ifdef SIGTSTP - signal(SIGTSTP, tstp); -# endif - if (curscr != NULL) { -# ifdef DEBUG - fprintf(outf, "INITSCR: curscr = 0%o\n", curscr); -# endif + if (gettmode() == ERR) + return (NULL); + + /* + * If My_term is set, or can't find a terminal in the environment, + * use Def_term. + */ + if (My_term || (sp = getenv("TERM")) == NULL) + sp = Def_term; + if (setterm(sp) == ERR) + return (NULL); + + /* Need either homing or cursor motion for refreshes */ + if (!HO && !CM) + return (NULL); + + if (curscr != NULL) delwin(curscr); - } -# ifdef DEBUG - fprintf(outf, "LINES = %d, COLS = %d\n", LINES, COLS); -# endif if ((curscr = newwin(LINES, COLS, 0, 0)) == ERR) - return ERR; - clearok(curscr, TRUE); - curscr->_flags &= ~_FULLLINE; - if (stdscr != NULL) { -# ifdef DEBUG - fprintf(outf, "INITSCR: stdscr = 0%o\n", stdscr); -# endif + return (NULL); + clearok(curscr, 1); + + if (stdscr != NULL) delwin(stdscr); + if ((stdscr = newwin(LINES, COLS, 0, 0)) == ERR) { + delwin(curscr); + return (NULL); } - stdscr = newwin(LINES, COLS, 0, 0); - return stdscr; + + __set_stophandler(); + +#ifdef DEBUG + __CTRACE("initscr: LINES = %d, COLS = %d\n", LINES, COLS); +#endif + __startwin(); + + return (stdscr); } diff --git a/lib/libcurses/insch.c b/lib/libcurses/insch.c index 5ec1c9a7d861..e9b389ba1ea7 100644 --- a/lib/libcurses/insch.c +++ b/lib/libcurses/insch.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,37 +32,41 @@ */ #ifndef lint -static char sccsid[] = "@(#)insch.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)insch.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> +#include <string.h> /* - * This routine performs an insert-char on the line, leaving - * (_cury,_curx) unchanged. - * + * winsch -- + * Do an insert-char on the line, leaving (cury, curx) unchanged. */ -winsch(win, c) -reg WINDOW *win; -char c; { +int +winsch(register WINDOW *win, char ch) +{ - reg chtype *temp1, *temp2; - reg chtype *end; + register __LDATA *end, *temp1, *temp2; - end = &win->_y[win->_cury][win->_curx]; - temp1 = &win->_y[win->_cury][win->_maxx - 1]; + end = &win->lines[win->cury]->line[win->curx]; + temp1 = &win->lines[win->cury]->line[win->maxx - 1]; temp2 = temp1 - 1; - while (temp1 > end) - *temp1-- = *temp2--; - *temp1 = (unsigned char) c; - touchline(win, win->_cury, win->_curx, win->_maxx - 1); - if (win->_cury == LINES - 1 && win->_y[LINES-1][COLS-1] != ' ') - if (win->_scroll) { + while (temp1 > end) { + (void)memcpy(temp1, temp2, sizeof(__LDATA)); + temp1--, temp2--; + } + temp1->ch = ch; + temp1->attr &= ~__STANDOUT; + __touchline(win, win->cury, win->curx, win->maxx - 1, 0); + if (win->cury == LINES - 1 && + (win->lines[LINES - 1]->line[COLS - 1].ch != ' ' || + win->lines[LINES -1]->line[COLS - 1].attr != 0)) + if (win->flags & __SCROLLOK) { wrefresh(win); scroll(win); - win->_cury--; - } - else - return ERR; - return OK; + win->cury--; + + } else + return (ERR); + return (OK); } diff --git a/lib/libcurses/insertln.c b/lib/libcurses/insertln.c index 09b8b4353035..9a9e321c72be 100644 --- a/lib/libcurses/insertln.c +++ b/lib/libcurses/insertln.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,43 +32,50 @@ */ #ifndef lint -static char sccsid[] = "@(#)insertln.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)insertln.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> +#include <string.h> /* - * This routine performs an insert-line on the window, leaving - * (_cury,_curx) unchanged. - * + * winsertln -- + * Do an insert-line on the window, leaving (cury, curx) unchanged. */ +int winsertln(win) -reg WINDOW *win; { + register WINDOW *win; +{ - reg chtype *temp; - reg int y; - reg chtype *end; - reg int x; + register int y, i; + register __LINE *temp; -#ifdef DEBUG - fprintf(outf, "INSERTLN(%0.2o)\n", win); +#ifdef DEBUG + __CTRACE("insertln: (%0.2o)\n", win); #endif - if (win->_orig == NULL) - temp = win->_y[win->_maxy - 1]; - for (y = win->_maxy - 1; y > win->_cury; --y) { - if (win->_orig == NULL) - win->_y[y] = win->_y[y - 1]; + if (win->orig == NULL) + temp = win->lines[win->maxy - 1]; + for (y = win->maxy - 1; y > (int) win->cury; --y) { + win->lines[y]->flags &= ~__ISPASTEOL; + win->lines[y - 1]->flags &= ~__ISPASTEOL; + if (win->orig == NULL) + win->lines[y] = win->lines[y - 1]; else - bcopy(win->_y[y - 1], win->_y[y], win->_maxx * sizeof(chtype)); - touchline(win, y, 0, win->_maxx - 1); + (void)memcpy(win->lines[y]->line, + win->lines[y - 1]->line, + win->maxx * __LDATASIZE); + __touchline(win, y, 0, win->maxx - 1, 0); } - if (win->_orig == NULL) - win->_y[y] = temp; + if (win->orig == NULL) + win->lines[y] = temp; else - temp = win->_y[y]; - for (end = &temp[win->_maxx]; temp < end; ) - *temp++ = ' '; - touchline(win, y, 0, win->_maxx - 1); - if (win->_orig == NULL) - _id_subwins(win); + temp = win->lines[y]; + for(i = 0; i < win->maxx; i++) { + temp->line[i].ch = ' '; + temp->line[i].attr = 0; + } + __touchline(win, y, 0, win->maxx - 1, 0); + if (win->orig == NULL) + __id_subwins(win); + return (OK); } diff --git a/lib/libcurses/longname.c b/lib/libcurses/longname.c index 94364b4a1be3..fd54630f161d 100644 --- a/lib/libcurses/longname.c +++ b/lib/libcurses/longname.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,29 +32,25 @@ */ #ifndef lint -static char sccsid[] = "@(#)longname.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ - -# define reg register +static char sccsid[] = "@(#)longname.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ /* - * This routine fills in "def" with the long name of the terminal. - * + * longname -- + * Fill in "def" with the long name of the terminal. */ char * longname(bp, def) -reg char *bp, *def; { - - reg char *cp; + register char *bp, *def; +{ + register char *cp; while (*bp && *bp != ':' && *bp != '|') bp++; if (*bp == '|') { - bp++; - cp = def; - while (*bp && *bp != ':' && *bp != '|') + for (cp = def, ++bp; *bp && *bp != ':' && *bp != '|';) *cp++ = *bp++; - *cp = 0; + *cp = '\0'; } - return def; + return (def); } diff --git a/lib/libcurses/move.c b/lib/libcurses/move.c index 78c104b31bc9..60a377b273fa 100644 --- a/lib/libcurses/move.c +++ b/lib/libcurses/move.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,27 +32,31 @@ */ #ifndef lint -static char sccsid[] = "@(#)move.c 5.5 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> /* - * This routine moves the cursor to the given point - * + * wmove -- + * Moves the cursor to the given point. */ +int wmove(win, y, x) -reg WINDOW *win; -reg int y, x; { + register WINDOW *win; + register int y, x; +{ -# ifdef DEBUG - fprintf(outf, "MOVE to (%d, %d)\n", y, x); -# endif +#ifdef DEBUG + __CTRACE("wmove: (%d, %d)\n", y, x); +#endif if (x < 0 || y < 0) - return ERR; - if (x >= win->_maxx || y >= win->_maxy) - return ERR; - win->_curx = x; - win->_cury = y; - return OK; + return (ERR); + if (x >= win->maxx || y >= win->maxy) + return (ERR); + win->curx = x; + win->lines[win->cury]->flags &= ~__ISPASTEOL; + win->cury = y; + win->lines[y]->flags &= ~__ISPASTEOL; + return (OK); } diff --git a/lib/libcurses/mvprintw.c b/lib/libcurses/mvprintw.c deleted file mode 100644 index 63aa58fefd34..000000000000 --- a/lib/libcurses/mvprintw.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static char sccsid[] = "@(#)mvprintw.c 5.8 (Berkeley) 6/19/91"; -#endif /* not lint */ - -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif -#include "curses.ext" - -/* - * implement the mvprintw commands. Due to the variable number of - * arguments, they cannot be macros. Sigh.... - */ - -#if __STDC__ -mvprintw(reg int y, reg int x, const char *fmt, ...) -#else -mvprintw(y, x, fmt, va_alist) - reg int y, x; - char *fmt; - va_dcl -#endif -{ - va_list ap; - int ret; - - if (move(y, x) != OK) - return ERR; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - ret = _sprintw(stdscr, fmt, ap); - va_end(ap); - return ret; -} - -#if __STDC__ -mvwprintw(reg WINDOW *win, reg int y, reg int x, const char *fmt, ...) -#else -mvwprintw(win, y, x, fmt, va_alist) - reg WINDOW *win; - reg int y, x; - char *fmt; - va_dcl -#endif -{ - va_list ap; - int ret; - - if (wmove(win, y, x) != OK) - return ERR; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - ret = _sprintw(win, fmt, ap); - va_end(ap); - return ret; -} diff --git a/lib/libcurses/mvscanw.c b/lib/libcurses/mvscanw.c deleted file mode 100644 index 544cbaa32d11..000000000000 --- a/lib/libcurses/mvscanw.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static char sccsid[] = "@(#)mvscanw.c 5.5 (Berkeley) 4/15/91"; -#endif /* not lint */ - -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif -#include "curses.ext" - -/* - * implement the mvscanw commands. Due to the variable number of - * arguments, they cannot be macros. Another sigh.... - */ - -#if __STDC__ -mvscanw(reg int y, reg int x, const char *fmt, ...) -#else -mvscanw(y, x, fmt, va_alist) - reg int y, x; - char *fmt; - va_dcl -#endif -{ - va_list ap; - int ret; - - if (move(y, x) != OK) - return ERR; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - ret = _sscans(stdscr, fmt, ap); - va_end(ap); - return ret; -} - -#if __STDC__ -mvwscanw(reg WINDOW *win, reg int y, reg int x, const char *fmt, ...) -#else -mvwscanw(win, y, x, fmt, va_alist) - reg WINDOW *win; - reg int y, x; - char *fmt; - va_dcl -#endif -{ - va_list ap; - int ret; - - if (move(y, x) != OK) - return ERR; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - ret = _sscans(win, fmt, ap); - va_end(ap); - return ret; -} diff --git a/lib/libcurses/mvwin.c b/lib/libcurses/mvwin.c index 69af8a9c4976..5699295769c3 100644 --- a/lib/libcurses/mvwin.c +++ b/lib/libcurses/mvwin.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,47 +32,46 @@ */ #ifndef lint -static char sccsid[] = "@(#)mvwin.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)mvwin.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> /* - * relocate the starting position of a window - * + * mvwin -- + * Relocate the starting position of a window. */ - +int mvwin(win, by, bx) -reg WINDOW *win; -reg int by, bx; { + register WINDOW *win; + register int by, bx; +{ + register WINDOW *orig; + register int dy, dx; - register WINDOW *orig; - register int dy, dx; - - if (by + win->_maxy > LINES || bx + win->_maxx > COLS) - return ERR; - dy = by - win->_begy; - dx = bx - win->_begx; - orig = win->_orig; + if (by + win->maxy > LINES || bx + win->maxx > COLS) + return (ERR); + dy = by - win->begy; + dx = bx - win->begx; + orig = win->orig; if (orig == NULL) { orig = win; do { - win->_begy += dy; - win->_begx += dx; - _swflags_(win); - win = win->_nextp; + win->begy += dy; + win->begx += dx; + __swflags(win); + win = win->nextp; } while (win != orig); + } else { + if (by < orig->begy || win->maxy + dy > orig->maxy) + return (ERR); + if (bx < orig->begx || win->maxx + dx > orig->maxx) + return (ERR); + win->begy = by; + win->begx = bx; + __swflags(win); + __set_subwin(orig, win); } - else { - if (by < orig->_begy || win->_maxy + dy > orig->_maxy) - return ERR; - if (bx < orig->_begx || win->_maxx + dx > orig->_maxx) - return ERR; - win->_begy = by; - win->_begx = bx; - _swflags_(win); - _set_subwin_(orig, win); - } - touchwin(win); - return OK; + __touchwin(win); + return (OK); } diff --git a/lib/libcurses/newwin.c b/lib/libcurses/newwin.c index dfa7e75e63bf..d0c75257773c 100644 --- a/lib/libcurses/newwin.c +++ b/lib/libcurses/newwin.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,204 +32,217 @@ */ #ifndef lint -static char sccsid[] = "@(#)newwin.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)newwin.c 8.1 (Berkeley) 7/20/93"; +#endif /* not lint */ -/* - * allocate space for and set up defaults for a new window - * - */ - -# include "curses.ext" - -char *malloc(); +#include <curses.h> +#include <stdlib.h> -# define SMALLOC (short *) malloc +#undef nl /* Don't need it here, and it interferes. */ -static WINDOW *makenew(); +static WINDOW *__makenew __P((int, int, int, int, int)); -# undef nl /* don't need it here, and it interferes */ +void __set_subwin __P((WINDOW *, WINDOW *)); +/* + * newwin -- + * Allocate space for and set up defaults for a new window. + */ WINDOW * -newwin(num_lines, num_cols, begy, begx) -int num_lines, num_cols, begy, begx; +newwin(nl, nc, by, bx) + register int nl, nc, by, bx; { - reg WINDOW *win; - reg chtype *sp; - reg int i, by, bx, nl, nc; - reg int j; - - by = begy; - bx = begx; - nl = num_lines; - nc = num_cols; + register WINDOW *win; + register __LINE *lp; + register int i, j; + register __LDATA *sp; if (nl == 0) nl = LINES - by; if (nc == 0) nc = COLS - bx; - if ((win = makenew(nl, nc, by, bx)) == NULL) - return ERR; - if ((win->_firstch = SMALLOC(nl * sizeof win->_firstch[0])) == NULL) { - free(win->_y); - free(win); - return NULL; - } - if ((win->_lastch = SMALLOC(nl * sizeof win->_lastch[0])) == NULL) { - free(win->_y); - free(win->_firstch); - free(win); - return NULL; - } - win->_nextp = win; + + if ((win = __makenew(nl, nc, by, bx, 0)) == NULL) + return (NULL); + + win->nextp = win; + win->ch_off = 0; + win->orig = NULL; + +#ifdef DEBUG + __CTRACE("newwin: win->ch_off = %d\n", win->ch_off); +#endif + for (i = 0; i < nl; i++) { - win->_firstch[i] = _NOCHANGE; - win->_lastch[i] = _NOCHANGE; - } - for (i = 0; i < nl; i++) - if ((win->_y[i] = (chtype *) malloc(nc * sizeof(chtype))) == NULL) { - for (j = 0; j < i; j++) - free(win->_y[j]); - free(win->_firstch); - free(win->_lastch); - free(win->_y); - free(win); - return ERR; + lp = win->lines[i]; + lp->flags = 0; + for (sp = lp->line, j = 0; j < nc; j++, sp++) { + sp->ch = ' '; + sp->attr = 0; } - else - for (sp = win->_y[i]; sp < win->_y[i] + nc; ) - *sp++ = ' '; - win->_ch_off = 0; -# ifdef DEBUG - fprintf(outf, "NEWWIN: win->_ch_off = %d\n", win->_ch_off); -# endif - return win; + lp->hash = __hash((char *) lp->line, nc * __LDATASIZE); + } + return (win); } WINDOW * -subwin(orig, num_lines, num_cols, begy, begx) -reg WINDOW *orig; -int num_lines, num_cols, begy, begx; +subwin(orig, nl, nc, by, bx) + register WINDOW *orig; + register int by, bx, nl, nc; { - reg int i; - reg WINDOW *win; - reg int by, bx, nl, nc; - - by = begy; - bx = begx; - nl = num_lines; - nc = num_cols; - - /* - * make sure window fits inside the original one - */ -# ifdef DEBUG - fprintf(outf, "SUBWIN(%0.2o, %d, %d, %d, %d)\n", orig, nl, nc, by, bx); -# endif - if (by < orig->_begy || bx < orig->_begx - || by + nl > orig->_maxy + orig->_begy - || bx + nc > orig->_maxx + orig->_begx) - return ERR; + int i; + __LINE *lp; + register WINDOW *win; + + /* Make sure window fits inside the original one. */ +#ifdef DEBUG + __CTRACE("subwin: (%0.2o, %d, %d, %d, %d)\n", orig, nl, nc, by, bx); +#endif + if (by < orig->begy || bx < orig->begx + || by + nl > orig->maxy + orig->begy + || bx + nc > orig->maxx + orig->begx) + return (NULL); if (nl == 0) - nl = orig->_maxy + orig->_begy - by; + nl = orig->maxy + orig->begy - by; if (nc == 0) - nc = orig->_maxx + orig->_begx - bx; - if ((win = makenew(nl, nc, by, bx)) == NULL) - return ERR; - win->_nextp = orig->_nextp; - orig->_nextp = win; - win->_orig = orig; - _set_subwin_(orig, win); - return win; + nc = orig->maxx + orig->begx - bx; + if ((win = __makenew(nl, nc, by, bx, 1)) == NULL) + return (NULL); + win->nextp = orig->nextp; + orig->nextp = win; + win->orig = orig; + + /* Initialize flags here so that refresh can also use __set_subwin. */ + for (lp = win->lspace, i = 0; i < win->maxy; i++, lp++) + lp->flags = 0; + __set_subwin(orig, win); + return (win); } /* - * this code is shared with mvwin() + * This code is shared with mvwin(). */ -_set_subwin_(orig, win) -register WINDOW *orig, *win; +void +__set_subwin(orig, win) + register WINDOW *orig, *win; { - register int i, j, k; - - j = win->_begy - orig->_begy; - k = win->_begx - orig->_begx; - win->_ch_off = k; -# ifdef DEBUG - fprintf(outf, "_SET_SUBWIN_: win->_ch_off = %d\n", win->_ch_off); -# endif - win->_firstch = &orig->_firstch[j]; - win->_lastch = &orig->_lastch[j]; - for (i = 0; i < win->_maxy; i++, j++) - win->_y[i] = &orig->_y[j][k]; + int i; + __LINE *lp, *olp; + + win->ch_off = win->begx - orig->begx; + /* Point line pointers to line space. */ + for (lp = win->lspace, i = 0; i < win->maxy; i++, lp++) { + win->lines[i] = lp; + olp = orig->lines[i + win->begy]; + lp->line = &olp->line[win->begx]; + lp->firstchp = &olp->firstch; + lp->lastchp = &olp->lastch; + lp->hash = __hash((char *) lp->line, win->maxx * __LDATASIZE); + } +#ifdef DEBUG + __CTRACE("__set_subwin: win->ch_off = %d\n", win->ch_off); +#endif } /* - * This routine sets up a window buffer and returns a pointer to it. + * __makenew -- + * Set up a window buffer and returns a pointer to it. */ static WINDOW * -makenew(num_lines, num_cols, begy, begx) -int num_lines, num_cols, begy, begx; { - - reg int i; - reg WINDOW *win; - reg int by, bx, nl, nc; - - by = begy; - bx = begx; - nl = num_lines; - nc = num_cols; - -# ifdef DEBUG - fprintf(outf, "MAKENEW(%d, %d, %d, %d)\n", nl, nc, by, bx); -# endif - if ((win = (WINDOW *) malloc(sizeof *win)) == NULL) - return NULL; -# ifdef DEBUG - fprintf(outf, "MAKENEW: nl = %d\n", nl); -# endif - if ((win->_y = (chtype **) malloc(nl * sizeof(chtype *))) == NULL) { +__makenew(nl, nc, by, bx, sub) + register int by, bx, nl, nc; + int sub; +{ + register WINDOW *win; + register __LINE *lp; + int i; + + +#ifdef DEBUG + __CTRACE("makenew: (%d, %d, %d, %d)\n", nl, nc, by, bx); +#endif + if ((win = malloc(sizeof(*win))) == NULL) + return (NULL); +#ifdef DEBUG + __CTRACE("makenew: nl = %d\n", nl); +#endif + + /* + * Set up line pointer array and line space. + */ + if ((win->lines = malloc (nl * sizeof(__LINE *))) == NULL) { free(win); return NULL; } -# ifdef DEBUG - fprintf(outf, "MAKENEW: nc = %d\n", nc); -# endif - win->_cury = win->_curx = 0; - win->_clear = FALSE; - win->_maxy = nl; - win->_maxx = nc; - win->_begy = by; - win->_begx = bx; - win->_flags = 0; - win->_scroll = win->_leave = FALSE; - _swflags_(win); -# ifdef DEBUG - fprintf(outf, "MAKENEW: win->_clear = %d\n", win->_clear); - fprintf(outf, "MAKENEW: win->_leave = %d\n", win->_leave); - fprintf(outf, "MAKENEW: win->_scroll = %d\n", win->_scroll); - fprintf(outf, "MAKENEW: win->_flags = %0.2o\n", win->_flags); - fprintf(outf, "MAKENEW: win->_maxy = %d\n", win->_maxy); - fprintf(outf, "MAKENEW: win->_maxx = %d\n", win->_maxx); - fprintf(outf, "MAKENEW: win->_begy = %d\n", win->_begy); - fprintf(outf, "MAKENEW: win->_begx = %d\n", win->_begx); -# endif - return win; + if ((win->lspace = malloc (nl * sizeof(__LINE))) == NULL) { + free (win); + free (win->lines); + return NULL; + } + + /* Don't allocate window and line space if it's a subwindow */ + if (!sub) { + /* + * Allocate window space in one chunk. + */ + if ((win->wspace = + malloc(nc * nl * sizeof(__LDATA))) == NULL) { + free(win->lines); + free(win->lspace); + free(win); + return NULL; + } + + /* + * Point line pointers to line space, and lines themselves into + * window space. + */ + for (lp = win->lspace, i = 0; i < nl; i++, lp++) { + win->lines[i] = lp; + lp->line = &win->wspace[i * nc]; + lp->firstchp = &lp->firstch; + lp->lastchp = &lp->lastch; + lp->firstch = 0; + lp->lastch = 0; + } + } +#ifdef DEBUG + __CTRACE("makenew: nc = %d\n", nc); +#endif + win->cury = win->curx = 0; + win->maxy = nl; + win->maxx = nc; + + win->begy = by; + win->begx = bx; + win->flags = 0; + __swflags(win); +#ifdef DEBUG + __CTRACE("makenew: win->flags = %0.2o\n", win->flags); + __CTRACE("makenew: win->maxy = %d\n", win->maxy); + __CTRACE("makenew: win->maxx = %d\n", win->maxx); + __CTRACE("makenew: win->begy = %d\n", win->begy); + __CTRACE("makenew: win->begx = %d\n", win->begx); +#endif + return (win); } -_swflags_(win) -register WINDOW *win; +void +__swflags(win) + register WINDOW *win; { - win->_flags &= ~(_ENDLINE|_FULLLINE|_FULLWIN|_SCROLLWIN); - if (win->_begx + win->_maxx == COLS) { - win->_flags |= _ENDLINE; - if (win->_begx == 0) { - if (AL && DL) - win->_flags |= _FULLLINE; - if (win->_maxy == LINES && win->_begy == 0) - win->_flags |= _FULLWIN; + win->flags &= + ~(__ENDLINE | __FULLLINE | __FULLWIN | __SCROLLWIN | __LEAVEOK); + if (win->begx + win->maxx == COLS) { + win->flags |= __ENDLINE; + if (win->begx == 0) { + if (!__noqch) + win->flags |= __FULLLINE; + if (win->maxy == LINES && win->begy == 0) + win->flags |= __FULLWIN; } - if (win->_begy + win->_maxy == LINES) - win->_flags |= _SCROLLWIN; + if (win->begy + win->maxy == LINES) + win->flags |= __SCROLLWIN; } } diff --git a/lib/libcurses/overlay.c b/lib/libcurses/overlay.c index d272c7ba6daf..1f50b6d1c72a 100644 --- a/lib/libcurses/overlay.c +++ b/lib/libcurses/overlay.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,46 +32,49 @@ */ #ifndef lint -static char sccsid[] = "@(#)overlay.c 5.6 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)overlay.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" - -# define min(a,b) (a < b ? a : b) -# define max(a,b) (a > b ? a : b) +#include <curses.h> /* - * This routine writes win1 on win2 non-destructively. - * + * overlay -- + * Writes win1 on win2 non-destructively. */ +int overlay(win1, win2) -reg WINDOW *win1, *win2; { + register WINDOW *win1, *win2; +{ - reg chtype *sp, *end; - reg int x, y, endy, endx, starty, startx; - reg int y1,y2; + register int x, y, y1, y2, endy, endx, starty, startx; + register __LDATA *sp, *end; -# ifdef DEBUG - fprintf(outf, "OVERLAY(%0.2o, %0.2o);\n", win1, win2); -# endif - starty = max(win1->_begy, win2->_begy); - startx = max(win1->_begx, win2->_begx); - endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begx); - endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx); -# ifdef DEBUG - fprintf(outf, "OVERLAY:from (%d,%d) to (%d,%d)\n", starty, startx, endy, endx); -# endif +#ifdef DEBUG + __CTRACE("overlay: (%0.2o, %0.2o);\n", win1, win2); +#endif + starty = max(win1->begy, win2->begy); + startx = max(win1->begx, win2->begx); + endy = min(win1->maxy + win1->begy, win2->maxy + win2->begx); + endx = min(win1->maxx + win1->begx, win2->maxx + win2->begx); +#ifdef DEBUG + __CTRACE("overlay: from (%d,%d) to (%d,%d)\n", + starty, startx, endy, endx); +#endif if (starty >= endy || startx >= endx) - return; - y1 = starty - win1->_begy; - y2 = starty - win2->_begy; + return (OK); + y1 = starty - win1->begy; + y2 = starty - win2->begy; for (y = starty; y < endy; y++, y1++, y2++) { - end = &win1->_y[y1][endx - win1->_begx]; - x = startx - win2->_begx; - for (sp = &win1->_y[y1][startx - win1->_begx]; sp < end; sp++) { - if (*sp != ' ') - mvwaddch(win2, y2, x, *sp); + end = &win1->lines[y1]->line[endx - win1->begx]; + x = startx - win2->begx; + for (sp = &win1->lines[y1]->line[startx - win1->begx]; + sp < end; sp++) { + if (sp->ch != ' ') { + wmove(win2, y2, x); + __waddch(win2, sp); + } x++; } } + return (OK); } diff --git a/lib/libcurses/overwrite.c b/lib/libcurses/overwrite.c index 655f923ab26a..0924fa7e9318 100644 --- a/lib/libcurses/overwrite.c +++ b/lib/libcurses/overwrite.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,40 +32,43 @@ */ #ifndef lint -static char sccsid[] = "@(#)overwrite.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)overwrite.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" -# include <ctype.h> - -# define min(a,b) (a < b ? a : b) -# define max(a,b) (a > b ? a : b) +#include <curses.h> +#include <string.h> /* - * This routine writes win1 on win2 destructively. - * + * overwrite -- + * Writes win1 on win2 destructively. */ +int overwrite(win1, win2) -reg WINDOW *win1, *win2; { - - reg int x, y, endy, endx, starty, startx; + register WINDOW *win1, *win2; +{ + register int x, y, endy, endx, starty, startx; -# ifdef DEBUG - fprintf(outf, "OVERWRITE(%0.2o, %0.2o);\n", win1, win2); -# endif - starty = max(win1->_begy, win2->_begy); - startx = max(win1->_begx, win2->_begx); - endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begx); - endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx); +#ifdef DEBUG + __CTRACE("overwrite: (%0.2o, %0.2o);\n", win1, win2); +#endif + starty = max(win1->begy, win2->begy); + startx = max(win1->begx, win2->begx); + endy = min(win1->maxy + win1->begy, win2->maxy + win2->begx); + endx = min(win1->maxx + win1->begx, win2->maxx + win2->begx); if (starty >= endy || startx >= endx) - return; -# ifdef DEBUG - fprintf(outf, "OVERWRITE:from (%d,%d) to (%d,%d)\n", starty, startx, endy, endx); -# endif + return (OK); +#ifdef DEBUG + __CTRACE("overwrite: from (%d, %d) to (%d, %d)\n", + starty, startx, endy, endx); +#endif x = endx - startx; for (y = starty; y < endy; y++) { - bcopy(&win1->_y[y - win1->_begy][startx - win1->_begx], - &win2->_y[y - win2->_begy][startx - win2->_begx], x * sizeof(chtype)); - touchline(win2, y, startx - win2->_begx, endx - win2->_begx); + (void)memcpy( + &win2->lines[y - win2->begy]->line[startx - win2->begx], + &win1->lines[y - win1->begy]->line[startx - win1->begx], + x * __LDATASIZE); + __touchline(win2, y, startx - win2->begx, endx - win2->begx, + 0); } + return (OK); } diff --git a/lib/libcurses/printw.c b/lib/libcurses/printw.c index 4568c5f4b875..bc34ce621b20 100644 --- a/lib/libcurses/printw.c +++ b/lib/libcurses/printw.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,8 +32,16 @@ */ #ifndef lint -static char sccsid[] = "@(#)printw.c 5.8 (Berkeley) 4/15/91"; -#endif /* not lint */ +static char sccsid[] = "@(#)printw.c 8.2 (Berkeley) 10/5/93"; +#endif /* not lint */ + +#include <curses.h> + +#ifdef __STDC__ +#include <stdarg.h> +#else +#include <varargs.h> +#endif /* * printw and friends. @@ -42,17 +50,14 @@ static char sccsid[] = "@(#)printw.c 5.8 (Berkeley) 4/15/91"; * is not in effect. */ -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif -#include "curses.ext" +static int __winwrite __P((void *, const char *, int)); /* - * This routine implements a printf on the standard screen. + * printw -- + * Printf on the standard screen. */ -#if __STDC__ +int +#ifdef __STDC__ printw(const char *fmt, ...) #else printw(fmt, va_alist) @@ -60,24 +65,26 @@ printw(fmt, va_alist) va_dcl #endif { - va_list ap; - int ret; + va_list ap; + int ret; -#if __STDC__ +#ifdef __STDC__ va_start(ap, fmt); #else va_start(ap); #endif - ret = _sprintw(stdscr, fmt, ap); + ret = vwprintw(stdscr, fmt, ap); va_end(ap); return (ret); } /* - * This routine implements a printf on the given window. + * wprintw -- + * Printf on the given window. */ -#if __STDC__ -wprintw(WINDOW *win, const char *fmt, ...) +int +#ifdef __STDC__ +wprintw(WINDOW * win, const char *fmt, ...) #else wprintw(win, fmt, va_alist) WINDOW *win; @@ -85,56 +92,109 @@ wprintw(win, fmt, va_alist) va_dcl #endif { - va_list ap; - int ret; + va_list ap; + int ret; + +#ifdef __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + ret = vwprintw(win, fmt, ap); + va_end(ap); + return (ret); +} + +/* + * mvprintw, mvwprintw -- + * Implement the mvprintw commands. Due to the variable number of + * arguments, they cannot be macros. Sigh.... + */ +int +#ifdef __STDC__ +mvprintw(register int y, register int x, const char *fmt, ...) +#else +mvprintw(y, x, fmt, va_alist) + register int y, x; + char *fmt; + va_dcl +#endif +{ + va_list ap; + int ret; + +#ifdef __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + if (move(y, x) != OK) + return (ERR); + ret = vwprintw(stdscr, fmt, ap); + va_end(ap); + return (ret); +} + +int +#ifdef __STDC__ +mvwprintw(register WINDOW * win, register int y, register int x, + const char *fmt, ...) +#else +mvwprintw(win, y, x, fmt, va_alist) + register WINDOW *win; + register int y, x; + char *fmt; + va_dcl +#endif +{ + va_list ap; + int ret; #ifdef __STDC__ va_start(ap, fmt); #else va_start(ap); #endif - ret = _sprintw(win, fmt, ap); + if (wmove(win, y, x) != OK) + return (ERR); + + ret = vwprintw(win, fmt, ap); va_end(ap); return (ret); } /* - * Internal write-buffer-to-window function. + * Internal write-buffer-to-window function. */ static int -_winwrite(cookie, buf, n) +__winwrite(cookie, buf, n) void *cookie; - register char *buf; + register const char *buf; int n; { - register WINDOW *win = (WINDOW *)cookie; - register int c = n; + register WINDOW *win; + register int c; - while (--c >= 0) { - if (waddch(win, (unsigned char) *buf++) == ERR) + for (c = n, win = cookie; --c >= 0;) + if (waddch(win, *buf++) == ERR) return (-1); - } - return n; + return (n); } /* + * vwprintw -- * This routine actually executes the printf and adds it to the window. - * It must not be declared static as it is used in mvprintw.c. - * THIS SHOULD BE RENAMED vwprintw AND EXPORTED */ -_sprintw(win, fmt, ap) +int +vwprintw(win, fmt, ap) WINDOW *win; -#if __STDC__ const char *fmt; -#else - char *fmt; -#endif - va_list ap; + va_list ap; { FILE *f; - if ((f = fwopen((void *)win, _winwrite)) == NULL) - return ERR; - (void) vfprintf(f, fmt, ap); - return fclose(f) ? ERR : OK; + if ((f = funopen(win, NULL, __winwrite, NULL, NULL)) == NULL) + return (ERR); + (void)vfprintf(f, fmt, ap); + return (fclose(f) ? ERR : OK); } diff --git a/lib/libcurses/putchar.c b/lib/libcurses/putchar.c index 886d1a94a399..4d90d93f1241 100644 --- a/lib/libcurses/putchar.c +++ b/lib/libcurses/putchar.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,17 +32,18 @@ */ #ifndef lint -static char sccsid[] = "@(#)putchar.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ +static char sccsid[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ -# include "curses.ext" +#include <curses.h> -char -_putchar(c) -reg char c; { +void +_putchar(ch) + int ch; +{ - putchar(c); #ifdef DEBUG - fprintf(outf, "_PUTCHAR(%s)\n", unctrl(c)); + __CTRACE("_putchar: %s\n", unctrl(ch)); #endif + (void)putchar(ch); } diff --git a/lib/libcurses/refresh.c b/lib/libcurses/refresh.c index 62673d2f8797..1a371fe45b2a 100644 --- a/lib/libcurses/refresh.c +++ b/lib/libcurses/refresh.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,308 +32,728 @@ */ #ifndef lint -static char sccsid[] = "@(#)refresh.c 5.5 (Berkeley) 3/3/91"; +static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 7/20/93"; #endif /* not lint */ -/* - * make the current screen look like "win" over the area coverd by - * win. - */ - -# include "curses.ext" - -# ifdef DEBUG -# define STATIC -# else -# define STATIC static -# endif +#include <curses.h> +#include <string.h> -STATIC short ly, lx; +static int curwin; +static short ly, lx; -STATIC bool curwin; - -WINDOW *_win = NULL; - -STATIC int domvcur(), makech(); +static void domvcur __P((int, int, int, int)); +static int makech __P((WINDOW *, int)); +static void quickch __P((WINDOW *)); +static void scrolln __P((int, int, int, int, int)); +/* + * wrefresh -- + * Make the current screen look like "win" over the area coverd by + * win. + */ +int wrefresh(win) -reg WINDOW *win; + register WINDOW *win; { - reg short wy; - reg int retval; - reg WINDOW *orig; - - /* - * make sure were in visual state - */ - if (_endwin) { - _puts(VS); - _puts(TI); - _endwin = FALSE; - } - - /* - * initialize loop parameters - */ - - ly = curscr->_cury; - lx = curscr->_curx; + register __LINE *wlp; + register int retval; + register short wy; + int dnum; + + /* Initialize loop parameters. */ + ly = curscr->cury; + lx = curscr->curx; wy = 0; - _win = win; curwin = (win == curscr); - if (win->_clear || curscr->_clear || curwin) { - if ((win->_flags & _FULLWIN) || curscr->_clear) { - _puts(CL); + if (!curwin) + for (wy = 0; wy < win->maxy; wy++) { + wlp = win->lines[wy]; + if (wlp->flags & __ISDIRTY) + wlp->hash = + __hash((char *) wlp->line, win->maxx * __LDATASIZE); + } + + if (win->flags & __CLEAROK || curscr->flags & __CLEAROK || curwin) { + if ((win->flags & __FULLWIN) || curscr->flags & __CLEAROK) { + tputs(CL, 0, __cputchar); ly = 0; lx = 0; if (!curwin) { - curscr->_clear = FALSE; - curscr->_cury = 0; - curscr->_curx = 0; + curscr->flags &= ~__CLEAROK; + curscr->cury = 0; + curscr->curx = 0; werase(curscr); } - touchwin(win); + __touchwin(win); } - win->_clear = FALSE; + win->flags &= ~__CLEAROK; } if (!CA) { - if (win->_curx != 0) - _putchar('\n'); + if (win->curx != 0) + putchar('\n'); if (!curwin) werase(curscr); } -# ifdef DEBUG - fprintf(outf, "REFRESH(%0.2o): curwin = %d\n", win, curwin); - fprintf(outf, "REFRESH:\n\tfirstch\tlastch\n"); -# endif - for (wy = 0; wy < win->_maxy; wy++) { -# ifdef DEBUG - fprintf(outf, "%d\t%d\t%d\n", wy, win->_firstch[wy], - win->_lastch[wy]); -# endif - if (win->_firstch[wy] != _NOCHANGE) +#ifdef DEBUG + __CTRACE("wrefresh: (%0.2o): curwin = %d\n", win, curwin); + __CTRACE("wrefresh: \tfirstch\tlastch\n"); +#endif + +#ifndef NOQCH + if ((win->flags & __FULLLINE) && !curwin) { + /* + * Invoke quickch() only if more than a quarter of the lines + * in the window are dirty. + */ + for (wy = 0, dnum = 0; wy < win->maxy; wy++) + if (win->lines[wy]->flags & (__ISDIRTY | __FORCEPAINT)) + dnum++; + /* __noqch already checked in __FULLLINE */ + if (dnum > (int) win->maxy / 4) + quickch(win); + } +#endif + +#ifdef DEBUG +{ int i, j; + __CTRACE("#####################################\n"); + for (i = 0; i < curscr->maxy; i++) { + __CTRACE("C: %d:", i); + __CTRACE(" 0x%x \n", curscr->lines[i]->hash); + for (j = 0; j < curscr->maxx; j++) + __CTRACE("%c", + curscr->lines[i]->line[j].ch); + __CTRACE("\n"); + for (j = 0; j < curscr->maxx; j++) + __CTRACE("%x", + curscr->lines[i]->line[j].attr); + __CTRACE("\n"); + if (i < win->begy || i > win->begy + win->maxy - 1) + continue; + __CTRACE("W: %d:", i - win->begy); + __CTRACE(" 0x%x \n", win->lines[i - win->begy]->hash); + __CTRACE(" 0x%x ", win->lines[i - win->begy]->flags); + for (j = 0; j < win->maxx; j++) + __CTRACE("%c", + win->lines[i - win->begy]->line[j].ch); + __CTRACE("\n"); + for (j = 0; j < win->maxx; j++) + __CTRACE("%x", + win->lines[i - win->begy]->line[j].attr); + __CTRACE("\n"); + } +} +#endif /* DEBUG */ + + for (wy = 0; wy < win->maxy; wy++) { +#ifdef DEBUG + __CTRACE("%d\t%d\t%d\n", + wy, *win->lines[wy]->firstchp, *win->lines[wy]->lastchp); +#endif + if (!curwin) + curscr->lines[win->begy + wy]->hash = win->lines[wy]->hash; + if (win->lines[wy]->flags & (__ISDIRTY | __FORCEPAINT)) { if (makech(win, wy) == ERR) - return ERR; + return (ERR); else { - if (win->_firstch[wy] >= win->_ch_off) - win->_firstch[wy] = win->_maxx + - win->_ch_off; - if (win->_lastch[wy] < win->_maxx + - win->_ch_off) - win->_lastch[wy] = win->_ch_off; - if (win->_lastch[wy] < win->_firstch[wy]) - win->_firstch[wy] = _NOCHANGE; + if (*win->lines[wy]->firstchp >= win->ch_off) + *win->lines[wy]->firstchp = win->maxx + + win->ch_off; + if (*win->lines[wy]->lastchp < win->maxx + + win->ch_off) + *win->lines[wy]->lastchp = win->ch_off; + if (*win->lines[wy]->lastchp < + *win->lines[wy]->firstchp) { +#ifdef DEBUG + __CTRACE("wrefresh: line %d notdirty \n", wy); +#endif + win->lines[wy]->flags &= ~__ISDIRTY; + } } -# ifdef DEBUG - fprintf(outf, "\t%d\t%d\n", win->_firstch[wy], - win->_lastch[wy]); -# endif + + } +#ifdef DEBUG + __CTRACE("\t%d\t%d\n", *win->lines[wy]->firstchp, + *win->lines[wy]->lastchp); +#endif } + +#ifdef DEBUG + __CTRACE("refresh: ly=%d, lx=%d\n", ly, lx); +#endif if (win == curscr) - domvcur(ly, lx, win->_cury, win->_curx); + domvcur(ly, lx, win->cury, win->curx); else { - if (win->_leave) { - curscr->_cury = ly; - curscr->_curx = lx; - ly -= win->_begy; - lx -= win->_begx; - if (ly >= 0 && ly < win->_maxy && lx >= 0 && - lx < win->_maxx) { - win->_cury = ly; - win->_curx = lx; - } - else - win->_cury = win->_curx = 0; - } - else { - domvcur(ly, lx, win->_cury + win->_begy, - win->_curx + win->_begx); - curscr->_cury = win->_cury + win->_begy; - curscr->_curx = win->_curx + win->_begx; + if (win->flags & __LEAVEOK) { + curscr->cury = ly; + curscr->curx = lx; + ly -= win->begy; + lx -= win->begx; + if (ly >= 0 && ly < win->maxy && lx >= 0 && + lx < win->maxx) { + win->cury = ly; + win->curx = lx; + } else + win->cury = win->curx = 0; + } else { + domvcur(ly, lx, win->cury + win->begy, + win->curx + win->begx); + curscr->cury = win->cury + win->begy; + curscr->curx = win->curx + win->begx; } } retval = OK; -ret: - _win = NULL; - fflush(stdout); - return retval; + + (void)fflush(stdout); + return (retval); } /* - * make a change on the screen + * makech -- + * Make a change on the screen. */ -STATIC +static int makech(win, wy) -reg WINDOW *win; -short wy; + register WINDOW *win; + int wy; { - reg chtype *nsp, *csp, *ce; - reg short wx, lch, y; - reg int nlsp, clsp; /* last space in lines */ - char *ce_tcap; - static chtype blank[] = {' ','\0'}; - - wx = win->_firstch[wy] - win->_ch_off; - if (wx >= win->_maxx) - return OK; - else if (wx < 0) + static __LDATA blank = {' ', 0}; + register int nlsp, clsp; /* Last space in lines. */ + register int wx, lch, y; + register __LDATA *nsp, *csp, *cp, *cep; + u_int force; + char *ce; + + /* Is the cursor still on the end of the last line? */ + if (wy > 0 && win->lines[wy - 1]->flags & __ISPASTEOL) { + domvcur(ly, lx, ly + 1, 0); + ly++; + lx = 0; + } + wx = *win->lines[wy]->firstchp - win->ch_off; + if (wx < 0) wx = 0; - lch = win->_lastch[wy] - win->_ch_off; + else if (wx >= win->maxx) + return (OK); + lch = *win->lines[wy]->lastchp - win->ch_off; if (lch < 0) - return OK; - else if (lch >= win->_maxx) - lch = win->_maxx - 1;; - y = wy + win->_begy; + return (OK); + else if (lch >= (int) win->maxx) + lch = win->maxx - 1; + y = wy + win->begy; if (curwin) - csp = blank; + csp = ␣ else - csp = &curscr->_y[wy + win->_begy][wx + win->_begx]; + csp = &curscr->lines[wy + win->begy]->line[wx + win->begx]; - nsp = &win->_y[wy][wx]; + nsp = &win->lines[wy]->line[wx]; + force = win->lines[wy]->flags & __FORCEPAINT; + win->lines[wy]->flags &= ~__FORCEPAINT; if (CE && !curwin) { - for (ce = &win->_y[wy][win->_maxx - 1]; *ce == ' '; ce--) - if (ce <= win->_y[wy]) + for (cp = &win->lines[wy]->line[win->maxx - 1]; + cp->ch == ' ' && cp->attr == 0; cp--) + if (cp <= win->lines[wy]->line) break; - nlsp = ce - win->_y[wy]; + nlsp = cp - win->lines[wy]->line; } - if (!curwin) - ce_tcap = CE; + ce = CE; else - ce_tcap = NULL; + ce = NULL; + if (force) { + if (CM) + tputs(tgoto(CM, lx, ly), 0, __cputchar); + else { + tputs(HO, 0, __cputchar); + __mvcur(0, 0, ly, lx, 1); + } + } while (wx <= lch) { - if (*nsp != *csp) { - domvcur(ly, lx, y, wx + win->_begx); -# ifdef DEBUG - fprintf(outf, "MAKECH: 1: wx = %d, lx = %d\n", wx, lx); -# endif - ly = y; - lx = wx + win->_begx; - while (*nsp != *csp && wx <= lch) { - if (ce_tcap != NULL && wx >= nlsp && *nsp == ' ') { - /* - * check for clear to end-of-line - */ - ce = &curscr->_y[ly][COLS - 1]; - while (*ce == ' ') - if (ce-- <= csp) - break; - clsp = ce - curscr->_y[ly] - win->_begx; -# ifdef DEBUG - fprintf(outf, "MAKECH: clsp = %d, nlsp = %d\n", clsp, nlsp); -# endif - if (clsp - nlsp >= strlen(CE) - && clsp < win->_maxx) { -# ifdef DEBUG - fprintf(outf, "MAKECH: using CE\n"); -# endif - _puts(CE); - lx = wx + win->_begx; - while (wx++ <= clsp) - *csp++ = ' '; - return OK; - } - ce_tcap = NULL; - } - /* - * enter/exit standout mode as appropriate - */ - if (SO && (*nsp&_STANDOUT) != (curscr->_flags&_STANDOUT)) { - if (*nsp & _STANDOUT) { - _puts(SO); - curscr->_flags |= _STANDOUT; - } - else { - _puts(SE); - curscr->_flags &= ~_STANDOUT; - } - } - wx++; - if (wx >= win->_maxx && wy == win->_maxy - 1) - if (win->_scroll) { - if ((curscr->_flags&_STANDOUT) && - (win->_flags & _ENDLINE)) - if (!MS) { - _puts(SE); - curscr->_flags &= ~_STANDOUT; - } + if (!force && memcmp(nsp, csp, sizeof(__LDATA)) == 0) { + if (wx <= lch) { + while (wx <= lch && + memcmp(nsp, csp, sizeof(__LDATA)) == 0) { + nsp++; if (!curwin) - _putchar((*csp = *nsp)); - else - _putchar(*nsp); - if (win->_flags&_FULLWIN && !curwin) - scroll(curscr); - ly = win->_begy+win->_cury; - lx = win->_begx+win->_curx; - return OK; - } - else if (win->_flags&_SCROLLWIN) { - lx = --wx; - return ERR; + csp++; + ++wx; + } + continue; + } + break; + } + domvcur(ly, lx, y, wx + win->begx); + +#ifdef DEBUG + __CTRACE("makech: 1: wx = %d, ly= %d, lx = %d, newy = %d, newx = %d, force =%d\n", + wx, ly, lx, y, wx + win->begx, force); +#endif + ly = y; + lx = wx + win->begx; + while ((force || memcmp(nsp, csp, sizeof(__LDATA)) != 0) + && wx <= lch) { + + if (ce != NULL && win->maxx + win->begx == + curscr->maxx && wx >= nlsp && nsp->ch == ' ') { + /* Check for clear to end-of-line. */ + cep = &curscr->lines[win->begy + wy]->line[win->begx + win->maxx - 1]; + while (cep->ch == ' ' && cep->attr == 0) + if (cep-- <= csp) + break; + clsp = cep - curscr->lines[win->begy + wy]->line - + win->begx; +#ifdef DEBUG + __CTRACE("makech: clsp = %d, nlsp = %d\n", clsp, nlsp); +#endif + if ((clsp - nlsp >= strlen(CE) + && clsp < win->maxx) || + wy == win->maxy - 1) { +#ifdef DEBUG + __CTRACE("makech: using CE\n"); +#endif + tputs(CE, 0, __cputchar); + lx = wx + win->begx; + while (wx++ <= clsp) { + csp->ch = ' '; + csp->attr = 0; + csp++; } - if (!curwin) - _putchar((*csp++ = *nsp)); - else - _putchar(*nsp); -# ifdef FULLDEBUG - fprintf(outf, - "MAKECH:putchar(%c)\n", *nsp); -# endif - if (UC && (*nsp & _STANDOUT)) { - _putchar('\b'); - _puts(UC); + return (OK); } - nsp++; + ce = NULL; } -# ifdef DEBUG - fprintf(outf, "MAKECH: 2: wx = %d, lx = %d\n", wx, lx); -# endif - if (lx == wx + win->_begx) /* if no change */ - break; - lx = wx + win->_begx; - if (lx >= COLS && AM) { - lx = 0; - ly++; - /* - * xn glitch: chomps a newline after auto-wrap. - * we just feed it now and forget about it. - */ - if (XN) { - _putchar('\n'); - _putchar('\r'); + + /* Enter/exit standout mode as appropriate. */ + if (SO && (nsp->attr & __STANDOUT) != + (curscr->flags & __WSTANDOUT)) { + if (nsp->attr & __STANDOUT) { + tputs(SO, 0, __cputchar); + curscr->flags |= __WSTANDOUT; + } else { + tputs(SE, 0, __cputchar); + curscr->flags &= ~__WSTANDOUT; } } - } - else if (wx <= lch) - while (*nsp == *csp && wx <= lch) { - nsp++; - if (!curwin) + + wx++; + if (wx >= win->maxx && wy == win->maxy - 1 && !curwin) + if (win->flags & __SCROLLOK) { + if (curscr->flags & __WSTANDOUT + && win->flags & __ENDLINE) + if (!MS) { + tputs(SE, 0, + __cputchar); + curscr->flags &= + ~__WSTANDOUT; + } + if (!(win->flags & __SCROLLWIN)) { + if (!curwin) { + csp->attr = nsp->attr; + putchar(csp->ch = nsp->ch); + } else + putchar(nsp->ch); + } + if (wx + win->begx < curscr->maxx) { + domvcur(ly, wx + win->begx, + win->begy + win->maxy - 1, + win->begx + win->maxx - 1); + } + ly = win->begy + win->maxy - 1; + lx = win->begx + win->maxx - 1; + return (OK); + } + if (wx < win->maxx || wy < win->maxy - 1 || + !(win->flags & __SCROLLWIN)) { + if (!curwin) { + csp->attr = nsp->attr; + putchar(csp->ch = nsp->ch); csp++; - ++wx; + } else + putchar(nsp->ch); } - else +#ifdef DEBUG + __CTRACE("makech: putchar(%c)\n", nsp->ch & 0177); +#endif + if (UC && (nsp->attr & __STANDOUT)) { + putchar('\b'); + tputs(UC, 0, __cputchar); + } + nsp++; +#ifdef DEBUG + __CTRACE("makech: 2: wx = %d, lx = %d\n", wx, lx); +#endif + } + if (lx == wx + win->begx) /* If no change. */ break; -# ifdef DEBUG - fprintf(outf, "MAKECH: 3: wx = %d, lx = %d\n", wx, lx); -# endif + lx = wx + win->begx; + if (lx >= COLS && AM) + lx = COLS - 1; + else if (wx >= win->maxx) { + domvcur(ly, lx, ly, win->maxx + win->begx - 1); + lx = win->maxx + win->begx - 1; + } + +#ifdef DEBUG + __CTRACE("makech: 3: wx = %d, lx = %d\n", wx, lx); +#endif } - return OK; + return (OK); } /* - * perform a mvcur, leaving standout mode if necessary + * domvcur -- + * Do a mvcur, leaving standout mode if necessary. */ -STATIC +static void domvcur(oy, ox, ny, nx) -int oy, ox, ny, nx; { + int oy, ox, ny, nx; +{ + if (curscr->flags & __WSTANDOUT && !MS) { + tputs(SE, 0, __cputchar); + curscr->flags &= ~__WSTANDOUT; + } + + __mvcur(oy, ox, ny, nx, 1); +} + +/* + * Quickch() attempts to detect a pattern in the change of the window + * in order to optimize the change, e.g., scroll n lines as opposed to + * repainting the screen line by line. + */ + +static void +quickch(win) + WINDOW *win; +{ +#define THRESH (int) win->maxy / 4 + + register __LINE *clp, *tmp1, *tmp2; + register int bsize, curs, curw, starts, startw, i, j; + int n, target, cur_period, bot, top, sc_region; + __LDATA buf[1024]; + u_int blank_hash; + + /* + * Find how many lines from the top of the screen are unchanged. + */ + for (top = win->begy; top < win->begy + win->maxy; top++) + if (win->lines[top - win->begy]->flags & __FORCEPAINT || + win->lines[top - win->begy]->hash != curscr->lines[top]->hash + || memcmp(win->lines[top - win->begy]->line, + curscr->lines[top]->line, + win->maxx * __LDATASIZE) != 0) + break; + else + win->lines[top - win->begy]->flags &= ~__ISDIRTY; + /* + * Find how many lines from bottom of screen are unchanged. + */ + for (bot = win->begy + win->maxy - 1; bot >= (int) win->begy; bot--) { + if (win->lines[bot - win->begy]->flags & __FORCEPAINT || + win->lines[bot - win->begy]->hash != curscr->lines[bot]->hash + || memcmp(win->lines[bot - win->begy]->line, + curscr->lines[bot]->line, + win->maxx * __LDATASIZE) != 0) + break; + else + win->lines[bot - win->begy]->flags &= ~__ISDIRTY; + } + +#ifdef NO_JERKINESS + /* + * If we have a bottom unchanged region return. Scrolling the + * bottom region up and then back down causes a screen jitter. + * This will increase the number of characters sent to the screen + * but it looks better. + */ + if (bot < (int) win->begy + win->maxy - 1) + return; +#endif /* NO_JERKINESS */ + + /* + * Search for the largest block of text not changed. + * Invariants of the loop: + * - Startw is the index of the beginning of the examined block in win. + * - Starts is the index of the beginning of the examined block in + * curscr. + * - Curw is the index of one past the end of the exmined block in win. + * - Curs is the index of one past the end of the exmined block in + * curscr. + * - bsize is the current size of the examined block. + */ + for (bsize = bot - top; bsize >= THRESH; bsize--) { + for (startw = top; startw <= bot - bsize; startw++) + for (starts = top; starts <= bot - bsize; + starts++) { + for (curw = startw, curs = starts; + curs < starts + bsize; curw++, curs++) + if (win->lines[curw - win->begy]->flags & + __FORCEPAINT || + (win->lines[curw - win->begy]->hash != + curscr->lines[curs]->hash || + memcmp(win->lines[curw - win->begy]->line, + curscr->lines[curs]->line, + win->maxx * __LDATASIZE) != 0)) + break; + if (curs == starts + bsize) + goto done; + } + } + done: + /* Did not find anything */ + if (bsize < THRESH) + return; + +#ifdef DEBUG + __CTRACE("quickch:bsize=%d,starts=%d,startw=%d,curw=%d,curs=%d,top=%d,bot=%d\n", + bsize, starts, startw, curw, curs, top, bot); +#endif + + /* + * Make sure that there is no overlap between the bottom and top + * regions and the middle scrolled block. + */ + if (bot < curs) + bot = curs - 1; + if (top > starts) + top = starts; - if (curscr->_flags & _STANDOUT && !MS) { - _puts(SE); - curscr->_flags &= ~_STANDOUT; + n = startw - starts; + +#ifdef DEBUG + __CTRACE("#####################################\n"); + for (i = 0; i < curscr->maxy; i++) { + __CTRACE("C: %d:", i); + __CTRACE(" 0x%x \n", curscr->lines[i]->hash); + for (j = 0; j < curscr->maxx; j++) + __CTRACE("%c", + curscr->lines[i]->line[j].ch); + __CTRACE("\n"); + for (j = 0; j < curscr->maxx; j++) + __CTRACE("%x", + curscr->lines[i]->line[j].attr); + __CTRACE("\n"); + if (i < win->begy || i > win->begy + win->maxy - 1) + continue; + __CTRACE("W: %d:", i - win->begy); + __CTRACE(" 0x%x \n", win->lines[i - win->begy]->hash); + __CTRACE(" 0x%x ", win->lines[i - win->begy]->flags); + for (j = 0; j < win->maxx; j++) + __CTRACE("%c", + win->lines[i - win->begy]->line[j].ch); + __CTRACE("\n"); + for (j = 0; j < win->maxx; j++) + __CTRACE("%x", + win->lines[i - win->begy]->line[j].attr); + __CTRACE("\n"); + } +#endif + + /* So we don't have to call __hash() each time */ + for (i = 0; i < win->maxx; i++) { + buf[i].ch = ' '; + buf[i].attr = 0; + } + blank_hash = __hash((char *) buf, win->maxx * __LDATASIZE); + + /* + * Perform the rotation to maintain the consistency of curscr. + * This is hairy since we are doing an *in place* rotation. + * Invariants of the loop: + * - I is the index of the current line. + * - Target is the index of the target of line i. + * - Tmp1 points to current line (i). + * - Tmp2 and points to target line (target); + * - Cur_period is the index of the end of the current period. + * (see below). + * + * There are 2 major issues here that make this rotation non-trivial: + * 1. Scrolling in a scrolling region bounded by the top + * and bottom regions determined (whose size is sc_region). + * 2. As a result of the use of the mod function, there may be a + * period introduced, i.e., 2 maps to 4, 4 to 6, n-2 to 0, and + * 0 to 2, which then causes all odd lines not to be rotated. + * To remedy this, an index of the end ( = beginning) of the + * current 'period' is kept, cur_period, and when it is reached, + * the next period is started from cur_period + 1 which is + * guaranteed not to have been reached since that would mean that + * all records would have been reached. (think about it...). + * + * Lines in the rotation can have 3 attributes which are marked on the + * line so that curscr is consistent with the visual screen. + * 1. Not dirty -- lines inside the scrolled block, top region or + * bottom region. + * 2. Blank lines -- lines in the differential of the scrolling + * region adjacent to top and bot regions + * depending on scrolling direction. + * 3. Dirty line -- all other lines are marked dirty. + */ + sc_region = bot - top + 1; + i = top; + tmp1 = curscr->lines[top]; + cur_period = top; + for (j = top; j <= bot; j++) { + target = (i - top + n + sc_region) % sc_region + top; + tmp2 = curscr->lines[target]; + curscr->lines[target] = tmp1; + /* Mark block as clean and blank out scrolled lines. */ + clp = curscr->lines[target]; +#ifdef DEBUG + __CTRACE("quickch: n=%d startw=%d curw=%d i = %d target=%d ", + n, startw, curw, i, target); +#endif + if ((target >= startw && target < curw) || target < top + || target > bot) { +#ifdef DEBUG + __CTRACE("-- notdirty"); +#endif + win->lines[target - win->begy]->flags &= ~__ISDIRTY; + } else if ((n > 0 && target >= top && target < top + n) || + (n < 0 && target <= bot && target > bot + n)) { + if (clp->hash != blank_hash || memcmp(clp->line, + buf, win->maxx * __LDATASIZE) !=0) { + (void)memcpy(clp->line, buf, + win->maxx * __LDATASIZE); +#ifdef DEBUG + __CTRACE("-- blanked out: dirty"); +#endif + clp->hash = blank_hash; + __touchline(win, target - win->begy, 0, win->maxx - 1, 0); + } else { + __touchline(win, target - win->begy, 0, win->maxx - 1, 0); +#ifdef DEBUG + __CTRACE(" -- blank line already: dirty"); +#endif + } + } else { +#ifdef DEBUG + __CTRACE(" -- dirty"); +#endif + __touchline(win, target - win->begy, 0, win->maxx - 1, 0); + } +#ifdef DEBUG + __CTRACE("\n"); +#endif + if (target == cur_period) { + i = target + 1; + tmp1 = curscr->lines[i]; + cur_period = i; + } else { + tmp1 = tmp2; + i = target; + } + } +#ifdef DEBUG + __CTRACE("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n"); + for (i = 0; i < curscr->maxy; i++) { + __CTRACE("C: %d:", i); + for (j = 0; j < curscr->maxx; j++) + __CTRACE("%c", + curscr->lines[i]->line[j].ch); + __CTRACE("\n"); + if (i < win->begy || i > win->begy + win->maxy - 1) + continue; + __CTRACE("W: %d:", i - win->begy); + for (j = 0; j < win->maxx; j++) + __CTRACE("%c", + win->lines[i - win->begy]->line[j].ch); + __CTRACE("\n"); + } +#endif + if (n != 0) { + WINDOW *wp; + scrolln(starts, startw, curs, bot, top); + /* + * Need to repoint any subwindow lines to the rotated + * line structured. + */ + for (wp = win->nextp; wp != win; wp = wp->nextp) + __set_subwin(win, wp); + } +} + +/* + * Scrolln performs the scroll by n lines, where n is starts - startw. + */ +static void +scrolln(starts, startw, curs, bot, top) + int starts, startw, curs, bot, top; +{ + int i, oy, ox, n; + + oy = curscr->cury; + ox = curscr->curx; + n = starts - startw; + + if (!__usecs) { /* Use insert/delete line */ + if (n > 0) { + __mvcur(oy, ox, top, 0, 1); + /* Scroll up the block */ + if (DL && (!dl || n > 1)) + tputs(__tscroll(DL, n), 0, __cputchar); + else + for(i = 0; i < n; i++) + tputs(dl, 0, __cputchar); + + /* + * Push down the bottom region. + */ + __mvcur(top, 0, bot - n + 1, 0, 1); + if (AL && (!al || n > 1)) + tputs(__tscroll(AL, n), 0, __cputchar); + else + for(i = 0; i < n; i++) + tputs(al, 0, __cputchar); + __mvcur(bot - n + 1, 0, oy, ox, 1); + } else { + /* Preserve the bottom lines */ + __mvcur(oy, ox, bot + n + 1, 0, 1); /* n < 0 */ + if (DL && (!dl || -n > 1)) + tputs(__tscroll(DL, -n), 0, __cputchar); + else + for(i = n; i < 0; i++) + tputs(dl, 0, __cputchar); + __mvcur(bot + n + 1, 0, top, 0, 1); + + /* Scroll the block down */ + if (AL && (!al || -n > 1)) + tputs(__tscroll(AL, -n), 0, __cputchar); + else + for(i = n; i < 0; i++) + tputs(al, 0, __cputchar); + __mvcur(top, 0, oy, ox, 1); + } + } else { /* Use change scroll region */ + if (bot != curscr->maxy - 1 || top != 0) + __set_scroll_region(top, bot); + if (n > 0) { + __mvcur(oy, ox, bot, 0, 1); + /* Scroll up the block */ + if (SF && n > 1) + tputs(__tscroll(SF, n), 0, __cputchar); + else + for(i = 0; i < n; i++) + if (NL && __pfast) + tputs(NL, 0, __cputchar); + else + putchar('\n'); + __mvcur(bot, 0, oy, ox, 1); + } else { + __mvcur(oy, ox, top, 0, 1); + /* Scroll the block down */ + if (SR && (!sr || -n > 1)) + tputs(__tscroll(SR, -n), 0, __cputchar); + else + for(i = n; i < 0; i++) + tputs(sr, 0, __cputchar); + __mvcur(top, 0, oy, ox, 1); + } + if (bot != curscr->maxy - 1 || top != 0) + __set_scroll_region(0, curscr->maxy - 1); } - mvcur(oy, ox, ny, nx); } diff --git a/lib/libcurses/scanw.c b/lib/libcurses/scanw.c index 470b9bd47371..ddd1ba9278d5 100644 --- a/lib/libcurses/scanw.c +++ b/lib/libcurses/scanw.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,25 +32,27 @@ */ #ifndef lint -static char sccsid[] = "@(#)scanw.c 5.7 (Berkeley) 4/15/91"; -#endif /* not lint */ +static char sccsid[] = "@(#)scanw.c 8.2 (Berkeley) 10/5/93"; +#endif /* not lint */ /* - * scanw and friends - * + * scanw and friends. */ -#if __STDC__ +#include <curses.h> + +#ifdef __STDC__ #include <stdarg.h> #else #include <varargs.h> #endif -#include "curses.ext" /* - * This routine implements a scanf on the standard screen. + * scanw -- + * Implement a scanf on the standard screen. */ -#if __STDC__ +int +#ifdef __STDC__ scanw(const char *fmt, ...) #else scanw(fmt, va_alist) @@ -61,20 +63,22 @@ scanw(fmt, va_alist) va_list ap; int ret; -#if __STDC__ +#ifdef __STDC__ va_start(ap, fmt); #else va_start(ap); #endif - ret = _sscans(stdscr, fmt, ap); + ret = vwscanw(stdscr, fmt, ap); va_end(ap); - return ret; + return (ret); } /* - * This routine implements a scanf on the given window. + * wscanw -- + * Implements a scanf on the given window. */ -#if __STDC__ +int +#ifdef __STDC__ wscanw(WINDOW *win, const char *fmt, ...) #else wscanw(win, fmt, va_alist) @@ -86,30 +90,86 @@ wscanw(win, fmt, va_alist) va_list ap; int ret; -#if __STDC__ +#ifdef __STDC__ va_start(ap, fmt); #else va_start(ap); #endif - ret = _sscans(win, fmt, ap); + ret = vwscanw(win, fmt, ap); va_end(ap); - return ret; + return (ret); } /* - * This routine actually executes the scanf from the window. - * THIS SHOULD BE RENAMED vwscanw AND EXPORTED + * mvscanw, mvwscanw -- + * Implement the mvscanw commands. Due to the variable number of + * arguments, they cannot be macros. Another sigh.... */ -_sscans(win, fmt, ap) - WINDOW *win; -#if __STDC__ - const char *fmt; +int +#ifdef __STDC__ +mvscanw(register int y, register int x, const char *fmt,...) +#else +mvscanw(y, x, fmt, va_alist) + register int y, x; + char *fmt; + va_dcl +#endif +{ + va_list ap; + int ret; + + if (move(y, x) != OK) + return (ERR); +#ifdef __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + ret = vwscanw(stdscr, fmt, ap); + va_end(ap); + return (ret); +} + +int +#ifdef __STDC__ +mvwscanw(register WINDOW * win, register int y, register int x, + const char *fmt, ...) #else +mvwscanw(win, y, x, fmt, va_alist) + register WINDOW *win; + register int y, x; char *fmt; + va_dcl #endif +{ + va_list ap; + int ret; + + if (move(y, x) != OK) + return (ERR); +#ifdef __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + ret = vwscanw(win, fmt, ap); + va_end(ap); + return (ret); +} + +/* + * vwscanw -- + * This routine actually executes the scanf from the window. + */ +int +vwscanw(win, fmt, ap) + WINDOW *win; + const char *fmt; va_list ap; { - char buf[100]; - return wgetstr(win, buf) == OK ? vsscanf(buf, fmt, ap) : ERR; + char buf[1024]; + + return (wgetstr(win, buf) == OK ? + vsscanf(buf, fmt, ap) : ERR); } diff --git a/lib/libcurses/scroll.c b/lib/libcurses/scroll.c index 25cf822cba84..1b03eccab9d1 100644 --- a/lib/libcurses/scroll.c +++ b/lib/libcurses/scroll.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,26 +32,27 @@ */ #ifndef lint -static char sccsid[] = "@(#)scroll.c 5.4 (Berkeley) 6/1/90"; +static char sccsid[] = "@(#)scroll.c 8.2 (Berkeley) 1/9/94"; #endif /* not lint */ -# include "curses.ext" +#include <curses.h> /* - * This routine scrolls the window up a line. - * + * scroll -- + * Scroll the window up a line. */ +int scroll(win) -register WINDOW *win; + register WINDOW *win; { - register int oy, ox; + register int oy, ox; -# ifdef DEBUG - fprintf(outf, "SCROLL(%0.2o)\n", win); -# endif +#ifdef DEBUG + __CTRACE("scroll: (%0.2o)\n", win); +#endif - if (!win->_scroll) - return ERR; + if (!(win->flags & __SCROLLOK)) + return (ERR); getyx(win, oy, ox); wmove(win, 0, 0); @@ -59,11 +60,12 @@ register WINDOW *win; wmove(win, oy, ox); if (win == curscr) { - _putchar('\n'); + putchar('\n'); if (!NONL) - win->_curx = 0; -# ifdef DEBUG - fprintf(outf, "SCROLL: win == curscr\n"); -# endif + win->curx = 0; +#ifdef DEBUG + __CTRACE("scroll: win == curscr\n"); +#endif } + return (OK); } diff --git a/lib/libcurses/setterm.c b/lib/libcurses/setterm.c new file mode 100644 index 000000000000..35e4e55b26d6 --- /dev/null +++ b/lib/libcurses/setterm.c @@ -0,0 +1,230 @@ +/* + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char sccsid[] = "@(#)setterm.c 8.3 (Berkeley) 1/2/94"; +#endif /* not lint */ + +#include <sys/ioctl.h> + +#include <curses.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +static void zap __P((void)); + +static char *sflags[] = { + /* am bs da eo hc in mi ms */ + &AM, &BS, &DA, &EO, &HC, &IN, &MI, &MS, + /* nc ns os ul xb xn xt xs xx */ + &NC, &NS, &OS, &UL, &XB, &XN, &XT, &XS, &XX + }; + +static char *_PC, + **sstrs[] = { + /* AL bc bt cd ce cl cm cr cs */ + &AL, &BC, &BT, &CD, &CE, &CL, &CM, &CR, &CS, + /* dc DL dm do ed ei k0 k1 k2 */ + &DC, &DL, &DM, &DO, &ED, &EI, &K0, &K1, &K2, + /* k3 k4 k5 k6 k7 k8 k9 ho ic */ + &K3, &K4, &K5, &K6, &K7, &K8, &K9, &HO, &IC, + /* im ip kd ke kh kl kr ks ku */ + &IM, &IP, &KD, &KE, &KH, &KL, &KR, &KS, &KU, + /* ll ma nd nl pc rc sc se SF */ + &LL, &MA, &ND, &NL, &_PC, &RC, &SC, &SE, &SF, + /* so SR ta te ti uc ue up us */ + &SO, &SR, &TA, &TE, &TI, &UC, &UE, &UP, &US, + /* vb vs ve al dl sf sr AL */ + &VB, &VS, &VE, &al, &dl, &sf, &sr, &AL_PARM, + /* DL UP DO LE */ + &DL_PARM, &UP_PARM, &DOWN_PARM, &LEFT_PARM, + /* RI */ + &RIGHT_PARM, + }; + +static char *aoftspace; /* Address of _tspace for relocation */ +static char tspace[2048]; /* Space for capability strings */ + +char *ttytype; + +int +setterm(type) + register char *type; +{ + static char genbuf[1024]; + static char __ttytype[1024]; + register int unknown; + struct winsize win; + char *p; + +#ifdef DEBUG + __CTRACE("setterm: (\"%s\")\nLINES = %d, COLS = %d\n", + type, LINES, COLS); +#endif + if (type[0] == '\0') + type = "xx"; + unknown = 0; + if (tgetent(genbuf, type) != 1) { + unknown++; + strcpy(genbuf, "xx|dumb:"); + } +#ifdef DEBUG + __CTRACE("setterm: tty = %s\n", type); +#endif + + /* Try TIOCGWINSZ, and, if it fails, the termcap entry. */ + if (ioctl(STDERR_FILENO, TIOCGWINSZ, &win) != -1 && + win.ws_row != 0 && win.ws_col != 0) { + LINES = win.ws_row; + COLS = win.ws_col; + } else { + LINES = tgetnum("li"); + COLS = tgetnum("co"); + } + + /* POSIX 1003.2 requires that the environment override. */ + if ((p = getenv("LINES")) != NULL) + LINES = strtol(p, NULL, 10); + if ((p = getenv("COLUMNS")) != NULL) + COLS = strtol(p, NULL, 10); + + /* + * Want cols > 4, otherwise things will fail. + */ + if (COLS <= 4) + return (ERR); + +#ifdef DEBUG + __CTRACE("setterm: LINES = %d, COLS = %d\n", LINES, COLS); +#endif + aoftspace = tspace; + zap(); /* Get terminal description. */ + + /* If we can't tab, we can't backtab, either. */ + if (!GT) + BT = NULL; + + /* + * Test for cursor motion capbility. + * + * XXX + * This is truly stupid -- tgoto returns "OOPS" if it can't + * do cursor motions. + */ + if (tgoto(CM, 0, 0)[0] == 'O') { + CA = 0; + CM = 0; + } else + CA = 1; + + PC = _PC ? _PC[0] : 0; + aoftspace = tspace; + ttytype = longname(genbuf, __ttytype); + + if (!NS && SC && RC && CS && (sr || SR)) + __usecs = 1; + + if ((!AL && !al || !DL && !dl) && !__usecs) + __noqch = 1; + + return (unknown ? ERR : OK); +} + +/* + * zap -- + * Gets all the terminal flags from the termcap database. + */ +static void +zap() +{ + register char *namp, ***sp; + register char **fp; + char tmp[3]; +#ifdef DEBUG + register char *cp; +#endif + tmp[2] = '\0'; + + namp = "ambsdaeohcinmimsncnsosulxbxnxtxsxx"; + fp = sflags; + do { + *tmp = *namp; + *(tmp + 1) = *(namp + 1); + *(*fp++) = tgetflag(tmp); +#ifdef DEBUG + __CTRACE("2.2s = %s\n", namp, *fp[-1] ? "TRUE" : "FALSE"); +#endif + namp += 2; + + } while (*namp); + namp = "ALbcbtcdceclcmcrcsdcDLdmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullmandnlpcrcscseSFsoSRtatetiucueupusvbvsvealdlsfsrALDLUPDOLERI"; + sp = sstrs; + do { + *tmp = *namp; + *(tmp + 1) = *(namp + 1); + *(*sp++) = tgetstr(tmp, &aoftspace); +#ifdef DEBUG + __CTRACE("2.2s = %s", namp, *sp[-1] == NULL ? "NULL\n" : "\""); + if (*sp[-1] != NULL) { + for (cp = *sp[-1]; *cp; cp++) + __CTRACE("%s", unctrl(*cp)); + __CTRACE("\"\n"); + } +#endif + namp += 2; + } while (*namp); + if (XS) + SO = SE = NULL; + else { + if (tgetnum("sg") > 0) + SO = NULL; + if (tgetnum("ug") > 0) + US = NULL; + if (!SO && US) { + SO = US; + SE = UE; + } + } +} + +/* + * getcap -- + * Return a capability from termcap. + */ +char * +getcap(name) + char *name; +{ + return (tgetstr(name, &aoftspace)); +} diff --git a/lib/libcurses/standout.c b/lib/libcurses/standout.c index 9cdaee6b1074..14a983da6185 100644 --- a/lib/libcurses/standout.c +++ b/lib/libcurses/standout.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,40 +32,37 @@ */ #ifndef lint -static char sccsid[] = "@(#)standout.c 5.4 (Berkeley) 6/1/90"; +static char sccsid[] = "@(#)standout.c 8.1 (Berkeley) 6/4/93"; #endif /* not lint */ -/* - * routines dealing with entering and exiting standout mode - * - */ - -# include "curses.ext" +#include <curses.h> /* - * enter standout mode + * wstandout + * Enter standout mode. */ -char * +int wstandout(win) -reg WINDOW *win; + register WINDOW *win; { if (!SO && !UC) - return FALSE; + return (0); - win->_flags |= _STANDOUT; - return (SO ? SO : UC); + win->flags |= __WSTANDOUT; + return (1); } /* - * exit standout mode + * wstandend -- + * Exit standout mode. */ -char * +int wstandend(win) -reg WINDOW *win; + register WINDOW *win; { if (!SO && !UC) - return FALSE; + return (0); - win->_flags &= ~_STANDOUT; - return (SE ? SE : UC); + win->flags &= ~__WSTANDOUT; + return (1); } diff --git a/lib/libcurses/toucholap.c b/lib/libcurses/toucholap.c index 4404755a731c..8924ebe24798 100644 --- a/lib/libcurses/toucholap.c +++ b/lib/libcurses/toucholap.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,42 +32,46 @@ */ #ifndef lint -static char sccsid[] = "@(#)toucholap.c 5.4 (Berkeley) 6/1/90"; +static char sccsid[] = "@(#)toucholap.c 8.1 (Berkeley) 6/4/93"; #endif /* not lint */ -# include "curses.ext" - -# define min(a,b) (a < b ? a : b) -# define max(a,b) (a > b ? a : b) +#include <curses.h> /* + * touchoverlap -- * Touch, on win2, the part that overlaps with win1. - * */ +int touchoverlap(win1, win2) -reg WINDOW *win1, *win2; { + register WINDOW *win1, *win2; +{ + register int y, endy, endx, starty, startx; - reg int x, y, endy, endx, starty, startx; - -# ifdef DEBUG - fprintf(outf, "TOUCHOVERLAP(%0.2o, %0.2o);\n", win1, win2); -# endif - starty = max(win1->_begy, win2->_begy); - startx = max(win1->_begx, win2->_begx); - endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begx); - endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx); -# ifdef DEBUG - fprintf(outf, "TOUCHOVERLAP:from (%d,%d) to (%d,%d)\n", starty, startx, endy, endx); - fprintf(outf, "TOUCHOVERLAP:win1 (%d,%d) to (%d,%d)\n", win1->_begy, win1->_begx, win1->_begy + win1->_maxy, win1->_begx + win1->_maxx); - fprintf(outf, "TOUCHOVERLAP:win2 (%d,%d) to (%d,%d)\n", win2->_begy, win2->_begx, win2->_begy + win2->_maxy, win2->_begx + win2->_maxx); -# endif +#ifdef DEBUG + __CTRACE("touchoverlap: (%0.2o, %0.2o);\n", win1, win2); +#endif + starty = max(win1->begy, win2->begy); + startx = max(win1->begx, win2->begx); + endy = min(win1->maxy + win1->begy, win2->maxy + win2->begx); + endx = min(win1->maxx + win1->begx, win2->maxx + win2->begx); +#ifdef DEBUG + __CTRACE("touchoverlap: from (%d,%d) to (%d,%d)\n", + starty, startx, endy, endx); + __CTRACE("touchoverlap: win1 (%d,%d) to (%d,%d)\n", + win1->begy, win1->begx, win1->begy + win1->maxy, + win1->begx + win1->maxx); + __CTRACE("touchoverlap: win2 (%d,%d) to (%d,%d)\n", + win2->begy, win2->begx, win2->begy + win2->maxy, + win2->begx + win2->maxx); +#endif if (starty >= endy || startx >= endx) - return; - starty -= win2->_begy; - startx -= win2->_begx; - endy -= win2->_begy; - endx -= win2->_begx; - endx--; - for (y = starty; y < endy; y++) - touchline(win2, y, startx, endx); + return (OK); + starty -= win2->begy; + startx -= win2->begx; + endy -= win2->begy; + endx -= win2->begx; + for (--endx, y = starty; y < endy; y++) + __touchline(win2, y, startx, endx, 0); + return (OK); } + diff --git a/lib/libcurses/touchwin.c b/lib/libcurses/touchwin.c index 13d433138956..68fa78588922 100644 --- a/lib/libcurses/touchwin.c +++ b/lib/libcurses/touchwin.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,52 +32,90 @@ */ #ifndef lint -static char sccsid[] = "@(#)touchwin.c 5.4 (Berkeley) 6/1/90"; +static char sccsid[] = "@(#)touchwin.c 8.1 (Berkeley) 6/4/93"; #endif /* not lint */ -# include "curses.ext" +#include <curses.h> + /* - * make it look like the whole window has been changed. - * + * touchline -- + * Touch a given line. */ +int +touchline(win, y, sx, ex) + WINDOW *win; + register int y, sx, ex; +{ + return (__touchline(win, y, sx, ex, 1)); +} + + +/* + * touchwin -- + * Make it look like the whole window has been changed. + */ +int touchwin(win) -register WINDOW *win; + register WINDOW *win; { - register int y, maxy; + register int y, maxy; -# ifdef DEBUG - fprintf(outf, "TOUCHWIN(%0.2o)\n", win); -# endif - maxy = win->_maxy; +#ifdef DEBUG + __CTRACE("touchwin: (%0.2o)\n", win); +#endif + maxy = win->maxy; for (y = 0; y < maxy; y++) - touchline(win, y, 0, win->_maxx - 1); + __touchline(win, y, 0, win->maxx - 1, 1); + return (OK); } -/* - * touch a given line - */ -touchline(win, y, sx, ex) -register WINDOW *win; -register int y, sx, ex; + +int +__touchwin(win) + register WINDOW *win; { -# ifdef DEBUG - fprintf(outf, "TOUCHLINE(%0.2o, %d, %d, %d)\n", win, y, sx, ex); - fprintf(outf, "TOUCHLINE:first = %d, last = %d\n", win->_firstch[y], win->_lastch[y]); -# endif - sx += win->_ch_off; - ex += win->_ch_off; - if (win->_firstch[y] == _NOCHANGE) { - win->_firstch[y] = sx; - win->_lastch[y] = ex; - } - else { - if (win->_firstch[y] > sx) - win->_firstch[y] = sx; - if (win->_lastch[y] < ex) - win->_lastch[y] = ex; + register int y, maxy; + +#ifdef DEBUG + __CTRACE("touchwin: (%0.2o)\n", win); +#endif + maxy = win->maxy; + for (y = 0; y < maxy; y++) + __touchline(win, y, 0, win->maxx - 1, 0); + return (OK); +} + +int +__touchline(win, y, sx, ex, force) + register WINDOW *win; + register int y, sx, ex; + int force; +{ +#ifdef DEBUG + __CTRACE("touchline: (%0.2o, %d, %d, %d, %d)\n", win, y, sx, ex, force); + __CTRACE("touchline: first = %d, last = %d\n", + *win->lines[y]->firstchp, *win->lines[y]->lastchp); +#endif + if (force) + win->lines[y]->flags |= __FORCEPAINT; + sx += win->ch_off; + ex += win->ch_off; + if (!(win->lines[y]->flags & __ISDIRTY)) { + win->lines[y]->flags |= __ISDIRTY; + *win->lines[y]->firstchp = sx; + *win->lines[y]->lastchp = ex; + } else { + if (*win->lines[y]->firstchp > sx) + *win->lines[y]->firstchp = sx; + if (*win->lines[y]->lastchp < ex) + *win->lines[y]->lastchp = ex; } -# ifdef DEBUG - fprintf(outf, "TOUCHLINE:first = %d, last = %d\n", win->_firstch[y], win->_lastch[y]); -# endif +#ifdef DEBUG + __CTRACE("touchline: first = %d, last = %d\n", + *win->lines[y]->firstchp, *win->lines[y]->lastchp); +#endif + return (OK); } + + diff --git a/lib/libcurses/tscroll.c b/lib/libcurses/tscroll.c new file mode 100644 index 000000000000..92faeaf399ea --- /dev/null +++ b/lib/libcurses/tscroll.c @@ -0,0 +1,140 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char sccsid[] = "@(#)tscroll.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ + +#include <curses.h> + +#define MAXRETURNSIZE 64 + +/* + * Routine to perform scrolling. Derived from tgoto.c in tercamp(3) library. + * Cap is a string containing printf type escapes to allow + * scrolling. + * The following escapes are defined for substituting n: + * + * %d as in printf + * %2 like %2d + * %3 like %3d + * %. gives %c hacking special case characters + * %+x like %c but adding x first + * + * The codes below affect the state but don't use up a value. + * + * %>xy if value > x add y + * %i increments n + * %% gives % + * %B BCD (2 decimal digits encoded in one byte) + * %D Delta Data (backwards bcd) + * + * all other characters are ``self-inserting''. + */ +char * +__tscroll(cap, n) + const char *cap; + int n; +{ + static char result[MAXRETURNSIZE]; + register char *dp; + register int c; + char *cp; + + if (cap == NULL) { +toohard: + /* + * ``We don't do that under BOZO's big top'' + */ + return ("OOPS"); + } + + cp = (char *) cap; + dp = result; + while (c = *cp++) { + if (c != '%') { + *dp++ = c; + continue; + } + switch (c = *cp++) { + case 'n': + n ^= 0140; + continue; + case 'd': + if (n < 10) + goto one; + if (n < 100) + goto two; + /* fall into... */ + case '3': + *dp++ = (n / 100) | '0'; + n %= 100; + /* fall into... */ + case '2': +two: + *dp++ = n / 10 | '0'; +one: + *dp++ = n % 10 | '0'; + continue; + case '>': + if (n > *cp++) + n += *cp++; + else + cp++; + continue; + case '+': + n += *cp++; + /* fall into... */ + case '.': + *dp++ = n; + continue; + case 'i': + n++; + continue; + case '%': + *dp++ = c; + continue; + + case 'B': + n = (n / 10 << 4) + n % 10; + continue; + case 'D': + n = n - 2 * (n % 16); + continue; + default: + goto toohard; + } + } + *dp = '\0'; + return (result); +} diff --git a/lib/libcurses/tstp.c b/lib/libcurses/tstp.c index 4c5f1a6ebbd6..daac9174d745 100644 --- a/lib/libcurses/tstp.c +++ b/lib/libcurses/tstp.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,42 +32,97 @@ */ #ifndef lint -static char sccsid[] = "@(#)tstp.c 5.6 (Berkeley) 3/3/91"; +static char sccsid[] = "@(#)tstp.c 8.2 (Berkeley) 1/2/94"; #endif /* not lint */ -# include <signal.h> +#include <curses.h> +#include <errno.h> +#include <signal.h> +#include <termios.h> +#include <unistd.h> -# include "curses.ext" /* - * handle stop and start signals - * - * @(#)tstp.c 5.6 (Berkeley) 3/3/91 + * stop_signal_handler -- + * Handle stop signals. */ void -tstp() { - -# ifdef SIGTSTP - - SGTTY tty; - int omask; -# ifdef DEBUG - if (outf) - fflush(outf); -# endif - tty = _tty; - mvcur(0, COLS - 1, LINES - 1, 0); +__stop_signal_handler(signo) + int signo; +{ + struct termios save; + sigset_t oset, set; + + /* Get the current terminal state (which the user may have changed). */ + if (tcgetattr(STDIN_FILENO, &save)) + return; + + /* + * Block window change and timer signals. The latter is because + * applications use timers to decide when to repaint the screen. + */ + (void)sigemptyset(&set); + (void)sigaddset(&set, SIGALRM); + (void)sigaddset(&set, SIGWINCH); + (void)sigprocmask(SIG_BLOCK, &set, &oset); + + /* + * End the window, which also resets the terminal state to the + * original modes. + */ endwin(); - fflush(stdout); - /* reset signal handler so kill below stops us */ - signal(SIGTSTP, SIG_DFL); -#define mask(s) (1 << ((s)-1)) - omask = sigsetmask(sigblock(0) &~ mask(SIGTSTP)); - kill(0, SIGTSTP); - sigblock(mask(SIGTSTP)); - signal(SIGTSTP, tstp); - _tty = tty; - ioctl(_tty_ch, TIOCSETP, &_tty); + + /* Unblock SIGTSTP. */ + (void)sigemptyset(&set); + (void)sigaddset(&set, SIGTSTP); + (void)sigprocmask(SIG_UNBLOCK, &set, NULL); + + /* Stop ourselves. */ + __restore_stophandler(); + (void)kill(0, SIGTSTP); + + /* Time passes ... */ + + /* Reset the curses SIGTSTP signal handler. */ + __set_stophandler(); + + /* save the new "default" terminal state */ + (void)tcgetattr(STDIN_FILENO, &__orig_termios); + + /* Reset the terminal state to the mode just before we stopped. */ + (void)tcsetattr(STDIN_FILENO, __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, &save); + + /* Restart the screen. */ + __startwin(); + + /* Repaint the screen. */ wrefresh(curscr); -# endif SIGTSTP + + /* Reset the signals. */ + (void)sigprocmask(SIG_SETMASK, &oset, NULL); } + +static void (*otstpfn)() = SIG_DFL; + +/* + * Set the TSTP handler. + */ +void +__set_stophandler() +{ + otstpfn = signal(SIGTSTP, __stop_signal_handler); +} + +/* + * Restore the TSTP handler. + */ +void +__restore_stophandler() +{ + (void)signal(SIGTSTP, otstpfn); +} + +/* For compatibility */ + +void tstp() { __stop_signal_handler(SIGTSTP); } diff --git a/lib/libcurses/tty.c b/lib/libcurses/tty.c new file mode 100644 index 000000000000..d0345bfba993 --- /dev/null +++ b/lib/libcurses/tty.c @@ -0,0 +1,277 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char sccsid[] = "@(#)tty.c 8.2 (Berkeley) 1/2/94"; +#endif /* not lint */ + +#include <sys/ioctl.h> + +#include <curses.h> +#include <termios.h> +#include <unistd.h> + +/* + * In general, curses should leave tty hardware settings alone (speed, parity, + * word size). This is most easily done in BSD by using TCSASOFT on all + * tcsetattr calls. On other systems, it would be better to get and restore + * those attributes at each change, or at least when stopped and restarted. + * See also the comments in getterm(). + */ +#ifdef TCSASOFT +int __tcaction = 1; /* Ignore hardware settings. */ +#else +int __tcaction = 0; +#endif + +struct termios __orig_termios, __baset; +static struct termios cbreakt, rawt, *curt; +static int useraw; + +#ifndef OXTABS +#ifdef XTABS /* SMI uses XTABS. */ +#define OXTABS XTABS +#else +#define OXTABS 0 +#endif +#endif + +/* + * gettmode -- + * Do terminal type initialization. + */ +int +gettmode() +{ + useraw = 0; + + if (tcgetattr(STDIN_FILENO, &__orig_termios)) + return (ERR); + + __baset = __orig_termios; + __baset.c_oflag &= ~OXTABS; + + GT = 0; /* historical. was used before we wired OXTABS off */ + NONL = (__baset.c_oflag & ONLCR) == 0; + + /* + * XXX + * System V and SMI systems overload VMIN and VTIME, such that + * VMIN is the same as the VEOF element, and VTIME is the same + * as the VEOL element. This means that, if VEOF was ^D, the + * default VMIN is 4. Majorly stupid. + */ + cbreakt = __baset; + cbreakt.c_lflag &= ~ICANON; + cbreakt.c_cc[VMIN] = 1; + cbreakt.c_cc[VTIME] = 0; + + rawt = cbreakt; + rawt.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|INLCR|IGNCR|ICRNL|IXON); + rawt.c_oflag &= ~OPOST; + rawt.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); + + /* + * In general, curses should leave hardware-related settings alone. + * This includes parity and word size. Older versions set the tty + * to 8 bits, no parity in raw(), but this is considered to be an + * artifact of the old tty interface. If it's desired to change + * parity and word size, the TCSASOFT bit has to be removed from the + * calls that switch to/from "raw" mode. + */ + if (!__tcaction) { + rawt.c_iflag &= ~ISTRIP; + rawt.c_cflag &= ~(CSIZE|PARENB); + rawt.c_cflag |= CS8; + } + + curt = &__baset; + return (tcsetattr(STDIN_FILENO, __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK); +} + +int +raw() +{ + useraw = __pfast = __rawmode = 1; + curt = &rawt; + return (tcsetattr(STDIN_FILENO, __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, curt)); +} + +int +noraw() +{ + useraw = __pfast = __rawmode = 0; + curt = &__baset; + return (tcsetattr(STDIN_FILENO, __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, curt)); +} + +int +cbreak() +{ + + __rawmode = 1; + curt = useraw ? &rawt : &cbreakt; + return (tcsetattr(STDIN_FILENO, __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, curt)); +} + +int +nocbreak() +{ + + __rawmode = 0; + curt = useraw ? &rawt : &__baset; + return (tcsetattr(STDIN_FILENO, __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, curt)); +} + +int +echo() +{ + rawt.c_lflag |= ECHO; + cbreakt.c_lflag |= ECHO; + __baset.c_lflag |= ECHO; + + __echoit = 1; + return (tcsetattr(STDIN_FILENO, __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, curt)); +} + +int +noecho() +{ + rawt.c_lflag &= ~ECHO; + cbreakt.c_lflag &= ~ECHO; + __baset.c_lflag &= ~ECHO; + + __echoit = 0; + return (tcsetattr(STDIN_FILENO, __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, curt)); +} + +int +nl() +{ + rawt.c_iflag |= ICRNL; + rawt.c_oflag |= ONLCR; + cbreakt.c_iflag |= ICRNL; + cbreakt.c_oflag |= ONLCR; + __baset.c_iflag |= ICRNL; + __baset.c_oflag |= ONLCR; + + __pfast = __rawmode; + return (tcsetattr(STDIN_FILENO, __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, curt)); +} + +int +nonl() +{ + rawt.c_iflag &= ~ICRNL; + rawt.c_oflag &= ~ONLCR; + cbreakt.c_iflag &= ~ICRNL; + cbreakt.c_oflag &= ~ONLCR; + __baset.c_iflag &= ~ICRNL; + __baset.c_oflag &= ~ONLCR; + + __pfast = 1; + return (tcsetattr(STDIN_FILENO, __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, curt)); +} + +void +__set_scroll_region(top, bot) +int top, bot; +{ + tputs(SC, 0, __cputchar); + tputs(tgoto(CS, bot, top), 0, __cputchar); + tputs(RC, 0, __cputchar); +} + +void +__startwin() +{ + (void)fflush(stdout); + (void)setvbuf(stdout, NULL, _IOFBF, 0); + + tputs(TI, 0, __cputchar); + tputs(VS, 0, __cputchar); + if (curscr != NULL && __usecs) + __set_scroll_region(0, curscr->maxy - 1); +} + +int +endwin() +{ + __restore_stophandler(); + + if (curscr != NULL) { + if (curscr->flags & __WSTANDOUT) { + tputs(SE, 0, __cputchar); + curscr->flags &= ~__WSTANDOUT; + } + if (__usecs) + __set_scroll_region(0, curscr->maxy - 1); + __mvcur(curscr->cury, curscr->cury, curscr->maxy - 1, 0, 0); + } + + (void)tputs(VE, 0, __cputchar); + (void)tputs(TE, 0, __cputchar); + (void)fflush(stdout); + (void)setvbuf(stdout, NULL, _IOLBF, 0); + + return (tcsetattr(STDIN_FILENO, __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, &__orig_termios)); +} + +/* + * The following routines, savetty and resetty are completely useless and + * are left in only as stubs. If people actually use them they will almost + * certainly screw up the state of the world. + */ +static struct termios savedtty; +int +savetty() +{ + return (tcgetattr(STDIN_FILENO, &savedtty)); +} + +int +resetty() +{ + return (tcsetattr(STDIN_FILENO, __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, &savedtty)); +} diff --git a/lib/libcurses/unctrl.c b/lib/libcurses/unctrl.c index fcd7a2f9a827..ff52230b2e9b 100644 --- a/lib/libcurses/unctrl.c +++ b/lib/libcurses/unctrl.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1981 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,24 +32,76 @@ */ #ifndef lint -static char sccsid[] = "@(#)unctrl.c 5.4 (Berkeley) 6/1/90"; +static char sccsid[] = "@(#)unctrl.c 8.1 (Berkeley) 6/4/93"; #endif /* not lint */ -/* - * define unctrl codes for each character - * - */ +char *__unctrl[256] = { + "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", + "^H", "^I", "^J", "^K", "^L", "^M", "^N", "^O", + "^P", "^Q", "^R", "^S", "^T", "^U", "^V", "^W", + "^X", "^Y", "^Z", "^[", "^\\", "^]", "^~", "^_", + " ", "!", "\"", "#", "$", "%", "&", "'", + "(", ")", "*", "+", ",", "-", ".", "/", + "0", "1", "2", "3", "4", "5", "6", "7", + "8", "9", ":", ";", "<", "=", ">", "?", + "@", "A", "B", "C", "D", "E", "F", "G", + "H", "I", "J", "K", "L", "M", "N", "O", + "P", "Q", "R", "S", "T", "U", "V", "W", + "X", "Y", "Z", "[", "\\", "]", "^", "_", + "`", "a", "b", "c", "d", "e", "f", "g", + "h", "i", "j", "k", "l", "m", "n", "o", + "p", "q", "r", "s", "t", "u", "v", "w", + "x", "y", "z", "{", "|", "}", "~", "^?", + + "0x80", "0x81", "0x82", "0x83", "0x84", "0x85", "0x86", "0x87", + "0x88", "0x89", "0x8a", "0x8b", "0x8c", "0x8d", "0x8e", "0x8f", + "0x90", "0x91", "0x92", "0x93", "0x94", "0x95", "0x96", "0x97", + "0x98", "0x99", "0x9a", "0x9b", "0x9c", "0x9d", "0x9e", "0x9f", + "0xa0", "0xa1", "0xa2", "0xa3", "0xa4", "0xa5", "0xa6", "0xa7", + "0xa8", "0xa9", "0xaa", "0xab", "0xac", "0xad", "0xae", "0xaf", + "0xb0", "0xb1", "0xb2", "0xb3", "0xb4", "0xb5", "0xb6", "0xb7", + "0xb8", "0xb9", "0xba", "0xbb", "0xbc", "0xbd", "0xbe", "0xbf", + "0xc0", "0xc1", "0xc2", "0xc3", "0xc4", "0xc5", "0xc6", "0xc7", + "0xc8", "0xc9", "0xca", "0xcb", "0xcc", "0xcd", "0xce", "0xcf", + "0xd0", "0xd1", "0xd2", "0xd3", "0xd4", "0xd5", "0xd6", "0xd7", + "0xd8", "0xd9", "0xda", "0xdb", "0xdc", "0xdd", "0xde", "0xdf", + "0xe0", "0xe1", "0xe2", "0xe3", "0xe4", "0xe5", "0xe6", "0xe7", + "0xe8", "0xe9", "0xea", "0xeb", "0xec", "0xed", "0xee", "0xef", + "0xf0", "0xf1", "0xf2", "0xf3", "0xf4", "0xf5", "0xf6", "0xf7", + "0xf8", "0xf9", "0xfa", "0xfb", "0xfc", "0xfd", "0xfe", "0xff", +}; -/* LINTLIBRARY */ -char *_unctrl[] = { /* unctrl codes for ttys */ - "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "^I", "^J", "^K", - "^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U", "^V", "^W", - "^X", "^Y", "^Z", "^[", "^\\", "^]", "^~", "^_", - " ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", - ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", - "<", "=", ">", "?", "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", - "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", - "X", "Y", "Z", "[", "\\", "]", "^", "_", "`", "a", "b", "c", "d", "e", - "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", - "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~", "^?" +char __unctrllen[256] = { + 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 2, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, }; |
