From 943b3a62e680e733ffe57552657d22ce148fed5f Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 23 May 2017 08:57:35 -0400 Subject: [PATCH] Add -l option to enable command logging. --- advent.txt | 4 ++++ main.c | 19 +++++++++++++++++-- main.h | 1 + misc.c | 7 ++++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/advent.txt b/advent.txt index f286e83..9b955aa 100644 --- a/advent.txt +++ b/advent.txt @@ -24,6 +24,10 @@ port of the 1976 ancestor of this game. To avoid a name collision, this game builds as 'advent', reflecting the fact that the PDP-10 on which it originally ran limited filenames to 6 characters. +== OPTIONS == + +-l:: Log commands to specified file. + == ENVIRONMENT VARIABLES == ADVENTURE:: Path to the text database file describing Colossal Cave. diff --git a/main.c b/main.c index 1cbf9e9..378c188 100644 --- a/main.c +++ b/main.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "main.h" #include "misc.h" @@ -39,6 +40,7 @@ long ABBNUM, ACTSPK[36], AMBER, ATTACK, AXE, BACK, BATTER, BEAR, BIRD, BLOOD, BO TRVSIZ = 885, TTEXT[6], TURNS, URN, V1, V2, VASE, VEND, VERB, VOLCAN, VRBSIZ = 35, VRSION = 25, WATER, WD1, WD1X, WD2, WD2X, WZDARK = false, ZZWORD; +FILE *logfp; extern void initialise(); extern void score(long); @@ -49,6 +51,7 @@ extern int action(long); */ int main(int argc, char *argv[]) { + int ch; /* Adventure (rev 2: 20 treasures) */ @@ -58,6 +61,20 @@ int main(int argc, char *argv[]) { * Errata fixed: 78/12/25 */ +/* Options. */ + + while ((ch = getopt(argc, argv, "l:")) != EOF) { + switch (ch) { + case 'l': + logfp = fopen(optarg, "w+"); + if (logfp == NULL) + fprintf(stderr, + "advent: can't open logfile %s for write\n", + optarg); + break; + } + } + /* Logical variables: * * CLOSED says whether we're all the way closed @@ -90,8 +107,6 @@ int main(int argc, char *argv[]) { RSPEAK(201); exit(0); - - /* Start-up, dwarf stuff */ L1: SETUP= -1; diff --git a/main.h b/main.h index 9dc7b3d..7a1d1c8 100644 --- a/main.h +++ b/main.h @@ -4,3 +4,4 @@ extern long ABB[], ATAB[], ATLOC[], BLKLIN, DFLAG, DLOC[], FIXED[], HOLDNG, KTAB[], *LINES, LINK[], LNLENG, LNPOSN, PARMS[], PLACE[], PTEXT[], RTEXT[], TABSIZ; extern signed char INLINE[LINESIZE+1], MAP1[], MAP2[]; +extern FILE *logfp; diff --git a/misc.c b/misc.c index 8f0a2b2..fafc15c 100644 --- a/misc.c +++ b/misc.c @@ -885,7 +885,12 @@ long I, VAL; if(MAP2[1] == 0)MPINIT(); IGNORE(fgets(INLINE+1,sizeof(INLINE)-1,OPENED)); - if (!feof(OPENED)) { + if (feof(OPENED)) { + if (logfp) + fclose(logfp); + } else { + if (logfp) + IGNORE(fputs(INLINE+1, logfp)); LNLENG=0; for (I=1; I<=sizeof(INLINE) && INLINE[I]!=0; I++) { VAL=INLINE[I]+1; -- 2.31.1