projects
/
open-adventure.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Flush log on interrupt, just for convenience.
[open-adventure.git]
/
main.c
diff --git
a/main.c
b/main.c
index 430f763501429f46e3a8c57a841b6623648d0778..7834084eac3ed27472688c23bade12ac7475eafc 100644
(file)
--- a/
main.c
+++ b/
main.c
@@
-7,6
+7,7
@@
#include <stdio.h>
#include <stdbool.h>
#include <getopt.h>
#include <stdio.h>
#include <stdbool.h>
#include <getopt.h>
+#include <signal.h>
#include "main.h"
#include "misc.h"
#include "main.h"
#include "misc.h"
@@
-48,6
+49,14
@@
extern void initialise();
extern void score(long);
extern int action(FILE *, long);
extern void score(long);
extern int action(FILE *, long);
+void sig_handler(int signo)
+{
+ if (signo == SIGINT)
+ if (logfp != NULL)
+ fflush(logfp);
+ exit(0);
+}
+
/*
* MAIN PROGRAM
*/
/*
* MAIN PROGRAM
*/
@@
-75,6
+84,7
@@
int main(int argc, char *argv[]) {
fprintf(stderr,
"advent: can't open logfile %s for write\n",
optarg);
fprintf(stderr,
"advent: can't open logfile %s for write\n",
optarg);
+ signal(SIGINT, sig_handler);
break;
case 'o':
oldstyle = true;
break;
case 'o':
oldstyle = true;
@@
-99,7
+109,8
@@
int main(int argc, char *argv[]) {
lcgstate.a = 1093;
lcgstate.c = 221587;
lcgstate.m = 1048576;
lcgstate.a = 1093;
lcgstate.c = 221587;
lcgstate.m = 1048576;
- set_seed((long)time(NULL));
+ long seedval = (long)time(NULL);
+ set_seed(seedval);
/* Read the database if we have not yet done so */
/* Read the database if we have not yet done so */
@@
-132,6
+143,9
@@
L1: SETUP= -1;
LIMIT=330;
if(NOVICE)LIMIT=1000;
LIMIT=330;
if(NOVICE)LIMIT=1000;
+ if (logfp)
+ fprintf(logfp, "seed %ld\n", seedval);
+
for (;;) {
if (!do_command(stdin))
break;
for (;;) {
if (!do_command(stdin))
break;
@@
-142,7
+156,12
@@
L1: SETUP= -1;
static bool fallback_handler(signed char *buf)
/* fallback handler for commands not handled by FORTRANish parser */
{
static bool fallback_handler(signed char *buf)
/* fallback handler for commands not handled by FORTRANish parser */
{
- printf("Fallback handler sees: %s\n", buf);
+ long sv;
+ if (sscanf(buf, "seed %ld", &sv) == 1) {
+ set_seed(sv);
+ printf("Seed set to %ld\n", sv);
+ return true;
+ }
return false;
}
return false;
}