-/* $NetBSD: wizard.c,v 1.2 1995/03/21 12:05:15 cgd Exp $ */
+/* $NetBSD: wizard.c,v 1.10 1999/07/16 01:38:20 hubertf Exp $ */
/*-
* Copyright (c) 1991, 1993
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)wizard.c 8.1 (Berkeley) 6/2/93";
#else
-static char rcsid[] = "$NetBSD: wizard.c,v 1.2 1995/03/21 12:05:15 cgd Exp $";
+__RCSID("$NetBSD: wizard.c,v 1.10 1999/07/16 01:38:20 hubertf Exp $");
#endif
-#endif /* not lint */
+#endif /* not lint */
/* Re-coding of advent in C: privileged operations */
-# include "hdr.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+#include "hdr.h"
+#include "extern.h"
-datime(d,t)
-int *d,*t;
-{ int tvec[2],*tptr;
- int *localtime();
-
- time(tvec);
- tptr=localtime(tvec);
- *d=tptr[7]+365*(tptr[5]-77); /* day since 1977 (mod leap) */
- /* bug: this will overflow in the year 2066 AD */
+void
+datime(d, t)
+ int *d, *t;
+{
+ time_t tvec;
+ struct tm *tptr;
+
+ time(&tvec);
+ tptr = localtime(&tvec);
+ /* day since 1977 (mod leap) */
+ *d = (tptr->tm_yday + 365 * (tptr->tm_year - 77)
+ + (tptr->tm_year - 77) / 4 - (tptr->tm_year - 1) / 100
+ + (tptr->tm_year + 299) / 400);
+ /* bug: this will overflow in the year 2066 AD (with 16 bit int) */
/* it will be attributed to Wm the C's millenial celebration */
- *t=tptr[2]*60+tptr[1]; /* and minutes since midnite */
-} /* pretty painless */
+ /* and minutes since midnite */
+ *t = tptr->tm_hour * 60 + tptr->tm_min;
+} /* pretty painless */
-char magic[6];
+char magic[6];
+void
poof()
{
- strcpy(magic, DECR(d,w,a,r,f));
+ strcpy(magic, DECR('d', 'w', 'a', 'r', 'f'));
latncy = 45;
}
-Start(n)
-{ int d,t,delay;
+int
+Start()
+{
+ int d, t, delay;
- datime(&d,&t);
- delay=(d-saved)*1440+(t-savet); /* good for about a month */
+ datime(&d, &t);
+ delay = (d - saveday) * 1440 + (t - savet); /* good for about a
+ * month */
- if (delay >= latncy)
- { saved = -1;
- return(FALSE);
+ if (delay >= latncy) {
+ saved = -1;
+ return (FALSE);
}
printf("This adventure was suspended a mere %d minute%s ago.",
- delay, delay == 1? "" : "s");
- if (delay <= latncy/3)
- { mspeak(2);
+ delay, delay == 1 ? "" : "s");
+ if (delay <= latncy / 3) {
+ mspeak(2);
exit(0);
}
mspeak(8);
- if (!wizard())
- { mspeak(9);
+ if (!wizard()) {
+ mspeak(9);
exit(0);
}
saved = -1;
- return(FALSE);
+ return (FALSE);
}
-wizard() /* not as complex as advent/10 (for now) */
-{ register int wiz;
- char *word,*x;
- if (!yesm(16,0,7)) return(FALSE);
+int
+wizard()
+{ /* not as complex as advent/10 (for now) */
+ char *word, *x;
+ if (!yesm(16, 0, 7))
+ return (FALSE);
mspeak(17);
- getin(&word,&x);
- if (!weq(word,magic))
- { mspeak(20);
- return(FALSE);
+ getin(&word, &x);
+ if (!weq(word, magic)) {
+ mspeak(20);
+ return (FALSE);
}
mspeak(19);
- return(TRUE);
+ return (TRUE);
}
-ciao(cmdfile)
-char *cmdfile;
-{ register char *c;
- register int outfd, size;
- char fname[80], buf[512];
- extern unsigned filesize;
+void
+ciao()
+{
+ char *c;
+ char fname[80];
printf("What would you like to call the saved version?\n");
- for (c=fname;; c++)
- if ((*c=getchar())=='\n') break;
- *c=0;
- if (save(fname) != 0) return; /* Save failed */
+ /* XXX - should use fgetln to avoid arbitrary limit */
+ for (c = fname; c < fname + sizeof fname - 1; c++) {
+ int ch;
+ ch = getchar();
+ if (ch == '\n' || ch == EOF)
+ break;
+ *c = ch;
+ }
+ *c = 0;
+ if (save(fname) != 0)
+ return; /* Save failed */
printf("To resume, say \"adventure %s\".\n", fname);
printf("\"With these rooms I might now have been familiarly acquainted.\"\n");
exit(0);
}
+int
ran(range)
-int range;
+ int range;
{
- long rand(), i;
+ long i;
i = rand() % range;
- return(i);
+ return (i);
}