From d129e7ccafb5305123dad3894b84730f9663254f Mon Sep 17 00:00:00 2001 From: dholland Date: Mon, 2 Mar 2009 07:33:30 +0000 Subject: More fixes from OpenBSD: use err instead of perror, don't hork on EOF during the initial setup questions. --- sail/pl_main.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'sail/pl_main.c') 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 #include #include #include @@ -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", -- cgit v1.2.3-56-ge451