BSD 4_3_Reno release
[unix-history] / usr / src / games / cribbage / crib.c
index bc1db63..7c73764 100644 (file)
@@ -1,58 +1,73 @@
-static char    *sccsid = "@(#)crib.c   1.17 (Berkeley) %G%";
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that: (1) source distributions retain this entire copyright
+ * notice and comment, and (2) distributions including binaries display
+ * the following acknowledgement:  ``This product includes software
+ * developed by the University of California, Berkeley and its contributors''
+ * in the documentation or other materials provided with the distribution
+ * and in all advertising materials mentioning features or use of this
+ * software. Neither the name of the University nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)crib.c     5.5 (Berkeley) 6/1/90";
+#endif /* not lint */
 
 
+# include      <sys/signal.h>
 # include      <curses.h>
 # include      <curses.h>
-# include      <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"
-
+# include      "pathnames.h"
 
 main(argc, argv)
 int    argc;
 char   *argv[];
 {
 
 main(argc, argv)
 int    argc;
 char   *argv[];
 {
+       extern char *optarg;
+       extern int optind;
        register  char          *p;
        register  char          *p;
+       int ch;
        BOOLEAN                 playing;
        char                    *s;             /* for reading arguments */
        BOOLEAN                 playing;
        char                    *s;             /* for reading arguments */
-       char                    bust;           /* flag for arg reader */
        FILE                    *f;
        FILE                    *fopen();
        FILE                    *f;
        FILE                    *fopen();
-       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':
                        explain = TRUE;
                        break;
                        explain = TRUE;
                        break;
-                   case 'q':
+               case 'q':
                        quiet = TRUE;
                        break;
                        quiet = TRUE;
                        break;
-                   case 'r':
+               case 'r':
                        rflag = TRUE;
                        break;
                        rflag = TRUE;
                        break;
-                   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;
-           }
-       }
 
        initscr();
 
        initscr();
-       signal(SIGINT, bye);
+       signal(SIGINT, rint);
        crmode();
        noecho();
        Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, 0);
        crmode();
        noecho();
        Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, 0);
@@ -68,8 +83,10 @@ char *argv[];
            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);
                fflush(stdout);
                fflush(stdout);
-               system(INSTRCMD);
+               instructions();
                crmode();
                noecho();
                clear();
                crmode();
                noecho();
                clear();
@@ -90,12 +107,18 @@ char       *argv[];
            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);
        }
        }
-
        bye();
        bye();
+       if (!f) {
+               (void)fprintf(stderr, "\ncribbage: can't open %s.\n",
+                   _PATH_LOG);
+               exit(1);
+       }
+       exit(0);
 }
 
 /*
 }
 
 /*