Implement fallback handler that looks at the raw command buffer.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 25 May 2017 22:21:38 +0000 (18:21 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 23 Mar 2023 15:28:53 +0000 (11:28 -0400)
main.c
main.h
misc.c

diff --git a/main.c b/main.c
index 616a57fcb8814dfc2cbc8314f8e470d2da39b6a2..1288540754b1a9ae173f22c754080b8bfdcc3799 100644 (file)
--- a/main.c
+++ b/main.c
@@ -16,7 +16,7 @@ long ABB[186], ATAB[331], ATLOC[186], BLKLIN = true, DFLAG,
                KTAB[331], *LINES, LINK[201], LNLENG, LNPOSN,
                PARMS[26], PLACE[101], PTEXT[101], RTEXT[278],
                SETUP = 0, TABSIZ = 330;
-signed char INLINE[LINESIZE+1], MAP1[129], MAP2[129];
+signed char rawbuf[LINESIZE], INLINE[LINESIZE+1], MAP1[129], MAP2[129];
 
 long ABBNUM, ACTSPK[36], AMBER, ATTACK, AXE, BACK, BATTER, BEAR, BIRD, BLOOD, BONUS,
                 BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST, CHLOC, CHLOC2,
@@ -137,8 +137,14 @@ L1:        SETUP= -1;
        }
 }
 
-static void do_command(FILE *cmdin) {
+static bool fallback_handler(signed char *buf)
+/* fallback handler for commands not handled by FORTRANish parser */
+{
+    printf("Fallback handler sees: %s\n", buf);
+    return false;
+}
 
+static void do_command(FILE *cmdin) {
 /*  Can't leave cave once it's closing (except by main office). */
 
 L2:    if(!OUTSID(NEWLOC) || NEWLOC == 0 || !CLOSNG) goto L71;
@@ -448,6 +454,8 @@ L2800:      WD1=WD2;
 /*  Gee, I don't understand. */
 
 L3000: SETPRM(1,WD1,WD1X);
+        if (fallback_handler(rawbuf))
+            return;
        RSPEAK(254);
         goto L2600;
 
diff --git a/main.h b/main.h
index a71b9e3ff113bce06f1915f1d36daf7e4a5acec3..184aceea0a17be1a0e727614318946042001e02a 100644 (file)
--- a/main.h
+++ b/main.h
@@ -10,7 +10,7 @@ typedef struct lcg_state
 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 signed char rawbuf[LINESIZE], INLINE[LINESIZE+1], MAP1[], MAP2[];
 extern FILE *logfp;
 extern bool oldstyle;
 extern lcg_state lcgstate;
diff --git a/misc.c b/misc.c
index 3bca47305d0c13fd8a39330aab154aa6f94e5a1d..b80d9b807e18917593d0727ca7da2fcd3d844428 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -1,6 +1,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 #include "main.h"
 #include "misc.h"
 #include "funcs.h"
@@ -885,7 +886,7 @@ long I, VAL;
        if (!oldstyle && OPENED == stdin)
                fputs("> ", stdout);
        do {
-               IGNORE(fgets(INLINE+1,sizeof(INLINE)-1,OPENED));
+               IGNORE(fgets(rawbuf,sizeof(INLINE)-1,OPENED));
        } while
                (!feof(OPENED) && INLINE[1] == '#');
        if (feof(OPENED)) {
@@ -893,11 +894,10 @@ long I, VAL;
                        fclose(logfp);
        } else {
                if (logfp && OPENED == stdin)
-                       IGNORE(fputs(INLINE+1, logfp));
-               else if (!isatty(0)) {
-                       IGNORE(fputs("> ", stdout));
-                       IGNORE(fputs(INLINE+1, stdout));
-               }
+                       IGNORE(fputs(rawbuf, logfp));
+               else if (!isatty(0))
+                       IGNORE(fputs(rawbuf, stdout));
+               strcpy(INLINE+1, rawbuf);
                LNLENG=0;
                for (I=1; I<=sizeof(INLINE) && INLINE[I]!=0; I++) {
                VAL=INLINE[I]+1;