diff options
author | dholland <dholland@NetBSD.org> | 2009-03-02 07:33:30 +0000 |
---|---|---|
committer | dholland <dholland@NetBSD.org> | 2009-03-02 07:33:30 +0000 |
commit | d129e7ccafb5305123dad3894b84730f9663254f (patch) | |
tree | 6f3b4f9b17db2cdeed2b43655d5ee1bf613c34f3 /sail | |
parent | cb23d290fb00d766334d734193c06058584163b4 (diff) | |
download | bsdgames-darwin-d129e7ccafb5305123dad3894b84730f9663254f.tar.gz bsdgames-darwin-d129e7ccafb5305123dad3894b84730f9663254f.tar.zst bsdgames-darwin-d129e7ccafb5305123dad3894b84730f9663254f.zip |
More fixes from OpenBSD: use err instead of perror, don't hork on EOF
during the initial setup questions.
Diffstat (limited to 'sail')
-rw-r--r-- | sail/pl_main.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/sail/pl_main.c b/sail/pl_main.c index bb373f55..fe407cae 100644 --- a/sail/pl_main.c +++ b/sail/pl_main.c @@ -1,4 +1,4 @@ -/* $NetBSD: pl_main.c,v 1.18 2009/03/02 07:21:56 dholland Exp $ */ +/* $NetBSD: pl_main.c,v 1.19 2009/03/02 07:33:30 dholland Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,10 +34,11 @@ #if 0 static char sccsid[] = "@(#)pl_main.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: pl_main.c,v 1.18 2009/03/02 07:21:56 dholland Exp $"); +__RCSID("$NetBSD: pl_main.c,v 1.19 2009/03/02 07:33:30 dholland Exp $"); #endif #endif /* not lint */ +#include <err.h> #include <setjmp.h> #include <signal.h> #include <stdio.h> @@ -86,12 +87,11 @@ reprint: printf("\nScenario number? "); fflush(stdout); scanf("%d", &game); - while (getchar() != '\n') + while (getchar() != '\n' && !feof(stdin)) ; } if (game < 0 || game >= NSCENE) { - puts("Very funny."); - exit(1); + errx(1, "Very funny."); } cc = &scene[game]; ls = SHIP(cc->vessels); @@ -101,8 +101,7 @@ reprint: foreachship(sp) { if (sp->file == NULL && (sp->file = (struct File *)calloc(1, sizeof (struct File))) == NULL) { - puts("OUT OF MEMORY"); - exit(1); + err(1, "calloc"); } sp->file->index = sp - SHIP(0); sp->file->stern = nat[sp->nationality]++; @@ -118,8 +117,7 @@ reprint: hasdriver = sync_exists(game); if (sync_open() < 0) { - perror("sail: syncfile"); - exit(1); + err(1, "syncfile"); } if (hasdriver) { @@ -156,13 +154,17 @@ reprint: fflush(stdout); if (scanf("%d", &player) != 1 || player < 0 || player >= cc->vessels) { - while (getchar() != '\n') + while (getchar() != '\n' && !feof(stdin)) ; puts("Say what?"); player = -1; } else - while (getchar() != '\n') + while (getchar() != '\n' && !feof(stdin)) ; + if (feof(stdin)) { + printf("\nExiting...\n"); + leave(LEAVE_QUIT); + } } if (player < 0) continue; @@ -246,6 +248,8 @@ reprint: } } + printf("\n"); + fflush(stdout); initscreen(); draw_board(); snprintf(message, sizeof message, "Captain %s assuming command", |