extern void score(enum termination);
extern int suspend(FILE *);
extern int resume(FILE *);
+extern int restore(FILE *);
/*
* MOD(N,M) = Arithmetic modulus
URN, VASE, VEND, VOLCAN, WATER;
long WD1, WD1X, WD2, WD2X;
-FILE *logfp;
+FILE *logfp = NULL, *rfp = NULL;
bool oldstyle = false;
bool editline = true;
bool prompt = true;
void sig_handler(int signo)
{
- if (signo == SIGINT)
+ if (signo == SIGINT){
if (logfp != NULL)
fflush(logfp);
+ }
exit(0);
}
/* Options. */
- while ((ch = getopt(argc, argv, "l:os")) != EOF) {
+ while ((ch = getopt(argc, argv, "l:or:s")) != EOF) {
switch (ch) {
case 'l':
logfp = fopen(optarg, "w");
oldstyle = true;
editline = prompt = false;
break;
+ case 'r':
+ rfp = fopen(optarg, "r");
+ if (rfp == NULL)
+ fprintf(stderr,
+ "advent: can't open save file %s for read\n",
+ optarg);
+ signal(SIGINT, sig_handler);
+ break;
case 's':
editline = false;
break;
/* Start-up, dwarf stuff */
game.zzword=RNDVOC(3,0);
- game.novice=YES(stdin, WELCOME_YOU,CAVE_NEARBY,NO_MESSAGE);
game.newloc = LOC_START;
game.loc = LOC_START;
game.limit=330;
- if (game.novice)game.limit=1000;
+ if (!rfp){
+ game.novice=YES(stdin, WELCOME_YOU,CAVE_NEARBY,NO_MESSAGE);
+ if (game.novice)game.limit=1000;
+ } else {
+ restore(rfp);
+ }
if (logfp)
fprintf(logfp, "seed %ld\n", seedval);
checksumming have been discarded - it's pointless to try
tamper-proofing saves when everyone has the source code.
+A -r command-line option has been added. It is functionally equivalent
+to RESTORE command, but faster.
+
== Translation ==
The 2.5 code was a mechanical C translation of a FORTRAN original.