Fixed problem with garbage .aux filenames.
authorDavid Griffith <dave@661.org>
Fri, 1 Feb 2019 21:28:24 +0000 (13:28 -0800)
committerDavid Griffith <dave@661.org>
Fri, 1 Feb 2019 21:28:24 +0000 (13:28 -0800)
Applied patch found at
https://www.intfiction.org/forum/viewtopic.php?f=38&t=19767
I happened across it by chance, looking for proper responses to handling
.aux files.

src/common/fastmem.c
src/common/frotz.h
src/common/text.c

index 64ea183de948cde05606ec2365a4ce610e1b1910..576a60f7a4aef0ded4a32f213571e2ebbfc13571 100644 (file)
@@ -632,34 +632,20 @@ void z_restart (void)
  * copy it to a string.
  *
  */
+char *filename_decoded = 0;
+
 static void get_default_name (char *default_name, zword addr)
 {
-    if (addr != 0) {
-
-       zbyte len;
-       int i;
-
-       LOW_BYTE (addr, len);
-       addr++;
-
-       for (i = 0; i < len; i++) {
-
-           zbyte c;
-
-           LOW_BYTE (addr, c);
-           addr++;
-
-           if (c >= 'A' && c <= 'Z')
-               c += 'a' - 'A';
-
-           default_name[i] = c;
-
-       }
+    int i;
 
-       default_name[i] = 0;
+    if (addr != 0) {
+        memset (default_name, 0, MAX_FILE_NAME + 1);
+        filename_decoded = default_name;
+        decode_text (FILENAME, addr);
+        filename_decoded = 0;
 
        if (strchr (default_name, '.') == NULL)
-           strcpy (default_name + i, ".AUX");
+           strcpy (strchr (default_name, '\0'), EXT_AUX);
 
     } else strcpy (default_name, f_setup.aux_name);
 
@@ -671,7 +657,7 @@ static void get_default_name (char *default_name, zword addr)
  *
  *     zargs[0] = address of area to restore (optional)
  *     zargs[1] = number of bytes to restore
- *     zargs[2] = address of suggested file name
+ *     zargs[2] = packed address of suggested file name
  *
  */
 void z_restore (void)
@@ -911,7 +897,7 @@ void z_restore_undo (void)
  *
  *     zargs[0] = address of memory area to save (optional)
  *     zargs[1] = number of bytes to save
- *     zargs[2] = address of suggested file name
+ *     zargs[2] = packed address of suggested file name
  *
  */
 void z_save (void)
index 260b58dc3ae14f50acb516a73b031a411c07a657..682d1aed579698b05df134de2a11834d8022458b 100644 (file)
@@ -832,6 +832,15 @@ void       os_init_setup (void);
 void   os_warn (const char *, ...);
 void   os_quit (void);
 
+
+/*** text decoding API ***/
+enum string_type {
+    LOW_STRING, ABBREVIATION, HIGH_STRING, EMBEDDED_STRING, VOCABULARY, FILENAME
+};
+
+void decode_text (enum string_type st, zword addr);
+
+
 /**
  * Called regularly by the interpreter, at least every few instructions
  * (only when interpreting: e.g., not when waiting for input).
index 9784c39b5e881716073b92dad136fd58825d1d75..a02f621e0bdf8b1dbaab1cb68ed3ac8caf62688f 100644 (file)
 
 #include "frotz.h"
 
-enum string_type {
-    LOW_STRING, ABBREVIATION, HIGH_STRING, EMBEDDED_STRING, VOCABULARY
-};
-
 extern zword object_name (zword);
 
 static zchar decoded[10];
 static zword encoded[3];
+extern zchar *filename_decoded;
 
 /*
  * According to Matteo De Luigi <matteo.de.luigi@libero.it>,
@@ -369,12 +366,14 @@ void z_encode_text (void)
  *    HIGH_STRING - from the end of the memory map (packed address)
  *    EMBEDDED_STRING - from the instruction stream (at PC)
  *    VOCABULARY - from the dictionary (byte address)
+ *    FIlENAME - high string used as a filename, to be decoded instead of
+ *               printed out
  *
- * The last type is only used for word completion.
+ * The VOCABULARY type is only used for word completion.
  *
  */
-#define outchar(c)     if (st==VOCABULARY) *ptr++=c; else print_char(c)
-static void decode_text (enum string_type st, zword addr)
+#define outchar(c)     if (st==VOCABULARY||st==FILENAME) *ptr++=c; else print_char(c)
+void decode_text (enum string_type st, zword addr)
 {
     zchar *ptr;
     long byte_addr;
@@ -394,7 +393,7 @@ static void decode_text (enum string_type st, zword addr)
 
        byte_addr = (long) addr << 1;
 
-    else if (st == HIGH_STRING) {
+    else if (st == HIGH_STRING || st == FILENAME) {
 
        if (h_version <= V3)
            byte_addr = (long) addr << 1;
@@ -415,6 +414,9 @@ static void decode_text (enum string_type st, zword addr)
     if (st == VOCABULARY)
        ptr = decoded;
 
+    else if (st == FILENAME)
+        ptr = filename_decoded;
+
     do {
 
        int i;
@@ -424,7 +426,7 @@ static void decode_text (enum string_type st, zword addr)
        if (st == LOW_STRING || st == VOCABULARY) {
            LOW_WORD (addr, code)
            addr += 2;
-       } else if (st == HIGH_STRING || st == ABBREVIATION) {
+       } else if (st == HIGH_STRING || st == ABBREVIATION || st == FILENAME) {
            HIGH_WORD (byte_addr, code)
            byte_addr += 2;
        } else
@@ -510,7 +512,7 @@ static void decode_text (enum string_type st, zword addr)
 
     } while (!(code & 0x8000));
 
-    if (st == VOCABULARY)
+    if (st == VOCABULARY || st == FILENAME)
        *ptr = 0;
 
 }/* decode_text */