From 795172f7a504475a68702297052619a5c90dbfbf Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Fri, 2 Dec 1994 06:40:24 +0000 Subject: [PATCH] Upgrade to version 1.8.6 --- lib/libncurses/COPYRIGHT.NEW | 17 +- lib/libncurses/MKkeyname.awk | 2 +- lib/libncurses/Makefile | 11 +- lib/libncurses/README | 11 +- lib/libncurses/TESTS/README | 1 - lib/libncurses/TESTS/bs.c | 1329 ++++++++++++++++++-------------- lib/libncurses/TESTS/gdc.c | 40 +- lib/libncurses/TESTS/hanoi.c | 3 +- lib/libncurses/TESTS/knight.c | 2 - lib/libncurses/TESTS/ncurses.c | 467 ++++++----- lib/libncurses/copyright.c | 36 +- lib/libncurses/curs_addch.3 | 14 +- lib/libncurses/curs_attr.3 | 5 +- lib/libncurses/curs_bkgd.3 | 2 +- lib/libncurses/curs_border.3 | 2 +- lib/libncurses/curs_color.3 | 2 +- lib/libncurses/curs_delln.3 | 3 - lib/libncurses/curs_inopts.3 | 2 +- lib/libncurses/curs_insstr.3 | 4 +- lib/libncurses/curs_kernel.3 | 6 +- lib/libncurses/curs_outopts.3 | 3 +- lib/libncurses/curs_scr_dmp.3 | 8 +- lib/libncurses/curs_termatt.3 | 2 - lib/libncurses/curs_util.3 | 3 +- lib/libncurses/curs_window.3 | 4 + lib/libncurses/curses.h | 530 +++++++++++++ lib/libncurses/curses.priv.h | 22 +- lib/libncurses/lib_acs.c | 7 +- lib/libncurses/lib_addch.c | 39 +- lib/libncurses/lib_addstr.c | 10 +- lib/libncurses/lib_beep.c | 10 +- lib/libncurses/lib_bkgd.c | 37 + lib/libncurses/lib_color.c | 18 +- lib/libncurses/lib_delch.c | 2 +- lib/libncurses/lib_doupdate.c | 93 ++- lib/libncurses/lib_endwin.c | 19 +- lib/libncurses/lib_erase.c | 2 +- lib/libncurses/lib_getch.c | 11 +- lib/libncurses/lib_getstr.c | 22 +- lib/libncurses/lib_initscr.c | 6 +- lib/libncurses/lib_insdel.c | 4 +- lib/libncurses/lib_kernel.c | 73 +- lib/libncurses/lib_longname.c | 2 +- lib/libncurses/lib_move.c | 5 +- lib/libncurses/lib_mvcur.c | 49 +- lib/libncurses/lib_mvwin.c | 2 +- lib/libncurses/lib_newterm.c | 20 +- lib/libncurses/lib_newwin.c | 5 +- lib/libncurses/lib_options.c | 37 +- lib/libncurses/lib_pad.c | 11 +- lib/libncurses/lib_printw.c | 10 +- lib/libncurses/lib_raw.c | 2 +- lib/libncurses/lib_scanw.c | 12 +- lib/libncurses/lib_scroll.c | 198 ++--- lib/libncurses/lib_scrreg.c | 18 +- lib/libncurses/lib_set_term.c | 8 +- lib/libncurses/lib_slk.c | 53 +- lib/libncurses/lib_trace.c | 41 +- lib/libncurses/lib_tstp.c | 4 +- lib/libncurses/lib_twait.c | 60 +- lib/libncurses/lib_unctrl.c | 8 +- lib/libncurses/lib_vidattr.c | 167 ++-- lib/libncurses/lib_window.c | 19 +- lib/libncurses/ncurses.3 | 2 +- lib/libncurses/termcap.h | 27 + lib/libncurses/terminfo.h | 2 + lib/libncurses/unctrl.h | 4 +- lib/libncurses/version.h | 2 +- lib/ncurses/ncurses/Makefile | 11 +- 69 files changed, 2290 insertions(+), 1373 deletions(-) create mode 100644 lib/libncurses/curses.h create mode 100644 lib/libncurses/lib_bkgd.c create mode 100644 lib/libncurses/terminfo.h diff --git a/lib/libncurses/COPYRIGHT.NEW b/lib/libncurses/COPYRIGHT.NEW index 4a79f1df92cb..7c5d22b55d9a 100644 --- a/lib/libncurses/COPYRIGHT.NEW +++ b/lib/libncurses/COPYRIGHT.NEW @@ -1,18 +1,19 @@ /*************************************************************************** -* COPYRIGHT NOTICE * +* COPYRIGHT NOTICE * **************************************************************************** -* ncurses is copyright (C) 1992, 1993, 1994 * -* by Zeyd M. Ben-Halim * -* zmbenhal@netcom.com * +* ncurses is copyright (C) 1992, 1993, 1994 * +* by Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * * * * Permission is hereby granted to reproduce and distribute ncurses * * by any means and for any fee, whether alone or as part of a * * larger distribution, in source or in binary form, PROVIDED * -* this notice remains in the sources and is reproduced in any * -* documentation accompanying it or the applications linked with it. * -* Any other use of ncurses, including incorporating it in another * -* product is subject to written permission. * +* this notice is included with any such distribution, not removed * +* from header files, and is reproduced in any documentation * +* accompanying it or the applications linked with it. * * * * ncurses comes AS IS with no warranty, implied or expressed. * * * ***************************************************************************/ + + diff --git a/lib/libncurses/MKkeyname.awk b/lib/libncurses/MKkeyname.awk index be51bc8e4281..12613cea3895 100644 --- a/lib/libncurses/MKkeyname.awk +++ b/lib/libncurses/MKkeyname.awk @@ -2,7 +2,7 @@ BEGIN { print "" print "#include " - print "#include " + print "#include \"curses.h\"" print "" print "struct kn {" print "\tchar *name;" diff --git a/lib/libncurses/Makefile b/lib/libncurses/Makefile index 9ed3a674a24d..b17b8b9cec86 100644 --- a/lib/libncurses/Makefile +++ b/lib/libncurses/Makefile @@ -1,8 +1,8 @@ # Makefile for ncurses -# $Id: Makefile,v 1.6 1994/10/28 06:56:55 ache Exp $ +# $Id: Makefile,v 1.7 1994/11/29 02:48:17 ache Exp $ LIB= ncurses -SRCS= lib_kernel.c lib_pad.c\ +SRCS= lib_kernel.c lib_pad.c lib_bkgd.c \ lib_unctrl.c lib_raw.c lib_vidattr.c lib_trace.c lib_beep.c \ lib_doupdate.c lib_refresh.c lib_initscr.c lib_newwin.c lib_addch.c \ lib_addstr.c lib_scroll.c lib_clreol.c lib_touch.c lib_mvcur.c lib_keyname.c\ @@ -13,7 +13,7 @@ SRCS= lib_kernel.c lib_pad.c\ lib_newterm.c lib_set_term.c lib_overlay.c lib_scrreg.c lib_color.c \ lib_insstr.c lib_insdel.c lib_twait.c copyright.c -CFLAGS+= -I. -I${.CURDIR} -Wall -DMYTINFO -DTERMIOS -DGOOD_SELECT -DBSDTABS +CFLAGS+= -I. -I${.CURDIR} -Wall -DMYTINFO -DGOOD_SELECT LDADD+= -lmytinfo CLEANFILES+= lib_keyname.c keys.tries @@ -21,10 +21,13 @@ CLEANFILES+= lib_keyname.c keys.tries beforedepend: keys.tries beforeinstall: - @cd ${.CURDIR}; for i in ncurses.h unctrl.h termcap.h; do \ + @cd ${.CURDIR}; for i in unctrl.h termcap.h; do \ cmp -s $$i ${DESTDIR}/usr/include/$$i || \ $(INSTALL) $(COPY) -m 444 -o $(BINOWN) -g $(BINGRP) $$i \ ${DESTDIR}/usr/include; done + @cd ${.CURDIR}; cmp -s curses.h ${DESTDIR}/usr/include/ncurses.h || \ + $(INSTALL) $(COPY) -m 444 -o $(BINOWN) -g $(BINGRP) curses.h \ + ${DESTDIR}/usr/include/ncurses.h keys.tries: ${.CURDIR}/keys.list ${.CURDIR}/MKkeys.awk awk -f ${.CURDIR}/MKkeys.awk ${.CURDIR}/keys.list > keys.tries diff --git a/lib/libncurses/README b/lib/libncurses/README index ad58ccdf36a1..d1f93bb7d0e3 100644 --- a/lib/libncurses/README +++ b/lib/libncurses/README @@ -1,10 +1,12 @@ +NCURSES 1.8.6 - July 24, 1994 +----------------------------- This file is intended to help people interested in working on fixing ncurses, enhancing it, or porting it to other platforms. PORTABILITY: -The file matrix is an attempt and centralizing all portability -information. The top line contains the different options, down +The file matrix is an attempt at centralizing all portability +information. The top line lists the different options, down the leftside are the operating systems supported. If an option is not needed then it should have an entry of NONE. Note the use of ':' to terminate each field. If somebody knows awk better @@ -23,13 +25,14 @@ SRCDIR: the directory where the terminfo database lives CC: ANSI C compiler FLAGS: standard compiler flags EXTRA: extra flags needed by individual systems - Linux: -DBROKEN_TCDRAIN tcdrain() is broken on Linux Sun: -DSUNIOCTL conflicts with HP-UX: -D_HPUX_SOURCE so that we get POSIX and XOPEN features. SVR4: -DBROKEN_TIOCGETWINSZ guess what? + AIX: -DSYS_SELECT if you need BASE: The directory under which headers and libraries will be installed. -INSTALL: The name of an intelligent install program. GNU install works. +INSTALL: The name of an install program similar to BSD's (ie. understands + -m, -g, -o, etc.) GNU install works. The awk script in script.src reads matrix and generates all the Config.* files. diff --git a/lib/libncurses/TESTS/README b/lib/libncurses/TESTS/README index 7f45243ff1e4..279c6d8479ba 100644 --- a/lib/libncurses/TESTS/README +++ b/lib/libncurses/TESTS/README @@ -19,4 +19,3 @@ worm.c - worms run all over your screen firework.c - multi-colored fireworks newdemo.c - a demo from the PDCurses people testcurs.c - a test from the PDCurses people - This will fail to link on machines that don't have vsscanf(). diff --git a/lib/libncurses/TESTS/bs.c b/lib/libncurses/TESTS/bs.c index 8d4183048e9f..3785fcdaf886 100644 --- a/lib/libncurses/TESTS/bs.c +++ b/lib/libncurses/TESTS/bs.c @@ -4,29 +4,43 @@ * with improved user interface, autoconfiguration and code cleanup * by Eric S. Raymond * v1.2 with color support and minor portability fixes, November 1990 + * v2.0 featuring strict ANSI/POSIX conformance, November 1993. */ -#include #include -#include -#ifndef NONPOSIX -#include -#endif #include -#include -#include #include #include -#ifdef SYSV /* aha, must be an AT&T system... */ +#ifndef A_UNDERLINE /* BSD curses */ +#define beep() write(1,"\007",1); +#define cbreak crmode +#define saveterm savetty +#define resetterm resetty +#define nocbreak nocrmode +#define strchr index +#endif /* !A_UNDERLINE */ + +#ifdef isxdigit /* aha, must be an AT&T system... */ #define srand(n) srand48(n) #define rand() lrand48() extern long lrand48(); extern void srand48(); -#define bzero(s, n) memset((char *)(s), '\0', n) +#define bzero(s, n) (void)memset((char *)(s), '\0', n) extern char *memset(); -#endif /* SYSV */ +/* + * Try this if ungetch() fails to resolve. + * + * #define ungetch ungetc + */ +#endif /* isxdigit */ +extern unsigned sleep(); +extern char *strchr(), *strcpy(); +extern long time(); +extern void exit(); + +static bool checkplace(); /* * Constants for tuning the random-fire algorithm. It prefers moves that @@ -59,14 +73,14 @@ extern char *memset(); #define PXBASE 3 #define PY(y) (PYBASE + (y)) #define PX(x) (PXBASE + (x)*3) -#define pgoto(y, x) move(PY(y), PX(x)) +#define pgoto(y, x) (void)move(PY(y), PX(x)) /* how to position us on cpu board */ #define CYBASE 3 #define CXBASE 48 #define CY(y) (CYBASE + (y)) #define CX(x) (CXBASE + (x)*3) -#define cgoto(y, x) move(CY(y), CX(x)) +#define cgoto(y, x) (void)move(CY(y), CX(x)) #define ONBOARD(x, y) (x >= 0 && x < BWIDTH && y >= 0 && y < BDEPTH) @@ -90,7 +104,7 @@ static char destroy[] = "Destroyer"; static char ptboat[] = "PT Boat"; static char name[40]; -static char dftname[] = "Stranger"; +static char dftname[] = "stranger"; /* direction constants */ #define E 0 @@ -115,7 +129,7 @@ typedef struct char symbol; /* symbol for game purposes */ char length; /* length of ship */ char x, y; /* coordinates of ship start point */ - int dir; /* direction of `bow' */ + char dir; /* direction of `bow' */ bool placed; /* has it been placed on the board? */ } ship_t; @@ -146,74 +160,78 @@ static int plywon=0, cpuwon=0; /* How many games has each won? */ static int salvo, blitz, closepack; -#define PR addstr +#define PR (void)addstr -static int rnd(int); -static int checkplace(int, ship_t *, int); -static int getcoord(int); - -static void uninitgame() +static void uninitgame(sig) /* end the game, either normally or due to signal */ +int sig; { clear(); - refresh(); - resetterm(); - echo(); - endwin(); + (void)refresh(); + (void)resetterm(); + (void)echo(); + (void)endwin(); exit(0); } static void announceopts() /* announce which game options are enabled */ { - if (salvo || blitz || closepack) { - printw("Playing optional game ("); - if (salvo) - printw("salvo, "); - else - printw("nosalvo, "); - if (blitz) - printw("blitz "); - else - printw("noblitz, "); - if (closepack) - printw("closepack)"); - else - printw("noclosepack)"); + if (salvo || blitz || closepack) + { + (void) printw("Playing optional game ("); + if (salvo) + (void) printw("salvo, "); + else + (void) printw("nosalvo, "); + if (blitz) + (void) printw("blitz "); + else + (void) printw("noblitz, "); + if (closepack) + (void) printw("closepack)"); + else + (void) printw("noclosepack)"); } - else - printw( "Playing standard game (noblitz, nosalvo, noclosepack)"); - + else + (void) printw( + "Playing standard game (noblitz, nosalvo, noclosepack)"); } static void intro() { -char *tmpname; + extern char *getlogin(); + char *tmpname; srand(time(0L)+getpid()); /* Kick the random number generator */ - signal(SIGINT,uninitgame); - signal(SIGINT,uninitgame); - signal(SIGIOT,uninitgame); /* for assert(3) */ + (void) signal(SIGINT,uninitgame); + (void) signal(SIGINT,uninitgame); + (void) signal(SIGIOT,uninitgame); /* for assert(3) */ if(signal(SIGQUIT,SIG_IGN) != SIG_IGN) - signal(SIGQUIT,uninitgame); + (void)signal(SIGQUIT,uninitgame); - if ((tmpname = getlogin()) != NULL) - strcpy(name,tmpname); + if(tmpname = getlogin()) + { + (void)strcpy(name,tmpname); + name[0] = toupper(name[0]); + } else - strcpy(name,dftname); - name[0] = toupper(name[0]); + (void)strcpy(name,dftname); - initscr(); - saveterm(); - nonl(); - cbreak(); - noecho(); + (void)initscr(); +#ifdef KEY_MIN + keypad(stdscr, TRUE); +#endif /* KEY_MIN */ + (void)saveterm(); + (void)nonl(); + (void)cbreak(); + (void)noecho(); #ifdef PENGUIN - clear(); - mvaddstr(4,29,"Welcome to Battleship!"); - move(8,0); + (void)clear(); + (void)mvaddstr(4,29,"Welcome to Battleship!"); + (void)move(8,0); PR(" \\\n"); PR(" \\ \\ \\\n"); PR(" \\ \\ \\ \\ \\_____________\n"); @@ -225,87 +243,10 @@ char *tmpname; PR(" \\ /\n"); PR(" \\___________________________________________________/\n"); - mvaddstr(22,27,"Hit any key to continue..."); refresh(); - getch(); + (void) mvaddstr(22,27,"Hit any key to continue..."); (void)refresh(); + (void) getch(); #endif /* PENGUIN */ - clear(); - mvaddstr(0,35,"BATTLESHIPS"); - move(PROMPTLINE + 2, 0); - announceopts(); - - mvaddstr(MYBASE, MXBASE, "Aiming keys:"); - mvaddstr(SYBASE, SXBASE, "y k u 7 8 9"); - mvaddstr(SYBASE+1, SXBASE, " \\|/ \\|/ "); - mvaddstr(SYBASE+2, SXBASE, "h-+-l 4-+-6"); - mvaddstr(SYBASE+3, SXBASE, " /|\\ /|\\ "); - mvaddstr(SYBASE+4, SXBASE, "b j n 1 2 3"); -} - -/* VARARGS1 */ -static void prompt(n, f, s) -/* print a message at the prompt line */ -int n; -char *f, *s; -{ - move(PROMPTLINE + n, 0); - clrtoeol(); - printw(f, s); - refresh(); -} - -static void error(s) -char *s; -{ - move(PROMPTLINE + 2, 0); - clrtoeol(); - if (s) { - addstr(s); - beep(); - } -} - -static void placeship(b, ss, vis) -int b; -ship_t *ss; -int vis; -{ -int l; - - for(l = 0; l < ss->length; ++l) { - int newx = ss->x + l * xincr[ss->dir]; - int newy = ss->y + l * yincr[ss->dir]; - - board[b][newx][newy] = ss->symbol; - if (vis) { - pgoto(newy, newx); - addch((chtype)ss->symbol); - } - } - ss->hits = 0; -} - -static void randomplace(b, ss) -/* generate a valid random ship placement into px,py */ -int b; -ship_t *ss; -{ -register int bwidth = BWIDTH - ss->length; -register int bdepth = BDEPTH - ss->length; - - do { - ss->y = rnd(bdepth); - ss->x = rnd(bwidth); - ss->dir = rnd(2) ? E : S; - } while - (!checkplace(b, ss, FALSE)); -} - -static void initgame() -{ -int i, j, unplaced; -ship_t *ss; - #ifdef A_COLOR start_color(); @@ -319,166 +260,52 @@ ship_t *ss; init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); #endif /* A_COLOR */ - bzero(board, sizeof(char) * BWIDTH * BDEPTH * 2); - bzero(hits, sizeof(char) * BWIDTH * BDEPTH * 2); - for (i = 0; i < SHIPTYPES; i++) { - ss = cpuship + i; - ss->x = ss->y = ss->dir = ss->hits = ss->placed = 0; - ss = plyship + i; - ss->x = ss->y = ss->dir = ss->hits = ss->placed = 0; +} + +/* VARARGS1 */ +static void prompt(n, f, s) +/* print a message at the prompt line */ +int n; +char *f, *s; +{ + (void) move(PROMPTLINE + n, 0); + (void) clrtoeol(); + (void) printw(f, s); + (void) refresh(); +} + +static void error(s) +char *s; +{ + (void) move(PROMPTLINE + 2, 0); + (void) clrtoeol(); + if (s) + { + (void) addstr(s); + (void) beep(); } +} - /* draw empty boards */ - mvaddstr(PYBASE - 2, PXBASE + 5, "Main Board"); - mvaddstr(PYBASE - 1, PXBASE - 3,numbers); - for(i=0; i < BDEPTH; ++i) { - mvaddch(PYBASE + i, PXBASE - 3, i + 'A'); -#ifdef A_COLOR - if (has_colors()) - attron(COLOR_PAIR(COLOR_BLUE)); -#endif /* A_COLOR */ - addch(' '); - for (j = 0; j < BWIDTH; j++) - addstr(" . "); -#ifdef A_COLOR - attrset(0); -#endif /* A_COLOR */ - addch(' '); - addch(i + 'A'); +static void placeship(b, ss, vis) +int b; +ship_t *ss; +int vis; +{ + int l; + + for(l = 0; l < ss->length; ++l) + { + int newx = ss->x + l * xincr[ss->dir]; + int newy = ss->y + l * yincr[ss->dir]; + + board[b][newx][newy] = ss->symbol; + if (vis) + { + pgoto(newy, newx); + (void) addch((chtype)ss->symbol); + } } - mvaddstr(PYBASE + BDEPTH, PXBASE - 3,numbers); - mvaddstr(CYBASE - 2, CXBASE + 7,"Hit/Miss Board"); - mvaddstr(CYBASE - 1, CXBASE - 3, numbers); - for(i=0; i < BDEPTH; ++i) { - mvaddch(CYBASE + i, CXBASE - 3, i + 'A'); -#ifdef A_COLOR - if (has_colors()) - attron(COLOR_PAIR(COLOR_BLUE)); -#endif /* A_COLOR */ - addch(' '); - for (j = 0; j < BWIDTH; j++) - addstr(" . "); -#ifdef A_COLOR - attrset(0); -#endif /* A_COLOR */ - addch(' '); - addch(i + 'A'); - } - mvaddstr(CYBASE + BDEPTH,CXBASE - 3,numbers); - - mvprintw(HYBASE, HXBASE, - "To position your ships: move the cursor to a spot, then"); - mvprintw(HYBASE+1,HXBASE, - "type the first letter of a ship type to select it, then"); - mvprintw(HYBASE+2,HXBASE, - "type a direction ([hjkl] or [4862]), indicating how the"); - mvprintw(HYBASE+3,HXBASE, - "ship should be pointed. You may also type a ship letter"); - mvprintw(HYBASE+4,HXBASE, - "followed by `r' to position it randomly, or type `R' to"); - mvprintw(HYBASE+5,HXBASE, - "place all remaining ships randomly."); - - /* have the computer place ships */ - for(ss = cpuship; ss < cpuship + SHIPTYPES; ss++) { - randomplace(COMPUTER, ss); - placeship(COMPUTER, ss, FALSE); - } - - ss = (ship_t *)NULL; - do { - char c, docked[SHIPTYPES + 2], *cp = docked; - - /* figure which ships still wait to be placed */ - *cp++ = 'R'; - for (i = 0; i < SHIPTYPES; i++) - if (!plyship[i].placed) - *cp++ = plyship[i].symbol; - *cp = '\0'; - - /* get a command letter */ - prompt(1, "Type one of [%s] to pick a ship.", docked+1); - do { - c = getcoord(PLAYER); - } while - (!strchr(docked, c)); - - if (c == 'R') - ungetch('R'); - else - { - /* map that into the corresponding symbol */ - for (ss = plyship; ss < plyship + SHIPTYPES; ss++) - if (ss->symbol == c) - break; - - prompt(1, "Type one of [hjklrR] to place your %s.", ss->name); - pgoto(cury, curx); - } - - do { - c = getch(); - } while - (!strchr("hjklrR", c) || c == FF); - - if (c == FF) { - clearok(stdscr, TRUE); - refresh(); - } else if (c == 'r') { - prompt(1, "Random-placing your %s", ss->name); - randomplace(PLAYER, ss); - placeship(PLAYER, ss, TRUE); - error((char *)NULL); - ss->placed = TRUE; - } else if (c == 'R') { - prompt(1, "Placing the rest of your fleet at random..."); - for (ss = plyship; ss < plyship + SHIPTYPES; ss++) - if (!ss->placed) { - randomplace(PLAYER, ss); - placeship(PLAYER, ss, TRUE); - ss->placed = TRUE; - } - error((char *)NULL); - } else if (strchr("hjkl8462", c)) { - ss->x = curx; - ss->y = cury; - - switch(c) { - case 'k': case '8': ss->dir = N; break; - case 'j': case '2': ss->dir = S; break; - case 'h': case '4': ss->dir = W; break; - case 'l': case '6': ss->dir = E; break; - } - - if (checkplace(PLAYER, ss, TRUE)) { - placeship(PLAYER, ss, TRUE); - error((char *)NULL); - ss->placed = TRUE; - } - } - - for (unplaced = i = 0; i < SHIPTYPES; i++) - unplaced += !plyship[i].placed; - } while - (unplaced); - - turn = rnd(2); - - mvprintw(HYBASE, HXBASE, - "To fire, move the cursor to your chosen aiming point "); - mvprintw(HYBASE+1, HXBASE, - "and strike any key other than a motion key. "); - mvprintw(HYBASE+2, HXBASE, - " "); - mvprintw(HYBASE+3, HXBASE, - " "); - mvprintw(HYBASE+4, HXBASE, - " "); - mvprintw(HYBASE+5, HXBASE, - " "); - - prompt(0, "Press any key to start..."); - getch(); + ss->hits = 0; } static int rnd(n) @@ -487,49 +314,306 @@ int n; return(((rand() & 0x7FFF) % n)); } +static void randomplace(b, ss) +/* generate a valid random ship placement into px,py */ +int b; +ship_t *ss; +{ + register int bwidth = BWIDTH - ss->length; + register int bdepth = BDEPTH - ss->length; + + do { + ss->y = rnd(bdepth); + ss->x = rnd(bwidth); + ss->dir = rnd(2) ? E : S; + } while + (!checkplace(b, ss, FALSE)); +} + +static void initgame() +{ + int i, j, unplaced; + ship_t *ss; + + (void) clear(); + (void) mvaddstr(0,35,"BATTLESHIPS"); + (void) move(PROMPTLINE + 2, 0); + announceopts(); + + bzero(board, sizeof(char) * BWIDTH * BDEPTH * 2); + bzero(hits, sizeof(char) * BWIDTH * BDEPTH * 2); + for (i = 0; i < SHIPTYPES; i++) + { + ss = cpuship + i; + ss->x = ss->y = ss->dir = ss->hits = ss->placed = 0; + ss = plyship + i; + ss->x = ss->y = ss->dir = ss->hits = ss->placed = 0; + } + + /* draw empty boards */ + (void) mvaddstr(PYBASE - 2, PXBASE + 5, "Main Board"); + (void) mvaddstr(PYBASE - 1, PXBASE - 3,numbers); + for(i=0; i < BDEPTH; ++i) + { + (void) mvaddch(PYBASE + i, PXBASE - 3, i + 'A'); +#ifdef A_COLOR + if (has_colors()) + attron(COLOR_PAIR(COLOR_BLUE)); +#endif /* A_COLOR */ + (void) addch(' '); + for (j = 0; j < BWIDTH; j++) + (void) addstr(" . "); +#ifdef A_COLOR + attrset(0); +#endif /* A_COLOR */ + (void) addch(' '); + (void) addch(i + 'A'); + } + (void) mvaddstr(PYBASE + BDEPTH, PXBASE - 3,numbers); + (void) mvaddstr(CYBASE - 2, CXBASE + 7,"Hit/Miss Board"); + (void) mvaddstr(CYBASE - 1, CXBASE - 3, numbers); + for(i=0; i < BDEPTH; ++i) + { + (void) mvaddch(CYBASE + i, CXBASE - 3, i + 'A'); +#ifdef A_COLOR + if (has_colors()) + attron(COLOR_PAIR(COLOR_BLUE)); +#endif /* A_COLOR */ + (void) addch(' '); + for (j = 0; j < BWIDTH; j++) + (void) addstr(" . "); +#ifdef A_COLOR + attrset(0); +#endif /* A_COLOR */ + (void) addch(' '); + (void) addch(i + 'A'); + } + + (void) mvaddstr(CYBASE + BDEPTH,CXBASE - 3,numbers); + + (void) mvprintw(HYBASE, HXBASE, + "To position your ships: move the cursor to a spot, then"); + (void) mvprintw(HYBASE+1,HXBASE, + "type the first letter of a ship type to select it, then"); + (void) mvprintw(HYBASE+2,HXBASE, + "type a direction ([hjkl] or [4862]), indicating how the"); + (void) mvprintw(HYBASE+3,HXBASE, + "ship should be pointed. You may also type a ship letter"); + (void) mvprintw(HYBASE+4,HXBASE, + "followed by `r' to position it randomly, or type `R' to"); + (void) mvprintw(HYBASE+5,HXBASE, + "place all remaining ships randomly."); + + (void) mvaddstr(MYBASE, MXBASE, "Aiming keys:"); + (void) mvaddstr(SYBASE, SXBASE, "y k u 7 8 9"); + (void) mvaddstr(SYBASE+1, SXBASE, " \\|/ \\|/ "); + (void) mvaddstr(SYBASE+2, SXBASE, "h-+-l 4-+-6"); + (void) mvaddstr(SYBASE+3, SXBASE, " /|\\ /|\\ "); + (void) mvaddstr(SYBASE+4, SXBASE, "b j n 1 2 3"); + + /* have the computer place ships */ + for(ss = cpuship; ss < cpuship + SHIPTYPES; ss++) + { + randomplace(COMPUTER, ss); + placeship(COMPUTER, ss, FALSE); + } + + ss = (ship_t *)NULL; + do { + extern char *strchr(); + static char getcoord(); + char c, docked[SHIPTYPES + 2], *cp = docked; + + /* figure which ships still wait to be placed */ + *cp++ = 'R'; + for (i = 0; i < SHIPTYPES; i++) + if (!plyship[i].placed) + *cp++ = plyship[i].symbol; + *cp = '\0'; + + /* get a command letter */ + prompt(1, "Type one of [%s] to pick a ship.", docked+1); + do { + c = getcoord(PLAYER); + } while + (!strchr(docked, c)); + + if (c == 'R') + (void) ungetch('R'); + else + { + /* map that into the corresponding symbol */ + for (ss = plyship; ss < plyship + SHIPTYPES; ss++) + if (ss->symbol == c) + break; + + prompt(1, "Type one of [hjklrR] to place your %s.", ss->name); + pgoto(cury, curx); + } + + do { + c = getch(); + } while + (!strchr("hjklrR", c) || c == FF); + + if (c == FF) + { + (void)clearok(stdscr, TRUE); + (void)refresh(); + } + else if (c == 'r') + { + prompt(1, "Random-placing your %s", ss->name); + randomplace(PLAYER, ss); + placeship(PLAYER, ss, TRUE); + error((char *)NULL); + ss->placed = TRUE; + } + else if (c == 'R') + { + prompt(1, "Placing the rest of your fleet at random..."); + for (ss = plyship; ss < plyship + SHIPTYPES; ss++) + if (!ss->placed) + { + randomplace(PLAYER, ss); + placeship(PLAYER, ss, TRUE); + ss->placed = TRUE; + } + error((char *)NULL); + } + else if (strchr("hjkl8462", c)) + { + ss->x = curx; + ss->y = cury; + + switch(c) + { + case 'k': case '8': ss->dir = N; break; + case 'j': case '2': ss->dir = S; break; + case 'h': case '4': ss->dir = W; break; + case 'l': case '6': ss->dir = E; break; + } + + if (checkplace(PLAYER, ss, TRUE)) + { + placeship(PLAYER, ss, TRUE); + error((char *)NULL); + ss->placed = TRUE; + } + } + + for (unplaced = i = 0; i < SHIPTYPES; i++) + unplaced += !plyship[i].placed; + } while + (unplaced); + + turn = rnd(2); + + (void) mvprintw(HYBASE, HXBASE, + "To fire, move the cursor to your chosen aiming point "); + (void) mvprintw(HYBASE+1, HXBASE, + "and strike any key other than a motion key. "); + (void) mvprintw(HYBASE+2, HXBASE, + " "); + (void) mvprintw(HYBASE+3, HXBASE, + " "); + (void) mvprintw(HYBASE+4, HXBASE, + " "); + (void) mvprintw(HYBASE+5, HXBASE, + " "); + + (void) prompt(0, "Press any key to start..."); + (void) getch(); +} + static int getcoord(atcpu) int atcpu; { -int ny, nx, c; + int ny, nx, c; if (atcpu) - cgoto(cury,curx); + cgoto(cury,curx); else - pgoto(cury, curx); - refresh(); - for (;;) { - if (atcpu) { - mvprintw(CYBASE + BDEPTH+1, CXBASE+11, "(%d, %c)", curx, 'A'+cury); - cgoto(cury, curx); - } else { - mvprintw(PYBASE + BDEPTH+1, PXBASE+11, "(%d, %c)", curx, 'A'+cury); - pgoto(cury, curx); - } + pgoto(cury, curx); + (void)refresh(); + for (;;) + { + if (atcpu) + { + (void) mvprintw(CYBASE + BDEPTH+1, CXBASE+11, "(%d, %c)", curx, 'A'+cury); + cgoto(cury, curx); + } + else + { + (void) mvprintw(PYBASE + BDEPTH+1, PXBASE+11, "(%d, %c)", curx, 'A'+cury); + pgoto(cury, curx); + } - switch(c = getch()) { - case 'k': case '8': ny = cury+BDEPTH-1; nx = curx; break; - case 'j': case '2': ny = cury+1; nx = curx; break; - case 'h': case '4': ny = cury; nx = curx+BWIDTH-1; break; - case 'l': case '6': ny = cury; nx = curx+1; break; - case 'y': case '7': ny = cury+BDEPTH-1; nx = curx+BWIDTH-1; break; - case 'b': case '1': ny = cury+1; nx = curx+BWIDTH-1; break; - case 'u': case '9': ny = cury+BDEPTH-1; nx = curx+1; break; - case 'n': case '3': ny = cury+1; nx = curx+1; break; - case FF: - nx = curx; ny = cury; - clearok(stdscr, TRUE); - refresh(); - break; - default: - if (atcpu) - mvaddstr(CYBASE + BDEPTH + 1, CXBASE + 11, " "); - else - mvaddstr(PYBASE + BDEPTH + 1, PXBASE + 11, " "); - return(c); - } + switch(c = getch()) + { + case 'k': case '8': +#ifdef KEY_MIN + case KEY_UP: +#endif /* KEY_MIN */ + ny = cury+BDEPTH-1; nx = curx; + break; + case 'j': case '2': +#ifdef KEY_MIN + case KEY_DOWN: +#endif /* KEY_MIN */ + ny = cury+1; nx = curx; + break; + case 'h': case '4': +#ifdef KEY_MIN + case KEY_LEFT: +#endif /* KEY_MIN */ + ny = cury; nx = curx+BWIDTH-1; + break; + case 'l': case '6': +#ifdef KEY_MIN + case KEY_RIGHT: +#endif /* KEY_MIN */ + ny = cury; nx = curx+1; + break; + case 'y': case '7': +#ifdef KEY_MIN + case KEY_A1: +#endif /* KEY_MIN */ + ny = cury+BDEPTH-1; nx = curx+BWIDTH-1; + break; + case 'b': case '1': +#ifdef KEY_MIN + case KEY_C1: +#endif /* KEY_MIN */ + ny = cury+1; nx = curx+BWIDTH-1; + break; + case 'u': case '9': +#ifdef KEY_MIN + case KEY_A3: +#endif /* KEY_MIN */ + ny = cury+BDEPTH-1; nx = curx+1; + break; + case 'n': case '3': +#ifdef KEY_MIN + case KEY_C3: +#endif /* KEY_MIN */ + ny = cury+1; nx = curx+1; + break; + case FF: + nx = curx; ny = cury; + (void)clearok(stdscr, TRUE); + (void)refresh(); + break; + default: + if (atcpu) + (void) mvaddstr(CYBASE + BDEPTH + 1, CXBASE + 11, " "); + else + (void) mvaddstr(PYBASE + BDEPTH + 1, PXBASE + 11, " "); + return(c); + } - curx = nx % BWIDTH; - cury = ny % BDEPTH; + curx = nx % BWIDTH; + cury = ny % BDEPTH; } } @@ -538,29 +622,31 @@ static int collidecheck(b, y, x) int b; int y, x; { -int collide; + int collide; /* anything on the square */ - if ((collide = IS_SHIP(board[b][x][y])) != 0) - return(collide); + if (collide = IS_SHIP(board[b][x][y])) + return(collide); /* anything on the neighbors */ - if (!closepack) { + if (!closepack) + { int i; - for (i = 0; i < 8; i++) { - int xend, yend; + for (i = 0; i < 8; i++) + { + int xend, yend; - yend = y + yincr[i]; - xend = x + xincr[i]; - if (ONBOARD(xend, yend)) - collide += IS_SHIP(board[b][xend][yend]); - } + yend = y + yincr[i]; + xend = x + xincr[i]; + if (ONBOARD(xend, yend)) + collide += IS_SHIP(board[b][xend][yend]); + } } return(collide); } -static int checkplace(b, ss, vis) +static bool checkplace(b, ss, vis) int b; ship_t *ss; int vis; @@ -570,54 +656,60 @@ int vis; /* first, check for board edges */ xend = ss->x + ss->length * xincr[ss->dir]; yend = ss->y + ss->length * yincr[ss->dir]; - if (!ONBOARD(xend, yend)) { - if(vis) - switch(rnd(3)) { + if (!ONBOARD(xend, yend)) + { + if (vis) + switch(rnd(3)) + { case 0: - error("Ship is hanging from the edge of the world"); - break; + error("Ship is hanging from the edge of the world"); + break; case 1: - error("Try fitting it on the board"); - break; + error("Try fitting it on the board"); + break; case 2: - error("Figure I won't find it if you put it there?"); - break; + error("Figure I won't find it if you put it there?"); + break; } - return(0); + return(0); } - for(l = 0; l < ss->length; ++l) { - if (collidecheck(b, ss->y+l*yincr[ss->dir], ss->x+l*xincr[ss->dir])) { - if (vis) - switch(rnd(3)) { + for(l = 0; l < ss->length; ++l) + { + if(collidecheck(b, ss->y+l*yincr[ss->dir], ss->x+l*xincr[ss->dir])) + { + if (vis) + switch(rnd(3)) + { case 0: - error("There's already a ship there"); - break; + error("There's already a ship there"); + break; case 1: - error("Collision alert! Aaaaaagh!"); - break; + error("Collision alert! Aaaaaagh!"); + break; case 2: - error("Er, Admiral, what about the other ship?"); - break; + error("Er, Admiral, what about the other ship?"); + break; } - return(0); + return(FALSE); } } - return(1); + return(TRUE); } static int awinna() { -int i, j; -ship_t *ss; + int i, j; + ship_t *ss; - for (i = 0; i < 2; ++i) { - ss = (i) ? cpuship : plyship; - for (j = 0; j < SHIPTYPES; ++j, ++ss) - if (ss->length > ss->hits) - break; - if (j == SHIPTYPES) - return(OTHER); + for(i=0; i<2; ++i) + { + ss = (i) ? cpuship : plyship; + for(j=0; j < SHIPTYPES; ++j, ++ss) + if(ss->length > ss->hits) + break; + if (j == SHIPTYPES) + return(OTHER); } return(-1); } @@ -665,7 +757,7 @@ int x, y; if (has_colors()) attron(COLOR_PAIR(COLOR_GREEN)); #endif /* A_COLOR */ - addch(MARK_MISS); + (void)addch(MARK_MISS); #ifdef A_COLOR attrset(0); #endif /* A_COLOR */ @@ -683,93 +775,100 @@ int x, y; if (turn % 2 == PLAYER) { cgoto(y, x); - addch(ss->symbol); + (void) addch(ss->symbol); } } - move(oldy, oldx); + (void) move(oldy, oldx); return(ss); } } - move(oldy, oldx); + (void) move(oldy, oldx); return((ship_t *)NULL); } static int plyturn() { -ship_t *ss; -bool hit; -char *m; + ship_t *ss; + bool hit; + char *m; prompt(1, "Where do you want to shoot? "); - for (;;) { - getcoord(COMPUTER); - if (hits[PLAYER][curx][cury]) { - prompt(1, "You shelled this spot already! Try again."); - beep(); - } else - break; - } - hit = IS_SHIP(board[COMPUTER][curx][cury]); - hits[PLAYER][curx][cury] = hit ? MARK_HIT : MARK_MISS; - cgoto(cury, curx); + for (;;) + { + (void) getcoord(COMPUTER); + if (hits[PLAYER][curx][cury]) + { + prompt(1, "You shelled this spot already! Try again."); + beep(); + } + else + break; + } + hit = IS_SHIP(board[COMPUTER][curx][cury]); + hits[PLAYER][curx][cury] = hit ? MARK_HIT : MARK_MISS; + cgoto(cury, curx); #ifdef A_COLOR - if (has_colors()) - if (hit) - attron(COLOR_PAIR(COLOR_RED)); - else - attron(COLOR_PAIR(COLOR_GREEN)); + if (has_colors()) + if (hit) + attron(COLOR_PAIR(COLOR_RED)); + else + attron(COLOR_PAIR(COLOR_GREEN)); #endif /* A_COLOR */ - addch((chtype)hits[PLAYER][curx][cury]); + (void) addch((chtype)hits[PLAYER][curx][cury]); #ifdef A_COLOR attrset(0); #endif /* A_COLOR */ prompt(1, "You %s.", hit ? "scored a hit" : "missed"); - if(hit && (ss = hitship(curx, cury))) { - switch(rnd(5)) { - case 0: - m = " You sank my %s!"; - break; - case 1: - m = " I have this sinking feeling about my %s...."; - break; - case 2: - m = " My %s has gone to Davy Jones's locker!"; - break; - case 3: - m = " Glub, glub -- my %s is headed for the bottom!"; - break; - case 4: - m = " You'll pick up survivors from my my %s, I hope...!"; - break; - } - printw(m, ss->name); - beep(); - return(awinna() == -1); - } - return(hit); + if(hit && (ss = hitship(curx, cury))) + { + switch(rnd(5)) + { + case 0: + m = " You sank my %s!"; + break; + case 1: + m = " I have this sinking feeling about my %s...."; + break; + case 2: + m = " My %s has gone to Davy Jones's locker!"; + break; + case 3: + m = " Glub, glub -- my %s is headed for the bottom!"; + break; + case 4: + m = " You'll pick up survivors from my my %s, I hope...!"; + break; + } + (void)printw(m, ss->name); + (void)beep(); + return(awinna() == -1); + } + return(hit); } static int sgetc(s) char *s; { -char *s1; -int ch; + char *s1; + int ch; - refresh(); - for(;;) { - ch = getch(); - if (islower(ch)) - ch = toupper(ch); - if (ch == CTRLC) - uninitgame(); - for (s1=s; *s1 && ch != *s1; ++s1) - continue; - if (*s1) { - addch((chtype)ch); - refresh(); - return(ch); + (void)refresh(); + for(;;) + { + ch = getch(); + if (islower(ch)) + ch = toupper(ch); + if (ch == CTRLC) + uninitgame(); + for (s1=s; *s1 && ch != *s1; ++s1) + continue; + if (*s1) + { + (void) addch((chtype)ch); + (void)refresh(); + return(ch); } } } @@ -779,12 +878,12 @@ static void randomfire(px, py) /* random-fire routine -- implements simple diagonal-striping strategy */ int *px, *py; { -static int turncount = 0; -static int srchstep = BEGINSTEP; -static int huntoffs; /* Offset on search strategy */ -int ypossible[BWIDTH * BDEPTH], xpossible[BWIDTH * BDEPTH], nposs; -int ypreferred[BWIDTH * BDEPTH], xpreferred[BWIDTH * BDEPTH], npref; -int x, y, i; + static int turncount = 0; + static int srchstep = BEGINSTEP; + static int huntoffs; /* Offset on search strategy */ + int ypossible[BWIDTH * BDEPTH], xpossible[BWIDTH * BDEPTH], nposs; + int ypreferred[BWIDTH * BDEPTH], xpreferred[BWIDTH * BDEPTH], npref; + int x, y, i; if (turncount++ == 0) huntoffs = rnd(srchstep); @@ -792,35 +891,42 @@ int x, y, i; /* first, list all possible moves */ nposs = npref = 0; for (x = 0; x < BWIDTH; x++) - for (y = 0; y < BDEPTH; y++) - if (!hits[COMPUTER][x][y]) { - xpossible[nposs] = x; - ypossible[nposs] = y; - nposs++; - if (((x+huntoffs) % srchstep) != (y % srchstep)) { - xpreferred[npref] = x; - ypreferred[npref] = y; - npref++; - } - } + for (y = 0; y < BDEPTH; y++) + if (!hits[COMPUTER][x][y]) + { + xpossible[nposs] = x; + ypossible[nposs] = y; + nposs++; + if (((x+huntoffs) % srchstep) != (y % srchstep)) + { + xpreferred[npref] = x; + ypreferred[npref] = y; + npref++; + } + } - if (npref) { - i = rnd(npref); + if (npref) + { + i = rnd(npref); - *px = xpreferred[i]; - *py = ypreferred[i]; - } else if (nposs) { - i = rnd(nposs); + *px = xpreferred[i]; + *py = ypreferred[i]; + } + else if (nposs) + { + i = rnd(nposs); - *px = xpossible[i]; - *py = ypossible[i]; + *px = xpossible[i]; + *py = ypossible[i]; - if (srchstep > 1) - --srchstep; - } else { - error("No moves possible?? Help!"); - exit(1); - /*NOTREACHED*/ + if (srchstep > 1) + --srchstep; + } + else + { + error("No moves possible?? Help!"); + exit(1); + /*NOTREACHED*/ } } @@ -832,30 +938,30 @@ static bool cpufire(x, y) /* fire away at given location */ int x, y; { -bool hit, sunk; -ship_t *ss; + bool hit, sunk; + ship_t *ss; hits[COMPUTER][x][y] = (hit = (board[PLAYER][x][y])) ? MARK_HIT : MARK_MISS; - mvprintw(PROMPTLINE, 0, + (void) mvprintw(PROMPTLINE, 0, "I shoot at %c%d. I %s!", y + 'A', x, hit ? "hit" : "miss"); - if ((sunk = (hit && (ss = hitship(x, y)))) != 0) - printw(" I've sunk your %s", ss->name); - clrtoeol(); + if (sunk = (hit && (ss = hitship(x, y)))) + (void) printw(" I've sunk your %s", ss->name); + (void)clrtoeol(); pgoto(y, x); #ifdef A_COLOR if (has_colors()) - if (hit) - attron(COLOR_PAIR(COLOR_RED)); - else - attron(COLOR_PAIR(COLOR_GREEN)); + if (hit) + attron(COLOR_PAIR(COLOR_RED)); + else + attron(COLOR_PAIR(COLOR_GREEN)); #endif /* A_COLOR */ - addch((chtype)(hit ? SHOWHIT : SHOWSPLASH)); + (void)addch((chtype)(hit ? SHOWHIT : SHOWSPLASH)); #ifdef A_COLOR - attrset(0); + attrset(0); #endif /* A_COLOR */ - return(hit ? (sunk ? S_SUNK : S_HIT) : S_MISS); + return(hit ? (sunk ? S_SUNK : S_HIT) : S_MISS); } /* @@ -877,34 +983,38 @@ static bool cputurn() static ship_t ts; int navail, x, y, d, n, hit = S_MISS; - switch(next) { + switch(next) + { case RANDOM_FIRE: /* last shot was random and missed */ refire: - randomfire(&x, &y); - if (!(hit = cpufire(x, y))) - next = RANDOM_FIRE; - else { - ts.x = x; ts.y = y; - ts.hits = 1; - next = (hit == S_SUNK) ? RANDOM_FIRE : RANDOM_HIT; - } - break; + randomfire(&x, &y); + if (!(hit = cpufire(x, y))) + next = RANDOM_FIRE; + else + { + ts.x = x; ts.y = y; + ts.hits = 1; + next = (hit == S_SUNK) ? RANDOM_FIRE : RANDOM_HIT; + } + break; case RANDOM_HIT: /* last shot was random and hit */ - used[E/2] = used[S/2] = used[W/2] = used[N/2] = FALSE; - /* FALLTHROUGH */ + used[E/2] = used[S/2] = used[W/2] = used[N/2] = FALSE; + /* FALLTHROUGH */ case HUNT_DIRECT: /* last shot hit, we're looking for ship's long axis */ - for (d = navail = 0; d < 4; d++) { - x = ts.x + xincr[d*2]; y = ts.y + yincr[d*2]; - if (!used[d] && POSSIBLE(x, y)) - navail++; - else - used[d] = TRUE; + for (d = navail = 0; d < 4; d++) + { + x = ts.x + xincr[d*2]; y = ts.y + yincr[d*2]; + if (!used[d] && POSSIBLE(x, y)) + navail++; + else + used[d] = TRUE; } if (navail == 0) /* no valid places for shots adjacent... */ goto refire; /* ...so we must random-fire */ - else { + else + { for (d = 0, n = rnd(navail) + 1; n; n--) while (used[d]) d++; @@ -930,7 +1040,8 @@ static bool cputurn() case FIRST_PASS: /* we have a start and a direction now */ x = ts.x + xincr[ts.dir]; y = ts.y + yincr[ts.dir]; - if (POSSIBLE(x, y) && (hit = cpufire(x, y))) { + if (POSSIBLE(x, y) && (hit = cpufire(x, y))) + { ts.x = x; ts.y = y; ts.hits++; next = (hit == S_SUNK) ? RANDOM_FIRE : FIRST_PASS; } @@ -942,7 +1053,8 @@ static bool cputurn() d = ts.dir + 4; x = ts.x + ts.hits * xincr[d]; y = ts.y + ts.hits * yincr[d]; - if (POSSIBLE(x, y) && (hit = cpufire(x, y))) { + if (POSSIBLE(x, y) && (hit = cpufire(x, y))) + { ts.x = x; ts.y = y; ts.dir = d; ts.hits++; next = (hit == S_SUNK) ? RANDOM_FIRE : SECOND_PASS; } @@ -953,52 +1065,57 @@ static bool cputurn() case SECOND_PASS: /* kill squares not caught on first pass */ x = ts.x + xincr[ts.dir]; y = ts.y + yincr[ts.dir]; - if (POSSIBLE(x, y) && (hit = cpufire(x, y))) { + if (POSSIBLE(x, y) && (hit = cpufire(x, y))) + { ts.x = x; ts.y = y; ts.hits++; next = (hit == S_SUNK) ? RANDOM_FIRE: SECOND_PASS; break; - } else + } + else next = RANDOM_FIRE; break; } /* check for continuation and/or winner */ - if (salvo) { - refresh(); - sleep(1); + if (salvo) + { + (void)refresh(); + (void)sleep(1); } if (awinna() != -1) - return(FALSE); + return(FALSE); #ifdef DEBUG - mvprintw(PROMPTLINE + 2, 0, "New state %d, x=%d, y=%d, d=%d", + (void) mvprintw(PROMPTLINE + 2, 0, + "New state %d, x=%d, y=%d, d=%d", next, x, y, d); #endif /* DEBUG */ return(hit); } -int playagain() { -int j; -ship_t *ss; + int j; + ship_t *ss; - for (ss = cpuship; ss < cpuship + SHIPTYPES; ss++) - for(j = 0; j < ss->length; j++) { - cgoto(ss->y + j * yincr[ss->dir], ss->x + j * xincr[ss->dir]); - addch((chtype)ss->symbol); - } + for (ss = cpuship; ss < cpuship + SHIPTYPES; ss++) + for(j = 0; j < ss->length; j++) + { + cgoto(ss->y + j * yincr[ss->dir], ss->x + j * xincr[ss->dir]); + (void)addch((chtype)ss->symbol); + } - if (awinna()) - ++cpuwon; + if(awinna()) + ++cpuwon; else - ++plywon; + ++plywon; j = 18 + strlen(name); if(plywon >= 10) - ++j; + ++j; if(cpuwon >= 10) - ++j; - mvprintw(1,(COLWIDTH-j)/2, "%s: %d Computer: %d",name,plywon,cpuwon); + ++j; + (void) mvprintw(1,(COLWIDTH-j)/2, + "%s: %d Computer: %d",name,plywon,cpuwon); prompt(2, (awinna()) ? "Want to be humiliated again, %s [yn]? " : "Going to give me a chance for revenge, %s [yn]? ",name); @@ -1009,73 +1126,78 @@ static void do_options(c,op) int c; char *op[]; { -register int i; + register int i; - if (c > 1) { - for (i=1; i 1) + { + for (i=1; ihits >= sp->length) - continue; /* dead ship */ - else - shots++; + for (i=0, shots = 0; i < SHIPTYPES; i++, sp++) + { + if (sp->hits >= sp->length) + continue; /* dead ship */ + else + shots++; } return(shots); } -int main(argc, argv) int argc; char *argv[]; @@ -1084,34 +1206,45 @@ char *argv[]; intro(); do { - initgame(); - while(awinna() == -1) { - if (!blitz) { - if (!salvo) { - if(turn) - cputurn(); - else - plyturn(); - } else { - register int i; - - i = scount(turn); - while (i--) { - if (turn) { - if (cputurn() && awinna() != -1) - i = 0; - } else { - if (plyturn() && awinna() != -1) - i = 0; - } - } - } - } else - while(turn ? cputurn() : plyturn()) - continue; - turn = OTHER; + initgame(); + while(awinna() == -1) + { + if (!blitz) + { + if (!salvo) + { + if(turn) + (void) cputurn(); + else + (void) plyturn(); } - } while (playagain()); + else + { + register int i; + + i = scount(turn); + while (i--) + { + if (turn) + { + if (cputurn() && awinna() != -1) + i = 0; + } + else + { + if (plyturn() && awinna() != -1) + i = 0; + } + } + } + } + else + while(turn ? cputurn() : plyturn()) + continue; + turn = OTHER; + } + } while + (playagain()); uninitgame(); /*NOTREACHED*/ } diff --git a/lib/libncurses/TESTS/gdc.c b/lib/libncurses/TESTS/gdc.c index 7f80d93b497a..84bd651e1d20 100644 --- a/lib/libncurses/TESTS/gdc.c +++ b/lib/libncurses/TESTS/gdc.c @@ -15,6 +15,11 @@ #include #endif +#define YBASE 10 +#define XBASE 10 +#define XLENGTH 54 +#define YDEPTH 5 + /* it won't be */ long now; /* yeah! */ struct tm *tm; @@ -64,6 +69,7 @@ int n = 0; start_color(); init_pair(1, COLOR_BLACK, COLOR_RED); init_pair(2, COLOR_RED, COLOR_BLACK); + init_pair(3, COLOR_WHITE, COLOR_BLACK); attrset(COLOR_PAIR(2)); } @@ -75,6 +81,26 @@ int n = 0; else n = atoi(*argv); } + + if(hascolor) { + attrset(COLOR_PAIR(3)); + + mvaddch(YBASE - 1, XBASE - 1, ACS_ULCORNER); + hline(ACS_HLINE, XLENGTH); + mvaddch(YBASE - 1, XBASE + XLENGTH, ACS_URCORNER); + + mvaddch(YBASE + YDEPTH, XBASE - 1, ACS_LLCORNER); + hline(ACS_HLINE, XLENGTH); + mvaddch(YBASE + YDEPTH, XBASE + XLENGTH, ACS_LRCORNER); + + move(YBASE, XBASE - 1); + vline(ACS_VLINE, YDEPTH); + + move(YBASE, XBASE + XLENGTH); + vline(ACS_VLINE, YDEPTH); + + attrset(COLOR_PAIR(2)); + } do { mask = 0; time(&now); @@ -102,7 +128,7 @@ int n = 0; for(j=0,t=1<<26; t; t>>=1,j++) { if(a&t) { if(!(a&(t<<1))) { - movto(i, 2*j); + movto(YBASE + i, XBASE + 2*j); } addstr(" "); } @@ -154,15 +180,17 @@ void standt(int on) { if (on) { - if(hascolor) + if(hascolor) { attron(COLOR_PAIR(1)); - else - attron(A_STANDOUT); + } else { + attron(A_STANDOUT); + } } else { - if(hascolor) + if(hascolor) { attron(COLOR_PAIR(2)); - else + } else { attroff(A_STANDOUT); + } } } diff --git a/lib/libncurses/TESTS/hanoi.c b/lib/libncurses/TESTS/hanoi.c index 422d5dae66ee..e7da51d2fa6c 100644 --- a/lib/libncurses/TESTS/hanoi.c +++ b/lib/libncurses/TESTS/hanoi.c @@ -28,7 +28,7 @@ #define MIDPEG 39 #define RIGHTPEG 59 -#define LENTOIND(x) (((x)-1)/2-1) +#define LENTOIND(x) (((x)-1)/2) #define OTHER(a,b) (3-((a)+(b))) struct Peg { @@ -91,7 +91,6 @@ unsigned char AutoFlag = 0; puts("terminal doesn't support color."); exit(1); } - traceon(); start_color(); { int i; diff --git a/lib/libncurses/TESTS/knight.c b/lib/libncurses/TESTS/knight.c index 4857e276eb37..cea9183e0947 100644 --- a/lib/libncurses/TESTS/knight.c +++ b/lib/libncurses/TESTS/knight.c @@ -88,9 +88,7 @@ init () initscr (); cbreak (); /* immediate char return */ noecho (); /* no immediate echo */ - traceon(); title (1,23); - traceoff(); mvaddstr (23, 25, "Would you like instructions? "); refresh(); if ((toupper(getch())) == 'Y') diff --git a/lib/libncurses/TESTS/ncurses.c b/lib/libncurses/TESTS/ncurses.c index 468cd5ddb75f..14630a8c5ffe 100644 --- a/lib/libncurses/TESTS/ncurses.c +++ b/lib/libncurses/TESTS/ncurses.c @@ -19,6 +19,7 @@ library source. #include #include #include +#include #include #include #include @@ -37,13 +38,27 @@ library source. static void getch_test(void) /* test the keypad feature */ { - unsigned int c; - int firsttime = 0; - - refresh(); - - c = '?'; - do { +char buf[BUFSIZ]; +unsigned int c; +int incount = 0, firsttime = 0; +bool blocking = TRUE; + + refresh(); + + (void) printw("Delay in 10ths of a second ( for blocking input)? "); + echo(); + getstr(buf); + noecho(); + + if (isdigit(buf[0])) + { + timeout(atoi(buf) * 100); + blocking = FALSE; + } + + c = '?'; + for (;;) + { if (firsttime++) { printw("Key pressed: %04o ", c); @@ -72,15 +87,19 @@ static void getch_test(void) break; if (c == '?') addstr("Type any key to see its keypad value, `q' to quit, `?' for help.\n"); - } while - ((c = getch()) != EOF); + while ((c = getch()) == ERR) + if (!blocking) + (void) printw("%05d: input timed out\n", incount++); + } + + timeout(-1); erase(); endwin(); } static void attr_test(void) -/* test text attrivutes */ +/* test text attributes */ { refresh(); @@ -455,14 +474,15 @@ static void slk_test(void) static void acs_display() /* display the ACS character set */ { -traceon(); + int i, j; + erase(); attron(A_BOLD); mvaddstr(0, 20, "Display of the ACS Character Set"); attroff(A_BOLD); refresh(); -#define ACSY 5 +#define ACSY 2 mvaddstr(ACSY + 0, 0, "ACS_ULCORNER: "); addch(ACS_ULCORNER); mvaddstr(ACSY + 1, 0, "ACS_LLCORNER: "); addch(ACS_LLCORNER); mvaddstr(ACSY + 2, 0, "ACS_URCORNER: "); addch(ACS_URCORNER); @@ -490,6 +510,15 @@ traceon(); mvaddstr(ACSY + 10,40, "ACS_LANTERN: "); addch(ACS_LANTERN); mvaddstr(ACSY + 11,40, "ACS_BLOCK: "); addch(ACS_BLOCK); +#define HYBASE (ACSY + 13) + mvprintw(HYBASE + 1, 0, "High-half characters via echochar:\n"); + for (i = 0; i < 4; i++) + { + move(HYBASE + i + 3, 24); + for (j = 0; j < 32; j++) + echochar(128 + 32 * i + j); + } + move(LINES - 1, 0); addstr("Press any key to continue... "); (void) getch(); @@ -542,6 +571,7 @@ int uli, ulj, lri, lrj; /* co-ordinates of corners */ case KEY_DOWN: i++; break; case KEY_LEFT: j += sj - 1; break; case KEY_RIGHT: j++; break; + case '\004': return((pair *)NULL); default: res.y = uli + i; res.x = ulj + j; return(&res); } i %= si; @@ -553,17 +583,21 @@ static WINDOW *getwindow(void) /* Ask user for a window definition */ { WINDOW *rwindow, *bwindow; - pair ul, lr; + pair ul, lr, *tmp; move(0, 0); clrtoeol(); addstr("Use arrows to move cursor, anything else to mark corner 1"); refresh(); - memcpy(&ul, selectcell(1, 0, LINES-1, COLS-1), sizeof(pair)); + if ((tmp = selectcell(1, 0, LINES-1, COLS-1)) == (pair *)NULL) + return((WINDOW *)NULL); + memcpy(&ul, tmp, sizeof(pair)); addch(ACS_ULCORNER); move(0, 0); clrtoeol(); addstr("Use arrows to move cursor, anything else to mark corner 2"); refresh(); - memcpy(&lr, selectcell(ul.y, ul.x, LINES-1, COLS-1), sizeof(pair)); + if ((tmp = selectcell(ul.y, ul.x, LINES-1, COLS-1)) == (pair *)NULL) + return((WINDOW *)NULL); + memcpy(&lr, tmp, sizeof(pair)); rwindow = newwin(lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x); @@ -593,7 +627,7 @@ static void acs_and_scroll() refresh(); mvaddstr(LINES - 2, 0, - "F1 = make new window, F2 = next window, F3 = previous window"); + "F1 = make new window, F2 = next window, F3 = previous window, Ctrl-D = exit"); mvaddstr(LINES - 1, 0, "All other characters are echoed, windows should scroll."); @@ -607,7 +641,8 @@ static void acs_and_scroll() { case KEY_F(1): neww = (struct frame *) malloc(sizeof(struct frame)); - neww->wind = getwindow(); + if ((neww->wind = getwindow()) == (WINDOW *)NULL) + goto breakout; if (oldw == NULL) /* First element, */ { neww->next = neww; /* so point it at itself */ @@ -650,41 +685,216 @@ static void acs_and_scroll() } while ((c = wgetch(current->wind)) != '\004'); + breakout: erase(); endwin(); } +#define GRIDSIZE 5 + +static void panner(WINDOW *pad, int iy, int ix, int (*pgetc)(void)) +{ + static int porty, portx, basex = 0, basey = 0; + int pxmax, pymax, c; + WINDOW *vscroll = (WINDOW *)NULL, *hscroll = (WINDOW *)NULL; + + porty = iy; portx = ix; + + getmaxyx(pad, pymax, pxmax); + + if (pymax > porty) + vscroll = newwin(porty - (pxmax > ix), 1, 0, portx - (pymax > iy)); + if (pxmax > portx) + hscroll = newwin(1, portx - (pymax > iy), porty - (pxmax > ix), 0); + + c = KEY_REFRESH; + do { + switch(c) + { + case KEY_REFRESH: + /* do nothing */ + break; + + case KEY_IC: + if (portx >= pxmax || portx >= ix) + beep(); + else + { + mvwin(vscroll, 0, ++portx - 1); + delwin(hscroll); + hscroll = newwin(1, portx - (pymax > porty), + porty - (pxmax > portx), 0); + } + break; + + case KEY_IL: + if (porty >= pymax || porty >= iy) + beep(); + else + { + mvwin(hscroll, ++porty - 1, 0); + delwin(vscroll); + vscroll = newwin(porty - (pxmax > portx), 1, + 0, portx - (pymax > porty)); + } + break; + + case KEY_DC: + if (portx <= 0) + beep(); + else + { + mvwin(vscroll, 0, --portx - 1); + delwin(hscroll); + hscroll = newwin(1, portx - (pymax > porty), + porty - (pxmax > portx), 0); + } + break; + + case KEY_DL: + if (porty <= 0) + beep(); + else + { + mvwin(hscroll, --porty - 1, 0); + delwin(vscroll); + vscroll = newwin(porty - (pxmax > portx), 1, + 0, portx - (pymax > porty)); + } + break; + + case KEY_LEFT: + if (basex > 0) + basex--; + else + beep(); + break; + + case KEY_RIGHT: + if (basex + portx < pxmax) + basex++; + else + beep(); + break; + + case KEY_UP: + if (basey > 0) + basey--; + else + beep(); + break; + + case KEY_DOWN: + if (basey + porty < pymax) + basey++; + else + beep(); + break; + } + + prefresh(pad, + basey, basex, + 0, 0, + porty - (hscroll != (WINDOW *)NULL) - 1, + portx - (vscroll != (WINDOW *)NULL) - 1); + if (vscroll) + { + int lowend, i, highend; + + lowend = basey * ((float)porty / (float)pymax); + highend = (basey + porty) * ((float)porty / (float)pymax); + + touchwin(vscroll); + for (i = 0; i < lowend; i++) + mvwaddch(vscroll, i, 0, ACS_VLINE); + wattron(vscroll, A_REVERSE); + for (i = lowend; i <= highend; i++) + mvwaddch(vscroll, i, 0, ' '); + wattroff(vscroll, A_REVERSE); + for (i = highend + 1; i < porty; i++) + mvwaddch(vscroll, i, 0, ACS_VLINE); + wrefresh(vscroll); + } + if (hscroll) + { + int lowend, j, highend; + + lowend = basex * ((float)portx / (float)pxmax); + highend = (basex + portx) * ((float)portx / (float)pxmax); + + touchwin(hscroll); + for (j = 0; j < lowend; j++) + mvwaddch(hscroll, 0, j, ACS_HLINE); + wattron(hscroll, A_REVERSE); + for (j = lowend; j <= highend; j++) + mvwaddch(hscroll, 0, j, ' '); + wattroff(hscroll, A_REVERSE); + for (j = highend + 1; j < portx; j++) + mvwaddch(hscroll, 0, j, ACS_HLINE); + wrefresh(hscroll); + } + mvaddch(porty - 1, portx - 1, ACS_LRCORNER); + + } while + ((c = pgetc()) != KEY_EXIT); +} + +int padgetch(void) +{ + int c; + + switch(c = getch()) + { + case 'u': return(KEY_UP); + case 'd': return(KEY_DOWN); + case 'r': return(KEY_RIGHT); + case 'l': return(KEY_LEFT); + case '+': return(KEY_IL); + case '-': return(KEY_DL); + case '>': return(KEY_IC); + case '<': return(KEY_DC); + default: return(c); + } +} + +static void demo_pad(void) +/* Demonstrate pads. */ +{ + int i, j, gridcount = 0; + WINDOW *panpad = newpad(200, 200); + + for (i = 0; i < 200; i++) + { + for (j = 0; j < 200; j++) + if (i % GRIDSIZE == 0 && j % GRIDSIZE == 0) + { + if (i == 0 || j == 0) + waddch(panpad, '+'); + else + waddch(panpad, 'A' + (gridcount++ % 26)); + } + else if (i % GRIDSIZE == 0) + waddch(panpad, '-'); + else if (j % GRIDSIZE == 0) + waddch(panpad, '|'); + else + waddch(panpad, ' '); + } + mvprintw(LINES - 3, 0, "Use arrow keys to pan over the test pattern"); + mvprintw(LINES - 2, 0, "Use +,- to grow/shrink the panner vertically."); + mvprintw(LINES - 1, 0, "Use <,> to grow/shrink the panner horizontally."); + panner(panpad, LINES - 4, COLS, padgetch); + + endwin(); + erase(); +} + /**************************************************************************** * * Tests from John Burnell's PDCurses tester * ****************************************************************************/ -static void demo_pad(void) -/* Demonstrate pads. */ -{ - WINDOW *pad; - - pad = newpad(50,100); - mvwaddstr(pad, 5, 2, "This is a new pad"); - mvwaddstr(pad, 8, 0, "The end of this line should be truncated here:abcd"); - mvwaddstr(pad,11, 1, "This line should not appear."); - wmove(pad, 10, 1); - wclrtoeol(pad); - mvwaddstr(pad, 10, 1, " Press any key to continue"); - prefresh(pad,0,0,0,0,10,45); - keypad(pad, TRUE); - wgetch(pad); - - mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad"); - mvwaddstr(pad, 40, 1, " Press any key to continue"); - prefresh(pad,30,0,0,0,10,45); - keypad(pad, TRUE); - wgetch(pad); - - delwin(pad); -} - static void Continue (WINDOW *win) { wmove(win, 10, 1); @@ -696,10 +906,13 @@ static void Continue (WINDOW *win) static void input_test(WINDOW *win) /* Input test, adapted from John Burnell's PDCurses tester */ { - int w, h, bx, by, sw, sh, i, c,num; - char buffer [80]; + int w, h, bx, by, sw, sh, i; WINDOW *subWin; wclear (win); +#ifdef FOO + char buffer [80]; + int num; +#endif /* FOO */ w = win->_maxx; h = win->_maxy; @@ -722,16 +935,19 @@ static void input_test(WINDOW *win) wattrset(subWin, A_BOLD); #endif box(subWin, ACS_VLINE, ACS_HLINE); +#ifdef FOO + mvwaddstr(subWin, 2, 1, "This is a subwindow"); +#endif /* FOO */ wrefresh(win); nocbreak(); - mvwaddstr(win, 2, 1, "Press some keys for 5 seconds"); - mvwaddstr(win, 1, 1, "Pressing ^C should do nothing"); + mvwaddstr(win, 1, 1, "Type random keys for 5 seconds."); + mvwaddstr(win, 2, 1, + "These should be discarded (not echoed) after the subwindow goes away."); wrefresh(win); - for (i = 0; i < 5; i++) { - werase (subWin); - box(subWin, ACS_VLINE, ACS_HLINE); + for (i = 0; i < 5; i++) + { mvwprintw (subWin, 1, 1, "Time = %d", i); wrefresh(subWin); sleep(1); @@ -750,27 +966,18 @@ static void input_test(WINDOW *win) echo(); wgetch(win); flushinp(); + mvwaddstr(win, 12, 0, + "If you see any key other than what you typed, flushinp() is broken."); + Continue(win); wmove(win, 9, 10); wdelch(win); - mvwaddstr(win, 4, 1, "The character should now have been deleted"); - Continue(win); - - wclear (win); - mvwaddstr(win, 2, 1, "Press a function key or an arrow key"); wrefresh(win); - keypad(win, TRUE); - c = wgetch(win); - - nodelay(win, TRUE); - wgetch(win); - nodelay(win, FALSE); - - refresh(); - wclear (win); - mvwaddstr(win, 3, 2, "The window should have moved"); - mvwaddstr(win, 4, 2, "This text should have appeared without you pressing a key"); - mvwprintw(win, 2, 2, "Keycode = %d", c); + wmove(win, 12, 0); + clrtoeol(); + waddstr(win, + "What you typed should now have been deleted; if not, wdelch() failed."); + Continue(win); #ifdef FOO /* @@ -785,126 +992,6 @@ static void input_test(WINDOW *win) Continue(win); } -static void output_test (WINDOW *win) -{ - WINDOW *win1; - char Buffer [80]; - chtype ch; - - wclear (win); - mvwaddstr(win, 1, 1, "You should now have a screen in the upper left corner, and this text should have wrapped"); - mvwin(win, 2, 1); - Continue(win); - - nl(); - wclear(win); - mvwaddstr(win, 1, 1, "A new window will appear with this text in it"); - mvwaddstr(win, 8, 1, "Press any key to continue"); - wrefresh(win); - wgetch(win); - - win1 = newwin(10, 50, 15, 25); - if(win1 == NULL) - { endwin(); - return; - } -#ifdef A_COLOR - if (has_colors()) - { - init_pair(3,COLOR_BLUE,COLOR_WHITE); - wattrset(win1, COLOR_PAIR(3)); - } - else - wattrset(win1, A_NORMAL); -#else - wattrset(win1, A_NORMAL); -#endif - wclear (win1); - mvwaddstr(win1, 5, 1, "This text should appear; using overlay option"); - copywin(win, win1,0,0,0,0,10,50,TRUE); - - box(win1,ACS_VLINE,ACS_HLINE); - wmove(win1, 8, 26); - wrefresh(win1); - wgetch(win1); - - wclear(win1); - wattron(win1, A_BLINK); - mvwaddstr(win1, 4, 1, "This blinking text should appear in only the second window"); - wattroff(win1, A_BLINK); - wrefresh(win1); - wgetch(win1); - delwin(win1); - - wclear(win); - wrefresh(win); - mvwaddstr(win, 6, 2, "This line shouldn't appear"); - mvwaddstr(win, 4, 2, "Only half of the next line is visible"); - mvwaddstr(win, 5, 2, "Only half of the next line is visible"); - wmove(win, 6, 1); - wclrtobot (win); - wmove(win, 5, 20); - wclrtoeol (win); - mvwaddstr(win, 8, 2, "This line also shouldn't appear"); - wmove(win, 8, 1); - wdeleteln(win); - Continue(win); - traceoff(); - - wmove (win, 5, 9); - ch = winch (win); - - wclear(win); - wmove (win, 6, 2); - waddstr (win, "The next char should be l: "); - winsch (win, ch); - Continue(win); - - wmove(win, 5, 1); - winsertln (win); - mvwaddstr(win, 5, 2, "The lines below should have moved down"); - Continue(win); - -#ifdef FOO - /* - * This test won't be portable until vsscanf() is - */ - wclear(win); - wmove(win, 2, 2); - wprintw(win, "This is a formatted string in a window: %d %s\n", 42, "is it"); - mvwaddstr(win, 10, 1, "Enter a string: "); - wrefresh(win); - echo(); - wscanw (win, "%s", Buffer); - - wclear(win); - mvwaddstr(win, 10, 1, "Enter a string"); - wrefresh(win); - clear(); - move(0,0); - printw("This is a formatted string in stdscr: %d %s\n", 42, "is it"); - mvaddstr(10, 1, "Enter a string: "); - refresh(); - echo(); - scanw ("%s", Buffer); -#endif /* FOO */ - - wclear(win); - curs_set(2); - mvwaddstr(win, 1, 1, "The cursor should appear as a block"); - Continue(win); - - wclear(win); - curs_set(0); - mvwaddstr(win, 1, 1, "The cursor should have disappeared"); - Continue(win); - - wclear(win); - curs_set(1); - mvwaddstr(win, 1, 1, "The cursor should be an underline"); - Continue(win); -} - /**************************************************************************** * * Main sequence @@ -963,10 +1050,6 @@ bool do_single_test(const char c) input_test(stdscr); return(TRUE); - case 'o': - output_test(stdscr); - return(TRUE); - case '?': (void) puts("This is the ncurses capability tester."); (void) puts("You may select a test from the main menu by typing the"); @@ -983,7 +1066,7 @@ int main(const int argc, const char *argv[]) char buf[BUFSIZ]; /* enable debugging */ - traceon(); + trace(TRACE_ORDINARY); /* tell it we're going to play with soft keys */ slk_init(1); @@ -1017,10 +1100,10 @@ int main(const int argc, const char *argv[]) (void) puts("g = display windows and scrolling"); (void) puts("p = exercise pad features"); (void) puts("i = subwindow input test"); - (void) puts("o = output test"); (void) puts("? = get help"); (void) fputs("> ", stdout); + (void) fflush(stdout); /* necessary under SVr4 curses */ (void) fgets(buf, BUFSIZ, stdin); if (do_single_test(buf[0])) { diff --git a/lib/libncurses/copyright.c b/lib/libncurses/copyright.c index c902fe3524ed..5964afc79c5a 100644 --- a/lib/libncurses/copyright.c +++ b/lib/libncurses/copyright.c @@ -1,19 +1,19 @@ char _ncurses_copyright[] = "\n\ -/***************************************************************************\n\ -* COPYRIGHT NOTICE *\n\ -****************************************************************************\n\ -* ncurses is copyright (C) 1992, 1993, 1994 *\n\ -* by Zeyd M. Ben-Halim *\n\ -* zmbenhal@netcom.com *\n\ -* *\n\ -* Permission is hereby granted to reproduce and distribute ncurses *\n\ -* by any means and for any fee, whether alone or as part of a *\n\ -* larger distribution, in source or in binary form, PROVIDED *\n\ -* this notice remains in the sources and is reproduced in any *\n\ -* documentation accompanying it or the applications linked with it. *\n\ -* Any other use of ncurses, including incorporating it in another *\n\ -* product is subject to written permission. *\n\ -* *\n\ -* ncurses comes AS IS with no warranty, implied or expressed. *\n\ -* *\n\ -***************************************************************************/\n"; +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992, 1993, 1994 * +* by Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, not removed * +* from header files, and is reproduced in any documentation * +* accompanying it or the applications linked with it. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ +\n"; diff --git a/lib/libncurses/curs_addch.3 b/lib/libncurses/curs_addch.3 index 2d6e643f0a93..0fc3cfac0661 100644 --- a/lib/libncurses/curs_addch.3 +++ b/lib/libncurses/curs_addch.3 @@ -91,16 +91,16 @@ All routines return the integer \fBERR\fR upon failure and an integer value other than \fBERR\fR upon successful completion, unless otherwise noted in the preceding routine descriptions. .SH BUGS -The ncurses implementation does not yet handle insertion of a character at the -bottom-rightmost position of the screen correctly. If the terminal has the -auto_right_margin property, the real screen will be scrolled up one regardless -of whether scrollok has been enabled for \fBstdscr\fR. - -The entry points \fBechochar\fR and \fBwechochar\fR are not yet implemented in -ncurses 1.8.1. .SH NOTES Note that \fBaddch\fR, \fBmvaddch\fR, \fBmvwaddch\fR, and \fBechochar\fR may be macros. + +On 386 and 486 consoles, giving \fBwechochar\fR an argument with its high +bit set will produce the corresponding high-half ASCIIZ graphic (SVr4 curses +also has this feature but does not document it). A control-character argument, +however, will not typically produce the corresponding graphic; +characters such as CR, NL, FF and TAB are typically interpreted by the console +driver itself, and ESC will be interpreted as the leader of a control sequence. .SH SEE ALSO \fBncurses\fR(3X), \fBcurs_attr\fR(3X), \fBcurs_clear\fR(3X), \fBcurs_inch\fR(3X), \fBcurs_outopts\fR(3X), \fBcurs_refresh\fR(3X), diff --git a/lib/libncurses/curs_attr.3 b/lib/libncurses/curs_attr.3 index f0f4f5251980..2f41e3be8138 100644 --- a/lib/libncurses/curs_attr.3 +++ b/lib/libncurses/curs_attr.3 @@ -40,7 +40,7 @@ The routine \fBattrset\fR sets the current attributes of the given window to turning any other attributes on or off. The routine \fBattron\fR turns on the named attributes without affecting any others. The routine \fBstandout\fR is the same as \fBattron(A_STANDOUT)\fR. The routine \fBstandend\fR is the same -as \fBattrset(A_NORMAL)\fR or \fBattrest(0)\fR, that is, it turns off all +as \fBattrset(A_NORMAL)\fR or \fBattrset(0)\fR, that is, it turns off all attributes. .SS Attributes The following video attributes, defined in \fB\fR, can be passed to @@ -70,9 +70,6 @@ The following macro is the reverse of \fBCOLOR_PAIR(\fR\fIn\fR\fB)\fR: The return values of these routines are not neaningful (many are implemented as macro-expanded assignments and simply return their argument). The SVr4 manual page claims (falsely) that these routines always return \fB1\fR. -.SH BUGS -As of 1.8.2, ncurses attributes still have a tendency to stick on in some -circumstances where SVr4 curses attributes would turn off. .SH NOTES Note that \fBattroff\fR, \fBwattroff\fR, \fBattron\fR, \fBwattron\fR, \fBattrset\fR, \fBwattrset\fR, \fBstandend\fR and \fBstandout\fR may be macros. diff --git a/lib/libncurses/curs_bkgd.3 b/lib/libncurses/curs_bkgd.3 index d2cd2f17268a..84dde0504e4d 100644 --- a/lib/libncurses/curs_bkgd.3 +++ b/lib/libncurses/curs_bkgd.3 @@ -39,7 +39,7 @@ non-negative integer, if \fBimmedok\fR is set. .SH NOTES Note that \fBbkgdset\fR and \fBbkgd\fR may be macros. .SH BUGS -These features and \fBimmedok\fR are not yet implemented in ncurses 1.8.1. +\fBimmedok\fR is not yet implemented in ncurses 1.8.6. .SH SEE ALSO \fBncurses\fR(3X), \fBcurs_addch\fR(3X), \fBcurs_outopts\fR(3X) .\"# diff --git a/lib/libncurses/curs_border.3 b/lib/libncurses/curs_border.3 index 23752bf0f250..619ba4c490ee 100644 --- a/lib/libncurses/curs_border.3 +++ b/lib/libncurses/curs_border.3 @@ -56,7 +56,7 @@ is also true of SVr4 curses, though the fact is not documented). Note that \fBborder\fR and \fBbox\fR may be macros. .SH BUGS -The \fBimmedok\fR function is not yet implemented in ncurses 1.8.1. +The \fBimmedok\fR function is not yet implemented in ncurses 1.8.6. .SH SEE ALSO \fBncurses\fR(3X), \fBcurs_outopts\fR(3X). .\"# diff --git a/lib/libncurses/curs_color.3 b/lib/libncurses/curs_color.3 index 56f937999c80..c1bb804f03f3 100644 --- a/lib/libncurses/curs_color.3 +++ b/lib/libncurses/curs_color.3 @@ -114,7 +114,7 @@ background color for all terminals. .SH RETURN VALUE All routines that return an integer return \fBERR\fR upon failure and \fBOK\fR upon successful completion. -.SH BUGS +.SH NOTES Several caveats apply onn 386 and 486 machines with VGA-compatible graphics: COLOR_YELLOW is actually brown. To get yellow, use COLOR_YELLOW combined with diff --git a/lib/libncurses/curs_delln.3 b/lib/libncurses/curs_delln.3 index d8a3c4674aba..9960554688a6 100644 --- a/lib/libncurses/curs_delln.3 +++ b/lib/libncurses/curs_delln.3 @@ -34,9 +34,6 @@ current line and the bottom line is lost. .SH RETURN VALUE All routines return the integer \fBERR\fR upon failure and an integer value other than \fBERR\fR upon successful completion. -.SH BUGS -All the above should be implemented through \fBwinsdelln\fR() but -currently only \fBinsdelln\fR() is implemented in terms of it. .SH NOTES Note that all but \fBwinsdelln\fR may be a macros. diff --git a/lib/libncurses/curs_inopts.3 b/lib/libncurses/curs_inopts.3 index c2372100262e..d50830dcb8e2 100644 --- a/lib/libncurses/curs_inopts.3 +++ b/lib/libncurses/curs_inopts.3 @@ -158,7 +158,7 @@ Note that \fBecho\fR, \fBnoecho\fR, \fBhalfdelay\fR, \fBintrflush\fR, \fBqiflush\fR, \fBtimeout\fR, and \fBwtimeout\fR may be macros. .SH BUGS The entry points \fBintrflush\fR, \fBqiflush\fR, \fBnoqiflush\fR, and -\fBtypeahead\fR are not yet implemented in ncurses 1.8.1. The ncurses +\fBtypeahead\fR are not yet implemented in ncurses 1.8.6. The ncurses code does not do typeahead checking during input as SVr4 curses does. .SH SEE ALSO \fBncurses\fR(3X), \fBcurs_getch\fR(3X), \fBcurs_initscr\fR(3X), \fBtermio\fR(7) diff --git a/lib/libncurses/curs_insstr.3 b/lib/libncurses/curs_insstr.3 index 85cad112202d..7a56ac021a89 100644 --- a/lib/libncurses/curs_insstr.3 +++ b/lib/libncurses/curs_insstr.3 @@ -43,8 +43,8 @@ returns a character in the the ^-representation of the control character. All routines return the integer \fBERR\fR upon failure and an integer value other than \fBERR\fR upon successful completion. .SH BUGS -Entry points for these functions are n ncurses.h but they are not -implemented as of ncurses 1.8.5. +Entry points for these functions are in ncurses.h but they are not +implemented as of ncurses 1.8.6. .SH NOTES Note that all but \fBwinsnstr\fR may be macros. .SH SEE ALSO diff --git a/lib/libncurses/curs_kernel.3 b/lib/libncurses/curs_kernel.3 index 24084f6fad94..8a776fb39584 100644 --- a/lib/libncurses/curs_kernel.3 +++ b/lib/libncurses/curs_kernel.3 @@ -100,8 +100,10 @@ requested \fIvisibility\fR is not supported. .SH NOTES Note that \fBgetsyx\fR is a macro, so \fB&\fR is not necessary before the variables \fIy\fR and \fIx\fR. -.SH BUGS -The return value of curs_set is currently incorrect. + +The SVr4 man pages warn that the return value of \fBcurs_set\fR "is currently +incorrect". This implementation gets it right, but it may be unwise to count +on the correctness of the return value anywhere else. .SH SEE ALSO \fBncurses\fR(3X), \fBcurs_initscr\fR(3X), \fBcurs_outopts\fR(3X), \fBcurs_refresh\fR(3X), \fBcurs_scr_dump\fR(3X), \fBcurs_slk\fR(3X) diff --git a/lib/libncurses/curs_outopts.3 b/lib/libncurses/curs_outopts.3 index ccf800d8c630..2b46bb6db340 100644 --- a/lib/libncurses/curs_outopts.3 +++ b/lib/libncurses/curs_outopts.3 @@ -96,7 +96,8 @@ linefeed capability, resulting in faster cursor motion. All other routines that return an integer always return \fBOK\fR. .SH BUGS The entry points \fBidcok\fR, \fBimmedok\fR are not yet implemented in -ncurses 1.8.1. +ncurses 1.8.6. Setting \fIidlok\fR has unfortunate effects on scrolling +windows. .SH NOTES Note that \fBclearok\fR, \fBleaveok\fR, \fBscrollok\fR, \fBidcok\fR, \fBnl\fR, \fBnonl\fR and \fBsetscrreg\fR may be macros. diff --git a/lib/libncurses/curs_scr_dmp.3 b/lib/libncurses/curs_scr_dmp.3 index 2572f98590f1..d74456d8b7eb 100644 --- a/lib/libncurses/curs_scr_dmp.3 +++ b/lib/libncurses/curs_scr_dmp.3 @@ -18,13 +18,13 @@ from (to) a file The \fBscr_dump\fR routine dumps the current contents of the virtual screen to the file \fIfilename\fR. -With the \fBscr_restore\fR routine, the virtual screen is set to the contents +The \fBscr_restore\fR routine sets the virtual screen to the contents of \fIfilename\fR, which must have been written using \fBscr_dump\fR. The next call to \fBdoupdate\fR restores the screen to the way it looked in the dump file. -With the \fBscr_init\fR routine, the contents of \fIfilename\fR are read in and -used to initialize the \fBncurses\fR data structures about what the terminal +The \fBscr_init\fR routine reads in the contents of \fIfilename\fR and uses +them to initialize the \fBncurses\fR data structures about what the terminal currently has on its screen. If the data is determined to be valid, \fBncurses\fR bases its next update of the screen on this information rather than clearing the screen and starting from scratch. \fBscr_init\fR is used @@ -45,6 +45,8 @@ All routines return the integer \fBERR\fR upon failure and \fBOK\fR upon success. .SH NOTES Note that \fBscr_init\fR, \fBscr_set\fR, and \fBscr_restore\fR may be macros. +.BUGS +The time-stamp and rmcup/nrrmc checks are not implemented in \fBncurses\fR(3X). .SH SEE ALSO \fBncurses\fR(3X), \fBcurs_initscr\fR(3X), \fBcurs_refresh\fR(3X), \fBcurs_util\fR(3X), \fBsystem\fR(3S) diff --git a/lib/libncurses/curs_termatt.3 b/lib/libncurses/curs_termatt.3 index fab073ee0f23..75599bd52413 100644 --- a/lib/libncurses/curs_termatt.3 +++ b/lib/libncurses/curs_termatt.3 @@ -62,8 +62,6 @@ variable \fBTERM\fR (truncated to 14 characters). Routines that return an integer return \fBERR\fR upon failure and an integer value other than \fBERR\fR upon successful completion. -.SH BUGS -The \fBtermattr\fR entry point is not implemented in ncurses 1.8.1. .SH NOTES Note that \fBtermattrs\fR may be a macro. .SH SEE ALSO diff --git a/lib/libncurses/curs_util.3 b/lib/libncurses/curs_util.3 index 70e8d1a3af75..93e83e8501cc 100644 --- a/lib/libncurses/curs_util.3 +++ b/lib/libncurses/curs_util.3 @@ -68,8 +68,7 @@ successful completion. Routines that return pointers return \fBNULL\fR on error. .SH BUGS -The \fBfilter\fR and \fBdelay_output\fR entry points are not yet -supported in ncurses 1.8.1. +The \fBfilter\fR entry point is not yet supported. .SH NOTES Note that \fBunctrl\fR is a macro, which is defined in <\fBunctrl.h\fR>. .SH SEE ALSO diff --git a/lib/libncurses/curs_window.3 b/lib/libncurses/curs_window.3 index 919c2f7ef0ba..b2a2315db660 100644 --- a/lib/libncurses/curs_window.3 +++ b/lib/libncurses/curs_window.3 @@ -109,6 +109,10 @@ If many small changes are made to the window, the \fBwsyncup\fR option could degrade performance. Note that \fBsyncok\fR may be a macro. +.SH BUGS +The subwindow functions (\fIsubwin\fR, \fIderwin\fR, etc.) are flaky, +incompletely implemented, and not well tested, especially in their +interaction with scrolling. .SH SEE ALSO \fBncurses\fR(3X), \fBcurs_refresh\fR(3X), \fBcurs_touch\fR(3X) .\"# diff --git a/lib/libncurses/curses.h b/lib/libncurses/curses.h new file mode 100644 index 000000000000..2191422e2f7d --- /dev/null +++ b/lib/libncurses/curses.h @@ -0,0 +1,530 @@ + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992, 1993, 1994 * +* by Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, not removed * +* from header files, and is reproduced in any documentation * +* accompanying it or the applications linked with it. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + +#ifndef __NCURSES_H +#define __NCURSES_H +#define CURSES 1 +#define CURSES_H 1 + +#include +#include +#ifndef NOTERMIOS +#include +#ifndef TERMIOS +#define TERMIOS 1 +#endif +#else +#include +#include +#endif +#include + +#define bool char + +typedef unsigned long chtype; + +/* attributes */ +#define A_ATTRIBUTES 0xffffff00 +#define A_NORMAL 0x00000000 +#define A_STANDOUT 0x00010000 +#define A_UNDERLINE 0x00020000 +#define A_REVERSE 0x00040000 +#define A_BLINK 0x00080000 +#define A_DIM 0x00100000 +#define A_BOLD 0x00200000 +#define A_ALTCHARSET 0x00400000 +#define A_INVIS 0x00800000 +#define A_PROTECT 0x01000000 +#define A_CHARTEXT 0x000000ff +#define A_COLOR 0x0000ff00 +#define COLOR_PAIR(n) (n << 8) +#define PAIR_NUMBER(a) ((a & A_COLOR) >> 8) + +/* colors */ +extern int COLORS; +extern int COLOR_PAIRS; +extern unsigned char *color_pairs; + +#define COLOR_BLACK 0 +#define COLOR_RED 1 +#define COLOR_GREEN 2 +#define COLOR_YELLOW 3 +#define COLOR_BLUE 4 +#define COLOR_MAGENTA 5 +#define COLOR_CYAN 6 +#define COLOR_WHITE 7 + +/* line graphics */ + +extern chtype acs_map[]; + + +#define ACS_ULCORNER (acs_map['l']) +#define ACS_LLCORNER (acs_map['m']) +#define ACS_URCORNER (acs_map['k']) +#define ACS_LRCORNER (acs_map['j']) +#define ACS_RTEE (acs_map['u']) +#define ACS_LTEE (acs_map['t']) +#define ACS_BTEE (acs_map['v']) +#define ACS_TTEE (acs_map['w']) +#define ACS_HLINE (acs_map['q']) +#define ACS_VLINE (acs_map['x']) +#define ACS_PLUS (acs_map['n']) +#define ACS_S1 (acs_map['o']) /* scan line 1 */ +#define ACS_S9 (acs_map['s']) /* scan line 9 */ +#define ACS_DIAMOND (acs_map['`']) /* diamond */ +#define ACS_CKBOARD (acs_map['a']) /* checker board (stipple) */ +#define ACS_DEGREE (acs_map['f']) /* degree symbol */ +#define ACS_PLMINUS (acs_map['g']) /* plus/minus */ +#define ACS_BULLET (acs_map['~']) /* bullet */ +#define ACS_LARROW (acs_map[',']) /* arrow pointing left */ +#define ACS_RARROW (acs_map['+']) /* arrow pointing right */ +#define ACS_DARROW (acs_map['.']) /* arrow pointing down */ +#define ACS_UARROW (acs_map['-']) /* arrow pointing up */ +#define ACS_BOARD (acs_map['h']) /* board of squares */ +#define ACS_LANTERN (acs_map['I']) /* lantern symbol */ +#define ACS_BLOCK (acs_map['0']) /* solid square block */ + +#ifndef TRUE +# define TRUE (1) +# define FALSE (0) +#endif + +#define ERR (-1) +#define OK (0) + +#define _SUBWIN 0x01 +#define _ENDLINE 0x02 +#define _FULLWIN 0x04 +#define _SCROLLWIN 0x08 +#define _ISPAD 0x10 +#define _HASMOVED 0x20 + +#define _NOCHANGE -1 + +typedef struct screen SCREEN; +typedef struct _win_st WINDOW; + +struct _win_st { + short _cury, _curx; /* current cursor position */ + short _maxy, _maxx; /* maximum values of x and y NOT the screen dimensions */ + short _begy, _begx; + short _flags; + chtype _attrs; + chtype _bkgd; + + /* The following should be consolidated into one bitset */ + bool _notimeout; + bool _use_idc; + bool _clear; + bool _leave; + bool _scroll; + bool _idlok; + bool _immed; + bool _sync; + bool _use_keypad; /* 0=no, 1=yes */ + bool _use_meta; /* T=use the meta key */ + + int _delay; /* 0 = nodelay + <0 = blocking + >0 = delay */ + chtype **_line; + short *_firstchar; /* First changed character in the line */ + short *_lastchar; /* Last changed character in the line */ + short _regtop; /* Top and bottom of scrolling region */ + short _regbottom; + int _parx; + int _pary; + WINDOW *_parent; /* parent if a sub-window */ +}; + +extern WINDOW *stdscr, *curscr, *newscr; + +extern int LINES, COLS; + +#ifdef __cplusplus +extern "C" { +#endif + +extern char ttytype[]; /* needed for backward compatibility */ + +extern int tigetflag(char *); +extern int tigetnum(char *); +extern char *tigetstr(char *); + +/* Debugging : use with libdcurses.a */ + +extern void _init_trace(void); +extern void _tracef(char *, ...); +extern char *_traceattr(int mode); +extern char *_tracechar(const unsigned char mode); +extern void trace(const unsigned int tracelevel); + +/* trace masks */ +#define TRACE_DISABLE 0x00 /* turn off tracing */ +#define TRACE_ORDINARY 0x01 /* ordinary trace mode */ +#define TRACE_CHARPUT 0x02 /* also trace all character outputs */ +#define TRACE_MAXIMUM 0x0f /* maximum trace level */ + +/* function prototypes */ + +extern int baudrate(void); +extern int beep(void); +extern int cbreak(void); +extern int clearok(WINDOW *,int); +extern int copywin(WINDOW *,WINDOW *,int,int,int,int,int,int,int); +extern int curs_set(int); +extern int def_prog_mode(void); +extern int def_shell_mode(void); +extern int delwin(WINDOW *); +extern WINDOW *derwin(WINDOW *,int,int,int,int); +extern int doupdate(void); +extern WINDOW *dupwin(WINDOW *); +extern int echo(void); +extern int endwin(void); +extern char erasechar(void); +extern int flash(void); +extern int flushinp(void); +extern int halfdelay(int); +extern int idlok(WINDOW *,int); +extern int intrflush(WINDOW *,bool); +extern int is_linetouched(WINDOW *,int); +extern int is_wintouched(WINDOW *); +extern WINDOW *initscr(void); +extern int isendwin(void); +extern char *keyname(int); +extern int keypad(WINDOW *,int); +extern char killchar(void); +extern int leaveok(WINDOW *,int); +extern char *longname(void); +extern int meta(WINDOW *,int); +extern int mvcur(int,int,int,int); +extern int mvprintw(int,int,char *,...); +extern int mvscanw(int,int,char *,...); +extern int mvwin(WINDOW *,int,int); +extern int mvwprintw(WINDOW *,int,int,char *,...); +extern int mvwscanw(WINDOW *,int,int,char *,...); +extern WINDOW *newpad(int,int); +extern SCREEN *newterm(char *,FILE *,FILE *); +extern WINDOW *newwin(int,int,int,int); +extern int nl(void); +extern int nocbreak(void); +extern int nodelay(WINDOW *,int); +extern int noecho(void); +extern int nonl(void); +extern int noraw(void); +extern int notimeout(WINDOW *,bool); +extern int overlay(WINDOW *,WINDOW *); +extern int overwrite(WINDOW *,WINDOW *); +extern int pnoutrefresh(WINDOW *,int,int,int,int,int,int); +extern int prefresh(WINDOW *,int,int,int,int,int,int); +extern int printw(char *,...); +extern int putp(char *); +extern int raw(void); +extern int reset_prog_mode(void); +extern int reset_shell_mode(void); +extern int resetty(void); +extern int ripoffline(int line, int (*init)(WINDOW *, int)); +extern int savetty(void); +extern int scanw(char *,...); +extern int scrollok(WINDOW *,int); +extern SCREEN *set_term(SCREEN *); +extern int setupterm(char *,int,int *); +extern WINDOW *subwin(WINDOW *,int,int,int,int); +extern int timeout(int); +extern char *tparm(char *, ...); +extern int tputs(char *,int,int (*)(char)); +extern int typeahead(int); +extern int ungetch(int); +extern int vidattr(chtype); +extern int vidputs(chtype,int (*)(char)); +extern int vwscanw(WINDOW *,char *,va_list); +extern int vwprintw(WINDOW *,char *,va_list); +extern int waddch(WINDOW *,chtype); +extern int waddchnstr(WINDOW *,chtype *,int); +extern int waddnstr(WINDOW *,char *,int); +extern int wattron(WINDOW *,chtype); +extern int wattroff(WINDOW *,chtype); +extern int wbkgd(WINDOW *,chtype); +extern int wborder(WINDOW *,chtype,chtype,chtype,chtype,chtype,chtype,chtype,chtype); +extern int wclear(WINDOW *); +extern int wclrtobot(WINDOW *); +extern int wclrtoeol(WINDOW *); +extern int wdelch(WINDOW *); +extern int wechochar(WINDOW *, chtype); +extern int werase(WINDOW *); +extern int wgetch(WINDOW *); +extern int wgetnstr(WINDOW *,char *,int maxlen); +extern int whline(WINDOW *,chtype,int); +extern int winsch(WINDOW *,chtype); +extern int winsdelln(WINDOW *,int); +extern int winsnstr(WINDOW *,char *,int); +extern int wmove(WINDOW *,int,int); +extern int wnoutrefresh(WINDOW *); +extern int wprintw(WINDOW *,char *,...); +extern int wredrawln(WINDOW *,int,int); +extern int wrefresh(WINDOW *); +extern int wscanw(WINDOW *,char *,...); +extern int wscrl(WINDOW *,int); +extern int wsetscrreg(WINDOW *,int,int); +extern int wtimeout(WINDOW *,int); +extern int wtouchln(WINDOW *,int,int,int); +extern int wvline(WINDOW *,chtype,int); + +extern bool can_change_color(void); +extern int color_content(short,short *,short *, short *); +extern int has_colors(void); +extern int init_color(short,short,short,short); +extern int init_pair(short,short,short); +extern int pair_content(short,short*,short*); +extern int start_color(void); + +extern int slk_init(int); +extern int slk_set(int,char *,int); +extern int slk_refresh(void); +extern int slk_noutrefresh(void); +extern char *slk_label(int); +extern int slk_clear(void); +extern int slk_restore(void); +extern int slk_touch(void); + +#ifdef __cplusplus +} +#endif + +/* + * pseudo functions + */ +#define wgetstr(w, s) wgetnstr(w, s, -1) + +#define napms(x) usleep(1000*x) +#define setterm(term) setupterm(term, 1, (int *)0) + +#define fixterm() reset_prog_mode() +#define resetterm() reset_shell_mode() +#define saveterm() def_prog_mode() +#define crmode() cbreak() +#define nocrmode() nocbreak() +#define gettmode() + +#define getyx(win,y,x) (y = (win)->_cury, x = (win)->_curx) +#define getbegyx(win,y,x) (y = (win)->_begy, x = (win)->_begx) +#define getmaxyx(win,y,x) (y = (win)->_maxy + 1, x = (win)->_maxx + 1) +#define getsyx(y,x) getyx(stdscr, y, x) +#define setsyx(y,x) (stdscr->_cury = y, stdscr->_curx = x) + +#define wbkgdset(w,ch) (win->_bkgd = ch) + +/* It seems older SYSV curses define these */ +#define getattrs(win) (win->_attrs) +#define getmaxx(win) ((win)->_maxx + 1) +#define getmaxy(win) ((win)->_maxy + 1) + +#define winch(win) ((win)->_line[(win)->_cury][(win)->_curx]) +#define wstandout(win) (wattrset(win,A_STANDOUT)) +#define wstandend(win) (wattrset(win,A_NORMAL)) +#define wattrset(win,at) ((win)->_attrs = (at)) + +#define subpad(p,l,c,y,x) derwin(p,l,c,y,x) +#define scroll(win) wscrl(win,1) + +#define touchwin(win) wtouchln((win), 0, (win)->_maxy + 1, 1) +#define touchline(win, s, c) wtouchln((win), s, c, 1) +#define untouchwin(win) wtouchln((win), 0, (win)->_maxy + 1, 0) + +#define box(win, v, h) wborder(win, v, v, h, h, 0, 0, 0, 0) +#define border(ls, rs, ts, bs, tl, tr, bl, br) wborder(stdscr, ls, rs, ts, bs, tl, tr, bl, br) +#define hline(ch, n) whline(stdscr, ch, n) +#define vline(ch, n) wvline(stdscr, ch, n) + +#define winsstr(w, s) winsnstr(w, s, 0) + +#define redrawwin(w) wredrawln(w, 0, w->_maxy+1) +#define waddstr(win,str) waddnstr(win,str,-1) +#define waddchstr(win,str) waddchnstr(win,str,-1) + +/* + * pseudo functions for standard screen + */ + +#define bkgdset(ch) wbkgdset(stdscr,ch) +#define bkgd(ch) wbkgd(stdscr,ch) +#define inch() winch(stdscr) +#define standout() wstandout(stdscr) +#define standend() wstandend(stdscr) +#define attron(at) wattron(stdscr,at) +#define attroff(at) wattroff(stdscr,at) +#define attrset(at) wattrset(stdscr,at) +#define addch(ch) waddch(stdscr,ch) +#define echochar(c) wechochar(stdscr, c) +#define getch() wgetch(stdscr) +#define addstr(str) waddnstr(stdscr,str,-1) +#define getstr(str) wgetstr(stdscr,str) +#define move(y, x) wmove(stdscr,y,x) +#define clear() wclear(stdscr) +#define erase() werase(stdscr) +#define clrtobot() wclrtobot(stdscr) +#define clrtoeol() wclrtoeol(stdscr) +#define insertln() winsdelln(stdscr, 1) +#define winsertln(w) winsdelln(w, 1) +#define deleteln() winsdelln(stdscr, -1) +#define wdeleteln(w) winsdelln(w, -1) +#define refresh() wrefresh(stdscr) +#define insch(c) winsch(stdscr,c) +#define delch() wdelch(stdscr) +#define setscrreg(t,b) wsetscrreg(stdscr,t,b) +#define scrl(n) wscrl(stdscr,n) +#define timeout(delay) wtimeout(stdscr, delay) +#define addnstr(str,n) waddnstr(stdscr,str,n) +#define addchstr(str) waddchstr(stdscr,str) +#define addchnstr(str,n) waddchnstr(stdscr,str, n) +#define insdelln(n) winsdelln(stdscr, n) +#define insstr(s) winsstr(stdscr, s) +#define insnstr(s,n) winsnstr(stdscr, s, n) + +/* + * mv functions +*/ + +#define mvwaddch(win,y,x,ch) (wmove(win,y,x) == ERR ? ERR : waddch(win,ch)) +#define mvwgetch(win,y,x) (wmove(win,y,x) == ERR ? ERR : wgetch(win)) +#define mvwaddchnstr(win,y,x,str,n) (wmove(win,y,x) == ERR ? ERR : waddchnstr(win,str,n)) +#define mvwaddchstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : waddchnstr(win,str,-1)) +#define mvwaddnstr(win,y,x,str,n) (wmove(win,y,x) == ERR ? ERR : waddnstr(win,str,n)) +#define mvwaddstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : waddnstr(win,str,-1)) +#define mvwgetstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : wgetstr(win,str)) +#define mvwinch(win,y,x) (wmove(win,y,x) == ERR ? ERR : winch(win)) +#define mvwdelch(win,y,x) (wmove(win,y,x) == ERR ? ERR : wdelch(win)) +#define mvwinsch(win,y,x,c) (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 mvaddnstr(y,x,str,n) mvwaddnstr(stdscr,y,x,str,n) +#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 mvwinsstr(w, y, x, s) (wmove(w,y,x) == ERR ? ERR : winsstr(w,s)) +#define mvwinsnstr(w, y, x, s, n) (wmove(w,y,x) == ERR ? ERR : winsnstr(w,s,n)) +#define mvinsstr(y,x,s) mvwinsstr(stdscr,y,x,s) +#define mvinsnstr(y,x,s,n) mvwinsnstr(stdscr,y,x,s,n) + +/* Funny "characters" enabled for various special function keys for input */ +/* Whether such a key exists depend if its definition is in the terminfo entry */ + +#define KEY_MIN 0401 /* Minimum curses key */ +#define KEY_BREAK 0401 /* break key (unreliable) */ +#define KEY_DOWN 0402 /* The four arrow keys ... */ +#define KEY_UP 0403 +#define KEY_LEFT 0404 +#define KEY_RIGHT 0405 /* ... */ +#define KEY_HOME 0406 /* Home key (upward+left arrow) */ +#define KEY_BACKSPACE 0407 /* backspace (unreliable) */ +#define KEY_F0 0410 /* Function keys. Space for 64 */ +#define KEY_F(n) (KEY_F0+(n)) /* keys is reserved. */ +#define KEY_DL 0510 /* Delete line */ +#define KEY_IL 0511 /* Insert line */ +#define KEY_DC 0512 /* Delete character */ +#define KEY_IC 0513 /* Insert char or enter insert mode */ +#define KEY_EIC 0514 /* Exit insert char mode */ +#define KEY_CLEAR 0515 /* Clear screen */ +#define KEY_EOS 0516 /* Clear to end of screen */ +#define KEY_EOL 0517 /* Clear to end of line */ +#define KEY_SF 0520 /* Scroll 1 line forward */ +#define KEY_SR 0521 /* Scroll 1 line backwards (reverse) */ +#define KEY_NPAGE 0522 /* Next page */ +#define KEY_PPAGE 0523 /* Previous page */ +#define KEY_STAB 0524 /* Set tab */ +#define KEY_CTAB 0525 /* Clear tab */ +#define KEY_CATAB 0526 /* Clear all tabs */ +#define KEY_ENTER 0527 /* Enter or send (unreliable) */ +#define KEY_SRESET 0530 /* soft (partial) reset (unreliable) */ +#define KEY_RESET 0531 /* reset or hard reset (unreliable) */ +#define KEY_PRINT 0532 /* print or copy */ +#define KEY_LL 0533 /* home down or bottom (lower left) */ + +/* The keypad is arranged like this: */ +/* a1 up a3 */ +/* left b2 right */ +/* c1 down c3 */ + +#define KEY_A1 0534 /* Upper left of keypad */ +#define KEY_A3 0535 /* Upper right of keypad */ +#define KEY_B2 0536 /* Center of keypad */ +#define KEY_C1 0537 /* Lower left of keypad */ +#define KEY_C3 0540 /* Lower right of keypad */ +#define KEY_BTAB 0541 /* Back tab key */ +#define KEY_BEG 0542 /* beg(inning) key */ +#define KEY_CANCEL 0543 /* cancel key */ +#define KEY_CLOSE 0544 /* close key */ +#define KEY_COMMAND 0545 /* cmd (command) key */ +#define KEY_COPY 0546 /* copy key */ +#define KEY_CREATE 0547 /* create key */ +#define KEY_END 0550 /* end key */ +#define KEY_EXIT 0551 /* exit key */ +#define KEY_FIND 0552 /* find key */ +#define KEY_HELP 0553 /* help key */ +#define KEY_MARK 0554 /* mark key */ +#define KEY_MESSAGE 0555 /* message key */ +#define KEY_MOVE 0556 /* move key */ +#define KEY_NEXT 0557 /* next object key */ +#define KEY_OPEN 0560 /* open key */ +#define KEY_OPTIONS 0561 /* options key */ +#define KEY_PREVIOUS 0562 /* previous object key */ +#define KEY_REDO 0563 /* redo key */ +#define KEY_REFERENCE 0564 /* ref(erence) key */ +#define KEY_REFRESH 0565 /* refresh key */ +#define KEY_REPLACE 0566 /* replace key */ +#define KEY_RESTART 0567 /* restart key */ +#define KEY_RESUME 0570 /* resume key */ +#define KEY_SAVE 0571 /* save key */ +#define KEY_SBEG 0572 /* shifted beginning key */ +#define KEY_SCANCEL 0573 /* shifted cancel key */ +#define KEY_SCOMMAND 0574 /* shifted command key */ +#define KEY_SCOPY 0575 /* shifted copy key */ +#define KEY_SCREATE 0576 /* shifted create key */ +#define KEY_SDC 0577 /* shifted delete char key */ +#define KEY_SDL 0600 /* shifted delete line key */ +#define KEY_SELECT 0601 /* select key */ +#define KEY_SEND 0602 /* shifted end key */ +#define KEY_SEOL 0603 /* shifted clear line key */ +#define KEY_SEXIT 0604 /* shifted exit key */ +#define KEY_SFIND 0605 /* shifted find key */ +#define KEY_SHELP 0606 /* shifted help key */ +#define KEY_SHOME 0607 /* shifted home key */ +#define KEY_SIC 0610 /* shifted input key */ +#define KEY_SLEFT 0611 /* shifted left arrow key */ +#define KEY_SMESSAGE 0612 /* shifted message key */ +#define KEY_SMOVE 0613 /* shifted move key */ +#define KEY_SNEXT 0614 /* shifted next key */ +#define KEY_SOPTIONS 0615 /* shifted options key */ +#define KEY_SPREVIOUS 0616 /* shifted prev key */ +#define KEY_SPRINT 0617 /* shifted print key */ +#define KEY_SREDO 0620 /* shifted redo key */ +#define KEY_SREPLACE 0621 /* shifted replace key */ +#define KEY_SRIGHT 0622 /* shifted right arrow */ +#define KEY_SRSUME 0623 /* shifted resume key */ +#define KEY_SSAVE 0624 /* shifted save key */ +#define KEY_SSUSPEND 0625 /* shifted suspend key */ +#define KEY_SUNDO 0626 /* shifted undo key */ +#define KEY_SUSPEND 0627 /* suspend key */ +#define KEY_UNDO 0630 /* undo key */ +#define KEY_MAX 0777 /* Maximum curses key */ + +#endif diff --git a/lib/libncurses/curses.priv.h b/lib/libncurses/curses.priv.h index da8bf0576a8c..4652ff502b3d 100644 --- a/lib/libncurses/curses.priv.h +++ b/lib/libncurses/curses.priv.h @@ -24,7 +24,7 @@ typedef struct sigaction sigaction_t; #include "SigAction.h" #endif -#include +#include "curses.h" #define min(a,b) ((a) > (b) ? (b) : (a)) #define max(a,b) ((a) < (b) ? (b) : (a)) @@ -34,17 +34,19 @@ typedef struct sigaction sigaction_t; #define CHANGED -1 -extern int _coloron; -extern int _isendwin; +extern WINDOW *newscr; #ifdef TRACE -#define T(a) if (_tracing) _tracef a +#define T(a) if (_tracing & TRACE_ORDINARY) _tracef a +#define TR(n, a) if (_tracing & (n)) _tracef a extern int _tracing; +extern char *visbuf(const char *); #else -#define T(a) +#define T(a) +#define TR(n, a) #endif -extern int _outc(char); +extern int _outch(char); extern void init_acs(void); extern void tstp(int); extern WINDOW *makenew(int, int, int, int); @@ -79,6 +81,7 @@ typedef struct { struct screen { FILE *_ifp; /* input file ptr for this terminal */ FILE *_ofp; /* output file ptr for this terminal */ + int _checkfd; #ifdef MYTINFO struct _terminal *_term; #else @@ -86,11 +89,16 @@ struct screen { #endif WINDOW *_curscr; /* windows specific to a given terminal */ WINDOW *_newscr; + WINDOW *_stdscr; struct try *_keytry; /* "Try" for use with keypad mode */ unsigned int _fifo[FIFO_SIZE]; /* Buffer for pushed back characters */ - signed char _fifohead, + signed char _fifohead, _fifotail, _fifopeek; + bool _endwin; + chtype _current_attr; + bool _coloron; + int _cursor; /* visibility of the cursor */ int _cursrow; /* Row and column of physical cursor */ int _curscol; bool _nl; /* True if NL -> CR/NL is on */ diff --git a/lib/libncurses/lib_acs.c b/lib/libncurses/lib_acs.c index 70fd6d2f6158..640ab897099b 100644 --- a/lib/libncurses/lib_acs.c +++ b/lib/libncurses/lib_acs.c @@ -5,7 +5,7 @@ #include "curses.priv.h" -#include +#include "terminfo.h" #include /* line graphics */ @@ -67,7 +67,7 @@ void init_acs() acs_map['0'] = (chtype)'#' & A_CHARTEXT; if (ena_acs != NULL) - tputs(ena_acs, 1, _outc); + putp(ena_acs); if (acs_chars != NULL) { int i = 0; @@ -91,8 +91,7 @@ void init_acs() } #ifdef TRACE else { - if (_tracing) - _tracef("acsc not defined, using default mapping"); + T(("acsc not defined, using default mapping")); } #endif } diff --git a/lib/libncurses/lib_addch.c b/lib/libncurses/lib_addch.c index 50c4ae7bac0a..00684eddd1d1 100644 --- a/lib/libncurses/lib_addch.c +++ b/lib/libncurses/lib_addch.c @@ -13,25 +13,23 @@ #include "curses.priv.h" #include "unctrl.h" -int -waddch(WINDOW *win, chtype c) +static int +wladdch(WINDOW *win, chtype c, bool literal) { int x, y; int newx; chtype ch = c; -#if 0 - /* enabling this causes tons of tracing output - and slow ncurses down to a crawl */ - T(("waddch(%x,%c (%x)) called", win, ch&A_CHARTEXT, ch)); -#endif - x = win->_curx; y = win->_cury; if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0) return(ERR); + /* ugly, but necessary --- and, bizarrely enough, even portable! */ + if (literal) + goto noctrl; + switch (ch&A_CHARTEXT) { case '\t': for (newx = x + (8 - (x & 07)); x < newx; x++) @@ -40,7 +38,7 @@ chtype ch = c; return(OK); case '\n': wclrtoeol(win); - x = 0; + x = 0; goto newline; case '\r': x = 0; @@ -53,8 +51,17 @@ chtype ch = c; if (ch < ' ') return(waddstr(win, unctrl(ch))); + /* FALL THROUGH */ + noctrl: + T(("win attr = %x", win->_attrs)); ch |= win->_attrs; + if (win->_line[y][x]&A_CHARTEXT == ' ') + ch |= win->_bkgd; + else + ch |= (win->_bkgd&A_ATTRIBUTES); + T(("bkg = %x -> ch = %x", win->_bkgd, ch)); + if (win->_line[y][x] != ch) { if (win->_firstchar[y] == _NOCHANGE) win->_firstchar[y] = win->_lastchar[y] = x; @@ -65,6 +72,7 @@ chtype ch = c; } + T(("char %d of line %d is %x", x, y, ch)); win->_line[y][x++] = ch; if (x > win->_maxx) { x = 0; @@ -84,3 +92,16 @@ chtype ch = c; return(OK); } + +int waddch(WINDOW *win, chtype ch) +{ + TR(TRACE_CHARPUT, ("waddch(%x,%c (%x)) called", win, ch&A_CHARTEXT, ch)); + return wladdch(win, ch, FALSE); +} + +int wechochar(WINDOW *win, chtype ch) +{ + T(("wechochar(%x,%c (%x)) called", win, ch&A_CHARTEXT, ch)); + + return wladdch(win, ch, TRUE); +} diff --git a/lib/libncurses/lib_addstr.c b/lib/libncurses/lib_addstr.c index 007598cdb308..d9cb30aae2fb 100644 --- a/lib/libncurses/lib_addstr.c +++ b/lib/libncurses/lib_addstr.c @@ -15,21 +15,21 @@ int waddnstr(WINDOW *win, char *str, int n) { - T(("waddnstr(%x,%s,%d) called", win, str, n)); + T(("waddnstr(%x,\"%s\",%d) called", win, visbuf(str), n)); if (str == NULL) return ERR; if (n < 0) { while (*str != '\0') { - if (waddch(win, (unsigned char)*str++) == ERR) + if (waddch(win, (chtype)(unsigned char)*str++) == ERR) return(ERR); } return OK; } while((n-- > 0) && (*str != '\0')) { - if (waddch(win, (unsigned char)*str++) == ERR) + if (waddch(win, (chtype)(unsigned char)*str++) == ERR) return ERR; } return OK; @@ -42,14 +42,14 @@ waddchnstr(WINDOW *win, chtype *str, int n) if (n < 0) { while (*str) { - if (waddch(win, *str++) == ERR) + if (waddch(win, (chtype)(unsigned char)*str++) == ERR) return(ERR); } return OK; } while(n-- > 0) { - if (waddch(win, *str++) == ERR) + if (waddch(win, (chtype)(unsigned char)*str++) == ERR) return ERR; } return OK; diff --git a/lib/libncurses/lib_beep.c b/lib/libncurses/lib_beep.c index 7837ac142a81..60ce5920b20e 100644 --- a/lib/libncurses/lib_beep.c +++ b/lib/libncurses/lib_beep.c @@ -11,7 +11,7 @@ */ #include "curses.priv.h" -#include +#include "terminfo.h" /* * beep() @@ -27,9 +27,9 @@ int beep() /* should make sure that we are not in altchar mode */ if (bell) - return(tputs(bell, 1, _outc)); + return(putp(bell)); else if (flash_screen) - return(tputs(flash_screen, 1, _outc)); + return(putp(flash_screen)); else return(ERR); } @@ -48,9 +48,9 @@ int flash() /* should make sure that we are not in altchar mode */ if (flash_screen) - return(tputs(flash_screen, 1, _outc)); + return(putp(flash_screen)); else if (bell) - return(tputs(bell, 1, _outc)); + return(putp(bell)); else return(ERR); } diff --git a/lib/libncurses/lib_bkgd.c b/lib/libncurses/lib_bkgd.c new file mode 100644 index 000000000000..0210995b7eb0 --- /dev/null +++ b/lib/libncurses/lib_bkgd.c @@ -0,0 +1,37 @@ + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992, 1993, 1994 * +* by Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, not removed * +* from header files, and is reproduced in any documentation * +* accompanying it or the applications linked with it. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + +#include "curses.h" +#include "curses.priv.h" + +int wbkgd(WINDOW *win, chtype ch) +{ +int x, y; + + T(("wbkgd(%x, %x) called", win, ch)); + for (y = 0; y < win->_maxy; y++) + for (x = 0; x < win->_maxx; x++) + if (win->_line[y][x]&A_CHARTEXT == ' ') + win->_line[y][x] |= ch; + else + win->_line[y][x] |= (ch&A_ATTRIBUTES); + touchwin(win); + return OK; +} + diff --git a/lib/libncurses/lib_color.c b/lib/libncurses/lib_color.c index 8ba3ad993ef1..17aaedeb7311 100644 --- a/lib/libncurses/lib_color.c +++ b/lib/libncurses/lib_color.c @@ -8,29 +8,29 @@ * */ +#include #include "curses.priv.h" -#include +#include "terminfo.h" int COLOR_PAIRS; int COLORS; -unsigned char color_pairs[64]; - -int _coloron = 0; +unsigned char *color_pairs; int start_color() { T(("start_color() called.")); if (orig_pair != NULL) - tputs(orig_pair, 1, _outc); + putp(orig_pair); else return ERR; if (max_pairs != -1) COLOR_PAIRS = max_pairs; else return ERR; + color_pairs = malloc(max_pairs); if (max_colors != -1) COLORS = max_colors; else return ERR; - _coloron = 1; + SP->_coloron = 1; T(("started color: COLORS = %d, COLOR_PAIRS = %d", COLORS, COLOR_PAIRS)); @@ -41,7 +41,7 @@ int init_pair(short pair, short f, short b) { T(("init_pair( %d, %d, %d )", pair, f, b)); - if ((pair < 1) || (pair > COLOR_PAIRS)) + if ((pair < 1) || (pair >= COLOR_PAIRS)) return ERR; if ((f < 0) || (f >= COLORS) || (b < 0) || (b >= COLORS)) return ERR; @@ -53,7 +53,7 @@ int init_pair(short pair, short f, short b) color_pairs[pair] = ( (f & 0x0f) | (b & 0x0f) << 4 ); - return color_pairs[pair]; + return OK; } int init_color(short color, short r, short g, short b) @@ -68,7 +68,7 @@ int init_color(short color, short r, short g, short b) if (r < 0 || r > 1000 || g < 0 || g > 1000 || b < 0 || b > 1000) return ERR; - tputs(tparm(initialize_color, color, r, g, b), 1, _outc); + putp(tparm(initialize_color, color, r, g, b)); return OK; } diff --git a/lib/libncurses/lib_delch.c b/lib/libncurses/lib_delch.c index 5c62acb38bd9..bc802ca81186 100644 --- a/lib/libncurses/lib_delch.c +++ b/lib/libncurses/lib_delch.c @@ -11,7 +11,7 @@ */ #include "curses.priv.h" -#include +#include "terminfo.h" int wdelch(WINDOW *win) { diff --git a/lib/libncurses/lib_doupdate.c b/lib/libncurses/lib_doupdate.c index e729a47e7370..4747691336e0 100644 --- a/lib/libncurses/lib_doupdate.c +++ b/lib/libncurses/lib_doupdate.c @@ -12,9 +12,13 @@ *-----------------------------------------------------------------*/ #include +#include +#ifdef SYS_SELECT +#include +#endif #include #include "curses.priv.h" -#include +#include "terminfo.h" #ifdef SVR4_ACTION #define _POSIX_SOURCE #endif @@ -30,9 +34,12 @@ static void DelChar( int count ); static inline void PutAttrChar(chtype ch) { + TR(TRACE_CHARPUT, ("PutAttrChar(%s, %s)", + _tracechar(ch & A_CHARTEXT), + _traceattr((ch & (chtype)A_ATTRIBUTES)))); if (curscr->_attrs != (ch & (chtype)A_ATTRIBUTES)) { curscr->_attrs = ch & (chtype)A_ATTRIBUTES; - vidputs(curscr->_attrs, _outc); + vidputs(curscr->_attrs, _outch); } putc(ch & A_CHARTEXT, SP->_ofp); } @@ -41,9 +48,8 @@ static int LRCORNER = FALSE; static inline void PutChar(chtype ch) { - T(("puttin %x", ch)); if (LRCORNER == TRUE && SP->_curscol == columns-1) { - int i = lines; + int i = lines -1; int j = columns -1; LRCORNER = FALSE; @@ -52,21 +58,21 @@ static inline void PutChar(chtype ch) ) return; if (cursor_left) - tputs(cursor_left, 1, _outc); + putp(cursor_left); else - mvcur(-1, -1, i-1, j); + mvcur(-1, -1, i, j); PutAttrChar(ch); if (cursor_left) - tputs(cursor_left, 1, _outc); + putp(cursor_left); else - mvcur(-1, -1, i-1, j); + mvcur(-1, -1, i, j); if (enter_insert_mode && exit_insert_mode) { - tputs(enter_insert_mode, 1, _outc); - PutAttrChar(newscr->_line[i-1][columns-2]); - tputs(exit_insert_mode, 1, _outc); + putp(enter_insert_mode); + PutAttrChar(newscr->_line[i][j-1]); + putp(exit_insert_mode); } else if (insert_character) { - tputs(insert_character, 1, _outc); - PutAttrChar(newscr->_line[i-1][columns-2]); + putp(insert_character); + PutAttrChar(newscr->_line[i][j-1]); } return; } @@ -89,9 +95,12 @@ static inline void GoTo(int row, int col) SP->_curscol = col; } -int _outc(char ch) +int _outch(char ch) { - putc(ch, SP->_ofp); + if (SP != NULL) + putc(ch, SP->_ofp); + else + putc(ch, stdout); return OK; } @@ -107,16 +116,29 @@ sigaction_t act, oact; act.sa_flags = 0; sigaction(SIGTSTP, &act, &oact); - if (_isendwin == 1) { + if (SP->_endwin == TRUE) { T(("coming back from shell mode")); reset_prog_mode(); /* is this necessary? */ if (enter_alt_charset_mode) init_acs(); newscr->_clear = TRUE; - _isendwin = 0; + SP->_endwin = FALSE; } + /* check for pending input */ + { + fd_set fdset; + struct timeval timeout = {0,0}; + + FD_ZERO(&fdset); + FD_SET(SP->_checkfd, &fdset); + if (select(SP->_checkfd+1, &fdset, NULL, NULL, &timeout) != 0) { + fflush(SP->_ofp); + return OK; + } + } + if (curscr->_clear) { /* force refresh ? */ T(("clearing and updating curscr")); ClrUpdate(curscr); /* yes, clear all & update */ @@ -194,11 +216,9 @@ int lastNonBlank; for (i = 0; i < lines; i++) { lastNonBlank = columns - 1; - while (scr->_line[i][lastNonBlank] == BLANK ) + while (lastNonBlank >= 0 && scr->_line[i][lastNonBlank] == BLANK) lastNonBlank--; - T(("updating line %d upto %d", i, lastNonBlank)); - /* check if we are at the lr corner */ if (i == lines-1) if ((auto_right_margin) && !(eat_newline_glitch) && @@ -221,7 +241,8 @@ int lastNonBlank; for (; inspace > 0; inspace--) PutChar(scr->_line[i][j-1]); } else { - tputs(tparm(parm_right_cursor, inspace), 1, _outc); + putp(tparm(parm_right_cursor, inspace)); + SP->_curscol += inspace; } inspace = 0; } @@ -312,7 +333,7 @@ int attrchanged = 0; T(("back_color_erase, turning attributes off")); vidattr(curscr->_attrs = A_NORMAL); } - tputs(clr_eol, 1, _outc); + putp(clr_eol); } } else { lastChar = columns - 1; @@ -382,7 +403,7 @@ int attrchanged = 0; T(("back_color_erase, turning attributes off")); vidattr(curscr->_attrs = A_NORMAL); } - tputs(clr_eol, 1, _outc); + putp(clr_eol); /* check if we are at the lr corner */ if (lineno == lines-1) @@ -403,11 +424,11 @@ int attrchanged = 0; return; oLastChar = columns - 1; - while (oLastChar > firstChar && oldLine[oLastChar] == ' ') + while (oLastChar > firstChar && oldLine[oLastChar] == BLANK) oLastChar--; nLastChar = columns - 1; - while (nLastChar > firstChar && newLine[nLastChar] == ' ') + while (nLastChar > firstChar && newLine[nLastChar] == BLANK) nLastChar--; if((nLastChar == firstChar) && clr_eol) { @@ -416,9 +437,9 @@ int attrchanged = 0; T(("back_color_erase, turning attributes off")); vidattr(curscr->_attrs = A_NORMAL); } - tputs(clr_eol,1,_outc); + putp(clr_eol); - if(newLine[firstChar] != ' ' ) { + if(newLine[firstChar] != BLANK ) { /* check if we are at the lr corner */ if (lineno == lines-1) if ((auto_right_margin) && !(eat_newline_glitch) && @@ -491,19 +512,19 @@ static void ClearScreen() T(("ClearScreen() called")); if (clear_screen) { - tputs(clear_screen, 1, _outc); + putp(clear_screen); SP->_cursrow = SP->_curscol = 0; } else if (clr_eos) { SP->_cursrow = SP->_curscol = -1; GoTo(0,0); - tputs(clr_eos, 1, _outc); + putp(clr_eos); } else if (clr_eol) { SP->_cursrow = SP->_curscol = -1; while (SP->_cursrow < lines) { GoTo(SP->_cursrow, 0); - tputs(clr_eol, 1, _outc); + putp(clr_eol); } GoTo(0,0); } @@ -523,15 +544,15 @@ static void InsStr(chtype *line, int count) T(("InsStr(%x,%d) called", line, count)); if (enter_insert_mode && exit_insert_mode) { - tputs(enter_insert_mode, 1, _outc); + putp(enter_insert_mode); while (count) { PutChar(*line); line++; count--; } - tputs(exit_insert_mode, 1, _outc); + putp(exit_insert_mode); } else if (parm_ich) { - tputs(tparm(parm_ich, count), 1, _outc); + putp(tparm(parm_ich, count)); while (count) { PutChar(*line); line++; @@ -539,7 +560,7 @@ static void InsStr(chtype *line, int count) } } else { while (count) { - tputs(insert_character, 1, _outc); + putp(insert_character); PutChar(*line); line++; count--; @@ -563,10 +584,10 @@ static void DelChar(int count) vidattr(curscr->_attrs = A_NORMAL); } if (parm_dch) { - tputs(tparm(parm_dch, count), 1, _outc); + putp(tparm(parm_dch, count)); } else { while (count--) - tputs(delete_character, 1, _outc); + putp(delete_character); } } diff --git a/lib/libncurses/lib_endwin.c b/lib/libncurses/lib_endwin.c index b32af2de5de3..fc4622288ce5 100644 --- a/lib/libncurses/lib_endwin.c +++ b/lib/libncurses/lib_endwin.c @@ -10,14 +10,14 @@ ** */ -#include +#include "terminfo.h" #include "curses.priv.h" -int _isendwin; - int isendwin() { - return _isendwin; + if (SP == NULL) + return FALSE; + return SP->_endwin; } int @@ -25,19 +25,22 @@ endwin() { T(("endwin() called")); - _isendwin = 1; + SP->_endwin = TRUE; mvcur(-1, -1, lines - 1, 0); if (exit_ca_mode) - tputs(exit_ca_mode, 1, _outc); + putp(exit_ca_mode); - if (_coloron == 1) - tputs(orig_pair, 1, _outc); + if (SP->_coloron == TRUE) + putp(orig_pair); if (curscr && (curscr->_attrs != A_NORMAL)) vidattr(curscr->_attrs = A_NORMAL); + if (SP->_cursor != 1) + putp(cursor_normal); + fflush(SP->_ofp); return(reset_shell_mode()); diff --git a/lib/libncurses/lib_erase.c b/lib/libncurses/lib_erase.c index 221a04cd8183..3e3703ca3463 100644 --- a/lib/libncurses/lib_erase.c +++ b/lib/libncurses/lib_erase.c @@ -11,7 +11,7 @@ */ #include "curses.priv.h" -#include +#include "terminfo.h" #define BLANK ' ' diff --git a/lib/libncurses/lib_getch.c b/lib/libncurses/lib_getch.c index 56fdb5b7fffe..458cdecf4861 100644 --- a/lib/libncurses/lib_getch.c +++ b/lib/libncurses/lib_getch.c @@ -14,7 +14,7 @@ #include #include #include -#ifdef BRAINDEAD +#if defined(BRAINDEAD) extern int errno; #endif #include "curses.priv.h" @@ -79,6 +79,7 @@ unsigned char ch; n = read(fileno(SP->_ifp), &ch, 1); if (n == -1 && errno == EINTR) goto again; + T(("read %d characters", n)); SP->_fifo[tail] = ch; if (head == -1) head = tail; t_inc(); @@ -139,7 +140,8 @@ int ch; if (win->_use_keypad) ch = kgetch(win); else { - fifo_push(); + if (head == -1) + fifo_push(); ch = fifo_pull(); } @@ -182,7 +184,7 @@ kgetch(WINDOW *win) { struct try *ptr; int ch = 0; -int timeleft = 2000; +int timeleft = 1000; T(("kgetch(%x) called", win)); @@ -204,8 +206,7 @@ int timeleft = 2000; } else { /* go back for another character */ ptr = ptr->child; T(("going back for more")); - } - else + } else break; T(("waiting for rest of sequence")); diff --git a/lib/libncurses/lib_getstr.c b/lib/libncurses/lib_getstr.c index fae5b21c1e7e..eb82bf213596 100644 --- a/lib/libncurses/lib_getstr.c +++ b/lib/libncurses/lib_getstr.c @@ -42,7 +42,7 @@ int ch; noecho(); noraw(); cbreak(); - keypad(win, FALSE); + keypad(win, TRUE); erasec = erasechar(); killc = killchar(); @@ -81,25 +81,25 @@ int ch; } } - win->_curx = 0; - if (win->_cury < win->_maxy) - win->_cury++; + win->_curx = 0; + if (win->_cury < win->_maxy) + win->_cury++; wrefresh(win); - if (! oldnl) + if (oldnl == FALSE) nonl(); - if (oldecho) + if (oldecho == TRUE) echo(); - if (oldraw) + if (oldraw == TRUE) raw(); - if (! oldcbreak) + if (oldcbreak == FALSE) nocbreak(); - if (oldkeypad) - keypad(win, TRUE); + if (oldkeypad == FALSE) + keypad(win, FALSE); if (ch == ERR) { *str = '\0'; @@ -107,7 +107,7 @@ int ch; } *str = '\0'; - T(("wgetnstr returns %s", oldstr)); + T(("wgetnstr returns \"%s\"", visbuf(oldstr))); return(OK); } diff --git a/lib/libncurses/lib_initscr.c b/lib/libncurses/lib_initscr.c index 863a74d76242..5c9dfc3326ee 100644 --- a/lib/libncurses/lib_initscr.c +++ b/lib/libncurses/lib_initscr.c @@ -18,11 +18,11 @@ WINDOW *initscr() #ifdef TRACE _init_trace(); - if (_tracing) - _tracef("initscr() called"); + T(("initscr() called")); #endif + if (newterm(getenv("TERM"), stdout, stdin) == NULL) - return NULL; + return NULL; else { def_shell_mode(); def_prog_mode(); diff --git a/lib/libncurses/lib_insdel.c b/lib/libncurses/lib_insdel.c index 9eb130bac270..da26a2a31c54 100644 --- a/lib/libncurses/lib_insdel.c +++ b/lib/libncurses/lib_insdel.c @@ -14,10 +14,10 @@ #include #include "curses.priv.h" -#include +#include "terminfo.h" int -winsdel(WINDOW *win, int n) +winsdelln(WINDOW *win, int n) { int ret, sscroll, stop, sbot; diff --git a/lib/libncurses/lib_kernel.c b/lib/libncurses/lib_kernel.c index 40ccd2ca4f4a..5fa18797d5e5 100644 --- a/lib/libncurses/lib_kernel.c +++ b/lib/libncurses/lib_kernel.c @@ -7,7 +7,6 @@ * lib_kernel.c * * Misc. low-level routines: - * wattron() * reset_prog_mode() * reset_shell_mode() * baudrate() @@ -21,15 +20,41 @@ */ #include "curses.priv.h" -#include +#include "terminfo.h" int wattron(WINDOW *win, chtype at) { - win->_attrs &= (unsigned long)0xffff00ff; - win->_attrs |= at; + T(("wattron(%x,%s) current = %s", win, _traceattr(at), _traceattr(win->_attrs))); + if (PAIR_NUMBER(at) > 0x00) { + win->_attrs = (win->_attrs & ~A_COLOR) | at ; + T(("new attribute is %s", _traceattr(win->_attrs))); + } else { + win->_attrs |= at; + T(("new attribute is %s", _traceattr(win->_attrs))); + } return OK; } +int wattroff(WINDOW *win, chtype at) +{ +#define IGNORE_COLOR_OFF FALSE + + T(("wattroff(%x,%s) current = %s", win, _traceattr(at), _traceattr(win->_attrs))); + if (IGNORE_COLOR_OFF == TRUE) { + if (PAIR_NUMBER(at) == 0xff) /* turn off color */ + win->_attrs &= ~at; + else /* leave color alone */ + win->_attrs &= ~(at|~A_COLOR); + } else { + if (PAIR_NUMBER(at) > 0x00) /* turn off color */ + win->_attrs &= ~at; + else /* leave color alone */ + win->_attrs &= ~(at|~A_COLOR); + } + T(("new attribute is %s", _traceattr(win->_attrs))); + return OK; +} + #ifndef MYTINFO int reset_prog_mode() { @@ -61,6 +86,8 @@ int reset_shell_mode() int curs_set(int vis) { +int cursor = SP->_cursor; + T(("curs_set(%d)", vis)); if (vis < 0 || vis > 2) @@ -69,20 +96,43 @@ int curs_set(int vis) switch(vis) { case 2: if (cursor_visible) - tputs(cursor_visible, 1, _outc); + putp(cursor_visible); break; case 1: if (cursor_normal) - tputs(cursor_normal, 1, _outc); + putp(cursor_normal); break; case 0: if (cursor_invisible) - tputs(cursor_invisible, 1, _outc); + putp(cursor_invisible); break; } - return OK; + SP->_cursor = vis; + return cursor; } +int delay_output(int ms) +{ +int speed; + + T(("delay_output(%d) called", ms)); + + if (!no_pad_char && (speed = baudrate()) == ERR) + return(ERR); + else { + register int nullcount; + + if (!no_pad_char) + for (nullcount = ms * 1000 / speed; nullcount > 0; nullcount--) + putc(*pad_char, SP->_ofp); + (void) fflush(SP->_ofp); + if (no_pad_char) + napms(ms); + } + + return OK; +} + /* * erasechar() * @@ -208,10 +258,9 @@ int baudrate() { int i, ret; -#ifdef UNTRACE - if (_tracing) - _tracef("baudrate() called"); -#endif + + T(("baudrate() called")); + #ifdef TERMIOS ret = cfgetospeed(&cur_term->Nttyb); #else diff --git a/lib/libncurses/lib_longname.c b/lib/libncurses/lib_longname.c index 528757bd8ae0..a8de0856a2aa 100644 --- a/lib/libncurses/lib_longname.c +++ b/lib/libncurses/lib_longname.c @@ -12,7 +12,7 @@ #include #include "curses.priv.h" -#include +#include "terminfo.h" char * longname() diff --git a/lib/libncurses/lib_move.c b/lib/libncurses/lib_move.c index e7a28ebb8e4f..cf56fa07df3f 100644 --- a/lib/libncurses/lib_move.c +++ b/lib/libncurses/lib_move.c @@ -15,10 +15,7 @@ int wmove(WINDOW *win, int y, int x) { -#ifdef TRACE - if (_tracing) - _tracef("wmove(%x,%d,%d) called", win, y, x); -#endif + T(("wmove(%x,%d,%d) called", win, y, x)); if (x >= 0 && x <= win->_maxx && y >= 0 && y <= win->_maxy) diff --git a/lib/libncurses/lib_mvcur.c b/lib/libncurses/lib_mvcur.c index 1a6ba6552118..a0f3bd5e1363 100644 --- a/lib/libncurses/lib_mvcur.c +++ b/lib/libncurses/lib_mvcur.c @@ -20,7 +20,7 @@ #include #include -#include +#include "terminfo.h" #include "curses.priv.h" #ifndef OPT_MVCUR @@ -175,17 +175,14 @@ struct Sequence seqA, seqB, /* allocate work structures */ *try; /* next try */ bool nlstat = SP->_nl; /* nl-output-mapping in effect ?*/ -#ifdef TRACE - if (_tracing) - _tracef("=============================\nmvcur(%d,%d,%d,%d) called", - oldrow, oldcol, newrow, newcol); -#endif + T(("=============================\nmvcur(%d,%d,%d,%d) called", + oldrow, oldcol, newrow, newcol)); if ((oldrow == newrow) && (oldcol == newcol)) return OK; if (oldcol == columns-1 && eat_newline_glitch && auto_right_margin) { - tputs(tparm(cursor_address, newrow, newcol), 1, _outc); + putp(tparm(cursor_address, newrow, newcol)); return OK; } @@ -255,10 +252,7 @@ bool nlstat = SP->_nl; /* nl-output-mapping in effect ?*/ nl(); #endif -#ifdef TRACE - if (_tracing) - _tracef("==================================="); -#endif + T(("===================================")); return OK; } @@ -488,10 +482,7 @@ add_seq(struct Sequence *seq1, struct Sequence *seq2) { int *vptr; -#ifdef TRACE - if (_tracing) - _tracef("add_seq(%x, %x)", seq1, seq2); -#endif + T(("add_seq(%x, %x)", seq1, seq2)); if(seq1->cost >= INFINITY || seq2->cost >= INFINITY) seq1->cost = INFINITY; @@ -511,10 +502,7 @@ int *opptr, prm[9], ps, p, op; int count; char *sequence(); -#ifdef TRACE - if (_tracing) - _tracef("out_seq(%x)", seq); -#endif + T(("out_seq(%x)", seq)); if (seq->cost >= INFINITY) return; @@ -526,14 +514,14 @@ char *sequence(); for (p = 0; p < ps; p++) /* fill in needed parms */ prm[p] = *(++opptr); - tputs(tparm(sequence(op), + putp(tparm(sequence(op), prm[0], prm[1], prm[2], prm[3], prm[4], - prm[5], prm[6], prm[7], prm[8]), 1, _outc); + prm[5], prm[6], prm[7], prm[8])); } else { count = *(++opptr); /*rev should save tputs output instead of mult calls */ while (count--) /* do count times */ - tputs(sequence(op), 1, _outc); + putp(sequence(op)); } } } @@ -550,10 +538,7 @@ char *sequence(); static void update_ops() { -#ifdef TRACE - if (_tracing) - _tracef("update_ops()"); -#endif + T(("update_ops()")); if (SP) { /* SP structure exists */ int op; @@ -631,10 +616,8 @@ static void add_op(struct Sequence *seq, int op, ...) va_list argp; int num_ps, p; -#ifdef TRACE - if (_tracing) - _tracef("adding op %d to sequence", op); -#endif + T(("adding op %d to sequence", op)); + va_start(argp, op); num_ps = - op_info[op]; /* get parms or -cost */ @@ -673,10 +656,8 @@ int num_ps, p; static char *sequence(int op) { -#ifdef TRACE - if (_tracing) - _tracef("sequence(%d)", op); -#endif + T(("sequence(%d)", op)); + switch(op) { case CARRIAGE_RETURN: return (carriage_return); diff --git a/lib/libncurses/lib_mvwin.c b/lib/libncurses/lib_mvwin.c index f58925e89d77..2e6159fa2788 100644 --- a/lib/libncurses/lib_mvwin.c +++ b/lib/libncurses/lib_mvwin.c @@ -11,7 +11,7 @@ */ #include "curses.priv.h" -#include +#include "terminfo.h" int mvwin(WINDOW *win, int by, int bx) { diff --git a/lib/libncurses/lib_newterm.c b/lib/libncurses/lib_newterm.c index 88d0a6039477..c1f8694f9f95 100644 --- a/lib/libncurses/lib_newterm.c +++ b/lib/libncurses/lib_newterm.c @@ -12,7 +12,7 @@ #include #include "curses.priv.h" -#include +#include "terminfo.h" #ifdef SVR4_ACTION #define _POSIX_SOURCE #endif @@ -52,7 +52,7 @@ char *use_it = _ncurses_copyright; use_it = use_it; /* shut up compiler */ #ifdef TRACE _init_trace(); - T(("newterm(%s,%x,%x) called", term, ofp, ifp)); + T(("newterm(\"%s\",%x,%x) called", term, ofp, ifp)); #endif #ifdef MYTINFO @@ -87,6 +87,9 @@ char *use_it = _ncurses_copyright; SP->_fifohead = -1; SP->_fifotail = 0; SP->_fifopeek = 0; + SP->_endwin = FALSE; + SP->_checkfd = fileno(ifp); + typeahead(fileno(ifp)); if (enter_ca_mode) putp(enter_ca_mode); @@ -108,8 +111,7 @@ char *use_it = _ncurses_copyright; curscr->_clear = FALSE; stolen = topstolen = 0; - for (rsp = rippedoff; rsp->line; rsp++) - { + for (rsp = rippedoff; rsp->line; rsp++) { if (rsp->hook) if (rsp->line < 0) rsp->hook(newwin(1,COLS, LINES-1,0), COLS); @@ -131,10 +133,14 @@ char *use_it = _ncurses_copyright; #if 0 sigaction(SIGSEGV, &act, NULL); #endif - if (stdscr == NULL) - if ((stdscr = newwin(lines - stolen, columns, topstolen, 0)) == NULL) - return(NULL); + if ((stdscr = newwin(lines - stolen, columns, topstolen, 0)) == NULL) + return(NULL); + SP->_stdscr = stdscr; + + def_shell_mode(); + def_prog_mode(); + T(("newterm returns %x", SP)); return(SP); diff --git a/lib/libncurses/lib_newwin.c b/lib/libncurses/lib_newwin.c index 84dab1663b78..a4db5f18f50a 100644 --- a/lib/libncurses/lib_newwin.c +++ b/lib/libncurses/lib_newwin.c @@ -11,7 +11,7 @@ */ #include -#include +#include "terminfo.h" #include "curses.priv.h" WINDOW * newwin(int num_lines, int num_columns, int begy, int begx) @@ -83,6 +83,8 @@ int i; win->_pary = begy; win->_parx = begx; + win->_attrs = orig->_attrs; + win->_bkgd = orig->_bkgd; for (i = 0; i < num_lines; i++) win->_line[i] = &orig->_line[begy++][begx]; @@ -142,6 +144,7 @@ WINDOW *win; win->_flags = 0; win->_attrs = A_NORMAL; + win->_bkgd = ' '; win->_clear = (num_lines == lines && num_columns == columns); win->_idlok = FALSE; diff --git a/lib/libncurses/lib_options.c b/lib/libncurses/lib_options.c index fa4cbf0d9814..e22bcb799516 100644 --- a/lib/libncurses/lib_options.c +++ b/lib/libncurses/lib_options.c @@ -11,15 +11,20 @@ */ #include -#include +#include "terminfo.h" #include "curses.priv.h" int idlok(WINDOW *win, int flag) { T(("idlok(%x,%d) called", win, flag)); - if (insert_line || delete_line || parm_insert_line || parm_delete_line) { - win->_idlok = flag; + if (flag == FALSE) { + win->_idlok = FALSE; + return OK; + } + + if ((insert_line || parm_insert_line) && (delete_line || parm_delete_line)) { + win->_idlok = TRUE; } return OK; } @@ -42,6 +47,10 @@ int leaveok(WINDOW *win, int flag) T(("leaveok(%x,%d) called", win, flag)); win->_leave = flag; + if (flag == TRUE) + curs_set(0); + else + curs_set(1); return OK; } @@ -102,9 +111,9 @@ int keypad(WINDOW *win, int flag) win->_use_keypad = flag; if (flag && keypad_xmit) - tputs(keypad_xmit, 1, _outc); + putp(keypad_xmit); else if (! flag && keypad_local) - tputs(keypad_local, 1, _outc); + putp(keypad_local); if (SP->_keytry == UNINITIALISED) init_keytry(); @@ -120,9 +129,9 @@ int meta(WINDOW *win, int flag) win->_use_meta = flag; if (flag && meta_on) - tputs(meta_on, 1, _outc); + putp(meta_on); else if (! flag && meta_off) - tputs(meta_off, 1, _outc); + putp(meta_off); return OK; } @@ -227,3 +236,17 @@ struct try *ptr, *savedptr; ptr->value = code; return; } + +int typeahead(int fd) +{ + + T(("typeahead(%d) called", fd)); + SP->_checkfd = fd; + return OK; +} + +int intrflush(WINDOW *win, bool flag) +{ + T(("intrflush(%x, %d) called", win, flag)); + return OK; +} diff --git a/lib/libncurses/lib_pad.c b/lib/libncurses/lib_pad.c index 75a639c84124..11a005480802 100644 --- a/lib/libncurses/lib_pad.c +++ b/lib/libncurses/lib_pad.c @@ -84,15 +84,16 @@ int m, n; return ERR; T(("three")); - if ((pminrow + smaxrow > win->_maxy) || (pmincol + smaxcol > win->_maxx)) + if ((pminrow + smaxrow - sminrow > win->_maxy) || + (pmincol + smaxcol - smincol > win->_maxx)) return ERR; T(("pad being refreshed")); - for (i = pminrow, m = sminrow; i <= smaxrow + pminrow; i++, m++) { - j = pmincol; - n = j + smincol; - for (; j <= pmincol + smaxcol; j++, n++) { + for (i = pminrow, m = sminrow; i <= pminrow + smaxrow-sminrow; + i++, m++) { + for (j = pmincol, n = smincol; j <= pmincol + smaxcol-smincol; + j++, n++) { if (win->_line[i][j] != newscr->_line[m][n]) { newscr->_line[m][n] = win->_line[i][j]; diff --git a/lib/libncurses/lib_printw.c b/lib/libncurses/lib_printw.c index f4609c3a552e..236c29a4beaa 100644 --- a/lib/libncurses/lib_printw.c +++ b/lib/libncurses/lib_printw.c @@ -17,10 +17,7 @@ int printw(char *fmt, ...) va_list argp; char buf[BUFSIZ]; -#ifdef TRACE - if (_tracing) - _tracef("printw(%s,...) called", fmt); -#endif + T(("printw(\"%s\",...) called", fmt)); va_start(argp, fmt); vsprintf(buf, fmt, argp); @@ -35,10 +32,7 @@ int wprintw(WINDOW *win, char *fmt, ...) va_list argp; char buf[BUFSIZ]; -#ifdef TRACE - if (_tracing) - _tracef("wprintw(%x,%s,...) called", win, fmt); -#endif + T(("wprintw(%x,\"%s\",...) called", win, fmt)); va_start(argp, fmt); vsprintf(buf, fmt, argp); diff --git a/lib/libncurses/lib_raw.c b/lib/libncurses/lib_raw.c index fb2b928f3bd5..5635caeedf76 100644 --- a/lib/libncurses/lib_raw.c +++ b/lib/libncurses/lib_raw.c @@ -19,7 +19,7 @@ */ #include "curses.priv.h" -#include +#include "terminfo.h" int raw() { diff --git a/lib/libncurses/lib_scanw.c b/lib/libncurses/lib_scanw.c index 68aeaeae3ffd..d9a6a3c9a6c6 100644 --- a/lib/libncurses/lib_scanw.c +++ b/lib/libncurses/lib_scanw.c @@ -10,6 +10,7 @@ ** */ +#include #include "curses.priv.h" int vwscanw(WINDOW *win, char *fmt, va_list argp) @@ -26,10 +27,7 @@ int scanw(char *fmt, ...) { va_list ap; -#ifdef TRACE - if (_tracing) - _tracef("scanw(%s,...) called", fmt); -#endif + T(("scanw(\"%s\",...) called", fmt)); va_start(ap, fmt); return(vwscanw(stdscr, fmt, ap)); @@ -39,10 +37,7 @@ int wscanw(WINDOW *win, char *fmt, ...) { va_list ap; -#ifdef TRACE - if (_tracing) - _tracef("wscanw(%x,%s,...) called", win, fmt); -#endif + T(("wscanw(%x,\"%s\",...) called", win, fmt)); va_start(ap, fmt); return(vwscanw(win, fmt, ap)); @@ -69,4 +64,3 @@ va_list ap; } - diff --git a/lib/libncurses/lib_scroll.c b/lib/libncurses/lib_scroll.c index 0f278171061d..d825c22162d5 100644 --- a/lib/libncurses/lib_scroll.c +++ b/lib/libncurses/lib_scroll.c @@ -14,43 +14,100 @@ #include #include "curses.priv.h" -#include +#include "terminfo.h" + +void scroll_window(WINDOW *win, int n, int regtop, int regbottom) +{ +int line, i; +chtype *ptr, *temp; +chtype **saved; +chtype blank = ' '; + + saved = (chtype **)malloc(sizeof(chtype *) * abs(n)); + + if (n < 0) { + /* save overwritten lines */ + + for (i = 0; i < -n; i++) + saved[i] = win->_line[regbottom-i]; + + /* shift n lines */ + + for (line = regbottom; line >= regtop-n; line--) + win->_line[line] = win->_line[line+n]; + + /* restore saved lines and blank them */ + + for (i = 0, line = regtop; line < regtop-n; line++, i++) { + win->_line[line] = saved[i]; + temp = win->_line[line]; + for (ptr = temp; ptr - temp <= win->_maxx; ptr++) + *ptr = blank; + } + } else { + /* save overwritten lines */ + + for (i = 0; i < n; i++) + saved[i] = win->_line[regtop+i]; + + /* shift n lines */ + + for (line = regtop; line <= regbottom-n; line++) + win->_line[line] = win->_line[line+n]; + + /* restore saved lines and blank them */ + + for (i = 0, line = regbottom; line > regbottom - n; line--, i++) { + win->_line[line] = saved[i]; + temp = win->_line[line]; + for (ptr = temp; ptr - temp <= win->_maxx; ptr++) + *ptr = blank; + } + } + + free(saved); +} int wscrl(WINDOW *win, int n) { -int line, i, touched = 0; -chtype *ptr, *temp; -chtype **saved, **newsaved = NULL, **cursaved = NULL; -chtype blank = ' '; +int physical = FALSE; +int i; T(("wscrl(%x,%d) called", win, n)); - if (! win->_scroll) + if (! win->_scroll) return ERR; if (n == 0) return OK; - /* test for scrolling region == entire screen */ - /* as an optimization, if the scrolling region is the entire screen scroll the physical screen */ /* should we extend this to include smaller scrolling ranges by using change_scroll_region? */ - if ( win->_begx == 0 && win->_maxx == columns - 1 - && !memory_above && !memory_below - && ((win->_regtop == 0 && win->_regbottom == lines - 1 - && ( (n < 0 && (parm_rindex || scroll_reverse)) - || (n > 0 && (parm_index || scroll_forward)) - ) - ) || (win->_idlok && (parm_insert_line || insert_line) - && (parm_delete_line || delete_line) - ) + if ( win->_begx == 0 && win->_maxx == columns - 1 + && !memory_above && !memory_below + && ((win->_regtop == 0 && win->_regbottom == lines - 1 + && ( (n < 0 && (parm_rindex || scroll_reverse)) + || (n > 0 && (parm_index || scroll_forward)) + ) + ) || (win->_idlok && (parm_insert_line || insert_line) + && (parm_delete_line || delete_line) + ) + ) ) - ) { + physical = TRUE; + + if (physical == TRUE) { wrefresh(win); + scroll_window(curscr, n, win->_begy+win->_regtop, win->_begy+win->_regbottom); + scroll_window(newscr, n, win->_begy+win->_regtop, win->_begy+win->_regbottom); + } + scroll_window(win, n, win->_regtop, win->_regbottom); + + if (physical == TRUE) { if (n < 0) { if ( win->_regtop == 0 && win->_regbottom == lines - 1 && (parm_rindex || scroll_reverse) @@ -118,107 +175,8 @@ chtype blank = ' '; } mvcur(-1, -1, win->_cury, win->_curx); - touched = 1; - } + } else + touchline(win, win->_regtop, win->_regbottom - win->_regtop + 1); - saved = (chtype **)malloc(sizeof(chtype *) * abs(n)); - if (touched) { - newsaved = (chtype **)malloc(sizeof(chtype *) * abs(n)); - cursaved = (chtype **)malloc(sizeof(chtype *) * abs(n)); - } - - if (n < 0) { - /* save overwritten lines */ - - for (i = 0; i < -n; i++) { - saved[i] = win->_line[win->_regbottom-i]; - if (touched) { - newsaved[i] = newscr->_line[win->_begy+win->_regbottom-i]; - cursaved[i] = curscr->_line[win->_begy+win->_regbottom-i]; - } - } - - /* shift n lines */ - - for (line = win->_regbottom; line >= win->_regtop - n; line--) { - win->_line[line] = win->_line[line+n]; - if (touched) { - newscr->_line[win->_begy+line] = newscr->_line[win->_begy+line+n]; - curscr->_line[win->_begy+line] = curscr->_line[win->_begy+line+n]; - } - } - - /* restore saved lines and blank them */ - - for (i = 0, line = win->_regtop; line < win->_regtop-n; line++, i++) { - win->_line[line] = saved[i]; - if (touched) { - newscr->_line[win->_begy+line] = newsaved[i]; - curscr->_line[win->_begy+line] = cursaved[i]; - } - temp = win->_line[line]; - for (ptr = temp; ptr - temp <= win->_maxx; ptr++) - *ptr = blank; - if (touched) { - temp = newscr->_line[win->_begy+line]; - for (ptr = temp; ptr - temp <= newscr->_maxx; ptr++) - *ptr = blank; - temp = curscr->_line[win->_begy+line]; - for (ptr = temp; ptr - temp <= curscr->_maxx; ptr++) - *ptr = blank; - } - } - } else { - /* save overwritten lines */ - - for (i = 0; i < n; i++) { - saved[i] = win->_line[win->_regtop+i]; - if (touched) { - newsaved[i] = newscr->_line[win->_begy+win->_regtop+i]; - cursaved[i] = curscr->_line[win->_begy+win->_regtop+i]; - } - } - - /* shift n lines */ - - for (line = win->_regtop; line <= win->_regbottom - n; line++) { - win->_line[line] = win->_line[line+n]; - if (touched) { - newscr->_line[win->_begy+line] = newscr->_line[win->_begy+line+n]; - curscr->_line[win->_begy+line] = curscr->_line[win->_begy+line+n]; - } - } - - /* restore saved lines and blank them */ - - for (i = 0, line = win->_regbottom; line > win->_regbottom - n; line--, i++) { - win->_line[line] = saved[i]; - if (touched) { - newscr->_line[win->_begy+line] = newsaved[i]; - curscr->_line[win->_begy+line] = cursaved[i]; - } - temp = win->_line[line]; - for (ptr = temp; ptr - temp <= win->_maxx; ptr++) - *ptr = blank; - if (touched) { - temp = newscr->_line[win->_begy+line]; - for (ptr = temp; ptr - temp <= newscr->_maxx; ptr++) - *ptr = blank; - temp = curscr->_line[win->_begy+line]; - for (ptr = temp; ptr - temp <= curscr->_maxx; ptr++) - *ptr = blank; - } - } - } - - free(saved); - if (touched) { - free(newsaved); - free(cursaved); - } - - if (!touched) - touchline(win, win->_regtop, win->_regbottom - win->_regtop + 1); - - return OK; + return OK; } diff --git a/lib/libncurses/lib_scrreg.c b/lib/libncurses/lib_scrreg.c index d8c142327ee3..b7d9ae2941b8 100644 --- a/lib/libncurses/lib_scrreg.c +++ b/lib/libncurses/lib_scrreg.c @@ -11,22 +11,26 @@ */ #include "curses.priv.h" +#include "terminfo.h" int wsetscrreg(WINDOW *win, int top, int bottom) { - T(("wsetscrreg(%x,%d,%d) called", win, top, bottom)); + T(("wsetscrreg(%x,%d,%d) called", win, top, bottom)); if (top >= 0 && top <= win->_maxy && bottom >= 0 && bottom <= win->_maxy && bottom > top) { - win->_regtop = top; - win->_regbottom = bottom; + win->_regtop = top; + win->_regbottom = bottom; T(("correctly set scrolling region between %d and %d", top, bottom)); + if (change_scroll_region != NULL) { + T(("changing scroll region")); + putp(tparm(change_scroll_region, top, bottom)); + } - return(OK); - } - else - return(ERR); + return(OK); + } else + return(ERR); } diff --git a/lib/libncurses/lib_set_term.c b/lib/libncurses/lib_set_term.c index 7f273a8f47d7..bc73ca335360 100644 --- a/lib/libncurses/lib_set_term.c +++ b/lib/libncurses/lib_set_term.c @@ -11,7 +11,7 @@ */ #include "curses.priv.h" -#include +#include "terminfo.h" struct screen * set_term(screen) @@ -19,10 +19,7 @@ struct screen *screen; { struct screen *oldSP; -#ifdef TRACE - if (_tracing) - _tracef("set_term(%o) called", screen); -#endif + T(("set_term(%o) called", screen)); oldSP = SP; SP = screen; @@ -30,6 +27,7 @@ struct screen *oldSP; cur_term = SP->_term; curscr = SP->_curscr; newscr = SP->_newscr; + stdscr = SP->_stdscr; return(oldSP); } diff --git a/lib/libncurses/lib_slk.c b/lib/libncurses/lib_slk.c index f220a374ae71..850556f171dd 100644 --- a/lib/libncurses/lib_slk.c +++ b/lib/libncurses/lib_slk.c @@ -8,7 +8,7 @@ * code under the terms of the GNU Copyleft. */ -#include +#include "terminfo.h" #include "curses.priv.h" #include #include @@ -26,10 +26,8 @@ char * slk_label(int n) { SLK *slk = SP->_slk; -#ifdef TRACE - if (_tracing) - _tracef("slk_label(%d)", n); -#endif + + T(("slk_label(%d)", n)); if (slk == NULL || n < 1 || n > 8) return NULL; @@ -44,10 +42,7 @@ static void slk_intern_refresh(SLK *slk) { int i; -#ifdef TRACE - if (_tracing) - _tracef("slk_intern_refresh(%x)", slk); -#endif + T(("slk_intern_refresh(%x)", slk)); for (i = 0; i < 8; i++) { if (slk->dirty || slk->ent[i].dirty) { @@ -71,10 +66,8 @@ int slk_noutrefresh(void) { SLK *slk = SP->_slk; -#ifdef TRACE - if (_tracing) - _tracef("slk_noutrefresh()"); -#endif + + T(("slk_noutrefresh()")); if (slk == NULL) return ERR; @@ -92,10 +85,8 @@ int slk_refresh(void) { SLK *slk = SP->_slk; -#ifdef TRACE - if (_tracing) - _tracef("slk_refresh()"); -#endif + + T(("slk_refresh()")); if (slk == NULL) return ERR; @@ -113,10 +104,8 @@ int slk_restore(void) { SLK *slk = SP->_slk; -#ifdef TRACE - if (_tracing) - _tracef("slk_restore()"); -#endif + + T(("slk_restore()")); if (slk == NULL) return ERR; @@ -134,10 +123,7 @@ slk_set(int i, char *str, int format) { SLK *slk = SP->_slk; int len; -#ifdef TRACE - if (_tracing) - _tracef("slk_set(%d, %s, %d)", i, str, format); -#endif + T(("slk_set(%d, \"%s\", %d)", i, str, format)); if (slk == NULL || i < 1 || i > 8 || format < 0 || format > 2) return ERR; @@ -172,10 +158,7 @@ int slk_touch(void) { SLK *slk = SP->_slk; -#ifdef TRACE - if (_tracing) - _tracef("slk_touch()"); -#endif + T(("slk_touch()")); if (slk == NULL) return ERR; @@ -191,10 +174,8 @@ int slk_clear(void) { SLK *slk = SP->_slk; -#ifdef TRACE - if (_tracing) - _tracef("slk_clear()"); -#endif + + T(("slk_clear()")); if (slk == NULL) return ERR; @@ -213,10 +194,8 @@ slk_initialize(WINDOW *stwin, int cols) { SLK *slk; int i, maxlab, x; -#ifdef TRACE - if (_tracing) - _tracef("slk_initialize()"); -#endif + + T(("slk_initialize()")); if ((SP->_slk = slk = (SLK*) calloc(1,sizeof(SLK))) == NULL) return OK; diff --git a/lib/libncurses/lib_trace.c b/lib/libncurses/lib_trace.c index c17f7dd9aaff..64743225ca7f 100644 --- a/lib/libncurses/lib_trace.c +++ b/lib/libncurses/lib_trace.c @@ -13,7 +13,7 @@ #include #include #include "curses.priv.h" -#include +#include "terminfo.h" #if defined(BRAINDEAD) extern int errno; @@ -43,19 +43,12 @@ static int been_here = 0; } -void traceon() +void trace(const unsigned int tracelevel) { - - _tracing = 1; + _tracing = tracelevel; } -void traceoff() -{ - - _tracing = 0; -} - char *_traceattr(int newmode) { static char buf[BUFSIZ]; @@ -98,8 +91,8 @@ colors[] = (void) sprintf(buf + strlen(buf), "COLOR_PAIR(%d) = (%s, %s), ", pairnum, - colors[BG(color_pairs[pairnum])].name, - colors[FG(color_pairs[pairnum])].name + colors[FG(color_pairs[pairnum])].name, + colors[BG(color_pairs[pairnum])].name ); } if ((newmode & A_ATTRIBUTES) == 0) @@ -109,7 +102,7 @@ colors[] = return(strcat(buf,"}")); } -static char *visbuf(const char *buf) +char *visbuf(const char *buf) /* visibilize a given string */ { static char vbuf[BUFSIZ]; @@ -154,17 +147,33 @@ static char *visbuf(const char *buf) return(vbuf); } +char *_tracechar(const unsigned char ch) +{ + static char crep[20]; + /* + * We can show the actual character if it's either an ordinary printable + * or one of the high-half characters. + */ + if (isprint(ch) || (ch & 0x80)) + { + crep[0] = '\''; + crep[1] = ch; /* necessary; printf tries too hard on metachars */ + (void) sprintf(crep + 2, "' = 0x%02x", ch); + } + else + (void) sprintf(crep, "0x%02x", ch); + return(crep); +} + void _tracef(char *fmt, ...) { va_list ap; char buffer[256]; -char *vp; va_start(ap, fmt); vsprintf(buffer, fmt, ap); - vp = visbuf(buffer); - write(tracefd, vp, strlen(vp)); + write(tracefd, buffer, strlen(buffer)); write(tracefd, "\n", 1); } diff --git a/lib/libncurses/lib_tstp.c b/lib/libncurses/lib_tstp.c index 691dcd3e7196..272c274dbc94 100644 --- a/lib/libncurses/lib_tstp.c +++ b/lib/libncurses/lib_tstp.c @@ -11,7 +11,7 @@ */ #include "curses.priv.h" -#include +#include "terminfo.h" #ifdef SVR4_ACTION #define _POSIX_SOURCE #endif @@ -41,7 +41,7 @@ sigset_t mask; reset_prog_mode(); flushinp(); if (enter_ca_mode) - tputs(enter_ca_mode, 1, _outc); + putp(enter_ca_mode); doupdate(); } diff --git a/lib/libncurses/lib_twait.c b/lib/libncurses/lib_twait.c index 01e7ffaa12ac..1b0fd1ea7563 100644 --- a/lib/libncurses/lib_twait.c +++ b/lib/libncurses/lib_twait.c @@ -1,6 +1,6 @@ -/* This work is copyrighted. See COPYRIGHT.OLD & COPYRIGHT.NEW for * -* details. If they are missing then this copy is in violation of * -* the copyright conditions. */ +/* This work is copyrighted. See COPYRIGHT.OLD & COPYRIGHT.NEW for * +* details. If they are missing then this copy is in violation of * +* the copyright conditions. */ /* ** lib_twait.c @@ -10,10 +10,26 @@ */ #include +#include /* some systems can't live without this */ #include #include +#if defined(SYS_SELECT) +#include +#endif #include "curses.priv.h" +#if defined(NOUSLEEP) +void usleep(unsigned int usec) +{ +struct timeval tval; + + tval.tv_sec = usec / 1000000; + tval.tv_usec = usec % 1000000; + select(0, NULL, NULL, NULL, &tval); + +} +#endif + int timed_wait(int fd, int wait, int *timeleft) { int result; @@ -22,38 +38,38 @@ static fd_set set; #ifndef GOOD_SELECT struct timeval starttime, returntime; - gettimeofday(&starttime, NULL); + gettimeofday(&starttime, NULL); #endif - FD_ZERO(&set); - FD_SET(fd, &set); + FD_ZERO(&set); + FD_SET(fd, &set); - /* the units of wait are milliseconds */ - timeout.tv_sec = wait / 1000; - timeout.tv_usec = (wait % 1000) * 1000; + /* the units of wait are milliseconds */ + timeout.tv_sec = wait / 1000; + timeout.tv_usec = (wait % 1000) * 1000; - T(("start twait: sec = %d, usec = %d", timeout.tv_sec, timeout.tv_usec)); + T(("start twait: sec = %d, usec = %d", timeout.tv_sec, timeout.tv_usec)); - result = select(fd+1, &set, NULL, NULL, &timeout); + result = select(fd+1, &set, NULL, NULL, &timeout); #ifndef GOOD_SELECT - gettimeofday(&returntime, NULL); - timeout.tv_sec -= (returntime.tv_sec - starttime.tv_sec); - timeout.tv_usec -= (returntime.tv_usec - starttime.tv_usec); - if (timeout.tv_usec < 0 && timeout.tv_sec > 0) { + gettimeofday(&returntime, NULL); + timeout.tv_sec -= (returntime.tv_sec - starttime.tv_sec); + timeout.tv_usec -= (returntime.tv_usec - starttime.tv_usec); + if (timeout.tv_usec < 0 && timeout.tv_sec > 0) { timeout.tv_sec--; timeout.tv_usec += 1000000; - } - if (timeout.tv_sec < 0) + } + if (timeout.tv_sec < 0) timeout.tv_sec = timeout.tv_usec = 0; #endif - /* return approximate time left on the timeout, in milliseconds */ - if (timeleft) + /* return approximate time left on the timeout, in milliseconds */ + if (timeleft) *timeleft = (timeout.tv_sec * 1000) + (timeout.tv_usec / 1000); - T(("end twait: returned %d, sec = %d, usec = %d (%d msec)", - result, timeout.tv_sec, timeout.tv_usec, *timeleft)); + T(("end twait: returned %d, sec = %d, usec = %d (%d msec)", + result, timeout.tv_sec, timeout.tv_usec, *timeleft)); - return(result); + return(result); } diff --git a/lib/libncurses/lib_unctrl.c b/lib/libncurses/lib_unctrl.c index 3c8f5831fb60..b0f10c2b4ef5 100644 --- a/lib/libncurses/lib_unctrl.c +++ b/lib/libncurses/lib_unctrl.c @@ -1,4 +1,6 @@ +#ifdef __FreeBSD__ #include +#endif #include char * @@ -6,7 +8,11 @@ char * { static char buffer[3] = "^x"; - if (isgraph(uch)) { +#ifdef __FreeBSD__ + if (isprint(uch)) { +#else + if ((uch & 0x60) != 0 && uch != 0x7F) { +#endif /* * Printable character. Simply return the character as a one-character * string. diff --git a/lib/libncurses/lib_vidattr.c b/lib/libncurses/lib_vidattr.c index e3efebb636f2..94cf31ee3aad 100644 --- a/lib/libncurses/lib_vidattr.c +++ b/lib/libncurses/lib_vidattr.c @@ -1,7 +1,21 @@ -/* This work is copyrighted. See COPYRIGHT.OLD & COPYRIGHT.NEW for * -* details. If they are missing then this copy is in violation of * -* the copyright conditions. */ +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992, 1993, 1994 * +* by Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, not removed * +* from header files, and is reproduced in any documentation * +* accompanying it or the applications linked with it. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ /* * vidputs(newmode, outc) @@ -28,11 +42,11 @@ #include #include "curses.priv.h" -#include +#include "terminfo.h" static void do_color(int pair, int (*outc)(char)) { -short fg, bg; +int fg, bg; if ( pair == 0 ) { tputs(orig_pair, 1, outc); @@ -53,84 +67,71 @@ short fg, bg; } } -static int current_pair = 0; -static chtype previous_attr = 0; +#define previous_attr SP->_current_attr int vidputs(chtype newmode, int (*outc)(char)) { -chtype turn_off, turn_on; +chtype turn_off = (~newmode & previous_attr) & ~A_COLOR; +chtype turn_on = (newmode & ~previous_attr) & ~A_COLOR; T(("vidputs(%x) called %s", newmode, _traceattr(newmode))); T(("previous attribute was %s", _traceattr(previous_attr))); + if (newmode == previous_attr) + return OK; if (newmode == A_NORMAL && exit_attribute_mode) { - if((previous_attr & A_ALTCHARSET) && exit_alt_charset_mode) - tputs(exit_alt_charset_mode, 1, outc); - tputs(exit_attribute_mode, 1, outc); - current_pair = -1; - goto set_color; - } - else if (set_attributes) { - tputs(tparm(set_attributes, - (newmode & A_STANDOUT) != 0, - (newmode & A_UNDERLINE) != 0, - (newmode & A_REVERSE) != 0, - (newmode & A_BLINK) != 0, - (newmode & A_DIM) != 0, - (newmode & A_BOLD) != 0, - (newmode & A_INVIS) != 0, - (newmode & A_PROTECT) != 0, - (newmode & A_ALTCHARSET) != 0), 1, outc); - goto set_color; - } else { - if (exit_attribute_mode) { - if((previous_attr & A_ALTCHARSET) && exit_alt_charset_mode) { - tputs(exit_alt_charset_mode, 1, outc); - previous_attr &= ~A_ALTCHARSET; - } - if (previous_attr) { - T(("exiting attribute mode")); - - tputs(exit_attribute_mode, 1, outc); - previous_attr = 0; - current_pair = -1; - } - } else { - turn_off = ~newmode & previous_attr; - - T(("turning %x off", turn_off)); - - if ((turn_off & A_ALTCHARSET) && exit_alt_charset_mode) - tputs(exit_alt_charset_mode, 1, outc); - - if ((turn_off & A_BOLD) && exit_standout_mode) - tputs(exit_standout_mode, 1, outc); - - if ((turn_off & A_DIM) && exit_standout_mode) - tputs(exit_standout_mode, 1, outc); - - if ((turn_off & A_BLINK) && exit_standout_mode) - tputs(exit_standout_mode, 1, outc); - - if ((turn_off & A_INVIS) && exit_standout_mode) - tputs(exit_standout_mode, 1, outc); - - if ((turn_off & A_PROTECT) && exit_standout_mode) - tputs(exit_standout_mode, 1, outc); - - if ((turn_off & A_UNDERLINE) && exit_underline_mode) - tputs(exit_underline_mode, 1, outc); - - if ((turn_off & A_REVERSE) && exit_standout_mode) - tputs(exit_standout_mode, 1, outc); - - if ((turn_off & A_STANDOUT) && exit_standout_mode) - tputs(exit_standout_mode, 1, outc); + if((previous_attr & A_ALTCHARSET) && exit_alt_charset_mode) { + tputs(exit_alt_charset_mode, 1, outc); + previous_attr &= ~A_ALTCHARSET; + } + if (previous_attr) + tputs(exit_attribute_mode, 1, outc); + + } else if (set_attributes) { + if (turn_on || turn_off) { + tputs(tparm(set_attributes, + (newmode & A_STANDOUT) != 0, + (newmode & A_UNDERLINE) != 0, + (newmode & A_REVERSE) != 0, + (newmode & A_BLINK) != 0, + (newmode & A_DIM) != 0, + (newmode & A_BOLD) != 0, + (newmode & A_INVIS) != 0, + (newmode & A_PROTECT) != 0, + (newmode & A_ALTCHARSET) != 0), 1, outc); } + } else { - turn_on = newmode & ~previous_attr; + T(("turning %x off", _traceattr(turn_off))); + + if ((turn_off & A_ALTCHARSET) && exit_alt_charset_mode) + tputs(exit_alt_charset_mode, 1, outc); - T(("turning %x on", turn_on)); + if ((turn_off & A_BOLD) && exit_standout_mode) + tputs(exit_standout_mode, 1, outc); + + if ((turn_off & A_DIM) && exit_standout_mode) + tputs(exit_standout_mode, 1, outc); + + if ((turn_off & A_BLINK) && exit_standout_mode) + tputs(exit_standout_mode, 1, outc); + + if ((turn_off & A_INVIS) && exit_standout_mode) + tputs(exit_standout_mode, 1, outc); + + if ((turn_off & A_PROTECT) && exit_standout_mode) + tputs(exit_standout_mode, 1, outc); + + if ((turn_off & A_UNDERLINE) && exit_underline_mode) + tputs(exit_underline_mode, 1, outc); + + if ((turn_off & A_REVERSE) && exit_standout_mode) + tputs(exit_standout_mode, 1, outc); + + if ((turn_off & A_STANDOUT) && exit_standout_mode) + tputs(exit_standout_mode, 1, outc); + + T(("turning %x on", _traceattr(turn_on))); if ((turn_on & A_ALTCHARSET) && enter_alt_charset_mode) tputs(enter_alt_charset_mode, 1, outc); @@ -158,18 +159,18 @@ chtype turn_off, turn_on; if ((turn_on & A_UNDERLINE) && enter_underline_mode) tputs(enter_underline_mode, 1, outc); - set_color: - if (_coloron) { - int pair = PAIR_NUMBER(newmode); - - T(("old pair = %d -- new pair = %d", current_pair, pair)); - if (pair != current_pair) { - current_pair = pair; - do_color(pair, outc); - } - } + } + if (SP->_coloron) { + int pair = PAIR_NUMBER(newmode); + int current_pair = PAIR_NUMBER(previous_attr); + + T(("old pair = %d -- new pair = %d", current_pair, pair)); + if (pair != current_pair || turn_off) { + do_color(pair, outc); + } + } previous_attr = newmode; @@ -182,6 +183,6 @@ int vidattr(chtype newmode) T(("vidattr(%x) called", newmode)); - return(vidputs(newmode, _outc)); + return(vidputs(newmode, _outch)); } diff --git a/lib/libncurses/lib_window.c b/lib/libncurses/lib_window.c index ec18694f7f94..c2686b982572 100644 --- a/lib/libncurses/lib_window.c +++ b/lib/libncurses/lib_window.c @@ -14,7 +14,7 @@ int mvder(WINDOW *win, int y, int x) { - + return(ERR); } void wsyncup(WINDOW *win) @@ -24,7 +24,7 @@ void wsyncup(WINDOW *win) int syncok(WINDOW *win, bool bf) { - + return(ERR); } void wcursyncup(WINDOW *win) @@ -40,12 +40,11 @@ void wsyncdown(WINDOW *win) WINDOW *dupwin(WINDOW *win) { WINDOW *nwin; -#ifdef TRACE - if (_tracing) - _tracef("dupwin(%x) called", win); -#endif +int linesize, i; - if ((nwin = newwin(win->_maxy, win->_maxx, win->_bey, win->_begx)) == NULL) + T(("dupwin(%x) called", win)); + + if ((nwin = newwin(win->_maxy + 1, win->_maxx + 1, win->_begy, win->_begx)) == NULL) return NULL; nwin->_curx = win->_curx; @@ -57,6 +56,7 @@ WINDOW *nwin; nwin->_flags = win->_flags; nwin->_attrs = win->_attrs; + nwin->_bkgd = win->_bkgd; nwin->_clear = win->_clear; nwin->_scroll = win->_scroll; @@ -73,8 +73,9 @@ WINDOW *nwin; nwin->_regtop = win->_regtop; nwin->_regbottom = win->_regbottom; - for (i = 0; i < nwin->_cury; i++) { - memcpy(nwin->_line[i], win->_line[i], win->_maxx * sizeof(chtype)); + linesize = (win->_maxx + 1) * sizeof(chtype); + for (i = 0; i <= nwin->_maxy; i++) { + memcpy(nwin->_line[i], win->_line[i], linesize); nwin->_firstchar[i] = win->_firstchar[i]; nwin->_lastchar[i] = win->_lastchar[i]; } diff --git a/lib/libncurses/ncurses.3 b/lib/libncurses/ncurses.3 index e8d74bb760df..8da84a0baa5b 100644 --- a/lib/libncurses/ncurses.3 +++ b/lib/libncurses/ncurses.3 @@ -1,6 +1,6 @@ .TH ncurses 3X "" .ds n 5 -.ds d /usr/lib/terminfo +.ds d @TERMINFO@ .SH NAME \fBncurses\fR - CRT screen handling and optimization package .SH SYNOPSIS diff --git a/lib/libncurses/termcap.h b/lib/libncurses/termcap.h index 9a5dd3293601..68fa7e54f2f1 100644 --- a/lib/libncurses/termcap.h +++ b/lib/libncurses/termcap.h @@ -1,14 +1,41 @@ #ifndef _TERMCAP_H #define _TERMCAP_H 1 +#ifdef __FreeBSD__ #include +#else +#ifndef __P +#if defined(__STDC__) || defined(__cplusplus) +#define __P(protos) protos +#else +#define __P(protos) () /* traditional C preprocessor */ +#endif +#endif +#ifndef __BEGIN_DECLS +#ifdef __cplusplus +#define __BEGIN_DECLS extern "C" { +#define __END_DECLS }; +#else +#define __BEGIN_DECLS +#define __END_DECLS +#endif +#endif +#endif __BEGIN_DECLS +#ifndef __FreeBSD__ +#include +#endif + extern char PC; extern char *UP; extern char *BC; +#ifdef __FreeBSD__ extern short ospeed; +#else +extern speed_t ospeed; +#endif extern int tgetent __P((char *, const char *)); extern int tgetflag __P((const char *)); diff --git a/lib/libncurses/terminfo.h b/lib/libncurses/terminfo.h new file mode 100644 index 000000000000..c238040b881c --- /dev/null +++ b/lib/libncurses/terminfo.h @@ -0,0 +1,2 @@ +/* fake header for sources compatibility */ +#include diff --git a/lib/libncurses/unctrl.h b/lib/libncurses/unctrl.h index c80689c06005..31205d313edc 100644 --- a/lib/libncurses/unctrl.h +++ b/lib/libncurses/unctrl.h @@ -14,8 +14,6 @@ #ifndef _UNCTRL_H #define _UNCTRL_H 1 -#include - -extern char *unctrl __P((unsigned char)); +extern char *unctrl(unsigned char); #endif /* _UNCTRL_H */ diff --git a/lib/libncurses/version.h b/lib/libncurses/version.h index 15ec8927b94f..45a8b469fadc 100644 --- a/lib/libncurses/version.h +++ b/lib/libncurses/version.h @@ -1,3 +1,3 @@ -#define NCURSES_VERSION "1.8.5" +#define NCURSES_VERSION "1.8.6" diff --git a/lib/ncurses/ncurses/Makefile b/lib/ncurses/ncurses/Makefile index 9ed3a674a24d..b17b8b9cec86 100644 --- a/lib/ncurses/ncurses/Makefile +++ b/lib/ncurses/ncurses/Makefile @@ -1,8 +1,8 @@ # Makefile for ncurses -# $Id: Makefile,v 1.6 1994/10/28 06:56:55 ache Exp $ +# $Id: Makefile,v 1.7 1994/11/29 02:48:17 ache Exp $ LIB= ncurses -SRCS= lib_kernel.c lib_pad.c\ +SRCS= lib_kernel.c lib_pad.c lib_bkgd.c \ lib_unctrl.c lib_raw.c lib_vidattr.c lib_trace.c lib_beep.c \ lib_doupdate.c lib_refresh.c lib_initscr.c lib_newwin.c lib_addch.c \ lib_addstr.c lib_scroll.c lib_clreol.c lib_touch.c lib_mvcur.c lib_keyname.c\ @@ -13,7 +13,7 @@ SRCS= lib_kernel.c lib_pad.c\ lib_newterm.c lib_set_term.c lib_overlay.c lib_scrreg.c lib_color.c \ lib_insstr.c lib_insdel.c lib_twait.c copyright.c -CFLAGS+= -I. -I${.CURDIR} -Wall -DMYTINFO -DTERMIOS -DGOOD_SELECT -DBSDTABS +CFLAGS+= -I. -I${.CURDIR} -Wall -DMYTINFO -DGOOD_SELECT LDADD+= -lmytinfo CLEANFILES+= lib_keyname.c keys.tries @@ -21,10 +21,13 @@ CLEANFILES+= lib_keyname.c keys.tries beforedepend: keys.tries beforeinstall: - @cd ${.CURDIR}; for i in ncurses.h unctrl.h termcap.h; do \ + @cd ${.CURDIR}; for i in unctrl.h termcap.h; do \ cmp -s $$i ${DESTDIR}/usr/include/$$i || \ $(INSTALL) $(COPY) -m 444 -o $(BINOWN) -g $(BINGRP) $$i \ ${DESTDIR}/usr/include; done + @cd ${.CURDIR}; cmp -s curses.h ${DESTDIR}/usr/include/ncurses.h || \ + $(INSTALL) $(COPY) -m 444 -o $(BINOWN) -g $(BINGRP) curses.h \ + ${DESTDIR}/usr/include/ncurses.h keys.tries: ${.CURDIR}/keys.list ${.CURDIR}/MKkeys.awk awk -f ${.CURDIR}/MKkeys.awk ${.CURDIR}/keys.list > keys.tries