Added save-restore prompt option to dumb interface with restriction to .aux.
authorDavid Griffith <dave@661.org>
Wed, 3 May 2023 04:28:58 +0000 (21:28 -0700)
committerDavid Griffith <dave@661.org>
Thu, 4 May 2023 06:13:15 +0000 (23:13 -0700)
src/dumb/dinit.c
src/dumb/dinput.c
src/dumb/doutput.c

index 2a9cd4c603775eb59f2c5c78e0b9374e637a36f6..e6b7faba21d7b27451d28f8e0d0a1dcaee548efd 100644 (file)
@@ -19,6 +19,8 @@
  * Or visit http://www.fsf.org/
  */
 
+#include <stdarg.h>
+
 #include "dfrotz.h"
 #include "dblorb.h"
 
@@ -315,6 +317,37 @@ void os_quit(int status)
 void os_restart_game (int UNUSED (stage)) {}
 
 
+/*
+ * os_warn
+ *
+ * Display a warning message and continue with the game.
+ *
+ */
+void os_warn (const char *s, ...)
+{
+       va_list m;
+       int style;
+
+       os_beep(BEEP_HIGH);
+       style = os_get_text_style();
+       os_set_text_style(BOLDFACE_STYLE);
+       fprintf(stderr, "Warning: ");
+       os_set_text_style(NORMAL_STYLE);
+       va_start(m, s);
+       vfprintf(stderr, s, m);
+       va_end(m);
+       fprintf(stderr, "\n");
+       os_set_text_style(style);
+       return;
+}
+
+
+/*
+ * os_fatal
+ *
+ * Display error message and exit program.
+ *
+ */
 void os_fatal (const char *s, ...)
 {
        fprintf(stderr, "\nFatal error: %s\n", s);
@@ -322,7 +355,7 @@ void os_fatal (const char *s, ...)
                fprintf(stderr, "Continuing anyway...\n");
        else
                os_quit(EXIT_FAILURE);
-}
+} /* os_fatal */
 
 
 FILE *os_load_story(void)
index 3f405ecabab8daab87ae95fca7e5df467eeadc44..9018117bcce619de8ce5251383ce4b50478cfe75 100644 (file)
@@ -529,6 +529,7 @@ char *os_read_file_name (const char *default_name, int flag)
        char *tempname;
        char path_separator[2];
        int i;
+       char *ext;
 
        path_separator[0] = PATH_SEPARATOR;
        path_separator[1] = 0;
@@ -538,6 +539,13 @@ char *os_read_file_name (const char *default_name, int flag)
         */
        if (f_setup.restore_mode) {
                return strdup(default_name);
+       } else if (flag == FILE_NO_PROMPT) {
+               ext = strrchr(default_name, '.');
+               if (strncmp(ext, EXT_AUX, 4)) {
+                       os_warn("Blocked unprompted access of %s. Should only be %s files.", default_name, EXT_AUX);
+                       return NULL;
+               }
+               buf = strndup(default_name, MAX_FILE_NAME);
        } else {
                if (f_setup.restricted_path) {
                        for (i = strlen(default_name); i > 0; i--) {
@@ -561,10 +569,10 @@ char *os_read_file_name (const char *default_name, int flag)
                }
        }
 
-       if (buf[0])
-               strncpy(file_name, fullpath, FILENAME_MAX);
-       else
+       if (buf == NULL || flag == FILE_NO_PROMPT)
                strncpy(file_name, default_name, FILENAME_MAX);
+       else
+               strncpy(file_name, fullpath, FILENAME_MAX);
 
        /* Check if we're restricted to one directory. */
        if (f_setup.restricted_path != NULL) {
index 7a25b0bb229d91e699e19e1c378e2a36de58c922..f8214b288b2d554774e395e18b90859914b1c55b 100644 (file)
@@ -718,6 +718,34 @@ bool os_repaint_window(int UNUSED(win), int UNUSED(ypos_old),
 }
 
 
+/*
+ * 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_set_text_style
+ *
+ * Set the current text style.  Following flags can be set:
+ *
+ *     REVERSE_STYLE
+ *     BOLDFACE_STYLE
+ *     EMPHASIS_STYLE (aka underline aka italics)
+ *     FIXED_WIDTH_STYLE
+ *
+ */
 void os_set_text_style(int x)
 {
        current_style = x;