|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T v
Length: 9473 (0x2501)
Types: TextFile
Names: »v7fortun.dif«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/General/Fortune/v7fortun.dif«
*** net/fortune.c Sun Jun 7 18:00:43 1987
--- fortune.c Tue Jun 16 20:59:56 1987
***************
*** 2,7
# include <sys/types.h>
# include <stdio.h>
# include <sys/file.h>
# include <sys/stat.h>
# include "strfile.h"
--- 2,8 -----
# include <sys/types.h>
# include <stdio.h>
+ # ifndef VENIX
# include <sys/file.h>
# endif
# include <sys/stat.h>
***************
*** 3,8
# include <sys/types.h>
# include <stdio.h>
# include <sys/file.h>
# include <sys/stat.h>
# include "strfile.h"
--- 4,10 -----
# include <stdio.h>
# ifndef VENIX
# include <sys/file.h>
+ # endif
# include <sys/stat.h>
# include "strfile.h"
***************
*** 18,23
# define CPERS 20 /* # of chars for each sec */
# define SLEN 160 /* # of chars in short fortune */
# define FORTFILE "/usr/games/lib/fortunes.dat"
bool Wflag = FALSE; /* wait desired after fortune */
--- 20,31 -----
# define CPERS 20 /* # of chars for each sec */
# define SLEN 160 /* # of chars in short fortune */
+ # ifdef VENIX
+ # define TBLFILE "/usr/games/lib/Tbl.dat"
+ char *Tblfile = TBLFILE; /* header information*/
+ FILE *Tabl;
+ # endif
+
# define FORTFILE "/usr/games/lib/fortunes.dat"
bool Wflag = FALSE; /* wait desired after fortune */
***************
*** 31,37
char *Fortfile = FORTFILE, /* fortune database */
*Usage[] = {
- # ifdef NO_REGEX
"usage: fortune [ - ] [ -wsloa ] [ file ]",
# else
"usage: fortune [ - ] [ -wsloai ] [ -m pattern ] [ file ]",
--- 39,44 -----
char *Fortfile = FORTFILE, /* fortune database */
*Usage[] = {
"usage: fortune [ - ] [ -wsloa ] [ file ]",
" - - give this summary of usage",
" w - have program wait after printing message in order",
***************
*** 33,41
*Usage[] = {
# ifdef NO_REGEX
"usage: fortune [ - ] [ -wsloa ] [ file ]",
- # else
- "usage: fortune [ - ] [ -wsloai ] [ -m pattern ] [ file ]",
- # endif
" - - give this summary of usage",
" w - have program wait after printing message in order",
" to give time to read",
--- 40,45 -----
char *Fortfile = FORTFILE, /* fortune database */
*Usage[] = {
"usage: fortune [ - ] [ -wsloa ] [ file ]",
" - - give this summary of usage",
" w - have program wait after printing message in order",
" to give time to read",
***************
*** 43,52
" l - long fortunes only",
" o - offensive fortunes only",
" a - any fortune, regular or offensive",
- # ifndef NO_REGEX
- " m - print fortunes which match a pattern",
- " i - ignore case in matching patterns",
- # endif
" Mail suggested fortunes to \"fortune@ucbvax.berkeley.edu\"",
NULL
};
--- 47,52 -----
" l - long fortunes only",
" o - offensive fortunes only",
" a - any fortune, regular or offensive",
" Mail suggested fortunes to \"fortune@ucbvax.berkeley.edu\"",
NULL
};
***************
*** 59,85
char *malloc();
- # ifndef NO_REGEX
- char *conv_pat();
- # endif
-
- # ifndef NO_REGX
- # ifdef REGCMP
- # define RE_COMP(p) (Re_pat = regcmp(p, NULL))
- # define BAD_COMP(f) ((f) == NULL)
- # define RE_EXEC(p) regex(Re_pat, (p))
- char *Re_pat,
- *regcmp(),
- *regex();
- # else
- # define RE_COMP(p) (p = re_comp(p))
- # define BAD_COMP(f) ((f) != NULL)
- # define RE_EXEC(p) re_exec(p)
- char *re_comp(),
- *re_exec();
- # endif REGCMP
- # endif NO_REGX
-
time_t time();
main(ac, av)
--- 59,64 -----
char *malloc();
time_t time();
main(ac, av)
***************
*** 90,95
register int nchar = 0;
getargs(ac, av);
if ((Inf = fopen(Fortfile, "r+")) == NULL) {
perror(Fortfile);
exit(-1);
--- 69,77 -----
register int nchar = 0;
getargs(ac, av);
+ # ifdef VENIX
+ if ((Inf = fopen(Fortfile, "r")) == NULL) {
+ # else
if ((Inf = fopen(Fortfile, "r+")) == NULL) {
# endif
perror(Fortfile);
***************
*** 91,96
getargs(ac, av);
if ((Inf = fopen(Fortfile, "r+")) == NULL) {
perror(Fortfile);
exit(-1);
}
--- 73,79 -----
if ((Inf = fopen(Fortfile, "r")) == NULL) {
# else
if ((Inf = fopen(Fortfile, "r+")) == NULL) {
+ # endif
perror(Fortfile);
exit(-1);
}
***************
*** 94,102
perror(Fortfile);
exit(-1);
}
! if (fread((char *) &Tbl, sizeof Tbl, 1, Inf) != 1) { /* NOSTRICT */
! fprintf(stderr, "fortune file is truncated\n");
! exit(-1);
}
if (Tbl.str_longlen <= SLEN && Lflag) {
fprintf(stderr, "Sorry, no long strings in this file\n");
--- 77,92 -----
perror(Fortfile);
exit(-1);
}
! if ((Tabl = fopen(Tblfile, "r"))) {
! if (fread((char *) &Tbl, sizeof Tbl, 1, Tabl) != 1) { /* NOSTRICT */
! fprintf(stderr, "fortune file is truncated\n");
! exit(-1);
! }
! } else {
! if (fread((char *) &Tbl, sizeof Tbl, 1, Inf) != 1) { /* NOSTRICT */
! fprintf(stderr, "fortune file is truncated\n");
! exit(-1);
! }
}
if (Tbl.str_longlen <= SLEN && Lflag) {
fprintf(stderr, "Sorry, no long strings in this file\n");
***************
*** 113,124
if (Tbl.str_delims[2] == 0)
Tbl.str_delims[2] = Tbl.str_delims[0];
- # ifndef NO_REGEX
- if (Mflag) {
- find_matches();
- /* NOTREACHED */
- }
- # endif
do {
getfort();
--- 103,108 -----
if (Tbl.str_delims[2] == 0)
Tbl.str_delims[2] = Tbl.str_delims[0];
do {
getfort();
***************
*** 130,135
putchar(c);
}
(void) fflush(stdout);
(void) fseek(Inf, 0L, 0);
# ifdef LOCK_EX
/*
--- 114,123 -----
putchar(c);
}
(void) fflush(stdout);
+ # ifdef VENIX
+ (void) fclose(Inf);
+ (void) fclose(Tabl);
+ # else
(void) fseek(Inf, 0L, 0);
# endif
# ifdef LOCK_EX
***************
*** 131,136
}
(void) fflush(stdout);
(void) fseek(Inf, 0L, 0);
# ifdef LOCK_EX
/*
* if we can, we exclusive lock, but since it isn't very
--- 119,125 -----
(void) fclose(Tabl);
# else
(void) fseek(Inf, 0L, 0);
+ # endif
# ifdef LOCK_EX
/*
* if we can, we exclusive lock, but since it isn't very
***************
*** 139,145
*/
(void) flock(fileno(Inf), LOCK_EX);
# endif LOCK_EX
! if (fwrite((char *) &Tbl, 1, sizeof Tbl, Inf) != sizeof Tbl)
fprintf(stderr, "can't update fortune data file\n");
# ifdef LOCK_EX
(void) flock(fileno(Inf), LOCK_UN);
--- 128,144 -----
*/
(void) flock(fileno(Inf), LOCK_EX);
# endif LOCK_EX
! # ifdef VENIX
! if ((Tabl = fopen(Tblfile, "w")) == NULL) {
! perror(Tblfile);
! exit(-1);
! }
! # endif
! # ifdef VENIX
! if (fwrite((char *) &Tbl, 1, sizeof Tbl, Tabl) != sizeof Tbl)
! # else
! if (fwrite((char *) &Tbl, 1, sizeof Tbl, Inf) != sizeof Tbl)
! # endif
fprintf(stderr, "can't update fortune data file\n");
# ifdef LOCK_EX
(void) flock(fileno(Inf), LOCK_UN);
***************
*** 278,298
}
}
- # ifndef NO_REGEX
- if (pat != NULL) {
- if (ignore_case)
- pat = conv_pat(pat);
- if (BAD_COMP(RE_COMP(pat))) {
- # ifndef REGCMP
- fprintf(stderr, "%s\n", pat);
- # else
- fprintf(stderr, "bad pattern: %s\n", pat);
- # endif
- bad++;
- }
- }
- # endif NO_REGEX
-
if (bad) {
printf("use \"%s -\" to get usage\n", av[0]);
exit(-1);
--- 277,282 -----
}
}
if (bad) {
printf("use \"%s -\" to get usage\n", av[0]);
exit(-1);
***************
*** 343,441
{
return (i >= j ? i : j);
}
-
- # ifndef NO_REGEX
- /*
- * conv_pat:
- * Convert the pattern to an ignore-case equivalent.
- */
- char *
- conv_pat(orig)
- register char *orig;
- {
- register char *sp;
- register int cnt;
- register char *new;
-
- cnt = 1; /* allow for '\0' */
- for (sp = orig; *sp != '\0'; sp++)
- if (isalpha(*sp))
- cnt += 4;
- else
- cnt++;
- if ((new = malloc(cnt)) == NULL) {
- fprintf(stderr, "pattern too long for ignoring case\n");
- exit(1);
- }
-
- for (sp = new; *orig != '\0'; orig++) {
- if (islower(*orig)) {
- *sp++ = '[';
- *sp++ = *orig;
- *sp++ = toupper(*orig);
- *sp++ = ']';
- }
- else if (isupper(*orig)) {
- *sp++ = '[';
- *sp++ = *orig;
- *sp++ = tolower(*orig);
- *sp++ = ']';
- }
- else
- *sp++ = *orig;
- }
- *sp = '\0';
- return new;
- }
-
- /*
- * find_matches:
- * Find all the fortunes which match the pattern we've been given.
- */
- find_matches()
- {
- register char *sp;
- register char *fortune;
- register int found_one;
- register int i;
- register int start, end;
-
- if (Oflag || Aflag)
- end = Tbl.str_numstr;
- else
- end = Tbl.str_delims[0];
- if (Oflag) {
- start = Tbl.str_delims[0];
- (void) fseek(Inf, Tbl.str_dpos[0], 0);
- }
- else {
- start = 0;
- (void) fseek(Inf,
- (off_t) (sizeof Tbl +
- sizeof Seekpts[0] * (Tbl.str_numstr + 1)),
- 0);
- }
-
- if ((fortune = malloc(Tbl.str_longlen + 1)) == NULL) {
- perror("malloc");
- exit(1);
- }
- found_one = FALSE;
- for (i = start; i < end; i++) {
- sp = fortune;
- while ((*sp++ = getc(Inf)) != '\0')
- continue;
- if (RE_EXEC(fortune)) {
- if (found_one)
- printf("%%%%\n");
- (void) fwrite(fortune, 1, sp - fortune, stdout);
- found_one = TRUE;
- }
- }
- if (found_one)
- exit(0);
- else
- exit(1);
- /* NOTREACHED */
- }
- # endif NO_REGEX
--- 327,329 -----
{
return (i >= j ? i : j);
}