On Nov 30 14:16:02, [email protected] wrote:
> On Nov 23 13:17:43, [email protected] wrote:
> > Declared usage() as __dead since it won't return, instructions() called
> > a handrolled pager (/bin/cat) using fork which I replaced for a simple
> > cicle of while(fgets) then fputs (greatly inspired, to not saying it was
> > bluntly copied, by a previous patch sent by tedu@ for another application).
> > After instructions() function is run then fish(6) only needs pledge "stdio".
>
> On Nov 30 01:42:03, [email protected] wrote:
> > slightly interesting pledge for fish:
> > start with "stdio rpath proc exec" since it pipes instructions to a pager
> > afterwards "stdio" is enough
>
> - just put the six lines of instructions into the manpage where they belong
> - remove fish.instr, remove instructions()
> - make the pledge a straightforward "stdio"
>
> This is what we did with quiz(6) before,
> and what I'm gonna do next with wump(6) and every other game
> which forks a PAGER just to spit out a help message.
> http://marc.info/?l=openbsd-tech&m=144576581513053&w=2
Forgot to remove pathnames.h;
and forgot the diff itself, sorry.
Jan
Index: Makefile
===================================================================
RCS file: /cvs/src/games/fish/Makefile,v
retrieving revision 1.5
diff -u -p -r1.5 Makefile
--- Makefile 23 May 2002 18:43:00 -0000 1.5
+++ Makefile 30 Nov 2015 13:24:21 -0000
@@ -3,8 +3,4 @@
PROG= fish
MAN= fish.6
-beforeinstall:
- ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 \
- ${.CURDIR}/fish.instr ${DESTDIR}/usr/share/games/fish.instr
-
.include <bsd.prog.mk>
Index: fish.6
===================================================================
RCS file: /cvs/src/games/fish/fish.6,v
retrieving revision 1.8
diff -u -p -r1.8 fish.6
--- fish.6 10 Sep 2015 15:16:43 -0000 1.8
+++ fish.6 30 Nov 2015 13:24:21 -0000
@@ -55,7 +55,8 @@ For example, collecting four 2's would g
The options are as follows:
.Bl -tag -width indent
.It Fl p
-Professional mode.
+Professional mode;
+makes the computer's game much smarter.
.El
.Pp
The computer makes a random decision as to who gets to start the
@@ -79,7 +80,34 @@ the rank is no longer in play.
The game ends when one player no longer has any cards.
The player with the most books wins.
.Pp
-.Nm
-provides instructions as to what input it accepts.
-.Sh BUGS
-The computer cheats only rarely.
+The player's input can be a card value
+.Po
+.Sq A ,
+.Sq 2 ,
+.Sq 3 ,
+.Sq 4 ,
+.Sq 5 ,
+.Sq 6 ,
+.Sq 7 ,
+.Sq 8 ,
+.Sq 9 ,
+.Sq 10 ,
+.Sq J ,
+.Sq Q ,
+.Sq K ,
+.Pc
+or the letter
+.Sq p ,
+or
+.Dq quit .
+The letter
+.Sq p
+is an equivalent of specifying the
+.Fl p
+option, and the line
+.Dq quit
+stops the game.
+Just hitting the carriage return key displays
+how many cards I have in my hand,
+how many are left in the deck,
+and which books I've gotten.
Index: fish.c
===================================================================
RCS file: /cvs/src/games/fish/fish.c,v
retrieving revision 1.18
diff -u -p -r1.18 fish.c
--- fish.c 30 Nov 2015 08:42:03 -0000 1.18
+++ fish.c 30 Nov 2015 13:24:21 -0000
@@ -43,7 +43,6 @@
#include <unistd.h>
#include <string.h>
#include <time.h>
-#include "pathnames.h"
#define RANKS 13
#define HANDSIZE 7
@@ -74,7 +73,6 @@ int getans(const char *);
int gofish(int, int, int *);
void goodmove(int, int, int *, int *);
void init(void);
-void instructions(void);
int nrandom(int);
void printhand(const int *);
void printplayer(int);
@@ -87,7 +85,7 @@ main(int argc, char *argv[])
{
int ch, move;
- if (pledge("stdio rpath proc exec", NULL) == -1)
+ if (pledge("stdio", NULL) == -1)
err(1, "pledge");
while ((ch = getopt(argc, argv, "ph")) != -1)
@@ -101,11 +99,6 @@ main(int argc, char *argv[])
usage();
}
- instructions();
-
- if (pledge("stdio", NULL) == -1)
- err(1, "pledge");
-
init();
if (nrandom(2) == 1) {
@@ -446,48 +439,6 @@ getans(const char *prompt)
"I don't understand your answer; please enter 'y' or 'n'!\n");
}
/* NOTREACHED */
-}
-
-void
-instructions(void)
-{
- const char *pager;
- pid_t pid;
- int status;
- int input;
- int fd;
-
- if (getans("Would you like instructions (y or n)? ") == 0)
- return;
-
- if ((fd = open(_PATH_INSTR, O_RDONLY)) == -1)
- (void)printf("No instruction file found!\n");
- else {
- switch (pid = fork()) {
- case 0: /* child */
- if (!isatty(1))
- pager = "/bin/cat";
- else {
- if (!(pager = getenv("PAGER")) || (*pager == 0))
- pager = _PATH_MORE;
- }
- if (dup2(fd, 0) == -1)
- err(1, "dup2");
- (void)execl(_PATH_BSHELL, "sh", "-c", pager, (char
*)NULL);
- err(1, "exec sh -c %s", pager);
- /* NOT REACHED */
- case -1:
- err(1, "fork");
- /* NOT REACHED */
- default:
- (void)waitpid(pid, &status, 0);
- close(fd);
- break;
- }
- }
-
- (void)printf("Hit return to continue...\n");
- while ((input = getchar()) != EOF && input != '\n');
}
void
Index: fish.instr
===================================================================
RCS file: fish.instr
diff -N fish.instr
--- fish.instr 22 Aug 1998 09:10:13 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,29 +0,0 @@
-This is the traditional children's card game "Go Fish". We each get seven
-cards, and the rest of the deck is kept to be drawn from later. The
-object of the game is to collect "books", or all of the cards of a single
-value. For example, getting four 2's would give you a "book of 2's".
-
-We take turns asking each other for cards, but you can't ask me for a card
-value if you don't have one of them in your hand! If I have any cards of
-the value you ask for, I have to give them to you. As long as I have one
-of the cards you ask for, you get to keep asking. If you ask me for a
-card value that I don't have, then I'll tell you to "Go Fish!" This means
-that you draw a card from the deck. If you draw the card you asked me
-for, you get to keep asking me for cards. If not, it's my turn and I ask
-you for a card.
-
-Sometimes you get to ask first, sometimes I do. I'll tell you when it's
-your turn to move, I'll draw cards from the deck for you, and I'll tell
-you what you have in your hand. (Don't worry, I don't look at your hand
-when I'm trying to decide what card to ask for, honest!)
-
-Your input can be a card value ("A", "2", "3", "4", "5", "6", "7", "8",
-"9", "10", "J", "Q" or "K") or the letter "p", or "quit". The letter "p"
-makes my game much smarter, and the line "quit" stops the game. Just
-hitting the carriage return key displays how many cards I have in my hand,
-how many are left in the deck, and which books I've gotten.
-
-Normally, the game stops when one of us runs out of cards, and the winner
-is whoever has the most books!
-
-Good luck!
Index: pathnames.h
===================================================================
RCS file: pathnames.h
diff -N pathnames.h
--- pathnames.h 3 Jun 2003 03:01:39 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,36 +0,0 @@
-/* $OpenBSD: pathnames.h,v 1.3 2003/06/03 03:01:39 millert Exp $ */
-/* $NetBSD: pathnames.h,v 1.3 1995/03/23 08:28:21 cgd Exp $ */
-
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. 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 BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)pathnames.h 8.1 (Berkeley) 5/31/93
- */
-
-#define _PATH_INSTR "/usr/share/games/fish.instr"
-#define _PATH_MORE "/usr/bin/more"