summaryrefslogtreecommitdiffstats
path: root/lib/libncurses/TESTS
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libncurses/TESTS')
-rw-r--r--lib/libncurses/TESTS/Makefile37
-rw-r--r--lib/libncurses/TESTS/README22
-rw-r--r--lib/libncurses/TESTS/battle.c705
-rw-r--r--lib/libncurses/TESTS/bs.642
-rw-r--r--lib/libncurses/TESTS/bs.c1119
-rw-r--r--lib/libncurses/TESTS/copy.c39
-rw-r--r--lib/libncurses/TESTS/corner.c16
-rw-r--r--lib/libncurses/TESTS/ensor.c52
-rw-r--r--lib/libncurses/TESTS/firework.c113
-rw-r--r--lib/libncurses/TESTS/gdc.622
-rw-r--r--lib/libncurses/TESTS/gdc.c174
-rw-r--r--lib/libncurses/TESTS/getch.c29
-rw-r--r--lib/libncurses/TESTS/hanoi.c267
-rw-r--r--lib/libncurses/TESTS/knight.c322
-rw-r--r--lib/libncurses/TESTS/ncurses.c1038
-rw-r--r--lib/libncurses/TESTS/newdemo.c350
-rw-r--r--lib/libncurses/TESTS/over.c120
-rw-r--r--lib/libncurses/TESTS/rain.c96
-rw-r--r--lib/libncurses/TESTS/scroll.c30
-rw-r--r--lib/libncurses/TESTS/scroll2.c91
-rw-r--r--lib/libncurses/TESTS/scroll3.c51
-rw-r--r--lib/libncurses/TESTS/test.c27
-rw-r--r--lib/libncurses/TESTS/testcurs.c532
-rw-r--r--lib/libncurses/TESTS/worm.c268
-rw-r--r--lib/libncurses/TESTS/xmas.c1192
25 files changed, 6754 insertions, 0 deletions
diff --git a/lib/libncurses/TESTS/Makefile b/lib/libncurses/TESTS/Makefile
new file mode 100644
index 0000000..9b258df
--- /dev/null
+++ b/lib/libncurses/TESTS/Makefile
@@ -0,0 +1,37 @@
+TESTS = test corner ensor getch ncurses bs gdc hanoi knight rain worm \
+ over scroll2 battle newdemo scroll3 xmas copy firework testcurs \
+ scroll
+
+CLEANFILES += $(TESTS)
+
+LIBS += -lncurses -lmytinfo
+
+all: $(TESTS)
+
+$(TESTS):
+ $(CC) $(CFLAGS) $(LDFLAGS) ${.CURDIR}/$@.c -o $@ $(LIBS)
+
+test: test.c
+corner: corner.c
+ensor: ensor.c
+getch: getch.c
+ncurses: ncurses.c
+bs: bs.c
+gdc: gdc.c
+hanoi: hanoi.c
+knight: knight.c
+rain: rain.c
+worm: worm.c
+over: over.c
+scroll2: scroll2.c
+battle: battle.c
+newdemo: newdemo.c
+scroll3: scroll3.c
+xmas: xmas.c
+copy: copy.c
+firework: firework.c
+testcurs: testcurs.c
+scroll: scroll.c
+
+.include "bsd.prog.mk"
+
diff --git a/lib/libncurses/TESTS/README b/lib/libncurses/TESTS/README
new file mode 100644
index 0000000..7f45243
--- /dev/null
+++ b/lib/libncurses/TESTS/README
@@ -0,0 +1,22 @@
+The programs in this directory are designed to test your newest toy :-)
+Check the sources for any further details.
+
+asc.c - tests the line drawing functions
+attr.c - display attributes available on the terminal
+bs.c - the game of battleship
+battle.c - older version of battleship with different interface
+caps.c - output a list of all capabilites to stderr (redirect to a file
+ or it will screw up the terminal)
+copy.c - test overlay
+gdc.c - Great Digital Clock, gives an example of usng color
+getch.c - tests ketpad() and getch()
+hanoi.c - the game of hanoi, also an example of using color
+knight.c - the game of Knight's Tour
+rain.c - rain drops are falling on my head..
+scroll.c - test scrolling region
+slk.c - test soft labels
+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/battle.c b/lib/libncurses/TESTS/battle.c
new file mode 100644
index 0000000..e7785fc
--- /dev/null
+++ b/lib/libncurses/TESTS/battle.c
@@ -0,0 +1,705 @@
+/*
+ * battle.c - original author: Bruce Holloway
+ * mods by: Chuck A DeGaul
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <time.h>
+#include <signal.h>
+#include <ncurses.h>
+
+#define OTHER 1-turn
+
+char numbers[] = " 0 1 2 3 4 5 6 7 8 9";
+
+char carrier[] = "Aircraft Carrier";
+char battle[] = "Battleship";
+char sub[] = "Submarine";
+char destroy[] = "Destroyer";
+char ptboat[] = "PT Boat";
+
+char name[40];
+char dftname[] = "Stranger";
+
+struct _ships {
+ char *name;
+ char symbol;
+ char length;
+ char start; /* Coordinates - 0,0=0; 10,10=100. */
+ char dir; /* Direction - 0 = right; 1 = down. */
+ char hits; /* How many times has this ship been hit? (-1==sunk) */
+};
+
+struct _ships plyship[] = {
+ { carrier,'A',5,0,0,0 },
+ { battle,'B',4,0,0,0 },
+ { destroy,'D',3,0,0,0 },
+ { sub,'S',3,0,0,0 },
+ { ptboat,'P',2,0,0,0 },
+};
+
+struct _ships cpuship[] = {
+ { carrier,'A',5,0,0,0 },
+ { battle,'B',4,0,0,0 },
+ { destroy,'D',3,0,0,0 },
+ { sub,'S',3,0,0,0 },
+ { ptboat,'P',2,0,0,0 },
+};
+
+char hits[2][100], board[2][100]; /* "Hits" board, and main board. */
+
+int srchstep;
+int cpuhits;
+int cstart, cdir;
+int plywon=0, cpuwon=0; /* How many games has each won? */
+int turn; /* 0=player, 1=computer */
+int huntoffs; /* Offset on search strategy */
+
+int salvo, blitz, ask, seemiss; /* options */
+
+void intro(void);
+void initgame(void);
+int rnd(int);
+void plyplace(struct _ships *);
+int getdir(void);
+void placeship(struct _ships *, int, int);
+int checkplace(struct _ships *, int, int);
+void error(char *);
+void prompt(void);
+char getcoord(void);
+void cpuplace(struct _ships *);
+int awinna(void);
+int plyturn(void);
+int hitship(int);
+int cputurn(void);
+int playagain(void);
+void uninitgame();
+int sgetc(char *);
+int do_options(int, char *[]);
+int scount(int);
+
+int
+main(int argc, char **argv)
+{
+ do_options(argc, 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())
+ if (awinna() != -1)
+ i = 0;
+ else
+ if(plyturn())
+ if (awinna() != -1)
+ i = 0;
+ }
+ }
+ } else {
+ while((turn) ? cputurn() : plyturn());
+ }
+ turn = OTHER;
+ }
+ } while(playagain());
+ uninitgame();
+ exit(0);
+}
+
+#define PR addstr
+
+void
+intro()
+{
+char *tmpname;
+
+ srand(time(0L)); /* Kick the random number generator */
+
+ signal(SIGINT,uninitgame);
+ if(signal(SIGQUIT,SIG_IGN) != SIG_IGN) signal(SIGQUIT,uninitgame);
+#if 1
+ /* for some bizzare reason, getlogin or cuserid cause havoc with the terminal */
+ if ((tmpname = getlogin()) != NULL) {
+ strcpy(name, tmpname);
+ } else
+#endif
+ strcpy(name,dftname);
+ name[0] = toupper(name[0]);
+
+ initscr();
+ savetty();
+ nonl();
+ cbreak();
+ noecho();
+ clear();
+ mvaddstr(4,29,"Welcome to Battleship!");
+ move(8,0);
+PR(" \\\n");
+PR(" \\ \\ \\\n");
+PR(" \\ \\ \\ \\ \\_____________\n");
+PR(" \\ \\ \\_____________ \\ \\/ |\n");
+PR(" \\ \\/ \\ \\/ |\n");
+PR(" \\/ \\_____/ |__\n");
+PR(" ________________/ |\n");
+PR(" \\ S.S. Penguin |\n");
+PR(" \\ /\n");
+PR(" \\___________________________________________________/\n");
+ mvaddstr(20,27,"Hit any key to continue..."); refresh();
+ getch();
+}
+
+void
+initgame()
+{
+int i;
+
+ clear();
+ mvaddstr(0,35,"BATTLESHIP");
+ mvaddstr(4,12,"Main Board");
+ mvaddstr(6,0,numbers);
+ move(7,0);
+ for(i=0; i<10; ++i){
+ printw("%c . . . . . . . . . . %c\n",i+'A',i+'A');
+ }
+ mvaddstr(17,0,numbers);
+ mvaddstr(4,55,"Hit/Miss Board");
+ mvaddstr(6,45,numbers);
+ for(i=0; i<10; ++i){
+ mvprintw(7+i,45,"%c . . . . . . . . . . %c",i+'A',i+'A');
+ }
+ mvaddstr(17,45,numbers);
+ for(turn=0; turn<2; ++turn)
+ for(i=0; i<100; ++i){
+ hits[turn][i] = board[turn][i] = 0;
+ }
+ for(turn=0; turn<2; ++turn){
+ for(i=0; i<5; ++i)
+ if (!turn)
+ plyplace(&plyship[i]);
+ else
+ cpuplace(&cpuship[i]);
+ }
+ turn = rnd(2);
+ cstart = cdir = -1;
+ cpuhits = 0;
+ srchstep = 3;
+ huntoffs = rnd(srchstep);
+}
+
+int
+rnd(int n)
+{
+ return(((rand() & 0x7FFF) % n));
+}
+
+void
+plyplace(ss)
+struct _ships *ss;
+{
+int c, d;
+
+ do {
+ prompt();
+ printw("Place your %s (ex.%c%d) ? ",ss->name,rnd(10)+'A',rnd(10));
+ c = getcoord();
+ d = getdir();
+ } while(!checkplace(ss,c,d));
+ placeship(ss,c,d);
+}
+
+int
+getdir()
+{
+
+ prompt();
+ addstr("What direction (0=right, 1=down) ? ");
+ return(sgetc("01")-'0');
+}
+
+void
+placeship(ss,c,d)
+struct _ships *ss;
+int c, d;
+{
+int x, y, l, i;
+
+ for(l=0; l<ss->length; ++l){
+ i = c + l * ((d) ? 10 : 1);
+ board[turn][i] = ss->symbol;
+ x = (i % 10) * 3 + 3;
+ y = (i / 10) + 7;
+ if(!turn) mvaddch(y,x,ss->symbol);
+ }
+ ss->start = c;
+ ss->dir = d;
+ ss->hits = 0;
+}
+
+int
+checkplace(ss,c,d)
+struct _ships *ss;
+int c, d;
+{
+int x, y, l;
+
+ x = c%10; y = c/10;
+ if(((x+ss->length) > 10 && !d) || ((y+ss->length) > 10 && d==1)){
+ if(!turn)
+ switch(rnd(3)){
+ case 0:
+ error("Ship is hanging from the edge of the world");
+ break;
+ case 1:
+ error("Try fitting it on the board");
+ break;
+ case 2:
+ error("Figure I won't find it if you put it there?");
+ break;
+ }
+ return(0);
+ }
+ for(l=0; l<ss->length; ++l){
+ x = c + l * ((d) ? 10 : 1);
+ if(board[turn][x]){
+ if(!turn)
+ switch(rnd(3)){
+ case 0:
+ error("There's already a ship there");
+ break;
+ case 1:
+ error("Collision alert! Aaaaaagh!");
+ break;
+ case 2:
+ error("Er, Admiral, what about the other ship?");
+ break;
+ }
+ return(0);
+ }
+ }
+ return(1);
+}
+
+void
+error(s)
+char *s;
+{
+ prompt();
+ beep();
+ printw("%s -- hit any key to continue --",s);
+ refresh();
+ getch();
+}
+
+void
+prompt(){
+ move(22,0);
+ clrtoeol();
+}
+
+char
+getcoord()
+{
+int ch, x, y;
+
+redo:
+ y = sgetc("ABCDEFGHIJ");
+ do {
+ ch = getch();
+ if (ch == 0x7F || ch == 8) {
+ addstr("\b \b");
+ refresh();
+ goto redo;
+ }
+ } while(ch < '0' || ch > '9');
+ addch(x = ch);
+ refresh();
+ return((y-'A')*10+x-'0');
+}
+
+void
+cpuplace(ss)
+struct _ships *ss;
+{
+int c, d;
+
+ do{
+ c = rnd(100);
+ d = rnd(2);
+ } while(!checkplace(ss,c,d));
+ placeship(ss,c,d);
+}
+
+int
+awinna()
+{
+int i, j;
+struct _ships *ss;
+
+ for (i = 0; i < 2; ++i) {
+ ss = (i) ? cpuship : plyship;
+ for(j=0; j<5; ++j, ++ss)
+ if(ss->length != ss->hits)
+ break;
+ if(j == 5) return(OTHER);
+ }
+ return(-1);
+}
+
+int
+plyturn()
+{
+int c, res;
+char *m;
+
+ prompt();
+ addstr("Where do you want to shoot? ");
+ c = getcoord();
+ if(!(res = hits[turn][c])){
+ hits[turn][c] = res = (board[OTHER][c]) ? 'H' : 'M';
+ mvaddch(7+c/10,48+3*(c%10),(res=='H') ? 'H' : 'o');
+ if(c = hitship(c)){
+ prompt();
+ switch(rnd(3)){
+ case 0:
+ m = "You sank my %s!";
+ break;
+ case 1:
+ m = "I have this sinking feeling about my %s....";
+ break;
+ case 2:
+ m = "Have some mercy for my %s!";
+ break;
+ }
+ move(23,0);
+ clrtoeol();
+ beep();
+ printw(m,cpuship[c-1].name); refresh();
+ return(awinna() == -1);
+ }
+ }
+ prompt();
+ move(23,0); clrtoeol();
+ printw("You %s.",(res=='M')?"missed":"scored a hit"); refresh();
+ return(res == 'H');
+}
+
+int
+hitship(c)
+int c;
+{
+struct _ships *ss;
+int sym, i, j;
+
+ ss = (turn) ? plyship : cpuship;
+ if (!(sym = board[OTHER][c])) return(0);
+ for (i = 0; i < 5; ++i, ++ss)
+ if (ss->symbol == sym) {
+ j = ss->hits;
+ ++j;
+ ss->hits = j;
+ if (j == ss->length)
+ return(i+1);
+ return(0);
+ }
+}
+
+int
+cputurn()
+{
+int c, res, x, y, i, d;
+
+redo:
+ if (cstart == -1){
+ if (cpuhits){
+ for(i=0, c=rnd(100); i<100; ++i, c = (c+1) % 100)
+ if(hits[turn][c] == 'H')
+ break;
+ if(i != 100){
+ cstart = c;
+ cdir = -1;
+ goto fndir;
+ }
+ }
+ do {
+ i = 0;
+ do{
+ while(hits[turn][c=rnd(100)]);
+ x = c % 10; y = c / 10;
+ if(++i == 1000) break;
+ } while(((x+huntoffs) % srchstep) != (y % srchstep));
+ if(i == 1000) --srchstep;
+ } while(i == 1000);
+ }
+ else if(cdir == -1){
+fndir: for(i=0, d=rnd(4); i++ < 4; d = (d+1) % 4){
+ x = cstart%10; y = cstart/10;
+ switch(d){
+ case 0: ++x; break;
+ case 1: ++y; break;
+ case 2: --x; break;
+ case 3: --y; break;
+ }
+ if(x<0 || x>9 || y<0 || y>9) continue;
+ if(hits[turn][c=y*10+x]) continue;
+ cdir = -2;
+ break;
+ }
+ if(i == 4){
+ cstart = -1;
+ goto redo;
+ }
+ }
+ else{
+ x = cstart%10; y = cstart/10;
+ switch(cdir){
+ case 0: ++x; break;
+ case 1: ++y; break;
+ case 2: --x; break;
+ case 3: --y; break;
+ }
+ if(x<0 || x>9 || y<0 || y>9 || hits[turn][y*10+x]){
+ cdir = (cdir+2) % 4;
+ for(;;){
+ switch(cdir){
+ case 0: ++x; break;
+ case 1: ++y; break;
+ case 2: --x; break;
+ case 3: --y; break;
+ }
+ if(x<0 || x>9 || y<0 || y>9){ cstart = -1;
+ goto redo;
+ }
+ if(!hits[turn][y*10+x]) break;
+ }
+ }
+ c = y*10 + x;
+ }
+
+ if (!ask) {
+ res = (board[OTHER][c]) ? 'H' : 'M';
+ move(21,0); clrtoeol();
+ printw("I shoot at %c%d. I %s!",c/10+'A',c%10,(res=='H')?"hit":"miss");
+ } else {
+ for(;;){
+ prompt();
+ printw("I shoot at %c%d. Do I (H)it or (M)iss? ",c/10+'A',c%10);
+ res = sgetc("HM");
+ if((res=='H' && !board[OTHER][c]) || (res=='M' && board[OTHER][c])){
+ error("You lie!");
+ continue;
+ }
+ break;
+ }
+ addch(res);
+ }
+ hits[turn][c] = res;
+ if(res == 'H') {
+ ++cpuhits;
+ if(cstart == -1) cdir = -1;
+ cstart = c;
+ if(cdir == -2) cdir = d;
+ mvaddch(7+(c/10),3+3*(c%10),'*');
+ if (blitz && !ask) {
+ refresh();
+ sleep(1);
+ }
+ }
+ else {
+ if (seemiss) {
+ mvaddch(7+(c/10),3+3*(c%10),' ');
+ } else {
+ if(cdir == -2) cdir = -1;
+ }
+ }
+ if(c=hitship(c)){
+ cstart = -1;
+ cpuhits -= plyship[c-1].length;
+ x = plyship[c-1].start;
+ d = plyship[c-1].dir;
+ y = plyship[c-1].length;
+ for(i=0; i<y; ++i){
+ hits[turn][x] = '*';
+ x += (d) ? 10 : 1;
+ }
+ }
+ if (salvo && !ask) {
+ refresh();
+ sleep(1);
+ }
+ if(awinna() != -1) return(0);
+ return(res == 'H');
+}
+
+int
+playagain()
+{
+int i, x, y, dx, dy, j;
+
+ for(i=0; i<5; ++i){
+ x = cpuship[i].start; y = x/10+7; x = (x % 10) * 3 + 48;
+ dx = (cpuship[i].dir) ? 0 : 3;
+ dy = (cpuship[i].dir) ? 1 : 0;
+ for(j=0; j < cpuship[i].length; ++j){
+ mvaddch(y,x,cpuship[i].symbol);
+ x += dx; y += dy;
+ }
+ }
+
+ if(awinna()) ++cpuwon; else ++plywon;
+ i = 18 + strlen(name);
+ if(plywon >= 10) ++i;
+ if(cpuwon >= 10) ++i;
+ mvprintw(2,(80-i)/2,"%s: %d Computer: %d",name,plywon,cpuwon);
+
+ prompt();
+ printw((awinna()) ? "Want to be humiliated again, %s? "
+ : "Going to give me a chance for revenge, %s? ",name);
+ return(sgetc("YN") == 'Y');
+}
+
+void
+uninitgame(int sig)
+{
+ refresh();
+ endwin();
+ exit(0);
+}
+
+int
+sgetc(s)
+char *s;
+{
+char *s1;
+int ch;
+
+ refresh();
+ for (;;) {
+ ch = toupper(getch());
+ for (s1 = s; *s1 && ch != *s1; ++s1);
+ if (*s1) {
+ addch(ch);
+ refresh();
+ return(ch);
+ }
+ }
+}
+
+/*
+ * I should use getopts() from libc.a, but I'm leary that other UNIX
+ * systems might not have it, although I'd love to use it.
+ */
+
+int
+do_options(c,op)
+int c;
+char *op[];
+{
+register int i;
+
+ if (c > 1) {
+ for (i=1; i<c; i++) {
+ switch(op[i][0]) {
+ default:
+ case '?':
+ fprintf(stderr, "Usage: battle [ -s | -b ] [ -a ] [ -m ]\n");
+ fprintf(stderr, "\tWhere the options are:\n");
+ fprintf(stderr, "\t-s : play a salvo game (mutex with -b)\n");
+ fprintf(stderr, "\t-b : play a blitz game (mutex with -s)\n");
+ fprintf(stderr, "\t-a : computer asks you for hit/miss\n");
+ fprintf(stderr, "\t-m : computer misses are displayed\n");
+ exit(1);
+ break;
+ case '-':
+ switch(op[i][1]) {
+ case 'b':
+ blitz = 1;
+ if (salvo == 1) {
+ fprintf(stderr,
+ "Bad Arg: -b and -s are mutually exclusive\n");
+ exit(1);
+ }
+ break;
+ case 's':
+ salvo = 1;
+ if (blitz == 1) {
+ fprintf(stderr,
+ "Bad Arg: -s and -b are mutually exclusive\n");
+ exit(1);
+ }
+ break;
+ case 'a':
+ ask = 1;
+ break;
+ case 'm':
+ seemiss = 1;
+ break;
+ default:
+ fprintf(stderr,
+ "Bad Arg: type \"%s ?\" for usage message\n", op[0]);
+ exit(1);
+ }
+ }
+ }
+ fprintf(stdout, "Playing optional game (");
+ if (salvo)
+ fprintf(stdout, "salvo, noblitz, ");
+ else if (blitz)
+ fprintf(stdout, "blitz, nosalvo, ");
+ else
+ fprintf(stdout, "noblitz, nosalvo, ");
+
+ if (ask)
+ fprintf(stdout, "ask, ");
+ else
+ fprintf(stdout, "noask, ");
+
+ if (seemiss)
+ fprintf(stdout, "seemiss)\n");
+ else
+ fprintf(stdout, "noseemiss)\n");
+ }
+ else
+ fprintf(stdout,
+ "Playing standard game (no blitz, no slavo, no ask, no seemiss)\n");
+ sleep(2);
+ return(0);
+}
+
+int
+scount(who)
+int who;
+{
+int i, shots;
+struct _ships *sp;
+
+ if (who) {
+ /* count cpu shots */
+ sp = cpuship;
+ } else {
+ /* count player shots */
+ sp = plyship;
+ }
+ for (i=0, shots = 0; i<5; i++, sp++) {
+ /* extra test for machines with unsigned chars! */
+ if (sp->hits == (char) -1 || sp->hits >= sp->length) {
+ continue; /* dead ship */
+ } else {
+ shots++;
+ }
+ }
+ return(shots);
+}
+
diff --git a/lib/libncurses/TESTS/bs.6 b/lib/libncurses/TESTS/bs.6
new file mode 100644
index 0000000..38cfe82
--- /dev/null
+++ b/lib/libncurses/TESTS/bs.6
@@ -0,0 +1,42 @@
+.TH BATTLESHIPS 6 "Aug 23, 1989"
+.SH NAME
+bs \- battleships game
+.SH SYNOPSIS
+battle [ -b | -s ] [ -c ]
+.SH DESCRIPTION
+This program allows you to play the familiar Battleships game against the
+computer on a 10x10 board. The interface is visual and largely
+self-explanatory; you place your ships and pick your shots by moving the
+cursor around the `sea' with the rogue/hack motion keys hjklyubn.
+.PP
+Note that when selecting a ship to place, you must type the capital letter
+(these are, after all, capital ships). During ship placement, the `r' command
+may be used to ignore the current position and randomly place your currently
+selected ship. The `R' command will place all remaining ships randomly. The ^L
+command (form feed, ASCII 12) will force a screen redraw).
+.PP
+The command-line arguments control game modes.
+
+.nf
+ -b selects a `blitz' variant
+ -s selects a `salvo' variant
+ -c permits ships to be placed adjacently
+.fi
+
+The `blitz' variant allows a side to shoot for as long as it continues to
+score hits.
+.PP
+The `salvo' game allows a player one shot per turn for each of his/her ships
+still afloat. This puts a premium scoring hits early and knocking out some
+ships and also makes much harder the situation where you face a superior force
+with only your PT-boat.
+.PP
+Normally, ships must be separated by at least one square of open water. The
+-c option disables this check and allows them to close-pack.
+.PP
+The algorithm the computer uses once it has found a ship to sink is provably
+optimal. The dispersion criterion for the random-fire algorithm may not be.
+.SH AUTHORS
+Originally written by one Bruce Holloway in 1986. Salvo mode added by Chuck A.
+DeGaul (cbosgd!cad). Visual user interface, `closepack' option, code rewrite
+and manual page by Eric S. Raymond <esr@snark.thyrsus.com> August 1989.
diff --git a/lib/libncurses/TESTS/bs.c b/lib/libncurses/TESTS/bs.c
new file mode 100644
index 0000000..8d41830
--- /dev/null
+++ b/lib/libncurses/TESTS/bs.c
@@ -0,0 +1,1119 @@
+/*
+ * bs.c - original author: Bruce Holloway
+ * salvo option by: Chuck A DeGaul
+ * with improved user interface, autoconfiguration and code cleanup
+ * by Eric S. Raymond <esr@snark.thyrsus.com>
+ * v1.2 with color support and minor portability fixes, November 1990
+ */
+
+#include <stdio.h>
+#include <ncurses.h>
+#include <stdlib.h>
+#ifndef NONPOSIX
+#include <unistd.h>
+#endif
+#include <signal.h>
+#include <string.h>
+#include <sys/time.h>
+#include <ctype.h>
+#include <assert.h>
+
+#ifdef SYSV /* 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)
+extern char *memset();
+#endif /* SYSV */
+
+
+/*
+ * Constants for tuning the random-fire algorithm. It prefers moves that
+ * diagonal-stripe the board with a stripe separation of srchstep. If
+ * no such preferred moves are found, srchstep is decremented.
+ */
+#define BEGINSTEP 3 /* initial value of srchstep */
+
+/* miscellaneous constants */
+#define SHIPTYPES 5
+#define OTHER (1-turn)
+#define PLAYER 0
+#define COMPUTER 1
+#define MARK_HIT 'H'
+#define MARK_MISS 'o'
+#define CTRLC '\003' /* used as terminate command */
+#define FF '\014' /* used as redraw command */
+
+/* coordinate handling */
+#define BWIDTH 10
+#define BDEPTH 10
+
+/* display symbols */
+#define SHOWHIT '*'
+#define SHOWSPLASH ' '
+#define IS_SHIP(c) isupper(c)
+
+/* how to position us on player board */
+#define PYBASE 3
+#define PXBASE 3
+#define PY(y) (PYBASE + (y))
+#define PX(x) (PXBASE + (x)*3)
+#define pgoto(y, x) 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 ONBOARD(x, y) (x >= 0 && x < BWIDTH && y >= 0 && y < BDEPTH)
+
+/* other board locations */
+#define COLWIDTH 80
+#define PROMPTLINE 21 /* prompt line */
+#define SYBASE CYBASE + BDEPTH + 3 /* move key diagram */
+#define SXBASE 63
+#define MYBASE SYBASE - 1 /* diagram caption */
+#define MXBASE 64
+#define HYBASE SYBASE - 1 /* help area */
+#define HXBASE 0
+
+/* this will need to be changed if BWIDTH changes */
+static char numbers[] = " 0 1 2 3 4 5 6 7 8 9";
+
+static char carrier[] = "Aircraft Carrier";
+static char battle[] = "Battleship";
+static char sub[] = "Submarine";
+static char destroy[] = "Destroyer";
+static char ptboat[] = "PT Boat";
+
+static char name[40];
+static char dftname[] = "Stranger";
+
+/* direction constants */
+#define E 0
+#define SE 1
+#define S 2
+#define SW 3
+#define W 4
+#define NW 5
+#define N 6
+#define NE 7
+static int xincr[8] = {1, 1, 0, -1, -1, -1, 0, 1};
+static int yincr[8] = {0, 1, 1, 1, 0, -1, -1, -1};
+
+/* current ship position and direction */
+static int curx = (BWIDTH / 2);
+static int cury = (BDEPTH / 2);
+
+typedef struct
+{
+ char *name; /* name of the ship type */
+ unsigned hits; /* how many times has this ship been hit? */
+ char symbol; /* symbol for game purposes */
+ char length; /* length of ship */
+ char x, y; /* coordinates of ship start point */
+ int dir; /* direction of `bow' */
+ bool placed; /* has it been placed on the board? */
+}
+ship_t;
+
+ship_t plyship[SHIPTYPES] =
+{
+ { carrier, 0, 'A', 5},
+ { battle, 0, 'B', 4},
+ { destroy, 0, 'D', 3},
+ { sub, 0, 'S', 3},
+ { ptboat, 0, 'P', 2},
+};
+
+ship_t cpuship[SHIPTYPES] =
+{
+ { carrier, 0, 'A', 5},
+ { battle, 0, 'B', 4},
+ { destroy, 0, 'D', 3},
+ { sub, 0, 'S', 3},
+ { ptboat, 0, 'P', 2},
+};
+
+/* "Hits" board, and main board. */
+static char hits[2][BWIDTH][BDEPTH], board[2][BWIDTH][BDEPTH];
+
+static int turn; /* 0=player, 1=computer */
+static int plywon=0, cpuwon=0; /* How many games has each won? */
+
+static int salvo, blitz, closepack;
+
+#define PR addstr
+
+static int rnd(int);
+static int checkplace(int, ship_t *, int);
+static int getcoord(int);
+
+static void uninitgame()
+/* end the game, either normally or due to signal */
+{
+ clear();
+ refresh();
+ resetterm();
+ echo();
+ 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)");
+ }
+ else
+ printw( "Playing standard game (noblitz, nosalvo, noclosepack)");
+
+}
+
+static void intro()
+{
+char *tmpname;
+
+ srand(time(0L)+getpid()); /* Kick the random number generator */
+
+ signal(SIGINT,uninitgame);
+ signal(SIGINT,uninitgame);
+ signal(SIGIOT,uninitgame); /* for assert(3) */
+ if(signal(SIGQUIT,SIG_IGN) != SIG_IGN)
+ signal(SIGQUIT,uninitgame);
+
+ if ((tmpname = getlogin()) != NULL)
+ strcpy(name,tmpname);
+ else
+ strcpy(name,dftname);
+ name[0] = toupper(name[0]);
+
+ initscr();
+ saveterm();
+ nonl();
+ cbreak();
+ noecho();
+
+#ifdef PENGUIN
+ clear();
+ mvaddstr(4,29,"Welcome to Battleship!");
+ move(8,0);
+ PR(" \\\n");
+ PR(" \\ \\ \\\n");
+ PR(" \\ \\ \\ \\ \\_____________\n");
+ PR(" \\ \\ \\_____________ \\ \\/ |\n");
+ PR(" \\ \\/ \\ \\/ |\n");
+ PR(" \\/ \\_____/ |__\n");
+ PR(" ________________/ |\n");
+ PR(" \\ S.S. Penguin |\n");
+ PR(" \\ /\n");
+ PR(" \\___________________________________________________/\n");
+
+ mvaddstr(22,27,"Hit any key to continue..."); refresh();
+ 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();
+
+ init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK);
+ init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
+ init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
+ init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
+ init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
+ init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
+ init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
+ init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
+#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;
+ }
+
+ /* 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');
+ }
+ 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();
+}
+
+static int rnd(n)
+int n;
+{
+ return(((rand() & 0x7FFF) % n));
+}
+
+static int getcoord(atcpu)
+int atcpu;
+{
+int ny, nx, c;
+
+ if (atcpu)
+ 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);
+ }
+
+ 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);
+ }
+
+ curx = nx % BWIDTH;
+ cury = ny % BDEPTH;
+ }
+}
+
+static int collidecheck(b, y, x)
+/* is this location on the selected zboard adjacent to a ship? */
+int b;
+int y, x;
+{
+int collide;
+
+ /* anything on the square */
+ if ((collide = IS_SHIP(board[b][x][y])) != 0)
+ return(collide);
+
+ /* anything on the neighbors */
+ if (!closepack) {
+ int i;
+
+ 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]);
+ }
+ }
+ return(collide);
+}
+
+static int checkplace(b, ss, vis)
+int b;
+ship_t *ss;
+int vis;
+{
+ int l, xend, yend;
+
+ /* 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)) {
+ case 0:
+ error("Ship is hanging from the edge of the world");
+ break;
+ case 1:
+ error("Try fitting it on the board");
+ break;
+ case 2:
+ error("Figure I won't find it if you put it there?");
+ break;
+ }
+ 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)) {
+ case 0:
+ error("There's already a ship there");
+ break;
+ case 1:
+ error("Collision alert! Aaaaaagh!");
+ break;
+ case 2:
+ error("Er, Admiral, what about the other ship?");
+ break;
+ }
+ return(0);
+ }
+ }
+ return(1);
+}
+
+static int awinna()
+{
+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);
+ }
+ return(-1);
+}
+
+static ship_t *hitship(x, y)
+/* register a hit on the targeted ship */
+int x, y;
+{
+ ship_t *sb, *ss;
+ char sym;
+ int oldx, oldy;
+
+ getyx(stdscr, oldy, oldx);
+ sb = (turn) ? plyship : cpuship;
+ if(!(sym = board[OTHER][x][y]))
+ return((ship_t *)NULL);
+ for(ss = sb; ss < sb + SHIPTYPES; ++ss)
+ if(ss->symbol == sym)
+ {
+ if (++ss->hits < ss->length) /* still afloat? */
+ return((ship_t *)NULL);
+ else /* sunk! */
+ {
+ int i, j;
+
+ if (!closepack)
+ for (j = -1; j <= 1; j++)
+ {
+ int bx = ss->x + j * xincr[(ss->dir + 2) % 8];
+ int by = ss->y + j * yincr[(ss->dir + 2) % 8];
+
+ for (i = -1; i <= ss->length; ++i)
+ {
+ int x, y;
+
+ x = bx + i * xincr[ss->dir];
+ y = by + i * yincr[ss->dir];
+ if (ONBOARD(x, y))
+ {
+ hits[turn][x][y] = MARK_MISS;
+ if (turn % 2 == PLAYER)
+ {
+ cgoto(y, x);
+#ifdef A_COLOR
+ if (has_colors())
+ attron(COLOR_PAIR(COLOR_GREEN));
+#endif /* A_COLOR */
+ addch(MARK_MISS);
+#ifdef A_COLOR
+ attrset(0);
+#endif /* A_COLOR */
+ }
+ }
+ }
+ }
+
+ for (i = 0; i < ss->length; ++i)
+ {
+ int x = ss->x + i * xincr[ss->dir];
+ int y = ss->y + i * yincr[ss->dir];
+
+ hits[turn][x][y] = ss->symbol;
+ if (turn % 2 == PLAYER)
+ {
+ cgoto(y, x);
+ addch(ss->symbol);
+ }
+ }
+
+ move(oldy, oldx);
+ return(ss);
+ }
+ }
+ move(oldy, oldx);
+ return((ship_t *)NULL);
+}
+
+static int plyturn()
+{
+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);
+#ifdef A_COLOR
+ 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]);
+#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);
+}
+
+static int sgetc(s)
+char *s;
+{
+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);
+ }
+ }
+}
+
+
+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;
+
+ if (turncount++ == 0)
+ huntoffs = rnd(srchstep);
+
+ /* 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++;
+ }
+ }
+
+ if (npref) {
+ i = rnd(npref);
+
+ *px = xpreferred[i];
+ *py = ypreferred[i];
+ } else if (nposs) {
+ i = rnd(nposs);
+
+ *px = xpossible[i];
+ *py = ypossible[i];
+
+ if (srchstep > 1)
+ --srchstep;
+ } else {
+ error("No moves possible?? Help!");
+ exit(1);
+ /*NOTREACHED*/
+ }
+}
+
+#define S_MISS 0
+#define S_HIT 1
+#define S_SUNK -1
+
+static bool cpufire(x, y)
+/* fire away at given location */
+int x, y;
+{
+bool hit, sunk;
+ship_t *ss;
+
+ hits[COMPUTER][x][y] = (hit = (board[PLAYER][x][y])) ? MARK_HIT : MARK_MISS;
+ 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();
+
+ pgoto(y, x);
+#ifdef A_COLOR
+ if (has_colors())
+ if (hit)
+ attron(COLOR_PAIR(COLOR_RED));
+ else
+ attron(COLOR_PAIR(COLOR_GREEN));
+#endif /* A_COLOR */
+ addch((chtype)(hit ? SHOWHIT : SHOWSPLASH));
+#ifdef A_COLOR
+ attrset(0);
+#endif /* A_COLOR */
+
+ return(hit ? (sunk ? S_SUNK : S_HIT) : S_MISS);
+}
+
+/*
+ * This code implements a fairly irregular FSM, so please forgive the rampant
+ * unstructuredness below. The five labels are states which need to be held
+ * between computer turns.
+ */
+static bool cputurn()
+{
+#define POSSIBLE(x, y) (ONBOARD(x, y) && !hits[COMPUTER][x][y])
+#define RANDOM_FIRE 0
+#define RANDOM_HIT 1
+#define HUNT_DIRECT 2
+#define FIRST_PASS 3
+#define REVERSE_JUMP 4
+#define SECOND_PASS 5
+ static int next = RANDOM_FIRE;
+ static bool used[4];
+ static ship_t ts;
+ int navail, x, y, d, n, hit = S_MISS;
+
+ 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;
+
+ case RANDOM_HIT: /* last shot was random and hit */
+ 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;
+ }
+ if (navail == 0) /* no valid places for shots adjacent... */
+ goto refire; /* ...so we must random-fire */
+ else {
+ for (d = 0, n = rnd(navail) + 1; n; n--)
+ while (used[d])
+ d++;
+
+ assert(d <= 4);
+
+ used[d] = FALSE;
+ x = ts.x + xincr[d*2];
+ y = ts.y + yincr[d*2];
+
+ assert(POSSIBLE(x, y));
+
+ if (!(hit = cpufire(x, y)))
+ next = HUNT_DIRECT;
+ else
+ {
+ ts.x = x; ts.y = y; ts.dir = d*2; ts.hits++;
+ next = (hit == S_SUNK) ? RANDOM_FIRE : FIRST_PASS;
+ }
+ }
+ break;
+
+ 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))) {
+ ts.x = x; ts.y = y; ts.hits++;
+ next = (hit == S_SUNK) ? RANDOM_FIRE : FIRST_PASS;
+ }
+ else
+ next = REVERSE_JUMP;
+ break;
+
+ case REVERSE_JUMP: /* nail down the ship's other end */
+ 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))) {
+ ts.x = x; ts.y = y; ts.dir = d; ts.hits++;
+ next = (hit == S_SUNK) ? RANDOM_FIRE : SECOND_PASS;
+ }
+ else
+ next = RANDOM_FIRE;
+ break;
+
+ 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))) {
+ ts.x = x; ts.y = y; ts.hits++;
+ next = (hit == S_SUNK) ? RANDOM_FIRE: SECOND_PASS;
+ break;
+ } else
+ next = RANDOM_FIRE;
+ break;
+ }
+
+ /* check for continuation and/or winner */
+ if (salvo) {
+ refresh();
+ sleep(1);
+ }
+ if (awinna() != -1)
+ return(FALSE);
+
+#ifdef DEBUG
+ 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;
+
+ 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);
+ }
+
+ if (awinna())
+ ++cpuwon;
+ else
+ ++plywon;
+ j = 18 + strlen(name);
+ if(plywon >= 10)
+ ++j;
+ if(cpuwon >= 10)
+ ++j;
+ 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);
+ return(sgetc("YN") == 'Y');
+}
+
+static void do_options(c,op)
+int c;
+char *op[];
+{
+register int i;
+
+ if (c > 1) {
+ for (i=1; i<c; i++) {
+ switch(op[i][0]) {
+ default:
+ case '?':
+ fprintf(stderr, "Usage: battle [-s | -b] [-c]\n");
+ fprintf(stderr, "\tWhere the options are:\n");
+ fprintf(stderr, "\t-s : play a salvo game\n");
+ fprintf(stderr, "\t-b : play a blitz game\n");
+ fprintf(stderr, "\t-c : ships may be adjacent\n");
+ exit(1);
+ break;
+ case '-':
+ switch(op[i][1]) {
+ case 'b':
+ blitz = 1;
+ if (salvo == 1) {
+ fprintf(stderr,
+ "Bad Arg: -b and -s are mutually exclusive\n");
+ exit(1);
+ }
+ break;
+ case 's':
+ salvo = 1;
+ if (blitz == 1)
+ {
+ fprintf(stderr,
+ "Bad Arg: -s and -b are mutually exclusive\n");
+ exit(1);
+ }
+ break;
+ case 'c':
+ closepack = 1;
+ break;
+ default:
+ fprintf(stderr,
+ "Bad arg: type \"%s ?\" for usage message\n", op[0]);
+ exit(1);
+ }
+ }
+ }
+ }
+}
+
+static int scount(who)
+int who;
+{
+register int i, shots;
+register ship_t *sp;
+
+ if (who)
+ sp = cpuship; /* count cpu shots */
+ else
+ sp = plyship; /* count player 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[];
+{
+ do_options(argc, 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;
+ }
+ } while (playagain());
+ uninitgame();
+ /*NOTREACHED*/
+}
+
+/* bs.c ends here */
diff --git a/lib/libncurses/TESTS/copy.c b/lib/libncurses/TESTS/copy.c
new file mode 100644
index 0000000..6ded258
--- /dev/null
+++ b/lib/libncurses/TESTS/copy.c
@@ -0,0 +1,39 @@
+#include <ncurses.h>
+
+main()
+{
+WINDOW *win1, *win2;
+int h, i;
+
+ initscr();
+ cbreak();
+ noecho();
+ win1 = newwin(20, 50, 0, 20);
+ for (h = 0; h < 20; h++)
+ for (i = 0; i < 50; i++)
+ mvwaddch(win1, h, i, 'X');
+ wrefresh(win1);
+ getch();
+
+ win2 = newwin(20, 50, 3, 30);
+ for (h = 0; h < 20; h++)
+ for (i = 0; i < 50; i++)
+ mvwaddch(win2, h, i, 'Y');
+ wnoutrefresh(win1);
+ wnoutrefresh(win2);
+ doupdate();
+ getch();
+
+ /* now, remove window 2 and restore the contents of window 1 */
+ i = copywin(win1, win2, 5, 10, 0, 0, 14, 39, 0);
+ wnoutrefresh(win1);
+ wnoutrefresh(win2);
+ printw("copywin returns %d\n", i);
+ wnoutrefresh(stdscr);
+ doupdate();
+
+ getch();
+
+ endwin();
+}
+
diff --git a/lib/libncurses/TESTS/corner.c b/lib/libncurses/TESTS/corner.c
new file mode 100644
index 0000000..2ab38a9
--- /dev/null
+++ b/lib/libncurses/TESTS/corner.c
@@ -0,0 +1,16 @@
+#include <ncurses.h>
+
+int main()
+{
+int i, j;
+
+ initscr();
+
+ for (i = 0; i < LINES; i++) {
+ j = mvaddch(i, COLS - 1, 'A' + i);
+ }
+ refresh();
+ endwin();
+ exit(0);
+}
+
diff --git a/lib/libncurses/TESTS/ensor.c b/lib/libncurses/TESTS/ensor.c
new file mode 100644
index 0000000..7ace038
--- /dev/null
+++ b/lib/libncurses/TESTS/ensor.c
@@ -0,0 +1,52 @@
+#include <ncurses.h>
+
+main()
+{
+ int i;
+ WINDOW *win;
+
+ initscr();
+ noecho();
+ nonl();
+ cbreak();
+
+ scrollok(stdscr, TRUE);
+
+ for (i=0; i<25; i++)
+ printw("This is in the background, this should be left alone!\n");
+
+ refresh();
+ win=newwin(10,50,6,20);
+ scrollok(win,TRUE);
+ wmove(win,0,0);
+ whline(win,0,49);
+ wmove(win,9,0);
+ whline(win,0,49);
+ wrefresh(win);
+ wattrset(win,A_STANDOUT);
+ mvwprintw(win, 0, 14, " Scrolling Demo! ");
+ mvwprintw(win, 9, 14, " Scrolling Demo! ");
+ wattroff(win,A_STANDOUT);
+ wsetscrreg(win, 1,8);
+
+ mvwprintw(win, 0, 5, " DOWN ");
+ wmove(win,1,0);
+ wrefresh(win);
+
+ getch();
+ for (i=0; i<25; i++){ wprintw(win, "This is window line test (%d).\n", i);
+ if (i%2) wattrset(win,A_BOLD); else wattroff(win,A_BOLD);
+ wrefresh(win); }
+
+ mvwprintw(win, 0, 5, " UP ");
+ wrefresh(win);
+ getch();
+ for (i=0; i<25; i++) { wmove(win,1,0); winsertln(win);
+ if (i%2) wattrset(win,A_BOLD); else wattroff(win,A_BOLD);
+ wprintw(win, "Scrolling backwards! (%d)\n", i); wrefresh(win); }
+
+ mvwprintw(win, 0, 5, " DONE "); wrefresh(win);
+
+ endwin();
+}
+
diff --git a/lib/libncurses/TESTS/firework.c b/lib/libncurses/TESTS/firework.c
new file mode 100644
index 0000000..b497584
--- /dev/null
+++ b/lib/libncurses/TESTS/firework.c
@@ -0,0 +1,113 @@
+#include <stdio.h>
+#include <signal.h>
+#include <ncurses.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <time.h>
+
+void explode();
+
+int main()
+{
+int start,end,row,diff,flag,direction,seed;
+
+ initscr();
+ if (has_colors())
+ start_color();
+ seed = time((time_t *)0);
+ srand(seed);
+ cbreak();
+ for (;;) {
+ do {
+ start = rand() % (COLS -3);
+ end = rand() % (COLS - 3);
+ start = (start < 2) ? 2 : start;
+ end = (end < 2) ? 2 : end;
+ direction = (start > end) ? -1 : 1;
+ diff = abs(start-end);
+ } while (diff<2 || diff>=LINES-2);
+ attrset(A_NORMAL);
+ for (row=0;row<diff;row++) {
+ mvprintw(LINES - row,start + (row * direction),
+ (direction < 0) ? "\\" : "/");
+ if (flag++) {
+ refresh();
+ erase();
+ flag = 0;
+ }
+ }
+ if (flag++) {
+ refresh();
+ flag = 0;
+ }
+ seed = time((time_t *)0);
+ srand(seed);
+ explode(LINES-row,start+(diff*direction));
+ erase();
+ refresh();
+ }
+ endwin();
+ exit(0);
+}
+
+void explode(int row, int col)
+{
+ erase();
+ mvprintw(row,col,"-");
+ refresh();
+
+ init_pair(1,get_colour(),COLOR_BLACK);
+ attrset(COLOR_PAIR(1));
+ mvprintw(row-1,col-1," - ");
+ mvprintw(row,col-1,"-+-");
+ mvprintw(row+1,col-1," - ");
+ refresh();
+
+ init_pair(1,get_colour(),COLOR_BLACK);
+ attrset(COLOR_PAIR(1));
+ mvprintw(row-2,col-2," --- ");
+ mvprintw(row-1,col-2,"-+++-");
+ mvprintw(row, col-2,"-+#+-");
+ mvprintw(row+1,col-2,"-+++-");
+ mvprintw(row+2,col-2," --- ");
+ refresh();
+
+ init_pair(1,get_colour(),COLOR_BLACK);
+ attrset(COLOR_PAIR(1));
+ mvprintw(row-2,col-2," +++ ");
+ mvprintw(row-1,col-2,"++#++");
+ mvprintw(row, col-2,"+# #+");
+ mvprintw(row+1,col-2,"++#++");
+ mvprintw(row+2,col-2," +++ ");
+ refresh();
+
+ init_pair(1,get_colour(),COLOR_BLACK);
+ attrset(COLOR_PAIR(1));
+ mvprintw(row-2,col-2," # ");
+ mvprintw(row-1,col-2,"## ##");
+ mvprintw(row, col-2,"# #");
+ mvprintw(row+1,col-2,"## ##");
+ mvprintw(row+2,col-2," # ");
+ refresh();
+
+ init_pair(1,get_colour(),COLOR_BLACK);
+ attrset(COLOR_PAIR(1));
+ mvprintw(row-2,col-2," # # ");
+ mvprintw(row-1,col-2,"# #");
+ mvprintw(row, col-2," ");
+ mvprintw(row+1,col-2,"# #");
+ mvprintw(row+2,col-2," # # ");
+ refresh();
+ return;
+}
+
+int get_colour()
+{
+ int attr;
+ attr = (rand() % 16)+1;
+ if (attr == 1 || attr == 9)
+ attr = COLOR_RED;
+ if (attr > 8)
+ attr |= A_BOLD;
+ return(attr);
+}
diff --git a/lib/libncurses/TESTS/gdc.6 b/lib/libncurses/TESTS/gdc.6
new file mode 100644
index 0000000..7fa60de
--- /dev/null
+++ b/lib/libncurses/TESTS/gdc.6
@@ -0,0 +1,22 @@
+.TH GDC 6
+.SH NAME
+gdc \- grand digital clock (curses)
+.SH SYNOPSIS
+.B gdc
+[-s] [
+.I n
+]
+.SH DESCRIPTION
+.I Gdc
+runs a digital clock made of reverse-video blanks on a curses
+compatible VDU screen. With an optional numeric argument
+.I n
+it stops after
+.I n
+seconds (default never).
+The optional
+.B -s
+flag makes digits scroll as they change. In this curses mode implementation,
+the scrolling option has trouble keeping up.
+.SH AUTHOR
+Amos Shapir, modified for curses by John Lupien.
diff --git a/lib/libncurses/TESTS/gdc.c b/lib/libncurses/TESTS/gdc.c
new file mode 100644
index 0000000..7f80d93
--- /dev/null
+++ b/lib/libncurses/TESTS/gdc.c
@@ -0,0 +1,174 @@
+/*
+ * Grand digital clock for curses compatible terminals
+ * Usage: gdc [-s] [n] -- run for n seconds (default infinity)
+ * Flags: -s: scroll
+ *
+ * modified 10-18-89 for curses (jrl)
+ * 10-18-89 added signal handling
+ */
+
+#include <time.h>
+#include <signal.h>
+#include <ncurses.h>
+#include <stdlib.h>
+#ifndef NONPOSIX
+#include <unistd.h>
+#endif
+
+/* it won't be */
+long now; /* yeah! */
+struct tm *tm;
+
+short disp[11] = {
+ 075557, 011111, 071747, 071717, 055711,
+ 074717, 074757, 071111, 075757, 075717, 002020
+};
+long old[6], next[6], new[6], mask;
+char scrol;
+
+int sigtermed=0;
+
+int hascolor = 0;
+
+void set(int, int);
+void standt(int);
+void movto(int, int);
+
+void sighndl(signo)
+int signo;
+{
+ signal(signo, sighndl);
+ sigtermed=signo;
+}
+
+int
+main(argc, argv)
+int argc;
+char **argv;
+{
+long t, a;
+int i, j, s, k;
+int n = 0;
+
+ signal(SIGINT,sighndl);
+ signal(SIGTERM,sighndl);
+ signal(SIGKILL,sighndl);
+
+ initscr();
+ cbreak();
+ noecho();
+
+ hascolor = has_colors();
+
+ if(hascolor) {
+ start_color();
+ init_pair(1, COLOR_BLACK, COLOR_RED);
+ init_pair(2, COLOR_RED, COLOR_BLACK);
+ attrset(COLOR_PAIR(2));
+ }
+
+ clear();
+ refresh();
+ while(--argc > 0) {
+ if(**++argv == '-')
+ scrol = 1;
+ else
+ n = atoi(*argv);
+ }
+ do {
+ mask = 0;
+ time(&now);
+ tm = localtime(&now);
+ set(tm->tm_sec%10, 0);
+ set(tm->tm_sec/10, 4);
+ set(tm->tm_min%10, 10);
+ set(tm->tm_min/10, 14);
+ set(tm->tm_hour%10, 20);
+ set(tm->tm_hour/10, 24);
+ set(10, 7);
+ set(10, 17);
+ for(k=0; k<6; k++) {
+ if(scrol) {
+ for(i=0; i<5; i++)
+ new[i] = (new[i]&~mask) | (new[i+1]&mask);
+ new[5] = (new[5]&~mask) | (next[k]&mask);
+ } else
+ new[k] = (new[k]&~mask) | (next[k]&mask);
+ next[k] = 0;
+ for(s=1; s>=0; s--) {
+ standt(s);
+ for(i=0; i<6; i++) {
+ if((a = (new[i]^old[i])&(s ? new : old)[i]) != 0) {
+ for(j=0,t=1<<26; t; t>>=1,j++) {
+ if(a&t) {
+ if(!(a&(t<<1))) {
+ movto(i, 2*j);
+ }
+ addstr(" ");
+ }
+ }
+ }
+ if(!s) {
+ old[i] = new[i];
+ }
+ }
+ if(!s) {
+ refresh();
+ }
+ }
+ }
+ movto(6, 0);
+ refresh();
+ sleep(1);
+ if (sigtermed) {
+ standend();
+ clear();
+ refresh();
+ endwin();
+ fprintf(stderr, "gdc terminated by signal %d\n", sigtermed);
+ exit(1);
+ }
+ } while(--n);
+ standend();
+ clear();
+ refresh();
+ endwin();
+ return(0);
+}
+
+void
+set(int t, int n)
+{
+int i, m;
+
+ m = 7<<n;
+ for(i=0; i<5; i++) {
+ next[i] |= ((disp[t]>>(4-i)*3)&07)<<n;
+ mask |= (next[i]^old[i])&m;
+ }
+ if(mask&m)
+ mask |= m;
+}
+
+void
+standt(int on)
+{
+ if (on) {
+ if(hascolor)
+ attron(COLOR_PAIR(1));
+ else
+ attron(A_STANDOUT);
+ } else {
+ if(hascolor)
+ attron(COLOR_PAIR(2));
+ else
+ attroff(A_STANDOUT);
+ }
+}
+
+void
+movto(int line, int col)
+{
+ move(line, col);
+}
+
diff --git a/lib/libncurses/TESTS/getch.c b/lib/libncurses/TESTS/getch.c
new file mode 100644
index 0000000..90a0ee4
--- /dev/null
+++ b/lib/libncurses/TESTS/getch.c
@@ -0,0 +1,29 @@
+#include <ncurses.h>
+
+main()
+ {
+ int c,i;
+ initscr();
+ cbreak();
+ noecho();
+#if 1
+ wtimeout(stdscr,1000);
+#endif
+ scrollok(stdscr,TRUE);
+ for (c='A';c<='Z';c++)
+ for (i=0;i<25;i++)
+ {
+ move(i,i);
+ addch(c);
+ refresh();
+ }
+ move (0,0);
+ while ((c=wgetch(stdscr))!='A')
+ {
+ if (c == EOF) printw(">>wait for keypress<<");
+ else printw(">>%c<<\n",c);
+ refresh();
+ }
+ endwin();
+ }
+
diff --git a/lib/libncurses/TESTS/hanoi.c b/lib/libncurses/TESTS/hanoi.c
new file mode 100644
index 0000000..422d5da
--- /dev/null
+++ b/lib/libncurses/TESTS/hanoi.c
@@ -0,0 +1,267 @@
+/*
+ * Name: Towers of Hanoi.
+ *
+ * Desc:
+ * This is a playable copy of towers of hanoi.
+ * Its sole purpose is to demonstrate my Amiga Curses package.
+ * This program should compile on any system that has Curses.
+ * 'hanoi' will give a manual game with 7 playing pieces.
+ * 'hanoi n' will give a manual game with n playing pieces.
+ * 'hanoi n a' will give an auto solved game with n playing pieces.
+ *
+ * Author: Simon J Raybould (sie@fulcrum.bt.co.uk).
+ *
+ * Date: 05.Nov.90
+ *
+ */
+
+#include <ncurses.h>
+
+#define NPEGS 3 /* This is not configurable !! */
+#define MINTILES 3
+#define MAXTILES 9
+#define DEFAULTTILES 7
+#define TOPLINE 6
+#define BASELINE 16
+#define STATUSLINE (LINES-3)
+#define LEFTPEG 19
+#define MIDPEG 39
+#define RIGHTPEG 59
+
+#define LENTOIND(x) (((x)-1)/2-1)
+#define OTHER(a,b) (3-((a)+(b)))
+
+struct Peg {
+ int Length[MAXTILES];
+ int Count;
+};
+
+struct Peg Pegs[NPEGS];
+int PegPos[] = { LEFTPEG, MIDPEG, RIGHTPEG };
+int TileColour[] = {
+ COLOR_GREEN, /* Length 3 */
+ COLOR_MAGENTA, /* Length 5 */
+ COLOR_RED, /* Length 7 */
+ COLOR_BLUE, /* Length 9 */
+ COLOR_CYAN, /* Length 11 */
+ COLOR_YELLOW, /* Length 13 */
+ COLOR_GREEN, /* Length 15 */
+ COLOR_MAGENTA, /* Length 17 */
+ COLOR_RED, /* Length 19 */
+};
+int NMoves = 0;
+
+void InitTiles(), DisplayTiles(), MakeMove(), AutoMove(), Usage();
+
+int
+main(int argc, char **argv)
+{
+int NTiles, FromCol, ToCol;
+unsigned char AutoFlag = 0;
+
+ switch(argc) {
+ case 1:
+ NTiles = DEFAULTTILES;
+ break;
+ case 2:
+ NTiles = atoi(argv[1]);
+ if (NTiles > MAXTILES || NTiles < MINTILES) {
+ fprintf(stderr, "Range %d to %d\n", MINTILES, MAXTILES);
+ exit(1);
+ }
+ break;
+ case 3:
+ if (strcmp(argv[2], "a")) {
+ Usage();
+ exit(1);
+ }
+ NTiles = atoi(argv[1]);
+ if (NTiles > MAXTILES || NTiles < MINTILES) {
+ fprintf(stderr, "Range %d to %d\n", MINTILES, MAXTILES);
+ exit(1);
+ }
+ AutoFlag = TRUE;
+ break;
+ default:
+ Usage();
+ exit(1);
+ }
+ initscr();
+ if (!has_colors()) {
+ puts("terminal doesn't support color.");
+ exit(1);
+ }
+ traceon();
+ start_color();
+ {
+ int i;
+ for (i = 0; i < 9; i++)
+ init_pair(i+1, COLOR_BLACK, TileColour[i]);
+ }
+ cbreak();
+ if (LINES < 24) {
+ fprintf(stderr, "Min screen length 24 lines\n");
+ endwin();
+ exit(1);
+ }
+ if(AutoFlag)
+ leaveok(stdscr, TRUE); /* Attempt to remove cursor */
+ InitTiles(NTiles);
+ DisplayTiles();
+ if(AutoFlag) {
+ do {
+ noecho();
+ AutoMove(0, 2, NTiles);
+ } while(!Solved(NTiles));
+ sleep(2);
+ } else {
+ for(;;) {
+ if(GetMove(&FromCol, &ToCol))
+ break;
+ if(InvalidMove(FromCol, ToCol)) {
+ mvaddstr(STATUSLINE, 0, "Invalid Move !!");
+ refresh();
+ beep();
+ continue;
+ }
+ MakeMove(FromCol, ToCol);
+ if(Solved(NTiles)) {
+ mvprintw(STATUSLINE, 0, "Well Done !! You did it in %d moves", NMoves);
+ refresh();
+ sleep(5);
+ break;
+ }
+ }
+ }
+ endwin();
+}
+
+int
+InvalidMove(int From, int To)
+{
+ if(From == To)
+ return TRUE;
+ if(!Pegs[From].Count)
+ return TRUE;
+ if(Pegs[To].Count &&
+ Pegs[From].Length[Pegs[From].Count-1] >
+ Pegs[To].Length[Pegs[To].Count-1])
+ return TRUE;
+ return FALSE;
+}
+
+void
+InitTiles(int NTiles)
+{
+int Size, SlotNo;
+
+ for(Size=NTiles*2+1, SlotNo=0; Size>=3; Size-=2)
+ Pegs[0].Length[SlotNo++] = Size;
+
+ Pegs[0].Count = NTiles;
+ Pegs[1].Count = 0;
+ Pegs[2].Count = 0;
+}
+
+#define gc() {noecho();getch();echo();}
+
+void
+DisplayTiles()
+{
+ int Line, Peg, SlotNo;
+ char TileBuf[BUFSIZ];
+
+ erase();
+ mvaddstr(1, 24, "T O W E R S O F H A N O I");
+ mvaddstr(3, 34, "SJR 1990");
+ mvprintw(19, 5, "Moves : %d", NMoves);
+ standout();
+ mvaddstr(BASELINE, 8, " ");
+
+ for(Line=TOPLINE; Line<BASELINE; Line++) {
+ mvaddch(Line, LEFTPEG, ' ');
+ mvaddch(Line, MIDPEG, ' ');
+ mvaddch(Line, RIGHTPEG, ' ');
+ }
+ mvaddch(BASELINE, LEFTPEG, '1');
+ mvaddch(BASELINE, MIDPEG, '2');
+ mvaddch(BASELINE, RIGHTPEG, '3');
+ standend();
+
+ /* Draw tiles */
+ for(Peg=0; Peg<NPEGS; Peg++) {
+ for(SlotNo=0; SlotNo<Pegs[Peg].Count; SlotNo++) {
+ memset(TileBuf, ' ', Pegs[Peg].Length[SlotNo]);
+ TileBuf[Pegs[Peg].Length[SlotNo]] = '\0';
+ attrset(COLOR_PAIR(LENTOIND(Pegs[Peg].Length[SlotNo])));
+ mvaddstr(BASELINE-(SlotNo+1),
+ PegPos[Peg]-Pegs[Peg].Length[SlotNo]/2, TileBuf);
+ }
+ }
+ attrset(A_NORMAL);
+ refresh();
+}
+
+int
+GetMove(int *From, int *To)
+{
+ mvaddstr(STATUSLINE, 0, "Next move ('q' to quit) from ");
+ clrtoeol();
+ refresh();
+ if((*From = getch()) == 'q')
+ return TRUE;
+ *From -= ('0'+1);
+ addstr(" to ");
+ clrtoeol();
+ refresh();
+ if((*To = getch()) == 'q')
+ return TRUE;
+ *To -= ('0'+1);
+ move(STATUSLINE, 0);
+ clrtoeol();
+ refresh();
+ return FALSE;
+}
+
+void
+MakeMove(int From, int To)
+{
+
+ Pegs[From].Count--;
+ Pegs[To].Length[Pegs[To].Count] = Pegs[From].Length[Pegs[From].Count];
+ Pegs[To].Count++;
+ NMoves++;
+ DisplayTiles();
+}
+
+void
+AutoMove(int From, int To, int Num)
+{
+
+ if(Num == 1) {
+ MakeMove(From, To);
+ return;
+ }
+ AutoMove(From, OTHER(From, To), Num-1);
+ MakeMove(From, To);
+ AutoMove(OTHER(From, To), To, Num-1);
+}
+
+int
+Solved(int NumTiles)
+{
+int i;
+
+ for(i = 1; i < NPEGS; i++)
+ if (Pegs[i].Count == NumTiles)
+ return TRUE;
+ return FALSE;
+}
+
+void
+Usage()
+{
+ fprintf(stderr, "Usage: hanoi [<No Of Tiles>] [a]\n");
+ fprintf(stderr, "The 'a' option causes the tower to be solved automatically\n");
+}
+
diff --git a/lib/libncurses/TESTS/knight.c b/lib/libncurses/TESTS/knight.c
new file mode 100644
index 0000000..4b2f989
--- /dev/null
+++ b/lib/libncurses/TESTS/knight.c
@@ -0,0 +1,322 @@
+/* Knights Tour - a brain game */
+
+#include <ncurses.h>
+#include <signal.h>
+#include <ctype.h>
+#include <stdlib.h>
+
+#ifdef __386BSD__
+#define srand48 srandom
+#define lrand48 random
+#endif
+
+short board [64]; /* the squares */
+char row, column; /* input characters */
+int rw,col; /* numeric equivalent of row and column */
+int curow,curcol; /* current row and column integers */
+int rdif, cdif; /* difference between input and current */
+int j; /* index into board */
+
+char script[]={"'_)//,/(-)/__/__(_<_(__),|/|/_///_/_<//_/_)__o__o'______///_(--_(_)___,(_/,_/__(_\0"};
+
+int ypos[] ={1,0,1,2,3,0,1,2,2,3,3,2,2,3,2,2,3,3,3,3,3,2,3,3,2,4,5,5,
+ 4,3,3,2,1,2,3,3,3,2,1,3,3,2,3,3,3,2,1,1,0,1,4,4,4,4,4,4,5,6,7,7,
+ 7,6,6,6,7,7,7,6,6,6,6,7,7,7,6,7,7,6,6,7,7};
+
+int xpos[]={0,1,2,1,0,5,4,3,2,4,6,7,8,8,9,10,10,11,12,13,14,15,15,16,
+ 16,16,15,14,15,17,18,19,20,20,20,21,22,23,24,23,25,26,27,26,28,
+ 13,23,25,27,27,2,3,4,5,6,7,4,3,2,1,0,1,2,5,4,5,6,6,7,8,9,8,9,10,
+ 11,11,12,13,14,14,15};
+
+static char *instructions[] =
+{
+" Knight's Tour is a board game for one player. It is played on",
+"an eight by eight board and is based on the allowable moves that a knight",
+"can make in the game of chess. For those who are unfamiliar with the",
+"game, a knight may move either on a row or a column but not diagonally.",
+"He may move one square in any direction and two squares in a perpendicular",
+"direction >or< two squares in any direction and one square in a",
+"perpendicular direction. He may not, of course, move off the board.",
+"",
+" At the beginning of a game you will be asked to either choose a",
+"starting square or allow the computer to select a random location.",
+"Squares are designated by a letter-number combination where the row is",
+"specified by a letter A-H and the numbers 1-8 define a column. Invalid",
+"entries are ignored and illegal moves produce a beep at the terminal.",
+"",
+" The objective is to visit every square on the board. When you claim",
+"a square a marker is placed on it to show where you've been. You may",
+"not revisit a square that you've landed on before.",
+"",
+" After each move the program checks to see if you have any legal",
+"moves left. If not, the game ends and your squares are counted. If",
+"you've made all the squares you win the game. Otherwise, you are told",
+"the number of squares you did make.",
+"END"
+};
+
+void init(void);
+int play(void);
+void drawboard(void);
+void dosquares(void);
+void getfirst(void);
+void getrc(void);
+void putstars(void);
+int evalmove(void);
+int chkmoves(void);
+int endgame(void);
+int chksqr(int, int);
+void instruct(void);
+void title(int, int);
+
+int
+main ()
+{
+ init ();
+ for (;;)
+ if (!play ()) {
+ endwin ();
+ exit (0);
+ }
+}
+
+void
+init ()
+{
+
+ srand48 (getpid());
+ 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')
+ instruct();
+ clear ();
+}
+
+int
+play ()
+{
+ drawboard (); /* clear screen and drawboard */
+ for (j = 0; j < 64; j++) board[j]=0;
+ getfirst (); /* get the starting square */
+ for (;;) {
+ getrc();
+ if (evalmove()) {
+ putstars ();
+ if (!chkmoves())
+ return (endgame ());
+ }
+ else beep();
+ }
+}
+
+void
+drawboard ()
+{
+ erase ();
+ dosquares ();
+ refresh ();
+ mvaddstr (0, 7, "1 2 3 4 5 6 7 8");
+ for (j = 0; j < 8; j++) mvaddch (2*j+2, 3, j + 'A');
+ refresh ();
+ mvaddstr (20, 5, "ROW:");
+ mvaddstr (20, 27, "COLUMN:");
+ mvaddstr (14, 49, "CURRENT ROW");
+ mvaddstr (16, 49, "CURRENT COL");
+ mvaddstr (22, 5, "A - H or Q to quit");
+ mvaddstr (22, 27, "1 - 8 or ESC to cancel row");
+ refresh ();
+ title (1,40);
+}
+
+void
+dosquares ()
+{
+ mvaddstr (1, 6, "-------------------------------");
+ for (j = 1; j < 9; j++){
+ mvaddstr (2*j, 5, "| | | | | | | | |");
+ mvaddstr (2*j+1, 6, "-------------------------------");
+ }
+}
+
+void
+getfirst () /* get first square */
+{
+ mvaddstr (23, 25, "(S)elect or (R)andom "); refresh ();
+ do {
+ row = toupper(getch());
+ } while ((row != 'S') && (row != 'R'));
+ if (row == 'R') {
+ rw = lrand48() % 8;
+ col = lrand48() % 8;
+ j = 8* rw + col;
+ row = rw + 'A';
+ column = col + '1';
+ }
+ else {
+ mvaddstr (23, 25, "Enter starting row and column");
+ refresh ();
+ getrc(); /* get row and column */
+ }
+ putstars ();
+ move (23, 0);
+ clrtobot();
+}
+
+void
+getrc () /* get row and column */
+{
+ noecho ();
+ do {
+ mvaddstr (20, 35, " ");
+ refresh ();
+ do {
+ mvaddch (20, 11, ' ');
+ move (20, 11);
+ refresh ();
+ row=toupper(getch());
+ if (row == 'Q') {
+ endwin ();
+ exit (1);
+ }
+ } while ((row < 'A') || (row > 'H'));
+ addch (row);
+ move (20, 35);
+ refresh ();
+ do {
+ column=getch();
+ if (column == '\033') break;
+ } while ((column < '1') || (column > '8'));
+ if (column != '\033') addch (column);
+ } while (column == '\033');
+ refresh();
+ rw = row - 'A';
+ col= column - '1';
+ j = 8 * rw + col;
+}
+
+void
+putstars () /* place the stars, update board & currents */
+{
+ mvaddch (2*curow+2, 38, ' ');
+ mvaddch (2*rw+2, 38, '<');
+ mvaddch (18, curcol*4+7, ' ');
+ mvaddch (18, col*4+7, '^');
+ curow = rw;
+ curcol= col;
+ mvaddstr (2 * rw + 2, 4*col+6, "***");
+ mvaddch (14, 61, row);
+ mvaddch (16, 61, column);
+ refresh ();
+ board[j] = 1;
+}
+
+int
+evalmove() /* convert row and column to integers */
+ /* and evaluate move */
+{
+ rdif = rw - curow;
+ cdif = col - curcol;
+ rdif = abs(rw - curow);
+ cdif = abs(col - curcol);
+ refresh ();
+ if ((rdif == 1) && (cdif == 2)) if (board [j] == 0) return (1);
+ if ((rdif == 2) && (cdif == 1)) if (board [j] == 0) return (1);
+ return (0);
+}
+
+int
+chkmoves () /* check to see if valid moves are available */
+{
+ if (chksqr(2,1)) return (1);
+ if (chksqr(2,-1)) return (1);
+ if (chksqr(-2,1)) return (1);
+ if (chksqr(-2,-1)) return (1);
+ if (chksqr(1,2)) return (1);
+ if (chksqr(1,-2)) return (1);
+ if (chksqr(-1,2)) return (1);
+ if (chksqr(-1,-2)) return (1);
+ return (0);
+}
+
+int
+endgame () /* check for filled board or not */
+{
+ rw = 0;
+ for (j = 0; j < 64; j++) if (board[j] != 0) rw+=1;
+ if (rw == 64) mvaddstr (20, 20, "Congratulations !! You got 'em all");
+ else mvprintw (20, 20, "You have ended up with %2d squares",rw);
+ mvaddstr (21, 25, "Play again ? (y/n) ");
+ refresh ();
+ if ((row=tolower(getch())) == 'y') return (1);
+ else return (0);
+}
+
+#ifndef abs
+abs(num)
+int num;
+{
+ if (num < 0) return (-num);
+ else return (num);
+}
+#endif
+
+int
+chksqr (int n1, int n2)
+{
+int r1, c1;
+
+ r1 = rw + n1;
+ c1 = col + n2;
+ if ((r1<0) || (r1>7)) return (0);
+ if ((c1<0) || (c1>7)) return (0);
+ if (board[r1*8+c1] == 0) return (1);
+ else return (0);
+}
+
+void
+instruct()
+{
+int i;
+
+ clear ();
+ for (i=0;;i++) {
+ if ((strcmp(instructions[i],"END"))) mvaddstr (i, 0, instructions[i]);
+ else {
+ mvaddstr (23, 25, "Ready to play ? (y/n) ");
+ refresh();
+ if (toupper(getch()) == 'Y') {
+ clear ();
+ return;
+ } else {
+ clear ();
+ refresh ();
+ endwin ();
+ exit (0);
+ }
+ }
+ }
+}
+
+void
+title (y,x)
+int y,x;
+{
+char c;
+
+ j = 0;
+ do {
+ c = script[j];
+ if (c == 0) break ;
+ mvaddch (ypos[j]+y, xpos[j]+x, c);
+ j++;
+ } while (c != 0);
+ refresh ();
+}
+
+
diff --git a/lib/libncurses/TESTS/ncurses.c b/lib/libncurses/TESTS/ncurses.c
new file mode 100644
index 0000000..468cd5d
--- /dev/null
+++ b/lib/libncurses/TESTS/ncurses.c
@@ -0,0 +1,1038 @@
+/****************************************************************************
+
+NAME
+ ncurses.c --- ncurses library exerciser
+
+SYNOPSIS
+ ncurses
+
+DESCRIPTION
+ An interactive test module for the ncurses library.
+
+AUTHOR
+ This software is Copyright (C) 1993 by Eric S. Raymond, all rights reserved.
+It is issued with ncurses under the same terms and conditions as the ncurses
+library source.
+
+***************************************************************************/
+/*LINTLIBRARY */
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <ncurses.h>
+
+#define P(s) printw("%s\n", s)
+#ifndef CTRL
+#define CTRL(x) ((x) & 0x1f)
+#endif
+
+/****************************************************************************
+ *
+ * Character input test
+ *
+ ****************************************************************************/
+
+static void getch_test(void)
+/* test the keypad feature */
+{
+ unsigned int c;
+ int firsttime = 0;
+
+ refresh();
+
+ c = '?';
+ do {
+ if (firsttime++)
+ {
+ printw("Key pressed: %04o ", c);
+ if (c >= KEY_MIN)
+ {
+ (void) addstr(keyname(c));
+ addch('\n');
+ }
+ else if (c > 0x80)
+ {
+ if (isprint(c & ~0x80))
+ (void) printw("M-%c", c);
+ else
+ (void) printw("M-%s", unctrl(c));
+ addstr(" (high-half character)\n");
+ }
+ else
+ {
+ if (isprint(c))
+ (void) printw("%c (ASCII printable character)\n", c);
+ else
+ (void) printw("%s (ASCII control character)\n", unctrl(c));
+ }
+ }
+ if (c == 'x' || c == 'q')
+ break;
+ if (c == '?')
+ addstr("Type any key to see its keypad value, `q' to quit, `?' for help.\n");
+ } while
+ ((c = getch()) != EOF);
+
+ erase();
+ endwin();
+}
+
+static void attr_test(void)
+/* test text attrivutes */
+{
+ refresh();
+
+ mvaddstr(0, 20, "Character attribute test display");
+
+ mvaddstr(2,8,"This is STANDOUT mode: ");
+ attron(A_STANDOUT);
+ addstr("abcde fghij klmno pqrst uvwxy x");
+ attroff(A_STANDOUT);
+
+ mvaddstr(4,8,"This is REVERSE mode: ");
+ attron(A_REVERSE);
+ addstr("abcde fghij klmno pqrst uvwxy x");
+ attroff(A_REVERSE);
+
+ mvaddstr(6,8,"This is BOLD mode: ");
+ attron(A_BOLD);
+ addstr("abcde fghij klmno pqrst uvwxy x");
+ attroff(A_BOLD);
+
+ mvaddstr(8,8,"This is UNDERLINE mode: ");
+ attron(A_UNDERLINE);
+ addstr("abcde fghij klmno pqrst uvwxy x");
+ attroff(A_UNDERLINE);
+
+ mvaddstr(10,8,"This is DIM mode: ");
+ attron(A_DIM);
+ addstr("abcde fghij klmno pqrst uvwxy x");
+ attroff(A_DIM);
+
+ mvaddstr(12,8,"This is BLINK mode: ");
+ attron(A_BLINK);
+ addstr("abcde fghij klmno pqrst uvwxy x");
+ attroff(A_BLINK);
+
+ mvaddstr(14,8,"This is BOLD UNDERLINE BLINK mode: ");
+ attron(A_BOLD|A_BLINK|A_UNDERLINE);
+ addstr("abcde fghij klmno pqrst uvwxy x");
+ attroff(A_BOLD|A_BLINK|A_UNDERLINE);
+
+ attrset(A_NORMAL);
+ mvaddstr(16,8,"This is NORMAL mode: ");
+ addstr("abcde fghij klmno pqrst uvwxy x");
+
+ refresh();
+
+ move(LINES - 1, 0);
+ addstr("Press any key to continue... ");
+ (void) getch();
+
+ erase();
+ endwin();
+}
+
+/****************************************************************************
+ *
+ * Color support tests
+ *
+ ****************************************************************************/
+
+static char *colors[] =
+{
+ "black",
+ "red",
+ "green",
+ "yellow",
+ "blue",
+ "magenta",
+ "cyan",
+ "white"
+};
+
+static void color_test(void)
+/* generate a color test pattern */
+{
+ int i;
+
+ refresh();
+ (void) printw("There are %d color pairs\n", COLOR_PAIRS);
+
+ (void) mvprintw(1, 0,
+ "%dx%d matrix of foreground/background colors, bright *off*\n",
+ COLORS, COLORS);
+ for (i = 0; i < COLORS; i++)
+ mvaddstr(2, (i+1) * 8, colors[i]);
+ for (i = 0; i < COLORS; i++)
+ mvaddstr(3 + i, 0, colors[i]);
+ for (i = 1; i < COLOR_PAIRS; i++)
+ {
+ init_pair(i, i % COLORS, i / COLORS);
+ attron(COLOR_PAIR(i));
+ mvaddstr(3 + (i / COLORS), (i % COLORS + 1) * 8, "Hello");
+ attrset(A_NORMAL);
+ }
+
+ (void) mvprintw(COLORS + 4, 0,
+ "%dx%d matrix of foreground/background colors, bright *on*\n",
+ COLORS, COLORS);
+ for (i = 0; i < COLORS; i++)
+ mvaddstr(5 + COLORS, (i+1) * 8, colors[i]);
+ for (i = 0; i < COLORS; i++)
+ mvaddstr(6 + COLORS + i, 0, colors[i]);
+ for (i = 1; i < COLOR_PAIRS; i++)
+ {
+ init_pair(i, i % COLORS, i / COLORS);
+ attron(COLOR_PAIR(i) | A_BOLD);
+ mvaddstr(6 + COLORS + (i / COLORS), (i % COLORS + 1) * 8, "Hello");
+ attrset(A_NORMAL);
+ }
+
+ move(LINES - 1, 0);
+ addstr("Press any key to continue... ");
+ (void) getch();
+
+ erase();
+ endwin();
+}
+
+static void color_edit(void)
+/* display the color test pattern, without trying to edit colors */
+{
+ int i, c, value = 0, current = 0, field = 0, usebase = 0;
+
+ refresh();
+
+ for (i = 0; i < COLORS; i++)
+ init_pair(i, COLOR_WHITE, i);
+
+ do {
+ short red, green, blue;
+
+ attron(A_BOLD);
+ mvaddstr(0, 20, "Color RGB Value Editing");
+ attroff(A_BOLD);
+
+ for (i = 0; i < COLORS; i++)
+ {
+ mvprintw(2 + i, 0, "%c %-8s:",
+ (i == current ? '>' : ' '),
+ (i < sizeof(colors)/sizeof(colors[0]) ? colors[i] : ""));
+ attrset(COLOR_PAIR(i));
+ addstr(" ");
+ attrset(A_NORMAL);
+
+ /*
+ * Note: this refresh should *not* be necessary! It works around
+ * a bug in attribute handling that apparently causes the A_NORMAL
+ * attribute sets to interfere with the actual emission of the
+ * color setting somehow. This needs to be fixed.
+ */
+ refresh();
+
+ color_content(i, &red, &green, &blue);
+ addstr(" R = ");
+ if (current == i && field == 0) attron(A_STANDOUT);
+ printw("%04d", red);
+ if (current == i && field == 0) attrset(A_NORMAL);
+ addstr(", G = ");
+ if (current == i && field == 1) attron(A_STANDOUT);
+ printw("%04d", green);
+ if (current == i && field == 1) attrset(A_NORMAL);
+ addstr(", B = ");
+ if (current == i && field == 2) attron(A_STANDOUT);
+ printw("%04d", blue);
+ if (current == i && field == 2) attrset(A_NORMAL);
+ attrset(A_NORMAL);
+ addstr(")");
+ }
+
+ mvaddstr(COLORS + 3, 0,
+ "Use up/down to select a color, left/right to change fields.");
+ mvaddstr(COLORS + 4, 0,
+ "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
+
+ move(2 + current, 0);
+
+ switch (c = getch())
+ {
+ case KEY_UP:
+ current = (current == 0 ? (COLORS - 1) : current - 1);
+ value = 0;
+ break;
+
+ case KEY_DOWN:
+ current = (current == (COLORS - 1) ? 0 : current + 1);
+ value = 0;
+ break;
+
+ case KEY_RIGHT:
+ field = (field == 2 ? 0 : field + 1);
+ value = 0;
+ break;
+
+ case KEY_LEFT:
+ field = (field == 0 ? 2 : field - 1);
+ value = 0;
+ break;
+
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ do {
+ value = value * 10 + (c - '0');
+ c = getch();
+ } while
+ (isdigit(c));
+ if (c != '+' && c != '-' && c != '=')
+ beep();
+ else
+ ungetch(c);
+ break;
+
+ case '+':
+ usebase = 1;
+ goto changeit;
+
+ case '-':
+ value = -value;
+ usebase = 1;
+ goto changeit;
+
+ case '=':
+ usebase = 0;
+ changeit:
+ color_content(current, &red, &green, &blue);
+ if (field == 0)
+ red = red * usebase + value;
+ else if (field == 1)
+ green = green * usebase + value;
+ else if (field == 2)
+ blue = blue * usebase + value;
+ init_color(current, red, green, blue);
+ break;
+
+ case '?':
+ erase();
+ P(" RGB Value Editing Help");
+ P("");
+ P("You are in the RGB value editor. Use the arrow keys to select one of");
+ P("the fields in one of the RGB triples of the current colors; the one");
+ P("currently selected will be reverse-video highlighted.");
+ P("");
+ P("To change a field, enter the digits of the new value; they won't be");
+ P("echoed. Finish by typing `='; the change will take effect instantly.");
+ P("To increment or decrement a value, use the same procedure, but finish");
+ P("with a `+' or `-'.");
+ P("");
+ P("To quit, do `x' or 'q'");
+
+ move(LINES - 1, 0);
+ addstr("Press any key to continue... ");
+ (void) getch();
+ erase();
+ break;
+
+ case 'x':
+ case 'q':
+ break;
+
+ default:
+ beep();
+ break;
+ }
+ } while
+ (c != 'x' && c != 'q');
+
+ erase();
+ endwin();
+}
+
+/****************************************************************************
+ *
+ * Soft-key label test
+ *
+ ****************************************************************************/
+
+static void slk_test(void)
+/* exercise the soft keys */
+{
+ int c, fmt = 1;
+ char buf[9];
+
+ c = CTRL('l');
+ do {
+ switch(c)
+ {
+ case CTRL('l'):
+ erase();
+ attron(A_BOLD);
+ mvaddstr(0, 20, "Soft Key Exerciser");
+ attroff(A_BOLD);
+
+ move(2, 0);
+ P("Available commands are:");
+ P("");
+ P("^L -- refresh screen");
+ P("a -- activate or restore soft keys");
+ P("d -- disable soft keys");
+ P("c -- set centered format for labels");
+ P("l -- set left-justified format for labels");
+ P("r -- set right-justified format for labels");
+ P("[12345678] -- set label; labels are numbered 1 through 8");
+ P("e -- erase stdscr (should not erase labels)");
+ P("s -- test scrolling of shortened screen");
+ P("x, q -- return to main menu");
+ P("");
+ P("Note: if activating the soft keys causes your terminal to");
+ P("scroll up one line, your terminal auto-scrolls when anything");
+ P("is written to the last screen position. The ncurses code");
+ P("does not yet handle this gracefully.");
+ refresh();
+ /* fall through */
+
+ case 'a':
+ slk_restore();
+ break;
+
+ case 'e':
+ wclear(stdscr);
+ break;
+
+ case 's':
+ move(20, 0);
+ while ((c = getch()) != 'Q')
+ addch(c);
+ break;
+
+ case 'd':
+ slk_clear();
+ break;
+
+ case 'l':
+ fmt = 0;
+ break;
+
+ case 'c':
+ fmt = 1;
+ break;
+
+ case 'r':
+ fmt = 2;
+ break;
+
+ case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8':
+ (void) mvaddstr(20, 0, "Please enter the label value: ");
+ wgetnstr(stdscr, buf, 8);
+ slk_set((c - '0'), buf, fmt);
+ slk_refresh();
+ break;
+
+ case 'x':
+ case 'q':
+ goto done;
+
+ default:
+ beep();
+ }
+ } while
+ ((c = getch()) != EOF);
+
+ done:
+ erase();
+ endwin();
+}
+
+/****************************************************************************
+ *
+ * Alternate character-set stuff
+ *
+ ****************************************************************************/
+
+static void acs_display()
+/* display the ACS character set */
+{
+traceon();
+ erase();
+ attron(A_BOLD);
+ mvaddstr(0, 20, "Display of the ACS Character Set");
+ attroff(A_BOLD);
+ refresh();
+
+#define ACSY 5
+ 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);
+ mvaddstr(ACSY + 3, 0, "ACS_LRCORNER: "); addch(ACS_LRCORNER);
+ mvaddstr(ACSY + 4, 0, "ACS_RTEE: "); addch(ACS_RTEE);
+ mvaddstr(ACSY + 5, 0, "ACS_LTEE: "); addch(ACS_LTEE);
+ mvaddstr(ACSY + 6, 0, "ACS_BTEE: "); addch(ACS_BTEE);
+ mvaddstr(ACSY + 7, 0, "ACS_TTEE: "); addch(ACS_TTEE);
+ mvaddstr(ACSY + 8, 0, "ACS_HLINE: "); addch(ACS_HLINE);
+ mvaddstr(ACSY + 9, 0, "ACS_VLINE: "); addch(ACS_VLINE);
+ mvaddstr(ACSY + 10,0, "ACS_PLUS: "); addch(ACS_PLUS);
+ mvaddstr(ACSY + 11,0, "ACS_S1: "); addch(ACS_S1);
+ mvaddstr(ACSY + 12,0, "ACS_S9: "); addch(ACS_S9);
+
+ mvaddstr(ACSY + 0, 40, "ACS_DIAMOND: "); addch(ACS_DIAMOND);
+ mvaddstr(ACSY + 1, 40, "ACS_CKBOARD: "); addch(ACS_CKBOARD);
+ mvaddstr(ACSY + 2, 40, "ACS_DEGREE: "); addch(ACS_DEGREE);
+ mvaddstr(ACSY + 3, 40, "ACS_PLMINUS: "); addch(ACS_PLMINUS);
+ mvaddstr(ACSY + 4, 40, "ACS_BULLET: "); addch(ACS_BULLET);
+ mvaddstr(ACSY + 5, 40, "ACS_LARROW: "); addch(ACS_LARROW);
+ mvaddstr(ACSY + 6, 40, "ACS_RARROW: "); addch(ACS_RARROW);
+ mvaddstr(ACSY + 7, 40, "ACS_DARROW: "); addch(ACS_DARROW);
+ mvaddstr(ACSY + 8, 40, "ACS_UARROW: "); addch(ACS_UARROW);
+ mvaddstr(ACSY + 9, 40, "ACS_BOARD: "); addch(ACS_BOARD);
+ mvaddstr(ACSY + 10,40, "ACS_LANTERN: "); addch(ACS_LANTERN);
+ mvaddstr(ACSY + 11,40, "ACS_BLOCK: "); addch(ACS_BLOCK);
+
+ move(LINES - 1, 0);
+ addstr("Press any key to continue... ");
+ (void) getch();
+
+ erase();
+ endwin();
+}
+
+/****************************************************************************
+ *
+ * Windows and scrolling tester.
+ *
+ ****************************************************************************/
+
+typedef struct
+{
+ int y, x;
+}
+pair;
+
+static void report(void)
+/* report on the cursor's current position, then restore it */
+{
+ int y, x;
+
+ getyx(stdscr, y, x);
+ move(LINES - 1, COLS - 17);
+ printw("Y = %2d X = %2d", y, x);
+ move(y, x);
+}
+
+static pair *selectcell(uli, ulj, lri, lrj)
+/* arrows keys move cursor, return location at current on non-arrow key */
+int uli, ulj, lri, lrj; /* co-ordinates of corners */
+{
+ static pair res; /* result cell */
+ int si = lri - uli + 1; /* depth of the select area */
+ int sj = lrj - ulj + 1; /* width of the select area */
+ int i = 0, j = 0; /* offsets into the select area */
+
+ for (;;)
+ {
+ move(LINES - 1, COLS - 17);
+ printw("Y = %2d X = %2d", uli + i, ulj + j);
+ move(uli + i, ulj + j);
+
+ switch(getch())
+ {
+ case KEY_UP: i += si - 1; break;
+ case KEY_DOWN: i++; break;
+ case KEY_LEFT: j += sj - 1; break;
+ case KEY_RIGHT: j++; break;
+ default: res.y = uli + i; res.x = ulj + j; return(&res);
+ }
+ i %= si;
+ j %= sj;
+ }
+}
+
+static WINDOW *getwindow(void)
+/* Ask user for a window definition */
+{
+ WINDOW *rwindow, *bwindow;
+ pair ul, lr;
+
+ 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));
+ 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));
+
+ rwindow = newwin(lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
+
+ bwindow = newwin(lr.y - ul.y + 3, lr.x - ul.x + 3, ul.y - 1, ul.x - 1);
+ wborder(bwindow, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE,
+ 0, 0, 0, 0);
+ wrefresh(bwindow);
+ delwin(bwindow);
+
+ scrollok(rwindow, TRUE);
+/* immedok(rwindow); */
+ wrefresh(rwindow);
+
+ return(rwindow);
+}
+
+static void acs_and_scroll()
+/* Demonstrate windows */
+{
+ int c;
+ struct frame
+ {
+ struct frame *next, *last;
+ WINDOW *wind;
+ }
+ *oldw = (struct frame *)NULL, *current = (struct frame *)NULL, *neww;
+
+ refresh();
+ mvaddstr(LINES - 2, 0,
+ "F1 = make new window, F2 = next window, F3 = previous window");
+ mvaddstr(LINES - 1, 0,
+ "All other characters are echoed, windows should scroll.");
+
+ c = KEY_F(1);
+ do {
+ report();
+ if (current)
+ wrefresh(current->wind);
+
+ switch(c)
+ {
+ case KEY_F(1):
+ neww = (struct frame *) malloc(sizeof(struct frame));
+ neww->wind = getwindow();
+ if (oldw == NULL) /* First element, */
+ {
+ neww->next = neww; /* so point it at itself */
+ neww->last = neww;
+ current = neww;
+ }
+ else
+ {
+ neww->last = oldw; oldw->next = neww;
+ neww->next = current; current->last = neww;
+ }
+ oldw = neww;
+ keypad(neww->wind, TRUE);
+ break;
+
+ case KEY_F(2):
+ current = current->next;
+ break;
+
+ case KEY_F(3):
+ current = current->last;
+ break;
+
+ case KEY_F(4): /* undocumented --- use this to test area clears */
+ selectcell(0, 0, LINES - 1, COLS - 1);
+ clrtobot();
+ refresh();
+ break;
+
+ case '\r':
+ c = '\n';
+ /* FALLTHROUGH */
+
+ default:
+ waddch(current->wind, c);
+ break;
+ }
+ report();
+ wrefresh(current->wind);
+ } while
+ ((c = wgetch(current->wind)) != '\004');
+
+ erase();
+ endwin();
+}
+
+/****************************************************************************
+ *
+ * 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);
+ mvwaddstr(win, 10, 1, " Press any key to continue");
+ wrefresh(win);
+ wgetch(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];
+ WINDOW *subWin;
+ wclear (win);
+
+ w = win->_maxx;
+ h = win->_maxy;
+ bx = win->_begx;
+ by = win->_begy;
+ sw = w / 3;
+ sh = h / 3;
+ if((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL)
+ return;
+
+#ifdef A_COLOR
+ if (has_colors())
+ {
+ init_pair(2,COLOR_CYAN,COLOR_BLUE);
+ wattrset(subWin, COLOR_PAIR(2) | A_BOLD);
+ }
+ else
+ wattrset(subWin, A_BOLD);
+#else
+ wattrset(subWin, A_BOLD);
+#endif
+ box(subWin, ACS_VLINE, ACS_HLINE);
+ wrefresh(win);
+
+ nocbreak();
+ mvwaddstr(win, 2, 1, "Press some keys for 5 seconds");
+ mvwaddstr(win, 1, 1, "Pressing ^C should do nothing");
+ wrefresh(win);
+
+ for (i = 0; i < 5; i++) {
+ werase (subWin);
+ box(subWin, ACS_VLINE, ACS_HLINE);
+ mvwprintw (subWin, 1, 1, "Time = %d", i);
+ wrefresh(subWin);
+ sleep(1);
+ flushinp();
+ }
+
+ delwin (subWin);
+ werase(win);
+ flash();
+ wrefresh(win);
+ sleep(1);
+
+ mvwaddstr(win, 2, 1, "Press a key");
+ wmove(win, 9, 10);
+ wrefresh(win);
+ echo();
+ wgetch(win);
+ flushinp();
+
+ 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);
+
+#ifdef FOO
+ /*
+ * This test won't be portable until vsscanf() is
+ */
+ mvwaddstr(win, 6, 2, "Enter a number then a string separated by space");
+ echo();
+ mvwscanw(win, 7, 6, "%d %s", &num,buffer);
+ mvwprintw(win, 8, 6, "String: %s Number: %d", buffer,num);
+#endif /* FOO */
+
+ 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
+ *
+ ****************************************************************************/
+
+bool do_single_test(const char c)
+/* perform a single specified test */
+{
+ switch (c)
+ {
+ case 'a':
+ getch_test();
+ return(TRUE);
+
+ case 'b':
+ attr_test();
+ return(TRUE);
+
+ case 'c':
+ if (!has_colors())
+ (void) printf("This %s terminal does not support color.\n",
+ getenv("TERM"));
+ else
+ color_test();
+ return(TRUE);
+
+ case 'd':
+ if (!has_colors())
+ (void) printf("This %s terminal does not support color.\n",
+ getenv("TERM"));
+ else if (!can_change_color())
+ (void) printf("This %s terminal has hardwired color values.\n",
+ getenv("TERM"));
+ else
+ color_edit();
+ return(TRUE);
+
+ case 'e':
+ slk_test();
+ return(TRUE);
+
+ case 'f':
+ acs_display();
+ return(TRUE);
+
+ case 'g':
+ acs_and_scroll();
+ return(TRUE);
+
+ case 'p':
+ demo_pad();
+ return(TRUE);
+
+ case 'i':
+ 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");
+ (void) puts("key letter of the choice (the letter to left of the =)");
+ (void) puts("at the > prompt. The commands `x' or `q' will exit.");
+ return(TRUE);
+ }
+
+ return(FALSE);
+}
+
+int main(const int argc, const char *argv[])
+{
+ char buf[BUFSIZ];
+
+ /* enable debugging */
+ traceon();
+
+ /* tell it we're going to play with soft keys */
+ slk_init(1);
+
+ /* we must initialize the curses data structure only once */
+ initscr();
+
+ /* tests, in general, will want these modes */
+ start_color();
+ cbreak();
+ noecho();
+ scrollok(stdscr, TRUE);
+ keypad(stdscr, TRUE);
+
+ /*
+ * Return to terminal mode, so we're guaranteed of being able to
+ * select terminal commands even if the capabilities are wrong.
+ */
+ endwin();
+
+ (void) puts("Welcome to ncurses. Press ? for help.");
+
+ do {
+ (void) puts("This is the ncurses main menu");
+ (void) puts("a = character input test");
+ (void) puts("b = character attribute test");
+ (void) puts("c = color test pattern");
+ (void) puts("d = edit RGB color values");
+ (void) puts("e = exercise soft keys");
+ (void) puts("f = display ACS characters");
+ (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) fgets(buf, BUFSIZ, stdin);
+
+ if (do_single_test(buf[0])) {
+ clear();
+ refresh();
+ endwin();
+ continue;
+ }
+ } while
+ (buf[0] != 'q' && buf[0] != 'x');
+
+ exit(0);
+}
+
+/* ncurses.c ends here */
diff --git a/lib/libncurses/TESTS/newdemo.c b/lib/libncurses/TESTS/newdemo.c
new file mode 100644
index 0000000..97c368d
--- /dev/null
+++ b/lib/libncurses/TESTS/newdemo.c
@@ -0,0 +1,350 @@
+/* $Header: c:/curses/demos/RCS/newdemo.c%v 2.0 1992/11/15 03:32:03 MH Rel $
+ *
+ * newdemo.c - A demo program using PDCurses. The program illustrate
+ * the use of colours for text output.
+ */
+
+#include <stdio.h>
+#include <signal.h>
+#include <time.h>
+#include <ncurses.h>
+
+#define delay_output(x)
+
+/*
+ * The Australian map
+ */
+char *AusMap[16] =
+{
+ " A A ",
+ " N.T. AAAAA AAAA ",
+ " AAAAAAAAAAA AAAAAAAA ",
+ " AAAAAAAAAAAAAAAAAAAAAAAAA Qld.",
+ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAA ",
+ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ",
+ " AAAAAAAAAAAAAAAAAAAAAAAAAAAA ",
+ " AAAAAAAAAAAAAAAAAAAAAAAAA N.S.W.",
+ "W.A. AAAAAAAAA AAAAAA Vic.",
+ " AAA S.A. AA",
+ " A Tas.",
+ ""
+};
+
+/*
+ * Funny messages
+ */
+#define NMESSAGES 6
+
+char *messages[] =
+{
+ "Hello from the Land Down Under",
+ "The Land of crocs. and a big Red Rock",
+ "Where the sunflower runs along the highways",
+ "the dusty red roads lead one to loneliness",
+ "Blue sky in the morning and",
+ "freezing nights and twinkling stars",
+ ""
+};
+
+/*
+ * Main driver
+ */
+main()
+{
+WINDOW *win;
+int w, x, y, i, j, c, len;
+time_t t;
+char buffer[80], *message;
+int width, height;
+chtype save[80];
+void trap();
+
+ initscr();
+ start_color();
+ cbreak();
+ signal(SIGINT, trap);
+ width = 48;
+ height = 14; /* Create a drawing window */
+ win = newwin(height, width, (LINES-height)/2, (COLS-width)/2);
+ if(win == NULL)
+ { endwin();
+ return 1;
+ }
+
+ while(1)
+ { init_pair(1,COLOR_WHITE,COLOR_BLUE);
+ wattrset(win, COLOR_PAIR(1));
+ werase(win);
+
+ init_pair(2,COLOR_RED,COLOR_RED);
+ wattrset(win, COLOR_PAIR(2));
+ box(win, ACS_VLINE, ACS_HLINE);
+ wrefresh(win);
+ /* Do ramdom output of a character */
+ wattrset(win, COLOR_PAIR(1));
+ c = 'a';
+ for(i=0; i < 5000; ++i)
+ { x = rand() % (width-2) + 1;
+ y = rand() % (height-2) + 1;
+ mvwaddch(win, y, x, c);
+ wrefresh(win);
+ nodelay(win,TRUE);
+ if (wgetch(win) != ERR)
+ break;
+ if(i == 2000)
+ { c = 'b';
+ init_pair(3,COLOR_CYAN,COLOR_YELLOW);
+ wattron(win, COLOR_PAIR(3));
+ }
+ }
+
+ SubWinTest(win);
+ /* Erase and draw green window */
+ init_pair(4,COLOR_YELLOW,COLOR_GREEN);
+ wattrset(win, COLOR_PAIR(4) | A_BOLD);
+ werase(win);
+ wrefresh(win);
+ /* Draw RED bounding box */
+ wattrset(win, COLOR_PAIR(2));
+ box(win, ' ', ' ');
+ wrefresh(win);
+ /* Display Australia map */
+ wattrset(win, COLOR_PAIR(4) | A_BOLD);
+ i = 0;
+ while(*AusMap[i])
+ { mvwaddstr(win, i+1, 8, AusMap[i]);
+ wrefresh(win);
+ delay_output(100);
+ ++i;
+ }
+
+ init_pair(5,COLOR_BLUE,COLOR_WHITE);
+ wattrset(win, COLOR_PAIR(5) | A_BLINK);
+ mvwaddstr(win, height-2, 6, " PDCurses 2.1 for DOS, OS/2 and Unix");
+ wrefresh(win);
+
+ /* Draw running messages */
+ init_pair(6,COLOR_YELLOW,COLOR_WHITE);
+ wattrset(win, COLOR_PAIR(6));
+ message = messages[0];
+ len = strlen(message);
+ j = 0;
+ i = 2;
+ w = width-2;
+ while(j < NMESSAGES)
+ { strncpy(buffer, message, w - i);
+ buffer[w-i] = 0;
+ mvwaddstr(win, height/2, i, buffer);
+ if(w - i < len)
+ { memset(buffer, ' ', i);
+ strcpy(buffer, message + (w - i));
+ buffer[strlen(buffer)] = ' ';
+ buffer[i-2] = '\0';
+ mvwaddstr(win, height/2, 2, buffer);
+ }
+ wrefresh(win);
+ nodelay(win,TRUE);
+ if (wgetch(win) != ERR)
+ { flushinp();
+ break;
+ }
+ mvwaddch(win, height/2, i, ' ');
+ i = ++i % w;
+ if(i < 2)
+ { message = messages[++j%NMESSAGES];
+ memset(buffer, ' ', w-2);
+ buffer[w-2] = 0;
+ mvwaddstr(win, height/2, 2, buffer);
+ i = 2;
+ }
+ delay_output(300);
+ }
+
+ j = 0;
+ /* Draw running As across in RED */
+ init_pair(7,COLOR_RED,COLOR_GREEN);
+ wattron(win, COLOR_PAIR(7));
+ for(i=2; i < width - 4; ++i)
+ { c = mvwinch(win, 4, i);
+ save[j++] = c;
+ c = c & 0x7f;
+ mvwaddch(win, 4, i, c);
+ }
+ wrefresh(win);
+
+ /* Put a message up wait for a key */
+ i = height-2;
+ wattrset(win, COLOR_PAIR(5));
+ mvwaddstr(win, i, 5, " Type a key to continue or 'Q' to quit ");
+ wrefresh(win);
+
+ if(WaitForUser() == 1)
+ break;
+
+ j = 0; /* Restore the old line */
+ for(i=2; i < width - 4; ++i)
+ mvwaddch(win, 4, i, save[j++]);
+ wrefresh(win);
+
+ BouncingBalls(win);
+ /* Put a message up wait for a key */
+ i = height-2;
+ wattrset(win, COLOR_PAIR(5));
+ mvwaddstr(win, i, 5, " Type a key to continue or 'Q' to quit ");
+ wrefresh(win);
+ if(WaitForUser() == 1)
+ break;
+ }
+exit:
+ endwin();
+ return 0;
+}
+
+/*
+ * Test sub windows
+ */
+SubWinTest(WINDOW *win)
+{
+int w, h, sw, sh, bx, by;
+WINDOW *swin1, *swin2, *swin3;
+
+ w = win->_maxx;
+ h = win->_maxy;
+ bx = win->_begx;
+ by = win->_begy;
+ sw = w / 3;
+ sh = h / 3;
+ if((swin1 = subwin(win, sh, sw, by+3, bx+5)) == NULL)
+ return 1;
+ if((swin2 = subwin(win, sh, sw, by+4, bx+8)) == NULL)
+ return 1;
+ if((swin3 = subwin(win, sh, sw, by+5, bx+11)) == NULL)
+ return 1;
+
+ init_pair(8,COLOR_RED,COLOR_BLUE);
+ wattrset(swin1, COLOR_PAIR(8));
+ werase(swin1);
+ mvwaddstr(swin1, 0, 3, "Sub-window 1");
+ wrefresh(swin1);
+
+ init_pair(8,COLOR_CYAN,COLOR_MAGENTA);
+ wattrset(swin2, COLOR_PAIR(8));
+ werase(swin2);
+ mvwaddstr(swin2, 0, 3, "Sub-window 2");
+ wrefresh(swin2);
+
+ init_pair(8,COLOR_YELLOW,COLOR_GREEN);
+ wattrset(swin3, COLOR_PAIR(8));
+ werase(swin3);
+ mvwaddstr(swin3, 0, 3, "Sub-window 3");
+ wrefresh(swin3);
+
+ delwin(swin1);
+ delwin(swin2);
+ delwin(swin3);
+ WaitForUser();
+ return 0;
+}
+
+/*
+ * Bouncing balls
+ */
+BouncingBalls(WINDOW *win)
+{
+chtype c1, c2, c3;
+int w, h;
+int x1, y1, xd1, yd1;
+int x2, y2, xd2, yd2;
+int x3, y3, xd3, yd3;
+
+ w = win->_maxx;
+ h = win->_maxy;
+ x1 = 2 + rand() % (w - 4);
+ y1 = 2 + rand() % (h - 4);
+ x2 = 2 + rand() % (w - 4);
+ y2 = 2 + rand() % (h - 4);
+ x3 = 2 + rand() % (w - 4);
+ y3 = 2 + rand() % (h - 4);
+ xd1 = 1; yd1 = 1;
+ xd2 = 1; yd2 = 0;
+ xd3 = 0; yd3 = 1;
+ nodelay(win,TRUE);
+ while(wgetch(win) == ERR)
+ { x1 = xd1 > 0 ? ++x1 : --x1;
+ if(x1 <= 1 || x1 >= w - 2)
+ xd1 = xd1 ? 0 : 1;
+ y1 = yd1 > 0 ? ++y1 : --y1;
+ if(y1 <= 1 || y1 >= h - 2)
+ yd1 = yd1 ? 0 : 1;
+
+ x2 = xd2 > 0 ? ++x2 : --x2;
+ if(x2 <= 1 || x2 >= w - 2)
+ xd2 = xd2 ? 0 : 1;
+ y2 = yd2 > 0 ? ++y2 : --y2;
+ if(y2 <= 1 || y2 >= h - 2)
+ yd2 = yd2 ? 0 : 1;
+
+ x3 = xd3 > 0 ? ++x3 : --x3;
+ if(x3 <= 1 || x3 >= w - 2)
+ xd3 = xd3 ? 0 : 1;
+ y3 = yd3 > 0 ? ++y3 : --y3;
+ if(y3 <= 1 || y3 >= h - 2)
+ yd3 = yd3 ? 0 : 1;
+
+ c1 = mvwinch(win, y1, x1);
+ c2 = mvwinch(win, y2, x2);
+ c3 = mvwinch(win, y3, x3);
+
+ init_pair(8,COLOR_RED,COLOR_BLUE);
+ wattrset(win, COLOR_PAIR(8));
+ mvwaddch(win, y1, x1, 'O');
+ init_pair(8,COLOR_BLUE,COLOR_RED);
+ wattrset(win, COLOR_PAIR(8));
+ mvwaddch(win, y2, x2, '*');
+ init_pair(8,COLOR_YELLOW,COLOR_WHITE);
+ wattrset(win, COLOR_PAIR(8));
+ mvwaddch(win, y3, x3, '@');
+ wmove(win, 0, 0);
+ wrefresh(win);
+ mvwaddch(win, y1, x1, c1);
+ mvwaddch(win, y2, x2, c2);
+ mvwaddch(win, y3, x3, c3);
+ delay_output(150);
+ }
+ return 0;
+}
+
+/*
+ * Wait for user
+ */
+int WaitForUser()
+{
+ time_t t;
+ chtype key;
+
+ nodelay(stdscr,TRUE);
+ t = time((time_t *)0);
+ while(1)
+ {
+ if ((key = getch()) != ERR)
+ {
+ if (key == 'q' || key == 'Q')
+ return 1;
+ else
+ return 0;
+ }
+ if (time((time_t *)0) - t > 5)
+ return 0;
+ }
+}
+
+/*
+ * Trap interrupt
+ */
+void trap()
+{
+ endwin();
+ exit(0);
+}
+
+/* End of DEMO.C */
diff --git a/lib/libncurses/TESTS/over.c b/lib/libncurses/TESTS/over.c
new file mode 100644
index 0000000..530e48d
--- /dev/null
+++ b/lib/libncurses/TESTS/over.c
@@ -0,0 +1,120 @@
+/*********************************************************************
+ * [program] overwrite() - Play with overwrite() function to *
+ * attempt pop-up windows. *
+ * ----------------------------------------------------------------- *
+ * [written] 1-Feb-1993 by Neal Ensor (ensor@cs.utk.edu) *
+ * ----------------------------------------------------------------- *
+ * [notes] Originally written on SVR4 UNIX, then recompiled on *
+ * Linux (Slackware 1.1.1, ncurses 1.8.1) *
+ * ----------------------------------------------------------------- *
+ * [problem] On ncurses, the overwrite() function doesn't seem to *
+ * overwrite. Maybe I'm missing something, but this *
+ * program in SVR4 displays three windows, waits for a *
+ * keypress, then removes the top window. With ncurses, *
+ * nothing changes on the display. *
+ *********************************************************************/
+
+# include <ncurses.h> /* ncurses include lives here */
+
+main()
+{
+ /****************************************************************
+ * Declare three little window pointers... *
+ ****************************************************************/
+ WINDOW *win, *win1, *win2;
+
+ /****************************************************************
+ * Set up the screen... *
+ ****************************************************************/
+ initscr();
+ traceon();
+ noecho();
+ nonl();
+ cbreak();
+ refresh();
+
+ /****************************************************************
+ * Draw three overlapping windows. *
+ ****************************************************************/
+ win=newwin(6,45, 6,6);
+ win1=newwin(10,20,5,5);
+ win2=newwin(10,30,7,7);
+
+ /****************************************************************
+ * Box them, and print a hidden message... *
+ ****************************************************************/
+ box(win, 0, 0);
+ box(win1, 0, 0);
+ box(win2, 0, 0);
+ mvwprintw(win1, 6,6, "Hey!");
+ mvwaddch(win, 1, 1, '0');
+ mvwaddch(win1, 1, 1, '1');
+ mvwaddch(win2, 1, 1, '2');
+ wnoutrefresh(win);
+ wnoutrefresh(win1);
+ wnoutrefresh(win2);
+ doupdate();
+
+ /****************************************************************
+ * Await a keypress to show what we've done so far. *
+ ****************************************************************/
+ getch();
+
+ /****************************************************************
+ * Now, overwrite win2 with contents of all lower windows IN *
+ * ORDER from the stdscr up... *
+ ****************************************************************/
+ if (overwrite(stdscr, win2) == ERR)
+ fprintf(stderr, "overwrite(stdscr, win2) failed!\n");
+
+ touchwin(stdscr); wnoutrefresh(stdscr);
+ touchwin(win); wnoutrefresh(win);
+ touchwin(win1); wnoutrefresh(win1);
+ touchwin(win2); wnoutrefresh(win2);
+ doupdate();
+
+ getch();
+ if (overwrite(win, win2) == ERR)
+ fprintf(stderr, "overwrite(win, win2) failed!\n");
+
+ touchwin(stdscr); wnoutrefresh(stdscr);
+ touchwin(win); wnoutrefresh(win);
+ touchwin(win1); wnoutrefresh(win1);
+ touchwin(win2); wnoutrefresh(win2);
+ doupdate();
+
+ getch();
+ if (overwrite(win1, win2) == ERR)
+ fprintf(stderr, "overwrite(win1, win2) failed!\n");
+
+ /****************************************************************
+ * Perform touches, and hidden refreshes on each window. *
+ * ------------------------------------------------------------ *
+ * NOTE: If you replace the wnoutrefresh() call with wrefresh()*
+ * you can see all windows being redrawn untouched. *
+ ****************************************************************/
+ touchwin(stdscr); wnoutrefresh(stdscr);
+ touchwin(win); wnoutrefresh(win);
+ touchwin(win1); wnoutrefresh(win1);
+ touchwin(win2); wnoutrefresh(win2);
+ doupdate();
+
+ /****************************************************************
+ * At this point, win2 should be "destroyed"; having all other *
+ * window contents overwritten onto it. The doupdate() should *
+ * effectively remove it from the screen, leaving the others *
+ * untouched. On SVR4, this happens, but not with ncurses. *
+ * I'd suspect something in overwrite() causes this, as nothing *
+ * appears to be overwritten after the calls, with no errors *
+ * being reported. This was compiled on my Linux from Slackware*
+ * 1.1.1, with ncurses1.8.1 recompiled on it, using the console *
+ * entry from the "new" terminfo from ncurses1.8.1. *
+ ****************************************************************/
+ getch();
+
+ /****************************************************************
+ * Clean up our act and exit. *
+ ****************************************************************/
+ endwin();
+}
+
diff --git a/lib/libncurses/TESTS/rain.c b/lib/libncurses/TESTS/rain.c
new file mode 100644
index 0000000..83951ae
--- /dev/null
+++ b/lib/libncurses/TESTS/rain.c
@@ -0,0 +1,96 @@
+#include <ncurses.h>
+#include <signal.h>
+/* rain 11/3/1980 EPS/CITHEP */
+
+#define cursor(col,row) move(row,col)
+
+float ranf();
+void onsig();
+
+main(argc,argv)
+int argc;
+char *argv[];
+{
+int x, y, j;
+static int xpos[5], ypos[5];
+float r;
+float c;
+
+ for (j=SIGHUP;j<=SIGTERM;j++)
+ if (signal(j,SIG_IGN)!=SIG_IGN) signal(j,onsig);
+
+ initscr();
+ nl();
+ noecho();
+ r = (float)(LINES - 4);
+ c = (float)(COLS - 4);
+ for (j=5;--j>=0;) {
+ xpos[j]=(int)(c* ranf())+2;
+ ypos[j]=(int)(r* ranf())+2;
+ }
+ for (j=0;;) {
+ x=(int)(c*ranf())+2;
+ y=(int)(r*ranf())+2;
+
+ cursor(x,y); addch('.');
+
+ cursor(xpos[j],ypos[j]); addch('o');
+
+ if (j==0) j=4; else --j;
+ cursor(xpos[j],ypos[j]); addch('O');
+
+ if (j==0) j=4; else --j;
+ cursor(xpos[j],ypos[j]-1);
+ addch('-');
+ cursor(xpos[j]-1,ypos[j]);
+ addstr("|.|");
+ cursor(xpos[j],ypos[j]+1);
+ addch('-');
+
+ if (j==0) j=4; else --j;
+ cursor(xpos[j],ypos[j]-2);
+ addch('-');
+ cursor(xpos[j]-1,ypos[j]-1);
+ addstr("/ \\");
+ cursor(xpos[j]-2,ypos[j]);
+ addstr("| O |");
+ cursor(xpos[j]-1,ypos[j]+1);
+ addstr("\\ /");
+ cursor(xpos[j],ypos[j]+2);
+ addch('-');
+
+ if (j==0) j=4; else --j;
+ cursor(xpos[j],ypos[j]-2);
+ addch(' ');
+ cursor(xpos[j]-1,ypos[j]-1);
+ addstr(" ");
+ cursor(xpos[j]-2,ypos[j]);
+ addstr(" ");
+ cursor(xpos[j]-1,ypos[j]+1);
+ addstr(" ");
+ cursor(xpos[j],ypos[j]+2);
+ addch(' ');
+ xpos[j]=x; ypos[j]=y;
+ refresh();
+ }
+}
+
+void
+onsig(n)
+int n;
+{
+ endwin();
+ exit(0);
+}
+
+float
+ranf()
+{
+ float rv;
+ long r = rand();
+
+ r &= 077777;
+ rv =((float)r/32767.);
+ return rv;
+}
+
diff --git a/lib/libncurses/TESTS/scroll.c b/lib/libncurses/TESTS/scroll.c
new file mode 100644
index 0000000..428a064
--- /dev/null
+++ b/lib/libncurses/TESTS/scroll.c
@@ -0,0 +1,30 @@
+#include <ncurses.h>
+
+main()
+{
+int i;
+
+ initscr();
+ noecho();
+ scrollok(stdscr, TRUE);
+ setscrreg(0, 9);
+ mvaddstr(0,0,"aaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
+ mvaddstr(1,0,"bbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
+ mvaddstr(2,0,"ccccccccccccccccccccccccccccc");
+ mvaddstr(3,0,"ddddddddddddddddddddddddddddd");
+ mvaddstr(4,0,"eeeeeeeeeeeeeeeeeeeeeeeeeeeee");
+ mvaddstr(5,0,"fffffffffffffffffffffffffffff");
+ mvaddstr(6,0,"ggggggggggggggggggggggggggggg");
+ mvaddstr(7,0,"hhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
+ mvaddstr(8,0,"iiiiiiiiiiiiiiiiiiiiiiiiiiiii");
+ mvaddstr(9,0,"jjjjjjjjjjjjjjjjjjjjjjjjjjjjj");
+ refresh();
+ for (i = 0; i < 4; i++) {
+ getch();
+ scrl(-1);
+ refresh();
+ }
+ getch();
+ endwin();
+
+}
diff --git a/lib/libncurses/TESTS/scroll2.c b/lib/libncurses/TESTS/scroll2.c
new file mode 100644
index 0000000..53abaa3
--- /dev/null
+++ b/lib/libncurses/TESTS/scroll2.c
@@ -0,0 +1,91 @@
+#include <ncurses.h>
+#define ROWS 20
+#define scroll_window wscrl
+
+main()
+{
+ int i;
+ WINDOW * w;
+
+
+ initscr();
+ cbreak();
+ noecho();
+ w = newwin (ROWS, 35, 2, 25);
+ scrollok(w, TRUE);
+ wsetscrreg(w, 0, ROWS-1);
+
+#ifdef LELE
+ mvaddstr (0, 0, "With my function");
+#else
+ mvaddstr (0, 0, "With the original wscrl");
+#endif
+ refresh();
+
+
+ for (i=0; i<ROWS-1; i++)
+ {
+ mvwprintw (w, i, 0, "Line number %d", i);
+ }
+ mvwaddstr (w, ROWS-1, 0, "Moving one line at a time");
+ wrefresh(w);
+ for (i = 0; i < 4; i++) {
+ getch();
+ scroll_window (w, 1);
+ wrefresh(w);
+ }
+ for (i = 0; i < 4; i++) {
+ getch();
+ scroll_window (w, -1);
+ wrefresh(w);
+ }
+ getch();
+ wclear (w);
+
+
+ for (i=0; i<ROWS-1; i++)
+ {
+ mvwprintw (w, i, 0, "Line number %d", i);
+ }
+ mvwaddstr (w, ROWS-1, 0, "Moving two line at a time");
+#ifndef LELE
+ mvaddstr (0, 30, "** THIS FAILS ON MY MACHINE WITH A BUS ERROR
+**");
+#endif
+
+
+ wrefresh(w);
+ for (i = 0; i < 4; i++) {
+ getch();
+ scroll_window (w, 2);
+ wrefresh(w);
+ }
+ for (i = 0; i < 4; i++) {
+ getch();
+ scroll_window (w, -2);
+ wrefresh(w);
+ }
+ getch();
+ wclear (w);
+ for (i=0; i<ROWS-1; i++)
+ {
+ mvwprintw (w, i, 0, "Line number %d", i);
+ }
+ mvwaddstr (w, ROWS-1, 0, "Moving three line at a time");
+ wrefresh(w);
+ for (i = 0; i < 4; i++) {
+ getch();
+ scroll_window (w, 3);
+ wrefresh(w);
+ }
+ for (i = 0; i < 4; i++) {
+ getch();
+ scroll_window (w, -3);
+ wrefresh(w);
+ }
+ getch();
+
+
+ endwin();
+}
+
diff --git a/lib/libncurses/TESTS/scroll3.c b/lib/libncurses/TESTS/scroll3.c
new file mode 100644
index 0000000..1d63c46
--- /dev/null
+++ b/lib/libncurses/TESTS/scroll3.c
@@ -0,0 +1,51 @@
+#include <ncurses.h>
+
+main(int argc, char **argv)
+{
+ WINDOW *w, *x;
+
+ initscr();
+ w = newwin(0, 0, 0, 0);
+ if (argc > 2)
+ x = newwin(0, 0, 0, 0);
+ scrollok(w, TRUE);
+ if (argc > 2)
+ scrollok(x, TRUE);
+ idlok(w, TRUE);
+ if (argc > 2)
+ idlok(x, TRUE);
+ wmove(w, LINES - 1, 0);
+ waddstr(w, "test 1 in w");
+ wrefresh(w);
+ sleep(1);
+ if (argc == 2 || argc == 4)
+ {
+ waddch(w, '\n');
+ sleep(1);
+ waddch(w, '\n');
+ sleep(1);
+ waddch(w, '\n');
+ sleep(1);
+ beep();
+ wrefresh(w);
+ }
+ sleep(1);
+ if (argc > 2)
+ {
+ wmove(x, LINES - 1, 0);
+ waddstr(x, "test 2 in x");
+ sleep(1);
+ waddch(x, '\n');
+ sleep(1);
+ waddch(x, '\n');
+ sleep(1);
+ waddch(x, '\n');
+ sleep(1);
+ beep();
+ wrefresh(w);
+ sleep(1);
+ }
+ endwin();
+ return 0;
+}
+
diff --git a/lib/libncurses/TESTS/test.c b/lib/libncurses/TESTS/test.c
new file mode 100644
index 0000000..1fc3e6e
--- /dev/null
+++ b/lib/libncurses/TESTS/test.c
@@ -0,0 +1,27 @@
+
+#include <ncurses.h>
+
+main()
+{
+int x, y;
+
+ initscr();
+ cbreak();
+ nodelay(stdscr, TRUE);
+
+ for (y = 0; y < 43; y++)
+ for (x =0; x < 132; x++) {
+ move(y,x);
+ printw("X");
+ refresh();
+ if (!getch()) {
+ beep();
+ sleep(1);
+ }
+ }
+
+ nocbreak();
+ endwin();
+}
+
+
diff --git a/lib/libncurses/TESTS/testcurs.c b/lib/libncurses/TESTS/testcurs.c
new file mode 100644
index 0000000..3c92027
--- /dev/null
+++ b/lib/libncurses/TESTS/testcurs.c
@@ -0,0 +1,532 @@
+/*
+ *
+ * This is a test program for the PDCurses screen package for IBM PC type
+ * machines.
+ * This program was written by John Burnell (johnb@kea.am.dsir.govt.nz)
+ *
+ */
+
+#include <stdio.h>
+#include <ncurses.h>
+
+#ifdef __STDC__
+void inputTest (WINDOW *);
+void scrollTest (WINDOW *);
+void introTest (WINDOW *);
+int initTest (WINDOW **);
+void outputTest (WINDOW *);
+void padTest (WINDOW *);
+void resizeTest (WINDOW *);
+void display_menu(int,int);
+#else
+void inputTest ();
+void scrollTest ();
+void introTest ();
+int initTest ();
+void outputTest ();
+void padTest ();
+void resizeTest ();
+void display_menu();
+#endif
+
+struct commands
+{
+ char *text;
+#ifdef __STDC__
+ void (*function)(WINDOW *);
+#else
+ void (*function)();
+#endif
+};
+typedef struct commands COMMAND;
+#define MAX_OPTIONS 6
+COMMAND command[MAX_OPTIONS] =
+{
+ {"Intro Test",introTest},
+ {"Pad Test",padTest},
+ {"Resize Test",resizeTest},
+ {"Scroll Test",scrollTest},
+ {"Input Test",inputTest},
+ {"Output Test",outputTest}
+};
+
+int width, height;
+
+main()
+{
+WINDOW *win;
+int key,old_option=(-1),new_option=0;
+bool quit=FALSE;
+
+#ifdef PDCDEBUG
+ PDC_debug("testcurs started\n");
+#endif
+ if (!initTest (&win)) {return 1;}
+
+#ifdef A_COLOR
+ if (has_colors())
+ {
+ init_pair(1,COLOR_WHITE,COLOR_BLUE);
+ wattrset(win, COLOR_PAIR(1));
+ }
+ else
+ wattrset(win, A_REVERSE);
+#else
+ wattrset(win, A_REVERSE);
+#endif
+
+ erase();
+ display_menu(old_option,new_option);
+ while(1)
+ {
+ noecho();
+ keypad(stdscr,TRUE);
+ raw();
+ key = getch();
+ switch(key)
+ {
+ case 10:
+ case 13:
+ case KEY_ENTER:
+ erase();
+ refresh();
+ (*command[new_option].function)(win);
+ erase();
+ display_menu(old_option,new_option);
+ break;
+ case KEY_UP:
+ new_option = (new_option == 0) ? new_option : new_option-1;
+ display_menu(old_option,new_option);
+ break;
+ case KEY_DOWN:
+ new_option = (new_option == MAX_OPTIONS-1) ? new_option : new_option+1;
+ display_menu(old_option,new_option);
+ break;
+ case 'Q':
+ case 'q':
+ quit = TRUE;
+ break;
+ default: break;
+ }
+ if (quit == TRUE)
+ break;
+ }
+
+ delwin (win);
+
+ endwin();
+ return 0;
+}
+#ifdef __STDC__
+void Continue (WINDOW *win)
+#else
+void Continue (win)
+WINDOW *win;
+#endif
+{
+ wmove(win, 10, 1);
+/* wclrtoeol(win);
+*/ mvwaddstr(win, 10, 1, " Press any key to continue");
+ wrefresh(win);
+ raw();
+ wgetch(win);
+}
+#ifdef __STDC_
+int initTest (WINDOW **win)
+#else
+int initTest (win)
+WINDOW **win;
+#endif
+{
+#ifdef PDCDEBUG
+ PDC_debug("initTest called\n");
+#endif
+ initscr();
+#ifdef PDCDEBUG
+ PDC_debug("after initscr()\n");
+#endif
+#ifdef A_COLOR
+ if (has_colors())
+ start_color();
+#endif
+ width = 60;
+ height = 13; /* Create a drawing window */
+ *win = newwin(height, width, (LINES-height)/2, (COLS-width)/2);
+ if(*win == NULL)
+ { endwin();
+ return 1;
+ }
+}
+#ifdef __STDC__
+void introTest (WINDOW *win)
+#else
+void introTest (win)
+WINDOW *win;
+#endif
+{
+ beep ();
+ werase(win);
+
+ box(win, ACS_VLINE, ACS_HLINE);
+ wrefresh(win);
+ cbreak ();
+ mvwaddstr(win, 1, 1, "You should have rectangle in the middle of the screen");
+ mvwaddstr(win, 2, 1, "You should have heard a beep");
+ Continue(win);
+ return;
+}
+#ifdef __STDC__
+void scrollTest (WINDOW *win)
+#else
+void scrollTest (win)
+WINDOW *win;
+#endif
+{
+ int i;
+ int OldX, OldY;
+ char *Message = "The window will now scroll slowly";
+
+ mvwprintw (win, height - 2, 1, Message);
+ wrefresh (win);
+ scrollok(win, TRUE);
+ for (i = 1; i <= height; i++) {
+ usleep (250);
+ scroll(win);
+ wrefresh (win);
+ };
+
+ getmaxyx (win, OldY, OldX);
+ mvwprintw (win, 6, 1, "The top of the window will scroll");
+ wmove (win, 1, 1);
+ wsetscrreg (win, 0, 4);
+ box(win, ACS_VLINE, ACS_HLINE);
+ wrefresh (win);
+ for (i = 1; i <= 5; i++) {
+ usleep (500);
+ scroll(win);
+ wrefresh (win);
+ };
+ wsetscrreg (win, 0, --OldY);
+
+}
+#ifdef __STDC__
+void inputTest (WINDOW *win)
+#else
+void inputTest (win)
+WINDOW *win;
+#endif
+{
+ int w, h, bx, by, sw, sh, i, c,num;
+ char buffer [80];
+ WINDOW *subWin;
+ wclear (win);
+
+ w = win->_maxx;
+ h = win->_maxy;
+ bx = win->_begx;
+ by = win->_begy;
+ sw = w / 3;
+ sh = h / 3;
+ if((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL)
+ return;
+
+#ifdef A_COLOR
+ if (has_colors())
+ {
+ init_pair(2,COLOR_CYAN,COLOR_BLUE);
+ wattrset(subWin, COLOR_PAIR(2) | A_BOLD);
+ }
+ else
+ wattrset(subWin, A_BOLD);
+#else
+ wattrset(subWin, A_BOLD);
+#endif
+ box(subWin, ACS_VLINE, ACS_HLINE);
+ wrefresh(win);
+
+ nocbreak();
+ mvwaddstr(win, 2, 1, "Press some keys for 5 seconds");
+ mvwaddstr(win, 1, 1, "Pressing ^C should do nothing");
+ wrefresh(win);
+
+ for (i = 0; i < 5; i++) {
+ werase (subWin);
+ box(subWin, ACS_VLINE, ACS_HLINE);
+ mvwprintw (subWin, 1, 1, "Time = %d", i);
+ wrefresh(subWin);
+ usleep(1000);
+ flushinp();
+ }
+
+ delwin (subWin);
+ werase(win);
+ flash();
+ wrefresh(win);
+ usleep(500);
+
+ mvwaddstr(win, 2, 1, "Press a key, followed by ENTER");
+ wmove(win, 9, 10);
+ wrefresh(win);
+ echo();
+ noraw();
+ wgetch(win);
+ flushinp();
+
+ 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);
+ raw();
+ 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);
+ mvwaddstr(win, 6, 2, "Enter a number then a string seperated by space");
+ echo();
+ noraw();
+ mvwscanw(win, 7, 6, "%d %s", &num,buffer);
+ mvwprintw(win, 8, 6, "String: %s Number: %d", buffer,num);
+ Continue(win);
+}
+#ifdef __STDC__
+void outputTest (WINDOW *win)
+#else
+void outputTest (win)
+WINDOW *win;
+#endif
+{
+ WINDOW *win1;
+ char Buffer [80];
+ chtype ch;
+
+ traceon();
+ nl ();
+ 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);
+
+ 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);
+
+#ifdef UNIX
+ box(win1,ACS_VLINE,ACS_HLINE);
+#else
+ box(win1,0xb3,0xc4);
+#endif
+ 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);
+
+ 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);
+ noraw();
+ 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();
+ noraw();
+ echo();
+ scanw ("%s", Buffer);
+
+ 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);
+}
+
+#ifdef __STDC__
+void resizeTest(WINDOW *dummy)
+#else
+void resizeTest(dummy)
+WINDOW *dummy;
+#endif
+{
+ WINDOW *win1;
+ char Buffer [80];
+ chtype ch;
+
+ savetty ();
+
+ clear();
+ refresh();
+#ifdef __PDCURSES__
+ resize(50);
+#endif
+
+
+ win1 = newwin(11, 50, 14, 25);
+ if(win1 == NULL)
+ { endwin();
+ return;
+ }
+#ifdef A_COLOR
+ if (has_colors())
+ {
+ init_pair(3,COLOR_BLUE,COLOR_WHITE);
+ wattrset(win1, COLOR_PAIR(3));
+ }
+#endif
+ wclear (win1);
+
+ mvwaddstr(win1, 1, 1, "The screen may now have 50 lines");
+ Continue(win1);
+
+ resetty ();
+
+ wclear (win1);
+ mvwaddstr(win1, 1, 1, "The screen should now be reset");
+ Continue(win1);
+
+ delwin(win1);
+
+ clear();
+ refresh();
+
+}
+#ifdef __STDC__
+void padTest(WINDOW *dummy)
+#else
+void padTest(dummy)
+WINDOW *dummy;
+#endif
+{
+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);
+ raw();
+ 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);
+ raw();
+ wgetch(pad);
+
+ delwin(pad);
+}
+
+#ifdef __STDC__
+void display_menu(int old_option,int new_option)
+#else
+void display_menu(old_option,new_option)
+int old_option,new_option;
+#endif
+{
+ register int i;
+
+ attrset(A_NORMAL);
+ mvaddstr(3,20,"PDCurses Test Program");
+
+ for (i=0;i<MAX_OPTIONS;i++)
+ mvaddstr(5+i,25,command[i].text);
+ if (old_option != (-1))
+ mvaddstr(5+old_option,25,command[old_option].text);
+ attrset(A_REVERSE);
+ mvaddstr(5+new_option,25,command[new_option].text);
+ attrset(A_NORMAL);
+ mvaddstr(13,3,"Use Up and Down Arrows to select - Enter to run - Q to quit");
+ refresh();
+}
+
diff --git a/lib/libncurses/TESTS/worm.c b/lib/libncurses/TESTS/worm.c
new file mode 100644
index 0000000..abbe241
--- /dev/null
+++ b/lib/libncurses/TESTS/worm.c
@@ -0,0 +1,268 @@
+/*
+
+ @@@ @@@ @@@@@@@@@@ @@@@@@@@@@@ @@@@@@@@@@@@
+ @@@ @@@ @@@@@@@@@@@@ @@@@@@@@@@@@ @@@@@@@@@@@@@
+ @@@ @@@ @@@@ @@@@ @@@@ @@@@ @@@ @@@@
+ @@@ @@ @@@ @@@ @@@ @@@ @@@ @@@ @@@
+ @@@ @@@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@
+ @@@@ @@@@ @@@@ @@@ @@@ @@@ @@@ @@@ @@@
+ @@@@@@@@@@@@ @@@@ @@@@ @@@ @@@ @@@ @@@
+ @@@@ @@@@ @@@@@@@@@@@@ @@@ @@@ @@@ @@@
+ @@ @@ @@@@@@@@@@ @@@ @@@ @@@ @@@
+
+ Eric P. Scott
+ Caltech High Energy Physics
+ October, 1980
+
+*/
+
+#include <ncurses.h>
+#include <signal.h>
+
+#define cursor(col,row) move(row,col)
+
+int Wrap;
+short *ref[128];
+static char flavor[]={
+ 'O', '*', '#', '$', '%', '0'
+};
+static short xinc[]={
+ 1, 1, 1, 0, -1, -1, -1, 0
+}, yinc[]={
+ -1, 0, 1, 1, 1, 0, -1, -1
+};
+static struct worm {
+ int orientation, head;
+ short *xpos, *ypos;
+} worm[40];
+static char *field;
+static int length=16, number=3, trail=' ';
+static struct options {
+ int nopts;
+ int opts[3];
+} normal[8]={
+ { 3, { 7, 0, 1 } },
+ { 3, { 0, 1, 2 } },
+ { 3, { 1, 2, 3 } },
+ { 3, { 2, 3, 4 } },
+ { 3, { 3, 4, 5 } },
+ { 3, { 4, 5, 6 } },
+ { 3, { 5, 6, 7 } },
+ { 3, { 6, 7, 0 } }
+}, upper[8]={
+ { 1, { 1, 0, 0 } },
+ { 2, { 1, 2, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 2, { 4, 5, 0 } },
+ { 1, { 5, 0, 0 } },
+ { 2, { 1, 5, 0 } }
+}, left[8]={
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 2, { 2, 3, 0 } },
+ { 1, { 3, 0, 0 } },
+ { 2, { 3, 7, 0 } },
+ { 1, { 7, 0, 0 } },
+ { 2, { 7, 0, 0 } }
+}, right[8]={
+ { 1, { 7, 0, 0 } },
+ { 2, { 3, 7, 0 } },
+ { 1, { 3, 0, 0 } },
+ { 2, { 3, 4, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 2, { 6, 7, 0 } }
+}, lower[8]={
+ { 0, { 0, 0, 0 } },
+ { 2, { 0, 1, 0 } },
+ { 1, { 1, 0, 0 } },
+ { 2, { 1, 5, 0 } },
+ { 1, { 5, 0, 0 } },
+ { 2, { 5, 6, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } }
+}, upleft[8]={
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 1, { 3, 0, 0 } },
+ { 2, { 1, 3, 0 } },
+ { 1, { 1, 0, 0 } }
+}, upright[8]={
+ { 2, { 3, 5, 0 } },
+ { 1, { 3, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 1, { 5, 0, 0 } }
+}, lowleft[8]={
+ { 3, { 7, 0, 1 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 1, { 1, 0, 0 } },
+ { 2, { 1, 7, 0 } },
+ { 1, { 7, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } }
+}, lowright[8]={
+ { 0, { 0, 0, 0 } },
+ { 1, { 7, 0, 0 } },
+ { 2, { 5, 7, 0 } },
+ { 1, { 5, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } },
+ { 0, { 0, 0, 0 } }
+};
+
+void onsig();
+float ranf();
+
+main(argc,argv)
+int argc;
+char *argv[];
+{
+int x, y;
+int n;
+struct worm *w;
+struct options *op;
+int h;
+short *ip;
+int last, bottom;
+
+ for (x=1;x<argc;x++) {
+ register char *p;
+ p=argv[x];
+ if (*p=='-') p++;
+ switch (*p) {
+ case 'f':
+ field="WORM";
+ break;
+ case 'l':
+ if (++x==argc) goto usage;
+ if ((length=atoi(argv[x]))<2||length>1024) {
+ fprintf(stderr,"%s: Invalid length\n",*argv);
+ exit(1);
+ }
+ break;
+ case 'n':
+ if (++x==argc) goto usage;
+ if ((number=atoi(argv[x]))<1||number>40) {
+ fprintf(stderr,"%s: Invalid number of worms\n",*argv);
+ exit(1);
+ }
+ break;
+ case 't':
+ trail='.';
+ break;
+ default:
+ usage:
+ fprintf(stderr, "usage: %s [-field] [-length #] [-number #] [-trail]\n",*argv);
+ exit(1);
+ break;
+ }
+ }
+
+ signal(SIGINT, onsig);
+ initscr();
+ bottom = LINES-1;
+ last = COLS-1;
+
+ ip=(short *)malloc(LINES*COLS*sizeof (short));
+
+ for (n=0;n<LINES;) {
+ ref[n++]=ip; ip+=COLS;
+ }
+ for (ip=ref[0],n=LINES*COLS;--n>=0;) *ip++=0;
+ ref[bottom][last]=1;
+ for (n=number, w= &worm[0];--n>=0;w++) {
+ w->orientation=w->head=0;
+ if (!(ip=(short *)malloc(length*sizeof (short)))) {
+ fprintf(stderr,"%s: out of memory\n",*argv);
+ exit(1);
+ }
+ w->xpos=ip;
+ for (x=length;--x>=0;) *ip++ = -1;
+ if (!(ip=(short *)malloc(length*sizeof (short)))) {
+ fprintf(stderr,"%s: out of memory\n",*argv);
+ exit(1);
+ }
+ w->ypos=ip;
+ for (y=length;--y>=0;) *ip++ = -1;
+ }
+ if (field) {
+ register char *p;
+ p=field;
+ for (y=bottom;--y>=0;) {
+ for (x=COLS;--x>=0;) {
+ addch(*p++);
+ if (!*p) p=field;
+ }
+ addch('\n');
+ }
+ }
+ refresh();
+
+ for (;;) {
+ for (n=0,w= &worm[0];n<number;n++,w++) {
+ if ((x=w->xpos[h=w->head])<0) {
+ cursor(x=w->xpos[h]=0,y=w->ypos[h]=bottom);
+ addch(flavor[n%6]);
+ ref[y][x]++;
+ }
+ else y=w->ypos[h];
+ if (++h==length) h=0;
+ if (w->xpos[w->head=h]>=0) {
+ register int x1, y1;
+ x1=w->xpos[h]; y1=w->ypos[h];
+ if (--ref[y1][x1]==0) {
+ cursor(x1,y1); addch(trail);
+ }
+ }
+ op= &(x==0 ? (y==0 ? upleft : (y==bottom ? lowleft : left)) :
+ (x==last ? (y==0 ? upright : (y==bottom ? lowright : right)) :
+ (y==0 ? upper : (y==bottom ? lower : normal))))[w->orientation];
+ switch (op->nopts) {
+ case 0:
+ refresh();
+ endwin();
+ exit(0);
+ case 1:
+ w->orientation=op->opts[0];
+ break;
+ default:
+ w->orientation=op->opts[(int)(ranf()*(float)op->nopts)];
+ }
+ cursor(x+=xinc[w->orientation], y+=yinc[w->orientation]);
+ if (!Wrap||x!=last||y!=bottom) addch(flavor[n%6]);
+ ref[w->ypos[h]=y][w->xpos[h]=x]++;
+ }
+ refresh();
+ }
+}
+
+void
+onsig()
+{
+ endwin();
+ exit(0);
+}
+
+float
+ranf()
+{
+float rv;
+long r = rand();
+
+ r &= 077777;
+ rv =((float)r/32767.);
+ return rv;
+}
diff --git a/lib/libncurses/TESTS/xmas.c b/lib/libncurses/TESTS/xmas.c
new file mode 100644
index 0000000..57cc0ea
--- /dev/null
+++ b/lib/libncurses/TESTS/xmas.c
@@ -0,0 +1,1192 @@
+/******************************************************************************/
+/* asciixmas */
+/* December 1989 Larry Bartz Indianapolis, IN */
+/* */
+/* */
+/* I'm dreaming of an ascii character-based monochrome Christmas, */
+/* Just like the one's I used to know! */
+/* Via a full duplex communications channel, */
+/* At 9600 bits per second, */
+/* Even though it's kinda slow. */
+/* */
+/* I'm dreaming of an ascii character-based monochrome Christmas, */
+/* With ev'ry C program I write! */
+/* May your screen be merry and bright! */
+/* And may all your Christmases be amber or green, */
+/* (for reduced eyestrain and improved visibility)! */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* IMPLEMENTATION */
+/* */
+/* Feel free to modify the defined string FROMWHO to reflect you, your */
+/* organization, your site, whatever. */
+/* */
+/* This really looks a lot better if you can turn off your cursor before */
+/* execution. I wanted to do that here but very few termcap entries or */
+/* terminfo definitions have the appropriate string defined. If you know */
+/* the string(s) for the terminal(s) you use or which your site supports, */
+/* you could call asciixmas from within a shell in which you issue the */
+/* string to the terminal. The cursor is distracting but it doesn't really */
+/* ruin the show. */
+/* */
+/* At our site, we invoke this for our users just after login and the */
+/* determination of terminal type. */
+/* */
+/* */
+/* PORTABILITY */
+/* */
+/* I wrote this using only the very simplest curses functions so that it */
+/* might be the most portable. I was personally able to test on five */
+/* different cpu/UNIX combinations. */
+/* */
+/* */
+/* COMPILE */
+/* */
+/* usually this: */
+/* */
+/* cc -O asciixmas.c -lcurses -o asciixmas -s */
+/* */
+/* */
+/* Zilog S8000 models 11, 21, 31, etc with ZEUS variant of SYSTEM III */
+/* maybe other SYSTEM III also: */
+/* */
+/* cc asciixmas.c -lcurses -ltermlib -o asciixmas -s */
+/* */
+/* as above with optional "peephole optimizer" installed: */
+/* */
+/* cc -O asciixmas.c -lcurses -ltermlib -o asciixmas -s */
+/* */
+/* */
+/* Zilog S8000 models 32, 130 with WE32100 chip and SYS V, REL2 */
+/* maybe 3B2 also? */
+/* */
+/* cc -f -O -K sd asciixmas.c -lcurses -o asciixmas -s */
+/* */
+/* */
+/* Pyramid, Sequent, any other "dual universe" types compile and execute */
+/* under either universe. The compile line for the ucb universe (as you */
+/* might expect) is the same as for SYS III UNIX: */
+/* */
+/* cc -O asciixmas.c -lcurses -ltermlib -o asciixmas -s */
+/* */
+/* The above compile will also hold true for other BSD systems. (I hope) */
+/* */
+/* */
+/* */
+/* */
+/* For the Scrooges out there among you who don't want this thing to loop */
+/* forever (or until the user hits a key), insert this into your compile */
+/* line just after "cc" : */
+/* */
+/* -DNOLOOP */
+/* */
+/* like so: */
+/* */
+/* cc -DNOLOOP -O asciixmas.c -lcurses -o asciixmas -s */
+/* */
+/* */
+/* */
+/******************************************************************************/
+
+#include <ncurses.h>
+#include <signal.h>
+
+#define FROMWHO "Mark Hessling - (M.Hessling@gu.edu.au)"
+
+int y_pos, x_pos;
+
+WINDOW
+ *treescrn, *treescrn2,*treescrn3, *treescrn4,*treescrn5, *treescrn6,
+ *treescrn7, *treescrn8,
+ *dotdeer0,
+ *stardeer0,
+ *lildeer0, *lildeer1, *lildeer2, *lildeer3,
+ *middeer0, *middeer1, *middeer2, *middeer3,
+ *bigdeer0, *bigdeer1, *bigdeer2, *bigdeer3, *bigdeer4,
+ *lookdeer0, *lookdeer1, *lookdeer2, *lookdeer3, *lookdeer4,
+ *w_holiday,
+ *w_del_msg;
+
+void main()
+{
+ void done();
+ int loopy;
+
+ initscr();
+ noecho();
+ nonl();
+ refresh();
+ signal(SIGINT,done);
+ signal(SIGTERM,done);
+#if !defined DOS && !defined OS2
+ signal(SIGHUP,done);
+ signal(SIGQUIT,done);
+#endif
+
+
+
+ treescrn = newwin(16,27,3,53);
+ treescrn2 = newwin(16,27,3,53);
+ treescrn3 = newwin(16,27,3,53);
+ treescrn4 = newwin(16,27,3,53);
+ treescrn5 = newwin(16,27,3,53);
+ treescrn6 = newwin(16,27,3,53);
+ treescrn7 = newwin(16,27,3,53);
+ treescrn8 = newwin(16,27,3,53);
+
+ dotdeer0 = newwin(3,71,0,8);
+
+ stardeer0 = newwin(4,56,0,8);
+
+ lildeer0 = newwin(7,53,0,8);
+ lildeer1 = newwin(2,4,0,0);
+ lildeer2 = newwin(2,4,0,0);
+ lildeer3 = newwin(2,4,0,0);
+
+ middeer0 = newwin(15,42,0,8);
+ middeer1 = newwin(3,7,0,0);
+ middeer2 = newwin(3,7,0,0);
+ middeer3 = newwin(3,7,0,0);
+
+ bigdeer0 = newwin(10,23,0,0);
+ bigdeer1 = newwin(10,23,0,0);
+ bigdeer2 = newwin(10,23,0,0);
+ bigdeer3 = newwin(10,23,0,0);
+ bigdeer4 = newwin(10,23,0,0);
+
+ lookdeer0 = newwin(10,25,0,0);
+ lookdeer1 = newwin(10,25,0,0);
+ lookdeer2 = newwin(10,25,0,0);
+ lookdeer3 = newwin(10,25,0,0);
+ lookdeer4 = newwin(10,25,0,0);
+
+ w_holiday = newwin(1,26,3,27);
+
+ w_del_msg = newwin(1,12,23,60);
+
+ mvwaddstr(w_del_msg,0,0,"Hit any key to quit");
+
+ mvwaddstr(w_holiday,0,0,"H A P P Y H O L I D A Y S");
+
+ /* set up the windows for our various reindeer */
+
+ /* lildeer1 */
+ mvwaddch(lildeer1,0,0,(chtype)'V');
+ mvwaddch(lildeer1,1,0,(chtype)'@');
+ mvwaddch(lildeer1,1,1,(chtype)'<');
+ mvwaddch(lildeer1,1,2,(chtype)'>');
+ mvwaddch(lildeer1,1,3,(chtype)'~');
+
+ /* lildeer2 */
+ mvwaddch(lildeer2,0,0,(chtype)'V');
+ mvwaddch(lildeer2,1,0,(chtype)'@');
+ mvwaddch(lildeer2,1,1,(chtype)'|');
+ mvwaddch(lildeer2,1,2,(chtype)'|');
+ mvwaddch(lildeer2,1,3,(chtype)'~');
+
+ /* lildeer3 */
+ mvwaddch(lildeer3,0,0,(chtype)'V');
+ mvwaddch(lildeer3,1,0,(chtype)'@');
+ mvwaddch(lildeer3,1,1,(chtype)'>');
+ mvwaddch(lildeer3,1,2,(chtype)'<');
+ mvwaddch(lildeer2,1,3,(chtype)'~');
+
+
+ /* middeer1 */
+ mvwaddch(middeer1,0,2,(chtype)'y');
+ mvwaddch(middeer1,0,3,(chtype)'y');
+ mvwaddch(middeer1,1,2,(chtype)'0');
+ mvwaddch(middeer1,1,3,(chtype)'(');
+ mvwaddch(middeer1,1,4,(chtype)'=');
+ mvwaddch(middeer1,1,5,(chtype)')');
+ mvwaddch(middeer1,1,6,(chtype)'~');
+ mvwaddch(middeer1,2,3,(chtype)'\\');
+ mvwaddch(middeer1,2,4,(chtype)'/');
+
+ /* middeer2 */
+ mvwaddch(middeer2,0,2,(chtype)'y');
+ mvwaddch(middeer2,0,3,(chtype)'y');
+ mvwaddch(middeer2,1,2,(chtype)'0');
+ mvwaddch(middeer2,1,3,(chtype)'(');
+ mvwaddch(middeer2,1,4,(chtype)'=');
+ mvwaddch(middeer2,1,5,(chtype)')');
+ mvwaddch(middeer2,1,6,(chtype)'~');
+ mvwaddch(middeer2,2,3,(chtype)'|');
+ mvwaddch(middeer2,2,5,(chtype)'|');
+
+ /* middeer3 */
+ mvwaddch(middeer3,0,2,(chtype)'y');
+ mvwaddch(middeer3,0,3,(chtype)'y');
+ mvwaddch(middeer3,1,2,(chtype)'0');
+ mvwaddch(middeer3,1,3,(chtype)'(');
+ mvwaddch(middeer3,1,4,(chtype)'=');
+ mvwaddch(middeer3,1,5,(chtype)')');
+ mvwaddch(middeer3,1,6,(chtype)'~');
+ mvwaddch(middeer3,2,2,(chtype)'/');
+ mvwaddch(middeer3,2,6,(chtype)'\\');
+
+
+ /* bigdeer1 */
+ mvwaddch(bigdeer1,0,17,(chtype)'\\');
+ mvwaddch(bigdeer1,0,18,(chtype)'/');
+ mvwaddch(bigdeer1,0,20,(chtype)'\\');
+ mvwaddch(bigdeer1,0,21,(chtype)'/');
+ mvwaddch(bigdeer1,1,18,(chtype)'\\');
+ mvwaddch(bigdeer1,1,20,(chtype)'/');
+ mvwaddch(bigdeer1,2,19,(chtype)'|');
+ mvwaddch(bigdeer1,2,20,(chtype)'_');
+ mvwaddch(bigdeer1,3,18,(chtype)'/');
+ mvwaddch(bigdeer1,3,19,(chtype)'^');
+ mvwaddch(bigdeer1,3,20,(chtype)'0');
+ mvwaddch(bigdeer1,3,21,(chtype)'\\');
+ mvwaddch(bigdeer1,4,17,(chtype)'/');
+ mvwaddch(bigdeer1,4,18,(chtype)'/');
+ mvwaddch(bigdeer1,4,19,(chtype)'\\');
+ mvwaddch(bigdeer1,4,22,(chtype)'\\');
+ mvwaddstr(bigdeer1,5,7,"^~~~~~~~~// ~~U");
+ mvwaddstr(bigdeer1,6,7,"( \\_____( /");
+ mvwaddstr(bigdeer1,7,8,"( ) /");
+ mvwaddstr(bigdeer1,8,9,"\\\\ /");
+ mvwaddstr(bigdeer1,9,11,"\\>/>");
+
+ /* bigdeer2 */
+ mvwaddch(bigdeer2,0,17,(chtype)'\\');
+ mvwaddch(bigdeer2,0,18,(chtype)'/');
+ mvwaddch(bigdeer2,0,20,(chtype)'\\');
+ mvwaddch(bigdeer2,0,21,(chtype)'/');
+ mvwaddch(bigdeer2,1,18,(chtype)'\\');
+ mvwaddch(bigdeer2,1,20,(chtype)'/');
+ mvwaddch(bigdeer2,2,19,(chtype)'|');
+ mvwaddch(bigdeer2,2,20,(chtype)'_');
+ mvwaddch(bigdeer2,3,18,(chtype)'/');
+ mvwaddch(bigdeer2,3,19,(chtype)'^');
+ mvwaddch(bigdeer2,3,20,(chtype)'0');
+ mvwaddch(bigdeer2,3,21,(chtype)'\\');
+ mvwaddch(bigdeer2,4,17,(chtype)'/');
+ mvwaddch(bigdeer2,4,18,(chtype)'/');
+ mvwaddch(bigdeer2,4,19,(chtype)'\\');
+ mvwaddch(bigdeer2,4,22,(chtype)'\\');
+ mvwaddstr(bigdeer2,5,7,"^~~~~~~~~// ~~U");
+ mvwaddstr(bigdeer2,6,7,"(( )____( /");
+ mvwaddstr(bigdeer2,7,7,"( / |");
+ mvwaddstr(bigdeer2,8,8,"\\/ |");
+ mvwaddstr(bigdeer2,9,9,"|> |>");
+
+ /* bigdeer3 */
+ mvwaddch(bigdeer3,0,17,(chtype)'\\');
+ mvwaddch(bigdeer3,0,18,(chtype)'/');
+ mvwaddch(bigdeer3,0,20,(chtype)'\\');
+ mvwaddch(bigdeer3,0,21,(chtype)'/');
+ mvwaddch(bigdeer3,1,18,(chtype)'\\');
+ mvwaddch(bigdeer3,1,20,(chtype)'/');
+ mvwaddch(bigdeer3,2,19,(chtype)'|');
+ mvwaddch(bigdeer3,2,20,(chtype)'_');
+ mvwaddch(bigdeer3,3,18,(chtype)'/');
+ mvwaddch(bigdeer3,3,19,(chtype)'^');
+ mvwaddch(bigdeer3,3,20,(chtype)'0');
+ mvwaddch(bigdeer3,3,21,(chtype)'\\');
+ mvwaddch(bigdeer3,4,17,(chtype)'/');
+ mvwaddch(bigdeer3,4,18,(chtype)'/');
+ mvwaddch(bigdeer3,4,19,(chtype)'\\');
+ mvwaddch(bigdeer3,4,22,(chtype)'\\');
+ mvwaddstr(bigdeer3,5,7,"^~~~~~~~~// ~~U");
+ mvwaddstr(bigdeer3,6,6,"( ()_____( /");
+ mvwaddstr(bigdeer3,7,6,"/ / /");
+ mvwaddstr(bigdeer3,8,5,"|/ \\");
+ mvwaddstr(bigdeer3,9,5,"/> \\>");
+
+ /* bigdeer4 */
+ mvwaddch(bigdeer4,0,17,(chtype)'\\');
+ mvwaddch(bigdeer4,0,18,(chtype)'/');
+ mvwaddch(bigdeer4,0,20,(chtype)'\\');
+ mvwaddch(bigdeer4,0,21,(chtype)'/');
+ mvwaddch(bigdeer4,1,18,(chtype)'\\');
+ mvwaddch(bigdeer4,1,20,(chtype)'/');
+ mvwaddch(bigdeer4,2,19,(chtype)'|');
+ mvwaddch(bigdeer4,2,20,(chtype)'_');
+ mvwaddch(bigdeer4,3,18,(chtype)'/');
+ mvwaddch(bigdeer4,3,19,(chtype)'^');
+ mvwaddch(bigdeer4,3,20,(chtype)'0');
+ mvwaddch(bigdeer4,3,21,(chtype)'\\');
+ mvwaddch(bigdeer4,4,17,(chtype)'/');
+ mvwaddch(bigdeer4,4,18,(chtype)'/');
+ mvwaddch(bigdeer4,4,19,(chtype)'\\');
+ mvwaddch(bigdeer4,4,22,(chtype)'\\');
+ mvwaddstr(bigdeer4,5,7,"^~~~~~~~~// ~~U");
+ mvwaddstr(bigdeer4,6,6,"( )______( /");
+ mvwaddstr(bigdeer4,7,5,"(/ \\");
+ mvwaddstr(bigdeer4,8,0,"v___= ----^");
+
+
+ /* lookdeer1 */
+ mvwaddstr(lookdeer1,0,16,"\\/ \\/");
+ mvwaddstr(lookdeer1,1,17,"\\Y/ \\Y/");
+ mvwaddstr(lookdeer1,2,19,"\\=/");
+ mvwaddstr(lookdeer1,3,17,"^\\o o/^");
+ mvwaddstr(lookdeer1,4,17,"//( )");
+ mvwaddstr(lookdeer1,5,7,"^~~~~~~~~// \\O/");
+ mvwaddstr(lookdeer1,6,7,"( \\_____( /");
+ mvwaddstr(lookdeer1,7,8,"( ) /");
+ mvwaddstr(lookdeer1,8,9,"\\\\ /");
+ mvwaddstr(lookdeer1,9,11,"\\>/>");
+
+ /* lookdeer2 */
+ mvwaddstr(lookdeer2,0,16,"\\/ \\/");
+ mvwaddstr(lookdeer2,1,17,"\\Y/ \\Y/");
+ mvwaddstr(lookdeer2,2,19,"\\=/");
+ mvwaddstr(lookdeer2,3,17,"^\\o o/^");
+ mvwaddstr(lookdeer2,4,17,"//( )");
+ mvwaddstr(lookdeer2,5,7,"^~~~~~~~~// \\O/");
+ mvwaddstr(lookdeer2,6,7,"(( )____( /");
+ mvwaddstr(lookdeer2,7,7,"( / |");
+ mvwaddstr(lookdeer2,8,8,"\\/ |");
+ mvwaddstr(lookdeer2,9,9,"|> |>");
+
+ /* lookdeer3 */
+ mvwaddstr(lookdeer3,0,16,"\\/ \\/");
+ mvwaddstr(lookdeer3,1,17,"\\Y/ \\Y/");
+ mvwaddstr(lookdeer3,2,19,"\\=/");
+ mvwaddstr(lookdeer3,3,17,"^\\o o/^");
+ mvwaddstr(lookdeer3,4,17,"//( )");
+ mvwaddstr(lookdeer3,5,7,"^~~~~~~~~// \\O/");
+ mvwaddstr(lookdeer3,6,6,"( ()_____( /");
+ mvwaddstr(lookdeer3,7,6,"/ / /");
+ mvwaddstr(lookdeer3,8,5,"|/ \\");
+ mvwaddstr(lookdeer3,9,5,"/> \\>");
+
+ /* lookdeer4 */
+ mvwaddstr(lookdeer4,0,16,"\\/ \\/");
+ mvwaddstr(lookdeer4,1,17,"\\Y/ \\Y/");
+ mvwaddstr(lookdeer4,2,19,"\\=/");
+ mvwaddstr(lookdeer4,3,17,"^\\o o/^");
+ mvwaddstr(lookdeer4,4,17,"//( )");
+ mvwaddstr(lookdeer4,5,7,"^~~~~~~~~// \\O/");
+ mvwaddstr(lookdeer4,6,6,"( )______( /");
+ mvwaddstr(lookdeer4,7,5,"(/ \\");
+ mvwaddstr(lookdeer4,8,0,"v___= ----^");
+
+
+
+ /***********************************************/
+ cbreak();
+ nodelay(stdscr,TRUE);
+ do
+ {
+ clear();
+ werase(treescrn);
+ touchwin(treescrn);
+ werase(treescrn2);
+ touchwin(treescrn2);
+ werase(treescrn8);
+ touchwin(treescrn8);
+ refresh();
+ usleep(1000);
+ boxit();
+ refresh();
+ usleep(1000);
+ seas();
+ refresh();
+ usleep(1000);
+ greet();
+ refresh();
+ usleep(1000);
+ fromwho();
+ refresh();
+ usleep(1000);
+ tree();
+ usleep(1000);
+ balls();
+ usleep(1000);
+ star();
+ usleep(1000);
+ strng1();
+ strng2();
+ strng3();
+ strng4();
+ strng5();
+
+
+ /* set up the windows for our blinking trees */
+ /* **************************************** */
+ /* treescrn3 */
+
+ overlay(treescrn, treescrn3);
+
+ /*balls*/
+ mvwaddch(treescrn3, 4, 18, ' ');
+ mvwaddch(treescrn3, 7, 6, ' ');
+ mvwaddch(treescrn3, 8, 19, ' ');
+ mvwaddch(treescrn3, 11, 22, ' ');
+
+ /*star*/
+ mvwaddch(treescrn3, 0, 12, '*');
+
+ /*strng1*/
+ mvwaddch(treescrn3, 3, 11, ' ');
+
+ /*strng2*/
+ mvwaddch(treescrn3, 5, 13, ' ');
+ mvwaddch(treescrn3, 6, 10, ' ');
+
+ /*strng3*/
+ mvwaddch(treescrn3, 7, 16, ' ');
+ mvwaddch(treescrn3, 7, 14, ' ');
+
+ /*strng4*/
+ mvwaddch(treescrn3, 10, 13, ' ');
+ mvwaddch(treescrn3, 10, 10, ' ');
+ mvwaddch(treescrn3, 11, 8, ' ');
+
+ /*strng5*/
+ mvwaddch(treescrn3, 11, 18, ' ');
+ mvwaddch(treescrn3, 12, 13, ' ');
+
+
+ /* treescrn4 */
+
+ overlay(treescrn, treescrn4);
+
+ /*balls*/
+ mvwaddch(treescrn4, 3, 9, ' ');
+ mvwaddch(treescrn4, 4, 16, ' ');
+ mvwaddch(treescrn4, 7, 6, ' ');
+ mvwaddch(treescrn4, 8, 19, ' ');
+ mvwaddch(treescrn4, 11, 2, ' ');
+ mvwaddch(treescrn4, 12, 23, ' ');
+
+ /*star*/
+ wstandout(treescrn4);
+ mvwaddch(treescrn4, 0, 12, '*');
+ wstandend(treescrn4);
+
+ /*strng1*/
+ mvwaddch(treescrn4, 3, 13, ' ');
+
+ /*strng2*/
+
+ /*strng3*/
+ mvwaddch(treescrn4, 7, 15, ' ');
+ mvwaddch(treescrn4, 8, 11, ' ');
+
+ /*strng4*/
+ mvwaddch(treescrn4, 9, 16, ' ');
+ mvwaddch(treescrn4, 10, 12, ' ');
+ mvwaddch(treescrn4, 11, 8, ' ');
+
+ /*strng5*/
+ mvwaddch(treescrn4, 11, 18, ' ');
+ mvwaddch(treescrn4, 12, 14, ' ');
+
+
+ /* treescrn5 */
+
+ overlay(treescrn, treescrn5);
+
+ /*balls*/
+ mvwaddch(treescrn5, 3, 15, ' ');
+ mvwaddch(treescrn5, 10, 20, ' ');
+ mvwaddch(treescrn5, 12, 1, ' ');
+
+ /*star*/
+ mvwaddch(treescrn5, 0, 12, '*');
+
+ /*strng1*/
+ mvwaddch(treescrn5, 3, 11, ' ');
+
+ /*strng2*/
+ mvwaddch(treescrn5, 5, 12, ' ');
+
+ /*strng3*/
+ mvwaddch(treescrn5, 7, 14, ' ');
+ mvwaddch(treescrn5, 8, 10, ' ');
+
+ /*strng4*/
+ mvwaddch(treescrn5, 9, 15, ' ');
+ mvwaddch(treescrn5, 10, 11, ' ');
+ mvwaddch(treescrn5, 11, 7, ' ');
+
+ /*strng5*/
+ mvwaddch(treescrn5, 11, 17, ' ');
+ mvwaddch(treescrn5, 12, 13, ' ');
+
+ /* treescrn6 */
+
+ overlay(treescrn, treescrn6);
+
+ /*balls*/
+ mvwaddch(treescrn6, 6, 7, ' ');
+ mvwaddch(treescrn6, 7, 18, ' ');
+ mvwaddch(treescrn6, 10, 4, ' ');
+ mvwaddch(treescrn6, 11, 23, ' ');
+
+ /*star*/
+ wstandout(treescrn6);
+ mvwaddch(treescrn6, 0, 12, '*');
+ wstandend(treescrn6);
+
+ /*strng1*/
+
+ /*strng2*/
+ mvwaddch(treescrn6, 5, 11, ' ');
+
+ /*strng3*/
+ mvwaddch(treescrn6, 7, 13, ' ');
+ mvwaddch(treescrn6, 8, 9, ' ');
+
+ /*strng4*/
+ mvwaddch(treescrn6, 9, 14, ' ');
+ mvwaddch(treescrn6, 10, 10, ' ');
+ mvwaddch(treescrn6, 11, 6, ' ');
+
+ /*strng5*/
+ mvwaddch(treescrn6, 11, 16, ' ');
+ mvwaddch(treescrn6, 12, 12, ' ');
+
+ /* treescrn7 */
+
+ overlay(treescrn, treescrn7);
+
+ /*balls*/
+ mvwaddch(treescrn7, 3, 15, ' ');
+ mvwaddch(treescrn7, 6, 7, ' ');
+ mvwaddch(treescrn7, 7, 18, ' ');
+ mvwaddch(treescrn7, 10, 4, ' ');
+ mvwaddch(treescrn7, 11, 22, ' ');
+
+ /*star*/
+ mvwaddch(treescrn7, 0, 12, '*');
+
+ /*strng1*/
+ mvwaddch(treescrn7, 3, 12, ' ');
+
+ /*strng2*/
+ mvwaddch(treescrn7, 5, 13, ' ');
+ mvwaddch(treescrn7, 6, 9, ' ');
+
+ /*strng3*/
+ mvwaddch(treescrn7, 7, 15, ' ');
+ mvwaddch(treescrn7, 8, 11, ' ');
+
+ /*strng4*/
+ mvwaddch(treescrn7, 9, 16, ' ');
+ mvwaddch(treescrn7, 10, 12, ' ');
+ mvwaddch(treescrn7, 11, 8, ' ');
+
+ /*strng5*/
+ mvwaddch(treescrn7, 11, 18, ' ');
+ mvwaddch(treescrn7, 12, 14, ' ');
+
+
+ usleep(1000);
+ reindeer();
+
+ touchwin(w_holiday);
+ wrefresh(w_holiday);
+ wrefresh(w_del_msg);
+
+ usleep(1000);
+ for(loopy = 0;loopy < 100;loopy++)
+ {
+ blinkit();
+ }
+
+#ifdef NOLOOP
+ done();
+#endif
+
+ }
+ while(getch() == (ERR));
+/* while(!typeahead(stdin));*/
+ done();
+}
+
+boxit()
+{
+ int x = 0;
+
+ while(x < 20)
+ {
+ mvaddch(x, 7, '|');
+ ++x;
+ }
+
+ x = 8;
+
+ while(x < 80)
+ {
+ mvaddch(19, x, '_');
+ ++x;
+ }
+
+ x = 0;
+
+ while(x < 80)
+ {
+ mvaddch(22, x, '_');
+ ++x;
+ }
+
+ return( 0 );
+}
+
+seas()
+{
+ mvaddch(4, 1, 'S');
+ mvaddch(6, 1, 'E');
+ mvaddch(8, 1, 'A');
+ mvaddch(10, 1, 'S');
+ mvaddch(12, 1, 'O');
+ mvaddch(14, 1, 'N');
+ mvaddch(16, 1, '`');
+ mvaddch(18, 1, 'S');
+
+ return( 0 );
+}
+
+
+greet()
+{
+ mvaddch(3, 5, 'G');
+ mvaddch(5, 5, 'R');
+ mvaddch(7, 5, 'E');
+ mvaddch(9, 5, 'E');
+ mvaddch(11, 5, 'T');
+ mvaddch(13, 5, 'I');
+ mvaddch(15, 5, 'N');
+ mvaddch(17, 5, 'G');
+ mvaddch(19, 5, 'S');
+
+ return( 0 );
+}
+
+
+fromwho()
+{
+ mvaddstr(21, 13, FROMWHO);
+ return( 0 );
+}
+
+
+del_msg()
+{
+ mvwaddstr(w_del_msg, 0, 0, "Hit any key to quit");
+ wrefresh(w_del_msg);
+
+ refresh();
+
+ return( 0 );
+}
+
+
+tree()
+{
+ mvwaddch(treescrn, 1, 11, (chtype)'/');
+ mvwaddch(treescrn, 2, 11, (chtype)'/');
+ mvwaddch(treescrn, 3, 10, (chtype)'/');
+ mvwaddch(treescrn, 4, 9, (chtype)'/');
+ mvwaddch(treescrn, 5, 9, (chtype)'/');
+ mvwaddch(treescrn, 6, 8, (chtype)'/');
+ mvwaddch(treescrn, 7, 7, (chtype)'/');
+ mvwaddch(treescrn, 8, 6, (chtype)'/');
+ mvwaddch(treescrn, 9, 6, (chtype)'/');
+ mvwaddch(treescrn, 10, 5, (chtype)'/');
+ mvwaddch(treescrn, 11, 3, (chtype)'/');
+ mvwaddch(treescrn, 12, 2, (chtype)'/');
+
+ mvwaddch(treescrn, 1, 13, (chtype)'\\');
+ mvwaddch(treescrn, 2, 13, (chtype)'\\');
+ mvwaddch(treescrn, 3, 14, (chtype)'\\');
+ mvwaddch(treescrn, 4, 15, (chtype)'\\');
+ mvwaddch(treescrn, 5, 15, (chtype)'\\');
+ mvwaddch(treescrn, 6, 16, (chtype)'\\');
+ mvwaddch(treescrn, 7, 17, (chtype)'\\');
+ mvwaddch(treescrn, 8, 18, (chtype)'\\');
+ mvwaddch(treescrn, 9, 18, (chtype)'\\');
+ mvwaddch(treescrn, 10, 19, (chtype)'\\');
+ mvwaddch(treescrn, 11, 21, (chtype)'\\');
+ mvwaddch(treescrn, 12, 22, (chtype)'\\');
+
+ mvwaddch(treescrn, 4, 10, (chtype)'_');
+ mvwaddch(treescrn, 4, 14, (chtype)'_');
+ mvwaddch(treescrn, 8, 7, (chtype)'_');
+ mvwaddch(treescrn, 8, 17, (chtype)'_');
+
+ mvwaddstr(treescrn, 13, 0, "//////////// \\\\\\\\\\\\\\\\\\\\\\\\");
+
+ mvwaddstr(treescrn, 14, 11, "| |");
+ mvwaddstr(treescrn, 15, 11, "|_|");
+
+ wrefresh(treescrn);
+ wrefresh(w_del_msg);
+
+ return( 0 );
+}
+
+
+balls()
+{
+
+ overlay(treescrn, treescrn2);
+
+ mvwaddch(treescrn2, 3, 9, (chtype)'@');
+ mvwaddch(treescrn2, 3, 15, (chtype)'@');
+ mvwaddch(treescrn2, 4, 8, (chtype)'@');
+ mvwaddch(treescrn2, 4, 16, (chtype)'@');
+ mvwaddch(treescrn2, 5, 7, (chtype)'@');
+ mvwaddch(treescrn2, 5, 17, (chtype)'@');
+ mvwaddch(treescrn2, 7, 6, (chtype)'@');
+ mvwaddch(treescrn2, 7, 18, (chtype)'@');
+ mvwaddch(treescrn2, 8, 5, (chtype)'@');
+ mvwaddch(treescrn2, 8, 19, (chtype)'@');
+ mvwaddch(treescrn2, 10, 4, (chtype)'@');
+ mvwaddch(treescrn2, 10, 20, (chtype)'@');
+ mvwaddch(treescrn2, 11, 2, (chtype)'@');
+ mvwaddch(treescrn2, 11, 22, (chtype)'@');
+ mvwaddch(treescrn2, 12, 1, (chtype)'@');
+ mvwaddch(treescrn2, 12, 23, (chtype)'@');
+
+ wrefresh(treescrn2);
+ wrefresh(w_del_msg);
+ return( 0 );
+}
+
+
+star()
+{
+ wstandout(treescrn2);
+ mvwaddch(treescrn2, 0, 12, (chtype)'*');
+ wstandend(treescrn2);
+
+ wrefresh(treescrn2);
+ wrefresh(w_del_msg);
+ return( 0 );
+}
+
+
+strng1()
+{
+ mvwaddch(treescrn2, 3, 13, (chtype)'\'');
+ mvwaddch(treescrn2, 3, 12, (chtype)':');
+ mvwaddch(treescrn2, 3, 11, (chtype)'.');
+
+ wrefresh(treescrn2);
+ wrefresh(w_del_msg);
+ return( 0 );
+}
+
+
+strng2()
+{
+ mvwaddch(treescrn2, 5, 14, (chtype)'\'');
+ mvwaddch(treescrn2, 5, 13, (chtype)':');
+ mvwaddch(treescrn2, 5, 12, (chtype)'.');
+ mvwaddch(treescrn2, 5, 11, (chtype)',');
+ mvwaddch(treescrn2, 6, 10, (chtype)'\'');
+ mvwaddch(treescrn2, 6, 9, (chtype)':');
+
+ wrefresh(treescrn2);
+ wrefresh(w_del_msg);
+ return( 0 );
+}
+
+
+strng3()
+{
+ mvwaddch(treescrn2, 7, 16, (chtype)'\'');
+ mvwaddch(treescrn2, 7, 15, (chtype)':');
+ mvwaddch(treescrn2, 7, 14, (chtype)'.');
+ mvwaddch(treescrn2, 7, 13, (chtype)',');
+ mvwaddch(treescrn2, 8, 12, (chtype)'\'');
+ mvwaddch(treescrn2, 8, 11, (chtype)':');
+ mvwaddch(treescrn2, 8, 10, (chtype)'.');
+ mvwaddch(treescrn2, 8, 9, (chtype)',');
+
+ wrefresh(treescrn2);
+ wrefresh(w_del_msg);
+ return( 0 );
+}
+
+
+strng4()
+{
+ mvwaddch(treescrn2, 9, 17, (chtype)'\'');
+ mvwaddch(treescrn2, 9, 16, (chtype)':');
+ mvwaddch(treescrn2, 9, 15, (chtype)'.');
+ mvwaddch(treescrn2, 9, 14, (chtype)',');
+ mvwaddch(treescrn2, 10, 13, (chtype)'\'');
+ mvwaddch(treescrn2, 10, 12, (chtype)':');
+ mvwaddch(treescrn2, 10, 11, (chtype)'.');
+ mvwaddch(treescrn2, 10, 10, (chtype)',');
+ mvwaddch(treescrn2, 11, 9, (chtype)'\'');
+ mvwaddch(treescrn2, 11, 8, (chtype)':');
+ mvwaddch(treescrn2, 11, 7, (chtype)'.');
+ mvwaddch(treescrn2, 11, 6, (chtype)',');
+ mvwaddch(treescrn2, 12, 5, (chtype)'\'');
+
+ wrefresh(treescrn2);
+ wrefresh(w_del_msg);
+ return( 0 );
+}
+
+
+strng5()
+{
+ mvwaddch(treescrn2, 11, 19, (chtype)'\'');
+ mvwaddch(treescrn2, 11, 18, (chtype)':');
+ mvwaddch(treescrn2, 11, 17, (chtype)'.');
+ mvwaddch(treescrn2, 11, 16, (chtype)',');
+ mvwaddch(treescrn2, 12, 15, (chtype)'\'');
+ mvwaddch(treescrn2, 12, 14, (chtype)':');
+ mvwaddch(treescrn2, 12, 13, (chtype)'.');
+ mvwaddch(treescrn2, 12, 12, (chtype)',');
+
+ /* save a fully lit tree */
+ overlay(treescrn2, treescrn);
+
+ wrefresh(treescrn2);
+ wrefresh(w_del_msg);
+ return( 0 );
+}
+
+
+
+blinkit()
+{
+ static int cycle;
+
+ if(cycle > 4)
+ {
+ cycle = 0;
+ }
+
+
+ touchwin(treescrn8);
+
+ switch(cycle)
+ {
+
+ case 0:
+ overlay(treescrn3, treescrn8);
+ wrefresh(treescrn8);
+ wrefresh(w_del_msg);
+
+ break;
+ case 1:
+ overlay(treescrn4, treescrn8);
+ wrefresh(treescrn8);
+ wrefresh(w_del_msg);
+
+ break;
+ case 2:
+ overlay(treescrn5, treescrn8);
+ wrefresh(treescrn8);
+ wrefresh(w_del_msg);
+
+ break;
+ case 3:
+ overlay(treescrn6, treescrn8);
+ wrefresh(treescrn8);
+ wrefresh(w_del_msg);
+
+ break;
+ case 4:
+ overlay(treescrn7, treescrn8);
+ wrefresh(treescrn8);
+ wrefresh(w_del_msg);
+
+ break;
+ }
+
+ touchwin(treescrn8);
+
+
+
+ /*ALL ON***************************************************/
+
+
+ overlay(treescrn, treescrn8);
+ wrefresh(treescrn8);
+ wrefresh(w_del_msg);
+
+
+ ++cycle;
+ return( 0 );
+}
+
+
+reindeer()
+{
+ int looper;
+
+ y_pos = 0;
+
+
+ for(x_pos = 70; x_pos > 62; x_pos--)
+ {
+ if(x_pos < 62)
+ {
+ y_pos = 1;
+ }
+ for(looper = 0; looper < 4; looper++)
+ {
+ mvwaddch(dotdeer0, y_pos, x_pos, (chtype)'.');
+ wrefresh(dotdeer0);
+ wrefresh(w_del_msg);
+ werase(dotdeer0);
+ wrefresh(dotdeer0);
+ wrefresh(w_del_msg);
+ }
+ }
+
+ y_pos = 2;
+
+ for(; x_pos > 50; x_pos--)
+ {
+
+ for(looper = 0; looper < 4; looper++)
+ {
+
+ if(x_pos < 56)
+ {
+ y_pos = 3;
+
+ mvwaddch(stardeer0, y_pos, x_pos, (chtype)'*');
+ wrefresh(stardeer0);
+ wrefresh(w_del_msg);
+ werase(stardeer0);
+ wrefresh(stardeer0);
+ wrefresh(w_del_msg);
+ }
+ else
+ {
+ mvwaddch(dotdeer0, y_pos, x_pos, (chtype)'*');
+ wrefresh(dotdeer0);
+ wrefresh(w_del_msg);
+ werase(dotdeer0);
+ wrefresh(dotdeer0);
+ wrefresh(w_del_msg);
+ }
+ }
+ }
+
+ x_pos = 58;
+
+ for(y_pos = 2; y_pos < 5; y_pos++)
+ {
+
+ touchwin(lildeer0);
+ wrefresh(lildeer0);
+ wrefresh(w_del_msg);
+
+ for(looper = 0; looper < 4; looper++)
+ {
+ mvwin(lildeer3, y_pos, x_pos);
+ wrefresh(lildeer3);
+ wrefresh(w_del_msg);
+
+ mvwin(lildeer2, y_pos, x_pos);
+ wrefresh(lildeer2);
+ wrefresh(w_del_msg);
+
+ mvwin(lildeer1, y_pos, x_pos);
+ wrefresh(lildeer1);
+ wrefresh(w_del_msg);
+
+ mvwin(lildeer2, y_pos, x_pos);
+ wrefresh(lildeer2);
+ wrefresh(w_del_msg);
+
+ mvwin(lildeer3, y_pos, x_pos);
+ wrefresh(lildeer3);
+ wrefresh(w_del_msg);
+
+ touchwin(lildeer0);
+ wrefresh(lildeer0);
+ wrefresh(w_del_msg);
+
+ x_pos -= 2;
+ }
+ }
+
+
+ x_pos = 35;
+
+ for(y_pos = 5; y_pos < 10; y_pos++)
+ {
+
+ touchwin(middeer0);
+ wrefresh(middeer0);
+ wrefresh(w_del_msg);
+
+ for(looper = 0; looper < 2; looper++)
+ {
+ mvwin(middeer3, y_pos, x_pos);
+ wrefresh(middeer3);
+ wrefresh(w_del_msg);
+
+ mvwin(middeer2, y_pos, x_pos);
+ wrefresh(middeer2);
+ wrefresh(w_del_msg);
+
+ mvwin(middeer1, y_pos, x_pos);
+ wrefresh(middeer1);
+ wrefresh(w_del_msg);
+
+ mvwin(middeer2, y_pos, x_pos);
+ wrefresh(middeer2);
+ wrefresh(w_del_msg);
+
+ mvwin(middeer3, y_pos, x_pos);
+ wrefresh(middeer3);
+ wrefresh(w_del_msg);
+
+ touchwin(middeer0);
+ wrefresh(middeer0);
+ wrefresh(w_del_msg);
+
+ x_pos -= 3;
+ }
+ }
+
+ usleep(2000);
+
+ y_pos = 1;
+
+ for(x_pos = 8; x_pos < 16; x_pos++)
+ {
+
+ mvwin(bigdeer4, y_pos, x_pos);
+ wrefresh(bigdeer4);
+ wrefresh(w_del_msg);
+
+ mvwin(bigdeer3, y_pos, x_pos);
+ wrefresh(bigdeer3);
+ wrefresh(w_del_msg);
+
+ mvwin(bigdeer2, y_pos, x_pos);
+ wrefresh(bigdeer2);
+ wrefresh(w_del_msg);
+
+ mvwin(bigdeer1, y_pos, x_pos);
+ wrefresh(bigdeer1);
+ wrefresh(w_del_msg);
+
+ mvwin(bigdeer2, y_pos, x_pos);
+ wrefresh(bigdeer2);
+ wrefresh(w_del_msg);
+
+ mvwin(bigdeer3, y_pos, x_pos);
+ wrefresh(bigdeer3);
+ wrefresh(w_del_msg);
+
+ mvwin(bigdeer4, y_pos, x_pos);
+ wrefresh(bigdeer4);
+ wrefresh(w_del_msg);
+
+ mvwin(bigdeer0, y_pos, x_pos);
+ wrefresh(bigdeer0);
+ wrefresh(w_del_msg);
+ }
+
+ --x_pos;
+
+ for(looper = 0; looper < 6; looper++)
+ {
+ mvwin(lookdeer4, y_pos, x_pos);
+ wrefresh(lookdeer4);
+ wrefresh(w_del_msg);
+
+ mvwin(lookdeer3, y_pos, x_pos);
+ wrefresh(lookdeer3);
+ wrefresh(w_del_msg);
+
+ mvwin(lookdeer2, y_pos, x_pos);
+ wrefresh(lookdeer2);
+ wrefresh(w_del_msg);
+
+ mvwin(lookdeer1, y_pos, x_pos);
+ wrefresh(lookdeer1);
+ wrefresh(w_del_msg);
+
+ mvwin(lookdeer2, y_pos, x_pos);
+ wrefresh(lookdeer2);
+ wrefresh(w_del_msg);
+
+ mvwin(lookdeer3, y_pos, x_pos);
+ wrefresh(lookdeer3);
+ wrefresh(w_del_msg);
+
+ mvwin(lookdeer4, y_pos, x_pos);
+ wrefresh(lookdeer4);
+ wrefresh(w_del_msg);
+
+ }
+
+ mvwin(lookdeer0, y_pos, x_pos);
+ wrefresh(lookdeer0);
+ wrefresh(w_del_msg);
+
+ for(; y_pos < 10; y_pos++)
+ {
+
+ for(looper = 0; looper < 2; looper++)
+ {
+ mvwin(bigdeer4, y_pos, x_pos);
+ wrefresh(bigdeer4);
+ wrefresh(w_del_msg);
+
+ mvwin(bigdeer3, y_pos, x_pos);
+ wrefresh(bigdeer3);
+ wrefresh(w_del_msg);
+
+ mvwin(bigdeer2, y_pos, x_pos);
+ wrefresh(bigdeer2);
+ wrefresh(w_del_msg);
+
+ mvwin(bigdeer1, y_pos, x_pos);
+ wrefresh(bigdeer1);
+ wrefresh(w_del_msg);
+
+ mvwin(bigdeer2, y_pos, x_pos);
+ wrefresh(bigdeer2);
+ wrefresh(w_del_msg);
+
+ mvwin(bigdeer3, y_pos, x_pos);
+ wrefresh(bigdeer3);
+ wrefresh(w_del_msg);
+
+ mvwin(bigdeer4, y_pos, x_pos);
+ wrefresh(bigdeer4);
+ wrefresh(w_del_msg);
+ }
+ mvwin(bigdeer0, y_pos, x_pos);
+ wrefresh(bigdeer0);
+ wrefresh(w_del_msg);
+ }
+
+ --y_pos;
+
+ mvwin(lookdeer3, y_pos, x_pos);
+ wrefresh(lookdeer3);
+ wrefresh(w_del_msg);
+ return( 0 );
+}
+
+
+
+void done()
+{
+ signal(SIGINT,done);
+ signal(SIGTERM,done);
+#if !defined DOS && !defined OS2
+ signal(SIGHUP,done);
+ signal(SIGQUIT,done);
+#endif
+ clear();
+ refresh();
+ endwin();
+ exit(0);
+}
OpenPOWER on IntegriCloud