7
char *index = "#9/lib/fortunes.index";
8
char *fortunes = "#9/lib/fortunes";
11
main(int argc, char *argv[])
17
int newindex, oldindex;
22
index = unsharp(index);
23
fortunes = unsharp(fortunes);
28
if((f=Bopen(argc>1?argv[1]:fortunes, OREAD)) == 0){
29
print("Misfortune!\n");
34
ix = open(index, OREAD);
38
fbuf = dirfstat(Bfildes(f));
39
if(ixbuf == nil || fbuf == nil){
40
print("Misfortune?\n");
43
if(fbuf->mtime > ixbuf->mtime){
44
nix = create(index, OWRITE, 0666);
53
ix = create(index, OWRITE, 0666);
60
seek(ix, lrand()%(ixbuf->length/sizeof(offs))*sizeof(offs), 0);
61
read(ix, off, sizeof(off));
62
Bseek(f, off[0]|(off[1]<<8)|(off[2]<<16)|(off[3]<<24), 0);
68
strcpy(choice, "Misfortune!");
84
Bwrite(&g, off, sizeof(off));
90
print("%s\n", choice);