static void intro(void) { char *tmpname; srand((unsigned) (time(0L) + getpid())); /* Kick the random number generator */ CATCHALL(uninitgame); if ((tmpname = getlogin()) != 0) { (void) strcpy(name, tmpname); name[0] = (char) toupper(UChar(name[0])); } else (void) strcpy(name, dftname); (void) initscr(); keypad(stdscr, TRUE); (void) def_prog_mode(); (void) nonl(); (void) cbreak(); (void) noecho(); #ifdef PENGUIN (void) clear(); (void) mvaddstr(4, 29, "Welcome to Battleship!"); (void) move(8, 0); PR(" \\\n"); PR(" \\ \\ \\\n"); PR(" \\ \\ \\ \\ \\_____________\n"); PR(" \\ \\ \\_____________ \\ \\/ |\n"); PR(" \\ \\/ \\ \\/ |\n"); PR(" \\/ \\_____/ |__\n"); PR(" ________________/ |\n"); PR(" \\ S.S. Penguin |\n"); PR(" \\ /\n"); PR(" \\___________________________________________________/\n"); (void) mvaddstr(22, 27, "Hit any key to continue..."); (void) refresh(); (void) getch(); #endif /* PENGUIN */ #ifdef A_COLOR start_color(); init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK); init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK); init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK); init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); #endif /* A_COLOR */ #ifdef NCURSES_MOUSE_VERSION (void) mousemask(BUTTON1_CLICKED, (mmask_t *) NULL); #endif /* NCURSES_MOUSE_VERSION */ }
int main(int argc, char *argv[]) { CATCHALL(die); setlocale(LC_ALL, ""); initscr(); /* * We use COLOR_GREEN because COLOR_BLACK is wired to the wrong thing. */ start_color(); init_pair(RED_ON_WHITE, COLOR_RED, COLOR_WHITE); init_pair(BLUE_ON_WHITE, COLOR_BLUE, COLOR_WHITE); init_pair(BLACK_ON_WHITE, COLOR_BLACK, COLOR_WHITE); #ifndef COLOR_PAIR letters[0] = OR_COLORS('h', RED_ON_WHITE); /* hearts */ letters[1] = OR_COLORS('s', BLACK_ON_WHITE); /* spades */ letters[2] = OR_COLORS('d', RED_ON_WHITE); /* diamonds */ letters[3] = OR_COLORS('c', BLACK_ON_WHITE); /* clubs */ #if USE_CP437 glyphs[0] = PC_COLORS('\003', RED_ON_WHITE); /* hearts */ glyphs[1] = PC_COLORS('\006', BLACK_ON_WHITE); /* spades */ glyphs[2] = PC_COLORS('\004', RED_ON_WHITE); /* diamonds */ glyphs[3] = PC_COLORS('\005', BLACK_ON_WHITE); /* clubs */ #endif #endif #if USE_CP437 if (tigetstr("smpch")) suits = glyphs; #endif /* USE_CP437 */ cbreak(); if (argc == 2) srand((unsigned) atoi(argv[1])); else srand((unsigned) time((time_t *) 0)); init_vars(); do { deal_number++; shuffle(deck_size); deal_cards(); display_cards(deal_number); play_game(); } while ((deck_size = collect_discards()) != 0); game_finished(deal_number); die(SIGINT); /*NOTREACHED */ }
static void railroad(char **args) { NCURSES_CONST char *name = getenv("TERM"); char buffer[1024]; char area[1024], *ap = area; if (name == 0) name = "dumb"; if (tgetent(buffer, name) >= 0) { wipeit = tgetstr("ce", &ap); height = tgetnum("li"); length = tgetnum("co"); moveit = tgetstr("cm", &ap); if (wipeit == 0 || moveit == 0 || height <= 0 || length <= 0) { wipeit = 0; moveit = 0; height = 0; length = 0; } startS = tgetstr("so", &ap); finisS = tgetstr("se", &ap); startU = tgetstr("us", &ap); finisU = tgetstr("ue", &ap); backup = tgetstr("le", &ap); startC = tgetstr("ve", &ap); finisC = tgetstr("vi", &ap); ShowCursor(0); CATCHALL(onsig); while (*args) { ShowSign(*args++); } ShowCursor(1); } }
int main(int argc, char *argv[]) { CATCHALL(die); setlocale(LC_ALL, ""); use_pc_display(); initscr(); start_color(); init_pair(RED_ON_WHITE, COLOR_RED, COLOR_WHITE); init_pair(BLUE_ON_WHITE, COLOR_BLUE, COLOR_WHITE); init_pair(BLACK_ON_WHITE, COLOR_BLACK, COLOR_WHITE); cbreak(); if (argc == 2) srand((unsigned) atoi(argv[1])); else srand((unsigned) time((time_t *) 0)); init_vars(); do { deal_number++; shuffle(deck_size); deal_cards(); display_cards(deal_number); play_game(); } while ((deck_size = collect_discards()) != 0); game_finished(deal_number); die(SIGINT); /*NOTREACHED */ }
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); }
int main(int argc, char *argv[]) { int c; int test_loops = 1; int test_normal = FALSE; int test_optimize = FALSE; setlocale(LC_ALL, ""); while ((c = getopt(argc, argv, "cf:h:l:norsx")) != -1) { switch (c) { case 'c': continuous = TRUE; break; case 'f': foot_lines = atoi(optarg); break; case 'h': head_lines = atoi(optarg); break; case 'l': test_loops = atoi(optarg); assert(test_loops >= 0); break; case 'n': test_normal = TRUE; break; case 'o': test_optimize = TRUE; break; case 'r': reverse_loops = TRUE; break; case 's': single_step = TRUE; break; case 'x': extend_corner = TRUE; break; default: usage(); } } if (!test_normal && !test_optimize) { test_normal = TRUE; test_optimize = TRUE; } #if USE_TRACE trace(TRACE_TIMES); #endif CATCHALL(finish); /* arrange interrupts to terminate */ (void) initscr(); /* initialize the curses library */ keypad(stdscr, TRUE); /* enable keyboard mapping */ (void) nonl(); /* tell curses not to do NL->CR/NL on output */ (void) cbreak(); /* take input chars one at a time, no wait for \n */ (void) noecho(); /* don't echo input */ scrollok(stdscr, TRUE); while (test_loops-- > 0) { if (test_normal) run_test(FALSE); if (test_optimize) run_test(TRUE); } cleanup(); /* we're done */ ExitProgram(EXIT_SUCCESS); }