Added save-restore prompt option to dos interface with restriction to .aux.
authorDavid Griffith <dave@661.org>
Sat, 29 Apr 2023 05:58:01 +0000 (22:58 -0700)
committerDavid Griffith <dave@661.org>
Sat, 29 Apr 2023 07:29:03 +0000 (00:29 -0700)
src/dos/dosinit.c
src/dos/dosinput.c
src/dos/dostext.c

index 130c66400032447d56e3689e06198707eb3d091d..465e01d51b2b28abba3f79ef45d7fc8097abb473 100644 (file)
@@ -22,6 +22,7 @@
 #include <conio.h>
 #include <dos.h>
 #include <stdio.h>
+#include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
 #include "frotz.h"
@@ -237,6 +238,44 @@ void os_quit(int status)
     exit(status);
 }
 
+
+static void print_c_string (const char *s)
+{
+       zchar c;
+
+       while ((c = *s++) != 0)
+               os_display_char (c);
+} /* print_c_string */
+
+
+/*
+ * os_warn
+ *
+ * Display a warning message and continue with the game.
+ *
+ */
+void os_warn (const char *s, ...)
+{
+       va_list m;
+       char errorstring[81];
+       int style;
+
+       va_start(m, s);
+       vsnprintf(errorstring, sizeof(char) * 80, s, m);
+       va_end(m);
+
+       os_beep(BEEP_HIGH);
+       style = os_get_text_style();
+       os_set_text_style(BOLDFACE_STYLE);
+       print_c_string("Warning: ");
+       os_set_text_style(NORMAL_STYLE);
+       print_c_string(errorstring);
+       new_line();
+       os_set_text_style(style);
+
+       return;
+} /* os_warn */
+
 /*
  * os_fatal
  *
index 2aba6043205ff95d52384060fee7d72caf113592..17c7fd0f350f10e2e94559788cce9a77a6979924 100644 (file)
@@ -889,6 +889,7 @@ char *os_read_file_name (const char *default_name, int flag)
        int i;
        char *tempname;
        char file_name[FILENAME_MAX + 1];
+       char *ext;
 
        /* Turn off playback and recording temporarily */
        istream_replay = FALSE;
@@ -904,14 +905,17 @@ char *os_read_file_name (const char *default_name, int flag)
        if (flag == FILE_RECORD || flag == FILE_PLAYBACK)
                extension = EXT_COMMAND;
 
-       /* Input file name (reserve four bytes for a file name extension) */
-       print_string("Enter file name (\"");
-       print_string(extension);
-       print_string("\" will be added).\nDefault is \"");
-       print_string(default_name);
-       print_string("\": ");
-
-       read_string(MAX_FILE_NAME - 4, (zchar *) file_name);
+       if (flag == FILE_NO_PROMPT) {
+               file_name[0] = 0;
+       } else {
+               /* Input file name (reserve four bytes for a file name extension) */
+               print_string("Enter file name (\"");
+               print_string(extension);
+               print_string("\" will be added).\nDefault is \"");
+               print_string(default_name);
+               print_string("\": ");
+               read_string(MAX_FILE_NAME - 4, (zchar *) file_name);
+       }
 
        /* Use the default name if nothing was typed */
        if (file_name[0] == 0)
@@ -935,6 +939,13 @@ char *os_read_file_name (const char *default_name, int flag)
                strcat(file_name, tempname);
        }
 
+       if (flag == FILE_NO_PROMPT) {
+               ext = strrchr(file_name, '.');
+               if (strncmp(ext, EXT_AUX, 4)) {
+                       os_warn("Blocked unprompted access of %s. Should only be %s files.", file_name, EXT_AUX);
+                        return NULL;
+               }
+       }
        /* Make sure it is safe to use this file name */
        result = TRUE;
 
index 527f12eef19a1b06ff0625da4758938b42562249..193048f63da3c5ee9d02a3f97b872820192b2798 100644 (file)
@@ -495,6 +495,23 @@ void os_set_colour(int new_foreground, int new_background)
 } /* os_set_colour */
 
 
+/*
+ * os_get_text_style
+ *
+ * Return the current text style.  Following flags can be set:
+ *
+ *     REVERSE_STYLE
+ *     BOLDFACE_STYLE
+ *     EMPHASIS_STYLE (aka underline aka italics)
+ *     FIXED_WIDTH_STYLE
+ *
+ */
+int os_get_text_style (void)
+{
+       return current_style;
+} /* os_get_text_style */
+
+
 /*
  * os_set_text_style
  *