Category : C Source Code
Archive   : ICURSES.ZIP
Filename : DEMO.C

 
Output of file : DEMO.C contained in archive : ICURSES.ZIP
/* demo.c -- Demonstrates the ICURSES capabilities */
#include "icurses.h"
#include

void bigmsg(void);
void greetings(void);
void lister(char *fn);

WINDOW *greet;
WINDOW *expl;


void main(void)
{

initscr();
bigmsg();
greetings();
wait4key();
lister("readme.txt");
wait4key();
lister("disclaim.txt");
wait4key();
delwin(greet);

expl = newwin(7, 70, 0, 5);
wattron(expl, A_REVERSE);
ibox(expl, 2);
wattroff(expl, A_REVERSE);
demo_winmgmt();
wait4key();
demo_prim();
wait4key();
demo_out();
wait4key();
demo_in();
wait4key();
demo_flag();
wait4key();
}
void greetings(void)
{

greet = newwin(8, 70, 1, 5);
ibox(greet, 2);
waddstr(greet, "Welcome to the wonderful world of ... \n");
wstandout(greet);
mvwaddstr(greet, 2, 30,"ICURSES\n");
wstandend(greet);
waddstr(greet, "A windowing package for IBM compatibles!\n");
waddstr(greet, "Copyright, Bob Whitten, 1988\n");
}

wait4key(void)
{
attron(A_BLINK);
mvaddstr(24, 10, "Press any key to continue");
attroff(A_BLINK);
getkey();
mvaddstr(24, 10, " ");
}

void lister(char *fn)
{
FILE *inf;
int k;
int lc;
int i;
int y,x;
char instr[133];
char savestr[133];
WINDOW *lw;
static char preskstr[] = {" Press any key to continue, ALT-S to stop . . . "};
#define MAXLIN 10

lw = newwin(MAXLIN+2, 80, 10, 0);
ibox(lw, 1);
inf = fopen(fn, "r");
lc = 0;
while (!feof(inf))
{
if (fgets(instr, 133, inf) == NULL)
break;
waddstr(lw, instr);
lc++;
if (lc == MAXLIN - 1)
{
wmove(lw, MAXLIN+1, 10); /* save the border */
for (i=0; i < strlen(preskstr); i++)
{
wmove(lw, MAXLIN+1, 10+i);
savestr[i] = winch(lw);
}
savestr[i] = '\0';
wmove(lw, MAXLIN+1, 10);
waddstr(lw, preskstr); /* write message in border */
k = getkey();
if (k == K_ALTS)
break; /* get out? */
lc = 0;
wmove(lw, MAXLIN+1, 10);
waddstr(lw, savestr); /* restore border */
wmove(lw, MAXLIN, 1);
}
}
if (k != K_ALTS) /* ... a little kludgey, but ... */
{
wmove(lw, MAXLIN+1, 10);
waddstr(lw, preskstr);
getkey();
}
fclose(inf);
delwin(lw);
}

void bigmsg(void)
{
int yb = 15;
int xb = 10;

mvaddch(yb+0, xb+0, 'I');
mvaddch(yb+0, xb+1, 'I');
mvaddch(yb+0, xb+2, 'I');
mvaddch(yb+0, xb+3, 'I');
mvaddch(yb+1, xb+1, 'I');
mvaddch(yb+1, xb+2, 'I');
mvaddch(yb+2, xb+1, 'I');
mvaddch(yb+2, xb+2, 'I');
mvaddch(yb+3, xb+1, 'I');
mvaddch(yb+3, xb+2, 'I');
mvaddch(yb+4, xb+1, 'I');
mvaddch(yb+4, xb+2, 'I');
mvaddch(yb+5, xb+0, 'I');
mvaddch(yb+5, xb+1, 'I');
mvaddch(yb+5, xb+2, 'I');
mvaddch(yb+5, xb+3, 'I');

xb += 7;
mvaddch(yb+0, xb+1, 'C');
mvaddch(yb+0, xb+2, 'C');
mvaddch(yb+1, xb+0, 'C');
mvaddch(yb+1, xb+3, 'C');
mvaddch(yb+2, xb+0, 'C');
mvaddch(yb+3, xb+0, 'C');
mvaddch(yb+4, xb+0, 'C');
mvaddch(yb+4, xb+3, 'C');
mvaddch(yb+5, xb+1, 'C');
mvaddch(yb+5, xb+2, 'C');

xb += 7;
mvaddch(yb+0, xb+0, 'U');
mvaddch(yb+0, xb+3, 'U');
mvaddch(yb+1, xb+0, 'U');
mvaddch(yb+1, xb+3, 'U');
mvaddch(yb+2, xb+0, 'U');
mvaddch(yb+2, xb+3, 'U');
mvaddch(yb+3, xb+0, 'U');
mvaddch(yb+3, xb+3, 'U');
mvaddch(yb+4, xb+0, 'U');
mvaddch(yb+4, xb+3, 'U');
mvaddch(yb+5, xb+1, 'U');
mvaddch(yb+5, xb+2, 'U');

xb += 7;
mvaddch(yb+0, xb+0, 'R');
mvaddch(yb+0, xb+1, 'R');
mvaddch(yb+0, xb+2, 'R');
mvaddch(yb+1, xb+0, 'R');
mvaddch(yb+1, xb+3, 'R');
mvaddch(yb+2, xb+0, 'R');
mvaddch(yb+2, xb+1, 'R');
mvaddch(yb+2, xb+2, 'R');
mvaddch(yb+3, xb+0, 'R');
mvaddch(yb+3, xb+1, 'R');
mvaddch(yb+4, xb+0, 'R');
mvaddch(yb+4, xb+2, 'R');
mvaddch(yb+5, xb+0, 'R');
mvaddch(yb+5, xb+3, 'R');

xb += 7;
mvaddch(yb+0, xb+3, 'S');
mvaddch(yb+0, xb+2, 'S');
mvaddch(yb+0, xb+1, 'S');
mvaddch(yb+1, xb+0, 'S');
mvaddch(yb+2, xb+0, 'S');
mvaddch(yb+3, xb+1, 'S');
mvaddch(yb+3, xb+2, 'S');
mvaddch(yb+4, xb+3, 'S');
mvaddch(yb+5, xb+2, 'S');

mvaddch(yb+5, xb+1, 'S');
mvaddch(yb+5, xb+0, 'S');

xb += 7;
mvaddch(yb+0, xb+0, 'E');
mvaddch(yb+0, xb+1, 'E');
mvaddch(yb+0, xb+2, 'E');
mvaddch(yb+0, xb+3, 'E');
mvaddch(yb+1, xb+0, 'E');
mvaddch(yb+2, xb+0, 'E');
mvaddch(yb+3, xb+0, 'E');
mvaddch(yb+3, xb+1, 'E');
mvaddch(yb+3, xb+2, 'E');
mvaddch(yb+4, xb+0, 'E');
mvaddch(yb+5, xb+0, 'E');
mvaddch(yb+5, xb+1, 'E');
mvaddch(yb+5, xb+2, 'E');
mvaddch(yb+5, xb+3, 'E');

xb += 7;
mvaddch(yb+0, xb+3, 'S');
mvaddch(yb+0, xb+2, 'S');
mvaddch(yb+0, xb+1, 'S');
mvaddch(yb+1, xb+0, 'S');
mvaddch(yb+2, xb+0, 'S');
mvaddch(yb+3, xb+1, 'S');
mvaddch(yb+3, xb+2, 'S');
mvaddch(yb+4, xb+3, 'S');
mvaddch(yb+5, xb+2, 'S');
mvaddch(yb+5, xb+1, 'S');
mvaddch(yb+5, xb+0, 'S');

}

demo_winmgmt()
{
WINDOW *dw, *cw;
WINDOW *w1, *w2, *w3;

wclear(expl);
waddstr(expl, "WINDOW MANAGEMENT calls\n");
waddstr(expl, "These calls allow management of ICURSES and of windows\n");
wait4key();
dw = newwin(8, 60, 3, 0);
ibox(dw, 2);
waddstr(dw,
"initscr() - initialization of the ICURSES package\n"
" must be called before any of the ICURSES routines\n"
"endwin() - run-down of the ICURSES package\n"
" should be called to clean up after ICURSES"
);
wait4key();
wclear(dw);
waddstr(dw,
"newwin(nrow, ncol, srow, scol) - create a new window\n"
"nrow = # of rows, ncol = # cols\n"
"srow = starting row number (0 is topmost),\n"
"scol = starting column number (0 is leftmost)\n"
"returns: pointer to the window."
);
w1 = newwin(7, 23, 15, 25);
ibox(w1, 1);
waddstr(w1, "This is a new\nwindow, it has been\ngiven a border, \n"
"for clarity.");
wait4key();
w2 = newwin(7, 23, 17, 30);
ibox(w2,1);
waddstr(w2, "This is another \nwindow. Notice \nthat it is partially\n"
"'on top of' the \nother window.");
wait4key();
wclear(dw);
waddstr(dw, "delwin(w) -- delete a window)\n"
"w = pointer to window to delete\n");
delwin(w1);
waddstr(dw,"Notice that removing the window reveals the window\n"
"beneath, but doesn't disturb the window above");
wait4key();
delwin(w2);
wait4key();
wclear(dw);
waddstr(dw, "mvwin(w, y, x) -- move a window)\n"
"w - window, y = column to move to, x = row to move to");
w1 = newwin(7, 23, 15, 25);
ibox(w1, 1);
waddstr(w1, "This is window 1\n\n\n\n This is window 1");
w2 = newwin(7, 23, 18, 30);
ibox(w2, 1);
waddstr(w2, "This is window 2\n\n\n\n This is window 2");
wait4key();
mvwin(w1, 14, 35);
wait4key();
wclear(dw);
waddstr(dw, "touchwin(w) -- bring window to top of stack\n"
"The windows are logically 'stacked', and a 'touch'\n"
"will pull the window out and put it on the top,\n"
"thus making the entire window visible.");
wait4key();
touchwin(w1);
wait4key();
delwin(w2);
delwin(w1);
delwin(dw);
}

demo_prim()
{
WINDOW *dw, *w1;
int i;

wclear(expl);
waddstr(expl, "ICURSES PRIMITIVE calls\n");
waddstr(expl, "These calls the simplest functions of the package");
wait4key();
dw = newwin(8, 60, 3, 0);
ibox(dw, 2);
waddstr(dw, "waddch(w, c) -- add a character to a window\n"
" This is the basic function for writing to windows.\n"
"It will always make sure that nothing 'escapes' from\n"
"the window, and also keeps track of the 'virtual cursor'."
);
w1 = newwin(7, 23, 15, 25);
ibox(w1, 1);
wait4key();
waddch(w1, 'c');
waddch(w1, ' ');
waddch(w1, ' ');
wait4key();
for (i=0; i < 26; i++)
waddch(w1, 'A'+i);
wait4key();

wclear(dw);
waddstr(dw, "waddstr(w, s) -- add a string of chars to the window.\n");
waddstr(w1, "The quick brown fox jumped over the lazy dog's back.");
waddstr(dw, "Notice that it wraps to the next line automatically.");
wait4key();
wclear(w1);

wclear(dw);
waddstr(dw, "wmove(w, y, x) -- move the virtual cursor for a window");
waddch(w1, '*');
wait4key();
wmove(w1, 4, 20);
waddch(w1, '*');
wait4key();
wclear(w1);

wclear(dw);
waddstr(dw,"winch(w) -- read back character from the window at the\n"
"virtual cursor\n");
waddstr(dw,"winat(w) -- read back the attribute");
waddstr(w1,"This is a\ntest");
wmove(w1, 2,3);
wprintw(dw, "character at 2, 3 of window is '%c'\n", winch(w1));
wprintw(dw, "attribute is 0x'%02x'", winat(w1));
wait4key();

delwin(w1);
delwin(dw);
}

demo_out()
{
WINDOW *dw, *w1;

wclear(expl);
waddstr(expl, "OUTPUT UTILITY calls\n");
waddstr(expl, "These calls provide for various changes to\n"
" windows.");
wait4key();
dw = newwin(9, 60, 3, 0);
ibox(dw, 2);
w1 = newwin(7, 23, 15, 25);
ibox(w1, 1);
waddstr(dw,
"winsch(w, c) -- insert character 'c' into window 'w'\n"
"winsstr(w, s) -- insert string 's' into window 'w'\n"
" Both of these cause the rest of the text on that line\n"
" to shift to the right to make room (any \"falling off\"\n"
" is lost).\n");
waddstr(dw, "wmove(w1, 1, 5); waddch(w1, '*');\n");
waddstr(dw, "wmove(w1, 2, 3); winsstr(w1, \"1234567890\");");
waddstr(w1, "Line A\n Line B\n Line C\n Line D\n Line E");
wait4key();
wmove(w1, 1, 2); waddch(w1, '*');
wmove(w1, 4, 8); winsstr(w1, "1234567890");
wait4key();

wclear(dw);
waddstr(dw,
"wdelch(w) -- delete character from window 'w'\n"
"wmove(w1, 1, 4); wdelch(w1);\n");
wait4key();
wmove(w1, 1, 8); wdelch(w1);
wait4key();
wclear(w1);

wclear(dw);
waddstr(dw,
"wdeleteln(w) -- delete a line from window 'w'\n"
"winsertln(w) -- insert a blank line into window 'w'\n"
);
waddstr(w1, "Line A\n Line B\n Line C\n Line D\n Line E");
waddstr(dw, "wmove(w1, 2, 1); wdeleteln(w1);\n");
wait4key();
wmove(w1, 2, 1); wdeleteln(w1);
wait4key();
waddstr(dw, "wmove(w1, 3, 8); winsertln(w1);\n");
wmove(w1, 3, 8); winsertln(w1);
wait4key();

wclear(dw);
waddstr(dw,
"wclear -- clear the window and move to top-left corner\n"
"werase -- clear window but do not move the cursor\n\n");
waddstr(dw, "werase(w1); waddch(w1, '*');\n");
wait4key();
werase(w1); waddch(w1, '*');
wait4key();

wclear(dw);
waddstr(dw,
"wclrtoeol(w) -- clear window from cursor to end-of-line\n"
"wclrtobot(w) -- clear window from cursor to bottom \n"
"of window\n");
waddstr(w1, "Line A\n Line B\n Line C\n Line D\n Line E");
waddstr(dw, "wmove(w1, 1, 3); wclrtoeol(w1);\n");
waddstr(dw, "wmove(w1, 3, 7); wclrtobot(w1);\n");
wait4key();
wmove(w1, 1, 3); wclrtoeol(w1);
wait4key();
wmove(w1, 3, 7); wclrtobot(w1);
wait4key();

wclear(dw);
waddstr(dw,
"scroll(w) -- move lines of the window up 1, losing the\n"
"top line.\n");
wait4key();
scroll(w1);
wait4key();

delwin(w1);
wclear(dw);
waddstr(dw,
"box(w, vchar, hchar) -- draw a box around window 'w', using\n"
" 'vchar' vertical character and 'hchar' horizontal.\n"
" box(w1, '|', '-');\n");
w1 = newwin(7, 23, 15, 25);
wait4key();
box(w1, '|', '-');
waddstr(dw,
"Standard curses draws ugly boxes and then forgets about them.\n"
"ICURSES allows this with the 'box' call, but check out the\n"
"'ibox' call");
wait4key();
delwin(w1);

wclear(dw);
waddstr(dw,
"ibox(w, type) -- draw in window 'w' of type 'type'\n"
" types: 1 - single line, 2 - double line,\n"
" 3 - single top/bottom, double sides,\n"
" 4 - double top/bottom, single sides, 5 - half solid box,\n"
" 6 - solid box");
w1 = newwin(7, 65, 15, 10);
ibox(w1, 4);
waddstr(w1, "ibox(w1, 4);\n"
" note: with ibox, the cursor is changed from 0,0 to 1,1\n"
" and scrolls within the box, etc. You may explicitly\n"
"wmove() to the border (useful for \"labeling\" the box)");
wait4key();

wclear(dw);
waddstr(dw,
" unbox(w) -- remove the \"boxed\" characteristic of window\n\n"
" unbox(w1);\n"
" scroll(w1);"
);
wait4key();
unbox(w1);
scroll(w1);
scroll(w1);
scroll(w1);
scroll(w1);
wait4key();
ibox(w1, 1);
wclear(w1);

wclear(dw);
waddstr(dw, "wprintw(w, fmt, ...) -- formatted output to window\n"
"implements a kind of printf() functionality for icurses.\n\n"
" wprintw(w1, \" number eighteen = %d, %2x.\\n char=%c\",\n"
" 18, 18, 'x'");
wait4key();
wprintw(w1, " number eighteen = %d, %2x.\n char=%c",
18, 18, 'x');
wait4key();

delwin(w1);
delwin(dw);
}

demo_in()
{
WINDOW *dw, *w1;
int c, inum;
float fnum;
char s[100];


wclear(expl);
waddstr(expl, "INPUT UTILITY calls\n");
waddstr(expl, " These calls provide various keyboard input\n"
" functions.");
wait4key();
dw = newwin(8, 60, 3, 0);
ibox(dw, 2);
w1 = newwin(7, 65, 15, 10);
ibox(w1, 1);
waddstr(dw,
"wgetch() -- get a character 'through' a window.\n"
" gets a KEY (usually an ASCII char) and echos\n"
" it through the window specified, (using waddch()\n"
" c = wgetch(w1); wprintw(w1, \"\\nchar = %c\\n\", c);\n"
);
wait4key();
waddstr(w1,"Type an ASCII char: ");
c = wgetch(w1); wprintw(w1, "\nchar = %c\n", c);
wait4key();
wclear(w1);

wclear(dw);
waddstr(dw,
"wgetstr(w, s) -- get an edited line through a window.\n"
" gets a string of characters by repetitively calling\n"
" waddstr() and interpretting rub-outs, etc.");
wait4key();
waddstr(w1, "Enter a short string: ");
wgetstr(w1, s);
waddstr(w1, "\ns: ");
waddstr(w1, s);
wait4key();
wclear(w1);

wclear(dw);
waddstr(dw,
"wscanw(w, fmt, ...) -- get formatted input through window\n"
" performs the scanf() function for icurses\n"
" waddstr(w1, \"Enter a int and a float: \");\n"
" wscanw(w1, \"%d %f\", &inum, &fnum);\n"
" wprintw(w1, \"\\n inum = %d, fnum = %f\");"
);
wait4key();
waddstr(w1, "Enter a int and a float: ");
wscanw(w1, "%d %f", &inum, &fnum);
wprintw(w1, "\n inum = %d, fnum = %f", inum, fnum);
wait4key();

delwin(w1);
delwin(dw);
}

demo_flag()
{
WINDOW *dw, *w1;

wclear(expl);
waddstr(expl, "WINDOW FLAG MANAGEMENT calls\n");
wait4key();
dw = newwin(8, 60, 3, 0);
ibox(dw, 2);
w1 = newwin(7, 65, 15, 10);
ibox(w1, 1);
waddstr(dw,
"wattrset(w1, atrf) -- set attribute flags\n"
"wattron(w1, atrf) -- turn on attribute flags\n"
"wattroff(w1, atrf) -- turn off attribute flags\n"
);
wait4key();
wattrset(w1, A_REVERSE); waddstr(w1, "atrf = A_REVERSE");
wattrset(w1, 0), waddstr(w1, ", ");
wattrset(w1, A_UNDERLINE); waddstr(w1, "atrf = A_UNDERLINE");
wattrset(w1, 0), waddstr(w1, ",\n");
wattrset(w1, A_BOLD); waddstr(w1, "atrf = A_BOLD");
wattrset(w1, 0), waddstr(w1, ", ");
wattrset(w1, A_BLINK); waddstr(w1, "atrf = A_BLINK");
wattrset(w1, 0), waddstr(w1, ", ");
wattrset(w1, A_BOLD | A_BLINK); waddstr(w1, "atrf = A_BOLD | A_BLINK");
wattrset(w1, 0), waddstr(w1, ",\n");
wattrset(w1, A_REVERSE | A_BLINK); waddstr(w1, "atrf = A_REVERSE | A_BLINK");
wait4key();

delwin(w1);
delwin(dw);
}


  3 Responses to “Category : C Source Code
Archive   : ICURSES.ZIP
Filename : DEMO.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/