Add -l option to enable command logging.

This commit is contained in:
Eric S. Raymond 2017-05-23 08:57:35 -04:00
parent 9bcbe342a4
commit 943b3a62e6
4 changed files with 28 additions and 3 deletions

View file

@ -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.

19
main.c
View file

@ -6,6 +6,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <getopt.h>
#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;

1
main.h
View file

@ -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;

7
misc.c
View file

@ -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;