diff --git a/src/common/fastmem.c b/src/common/fastmem.c index 75b042d..b11af74 100644 --- a/src/common/fastmem.c +++ b/src/common/fastmem.c @@ -639,34 +639,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'), ".AUX"); } else strcpy (default_name, f_setup.aux_name); @@ -678,7 +664,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) @@ -918,7 +904,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) diff --git a/src/common/frotz.h b/src/common/frotz.h index 1fa208b..3a3f03c 100644 --- a/src/common/frotz.h +++ b/src/common/frotz.h @@ -772,3 +772,10 @@ int os_string_width (const zchar *); void os_init_setup (void); int os_speech_output(const zchar *); +/*** text decoding API ***/ +enum string_type { + LOW_STRING, ABBREVIATION, HIGH_STRING, EMBEDDED_STRING, VOCABULARY, FILENAME +}; + +void decode_text (enum string_type st, zword addr); + diff --git a/src/common/text.c b/src/common/text.c index 9784c39..a02f621 100644 --- a/src/common/text.c +++ b/src/common/text.c @@ -20,14 +20,11 @@ #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 , @@ -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 */