Exemple #1
0
static void
part6(DATA * drop)
{
    MvAddCh(drop->y - 2, drop->x, ' ');
    MvAddStr(drop->y - 1, drop->x - 1, "   ");
    MvAddStr(drop->y, drop->x - 2, "     ");
    MvAddStr(drop->y + 1, drop->x - 1, "   ");
    MvAddCh(drop->y + 2, drop->x, ' ');
}
Exemple #2
0
static void
part5(DATA * drop)
{
    MvAddCh(drop->y - 2, drop->x, '-');
    MvAddStr(drop->y - 1, drop->x - 1, "/ \\");
    MvAddStr(drop->y, drop->x - 2, "| O |");
    MvAddStr(drop->y + 1, drop->x - 1, "\\ /");
    MvAddCh(drop->y + 2, drop->x, '-');
}
Exemple #3
0
static 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);
    refresh();
    if (!AutoFlag)
	napms(500);

    move(STATUSLINE, 0);
    clrtoeol();
    refresh();
    return FALSE;
}
Exemple #4
0
static void
part4(DATA * drop)
{
    MvAddCh(drop->y - 1, drop->x, '-');
    MvAddStr(drop->y, drop->x - 1, "|.|");
    MvAddCh(drop->y + 1, drop->x, '-');
}
Exemple #5
0
static void
show_insert_mode(bool insert_mode)
{
    MvAddStr(5, 57, (insert_mode
		     ? "form_status: insert "
		     : "form_status: overlay"));
}
Exemple #6
0
static void
DisplayTiles(void)
{
    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);
    (void) attrset(A_REVERSE);
    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');
    (void) attrset(A_NORMAL);

    /* Draw tiles */
    for (peg = 0; peg < NPEGS; peg++) {
	for (SlotNo = 0; SlotNo < Pegs[peg].Count; SlotNo++) {
	    size_t len = Pegs[peg].Length[SlotNo];
	    if (len < sizeof(TileBuf) - 1 && len < (size_t) PegPos[peg]) {
		memset(TileBuf, ' ', len);
		TileBuf[len] = '\0';
		if (has_colors())
		    (void) attrset((attr_t) COLOR_PAIR(LENTOIND(len)));
		else
		    (void) attrset(A_REVERSE);
		MvAddStr(BASELINE - (SlotNo + 1),
			 (PegPos[peg] - (int) len / 2),
			 TileBuf);
	    }
	}
    }
    (void) attrset(A_NORMAL);
    refresh();
}
Exemple #7
0
int
main(int argc, char **argv)
{
    int NTiles, FromCol, ToCol;

    setlocale(LC_ALL, "");

    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);
	    ExitProgram(EXIT_FAILURE);
	}
	break;
    case 3:
	if (strcmp(argv[2], "a")) {
	    Usage();
	    ExitProgram(EXIT_FAILURE);
	}
	NTiles = atoi(argv[1]);
	if (NTiles > MAXTILES || NTiles < MINTILES) {
	    fprintf(stderr, "Range %d to %d\n", MINTILES, MAXTILES);
	    ExitProgram(EXIT_FAILURE);
	}
	AutoFlag = TRUE;
	break;
    default:
	Usage();
	ExitProgram(EXIT_FAILURE);
    }
#ifdef TRACE
    trace(TRACE_MAXIMUM);
#endif
    initscr();
    if (has_colors()) {
	int i;
	short bg = COLOR_BLACK;
	start_color();
#if HAVE_USE_DEFAULT_COLORS
	if (use_default_colors() == OK)
	    bg = -1;
#endif
	for (i = 0; i < 9; i++)
	    init_pair((short) (i + 1), bg, TileColour[i]);
    }
    cbreak();
    if (LINES < 24) {
	endwin();
	fprintf(stderr, "Min screen length 24 lines\n");
	ExitProgram(EXIT_FAILURE);
    }
    if (AutoFlag) {
	curs_set(0);
	leaveok(stdscr, TRUE);	/* Attempt to remove cursor */
    }
    InitTiles(NTiles);
    DisplayTiles();
    if (AutoFlag) {
	do {
	    noecho();
	    AutoMove(0, 2, NTiles);
	} while (!Solved(NTiles));
	sleep(2);
    } else {
	echo();
	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();
    ExitProgram(EXIT_SUCCESS);
}
Exemple #8
0
static void
test_adds(int level)
{
    static bool first = TRUE;

    int ch;
    int limit;
    int row = 1;
    int col;
    int row2, col2;
    int length;
    char buffer[BUFSIZ];
    WINDOW *look = 0;
    WINDOW *work = 0;
    WINDOW *show = 0;
    int margin = (2 * MY_TABSIZE) - 1;
    Options option = (Options) ((unsigned) (m_opt
                                            ? oMove
                                            : oDefault)
                                | (unsigned) ((w_opt || (level > 0))
                                        ? oWindow
                                        : oDefault));

    if (first) {
        static char cmd[80];
        setlocale(LC_ALL, "");

        putenv(strcpy(cmd, "TABSIZE=8"));

        initscr();
        (void) cbreak();	/* take input chars one at a time, no wait for \n */
        (void) noecho();	/* don't echo input */
        keypad(stdscr, TRUE);
    }

    limit = LINES - 5;
    if (level > 0) {
        look = newwin(limit, COLS - (2 * (level - 1)), 0, level - 1);
        work = newwin(limit - 2, COLS - (2 * level), 1, level);
        show = newwin(4, COLS, limit + 1, 0);
        box(look, 0, 0);
        wnoutrefresh(look);
        limit -= 2;
    } else {
        work = stdscr;
        show = derwin(stdscr, 4, COLS, limit + 1, 0);
    }
    keypad(work, TRUE);

    for (col = margin + 1; col < COLS; col += MY_TABSIZE)
        MvWVLine(work, row, col, '.', limit - 2);

    MvWVLine(work, row, margin, ACS_VLINE, limit - 2);
    MvWVLine(work, row, margin + 1, ACS_VLINE, limit - 2);
    limit /= 2;

    MvWAddChStr(work, 1, 2, ChStr("String"));
    MvWAddChStr(work, limit + 1, 2, ChStr("Chars"));
    wnoutrefresh(work);

    buffer[length = 0] = '\0';
    legend(show, level, option, buffer, length);
    wnoutrefresh(show);

    doupdate();

    /*
     * Show the characters added in color, to distinguish from those that
     * are shifted.
     */
    if (has_colors()) {
        start_color();
        init_pair(1, COLOR_WHITE, COLOR_BLUE);
        show_attr = (attr_t) COLOR_PAIR(1);
        wbkgdset(work, show_attr | ' ');
    } else {
        show_attr = A_STANDOUT;
    }

    while ((ch = read_linedata(work)) != ERR && !isQUIT(ch)) {
        wmove(work, row, margin + 1);
        switch (ch) {
        case key_RECUR:
            test_adds(level + 1);

            touchwin(look);
            touchwin(work);
            touchwin(show);

            wnoutrefresh(look);
            wnoutrefresh(work);
            wnoutrefresh(show);

            doupdate();
            break;
        case key_NEWLINE:
            if (row < limit) {
                ++row;
                /* put the whole string in, all at once */
                col2 = margin + 1;
                switch (option) {
                case oDefault:
                    if (n_opt > 1) {
                        for (col = 0; col < length; col += n_opt) {
                            col2 = ColOf(buffer, col, margin);
                            if (move(row, col2) != ERR) {
                                AddNStr(ChStr2(buffer + col), LEN(col));
                            }
                        }
                    } else {
                        if (move(row, col2) != ERR) {
                            AddStr(ChStr2(buffer));
                        }
                    }
                    break;
                case oMove:
                    if (n_opt > 1) {
                        for (col = 0; col < length; col += n_opt) {
                            col2 = ColOf(buffer, col, margin);
                            MvAddNStr(row, col2, ChStr2(buffer + col), LEN(col));
                        }
                    } else {
                        MvAddStr(row, col2, ChStr2(buffer));
                    }
                    break;
                case oWindow:
                    if (n_opt > 1) {
                        for (col = 0; col < length; col += n_opt) {
                            col2 = ColOf(buffer, col, margin);
                            if (wmove(work, row, col2) != ERR) {
                                WAddNStr(work, ChStr2(buffer + col), LEN(col));
                            }
                        }
                    } else {
                        if (wmove(work, row, col2) != ERR) {
                            WAddStr(work, ChStr2(buffer));
                        }
                    }
                    break;
                case oMoveWindow:
                    if (n_opt > 1) {
                        for (col = 0; col < length; col += n_opt) {
                            col2 = ColOf(buffer, col, margin);
                            MvWAddNStr(work, row, col2, ChStr2(buffer + col),
                                       LEN(col));
                        }
                    } else {
                        MvWAddStr(work, row, col2, ChStr2(buffer));
                    }
                    break;
                }

                /* do the corresponding single-character add */
                row2 = limit + row;
                for (col = 0; col < length; ++col) {
                    col2 = ColOf(buffer, col, margin);
                    switch (option) {
                    case oDefault:
                        if (move(row2, col2) != ERR) {
                            AddCh(UChar(buffer[col]));
                        }
                        break;
                    case oMove:
                        MvAddCh(row2, col2, UChar(buffer[col]));
                        break;
                    case oWindow:
                        if (wmove(work, row2, col2) != ERR) {
                            WAddCh(work, UChar(buffer[col]));
                        }
                        break;
                    case oMoveWindow:
                        MvWAddCh(work, row2, col2, UChar(buffer[col]));
                        break;
                    }
                }
            } else {
                beep();
            }
            break;
        case KEY_BACKSPACE:
            ch = '\b';
        /* FALLTHRU */
        default:
            if (ch <= 0 || ch > 255) {
                beep();
                break;
            }
            buffer[length++] = (char) ch;
            buffer[length] = '\0';

            /* put the string in, one character at a time */
            col = ColOf(buffer, length - 1, margin);
            switch (option) {
            case oDefault:
                if (move(row, col) != ERR) {
                    AddStr(ChStr2(buffer + length - 1));
                }
                break;
            case oMove:
                MvAddStr(row, col, ChStr2(buffer + length - 1));
                break;
            case oWindow:
                if (wmove(work, row, col) != ERR) {
                    WAddStr(work, ChStr2(buffer + length - 1));
                }
                break;
            case oMoveWindow:
                MvWAddStr(work, row, col, ChStr2(buffer + length - 1));
                break;
            }

            /* do the corresponding single-character add */
            switch (option) {
            case oDefault:
                if (move(limit + row, col) != ERR) {
                    AddCh(UChar(ch));
                }
                break;
            case oMove:
                MvAddCh(limit + row, col, UChar(ch));
                break;
            case oWindow:
                if (wmove(work, limit + row, col) != ERR) {
                    WAddCh(work, UChar(ch));
                }
                break;
            case oMoveWindow:
                MvWAddCh(work, limit + row, col, UChar(ch));
                break;
            }

            wnoutrefresh(work);

            legend(show, level, option, buffer, length);
            wnoutrefresh(show);

            doupdate();
            break;
        }
    }
    if (level > 0) {
        delwin(show);
        delwin(work);
        delwin(look);
    }
}
Exemple #9
0
static void
demo_forms(void)
{
    WINDOW *w;
    FORM *form;
    FIELD *f[100];		/* FIXME memset to zero */
    int finished = 0, c;
    unsigned n = 0;
    int pg;
    WINDOW *also;

#ifdef NCURSES_MOUSE_VERSION
    mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
#endif

    help_edit_field();

    MvAddStr(4, 57, "Forms Entry Test");
    show_insert_mode(TRUE);

    refresh();

    /* describe the form */
    memset(f, 0, sizeof(f));
    for (pg = 0; pg < 4; ++pg) {
	char label[80];
	sprintf(label, "Sample Form Page %d", pg + 1);
	f[n++] = make_label(0, 15, label);
	set_new_page(f[n - 1], TRUE);

	switch (pg) {
	default:
	    f[n++] = make_label(2, 0, "Last Name");
	    f[n++] = make_field(3, 0, 1, 18);
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);

	    f[n++] = make_label(2, 20, "First Name");
	    f[n++] = make_field(3, 20, 1, 12);
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);

	    f[n++] = make_label(2, 34, "Middle Name");
	    f[n++] = make_field(3, 34, 1, 12);
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);
	    break;
	case 1:
	    f[n++] = make_label(2, 0, "Last Name");
	    f[n++] = make_field(3, 0, 1, 18);
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);

	    f[n++] = make_label(2, 20, "First Name");
	    f[n++] = make_field(3, 20, 1, 12);
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);

	    f[n++] = make_label(2, 34, "MI");
	    f[n++] = make_field(3, 34, 1, 1);
	    set_field_pad(f[n - 1], '?');
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);
	    break;
	case 2:
	    f[n++] = make_label(2, 0, "Host Name");
	    f[n++] = make_field(3, 0, 1, 18);
	    set_field_type(f[n - 1], TYPE_ALNUM, 1);

#ifdef NCURSES_VERSION
	    f[n++] = make_label(2, 20, "IP Address");
	    f[n++] = make_field(3, 20, 1, 12);
	    set_field_type(f[n - 1], TYPE_IPV4, 1);
#endif

	    break;

	case 3:
	    f[n++] = make_label(2, 0, "Four digits");
	    f[n++] = make_field(3, 0, 1, 18);
	    set_field_type(f[n - 1], TYPE_INTEGER, 4, 0, 0);

	    f[n++] = make_label(2, 20, "Numeric");
	    f[n++] = make_field(3, 20, 1, 12);
	    set_field_type(f[n - 1], TYPE_NUMERIC, 3, -10000.0, 100000000.0);

	    break;
	}

	f[n++] = make_label(5, 0, "Comments");
	f[n++] = make_field(6, 0, 4, 46);
	set_field_buffer(f[n - 1], 0, "HELLO\nWORLD!");
	set_field_buffer(f[n - 1], 1, "Hello\nWorld!");
    }

    f[n] = (FIELD *) 0;

    if ((form = new_form(f)) != 0) {

	display_form(form);

	w = form_win(form);
	also = newwin(getmaxy(stdscr) - getmaxy(w), COLS, getmaxy(w), 0);
	show_current_field(also, form);

	while (!finished) {
	    switch (edit_field(form, &c)) {
	    case E_OK:
		break;
	    case E_UNKNOWN_COMMAND:
		finished = my_form_driver(form, c);
		break;
	    default:
		beep();
		break;
	    }
	    show_current_field(also, form);
	}

	erase_form(form);

	free_form(form);
    }
    for (c = 0; f[c] != 0; c++) {
	void *ptr = field_userptr(f[c]);
	free(ptr);
	free_field(f[c]);
    }
    noraw();
    nl();

#ifdef NCURSES_MOUSE_VERSION
    mousemask(0, (mmask_t *) 0);
#endif
}
static void
outputTest(WINDOW *win)
{
    WINDOW *win1;
    char Buffer[80];
    chtype ch;
    int by, bx;

#if !HAVE_TIGETSTR
#if HAVE_TGETENT
    char tc_buffer[4096];
    char tc_parsed[4096];
    char *area_pointer = tc_parsed;
    tgetent(tc_buffer, getenv("TERM"));
#else
#define tgetstr(a,b) 0
#endif
#endif /* !HAVE_TIGETSTR */

    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);
    waddstr(win, "\nThis text should be down\n");
    waddstr(win, "and broken into two here ^");
    Continue(win);

    wclear(win);
    wattron(win, A_BOLD);
    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);

    getbegyx(win, by, bx);

    if (LINES < 24 || COLS < 75) {
	MvWAddStr(win, 5, 1,
		  "Some tests have been skipped as they require a");
	MvWAddStr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
	Continue(win);
    } else {
	win1 = newwin(10, 50, 14, 25);
	if (win1 == NULL) {
	    endwin();
	    return;
	}
#ifdef A_COLOR
	if (has_colors()) {
	    init_pair(3, COLOR_BLUE, COLOR_WHITE);
	    wbkgd(win1, (chtype) COLOR_PAIR(3));
	} else
	    wbkgd(win1, A_NORMAL);
#else
	wbkgd(win1, A_NORMAL);
#endif
	wclear(win1);
	MvWAddStr(win1, 5, 1,
		  "This text should appear; using overlay option");
	copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);

#if defined(PDCURSES) && !defined(XCURSES)
	box(win1, 0xb3, 0xc4);
#else
	box(win1, ACS_VLINE, ACS_HLINE);
#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);
	mvwin(win1, by, bx);
	overlay(win, win1);
	mvwin(win1, 14, 25);
	wmove(win1, 8, 26);
	wrefresh(win1);
	wgetch(win1);
	delwin(win1);
    }

    clear();
    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);

    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);

#if HAVE_WINSSTR
    (void) mvwinsstr(win, 6, 2, "A1B2C3D4E5");
    Continue(win);
#endif

    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();
    *Buffer = 0;
    wscanw(win, "%s", Buffer);

    printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
    MvAddStr(10, 1, "Enter a string: ");
    *Buffer = 0;
    scanw("%s", Buffer);

    if (TIGETSTR("cvvis", "vs") != 0) {
	wclear(win);
	curs_set(2);
	MvWAddStr(win, 1, 1, "The cursor should appear as a block (visible)");
	Continue(win);
    }

    if (TIGETSTR("civis", "vi") != 0) {
	wclear(win);
	curs_set(0);
	MvWAddStr(win, 1, 1,
		  "The cursor should have disappeared (invisible)");
	Continue(win);
    }

    if (TIGETSTR("cnorm", "ve") != 0) {
	wclear(win);
	curs_set(1);
	MvWAddStr(win, 1, 1, "The cursor should be an underline (normal)");
	Continue(win);
    }
#ifdef A_COLOR
    if (has_colors()) {
	wclear(win);
	MvWAddStr(win, 1, 1, "Colors should change after you press a key");
	Continue(win);
	init_pair(1, COLOR_RED, COLOR_WHITE);
	wrefresh(win);
    }
#endif

    werase(win);

#if HAVE_TERMNAME
    MvWAddStr(win, 1, 1, "Information About Your Terminal");
    MvWAddStr(win, 3, 1, termname());
    MvWAddStr(win, 4, 1, longname());
    if (termattrs() & A_BLINK)
	MvWAddStr(win, 5, 1, "This terminal supports blinking.");
    else
	MvWAddStr(win, 5, 1, "This terminal does NOT support blinking.");
#endif

    (void) mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
    wrefresh(win);

    (void) mvwinnstr(win, 7, 5, Buffer, 18);
    MvAddStr(LINES - 2, 10, Buffer);
    refresh();
    Continue(win);
}
Exemple #11
0
int
main(int argc, char *argv[])
{
    time_t now;
    struct tm *tm;
    long t, a;
    int i, j, s, k;
    int count = 0;
    FILE *ofp = stdout;
    FILE *ifp = stdin;
    bool scrol = FALSE;

    setlocale(LC_ALL, "");

    CATCHALL(sighndl);

    while ((k = getopt(argc, argv, "sn")) != -1) {
	switch (k) {
	case 's':
	    scrol = TRUE;
	    break;
	case 'n':
	    ifp = fopen("/dev/null", "r");
	    redirected = TRUE;
	    break;
	default:
	    usage();
	}
    }
    if (optind < argc) {
	count = atoi(argv[optind++]);
	assert(count >= 0);
    }
    if (optind < argc)
	usage();

    if (redirected) {
	char *name = getenv("TERM");
	if (name == 0
	    || newterm(name, ofp, ifp) == 0) {
	    fprintf(stderr, "cannot open terminal\n");
	    ExitProgram(EXIT_FAILURE);
	}

    } else {
	initscr();
    }
    cbreak();
    noecho();
    nodelay(stdscr, 1);
    curs_set(0);

    hascolor = has_colors();

    if (hascolor) {
	short bg = COLOR_BLACK;
	start_color();
#if HAVE_USE_DEFAULT_COLORS
	if (use_default_colors() == OK)
	    bg = -1;
#endif
	init_pair(PAIR_DIGITS, COLOR_BLACK, COLOR_RED);
	init_pair(PAIR_OTHERS, COLOR_RED, bg);
	init_pair(PAIR_FRAMES, COLOR_WHITE, bg);
	(void) attrset(COLOR_PAIR(PAIR_OTHERS));
    }

  restart:
    for (j = 0; j < 5; j++)
	older[j] = newer[j] = next[j] = 0;

    clear();
    drawbox(FALSE);

    do {
	char buf[30];

	time(&now);
	tm = localtime(&now);

	mask = 0;
	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++)
		    newer[i] = (newer[i] & ~mask) | (newer[i + 1] & mask);
		newer[5] = (newer[5] & ~mask) | (next[k] & mask);
	    } else
		newer[k] = (newer[k] & ~mask) | (next[k] & mask);
	    next[k] = 0;
	    for (s = 1; s >= 0; s--) {
		standt(s);
		for (i = 0; i < 6; i++) {
		    if ((a = (newer[i] ^ older[i]) & (s ? newer : older)[i])
			!= 0) {
			for (j = 0, t = 1 << 26; t; t >>= 1, j++) {
			    if (a & t) {
				if (!(a & (t << 1))) {
				    move(YBASE + i, XBASE + 2 * j);
				}
				addstr("  ");
			    }
			}
		    }
		    if (!s) {
			older[i] = newer[i];
		    }
		}
		if (!s) {
		    if (scrol)
			drawbox(TRUE);
		    refresh();
		    /*
		     * If we're scrolling, space out the refreshes to fake
		     * movement.  That's 7 frames, or 6 intervals, which would
		     * be 166 msec if we spread it out over a second.  It looks
		     * better (but will work on a slow terminal, e.g., less
		     * than 9600bd) to squeeze that into a half-second, and use
		     * half of 170 msec to ensure that the program doesn't eat
		     * a lot of time when asking what time it is, at the top of
		     * this loop -T.Dickey
		     */
		    if (scrol)
			napms(85);
		}
	    }
	}

	/* this depends on the detailed format of ctime(3) */
	(void) strcpy(buf, ctime(&now));
	(void) strcpy(buf + 10, buf + 19);
	MvAddStr(16, 30, buf);

	move(6, 0);
	drawbox(FALSE);
	refresh();

	/*
	 * If we're not scrolling, wait 1000 msec (1 sec).  Use napms() rather
	 * than sleep() because the latter does odd things on some systems,
	 * e.g., suspending output as well.
	 */
	if (scrol)
	    napms(500);
	else
	    napms(1000);

	/*
	 * This is a safe way to check if we're interrupted - making the signal
	 * handler set a flag that we can check.  Since we're running
	 * nodelay(), the wgetch() call returns immediately, and in particular
	 * will return an error if interrupted.  This works only if we can
	 * read from the input, of course.
	 */
	switch (wgetch(stdscr)) {
	case 'q':
	    count = 1;
	    break;
	case 's':
	    nodelay(stdscr, FALSE);
	    break;
	case ' ':
	    nodelay(stdscr, TRUE);
	    break;
#ifdef KEY_RESIZE
	case KEY_RESIZE:
#endif
	case '?':
	    goto restart;
	case ERR:
	    if (sigtermed) {
		(void) standend();
		endwin();
		fprintf(stderr, "gdc terminated by signal %d\n", sigtermed);
		ExitProgram(EXIT_FAILURE);
	    }
	    /* FALLTHRU */
	default:
	    continue;
	}
    } while (--count);
    (void) standend();
    endwin();
    ExitProgram(EXIT_SUCCESS);
}
Exemple #12
0
static void
dosquares(void)
{
    int i, j;

    MvAddStr(0, 20, "KNIGHT'S MOVE -- a logical solitaire");

    move(BOARDY, BOARDX);
    waddch(boardwin, ACS_ULCORNER);
    for (j = 0; j < 7; j++) {
	waddch(boardwin, ACS_HLINE);
	waddch(boardwin, ACS_HLINE);
	waddch(boardwin, ACS_HLINE);
	waddch(boardwin, ACS_TTEE);
    }
    waddch(boardwin, ACS_HLINE);
    waddch(boardwin, ACS_HLINE);
    waddch(boardwin, ACS_HLINE);
    waddch(boardwin, ACS_URCORNER);

    for (i = 1; i < BDEPTH; i++) {
	move(BOARDY + i * 2 - 1, BOARDX);
	waddch(boardwin, ACS_VLINE);
	for (j = 0; j < BWIDTH; j++) {
	    waddch(boardwin, ' ');
	    waddch(boardwin, ' ');
	    waddch(boardwin, ' ');
	    waddch(boardwin, ACS_VLINE);
	}
	move(BOARDY + i * 2, BOARDX);
	waddch(boardwin, ACS_LTEE);
	for (j = 0; j < BWIDTH - 1; j++) {
	    waddch(boardwin, ACS_HLINE);
	    waddch(boardwin, ACS_HLINE);
	    waddch(boardwin, ACS_HLINE);
	    waddch(boardwin, ACS_PLUS);
	}
	waddch(boardwin, ACS_HLINE);
	waddch(boardwin, ACS_HLINE);
	waddch(boardwin, ACS_HLINE);
	waddch(boardwin, ACS_RTEE);
    }

    move(BOARDY + i * 2 - 1, BOARDX);
    waddch(boardwin, ACS_VLINE);
    for (j = 0; j < BWIDTH; j++) {
	waddch(boardwin, ' ');
	waddch(boardwin, ' ');
	waddch(boardwin, ' ');
	waddch(boardwin, ACS_VLINE);
    }

    move(BOARDY + i * 2, BOARDX);
    waddch(boardwin, ACS_LLCORNER);
    for (j = 0; j < BWIDTH - 1; j++) {
	waddch(boardwin, ACS_HLINE);
	waddch(boardwin, ACS_HLINE);
	waddch(boardwin, ACS_HLINE);
	waddch(boardwin, ACS_BTEE);
    }
    waddch(boardwin, ACS_HLINE);
    waddch(boardwin, ACS_HLINE);
    waddch(boardwin, ACS_HLINE);
    waddch(boardwin, ACS_LRCORNER);
}