2011-09-01 11:18:50 +04:00
|
|
|
/* $NetBSD: fish.c,v 1.22 2011/09/01 07:18:50 plunky Exp $ */
|
1995-03-23 11:28:00 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
1995-03-23 11:28:00 +03:00
|
|
|
* Copyright (c) 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Muffy Barkocy.
|
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 13:36:50 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1997-10-10 16:58:29 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
2008-07-20 04:52:39 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1990, 1993\
|
|
|
|
The Regents of the University of California. All rights reserved.");
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1995-03-23 11:28:00 +03:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)fish.c 8.1 (Berkeley) 5/31/93";
|
|
|
|
#else
|
2011-09-01 11:18:50 +04:00
|
|
|
__RCSID("$NetBSD: fish.c,v 1.22 2011/09/01 07:18:50 plunky Exp $");
|
1995-03-23 11:28:00 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
1997-11-17 00:41:53 +03:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <errno.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1997-11-17 00:41:53 +03:00
|
|
|
#include <unistd.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <string.h>
|
1997-10-10 16:58:29 +04:00
|
|
|
#include <time.h>
|
1997-11-17 00:41:53 +03:00
|
|
|
#include <err.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "pathnames.h"
|
|
|
|
|
|
|
|
#define RANKS 13
|
|
|
|
#define HANDSIZE 7
|
|
|
|
#define CARDS 4
|
2000-03-28 23:37:54 +04:00
|
|
|
#define TOTCARDS RANKS * CARDS
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#define USER 1
|
|
|
|
#define COMPUTER 0
|
|
|
|
#define OTHER(a) (1 - (a))
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static const char *const cards[] = {
|
1993-03-21 12:45:37 +03:00
|
|
|
"A", "2", "3", "4", "5", "6", "7",
|
|
|
|
"8", "9", "10", "J", "Q", "K", NULL,
|
|
|
|
};
|
|
|
|
#define PRC(card) (void)printf(" %s", cards[card])
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static int promode;
|
|
|
|
static int asked[RANKS], comphand[RANKS], deck[TOTCARDS];
|
|
|
|
static int userasked[RANKS], userhand[RANKS];
|
|
|
|
static int curcard = TOTCARDS;
|
|
|
|
|
|
|
|
static void chkwinner(int, const int *);
|
|
|
|
static int compmove(void);
|
|
|
|
static int countbooks(const int *);
|
|
|
|
static int countcards(const int *);
|
|
|
|
static int drawcard(int, int *);
|
|
|
|
static int gofish(int, int, int *);
|
|
|
|
static void goodmove(int, int, int *, int *);
|
|
|
|
static void init(void);
|
|
|
|
static void instructions(void);
|
|
|
|
static int nrandom(int);
|
|
|
|
static void printhand(const int *);
|
|
|
|
static void printplayer(int);
|
|
|
|
static int promove(void);
|
|
|
|
static void usage(void) __dead;
|
|
|
|
static int usermove(void);
|
1997-10-10 16:58:29 +04:00
|
|
|
|
|
|
|
int
|
2005-07-02 12:35:29 +04:00
|
|
|
main(int argc, char **argv)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
int ch, move;
|
|
|
|
|
1999-09-12 13:02:20 +04:00
|
|
|
/* Revoke setgid privileges */
|
2000-05-08 11:55:59 +04:00
|
|
|
setgid(getgid());
|
1999-07-14 21:30:21 +04:00
|
|
|
|
1997-10-10 16:58:29 +04:00
|
|
|
while ((ch = getopt(argc, argv, "p")) != -1)
|
1993-03-21 12:45:37 +03:00
|
|
|
switch(ch) {
|
|
|
|
case 'p':
|
|
|
|
promode = 1;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
1999-09-22 22:55:14 +04:00
|
|
|
usage();
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2011-08-31 20:24:54 +04:00
|
|
|
srandom(time(NULL));
|
1993-03-21 12:45:37 +03:00
|
|
|
instructions();
|
|
|
|
init();
|
|
|
|
|
|
|
|
if (nrandom(2) == 1) {
|
|
|
|
printplayer(COMPUTER);
|
|
|
|
(void)printf("get to start.\n");
|
|
|
|
goto istart;
|
|
|
|
}
|
|
|
|
printplayer(USER);
|
|
|
|
(void)printf("get to start.\n");
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
move = usermove();
|
|
|
|
if (!comphand[move]) {
|
|
|
|
if (gofish(move, USER, userhand))
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
goodmove(USER, move, userhand, comphand);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
istart: for (;;) {
|
|
|
|
move = compmove();
|
|
|
|
if (!userhand[move]) {
|
|
|
|
if (!gofish(move, COMPUTER, comphand))
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
goodmove(COMPUTER, move, comphand, userhand);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static int
|
2005-07-02 12:35:29 +04:00
|
|
|
usermove(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 16:58:29 +04:00
|
|
|
int n;
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
const char *const *p;
|
1993-03-21 12:45:37 +03:00
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
(void)printf("\nYour hand is:");
|
|
|
|
printhand(userhand);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
(void)printf("You ask me for: ");
|
|
|
|
(void)fflush(stdout);
|
1999-04-25 02:09:06 +04:00
|
|
|
if (fgets(buf, sizeof(buf), stdin) == NULL)
|
1993-03-21 12:45:37 +03:00
|
|
|
exit(0);
|
|
|
|
if (buf[0] == '\0')
|
|
|
|
continue;
|
|
|
|
if (buf[0] == '\n') {
|
|
|
|
(void)printf("%d cards in my hand, %d in the pool.\n",
|
2000-03-28 23:37:54 +04:00
|
|
|
countcards(comphand), curcard);
|
1993-03-21 12:45:37 +03:00
|
|
|
(void)printf("My books:");
|
|
|
|
(void)countbooks(comphand);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
buf[strlen(buf) - 1] = '\0';
|
|
|
|
if (!strcasecmp(buf, "p") && !promode) {
|
|
|
|
promode = 1;
|
|
|
|
(void)printf("Entering pro mode.\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!strcasecmp(buf, "quit"))
|
|
|
|
exit(0);
|
|
|
|
for (p = cards; *p; ++p)
|
|
|
|
if (!strcasecmp(*p, buf))
|
|
|
|
break;
|
|
|
|
if (!*p) {
|
|
|
|
(void)printf("I don't understand!\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
n = p - cards;
|
|
|
|
if (userhand[n]) {
|
|
|
|
userasked[n] = 1;
|
|
|
|
return(n);
|
|
|
|
}
|
|
|
|
if (nrandom(3) == 1)
|
|
|
|
(void)printf("You don't have any of those!\n");
|
|
|
|
else
|
|
|
|
(void)printf("You don't have any %s's!\n", cards[n]);
|
|
|
|
if (nrandom(4) == 1)
|
|
|
|
(void)printf("No cheating!\n");
|
|
|
|
(void)printf("Guess again.\n");
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static int
|
2005-07-02 12:35:29 +04:00
|
|
|
compmove(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
static int lmove;
|
|
|
|
|
|
|
|
if (promode)
|
|
|
|
lmove = promove();
|
|
|
|
else {
|
|
|
|
do {
|
|
|
|
lmove = (lmove + 1) % RANKS;
|
|
|
|
} while (!comphand[lmove] || comphand[lmove] == CARDS);
|
|
|
|
}
|
|
|
|
asked[lmove] = 1;
|
|
|
|
|
|
|
|
(void)printf("I ask you for: %s.\n", cards[lmove]);
|
|
|
|
return(lmove);
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static int
|
2005-07-02 12:35:29 +04:00
|
|
|
promove(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 16:58:29 +04:00
|
|
|
int i, max;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
for (i = 0; i < RANKS; ++i)
|
|
|
|
if (userasked[i] &&
|
|
|
|
comphand[i] > 0 && comphand[i] < CARDS) {
|
|
|
|
userasked[i] = 0;
|
|
|
|
return(i);
|
|
|
|
}
|
|
|
|
if (nrandom(3) == 1) {
|
|
|
|
for (i = 0;; ++i)
|
|
|
|
if (comphand[i] && comphand[i] != CARDS) {
|
|
|
|
max = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (++i < RANKS)
|
|
|
|
if (comphand[i] != CARDS &&
|
|
|
|
comphand[i] > comphand[max])
|
|
|
|
max = i;
|
|
|
|
return(max);
|
|
|
|
}
|
|
|
|
if (nrandom(1024) == 0723) {
|
|
|
|
for (i = 0; i < RANKS; ++i)
|
|
|
|
if (userhand[i] && comphand[i])
|
|
|
|
return(i);
|
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
for (i = 0; i < RANKS; ++i)
|
|
|
|
if (comphand[i] && comphand[i] != CARDS &&
|
|
|
|
!asked[i])
|
|
|
|
return(i);
|
|
|
|
for (i = 0; i < RANKS; ++i)
|
|
|
|
asked[i] = 0;
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static int
|
2005-07-02 12:35:29 +04:00
|
|
|
drawcard(int player, int *hand)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
int card;
|
|
|
|
|
2000-03-28 23:37:54 +04:00
|
|
|
++hand[card = deck[--curcard]];
|
1993-03-21 12:45:37 +03:00
|
|
|
if (player == USER || hand[card] == CARDS) {
|
|
|
|
printplayer(player);
|
|
|
|
(void)printf("drew %s", cards[card]);
|
|
|
|
if (hand[card] == CARDS) {
|
|
|
|
(void)printf(" and made a book of %s's!\n",
|
|
|
|
cards[card]);
|
|
|
|
chkwinner(player, hand);
|
|
|
|
} else
|
|
|
|
(void)printf(".\n");
|
|
|
|
}
|
|
|
|
return(card);
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static int
|
2005-07-02 12:35:29 +04:00
|
|
|
gofish(int askedfor, int player, int *hand)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
printplayer(OTHER(player));
|
|
|
|
(void)printf("say \"GO FISH!\"\n");
|
|
|
|
if (askedfor == drawcard(player, hand)) {
|
|
|
|
printplayer(player);
|
|
|
|
(void)printf("drew the guess!\n");
|
|
|
|
printplayer(player);
|
|
|
|
(void)printf("get to ask again!\n");
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static void
|
2005-07-02 12:35:29 +04:00
|
|
|
goodmove(int player, int move, int *hand, int *opphand)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
printplayer(OTHER(player));
|
|
|
|
(void)printf("have %d %s%s.\n",
|
|
|
|
opphand[move], cards[move], opphand[move] == 1 ? "": "'s");
|
|
|
|
|
|
|
|
hand[move] += opphand[move];
|
|
|
|
opphand[move] = 0;
|
|
|
|
|
|
|
|
if (hand[move] == CARDS) {
|
|
|
|
printplayer(player);
|
|
|
|
(void)printf("made a book of %s's!\n", cards[move]);
|
|
|
|
chkwinner(player, hand);
|
|
|
|
}
|
|
|
|
|
|
|
|
chkwinner(OTHER(player), opphand);
|
|
|
|
|
|
|
|
printplayer(player);
|
|
|
|
(void)printf("get another guess!\n");
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static void
|
2005-07-02 12:35:29 +04:00
|
|
|
chkwinner(int player, const int *hand)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 16:58:29 +04:00
|
|
|
int cb, i, ub;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
for (i = 0; i < RANKS; ++i)
|
|
|
|
if (hand[i] > 0 && hand[i] < CARDS)
|
|
|
|
return;
|
|
|
|
printplayer(player);
|
|
|
|
(void)printf("don't have any more cards!\n");
|
|
|
|
(void)printf("My books:");
|
|
|
|
cb = countbooks(comphand);
|
|
|
|
(void)printf("Your books:");
|
|
|
|
ub = countbooks(userhand);
|
|
|
|
(void)printf("\nI have %d, you have %d.\n", cb, ub);
|
|
|
|
if (ub > cb) {
|
|
|
|
(void)printf("\nYou win!!!\n");
|
|
|
|
if (nrandom(1024) == 0723)
|
|
|
|
(void)printf("Cheater, cheater, pumpkin eater!\n");
|
|
|
|
} else if (cb > ub) {
|
|
|
|
(void)printf("\nI win!!!\n");
|
|
|
|
if (nrandom(1024) == 0723)
|
|
|
|
(void)printf("Hah! Stupid peasant!\n");
|
|
|
|
} else
|
|
|
|
(void)printf("\nTie!\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static void
|
2005-07-02 12:35:29 +04:00
|
|
|
printplayer(int player)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
switch (player) {
|
|
|
|
case COMPUTER:
|
|
|
|
(void)printf("I ");
|
|
|
|
break;
|
|
|
|
case USER:
|
|
|
|
(void)printf("You ");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static void
|
2005-07-02 12:35:29 +04:00
|
|
|
printhand(const int *hand)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 16:58:29 +04:00
|
|
|
int book, i, j;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
for (book = i = 0; i < RANKS; i++)
|
|
|
|
if (hand[i] < CARDS)
|
|
|
|
for (j = hand[i]; --j >= 0;)
|
|
|
|
PRC(i);
|
|
|
|
else
|
|
|
|
++book;
|
|
|
|
if (book) {
|
|
|
|
(void)printf(" + Book%s of", book > 1 ? "s" : "");
|
|
|
|
for (i = 0; i < RANKS; i++)
|
|
|
|
if (hand[i] == CARDS)
|
|
|
|
PRC(i);
|
|
|
|
}
|
|
|
|
(void)putchar('\n');
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static int
|
2005-07-02 12:35:29 +04:00
|
|
|
countcards(const int *hand)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 16:58:29 +04:00
|
|
|
int i, count;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
for (count = i = 0; i < RANKS; i++)
|
|
|
|
count += *hand++;
|
|
|
|
return(count);
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static int
|
2005-07-02 12:35:29 +04:00
|
|
|
countbooks(const int *hand)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
int i, count;
|
|
|
|
|
|
|
|
for (count = i = 0; i < RANKS; i++)
|
|
|
|
if (hand[i] == CARDS) {
|
|
|
|
++count;
|
|
|
|
PRC(i);
|
|
|
|
}
|
|
|
|
if (!count)
|
|
|
|
(void)printf(" none");
|
|
|
|
(void)putchar('\n');
|
|
|
|
return(count);
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static void
|
2005-07-02 12:35:29 +04:00
|
|
|
init(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-03-28 23:37:54 +04:00
|
|
|
int i, j, temp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-03-28 23:37:54 +04:00
|
|
|
for (i = 0; i < TOTCARDS; ++i)
|
|
|
|
deck[i] = i % RANKS;
|
|
|
|
for (i = 0; i < TOTCARDS - 1; ++i) {
|
|
|
|
j = nrandom(TOTCARDS-i);
|
|
|
|
if (j == 0)
|
|
|
|
continue;
|
|
|
|
temp = deck[i];
|
|
|
|
deck[i] = deck[i+j];
|
|
|
|
deck[i+j] = temp;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
for (i = 0; i < HANDSIZE; ++i) {
|
2000-03-28 23:37:54 +04:00
|
|
|
++userhand[deck[--curcard]];
|
|
|
|
++comphand[deck[--curcard]];
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static int
|
2005-07-02 12:35:29 +04:00
|
|
|
nrandom(int n)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
return((int)random() % n);
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static void
|
2005-07-02 12:35:29 +04:00
|
|
|
instructions(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
int input;
|
1997-11-17 00:41:53 +03:00
|
|
|
pid_t pid;
|
1999-07-14 21:30:21 +04:00
|
|
|
int fd;
|
|
|
|
const char *pager;
|
1997-11-17 00:41:53 +03:00
|
|
|
int status;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
(void)printf("Would you like instructions (y or n)? ");
|
|
|
|
input = getchar();
|
|
|
|
while (getchar() != '\n');
|
|
|
|
if (input != 'y')
|
|
|
|
return;
|
|
|
|
|
1997-11-17 00:41:53 +03:00
|
|
|
switch (pid = fork()) {
|
|
|
|
case 0: /* child */
|
1999-07-14 21:30:21 +04:00
|
|
|
if (!isatty(1))
|
|
|
|
pager = "cat";
|
|
|
|
else {
|
|
|
|
if (!(pager = getenv("PAGER")) || (*pager == 0))
|
|
|
|
pager = _PATH_MORE;
|
|
|
|
}
|
|
|
|
if ((fd = open(_PATH_INSTR, O_RDONLY)) == -1)
|
|
|
|
err(1, "open %s", _PATH_INSTR);
|
|
|
|
if (dup2(fd, 0) == -1)
|
|
|
|
err(1, "dup2");
|
2011-09-01 11:18:50 +04:00
|
|
|
(void)execl("/bin/sh", "sh", "-c", pager, (char *) NULL);
|
1999-07-14 21:30:21 +04:00
|
|
|
err(1, "exec sh -c %s", pager);
|
1997-11-17 00:41:53 +03:00
|
|
|
/*NOTREACHED*/
|
|
|
|
case -1:
|
|
|
|
err(1, "fork");
|
|
|
|
/*NOTREACHED*/
|
|
|
|
default:
|
|
|
|
(void)waitpid(pid, &status, 0);
|
|
|
|
break;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
(void)printf("Hit return to continue...\n");
|
|
|
|
while ((input = getchar()) != EOF && input != '\n');
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:48:04 +04:00
|
|
|
static void
|
2005-07-02 12:35:29 +04:00
|
|
|
usage(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
(void)fprintf(stderr, "usage: fish [-p]\n");
|
|
|
|
exit(1);
|
|
|
|
}
|