[comp.os.minix] fortune...

bert@bebux.UUCP (Bert Reuling) (12/27/88)

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
#                 "End of archive"
#
# Contents:
#
#   README
#   Makefile
#   fortune.c
#   fortunes.dat
#   popen.c
#   fdopen.c
#
# Wrapped by bert@tjilp on Thu Dec 26 21:19:07 1988
PATH=/bin:/usr/bin:/usr/local/bin ; export PATH
if test -f 'README' -a "${1}" != "-c"
then
   echo "$0: Will not overwrite existing file: README"
else
   echo "x - README (2112 characters)"
sed 's/^X//' <<\END_OF_SHAR >README
X
X                            fortune(6)
X
X                        Copyright (c) 1988
X
X                           Bert Reuling
X
X      A source of wisdom and advice for impatient modern people.
X
X
X
X            This fortune(6) program may be copied freely.
X
X
X
X     To  make  fortune,  all  you  have  to  do  is to type "make
X     fortune". Unfortunately this does not mean  instant  wealth.
X     To  install  fortune  you have to be super! It is considered
X     cheating to peek in the cookie jar (fortunes.dat). You  will
X     suffer  from  sleepless  nights and paranoia if you do! Good
X     luck!
X
X     Fortune has been in existence for over decade  now.  It  has
X     slightly  changed  from  a  source of wisdom and advice to a
X     more popular form of "notice board" for phrase-mongers  (eh,
X     phrases by well known personalities). The file format of the
X     cookie  jar  (fortunes.dat)  is  very  simple.  Each  cookie
X     consists  of one or more lines of text. The cookie ends with
X     a line that starts with "%%". The output of each  cookie  is
X     printed  'as  is'.  When fortune is compiled with the option
X     -DFORMATTER = \"formatter\", it will use formatter to format
X     the  output.  If you plan to use this with minix, you should
X     be aware of a bug in the minix library. I have included  the
X     popen.c  and fdopen.c library functions (as I think how they
X     should be).  You  should  remove  the  popen.o  module  from
X     /usr/lib/libc.a  and replace it with the new version and add
X     fdopen.o.
X
X     The karma of the super is not affected by luck, as a  result
X     of this, he (or she) will always get the same cookie.
X
X     If you have any contributions (wisdom, advice), please send
X     them to:
X
X                       ...!mcvax!bebux!bert
X
X
X                 /             /      Bert Reuling
X                /-,  ,--, ,-, /-      p/a Radio Holland bv
X               /  / /--- /   /        Jan Rebelstraat 20
X               `-'  `--  `   `--      1069 CC Amsterdam
X                                      The Netherlands
X
X                  MINIX werkgroep UNIXgg/HCC
END_OF_SHAR
   if test 2112 -ne `wc -c <'README'`
   then
      echo "$0: unpacked with wrong size: README"
   fi
fi
if test -f 'Makefile' -a "${1}" != "-c"
then
   echo "$0: Will not overwrite existing file: Makefile"
else
   echo "x - Makefile (600 characters)"
sed 's/^X//' <<\END_OF_SHAR >Makefile
X#
X# fortune  -  a source of wisdom and advice
X#
XALL = README Makefile fortune.c fortunes.dat
XDAT = /usr/games/lib
XDST = /usr/games
XCFLAGS = -O
X#
Xfortune: fortune.c
X	cc $(CFLAGS) fortune.c -o fortune
X#
X# minix formatter:
X#	cc $(CFLAGS) -DFORMATTER="\"roff \| uniq\"" fortune.c -o fortune
X#
Xinstall: fortune fortunes.dat
X	mv fortune $(DST)
X	chown bin $(DST)/fortune
X	chmod 4555 $(DST)/fortune
X	mv fortunes.dat $(DAT)/fortunes.dat
X	chown bin $(DAT)/fortunes.dat
X	chmod 0600 $(DAT)/fortunes.dat
X#
X#
X#
Xclean:
X	rm -f *.o
X	rm -f fortune core
X#
X#
X#
Xarchive:
X	shar $(ALL) popen.c fdopen.c >fortune.shar
X#
X#
X#
END_OF_SHAR
   if test 600 -ne `wc -c <'Makefile'`
   then
      echo "$0: unpacked with wrong size: Makefile"
   fi
fi
if test -f 'fortune.c' -a "${1}" != "-c"
then
   echo "$0: Will not overwrite existing file: fortune.c"
else
   echo "x - fortune.c (2176 characters)"
sed 's/^X//' <<\END_OF_SHAR >fortune.c
X/*
X *  fortune  -  hand out Chinese fortune cookies
X */
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <stdio.h>
X#include <time.h>
X
X#define COOKIEJAR "/usr/games/lib/fortunes.dat"
X
Xstatic char *Copyright = "\0fortune v1.1 Copyright (c) 1988 Bert Reuling";
X
Xlong seed;
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X   int c1, c2, c3;
X   long magic();
X   struct stat cookie_stat;
X   FILE *cookie, *out, *fopen(), *popen();
X
X   if ((cookie = fopen(COOKIEJAR, "r")) == NULL) {
X      fprintf(stderr, "%s:\nSomeone closed the cookie jar!\n", argv[0]);
X      exit(-1);
X   }
X
X   /*
X    *  create seed from : date, time, user-id and process-id
X    *  we can't get the position of the moon, unfortunately.
X    *  Note that super cookies are not affected by chance...
X    */
X   seed = time(0L) * (long) getuid() * (long) getpid();
X
X   if (stat(COOKIEJAR, &cookie_stat) != 0) {
X      fprintf(stderr, "%s:\nCannot stat cookie jar\n", argv[0]);
X      exit(-1);
X   }
X
X   fseek(cookie, magic((long) cookie_stat.st_size), 0); /* move by magic... */
X
X   c2 = c3 = '\n';
X   while (((c1 = getc(cookie)) != EOF) && ((c1 != '%') || (c2 != '%') || (c3 != '\n'))) {
X      c3 = c2;
X      c2 = c1;
X   }
X
X   if (c1 == EOF) {
X      fprintf(stderr, "%s:\n", argv[0]);
X      fprintf(stderr, "The cookie jar does not have a bottom!\n");
X      fprintf(stderr, "All cookies have fallen out...\n");
X      exit(-1);
X   }
X
X#ifdef FORMATTER
X   if ((out = popen(FORMATTER, "w")) == NULL) {
X      fprintf(stderr, "%s:\nIt furthers one to see a plumber!\n", argv[0]);
X      exit(-1);
X   }
X#else
X   out = stdout;
X#endif
X
X   c2 = c3 = '\n';
X   while (((c1 = getc(cookie)) != '%') || (c2 != '%') || (c3 != '\n')) {
X      if (c1 == EOF) {
X         rewind(cookie);
X         continue;
X      }
X      putc(c2, out);
X      c3 = c2;
X      c2 = c1;
X   }
X   putc('\n', out);
X   fclose(cookie);
X#ifdef FORMATTER
X   pclose(out);
X#endif
X   exit(0);
X}
X
X/*
X *  magic  -  please study carefull: there is more than meets the eye
X */
Xlong magic(range)
Xlong range;
X{
X   int i;
X
X   for (i = 0; i < 1234; i++)
X      seed = 883L * (seed % 881L) - 2 * (seed / 883L) + 1L;
X   return ((long)((int)(seed & 0x7fffL) * range / 0x7fffL));
X}
X
END_OF_SHAR
   if test 2176 -ne `wc -c <'fortune.c'`
   then
      echo "$0: unpacked with wrong size: fortune.c"
   fi
fi
if test -f 'fortunes.dat' -a "${1}" != "-c"
then
   echo "$0: Will not overwrite existing file: fortunes.dat"
else
   echo "x - fortunes.dat (4719 characters)"
sed 's/^X//' <<\END_OF_SHAR >fortunes.dat
XA bore is a man who, when you ask him how he is, tells you.
X  - B. L. Taylor
X%%
XOh gracious, why wasn't I born old and ugly?
X  - Dickens
X%%
XWeather is a literary specialty, and no untrained hand
Xcan turn out a good article on it.
X  - M. Twain
X%%
XA verbal contract isn't worth the paper it's written on.
X  - S. Goldwyn
X%%
X"Classic." A book which people praise and don't read.
X  - M. Twain
X%%
XThree may keep a secret, if two of them are dead.
X  - Benjamin Franklin
X%%
XEverything is funny as long as it is happening
Xto someone else.
X  - Will Rogers
X%%
XI never forget a face, but in your case I'll make an exception.
X  - Groucho Marx
X%%
XOne of the most striking differences between a cat and a lie
Xis that a cat has only nine lives.
X  - M. Twain
X%%
XWhy is it that we rejoice at a birth and grieve at a funeral?
XIt is because we are not the person involved.
X  - M. Twain
X%%
XWhen angry, count four;
Xwhen very angry, swear.
X  - M. Twain
X%%
XA perfect vacuum exists only in the minds of men.
X  - P. H. Beck
X%%
XThose whose courses are different cannot lay plans for one another.
X  - Confucian Analects Bk. 15:39
X%%
XLearning without thought is labor lost;
Xthought without learning is perilous.
X  - Confucian Analects Bk. 2:15
X%%
XThe falsely dramatic drives out the truly dull.
X  - Gennerat's Law
X%%
XOur universe is simply one of those things that happen from time to time.
X  - Edward Tryon
X%%
XWhen you have eliminated the impossible, whatever remains,
Xhowever improbable, must be the truth.
X  - Sherlock Holmes
X%%
Xadmiration, n.
XOur polite recognition of another's resemblance to ourselves.
X  - Ambrose Bierce, "The Devil's Dictionary"
X%%
Xbore, n.
XA person who talks when you wish him to listen.
X  - Ambrose Bierce, "The Devil's Dictionary"
X%%
Xcoward, n.
XOne who in a perilous emergency thinks with his legs.
X  - Ambrose Bierce, "The Devil's Dictionary"
X%%
XWhat is worth doing is worth the trouble of asking somebody to do it.
X%%
XFamous remarks are very seldom quoted correctly.
X  - Simeon Strunsky
X%%
XTo go beyond is as wrong as to fall short.
X  - Confucian Analects, Bk. 11:15,iii
X%%
XHe who speaks without modesty will find
Xit difficult to make his words good.
X  - Confucian Analects, Bk. 14:21
X%%
XHeaven and earth are not humane.
XThey regard all things as straw dogs.
X  - Lao Tzu
X%%
XHe who knows others is wise.
XHe who knows himself is enlightened.
X  - Lao Tzu
X%%
XHe who knows does not speak.
XHe who speaks does not know.
X  - Lao Tzu
X%%
XTo know that you do not know is the best.
XTo pretend to know when you do not know is a disease.
X  - Lao Tzu
X%%
XTime is the most valuable thing a man can spend.
X  - Theophrastus
X%%
XYou cannot put the same shoe on every foot.
X  - Publilius Syrus
X%%
XIf I have seen further it is by standing on the shoulders of giants.
X  - Sir Isaac Newton
X%%
XThe probability of someone watching you is
Xproportional to the stupidity of your action.
X  - A. Kindsvater
X%%
XThe various forms of worship, which prevailed in the Roman world,
Xwere all considered by the people as equally true; by the philosopher,
Xas equally false; and by the magistrate, as equally useful.
X  - Edward Gibbon, "The Decline and Fall of the Roman Empire"
X%%
XOf course you realize this means war!
X  - Bugs Bunny
X%%
XThe optimist proclaims that we live in the best of all possible worlds;
Xand the pessimist fears this is true.
X  - James Branch Cabell
X%%
XNever underestimate the power of human stupidity.
X  - From the "Notebooks of Lazarus Long" by Robert Heinlein
X%%
XOnly a mediocre person is always at his best.
X  - W. Somerset Maugham
X%%
XLife is a continuing series of multiple-choice questions, with the answers
Xtorn out of the back of the book.
X  - Sydney J. Harris
X%%
XThere is a theory which states that if ever anyone discovers exactly what
Xthe Universe is for and why it is  here. it  will instantly disappear and
Xbe replaced by something even more bizarre and inexplicable.
X
XThere is another theory which states that this has already happened.
X  - Douglas Adams, "The Restaurant at the end of the Universe"
X%%
XThe following sentence is false.
XThe preceding sentence is true.
X%%
XA well-frog cannot imagine the ocean, nor can a
Xsummer insect conceive of ice. How can a scholar
Xunderstand the Tao? He is restricted by his own
Xlearning.
X  - Chung-tse
X%%
Xpanic: can't spare any memory for you today.
X%%
X!XINIM ni deppart m'I !pleH
X%%
Xpanic: page segment violation
X%%
Xpanic: not enough memory (hey, I've got some very cheap 41256's for you)
X%% 
XHeaven wheels above you
XDisplaying to you eternal glories
XAnd still your eyes are on the ground.
X  - Dante
X%%
XWhen the mind is disturbed, the multiplicity of things is
Xproduced, but when the mind is quieted, the multiplicity
Xof things disappears.
X  - Ashvaghosha, "The Awakening of Faith.
X%%
END_OF_SHAR
   if test 4719 -ne `wc -c <'fortunes.dat'`
   then
      echo "$0: unpacked with wrong size: fortunes.dat"
   fi
fi
if test -f 'popen.c' -a "${1}" != "-c"
then
   echo "$0: Will not overwrite existing file: popen.c"
else
   echo "x - popen.c (1122 characters)"
sed 's/^X//' <<\END_OF_SHAR >popen.c
X#include <stdio.h>
X#include <signal.h>
X
Xstatic int pids[20];
X
XFILE *
Xpopen(command, type)
X	char *command, *type;
X{
X	int piped[2];
X	int Xtype = *type == 'r' ? 0 : *type == 'w' ? 1 : 2;
X	int pid;
X	extern FILE *fdopen();
X
X	if (Xtype == 2 ||
X	    pipe(piped) < 0 ||
X	    (pid = fork()) < 0) return 0;
X	
X	if (pid == 0) {
X		/* child */
X		register int *p;
X
X		for (p = pids; p < &pids[20]; p++) {
X			if (*p) close(p - pids);
X		}
X		close(piped[Xtype]);
X		dup2(piped[!Xtype], !Xtype);
X		close(piped[!Xtype]);
X		execl("/bin/sh", "sh", "-c", command, (char *) 0);
X		exit(-1);	/* like system() ??? */
X	}
X
X	pids[piped[Xtype]] = pid;
X	close(piped[!Xtype]);
X	return (fdopen(piped[Xtype], type));
X}
X
Xpclose(iop)
X	FILE *iop;
X{
X	int fd = fileno(iop);
X	int status, wret;
X	int (*intsave)() = signal(SIGINT, SIG_IGN);
X	int (*quitsave)() = signal(SIGQUIT, SIG_IGN);
X	int (*hupsave)() = signal(SIGHUP, SIG_IGN);
X
X	fclose(iop);
X	while ((wret = wait(&status)) != -1) {
X		if (wret == pids[fd]) break;
X	}
X	if (wret == -1) status = -1;
X	signal(SIGINT, intsave);
X	signal(SIGQUIT, quitsave);
X	signal(SIGHUP, hupsave);
X	pids[fd] = 0;
X	return (status);
X}
END_OF_SHAR
   if test 1122 -ne `wc -c <'popen.c'`
   then
      echo "$0: unpacked with wrong size: popen.c"
   fi
fi
if test -f 'fdopen.c' -a "${1}" != "-c"
then
   echo "$0: Will not overwrite existing file: fdopen.c"
else
   echo "x - fdopen.c (621 characters)"
sed 's/^X//' <<\END_OF_SHAR >fdopen.c
X#include <stdio.h>
X
XFILE *
Xfdopen(fd ,mode)
X	int fd;
X	char *mode;
X{
X	register int i;
X	FILE *fp;
X	char *malloc();
X	int flags = 0;
X
X	for (i = 0; _io_table[i] != 0 ; i++)
X		if ( i >= NFILES )
X			return(NULL);
X
X	switch(*mode) {
X		case 'w':
X			flags |= WRITEMODE;
X			break;
X		case 'a':
X			flags |= WRITEMODE;
X			break;
X		case 'r':
X			flags |= READMODE;
X			break;
X		default:
X			return(NULL);
X	}
X
X	if ((fp = (FILE *) malloc (sizeof(FILE))) == NULL)
X		return(NULL);
X
X	fp->_count = 0;
X	fp->_fd = fd;
X	fp->_flags = flags;
X	fp->_buf = malloc(BUFSIZ);
X	fp->_flags |= IOMYBUF;
X	fp->_ptr = fp->_buf;
X	_io_table[i] = fp;
X	return(fp);
X}
END_OF_SHAR
   if test 621 -ne `wc -c <'fdopen.c'`
   then
      echo "$0: unpacked with wrong size: fdopen.c"
   fi
fi
echo "End of archive"
exit 0
#
#
#

dono@killer.DALLAS.TX.US (Don OConnell) (01/13/89)

There is a fortune program in comp.sources.games vol #1 in several parts,
the fortune part itself is appx 500K for the scene part and 150K for the
obscene part. But I noticed that there is one being posted in parts - to
alt.sources, even as I type this, part one just hit killer.

Don O'Connell				killer!dono