libpayload: Rename PDCurses-3.4 to PDCurses

Change-Id: If881ec130833c7e7e62caa3d31e350a531f5bc8e
Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Reviewed-on: http://review.coreboot.org/12398
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
Stefan Reinauer
2015-11-10 09:00:41 -08:00
parent 2ea24dabd6
commit 4f85a1eb76
164 changed files with 2 additions and 2 deletions

View File

@@ -0,0 +1,25 @@
PDCurses Demos
==============
This directory contains demonstration programs to show and test the
capabilities of curses libraries. Some of them predate PDCurses,
PCcurses or even pcurses/ncurses. Although some PDCurses-specific code
has been added, all programs remain portable to other implementations
(at a minimum, to ncurses).
Building
--------
The demos are built by the platform-specific makefiles, in the platform
directories. Alternatively, you can build them manually, individually,
and link with any curses library; e.g., "cc -lcurses -orain rain.c".
There are no dependencies besides curses and the standard C library, and
no configuration is needed.
Distribution Status
-------------------
Public Domain, except for rain.c and worm.c, which are under the ncurses
license (MIT-like).

View File

@@ -0,0 +1,148 @@
/* $Id: firework.c,v 1.25 2008/07/13 16:08:17 wmcbrine Exp $ */
#include <stdio.h>
#include <signal.h>
#include <curses.h>
#include <ctype.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#define DELAYSIZE 200
void myrefresh(void);
void get_color(void);
void explode(int, int);
short color_table[] =
{
COLOR_RED, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN,
COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE
};
int main(int argc, char **argv)
{
int i, start, end, row, diff, flag, direction, seed;
#ifdef XCURSES
Xinitscr(argc, argv);
#else
initscr();
#endif
nodelay(stdscr, TRUE);
noecho();
if (has_colors())
start_color();
for (i = 0; i < 8; i++)
init_pair(i, color_table[i], COLOR_BLACK);
seed = time((time_t *)0);
srand(seed);
flag = 0;
while (getch() == ERR) /* loop until a key is hit */
{
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++)
{
mvaddstr(LINES - row, row * direction + start,
(direction < 0) ? "\\" : "/");
if (flag++)
{
myrefresh();
erase();
flag = 0;
}
}
if (flag++)
{
myrefresh();
flag = 0;
}
explode(LINES - row, diff * direction + start);
erase();
myrefresh();
}
endwin();
return 0;
}
void explode(int row, int col)
{
erase();
mvaddstr(row, col, "-");
myrefresh();
--col;
get_color();
mvaddstr(row - 1, col, " - ");
mvaddstr(row, col, "-+-");
mvaddstr(row + 1, col, " - ");
myrefresh();
--col;
get_color();
mvaddstr(row - 2, col, " --- ");
mvaddstr(row - 1, col, "-+++-");
mvaddstr(row, col, "-+#+-");
mvaddstr(row + 1, col, "-+++-");
mvaddstr(row + 2, col, " --- ");
myrefresh();
get_color();
mvaddstr(row - 2, col, " +++ ");
mvaddstr(row - 1, col, "++#++");
mvaddstr(row, col, "+# #+");
mvaddstr(row + 1, col, "++#++");
mvaddstr(row + 2, col, " +++ ");
myrefresh();
get_color();
mvaddstr(row - 2, col, " # ");
mvaddstr(row - 1, col, "## ##");
mvaddstr(row, col, "# #");
mvaddstr(row + 1, col, "## ##");
mvaddstr(row + 2, col, " # ");
myrefresh();
get_color();
mvaddstr(row - 2, col, " # # ");
mvaddstr(row - 1, col, "# #");
mvaddstr(row, col, " ");
mvaddstr(row + 1, col, "# #");
mvaddstr(row + 2, col, " # # ");
myrefresh();
}
void myrefresh(void)
{
napms(DELAYSIZE);
move(LINES - 1, COLS - 1);
refresh();
}
void get_color(void)
{
chtype bold = (rand() % 2) ? A_BOLD : A_NORMAL;
attrset(COLOR_PAIR(rand() % 8) | bold);
}

View File

@@ -0,0 +1,425 @@
/*
* newdemo.c - A demo program using PDCurses. The program
* illustrates the use of colors for text output.
*
* Hacks by jbuhler@cs.washington.edu on 12/29/96
*
* $Id: newdemo.c,v 1.39 2008/07/13 16:08:17 wmcbrine Exp $
*/
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <curses.h>
#include <stdlib.h>
#include <time.h>
int WaitForUser(void);
int SubWinTest(WINDOW *);
int BouncingBalls(WINDOW *);
void trap(int);
/* An ASCII map of Australia */
char *AusMap[17] =
{
" A ",
" AA AA ",
" N.T. AAAAA AAAA ",
" AAAAAAAAAAA AAAAAAAA ",
" AAAAAAAAAAAAAAAAAAAAAAAAA Qld.",
" AAAAAAAAAAAAAAAAAAAAAAAAAAAA ",
" AAAAAAAAAAAAAAAAAAAAAAAAAAAAA ",
" AAAAAAAAAAAAAAAAAAAAAAAAAAAA ",
" AAAAAAAAAAAAAAAAAAAAAAAAA N.S.W.",
"W.A. AAAAAAAAA AAAAAA Vic.",
" AAA S.A. AA",
" A Tas.",
""
};
/* Funny messages for the scroller */
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",
NULL
};
int WaitForUser(void)
{
chtype ch;
nodelay(stdscr, TRUE);
halfdelay(50);
ch = getch();
nodelay(stdscr, FALSE);
nocbreak(); /* Reset the halfdelay() value */
cbreak();
return (ch == '\033') ? ch : 0;
}
int SubWinTest(WINDOW *win)
{
WINDOW *swin1, *swin2, *swin3;
int w, h, sw, sh, bx, by;
wattrset(win, 0);
getmaxyx(win, h, w);
getbegyx(win, by, bx);
sw = w / 3;
sh = h / 3;
if ((swin1 = derwin(win, sh, sw, 3, 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);
wbkgd(swin1, COLOR_PAIR(8));
werase(swin1);
mvwaddstr(swin1, 0, 3, "Sub-window 1");
wrefresh(swin1);
init_pair(9, COLOR_CYAN, COLOR_MAGENTA);
wbkgd(swin2, COLOR_PAIR(9));
werase(swin2);
mvwaddstr(swin2, 0, 3, "Sub-window 2");
wrefresh(swin2);
init_pair(10, COLOR_YELLOW, COLOR_GREEN);
wbkgd(swin3, COLOR_PAIR(10));
werase(swin3);
mvwaddstr(swin3, 0, 3, "Sub-window 3");
wrefresh(swin3);
delwin(swin1);
delwin(swin2);
delwin(swin3);
WaitForUser();
return 0;
}
int BouncingBalls(WINDOW *win)
{
chtype c1, c2, c3, ball1, ball2, ball3;
int w, h, x1, y1, xd1, yd1, x2, y2, xd2, yd2, x3, y3, xd3, yd3, c;
curs_set(0);
wbkgd(win, COLOR_PAIR(1));
wrefresh(win);
wattrset(win, 0);
init_pair(11, COLOR_RED, COLOR_GREEN);
init_pair(12, COLOR_BLUE, COLOR_RED);
init_pair(13, COLOR_YELLOW, COLOR_WHITE);
ball1 = 'O' | COLOR_PAIR(11);
ball2 = '*' | COLOR_PAIR(12);
ball3 = '@' | COLOR_PAIR(13);
getmaxyx(win, h, w);
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 = -1;
xd3 = -1;
yd3 = 1;
nodelay(stdscr, TRUE);
while ((c = getch()) == ERR)
{
x1 += xd1;
if (x1 <= 1 || x1 >= w - 2)
xd1 *= -1;
y1 += yd1;
if (y1 <= 1 || y1 >= h - 2)
yd1 *= -1;
x2 += xd2;
if (x2 <= 1 || x2 >= w - 2)
xd2 *= -1;
y2 += yd2;
if (y2 <= 1 || y2 >= h - 2)
yd2 *= -1;
x3 += xd3;
if (x3 <= 1 || x3 >= w - 2)
xd3 *= -1;
y3 += yd3;
if (y3 <= 1 || y3 >= h - 2)
yd3 *= -1;
c1 = mvwinch(win, y1, x1);
c2 = mvwinch(win, y2, x2);
c3 = mvwinch(win, y3, x3);
mvwaddch(win, y1, x1, ball1);
mvwaddch(win, y2, x2, ball2);
mvwaddch(win, y3, x3, ball3);
wmove(win, 0, 0);
wrefresh(win);
mvwaddch(win, y1, x1, c1);
mvwaddch(win, y2, x2, c2);
mvwaddch(win, y3, x3, c3);
napms(150);
}
nodelay(stdscr, FALSE);
ungetch(c);
return 0;
}
/* Trap interrupt */
void trap(int sig)
{
if (sig == SIGINT)
{
endwin();
exit(0);
}
}
int main(int argc, char **argv)
{
WINDOW *win;
chtype save[80], ch;
int width, height, w, x, y, i, j, seed;
#ifdef XCURSES
Xinitscr(argc, argv);
#else
initscr();
#endif
seed = time((time_t *)0);
srand(seed);
start_color();
# if defined(NCURSES_VERSION) || (defined(PDC_BUILD) && PDC_BUILD > 3000)
use_default_colors();
# endif
cbreak();
noecho();
curs_set(0);
#if !defined(__TURBOC__) && !defined(OS2)
signal(SIGINT, trap);
#endif
noecho();
/* refresh stdscr so that reading from it will not cause it to
overwrite the other windows that are being created */
refresh();
/* Create a drawing window */
width = 48;
height = 15;
win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
if (win == NULL)
{
endwin();
return 1;
}
for (;;)
{
init_pair(1, COLOR_WHITE, COLOR_BLUE);
wbkgd(win, COLOR_PAIR(1));
werase(win);
init_pair(2, COLOR_RED, COLOR_RED);
wattrset(win, COLOR_PAIR(2));
box(win, ' ', ' ');
wrefresh(win);
wattrset(win, 0);
/* Do random output of a character */
ch = 'a';
nodelay(stdscr, TRUE);
for (i = 0; i < 5000; ++i)
{
x = rand() % (width - 2) + 1;
y = rand() % (height - 2) + 1;
mvwaddch(win, y, x, ch);
wrefresh(win);
if (getch() != ERR)
break;
if (i == 2000)
{
ch = 'b';
init_pair(3, COLOR_CYAN, COLOR_YELLOW);
wattrset(win, COLOR_PAIR(3));
}
}
nodelay(stdscr, FALSE);
SubWinTest(win);
/* Erase and draw green window */
init_pair(4, COLOR_YELLOW, COLOR_GREEN);
wbkgd(win, COLOR_PAIR(4));
wattrset(win, A_BOLD);
werase(win);
wrefresh(win);
/* Draw RED bounding box */
wattrset(win, COLOR_PAIR(2));
box(win, ' ', ' ');
wrefresh(win);
/* Display Australia map */
wattrset(win, A_BOLD);
i = 0;
while (*AusMap[i])
{
mvwaddstr(win, i + 1, 8, AusMap[i]);
wrefresh(win);
napms(100);
++i;
}
init_pair(5, COLOR_BLUE, COLOR_WHITE);
wattrset(win, COLOR_PAIR(5) | A_BLINK);
mvwaddstr(win, height - 2, 3,
" PDCurses 3.4 - DOS, OS/2, Win32, X11, SDL");
wrefresh(win);
/* Draw running messages */
init_pair(6, COLOR_BLACK, COLOR_WHITE);
wattrset(win, COLOR_PAIR(6));
w = width - 2;
nodelay(win, TRUE);
/* jbuhler's re-hacked scrolling messages */
for (j = 0; messages[j] != NULL; j++)
{
char *message = messages[j];
int msg_len = strlen(message);
int scroll_len = w + 2 * msg_len;
char *scrollbuf = malloc(scroll_len);
char *visbuf = scrollbuf + msg_len;
int stop = 0;
int i;
for (i = w + msg_len; i > 0; i--)
{
memset(visbuf, ' ', w);
strncpy(scrollbuf + i, message, msg_len);
mvwaddnstr(win, height / 2, 1, visbuf, w);
wrefresh(win);
if (wgetch(win) != ERR)
{
flushinp();
stop = 1;
break;
}
napms(100);
}
free(scrollbuf);
if (stop)
break;
}
j = 0;
/* Draw running 'A's across in RED */
init_pair(7, COLOR_RED, COLOR_GREEN);
wattron(win, COLOR_PAIR(7));
for (i = 2; i < width - 4; ++i)
{
ch = mvwinch(win, 5, i);
save[j++] = ch;
ch = ch & 0x7f;
mvwaddch(win, 5, i, ch);
}
wrefresh(win);
/* Put a message up; wait for a key */
i = height - 2;
wattrset(win, COLOR_PAIR(5));
mvwaddstr(win, i, 3,
" Type a key to continue or ESC to quit ");
wrefresh(win);
if (WaitForUser() == '\033')
break;
/* Restore the old line */
wattrset(win, 0);
for (i = 2, j = 0; i < width - 4; ++i)
mvwaddch(win, 5, i, save[j++]);
wrefresh(win);
BouncingBalls(win);
/* BouncingBalls() leaves a keystroke in the queue */
if (WaitForUser() == '\033')
break;
}
endwin();
return 0;
}

View File

@@ -0,0 +1,285 @@
/* $Id: ptest.c,v 1.24 2008/07/13 16:08:17 wmcbrine Exp $ */
#include <curses.h>
#include <panel.h>
#include <stdlib.h>
PANEL *p1, *p2, *p3, *p4, *p5;
WINDOW *w4, *w5;
long nap_msec = 1;
char *mod[] =
{
"test ", "TEST ", "(**) ", "*()* ", "<--> ", "LAST "
};
void pflush(void)
{
update_panels();
doupdate();
}
void backfill(void)
{
int y, x;
erase();
for (y = 0; y < LINES - 1; y++)
for (x = 0; x < COLS; x++)
printw("%d", (y + x) % 10);
}
void wait_a_while(long msec)
{
int c;
if (msec != 1)
timeout(msec);
c = getch();
if (c == 'q')
{
endwin();
exit(1);
}
}
void saywhat(const char *text)
{
mvprintw(LINES - 1, 0, "%-20.20s", text);
}
/* mkpanel - alloc a win and panel and associate them */
PANEL *mkpanel(int rows, int cols, int tly, int tlx)
{
WINDOW *win = newwin(rows, cols, tly, tlx);
PANEL *pan = (PANEL *)0;
if (win)
{
pan = new_panel(win);
if (!pan)
delwin(win);
}
return pan;
}
void rmpanel(PANEL *pan)
{
WINDOW *win = pan->win;
del_panel(pan);
delwin(win);
}
void fill_panel(PANEL *pan)
{
WINDOW *win = pan->win;
char num = *((char *)pan->user + 1);
int y, x, maxy, maxx;
box(win, 0, 0);
mvwprintw(win, 1, 1, "-pan%c-", num);
getmaxyx(win, maxy, maxx);
for (y = 2; y < maxy - 1; y++)
for (x = 1; x < maxx - 1; x++)
mvwaddch(win, y, x, num);
}
int main(int argc, char **argv)
{
int itmp, y;
if (argc > 1 && atol(argv[1]))
nap_msec = atol(argv[1]);
#ifdef XCURSES
Xinitscr(argc, argv);
#else
initscr();
#endif
backfill();
for (y = 0; y < 5; y++)
{
p1 = mkpanel(10, 10, 0, 0);
set_panel_userptr(p1, "p1");
p2 = mkpanel(14, 14, 5, 5);
set_panel_userptr(p2, "p2");
p3 = mkpanel(6, 8, 12, 12);
set_panel_userptr(p3, "p3");
p4 = mkpanel(10, 10, 10, 30);
w4 = panel_window(p4);
set_panel_userptr(p4, "p4");
p5 = mkpanel(10, 10, 13, 37);
w5 = panel_window(p5);
set_panel_userptr(p5, "p5");
fill_panel(p1);
fill_panel(p2);
fill_panel(p3);
fill_panel(p4);
fill_panel(p5);
hide_panel(p4);
hide_panel(p5);
pflush();
wait_a_while(nap_msec);
saywhat("h3 s1 s2 s4 s5;");
move_panel(p1, 0, 0);
hide_panel(p3);
show_panel(p1);
show_panel(p2);
show_panel(p4);
show_panel(p5);
pflush();
wait_a_while(nap_msec);
saywhat("s1;");
show_panel(p1);
pflush();
wait_a_while(nap_msec);
saywhat("s2;");
show_panel(p2);
pflush();
wait_a_while(nap_msec);
saywhat("m2;");
move_panel(p2, 10, 10);
pflush();
wait_a_while(nap_msec);
saywhat("s3;");
show_panel(p3);
pflush();
wait_a_while(nap_msec);
saywhat("m3;");
move_panel(p3, 5, 5);
pflush();
wait_a_while(nap_msec);
saywhat("b3;");
bottom_panel(p3);
pflush();
wait_a_while(nap_msec);
saywhat("s4;");
show_panel(p4);
pflush();
wait_a_while(nap_msec);
saywhat("s5;");
show_panel(p5);
pflush();
wait_a_while(nap_msec);
saywhat("t3;");
top_panel(p3);
pflush();
wait_a_while(nap_msec);
saywhat("t1;");
top_panel(p1);
pflush();
wait_a_while(nap_msec);
saywhat("t2;");
top_panel(p2);
pflush();
wait_a_while(nap_msec);
saywhat("t3;");
top_panel(p3);
pflush();
wait_a_while(nap_msec);
saywhat("t4;");
top_panel(p4);
pflush();
wait_a_while(nap_msec);
for (itmp = 0; itmp < 6; itmp++)
{
saywhat("m4;");
mvwaddstr(w4, 3, 1, mod[itmp]);
move_panel(p4, 4, itmp * 10);
mvwaddstr(w5, 4, 1, mod[itmp]);
pflush();
wait_a_while(nap_msec);
saywhat("m5;");
mvwaddstr(w4, 4, 1, mod[itmp]);
move_panel(p5, 7, itmp * 10 + 6);
mvwaddstr(w5, 3, 1, mod[itmp]);
pflush();
wait_a_while(nap_msec);
}
saywhat("m4;");
move_panel(p4, 4, itmp * 10);
pflush();
wait_a_while(nap_msec);
saywhat("t5;");
top_panel(p5);
pflush();
wait_a_while(nap_msec);
saywhat("t2;");
top_panel(p2);
pflush();
wait_a_while(nap_msec);
saywhat("t1;");
top_panel(p1);
pflush();
wait_a_while(nap_msec);
saywhat("d2;");
rmpanel(p2);
pflush();
wait_a_while(nap_msec);
saywhat("h3;");
hide_panel(p3);
pflush();
wait_a_while(nap_msec);
saywhat("d1;");
rmpanel(p1);
pflush();
wait_a_while(nap_msec);
saywhat("d4; ");
rmpanel(p4);
pflush();
wait_a_while(nap_msec);
saywhat("d5; ");
rmpanel(p5);
pflush();
wait_a_while(nap_msec);
if (nap_msec == 1)
break;
nap_msec = 100L;
}
endwin();
return 0;
} /* end of main */

View File

@@ -0,0 +1,159 @@
/****************************************************************************
* Copyright (c) 2002 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/* $Id: rain.c,v 1.11 2008/07/13 16:08:17 wmcbrine Exp $ */
#include <curses.h>
#include <stdlib.h>
#include <time.h>
/* rain 11/3/1980 EPS/CITHEP */
static int next_j(int j)
{
if (j == 0)
j = 4;
else
--j;
if (has_colors())
{
int z = rand() % 3;
chtype color = COLOR_PAIR(z);
if (z)
color |= A_BOLD;
attrset(color);
}
return j;
}
int main(int argc, char *argv[])
{
int x, y, j, r, c, seed;
static int xpos[5], ypos[5];
#ifdef XCURSES
Xinitscr(argc, argv);
#else
initscr();
#endif
seed = time((time_t *)0);
srand(seed);
if (has_colors())
{
int bg = COLOR_BLACK;
start_color();
#if defined(NCURSES_VERSION) || (defined(PDC_BUILD) && PDC_BUILD > 3000)
if (use_default_colors() == OK)
bg = -1;
#endif
init_pair(1, COLOR_BLUE, bg);
init_pair(2, COLOR_CYAN, bg);
}
nl();
noecho();
curs_set(0);
timeout(0);
keypad(stdscr, TRUE);
r = LINES - 4;
c = COLS - 4;
for (j = 5; --j >= 0;)
{
xpos[j] = rand() % c + 2;
ypos[j] = rand() % r + 2;
}
for (j = 0;;)
{
x = rand() % c + 2;
y = rand() % r + 2;
mvaddch(y, x, '.');
mvaddch(ypos[j], xpos[j], 'o');
j = next_j(j);
mvaddch(ypos[j], xpos[j], 'O');
j = next_j(j);
mvaddch(ypos[j] - 1, xpos[j], '-');
mvaddstr(ypos[j], xpos[j] - 1, "|.|");
mvaddch(ypos[j] + 1, xpos[j], '-');
j = next_j(j);
mvaddch(ypos[j] - 2, xpos[j], '-');
mvaddstr(ypos[j] - 1, xpos[j] - 1, "/ \\");
mvaddstr(ypos[j], xpos[j] - 2, "| O |");
mvaddstr(ypos[j] + 1, xpos[j] - 1, "\\ /");
mvaddch(ypos[j] + 2, xpos[j], '-');
j = next_j(j);
mvaddch(ypos[j] - 2, xpos[j], ' ');
mvaddstr(ypos[j] - 1, xpos[j] - 1, " ");
mvaddstr(ypos[j], xpos[j] - 2, " ");
mvaddstr(ypos[j] + 1, xpos[j] - 1, " ");
mvaddch(ypos[j] + 2, xpos[j], ' ');
xpos[j] = x;
ypos[j] = y;
switch (getch())
{
case 'q':
case 'Q':
curs_set(1);
endwin();
return EXIT_SUCCESS;
case 's':
nodelay(stdscr, FALSE);
break;
case ' ':
nodelay(stdscr, TRUE);
#ifdef KEY_RESIZE
break;
case KEY_RESIZE:
# ifdef PDCURSES
resize_term(0, 0);
erase();
# endif
r = LINES - 4;
c = COLS - 4;
#endif
}
napms(50);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,821 @@
/********************************* tui.c ************************************/
/*
* 'textual user interface'
*
* $Id: tui.c,v 1.34 2008/07/14 12:35:23 wmcbrine Exp $
*
* Author : P.J. Kunst <kunst@prl.philips.nl>
* Date : 25-02-93
*/
#include <ctype.h>
#include <curses.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "tui.h"
void statusmsg(char *);
int waitforkey(void);
void rmerror(void);
#if defined(__unix) && !defined(__DJGPP__)
#include <unistd.h>
#endif
#ifdef A_COLOR
# define TITLECOLOR 1 /* color pair indices */
# define MAINMENUCOLOR (2 | A_BOLD)
# define MAINMENUREVCOLOR (3 | A_BOLD | A_REVERSE)
# define SUBMENUCOLOR (4 | A_BOLD)
# define SUBMENUREVCOLOR (5 | A_BOLD | A_REVERSE)
# define BODYCOLOR 6
# define STATUSCOLOR (7 | A_BOLD)
# define INPUTBOXCOLOR 8
# define EDITBOXCOLOR (9 | A_BOLD | A_REVERSE)
#else
# define TITLECOLOR 0 /* color pair indices */
# define MAINMENUCOLOR (A_BOLD)
# define MAINMENUREVCOLOR (A_BOLD | A_REVERSE)
# define SUBMENUCOLOR (A_BOLD)
# define SUBMENUREVCOLOR (A_BOLD | A_REVERSE)
# define BODYCOLOR 0
# define STATUSCOLOR (A_BOLD)
# define INPUTBOXCOLOR 0
# define EDITBOXCOLOR (A_BOLD | A_REVERSE)
#endif
#define th 1 /* title window height */
#define mh 1 /* main menu height */
#define sh 2 /* status window height */
#define bh (LINES - th - mh - sh) /* body window height */
#define bw COLS /* body window width */
/******************************* STATIC ************************************/
static WINDOW *wtitl, *wmain, *wbody, *wstat; /* title, menu, body, status win*/
static int nexty, nextx;
static int key = ERR, ch = ERR;
static bool quit = FALSE;
static bool incurses = FALSE;
#ifndef PDCURSES
static char wordchar(void)
{
return 0x17; /* ^W */
}
#endif
static char *padstr(char *s, int length)
{
static char buf[MAXSTRLEN];
char fmt[10];
sprintf(fmt, (int)strlen(s) > length ? "%%.%ds" : "%%-%ds", length);
sprintf(buf, fmt, s);
return buf;
}
static char *prepad(char *s, int length)
{
int i;
char *p = s;
if (length > 0)
{
memmove((void *)(s + length), (const void *)s, strlen(s) + 1);
for (i = 0; i < length; i++)
*p++ = ' ';
}
return s;
}
static void rmline(WINDOW *win, int nr) /* keeps box lines intact */
{
mvwaddstr(win, nr, 1, padstr(" ", bw - 2));
wrefresh(win);
}
static void initcolor(void)
{
#ifdef A_COLOR
if (has_colors())
start_color();
/* foreground, background */
init_pair(TITLECOLOR & ~A_ATTR, COLOR_BLACK, COLOR_CYAN);
init_pair(MAINMENUCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_CYAN);
init_pair(MAINMENUREVCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_BLACK);
init_pair(SUBMENUCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_CYAN);
init_pair(SUBMENUREVCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_BLACK);
init_pair(BODYCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_BLUE);
init_pair(STATUSCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_CYAN);
init_pair(INPUTBOXCOLOR & ~A_ATTR, COLOR_BLACK, COLOR_CYAN);
init_pair(EDITBOXCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_BLACK);
#endif
}
static void setcolor(WINDOW *win, chtype color)
{
chtype attr = color & A_ATTR; /* extract Bold, Reverse, Blink bits */
#ifdef A_COLOR
attr &= ~A_REVERSE; /* ignore reverse, use colors instead! */
wattrset(win, COLOR_PAIR(color & A_CHARTEXT) | attr);
#else
attr &= ~A_BOLD; /* ignore bold, gives messy display on HP-UX */
wattrset(win, attr);
#endif
}
static void colorbox(WINDOW *win, chtype color, int hasbox)
{
int maxy;
#ifndef PDCURSES
int maxx;
#endif
chtype attr = color & A_ATTR; /* extract Bold, Reverse, Blink bits */
setcolor(win, color);
#ifdef A_COLOR
if (has_colors())
wbkgd(win, COLOR_PAIR(color & A_CHARTEXT) | (attr & ~A_REVERSE));
else
#endif
wbkgd(win, attr);
werase(win);
#ifdef PDCURSES
maxy = getmaxy(win);
#else
getmaxyx(win, maxy, maxx);
#endif
if (hasbox && (maxy > 2))
box(win, 0, 0);
touchwin(win);
wrefresh(win);
}
static void idle(void)
{
char buf[MAXSTRLEN];
time_t t;
struct tm *tp;
if (time (&t) == -1)
return; /* time not available */
tp = localtime(&t);
sprintf(buf, " %.2d-%.2d-%.4d %.2d:%.2d:%.2d",
tp->tm_mday, tp->tm_mon + 1, tp->tm_year + 1900,
tp->tm_hour, tp->tm_min, tp->tm_sec);
mvwaddstr(wtitl, 0, bw - strlen(buf) - 2, buf);
wrefresh(wtitl);
}
static void menudim(menu *mp, int *lines, int *columns)
{
int n, l, mmax = 0;
for (n=0; mp->func; n++, mp++)
if ((l = strlen(mp->name)) > mmax) mmax = l;
*lines = n;
*columns = mmax + 2;
}
static void setmenupos(int y, int x)
{
nexty = y;
nextx = x;
}
static void getmenupos(int *y, int *x)
{
*y = nexty;
*x = nextx;
}
static int hotkey(const char *s)
{
int c0 = *s; /* if no upper case found, return first char */
for (; *s; s++)
if (isupper((unsigned char)*s))
break;
return *s ? *s : c0;
}
static void repaintmenu(WINDOW *wmenu, menu *mp)
{
int i;
menu *p = mp;
for (i = 0; p->func; i++, p++)
mvwaddstr(wmenu, i + 1, 2, p->name);
touchwin(wmenu);
wrefresh(wmenu);
}
static void repaintmainmenu(int width, menu *mp)
{
int i;
menu *p = mp;
for (i = 0; p->func; i++, p++)
mvwaddstr(wmain, 0, i * width, prepad(padstr(p->name, width - 1), 1));
touchwin(wmain);
wrefresh(wmain);
}
static void mainhelp(void)
{
#ifdef ALT_X
statusmsg("Use arrow keys and Enter to select (Alt-X to quit)");
#else
statusmsg("Use arrow keys and Enter to select");
#endif
}
static void mainmenu(menu *mp)
{
int nitems, barlen, old = -1, cur = 0, c, cur0;
menudim(mp, &nitems, &barlen);
repaintmainmenu(barlen, mp);
while (!quit)
{
if (cur != old)
{
if (old != -1)
{
mvwaddstr(wmain, 0, old * barlen,
prepad(padstr(mp[old].name, barlen - 1), 1));
statusmsg(mp[cur].desc);
}
else
mainhelp();
setcolor(wmain, MAINMENUREVCOLOR);
mvwaddstr(wmain, 0, cur * barlen,
prepad(padstr(mp[cur].name, barlen - 1), 1));
setcolor(wmain, MAINMENUCOLOR);
old = cur;
wrefresh(wmain);
}
switch (c = (key != ERR ? key : waitforkey()))
{
case KEY_DOWN:
case '\n': /* menu item selected */
touchwin(wbody);
wrefresh(wbody);
rmerror();
setmenupos(th + mh, cur * barlen);
curs_set(1);
(mp[cur].func)(); /* perform function */
curs_set(0);
switch (key)
{
case KEY_LEFT:
cur = (cur + nitems - 1) % nitems;
key = '\n';
break;
case KEY_RIGHT:
cur = (cur + 1) % nitems;
key = '\n';
break;
default:
key = ERR;
}
repaintmainmenu(barlen, mp);
old = -1;
break;
case KEY_LEFT:
cur = (cur + nitems - 1) % nitems;
break;
case KEY_RIGHT:
cur = (cur + 1) % nitems;
break;
case KEY_ESC:
mainhelp();
break;
default:
cur0 = cur;
do
{
cur = (cur + 1) % nitems;
} while ((cur != cur0) && (hotkey(mp[cur].name) != toupper(c)));
if (hotkey(mp[cur].name) == toupper(c))
key = '\n';
}
}
rmerror();
touchwin(wbody);
wrefresh(wbody);
}
static void cleanup(void) /* cleanup curses settings */
{
if (incurses)
{
delwin(wtitl);
delwin(wmain);
delwin(wbody);
delwin(wstat);
curs_set(1);
endwin();
incurses = FALSE;
}
}
/******************************* EXTERNAL **********************************/
void clsbody(void)
{
werase(wbody);
wmove(wbody, 0, 0);
}
int bodylen(void)
{
#ifdef PDCURSES
return getmaxy(wbody);
#else
int maxy, maxx;
getmaxyx(wbody, maxy, maxx);
return maxy;
#endif
}
WINDOW *bodywin(void)
{
return wbody;
}
void rmerror(void)
{
rmline(wstat, 0);
}
void rmstatus(void)
{
rmline(wstat, 1);
}
void titlemsg(char *msg)
{
mvwaddstr(wtitl, 0, 2, padstr(msg, bw - 3));
wrefresh(wtitl);
}
void bodymsg(char *msg)
{
waddstr(wbody, msg);
wrefresh(wbody);
}
void errormsg(char *msg)
{
beep();
mvwaddstr(wstat, 0, 2, padstr(msg, bw - 3));
wrefresh(wstat);
}
void statusmsg(char *msg)
{
mvwaddstr(wstat, 1, 2, padstr(msg, bw - 3));
wrefresh(wstat);
}
bool keypressed(void)
{
ch = wgetch(wbody);
return ch != ERR;
}
int getkey(void)
{
int c = ch;
ch = ERR;
#ifdef ALT_X
quit = (c == ALT_X); /* PC only ! */
#endif
return c;
}
int waitforkey(void)
{
do idle(); while (!keypressed());
return getkey();
}
void DoExit(void) /* terminate program */
{
quit = TRUE;
}
void domenu(menu *mp)
{
int y, x, nitems, barlen, mheight, mw, old = -1, cur = 0, cur0;
bool stop = FALSE;
WINDOW *wmenu;
curs_set(0);
getmenupos(&y, &x);
menudim(mp, &nitems, &barlen);
mheight = nitems + 2;
mw = barlen + 2;
wmenu = newwin(mheight, mw, y, x);
colorbox(wmenu, SUBMENUCOLOR, 1);
repaintmenu(wmenu, mp);
key = ERR;
while (!stop && !quit)
{
if (cur != old)
{
if (old != -1)
mvwaddstr(wmenu, old + 1, 1,
prepad(padstr(mp[old].name, barlen - 1), 1));
setcolor(wmenu, SUBMENUREVCOLOR);
mvwaddstr(wmenu, cur + 1, 1,
prepad(padstr(mp[cur].name, barlen - 1), 1));
setcolor(wmenu, SUBMENUCOLOR);
statusmsg(mp[cur].desc);
old = cur;
wrefresh(wmenu);
}
switch (key = ((key != ERR) ? key : waitforkey()))
{
case '\n': /* menu item selected */
touchwin(wbody);
wrefresh(wbody);
setmenupos(y + 1, x + 1);
rmerror();
key = ERR;
curs_set(1);
(mp[cur].func)(); /* perform function */
curs_set(0);
repaintmenu(wmenu, mp);
old = -1;
break;
case KEY_UP:
cur = (cur + nitems - 1) % nitems;
key = ERR;
break;
case KEY_DOWN:
cur = (cur + 1) % nitems;
key = ERR;
break;
case KEY_ESC:
case KEY_LEFT:
case KEY_RIGHT:
if (key == KEY_ESC)
key = ERR; /* return to prev submenu */
stop = TRUE;
break;
default:
cur0 = cur;
do
{
cur = (cur + 1) % nitems;
} while ((cur != cur0) &&
(hotkey(mp[cur].name) != toupper((int)key)));
key = (hotkey(mp[cur].name) == toupper((int)key)) ? '\n' : ERR;
}
}
rmerror();
delwin(wmenu);
touchwin(wbody);
wrefresh(wbody);
}
void startmenu(menu *mp, char *mtitle)
{
initscr();
incurses = TRUE;
initcolor();
wtitl = subwin(stdscr, th, bw, 0, 0);
wmain = subwin(stdscr, mh, bw, th, 0);
wbody = subwin(stdscr, bh, bw, th + mh, 0);
wstat = subwin(stdscr, sh, bw, th + mh + bh, 0);
colorbox(wtitl, TITLECOLOR, 0);
colorbox(wmain, MAINMENUCOLOR, 0);
colorbox(wbody, BODYCOLOR, 0);
colorbox(wstat, STATUSCOLOR, 0);
if (mtitle)
titlemsg(mtitle);
cbreak(); /* direct input (no newline required)... */
noecho(); /* ... without echoing */
curs_set(0); /* hide cursor (if possible) */
nodelay(wbody, TRUE); /* don't wait for input... */
halfdelay(10); /* ...well, no more than a second, anyway */
keypad(wbody, TRUE); /* enable cursor keys */
scrollok(wbody, TRUE); /* enable scrolling in main window */
leaveok(stdscr, TRUE);
leaveok(wtitl, TRUE);
leaveok(wmain, TRUE);
leaveok(wstat, TRUE);
mainmenu(mp);
cleanup();
}
static void repainteditbox(WINDOW *win, int x, char *buf)
{
#ifndef PDCURSES
int maxy;
#endif
int maxx;
#ifdef PDCURSES
maxx = getmaxx(win);
#else
getmaxyx(win, maxy, maxx);
#endif
werase(win);
mvwprintw(win, 0, 0, "%s", padstr(buf, maxx));
wmove(win, 0, x);
wrefresh(win);
}
/*
weditstr() - edit string
Description:
The initial value of 'str' with a maximum length of 'field' - 1,
which is supplied by the calling routine, is editted. The user's
erase (^H), kill (^U) and delete word (^W) chars are interpreted.
The PC insert or Tab keys toggle between insert and edit mode.
Escape aborts the edit session, leaving 'str' unchanged.
Enter, Up or Down Arrow are used to accept the changes to 'str'.
NOTE: editstr(), mveditstr(), and mvweditstr() are macros.
Return Value:
Returns the input terminating character on success (Escape,
Enter, Up or Down Arrow) and ERR on error.
Errors:
It is an error to call this function with a NULL window pointer.
The length of the initial 'str' must not exceed 'field' - 1.
*/
int weditstr(WINDOW *win, char *buf, int field)
{
char org[MAXSTRLEN], *tp, *bp = buf;
bool defdisp = TRUE, stop = FALSE, insert = FALSE;
int cury, curx, begy, begx, oldattr;
WINDOW *wedit;
int c = 0;
if ((field >= MAXSTRLEN) || (buf == NULL) ||
((int)strlen(buf) > field - 1))
return ERR;
strcpy(org, buf); /* save original */
wrefresh(win);
getyx(win, cury, curx);
getbegyx(win, begy, begx);
wedit = subwin(win, 1, field, begy + cury, begx + curx);
oldattr = wedit->_attrs;
colorbox(wedit, EDITBOXCOLOR, 0);
keypad(wedit, TRUE);
curs_set(1);
while (!stop)
{
idle();
repainteditbox(wedit, bp - buf, buf);
switch (c = wgetch(wedit))
{
case ERR:
break;
case KEY_ESC:
strcpy(buf, org); /* restore original */
stop = TRUE;
break;
case '\n':
case KEY_UP:
case KEY_DOWN:
stop = TRUE;
break;
case KEY_LEFT:
if (bp > buf)
bp--;
break;
case KEY_RIGHT:
defdisp = FALSE;
if (bp - buf < (int)strlen(buf))
bp++;
break;
case '\t': /* TAB -- because insert
is broken on HPUX */
case KEY_IC: /* enter insert mode */
case KEY_EIC: /* exit insert mode */
defdisp = FALSE;
insert = !insert;
curs_set(insert ? 2 : 1);
break;
default:
if (c == erasechar()) /* backspace, ^H */
{
if (bp > buf)
{
memmove((void *)(bp - 1), (const void *)bp, strlen(bp) + 1);
bp--;
}
}
else if (c == killchar()) /* ^U */
{
bp = buf;
*bp = '\0';
}
else if (c == wordchar()) /* ^W */
{
tp = bp;
while ((bp > buf) && (*(bp - 1) == ' '))
bp--;
while ((bp > buf) && (*(bp - 1) != ' '))
bp--;
memmove((void *)bp, (const void *)tp, strlen(tp) + 1);
}
else if (isprint(c))
{
if (defdisp)
{
bp = buf;
*bp = '\0';
defdisp = FALSE;
}
if (insert)
{
if ((int)strlen(buf) < field - 1)
{
memmove((void *)(bp + 1), (const void *)bp,
strlen(bp) + 1);
*bp++ = c;
}
}
else if (bp - buf < field - 1)
{
/* append new string terminator */
if (!*bp)
bp[1] = '\0';
*bp++ = c;
}
}
}
}
curs_set(0);
wattrset(wedit, oldattr);
repainteditbox(wedit, bp - buf, buf);
delwin(wedit);
return c;
}
WINDOW *winputbox(WINDOW *win, int nlines, int ncols)
{
WINDOW *winp;
int cury, curx, begy, begx;
getyx(win, cury, curx);
getbegyx(win, begy, begx);
winp = newwin(nlines, ncols, begy + cury, begx + curx);
colorbox(winp, INPUTBOXCOLOR, 1);
return winp;
}
int getstrings(char *desc[], char *buf[], int field)
{
WINDOW *winput;
int oldy, oldx, maxy, maxx, nlines, ncols, i, n, l, mmax = 0;
int c = 0;
bool stop = FALSE;
for (n = 0; desc[n]; n++)
if ((l = strlen(desc[n])) > mmax)
mmax = l;
nlines = n + 2; ncols = mmax + field + 4;
getyx(wbody, oldy, oldx);
getmaxyx(wbody, maxy, maxx);
winput = mvwinputbox(wbody, (maxy - nlines) / 2, (maxx - ncols) / 2,
nlines, ncols);
for (i = 0; i < n; i++)
mvwprintw(winput, i + 1, 2, "%s", desc[i]);
i = 0;
while (!stop)
{
switch (c = mvweditstr(winput, i+1, mmax+3, buf[i], field))
{
case KEY_ESC:
stop = TRUE;
break;
case KEY_UP:
i = (i + n - 1) % n;
break;
case '\n':
case '\t':
case KEY_DOWN:
if (++i == n)
stop = TRUE; /* all passed? */
}
}
delwin(winput);
touchwin(wbody);
wmove(wbody, oldy, oldx);
wrefresh(wbody);
return c;
}

View File

@@ -0,0 +1,67 @@
/*
* 'textual user interface'
*
* $Id: tui.h,v 1.11 2008/07/14 12:35:23 wmcbrine Exp $
*
* Author : P.J. Kunst <kunst@prl.philips.nl>
* Date : 25-02-93
*/
#ifndef _TUI_H_
#define _TUI_H_
#include <curses.h>
#ifdef A_COLOR
#define A_ATTR (A_ATTRIBUTES ^ A_COLOR) /* A_BLINK, A_REVERSE, A_BOLD */
#else
#define A_ATTR (A_ATTRIBUTES) /* standard UNIX attributes */
#endif
#define MAXSTRLEN 256
#define KEY_ESC 0x1b /* Escape */
typedef void (*FUNC)(void);
typedef struct
{
char *name; /* item label */
FUNC func; /* (pointer to) function */
char *desc; /* function description */
} menu;
/* ANSI C function prototypes: */
void clsbody(void);
int bodylen(void);
WINDOW *bodywin(void);
void rmerror(void);
void rmstatus(void);
void titlemsg(char *msg);
void bodymsg(char *msg);
void errormsg(char *msg);
void statusmsg(char *msg);
bool keypressed(void);
int getkey(void);
int waitforkey(void);
void DoExit(void);
void startmenu(menu *mp, char *title);
void domenu(menu *mp);
int weditstr(WINDOW *win, char *buf, int field);
WINDOW *winputbox(WINDOW *win, int nlines, int ncols);
int getstrings(char *desc[], char *buf[], int field);
#define editstr(s,f) (weditstr(stdscr,s,f))
#define mveditstr(y,x,s,f) (move(y,x)==ERR?ERR:editstr(s,f))
#define mvweditstr(w,y,x,s,f) (wmove(w,y,x)==ERR?ERR:weditstr(w,s,f))
#define inputbox(l,c) (winputbox(stdscr,l,c))
#define mvinputbox(y,x,l,c) (move(y,x)==ERR?w:inputbox(l,c))
#define mvwinputbox(w,y,x,l,c) (wmove(w,y,x)==ERR?w:winputbox(w,l,c))
#endif

View File

@@ -0,0 +1,233 @@
/*
* $Id: tuidemo.c,v 1.22 2008/07/14 12:35:23 wmcbrine Exp $
*
* Author : P.J. Kunst <kunst@prl.philips.nl>
* Date : 25-02-93
*
* Purpose: This program demonstrates the use of the 'curses' library
* for the creation of (simple) menu-operated programs.
* In the PDCurses version, use is made of colors for the
* highlighting of subwindows (title bar, status bar etc).
*
* Acknowledgement: some ideas were borrowed from Mark Hessling's
* version of the 'testcurs' program.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include "tui.h"
/* change this if source at other location */
#ifdef XCURSES
# define FNAME "../demos/tui.c"
#else
# define FNAME "..\\demos\\tui.c"
#endif
/**************************** strings entry box ***************************/
void address(void)
{
char *fieldname[6] =
{
"Name", "Street", "City", "State", "Country", (char *)0
};
char *fieldbuf[5];
WINDOW *wbody = bodywin();
int i, field = 50;
for (i = 0; i < 5; i++)
fieldbuf[i] = calloc(1, field + 1);
if (getstrings(fieldname, fieldbuf, field) != KEY_ESC)
{
for (i = 0; fieldname[i]; i++)
wprintw(wbody, "%10s : %s\n",
fieldname[i], fieldbuf[i]);
wrefresh(wbody);
}
for (i = 0; i < 5; i++)
free(fieldbuf[i]);
}
/**************************** string entry box ****************************/
char *getfname(char *desc, char *fname, int field)
{
char *fieldname[2];
char *fieldbuf[1];
fieldname[0] = desc;
fieldname[1] = 0;
fieldbuf[0] = fname;
return (getstrings(fieldname, fieldbuf, field) == KEY_ESC) ? NULL : fname;
}
/**************************** a very simple file browser ******************/
void showfile(char *fname)
{
int i, bh = bodylen();
FILE *fp;
char buf[MAXSTRLEN];
bool ateof = FALSE;
statusmsg("FileBrowser: Hit key to continue, Q to quit");
if ((fp = fopen(fname, "r")) != NULL) /* file available? */
{
while (!ateof)
{
clsbody();
for (i = 0; i < bh - 1 && !ateof; i++)
{
buf[0] = '\0';
fgets(buf, MAXSTRLEN, fp);
if (strlen(buf))
bodymsg(buf);
else
ateof = TRUE;
}
switch (waitforkey())
{
case 'Q':
case 'q':
case 0x1b:
ateof = TRUE;
}
}
fclose(fp);
}
else
{
sprintf(buf, "ERROR: file '%s' not found", fname);
errormsg(buf);
}
}
/***************************** forward declarations ***********************/
void sub0(void), sub1(void), sub2(void), sub3(void);
void func1(void), func2(void);
void subfunc1(void), subfunc2(void);
void subsub(void);
/***************************** menus initialization ***********************/
menu MainMenu[] =
{
{ "Asub", sub0, "Go inside first submenu" },
{ "Bsub", sub1, "Go inside second submenu" },
{ "Csub", sub2, "Go inside third submenu" },
{ "Dsub", sub3, "Go inside fourth submenu" },
{ "", (FUNC)0, "" } /* always add this as the last item! */
};
menu SubMenu0[] =
{
{ "Exit", DoExit, "Terminate program" },
{ "", (FUNC)0, "" }
};
menu SubMenu1[] =
{
{ "OneBeep", func1, "Sound one beep" },
{ "TwoBeeps", func2, "Sound two beeps" },
{ "", (FUNC)0, "" }
};
menu SubMenu2[] =
{
{ "Browse", subfunc1, "Source file lister" },
{ "Input", subfunc2, "Interactive file lister" },
{ "Address", address, "Get address data" },
{ "", (FUNC)0, "" }
};
menu SubMenu3[] =
{
{ "SubSub", subsub, "Go inside sub-submenu" },
{ "", (FUNC)0, "" }
};
/***************************** main menu functions ************************/
void sub0(void)
{
domenu(SubMenu0);
}
void sub1(void)
{
domenu(SubMenu1);
}
void sub2(void)
{
domenu(SubMenu2);
}
void sub3(void)
{
domenu(SubMenu3);
}
/***************************** submenu1 functions *************************/
void func1(void)
{
beep();
bodymsg("One beep! ");
}
void func2(void)
{
beep();
bodymsg("Two beeps! ");
beep();
}
/***************************** submenu2 functions *************************/
void subfunc1(void)
{
showfile(FNAME);
}
void subfunc2(void)
{
char fname[MAXSTRLEN];
strcpy(fname, FNAME);
if (getfname ("File to browse:", fname, 50))
showfile(fname);
}
/***************************** submenu3 functions *************************/
void subsub(void)
{
domenu(SubMenu2);
}
/***************************** start main menu ***************************/
int main(int argc, char **argv)
{
setlocale(LC_ALL, "");
startmenu(MainMenu, "TUI - 'textual user interface' demonstration program");
return 0;
}

View File

@@ -0,0 +1,434 @@
/****************************************************************************
* Copyright (c) 2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/*
@@@ @@@ @@@@@@@@@@ @@@@@@@@@@@ @@@@@@@@@@@@
@@@ @@@ @@@@@@@@@@@@ @@@@@@@@@@@@ @@@@@@@@@@@@@
@@@ @@@ @@@@ @@@@ @@@@ @@@@ @@@ @@@@
@@@ @@ @@@ @@@ @@@ @@@ @@@ @@@ @@@
@@@ @@@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@
@@@@ @@@@ @@@@ @@@ @@@ @@@ @@@ @@@ @@@
@@@@@@@@@@@@ @@@@ @@@@ @@@ @@@ @@@ @@@
@@@@ @@@@ @@@@@@@@@@@@ @@@ @@@ @@@ @@@
@@ @@ @@@@@@@@@@ @@@ @@@ @@@ @@@
Eric P. Scott
Caltech High Energy Physics
October, 1980
Color by Eric S. Raymond
July, 1995
Options:
-f fill screen with copies of 'WORM' at start.
-l <n> set worm length
-n <n> set number of worms
-t make worms leave droppings
$Id: worm.c,v 1.16 2008/07/13 16:08:17 wmcbrine Exp $
*/
#include <curses.h>
#include <stdlib.h>
#include <time.h>
#define FLAVORS 7
static chtype flavor[FLAVORS] =
{
'O', '*', '#', '$', '%', '0', '@'
};
static const 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 const char *field;
static int length = 16, number = 3;
static chtype trail = ' ';
static const 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 } }
};
static void cleanup(void)
{
standend();
refresh();
curs_set(1);
endwin();
}
int main(int argc, char *argv[])
{
const struct options *op;
struct worm *w;
short **ref, *ip;
int x, y, n, h, last, bottom, seed;
for (x = 1; x < argc; x++)
{
char *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);
return EXIT_FAILURE;
}
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);
return EXIT_FAILURE;
}
break;
case 't':
trail = '.';
break;
default:
usage:
fprintf(stderr, "usage: %s [-field] [-length #] "
"[-number #] [-trail]\n", *argv);
return EXIT_FAILURE;
}
}
#ifdef XCURSES
Xinitscr(argc, argv);
#else
initscr();
#endif
seed = time((time_t *)0);
srand(seed);
noecho();
cbreak();
nonl();
keypad(stdscr, TRUE);
curs_set(0);
bottom = LINES - 1;
last = COLS - 1;
#ifdef A_COLOR
if (has_colors())
{
int bg = COLOR_BLACK;
start_color();
# if defined(NCURSES_VERSION) || (defined(PDC_BUILD) && PDC_BUILD > 3000)
if (use_default_colors() == OK)
bg = -1;
# endif
# define SET_COLOR(num, fg) \
init_pair(num + 1, fg, bg); \
flavor[num] |= COLOR_PAIR(num + 1) | A_BOLD
SET_COLOR(0, COLOR_GREEN);
SET_COLOR(1, COLOR_RED);
SET_COLOR(2, COLOR_CYAN);
SET_COLOR(3, COLOR_WHITE);
SET_COLOR(4, COLOR_MAGENTA);
SET_COLOR(5, COLOR_BLUE);
SET_COLOR(6, COLOR_YELLOW);
}
#endif
ref = malloc(sizeof(short *) * LINES);
for (y = 0; y < LINES; y++)
{
ref[y] = malloc(sizeof(short) * COLS);
for (x = 0; x < COLS; x++)
ref[y][x] = 0;
}
#ifdef BADCORNER
/* if addressing the lower right corner doesn't work in your curses */
ref[bottom][last] = 1;
#endif
for (n = number, w = &worm[0]; --n >= 0; w++)
{
w->orientation = w->head = 0;
if ((ip = malloc(sizeof(short) * (length + 1))) == NULL)
{
fprintf(stderr, "%s: out of memory\n", *argv);
return EXIT_FAILURE;
}
w->xpos = ip;
for (x = length; --x >= 0;)
*ip++ = -1;
if ((ip = malloc(sizeof(short) * (length + 1))) == NULL)
{
fprintf(stderr, "%s: out of memory\n", *argv);
return EXIT_FAILURE;
}
w->ypos = ip;
for (y = length; --y >= 0;)
*ip++ = -1;
}
if (field)
{
const char *p = field;
for (y = bottom; --y >= 0;)
for (x = COLS; --x >= 0;)
{
addch((chtype) (*p++));
if (!*p)
p = field;
}
}
napms(12);
refresh();
nodelay(stdscr, TRUE);
for (;;)
{
int ch;
if ((ch = getch()) > 0)
{
#ifdef KEY_RESIZE
if (ch == KEY_RESIZE)
{
# ifdef PDCURSES
resize_term(0, 0);
erase();
# endif
if (last != COLS - 1)
{
for (y = 0; y <= bottom; y++)
{
ref[y] = realloc(ref[y], sizeof(short) * COLS);
for (x = last + 1; x < COLS; x++)
ref[y][x] = 0;
}
last = COLS - 1;
}
if (bottom != LINES - 1)
{
for (y = LINES; y <= bottom; y++)
free(ref[y]);
ref = realloc(ref, sizeof(short *) * LINES);
for (y = bottom + 1; y < LINES; y++)
{
ref[y] = malloc(sizeof(short) * COLS);
for (x = 0; x < COLS; x++)
ref[y][x] = 0;
}
bottom = LINES - 1;
}
}
#endif /* KEY_RESIZE */
/* Make it simple to put this into single-step mode,
or resume normal operation - T. Dickey */
if (ch == 'q')
{
cleanup();
return EXIT_SUCCESS;
}
else if (ch == 's')
nodelay(stdscr, FALSE);
else if (ch == ' ')
nodelay(stdscr, TRUE);
}
for (n = 0, w = &worm[0]; n < number; n++, w++)
{
if ((x = w->xpos[h = w->head]) < 0)
{
move(y = w->ypos[h] = bottom, x = w->xpos[h] = 0);
addch(flavor[n % FLAVORS]);
ref[y][x]++;
}
else
y = w->ypos[h];
if (x > last)
x = last;
if (y > bottom)
y = bottom;
if (++h == length)
h = 0;
if (w->xpos[w->head = h] >= 0)
{
int x1 = w->xpos[h];
int y1 = w->ypos[h];
if (y1 < LINES && x1 < COLS && --ref[y1][x1] == 0)
{
move(y1, x1);
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:
cleanup();
return EXIT_SUCCESS;
case 1:
w->orientation = op->opts[0];
break;
default:
w->orientation = op->opts[rand() % op->nopts];
}
move(y += yinc[w->orientation], x += xinc[w->orientation]);
if (y < 0)
y = 0;
addch(flavor[n % FLAVORS]);
ref[w->ypos[h] = y][w->xpos[h] = x]++;
}
napms(12);
refresh();
}
}

View File

@@ -0,0 +1,957 @@
/******************************************************************************/
/* 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 looks a lot better if you can turn off your cursor before execution. */
/* 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 xmas.c -lcurses -o xmas -s */
/* */
/******************************************************************************/
/* $Id: xmas.c,v 1.29 2008/07/13 16:08:17 wmcbrine Exp $ */
#include <curses.h>
#include <signal.h>
void lil(WINDOW *);
void midtop(WINDOW *);
void bigtop(WINDOW *);
void bigface(WINDOW *, chtype);
void legs1(WINDOW *);
void legs2(WINDOW *);
void legs3(WINDOW *);
void legs4(WINDOW *);
void initdeer(void);
void boxit(void);
void seas(void);
void greet(void);
void fromwho(void);
void del_msg(void);
void tree(void);
void balls(void);
void star(void);
void strng1(void);
void strng2(void);
void strng3(void);
void strng4(void);
void strng5(void);
void blinkit(void);
void reindeer(void);
#define FROMWHO "From Larry Bartz, Mark Hessling and William McBrine"
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;
int main(int argc, char **argv)
{
int loopy;
#ifdef XCURSES
Xinitscr(argc, argv);
#else
initscr();
#endif
nodelay(stdscr, TRUE);
noecho();
nonl();
refresh();
#ifdef A_COLOR
if (has_colors())
start_color();
#endif
curs_set(0);
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);
w_holiday = newwin(1, 26, 3, 27);
w_del_msg = newwin(1, 12, 23, 60);
mvwaddstr(w_holiday, 0, 0, "H A P P Y H O L I D A Y S");
initdeer();
clear();
werase(treescrn);
touchwin(treescrn);
werase(treescrn2);
touchwin(treescrn2);
werase(treescrn8);
touchwin(treescrn8);
refresh();
napms(1000);
boxit();
del_msg();
napms(1000);
seas();
del_msg();
napms(1000);
greet();
del_msg();
napms(1000);
fromwho();
del_msg();
napms(1000);
tree();
napms(1000);
balls();
napms(1000);
star();
napms(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 */
mvwaddch(treescrn4, 0, 12, '*' | A_STANDOUT);
/* 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 */
mvwaddch(treescrn6, 0, 12, '*' | A_STANDOUT);
/* 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, ' ');
napms(1000);
reindeer();
touchwin(w_holiday);
wrefresh(w_holiday);
wrefresh(w_del_msg);
napms(1000);
for (loopy = 0; loopy < 50; loopy++)
blinkit();
clear();
refresh();
endwin();
return 0;
}
void lil(WINDOW *win)
{
mvwaddch(win, 0, 0, (chtype) 'V');
mvwaddch(win, 1, 0, (chtype) '@');
mvwaddch(win, 1, 3, (chtype) '~');
}
void midtop(WINDOW *win)
{
mvwaddstr(win, 0, 2, "yy");
mvwaddstr(win, 1, 2, "0(=)~");
}
void bigtop(WINDOW *win)
{
mvwaddstr(win, 0, 17, "\\/");
mvwaddstr(win, 0, 20, "\\/");
mvwaddch(win, 1, 18, (chtype) '\\');
mvwaddch(win, 1, 20, (chtype) '/');
mvwaddstr(win, 2, 19, "|_");
mvwaddstr(win, 3, 18, "/^0\\");
mvwaddstr(win, 4, 17, "//\\");
mvwaddch(win, 4, 22, (chtype) '\\');
mvwaddstr(win, 5, 7, "^~~~~~~~~// ~~U");
}
void bigface(WINDOW *win, chtype noseattr)
{
mvwaddstr(win, 0, 16, "\\/ \\/");
mvwaddstr(win, 1, 17, "\\Y/ \\Y/");
mvwaddstr(win, 2, 19, "\\=/");
mvwaddstr(win, 3, 17, "^\\o o/^");
mvwaddstr(win, 4, 17, "//( )");
mvwaddstr(win, 5, 7, "^~~~~~~~~// \\");
waddch(win, 'O' | noseattr);
waddstr(win, "/");
}
void legs1(WINDOW *win)
{
mvwaddstr(win, 6, 7, "( \\_____( /");
mvwaddstr(win, 7, 8, "( ) /");
mvwaddstr(win, 8, 9, "\\\\ /");
mvwaddstr(win, 9, 11, "\\>/>");
}
void legs2(WINDOW *win)
{
mvwaddstr(win, 6, 7, "(( )____( /");
mvwaddstr(win, 7, 7, "( / |");
mvwaddstr(win, 8, 8, "\\/ |");
mvwaddstr(win, 9, 9, "|> |>");
}
void legs3(WINDOW *win)
{
mvwaddstr(win, 6, 6, "( ()_____( /");
mvwaddstr(win, 7, 6, "/ / /");
mvwaddstr(win, 8, 5, "|/ \\");
mvwaddstr(win, 9, 5, "/> \\>");
}
void legs4(WINDOW *win)
{
mvwaddstr(win, 6, 6, "( )______( /");
mvwaddstr(win, 7, 5, "(/ \\");
mvwaddstr(win, 8, 0, "v___= ----^");
}
void initdeer(void)
{
chtype noseattr;
#ifdef A_COLOR
if (has_colors())
{
init_pair(31, COLOR_RED, COLOR_BLACK);
noseattr = COLOR_PAIR(31);
}
else
#endif
noseattr = A_NORMAL;
/* set up the windows for our various reindeer */
dotdeer0 = newwin(3, 71, 0, 8);
stardeer0 = newwin(4, 56, 0, 8);
lildeer0 = newwin(7, 54, 0, 8);
middeer0 = newwin(15, 42, 0, 8);
bigdeer0 = newwin(10, 23, 0, 0);
lookdeer0 = newwin(10, 25, 0, 0);
/* lildeer1 */
lildeer1 = newwin(2, 4, 0, 0);
lil(lildeer1);
mvwaddstr(lildeer1, 1, 1, "<>");
/* lildeer2 */
lildeer2 = newwin(2, 4, 0, 0);
lil(lildeer2);
mvwaddstr(lildeer2, 1, 1, "||");
/* lildeer3 */
lildeer3 = newwin(2, 4, 0, 0);
lil(lildeer3);
mvwaddstr(lildeer3, 1, 1, "><");
/* middeer1 */
middeer1 = newwin(3, 7, 0, 0);
midtop(middeer1);
mvwaddstr(middeer1, 2, 3, "\\/");
/* middeer2 */
middeer2 = newwin(3, 7, 0, 0);
midtop(middeer2);
mvwaddch(middeer2, 2, 3, (chtype) '|');
mvwaddch(middeer2, 2, 5, (chtype) '|');
/* middeer3 */
middeer3 = newwin(3, 7, 0, 0);
midtop(middeer3);
mvwaddch(middeer3, 2, 2, (chtype) '/');
mvwaddch(middeer3, 2, 6, (chtype) '\\');
/* bigdeer1 */
bigdeer1 = newwin(10, 23, 0, 0);
bigtop(bigdeer1);
legs1(bigdeer1);
/* bigdeer2 */
bigdeer2 = newwin(10, 23, 0, 0);
bigtop(bigdeer2);
legs2(bigdeer2);
/* bigdeer3 */
bigdeer3 = newwin(10, 23, 0, 0);
bigtop(bigdeer3);
legs3(bigdeer3);
/* bigdeer4 */
bigdeer4 = newwin(10, 23, 0, 0);
bigtop(bigdeer4);
legs4(bigdeer4);
/* lookdeer1 */
lookdeer1 = newwin(10, 25, 0, 0);
bigface(lookdeer1, noseattr);
legs1(lookdeer1);
/* lookdeer2 */
lookdeer2 = newwin(10, 25, 0, 0);
bigface(lookdeer2, noseattr);
legs2(lookdeer2);
/* lookdeer3 */
lookdeer3 = newwin(10, 25, 0, 0);
bigface(lookdeer3, noseattr);
legs3(lookdeer3);
/* lookdeer4 */
lookdeer4 = newwin(10, 25, 0, 0);
bigface(lookdeer4, noseattr);
legs4(lookdeer4);
}
void boxit(void)
{
int x;
for (x = 0; x < 20; ++x)
mvaddch(x, 7, '|');
for (x = 0; x < 80; ++x)
{
if (x > 7)
mvaddch(19, x, '_');
mvaddch(22, x, '_');
}
}
void seas(void)
{
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');
}
void greet(void)
{
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');
}
void fromwho(void)
{
mvaddstr(21, 13, FROMWHO);
}
void del_msg(void)
{
refresh();
}
void tree(void)
{
#ifdef A_COLOR
if (has_colors())
{
init_pair(30, COLOR_GREEN, COLOR_BLACK);
wattrset(treescrn, COLOR_PAIR(30));
}
#endif
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,
"//////////// \\\\\\\\\\\\\\\\\\\\\\\\");
#ifdef A_COLOR
if (has_colors())
{
init_pair(20, COLOR_YELLOW, COLOR_BLACK);
wattrset(treescrn, COLOR_PAIR(20));
}
#endif
mvwaddstr(treescrn, 14, 11, "| |");
mvwaddstr(treescrn, 15, 11, "|_|");
wrefresh(treescrn);
wrefresh(w_del_msg);
}
void balls(void)
{
chtype ball1, ball2, ball3, ball4, ball5, ball6;
overlay(treescrn, treescrn2);
#ifdef A_COLOR
if (has_colors())
{
init_pair(1, COLOR_BLUE, COLOR_BLACK);
init_pair(2, COLOR_RED, COLOR_BLACK);
init_pair(3, COLOR_MAGENTA, COLOR_BLACK);
init_pair(4, COLOR_CYAN, COLOR_BLACK);
init_pair(5, COLOR_YELLOW, COLOR_BLACK);
init_pair(6, COLOR_WHITE, COLOR_BLACK);
ball1 = COLOR_PAIR(1) | '@';
ball2 = COLOR_PAIR(2) | '@';
ball3 = COLOR_PAIR(3) | '@';
ball4 = COLOR_PAIR(4) | '@';
ball5 = COLOR_PAIR(5) | '@';
ball6 = COLOR_PAIR(6) | '@';
}
else
#endif
ball1 = ball2 = ball3 = ball4 = ball5 = ball6 = '@';
mvwaddch(treescrn2, 3, 9, ball1);
mvwaddch(treescrn2, 3, 15, ball2);
mvwaddch(treescrn2, 4, 8, ball3);
mvwaddch(treescrn2, 4, 16, ball4);
mvwaddch(treescrn2, 5, 7, ball5);
mvwaddch(treescrn2, 5, 17, ball6);
mvwaddch(treescrn2, 7, 6, ball1 | A_BOLD);
mvwaddch(treescrn2, 7, 18, ball2 | A_BOLD);
mvwaddch(treescrn2, 8, 5, ball3 | A_BOLD);
mvwaddch(treescrn2, 8, 19, ball4 | A_BOLD);
mvwaddch(treescrn2, 10, 4, ball5 | A_BOLD);
mvwaddch(treescrn2, 10, 20, ball6 | A_BOLD);
mvwaddch(treescrn2, 11, 2, ball1);
mvwaddch(treescrn2, 11, 22, ball2);
mvwaddch(treescrn2, 12, 1, ball3);
mvwaddch(treescrn2, 12, 23, ball4);
wrefresh(treescrn2);
wrefresh(w_del_msg);
}
void star(void)
{
mvwaddch(treescrn2, 0, 12, (chtype) '*' | A_STANDOUT);
wrefresh(treescrn2);
wrefresh(w_del_msg);
}
void strng1(void)
{
#ifdef A_COLOR
if (has_colors())
{
init_pair(10, COLOR_YELLOW, COLOR_BLACK);
wattrset(treescrn2, COLOR_PAIR(10) | A_BOLD);
}
#endif
mvwaddstr(treescrn2, 3, 11, ".:'");
wrefresh(treescrn2);
wrefresh(w_del_msg);
}
void strng2(void)
{
#ifdef A_COLOR
if (has_colors())
{
init_pair(11, COLOR_RED, COLOR_BLACK);
wattrset(treescrn2, COLOR_PAIR(11) | A_BOLD);
}
#endif
mvwaddstr(treescrn2, 5, 11, ",.:'");
mvwaddstr(treescrn2, 6, 9, ":'");
wrefresh(treescrn2);
wrefresh(w_del_msg);
}
void strng3(void)
{
#ifdef A_COLOR
if (has_colors())
{
init_pair(12, COLOR_GREEN, COLOR_BLACK);
wattrset(treescrn2, COLOR_PAIR(12) | A_BOLD);
}
#endif
mvwaddstr(treescrn2, 7, 13, ",.:'");
mvwaddstr(treescrn2, 8, 9, ",.:'");
wrefresh(treescrn2);
wrefresh(w_del_msg);
}
void strng4(void)
{
#ifdef A_COLOR
if (has_colors())
{
init_pair(13, COLOR_WHITE, COLOR_BLACK);
wattrset(treescrn2, COLOR_PAIR(13) | A_BOLD);
}
#endif
mvwaddstr(treescrn2, 9, 14, ",.:'");
mvwaddstr(treescrn2, 10, 10, ",.:'");
mvwaddstr(treescrn2, 11, 6, ",.:'");
mvwaddch(treescrn2, 12, 5, (chtype) '\'');
wrefresh(treescrn2);
wrefresh(w_del_msg);
}
void strng5(void)
{
#ifdef A_COLOR
if (has_colors())
{
init_pair(14, COLOR_CYAN, COLOR_BLACK);
wattrset(treescrn2, COLOR_PAIR(14) | A_BOLD);
}
#endif
mvwaddstr(treescrn2, 11, 16, ",.:'");
mvwaddstr(treescrn2, 12, 12, ",.:'");
/* save a fully lit tree */
overlay(treescrn2, treescrn);
wrefresh(treescrn2);
wrefresh(w_del_msg);
}
void blinkit(void)
{
static int cycle;
if (cycle > 4)
cycle = 0;
touchwin(treescrn8);
switch (cycle)
{
case 0:
overlay(treescrn3, treescrn8);
break;
case 1:
overlay(treescrn4, treescrn8);
break;
case 2:
overlay(treescrn5, treescrn8);
break;
case 3:
overlay(treescrn6, treescrn8);
break;
case 4:
overlay(treescrn7, treescrn8);
}
wrefresh(treescrn8);
wrefresh(w_del_msg);
napms(50);
touchwin(treescrn8);
/*ALL ON************************************************** */
overlay(treescrn, treescrn8);
wrefresh(treescrn8);
wrefresh(w_del_msg);
++cycle;
}
#define TSHOW(win, pause) touchwin(win); wrefresh(win); \
wrefresh(w_del_msg); napms(pause)
#define SHOW(win, pause) mvwin(win, y_pos, x_pos); wrefresh(win); \
wrefresh(w_del_msg); napms(pause)
void reindeer(void)
{
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);
}
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++)
{
TSHOW(lildeer0, 50);
for (looper = 0; looper < 4; looper++)
{
SHOW(lildeer3, 50);
SHOW(lildeer2, 50);
SHOW(lildeer1, 50);
SHOW(lildeer2, 50);
SHOW(lildeer3, 50);
TSHOW(lildeer0, 50);
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++)
{
SHOW(middeer3, 50);
SHOW(middeer2, 50);
SHOW(middeer1, 50);
SHOW(middeer2, 50);
SHOW(middeer3, 50);
TSHOW(middeer0, 50);
x_pos -= 3;
}
}
napms(2000);
y_pos = 1;
for (x_pos = 8; x_pos < 16; x_pos++)
{
SHOW(bigdeer4, 30);
SHOW(bigdeer3, 30);
SHOW(bigdeer2, 30);
SHOW(bigdeer1, 30);
SHOW(bigdeer2, 30);
SHOW(bigdeer3, 30);
SHOW(bigdeer4, 30);
SHOW(bigdeer0, 30);
}
--x_pos;
for (looper = 0; looper < 6; looper++)
{
SHOW(lookdeer4, 40);
SHOW(lookdeer3, 40);
SHOW(lookdeer2, 40);
SHOW(lookdeer1, 40);
SHOW(lookdeer2, 40);
SHOW(lookdeer3, 40);
SHOW(lookdeer4, 40);
}
SHOW(lookdeer0, 40);
for (; y_pos < 10; y_pos++)
{
for (looper = 0; looper < 2; looper++)
{
SHOW(bigdeer4, 30);
SHOW(bigdeer3, 30);
SHOW(bigdeer2, 30);
SHOW(bigdeer1, 30);
SHOW(bigdeer2, 30);
SHOW(bigdeer3, 30);
SHOW(bigdeer4, 30);
}
SHOW(bigdeer0, 30);
}
--y_pos;
mvwin(lookdeer3, y_pos, x_pos);
wrefresh(lookdeer3);
wrefresh(w_del_msg);
}