[comp.sources.games] v01i091: fortune - quote for the day, v7diffs

games-request@tekred.TEK.COM (07/13/87)

Submitted by: gerry@eclectic.UUCP (G. R. Singleton)
Comp.sources.games: Volume 1, Issue 91
Archive-name: fortune/v7diffs

	[I am associating this with the fortune distribution so
	 people desiring this info won't have to look all over
	 for it.	-br]

[[I have managed to shoehorn the BSD fortune that was recently posted to
comp.sources.games into the Venix/86 version 2.x environment.

In expectation that there are others out there with V7 clones rather than
the fancy new Berkeley and AT&T version, I would like you to post the
changes (context diffs) to the net.  

Thanks,
G. R. Singleton, <gerry@eclectic.UUCP>]]
---------------------------

#! /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 shell archive."
# Contents:  v7Makefile.dif v7fortun.dif v7strfl_h.dif
# Wrapped by billr@tekred on Mon Jul 13 09:31:55 1987
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f v7Makefile.dif -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"v7Makefile.dif\"
else
echo shar: Extracting \"v7Makefile.dif\" \(1240 characters\)
sed "s/^X//" >v7Makefile.dif <<'END_OF_v7Makefile.dif'
X*** net/Makefile      Sun Jun  7 17:58:45 1987
X--- Makefile    Tue Jun 16 21:40:30 1987
X***************
X*** 10,16
X  MISC=		READ_ME fortune.6 strfile.8 Makefile Notes Rot13 Shar_split :trfix
X  LIBDIR=		/usr/games/lib
X  BINDIR=		/usr/games
X! USER=		sys			# owner of fortune system
X  #DEFS=					# BSD systems
X  #DEFS=		-DNO_RANDOM -DREGCMP	# System V systems
X  # for venix use the following entry
X
X--- 10,16 -----
X  MISC=		READ_ME fortune.6 strfile.8 Makefile Notes Rot13 Shar_split :trfix
X  LIBDIR=		/usr/games/lib
X  BINDIR=		/usr/games
X! USER=		games			# owner of fortune system
X  #DEFS=					# BSD systems
X  #DEFS=		-DNO_RANDOM -DREGCMP 	# System V systems
X  # for venix use the following entry
X***************
X*** 12,18
X  BINDIR=		/usr/games
X  USER=		sys			# owner of fortune system
X  #DEFS=					# BSD systems
X! #DEFS=		-DNO_RANDOM -DREGCMP	# System V systems
X  # for venix use the following entry
X  DEFS=		-DNO_RANDOM -DNO_REGX -Dvoid=int -DVENIX
X  CFLAGS=		-O $(DEFS)
X
X--- 12,18 -----
X  BINDIR=		/usr/games
X  USER=		games			# owner of fortune system
X  #DEFS=					# BSD systems
X! #DEFS=		-DNO_RANDOM -DREGCMP 	# System V systems
X  # for venix use the following entry
X  DEFS=		-DNO_RANDOM -DNO_REGX -Dvoid=int -DVENIX
X  CFLAGS=		-O $(DEFS)
END_OF_v7Makefile.dif
if test 1240 -ne `wc -c <v7Makefile.dif`; then
    echo shar: \"v7Makefile.dif\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f v7fortun.dif -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"v7fortun.dif\"
else
echo shar: Extracting \"v7fortun.dif\" \(9473 characters\)
sed "s/^X//" >v7fortun.dif <<'END_OF_v7fortun.dif'
X*** net/fortune.c      Sun Jun  7 18:00:43 1987
X--- fortune.c    Tue Jun 16 20:59:56 1987
X***************
X*** 2,7
X  
X  # include	<sys/types.h>
X  # include	<stdio.h>
X  # include	<sys/file.h>
X  # include	<sys/stat.h>
X  # include	"strfile.h"
X
X--- 2,8 -----
X  
X  # include	<sys/types.h>
X  # include	<stdio.h>
X+ # ifndef VENIX
X  # include	<sys/file.h>
X  # endif
X  # include	<sys/stat.h>
X***************
X*** 3,8
X  # include	<sys/types.h>
X  # include	<stdio.h>
X  # include	<sys/file.h>
X  # include	<sys/stat.h>
X  # include	"strfile.h"
X  
X
X--- 4,10 -----
X  # include	<stdio.h>
X  # ifndef VENIX
X  # include	<sys/file.h>
X+ # endif
X  # include	<sys/stat.h>
X  # include	"strfile.h"
X  
X***************
X*** 18,23
X  # define	CPERS	20		/* # of chars for each sec */
X  # define	SLEN	160		/* # of chars in short fortune */
X  
X  # define	FORTFILE	"/usr/games/lib/fortunes.dat"
X  
X  bool	Wflag		= FALSE;	/* wait desired after fortune */
X
X--- 20,31 -----
X  # define	CPERS	20		/* # of chars for each sec */
X  # define	SLEN	160		/* # of chars in short fortune */
X  
X+ # ifdef VENIX
X+ # define TBLFILE		"/usr/games/lib/Tbl.dat"
X+ char	*Tblfile	= TBLFILE;	/* header information*/
X+ FILE	*Tabl;
X+ # endif
X+ 
X  # define	FORTFILE	"/usr/games/lib/fortunes.dat"
X  
X  bool	Wflag		= FALSE;	/* wait desired after fortune */
X***************
X*** 31,37
X  
X  char	*Fortfile	= FORTFILE,	/* fortune database */
X  	*Usage[]	= {
X- # ifdef	NO_REGEX
X         "usage:  fortune [ - ] [ -wsloa ] [ file ]",
X  # else
X         "usage:  fortune [ - ] [ -wsloai ] [ -m pattern ] [ file ]",
X
X--- 39,44 -----
X  
X  char	*Fortfile	= FORTFILE,	/* fortune database */
X  	*Usage[]	= {
X         "usage:  fortune [ - ] [ -wsloa ] [ file ]",
X         "	- - give this summary of usage",
X         "	w - have program wait after printing message in order",
X***************
X*** 33,41
X  	*Usage[]	= {
X  # ifdef	NO_REGEX
X         "usage:  fortune [ - ] [ -wsloa ] [ file ]",
X- # else
X-        "usage:  fortune [ - ] [ -wsloai ] [ -m pattern ] [ file ]",
X- # endif
X         "	- - give this summary of usage",
X         "	w - have program wait after printing message in order",
X         "	    to give time to read",
X
X--- 40,45 -----
X  char	*Fortfile	= FORTFILE,	/* fortune database */
X  	*Usage[]	= {
X         "usage:  fortune [ - ] [ -wsloa ] [ file ]",
X         "	- - give this summary of usage",
X         "	w - have program wait after printing message in order",
X         "	    to give time to read",
X***************
X*** 43,52
X         "	l - long fortunes only",
X         "	o - offensive fortunes only",
X         "	a - any fortune, regular or offensive",
X- # ifndef NO_REGEX
X-        "	m - print fortunes which match a pattern",
X-        "	i - ignore case in matching patterns",
X- # endif
X         "		Mail suggested fortunes to \"fortune@ucbvax.berkeley.edu\"",
X  	NULL
X  	};
X
X--- 47,52 -----
X         "	l - long fortunes only",
X         "	o - offensive fortunes only",
X         "	a - any fortune, regular or offensive",
X         "		Mail suggested fortunes to \"fortune@ucbvax.berkeley.edu\"",
X  	NULL
X  	};
X***************
X*** 59,85
X  
X  char	*malloc();
X  
X- # ifndef NO_REGEX
X- char	*conv_pat();
X- # endif
X- 
X- # ifndef	NO_REGX
X- # ifdef REGCMP
X- # define	RE_COMP(p)	(Re_pat = regcmp(p, NULL))
X- # define	BAD_COMP(f)	((f) == NULL)
X- # define	RE_EXEC(p)	regex(Re_pat, (p))
X- char	*Re_pat, 
X- 	*regcmp(), 
X- 	*regex();
X- # else
X- # define	RE_COMP(p)	(p = re_comp(p))
X- # define	BAD_COMP(f)	((f) != NULL)
X- # define	RE_EXEC(p)	re_exec(p)
X- char	*re_comp(), 
X- 	*re_exec();
X- # endif REGCMP
X- # endif NO_REGX
X- 
X  time_t	time();
X  
X  main(ac, av)
X
X--- 59,64 -----
X  
X  char	*malloc();
X  
X  time_t	time();
X  
X  main(ac, av)
X***************
X*** 90,95
X  	register int	nchar = 0;
X  
X  	getargs(ac, av);
X  	if ((Inf = fopen(Fortfile, "r+")) == NULL) {
X  		perror(Fortfile);
X  		exit(-1);
X
X--- 69,77 -----
X  	register int	nchar = 0;
X  
X  	getargs(ac, av);
X+ # ifdef VENIX
X+ 	if ((Inf = fopen(Fortfile, "r")) == NULL) {
X+ # else
X  	if ((Inf = fopen(Fortfile, "r+")) == NULL) {
X  # endif
X  		perror(Fortfile);
X***************
X*** 91,96
X  
X  	getargs(ac, av);
X  	if ((Inf = fopen(Fortfile, "r+")) == NULL) {
X  		perror(Fortfile);
X  		exit(-1);
X  	}
X
X--- 73,79 -----
X  	if ((Inf = fopen(Fortfile, "r")) == NULL) {
X  # else
X  	if ((Inf = fopen(Fortfile, "r+")) == NULL) {
X+ # endif
X  		perror(Fortfile);
X  		exit(-1);
X  	}
X***************
X*** 94,102
X  		perror(Fortfile);
X  		exit(-1);
X  	}
X! 	if (fread((char *) &Tbl, sizeof Tbl, 1, Inf) != 1) {	/* NOSTRICT */
X! 		fprintf(stderr, "fortune file is truncated\n");
X! 		exit(-1);
X  	}
X  	if (Tbl.str_longlen <= SLEN && Lflag) {
X  		fprintf(stderr, "Sorry, no long strings in this file\n");
X
X--- 77,92 -----
X  		perror(Fortfile);
X  		exit(-1);
X  	}
X! 	if ((Tabl = fopen(Tblfile, "r"))) {
X! 		if (fread((char *) &Tbl, sizeof Tbl, 1, Tabl) != 1) { 	/* NOSTRICT */
X! 			fprintf(stderr, "fortune file is truncated\n");
X! 			exit(-1);
X! 		}
X! 	} else {
X! 		if (fread((char *) &Tbl, sizeof Tbl, 1, Inf) != 1) {	/* NOSTRICT */
X! 			fprintf(stderr, "fortune file is truncated\n");
X! 			exit(-1);
X! 		}
X  	}
X  	if (Tbl.str_longlen <= SLEN && Lflag) {
X  		fprintf(stderr, "Sorry, no long strings in this file\n");
X***************
X*** 113,124
X  	if (Tbl.str_delims[2] == 0)
X  		Tbl.str_delims[2] = Tbl.str_delims[0];
X  
X- # ifndef NO_REGEX
X- 	if (Mflag) {
X- 		find_matches();
X- 		/* NOTREACHED */
X- 	}
X- # endif
X  
X  	do {
X  		getfort();
X
X--- 103,108 -----
X  	if (Tbl.str_delims[2] == 0)
X  		Tbl.str_delims[2] = Tbl.str_delims[0];
X  
X  
X  	do {
X  		getfort();
X***************
X*** 130,135
X  		putchar(c);
X  	}
X  	(void) fflush(stdout);
X  	(void) fseek(Inf, 0L, 0);
X  # ifdef	LOCK_EX
X  	/*
X
X--- 114,123 -----
X  		putchar(c);
X  	}
X  	(void) fflush(stdout);
X+ # ifdef VENIX
X+ 	(void) fclose(Inf);
X+ 	(void) fclose(Tabl);
X+ # else
X  	(void) fseek(Inf, 0L, 0);
X  # endif
X  # ifdef	LOCK_EX
X***************
X*** 131,136
X  	}
X  	(void) fflush(stdout);
X  	(void) fseek(Inf, 0L, 0);
X  # ifdef	LOCK_EX
X  	/*
X  	 * if we can, we exclusive lock, but since it isn't very
X
X--- 119,125 -----
X  	(void) fclose(Tabl);
X  # else
X  	(void) fseek(Inf, 0L, 0);
X+ # endif
X  # ifdef	LOCK_EX
X  	/*
X  	 * if we can, we exclusive lock, but since it isn't very
X***************
X*** 139,145
X  	 */
X  	(void) flock(fileno(Inf), LOCK_EX);
X  # endif	LOCK_EX
X! 	if (fwrite((char *) &Tbl, 1, sizeof Tbl, Inf) != sizeof Tbl)
X  		fprintf(stderr, "can't update fortune data file\n");
X  # ifdef	LOCK_EX
X  	(void) flock(fileno(Inf), LOCK_UN);
X
X--- 128,144 -----
X  	 */
X  	(void) flock(fileno(Inf), LOCK_EX);
X  # endif	LOCK_EX
X! # ifdef VENIX
X! 	if ((Tabl = fopen(Tblfile, "w")) == NULL) {
X! 		perror(Tblfile);
X! 		exit(-1);
X! 	}
X! # endif
X! # ifdef VENIX
X! 	if (fwrite((char *) &Tbl, 1,  sizeof Tbl, Tabl) != sizeof Tbl)
X! # else
X! 	if (fwrite((char *) &Tbl, 1,  sizeof Tbl, Inf) != sizeof Tbl)
X! # endif
X  		fprintf(stderr, "can't update fortune data file\n");
X  # ifdef	LOCK_EX
X  	(void) flock(fileno(Inf), LOCK_UN);
X***************
X*** 278,298
X  				}
X  	}
X  
X- # ifndef NO_REGEX
X- 	if (pat != NULL) {
X- 		if (ignore_case)
X- 			pat = conv_pat(pat);
X- 		if (BAD_COMP(RE_COMP(pat))) {
X- # ifndef REGCMP
X- 			fprintf(stderr, "%s\n", pat);
X- # else
X- 			fprintf(stderr, "bad pattern: %s\n", pat);
X- # endif
X- 			bad++;
X- 		}
X- 	}
X- # endif	NO_REGEX
X- 
X  	if (bad) {
X  		printf("use \"%s -\" to get usage\n", av[0]);
X  		exit(-1);
X
X--- 277,282 -----
X  				}
X  	}
X  
X  	if (bad) {
X  		printf("use \"%s -\" to get usage\n", av[0]);
X  		exit(-1);
X***************
X*** 343,441
X  {
X  	return (i >= j ? i : j);
X  }
X- 
X- # ifndef	NO_REGEX
X- /*
X-  * conv_pat:
X-  *	Convert the pattern to an ignore-case equivalent.
X-  */
X- char *
X- conv_pat(orig)
X- register char	*orig;
X- {
X- 	register char	*sp;
X- 	register int	cnt;
X- 	register char	*new;
X- 
X- 	cnt = 1;	/* allow for '\0' */
X- 	for (sp = orig; *sp != '\0'; sp++)
X- 		if (isalpha(*sp))
X- 			cnt += 4;
X- 		else
X- 			cnt++;
X- 	if ((new = malloc(cnt)) == NULL) {
X- 		fprintf(stderr, "pattern too long for ignoring case\n");
X- 		exit(1);
X- 	}
X- 
X- 	for (sp = new; *orig != '\0'; orig++) {
X- 		if (islower(*orig)) {
X- 			*sp++ = '[';
X- 			*sp++ = *orig;
X- 			*sp++ = toupper(*orig);
X- 			*sp++ = ']';
X- 		}
X- 		else if (isupper(*orig)) {
X- 			*sp++ = '[';
X- 			*sp++ = *orig;
X- 			*sp++ = tolower(*orig);
X- 			*sp++ = ']';
X- 		}
X- 		else
X- 			*sp++ = *orig;
X- 	}
X- 	*sp = '\0';
X- 	return new;
X- }
X- 
X- /*
X-  * find_matches:
X-  *	Find all the fortunes which match the pattern we've been given.
X-  */
X- find_matches()
X- {
X- 	register char		*sp;
X- 	register char		*fortune;
X- 	register int		found_one;
X- 	register int		i;
X- 	register int		start, end;
X- 
X- 	if (Oflag || Aflag)
X- 		end = Tbl.str_numstr;
X- 	else
X- 		end = Tbl.str_delims[0];
X- 	if (Oflag) {
X- 		start = Tbl.str_delims[0];
X- 		(void) fseek(Inf, Tbl.str_dpos[0], 0);
X- 	}
X- 	else {
X- 		start = 0;
X- 		(void) fseek(Inf,
X- 			     (off_t) (sizeof Tbl +
X- 				      sizeof Seekpts[0] * (Tbl.str_numstr + 1)),
X- 			     0);
X- 	}
X- 
X- 	if ((fortune = malloc(Tbl.str_longlen + 1)) == NULL) {
X- 		perror("malloc");
X- 		exit(1);
X- 	}
X- 	found_one = FALSE;
X- 	for (i = start; i < end; i++) {
X- 		sp = fortune;
X- 		while ((*sp++ = getc(Inf)) != '\0')
X- 			continue;
X- 		if (RE_EXEC(fortune)) {
X- 			if (found_one)
X- 				printf("%%%%\n");
X- 			(void) fwrite(fortune, 1, sp - fortune, stdout);
X- 			found_one = TRUE;
X- 		}
X- 	}
X- 	if (found_one)
X- 		exit(0);
X- 	else
X- 		exit(1);
X- 	/* NOTREACHED */
X- }
X- # endif	NO_REGEX
X
X--- 327,329 -----
X  {
X  	return (i >= j ? i : j);
X  }
END_OF_v7fortun.dif
if test 9473 -ne `wc -c <v7fortun.dif`; then
    echo shar: \"v7fortun.dif\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f v7strfl_h.dif -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"v7strfl_h.dif\"
else
echo shar: Extracting \"v7strfl_h.dif\" \(503 characters\)
sed "s/^X//" >v7strfl_h.dif <<'END_OF_v7strfl_h.dif'
X*** net/strfile.h      Tue Jun 16 21:37:20 1987
X--- strfile.h    Sun Jun  7 00:02:05 1987
X***************
X*** 3,8
X  
X  # define	__STRFILE__
X  
X  # include	<sys/types.h>
X  
X  # define	MAXDELIMS	3
X
X--- 3,9 -----
X  
X  # define	__STRFILE__
X  
X+ #ifndef major(x)
X  # include	<sys/types.h>
X  #endif
X  
X***************
X*** 4,9
X  # define	__STRFILE__
X  
X  # include	<sys/types.h>
X  
X  # define	MAXDELIMS	3
X  
X
X--- 5,11 -----
X  
X  #ifndef major(x)
X  # include	<sys/types.h>
X+ #endif
X  
X  # define	MAXDELIMS	3
X  
END_OF_v7strfl_h.dif
if test 503 -ne `wc -c <v7strfl_h.dif`; then
    echo shar: \"v7strfl_h.dif\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0