-/* $NetBSD: crib.c,v 1.7 1997/07/10 06:47:29 mikel Exp $ */
+/* $NetBSD: crib.c,v 1.16 2001/12/06 11:59:45 blymn Exp $ */
/*-
* Copyright (c) 1980, 1993
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1980, 1993\n\
- The Regents of the University of California. All rights reserved.\n";
+__COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
+ The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)crib.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$NetBSD: crib.c,v 1.7 1997/07/10 06:47:29 mikel Exp $";
+__RCSID("$NetBSD: crib.c,v 1.16 2001/12/06 11:59:45 blymn Exp $");
#endif
#endif /* not lint */
#include <curses.h>
+#include <err.h>
+#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include "cribcur.h"
#include "pathnames.h"
+int main __P((int, char *[]));
+
int
main(argc, argv)
int argc;
BOOLEAN playing;
FILE *f;
int ch;
+ int fd;
+ int flags;
+
+ f = fopen(_PATH_LOG, "a");
+ if (f == NULL)
+ warn("fopen %s", _PATH_LOG);
+ if (f != NULL && fileno(f) < 3)
+ exit(1);
+
+ /* Revoke setgid privileges */
+ setgid(getgid());
+
+ /* Set close-on-exec flag on log file */
+ if (f != NULL) {
+ fd = fileno(f);
+ flags = fcntl(fd, F_GETFD);
+ if (flags < 0)
+ err(1, "fcntl F_GETFD");
+ flags |= FD_CLOEXEC;
+ if (fcntl(fd, F_SETFD, flags) == -1)
+ err(1, "fcntl F_SETFD");
+ }
- while ((ch = getopt(argc, argv, "eqr")) != EOF)
+ while ((ch = getopt(argc, argv, "eqr")) != -1)
switch (ch) {
case 'e':
explain = TRUE;
initscr();
(void)signal(SIGINT, rint);
- crmode();
+ cbreak();
noecho();
Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, 0);
mvcur(0, COLS - 1, LINES - 1, 0);
fflush(stdout);
instructions();
- crmode();
+ cbreak();
noecho();
clear();
refresh();
playing = (getuchar() == 'Y');
} while (playing);
- if ((f = fopen(_PATH_LOG, "a")) != NULL) {
+ if (f != NULL) {
(void)fprintf(f, "%s: won %5.5d, lost %5.5d\n",
getlogin(), cgames, pgames);
(void) fclose(f);
}
bye();
- if (!f) {
- (void) fprintf(stderr, "\ncribbage: can't open %s.\n",
- _PATH_LOG);
- exit(1);
- }
exit(0);
}
void
gamescore()
{
- extern int Lastscore[];
-
if (pgames || cgames) {
mvprintw(SCORE_Y + 1, SCORE_X + 28, "Games: %3d", pgames);
mvprintw(SCORE_Y + 7, SCORE_X + 28, "Games: %3d", cgames);
void
game()
{
- register int i, j;
+ int i, j;
BOOLEAN flag;
BOOLEAN compcrib;
+ compcrib = FALSE;
makedeck(deck);
shuffle(deck);
if (gamecount == 0) {
playhand(mycrib)
BOOLEAN mycrib;
{
- register int deckpos;
+ int deckpos;
werase(Compwin);
wrefresh(Compwin);
deal(mycrib)
BOOLEAN mycrib;
{
- register int i, j;
+ int i, j;
for (i = j = 0; i < FULLHAND; i++) {
if (mycrib) {
discard(mycrib)
BOOLEAN mycrib;
{
- register char *prompt;
+ const char *prompt;
CARD crd;
prcrib(mycrib, TRUE);
BOOLEAN mycrib;
int pos;
{
- register int i;
+ int i;
BOOLEAN win;
win = FALSE;
prcrib(mycrib, blank)
BOOLEAN mycrib, blank;
{
- register int y, cardx;
+ int y, cardx;
if (mycrib)
cardx = CRIB_X;
BOOLEAN mycrib;
{
static CARD ch[CINHAND], ph[CINHAND];
- register int i, j, k;
- register int l;
- register int cnum, pnum, sum;
- register BOOLEAN myturn, mego, ugo, last, played;
+ int i, j, k;
+ int l;
+ int cnum, pnum, sum;
+ BOOLEAN myturn, mego, ugo, last, played;
CARD crd;
+ played = FALSE;
cnum = pnum = CINHAND;
for (i = 0; i < CINHAND; i++) { /* make copies of hands */
ch[i] = chand[i];
prhand(ph, pnum, Playwin, FALSE);
prhand(ch, cnum, Compwin, TRUE);
prtable(sum);
- if (last)
+ if (last) {
if (played) {
msg(quiet ? "I get one for last" :
"I get one point for last");
if (chkscr(&pscore, 1))
return TRUE;
}
+ }
return (FALSE);
}