Пример #1
0
int
help()
{
	extern int nlines;
	int eof, i;
	FILE *fp;
	WINDOW *win;
	char buf[BUFSIZ];

	if ((fp = fopen(HELPFILE, "r")) == NULL)
		return(-1);
	win = newwin(0, 0, 0, 0);
	clearok(win, 1);

	eof = 0;
	if (ungetc(getc(fp), fp) == EOF) {
		wprintw(win, "There doesn't seem to be any help.");
		eof = 1;			/* Nothing there... */
	}

	while (!eof) {
		for (i = 0; i < nlines - 3; i++) {
			if (fgets(buf, sizeof(buf), fp) == (char *) NULL) {
				eof = 1;
				break;
			}
			if (buf[0] == '.' && buf[1] == '\n')
				break;
			wprintw(win, "%s", buf);
		}
		if (eof || ungetc(getc(fp), fp) == EOF) {
			eof = 1;
			break;
		}
		wmove(win, nlines - 1, 0);
		wprintw(win,
		    "Type <space> to continue, anything else to quit...");
		wrefresh(win);
		if ((inputch() & 0177) != ' ')
			break;
		wclear(win);
	}

	fclose(fp);
	if (eof) {
		wmove(win, nlines - 1, 0);
		wprintw(win, "Hit any key to continue...");
		wrefresh(win);
		inputch();
	}
	delwin(win);
	clearok(stdscr, 1);
	refresh();
	return(0);
}
Пример #2
0
/*
 * Update the display of the remaining time while waiting for a character
 * If time runs out do a longjmp() to the game controlling routine, returning
 * non-zero; oth. return the character
 * Leave the cursor where it was initially
 */
int
timerch(void)
{
	extern int tlimit;
	extern time_t start_t;
	extern jmp_buf env;
	time_t prevt, t;
	int col, remaining, row;

	getyx(stdscr, row, col);
	prevt = 0L;
	for (;;) {
		if (waitch(1000L) == 1)
			break;
		time(&t);
		if (t == prevt)
			continue;
		prevt = t;
		remaining = tlimit - (int) (t - start_t);
		if (remaining < 0) {
			longjmp(env, 1);
		}
		move(TIMER_LINE, TIMER_COL);
		printw("%d:%02d", remaining / 60, remaining % 60);
		move(row, col);
		refresh();
	}
	return (inputch());
}
Пример #3
0
int
main(int argc, char *argv[])
{
	int ch, done;
	char *bspec, *p, *seed;

	batch = debug = reuse = selfuse;
	bspec = seed = NULL;
	minlength = -1;
	tlimit = 180;		/* 3 minutes is standard */

	while ((ch = getopt(argc, argv, "Bbcds:t:w:")) != -1)
		switch(ch) {
		case 'B':
			grid = 5;
			break;
		case 'b':
			batch = 1;
			break;
		case 'c':
			challenge = 1;
			break;
		case 'd':
			debug = 1;
			break;
		case 's':
			seed = optarg;
			break;
		case 't':
			if ((tlimit = atoi(optarg)) < 1)
				errx(1, "bad time limit");
			break;
		case 'w':
			if ((minlength = atoi(optarg)) < 3)
				errx(1, "min word length must be > 2");
			break;
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	/* process final arguments */
	if (argc > 0) {
		if (strcmp(argv[0], "+") == 0)
			reuse = 1;
		else if (strcmp(argv[0], "++") == 0)
			selfuse = 1;
	}

	if (reuse || selfuse) {
		argc -= 1;
		argv += 1;
	}

	if (argc > 0) {
		if (islower(argv[0][0])) {
			if (strlen(argv[0]) != ncubes) {
				usage();
			} else {
				/* This board is assumed to be valid... */
				bspec = argv[0];
			}
		} else {
		  	usage();
		}
	}

	if (batch && bspec == NULL)
		errx(1, "must give both -b and a board setup");

	init();
	if (batch) {
		newgame(bspec);
		while ((p = batchword(stdin)) != NULL)
			(void) printf("%s\n", p);
		exit(0);
	}
	setup(seed);
	prompt("Loading the dictionary...");
	if ((dictfp = opendict(DICT)) == NULL) {
		warn("%s", DICT);
		cleanup();
		exit(1);
	}
#ifdef LOADDICT
	if (loaddict(dictfp) < 0) {
		warnx("can't load %s", DICT);
		cleanup();
		exit(1);
	}
	(void)fclose(dictfp);
	dictfp = NULL;
#endif
	if (loadindex(DICTINDEX) < 0) {
		warnx("can't load %s", DICTINDEX);
		cleanup();
		exit(1);
	}

	prompt("Type <space> to begin...");
	while (inputch() != ' ');

	for (done = 0; !done;) {
		newgame(bspec);
		bspec = NULL;	/* reset for subsequent games */
		playgame();
		prompt("Type <space> to continue, any cap to quit...");
		delay(10);	/* wait for user to quit typing */
		flushin(stdin);
		for (;;) {
			ch = inputch();
			if (ch == '\033')
				findword();
			else if (ch == '\014' || ch == '\022')	/* ^l or ^r */
				redraw();
			else {
				if (isupper(ch)) {
					done = 1;
					break;
				}
				if (ch == ' ')
					break;
			}
		}
	}
	cleanup();
	exit(0);
}
Пример #4
0
// Main input routine
// - doesn't accept words longer than MAXWORDLEN or containing caps
char *boggle_getline(char *q)
{
    int ch, done;
    char *p;
    int row, col;

    p = q;
    done = 0;
    while (!done) {
	ch = timerch();
	switch (ch) {
	    case '\n':
	    case '\r':
	    case ' ':
		done = 1;
		break;
	    case '\033':
		findword();
		break;
	    case '\177':      // <del>
	    case '\010':      // <bs>
		if (p == q)
		    break;
		p--;
		getyx(stdscr, row, col);
		move(row, col - 1);
		clrtoeol();
		refresh();
		break;
	    case '\025':      // <^u>
	    case '\027':      // <^w>
		if (p == q)
		    break;
		getyx(stdscr, row, col);
		move(row, col - (int) (p - q));
		p = q;
		clrtoeol();
		refresh();
		break;
#ifdef SIGTSTP
	    case '\032':      // <^z>
		stop_catcher(0);
		break;
#endif
	    case '\023':      // <^s>
		stoptime();
		printw("<PAUSE>");
		refresh();
		while ((ch = inputch()) != '\021' && ch != '\023');
		move(crow, ccol);
		clrtoeol();
		refresh();
		starttime();
		break;
	    case '\003':      // <^c>
		cleanup();
		exit(0);
	     /*NOTREACHED*/ case '\004':	// <^d>
		done = 1;
		ch = EOF;
		break;
	    case '\014':      // <^l>
	    case '\022':      // <^r>
		redraw();
		break;
	    case '?':
		stoptime();
		if (help() < 0)
		    showstr("Can't open help file", 1);
		starttime();
		break;
	    default:
		if (!islower(ch))
		    break;
		if ((int) (p - q) == MAXWORDLEN) {
		    p = q;
		    badword();
		    break;
		}
		*p++ = ch;
		addch(ch);
		refresh();
		break;
	}
    }
    *p = '\0';
    if (ch == EOF)
	return (char *) NULL;
    return q;
}
Пример #5
0
/*
 * Routine to print a table
 * Modified from 'ls.c' mods (BJB/83)
 * Arguments:
 *	base	- address of first entry
 *	num     - number of entries
 *	d_cols  - number of columns to use if > 0, "best" size if == 0
 *	width	- max line width if not zero
 *	prentry - address of the routine to call to print the string
 *	length  - address of the routine to call to determine the length
 *		  of string to be printed 
 *
 * prtable and length are called with the address of the base and
 * an index
 */
void
prtable(char **base, int num, int d_cols, int width, 
        void (*prentry)(char **, int), int (*length)(char **, int))
{
	int c, j;
	int a, b, cols, loc, maxlen, nrows, z;
	int col, row;

	if (num == 0)
		return;
	maxlen = get_maxlen(base, num, length) + 1;
	if (d_cols > 0)
		cols = d_cols;
	else
		cols = width / maxlen;
	if (cols == 0)
		cols = NCOLS;
	nrows = (num - 1) / cols + 1;
	for (a = 1; a <= nrows; a++) {
		b = c = z = loc = 0;
		for (j = 0; j < num; j++) {
			c++;
			if (c >= a + b)
				break;
		}
		while (j < num) {
			(*prentry)(base, j);
			loc += (*length)(base, j);
			z++;
			b += nrows;
			for (j++; j < num; j++) {
				c++;
				if (c >= a + b)
					break;
			}
			if (j < num) {
				while (loc < z * maxlen) {
					addch(' ');
					loc++;
				}
			}
		}
		getyx(stdscr, row, col);
		move(row + 1, 0);
		if (row + 1 == lastline && a != nrows) {
			attron(A_REVERSE);
			printw("--More--");
			attroff(A_REVERSE);
			do {
			    j = inputch();
			} while (j != ' ' && j != 'q' && j != 'Q');
			if (j == 'q' || j == 'Q') {
				move(row + 1, 0);
				wclrtoeol(stdscr);
				break;
			}
			move(LIST_LINE, LIST_COL);
			wclrtobot(stdscr);
		}
	}
	refresh();
}