Abolish a silly layer of macros.
[open-adventure.git] / misc.c
diff --git a/misc.c b/misc.c
index e005d8138d470dd05c227a641e20591dffe3150c..39fafd2e6bfb61276646920a057efd9025f5b371 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -3,9 +3,10 @@
 #include <stdio.h>
 #include <string.h>
 #include <sys/time.h>
+
 #include "advent.h"
-#include "funcs.h"
 #include "database.h"
+#include "linenoise/linenoise.h"
 
 /* hack to ignore GCC Unused Result */
 #define IGNORE(r) do{if (r){}}while(0)
@@ -31,7 +32,7 @@ void SPEAK(vocab_t msg)
        LNPOSN=1;
        state=0;
        for (i = msg; i <= nxt; i++) {
-           PUTTXT(LINES[i],state,2);
+           PUTTXT(LINES[i],&state,2);
        }
        LNPOSN=0;
        ++LNPOSN;
@@ -68,7 +69,7 @@ void SPEAK(vocab_t msg)
                while (PARMS[nparms] > 0) {
                    if (PARMS[nparms+1] < 0)
                        casemake=0;
-                   PUTTXT(PARMS[nparms],state,casemake);
+                   PUTTXT(PARMS[nparms],&state,casemake);
                    nparms=nparms+1;
                }
                ++nparms;
@@ -95,8 +96,8 @@ void SPEAK(vocab_t msg)
                if (prmtyp == 33)
                    casemake=0;
                i = LNPOSN;
-               PUTTXT(PARMS[nparms],state,casemake);
-               PUTTXT(PARMS[nparms+1],state,casemake);
+               PUTTXT(PARMS[nparms],&state,casemake);
+               PUTTXT(PARMS[nparms+1],&state,casemake);
                if (prmtyp == 13 && INLINE[i] >= 37 && INLINE[i] <= 62)
                    INLINE[i] -= 26;
                nparms += 2;
@@ -175,7 +176,7 @@ void SETPRM(long first, long p1, long p2)
     }
 }
 
-bool fGETIN(FILE *input, 
+bool GETIN(FILE *input,
            long *pword1, long *pword1x, 
            long *pword2, long *pword2x) 
 /*  Get a command from the adventurer.  Snarf out the first word, pad it with
@@ -220,7 +221,7 @@ long YES(FILE *input, vocab_t x, vocab_t y, vocab_t z)
 
     for (;;) {
        RSPEAK(x);
-       GETIN(input, reply,junk1,junk2,junk3);
+       GETIN(input, &reply, &junk1, &junk2, &junk3);
        if (reply == MAKEWD(250519) || reply == MAKEWD(25)) {
            RSPEAK(y);
            return true;
@@ -305,7 +306,7 @@ token_t MAKEWD(long letters)
     return word;
 }
 
-void fPUTTXT(token_t word, long *state, long casemake)
+void PUTTXT(token_t word, long *state, long casemake)
 /*  Unpack the 30-bit value in word to obtain up to TOKLEN (currently
  *  5) integer-encoded chars, and store them in inline starting at
  *  LNPOSN.  If LNLENG>=LNPOSN, shift existing characters to the right
@@ -605,7 +606,7 @@ long ATDWRF(long where)
 long SETBIT(long bit)
 /*  Returns 2**bit for use in constructing bit-masks. */
 {
-    return(2 << bit);
+    return(1 << bit);
 }
 
 bool TSTBIT(long mask, int bit)
@@ -819,8 +820,8 @@ void fSAVEIO(long op, long in, long arr[])
  *  automatically.  Finishing reading can be a no-op as long as a subsequent
  *  SAVEIO(0,false,X) will still work.) */
 {
-    static FILE *fp = NULL; 
-    char name[50];
+    static FILE *fp = NULL;
+    char* name;
 
     switch (op < 0 ? -1 : (op > 0 ? 1 : 0)) 
     { 
@@ -829,12 +830,12 @@ void fSAVEIO(long op, long in, long arr[])
        break;
     case 0:
        while (fp == NULL) {
-           printf("\nFile name: ");
-           IGNORE(fgets(name, sizeof(name), stdin));
+           name = linenoise("File name: ");
            fp = fopen(name,(in ? READ_MODE : WRITE_MODE));
            if (fp == NULL)
                printf("Can't open file %s, try again.\n", name); 
        }
+       linenoiseFree(name);
        break;
     case 1: 
        if (in)