Sun Jul 25 02:00:42 2021 UTC ()
Flush input to EOL correctly in games/fish.

PR 54885 from Mouse, with a somewhat different patch.


(dholland)
diff -r1.26 -r1.27 src/games/fish/fish.c

cvs diff -r1.26 -r1.27 src/games/fish/fish.c (expand / switch to unified diff)

--- src/games/fish/fish.c 2021/05/02 12:25:55 1.26
+++ src/games/fish/fish.c 2021/07/25 02:00:42 1.27
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: fish.c,v 1.26 2021/05/02 12:25:55 rillig Exp $ */ 1/* $NetBSD: fish.c,v 1.27 2021/07/25 02:00:42 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1990, 1993 4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Muffy Barkocy. 8 * Muffy Barkocy.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -32,27 +32,27 @@ @@ -32,27 +32,27 @@
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36#ifndef lint 36#ifndef lint
37__COPYRIGHT("@(#) Copyright (c) 1990, 1993\ 37__COPYRIGHT("@(#) Copyright (c) 1990, 1993\
38 The Regents of the University of California. All rights reserved."); 38 The Regents of the University of California. All rights reserved.");
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#ifndef lint 41#ifndef lint
42#if 0 42#if 0
43static char sccsid[] = "@(#)fish.c 8.1 (Berkeley) 5/31/93"; 43static char sccsid[] = "@(#)fish.c 8.1 (Berkeley) 5/31/93";
44#else 44#else
45__RCSID("$NetBSD: fish.c,v 1.26 2021/05/02 12:25:55 rillig Exp $"); 45__RCSID("$NetBSD: fish.c,v 1.27 2021/07/25 02:00:42 dholland Exp $");
46#endif 46#endif
47#endif /* not lint */ 47#endif /* not lint */
48 48
49#include <sys/types.h> 49#include <sys/types.h>
50#include <sys/wait.h> 50#include <sys/wait.h>
51#include <errno.h> 51#include <errno.h>
52#include <fcntl.h> 52#include <fcntl.h>
53#include <stdio.h> 53#include <stdio.h>
54#include <stdlib.h> 54#include <stdlib.h>
55#include <unistd.h> 55#include <unistd.h>
56#include <string.h> 56#include <string.h>
57#include <err.h> 57#include <err.h>
58#include "pathnames.h" 58#include "pathnames.h"
@@ -422,35 +422,40 @@ init(void) @@ -422,35 +422,40 @@ init(void)
422 temp = deck[i]; 422 temp = deck[i];
423 deck[i] = deck[i+j]; 423 deck[i] = deck[i+j];
424 deck[i+j] = temp; 424 deck[i+j] = temp;
425 } 425 }
426 for (i = 0; i < HANDSIZE; ++i) { 426 for (i = 0; i < HANDSIZE; ++i) {
427 ++userhand[deck[--curcard]]; 427 ++userhand[deck[--curcard]];
428 ++comphand[deck[--curcard]]; 428 ++comphand[deck[--curcard]];
429 } 429 }
430} 430}
431 431
432static void 432static void
433instructions(void) 433instructions(void)
434{ 434{
435 int input; 435 int input, c;
436 pid_t pid; 436 pid_t pid;
437 int fd; 437 int fd;
438 const char *pager; 438 const char *pager;
439 int status; 439 int status;
440 440
441 (void)printf("Would you like instructions (y or n)? "); 441 (void)printf("Would you like instructions (y or n)? ");
442 input = getchar(); 442 input = c = getchar();
443 while (getchar() != '\n'); 443 while (c != '\n') {
 444 c = getchar();
 445 if (c == EOF) {
 446 exit(1);
 447 }
 448 }
444 if (input != 'y') 449 if (input != 'y')
445 return; 450 return;
446 451
447 switch (pid = fork()) { 452 switch (pid = fork()) {
448 case 0: /* child */ 453 case 0: /* child */
449 if (!isatty(1)) 454 if (!isatty(1))
450 pager = "cat"; 455 pager = "cat";
451 else { 456 else {
452 if (!(pager = getenv("PAGER")) || (*pager == 0)) 457 if (!(pager = getenv("PAGER")) || (*pager == 0))
453 pager = _PATH_MORE; 458 pager = _PATH_MORE;
454 } 459 }
455 if ((fd = open(_PATH_INSTR, O_RDONLY)) == -1) 460 if ((fd = open(_PATH_INSTR, O_RDONLY)) == -1)
456 err(1, "open %s", _PATH_INSTR); 461 err(1, "open %s", _PATH_INSTR);