SCCS-vsn: games/cribbage/io.c 5.5
SCCS-vsn: games/cribbage/crib.c 5.4
#endif /* not lint */
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)crib.c 5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)crib.c 5.4 (Berkeley) %G%";
+# include <sys/signal.h>
# include "deck.h"
# include "cribbage.h"
# include "cribcur.h"
# include "deck.h"
# include "cribbage.h"
# include "cribcur.h"
-
-
-# define LOGFILE "/usr/games/lib/criblog"
-# define INSTRCMD "ul /usr/games/lib/crib.instr | more -f"
-
main(argc, argv)
int argc;
char *argv[];
{
main(argc, argv)
int argc;
char *argv[];
{
+ extern char *optarg;
+ extern int optind;
BOOLEAN playing;
char *s; /* for reading arguments */
BOOLEAN playing;
char *s; /* for reading arguments */
- char bust; /* flag for arg reader */
- char *getline();
- int bye();
+ char *getline(), *getlogin();
+ void rint();
- while (--argc > 0) {
- if ((*++argv)[0] != '-') {
- fprintf(stderr, "\n\ncribbage: usage is 'cribbage [-eqr]'\n");
- exit(1);
- }
- bust = FALSE;
- for (s = argv[0] + 1; *s != NULL; s++) {
- switch (*s) {
- case 'e':
+ while ((ch = getopt(argc, argv, "eqr")) != EOF)
+ switch(ch) {
+ case 'e':
- default:
- fprintf(stderr, "\n\ncribbage: usage is 'cribbage [-eqr]'\n");
- exit(2);
- break;
+ case '?':
+ default:
+ (void) fprintf(stderr, "usage: cribbage [-eqr]\n");
+ exit(1);
- if (bust)
- break;
- }
- }
crmode();
noecho();
Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, 0);
crmode();
noecho();
Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, 0);
msg("Do you need instructions for cribbage? ");
if (getuchar() == 'Y') {
endwin();
msg("Do you need instructions for cribbage? ");
if (getuchar() == 'Y') {
endwin();
+ clear();
+ mvcur(0, COLS - 1, LINES - 1, 0);
crmode();
noecho();
clear();
crmode();
noecho();
clear();
playing = (getuchar() == 'Y');
} while (playing);
playing = (getuchar() == 'Y');
} while (playing);
- if ((f = fopen(LOGFILE, "a")) != NULL) {
- fprintf(f, "Won %5.5d, Lost %5.5d\n", cgames, pgames);
- fclose(f);
+ if (f = fopen(_PATH_LOG, "a")) {
+ (void)fprintf(f, "%s: won %5.5d, lost %5.5d\n",
+ getlogin(), cgames, pgames);
+ (void)fclose(f);
+ if (!f) {
+ (void)fprintf(stderr, "\ncribbage: can't open %s.\n",
+ _PATH_LOG);
+ exit(1);
+ }
+ exit(0);
-static char sccsid[] = "@(#)io.c 5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)io.c 5.5 (Berkeley) %G%";
#endif /* not lint */
# include <curses.h>
#endif /* not lint */
# include <curses.h>
over:
cnt = 0;
while (read(0, &c, 1) <= 0)
over:
cnt = 0;
while (read(0, &c, 1) <= 0)
- if (cnt++ > 100) /* if we are getting infinite EOFs */
- bye(); /* quit the game */
+ if (cnt++ > 100) { /* if we are getting infinite EOFs */
+ bye(); /* quit the game */
+ exit(1);
+ }
if (c == CTRL(L)) {
wrefresh(curscr);
goto over;
if (c == CTRL(L)) {
wrefresh(curscr);
goto over;
+rint()
+{
+ bye();
+ exit(1);
+}
+
/*
* bye:
* Leave the program, cleaning things up as we go.
/*
* bye:
* Leave the program, cleaning things up as we go.
fflush(stdout);
endwin();
putchar('\n');
fflush(stdout);
endwin();
putchar('\n');