Added save-restore prompt option to x11 interface with restriction to .aux.
authorDavid Griffith <dave@661.org>
Sat, 29 Apr 2023 04:31:28 +0000 (21:31 -0700)
committerDavid Griffith <dave@661.org>
Sat, 29 Apr 2023 05:50:45 +0000 (22:50 -0700)
src/x11/x_init.c
src/x11/x_input.c
src/x11/x_text.c

index a75559a845d9d8bb8b29d6e15b99e6819cd35cdb..fdbbb3a2546bdcf51c98d3ed6088d5ee3408926b 100644 (file)
@@ -56,6 +56,34 @@ static void print_c_string(const char *s)
 } /* 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);
+
+       style = os_get_text_style();
+       os_beep(BEEP_HIGH);
+       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_fatal
  *
index 44f48aa4464176d882f817714a48a4d44c770272..ea53910fca1b1447f16b1b2426da51e93a75d4c4 100644 (file)
@@ -241,12 +241,13 @@ char *os_read_file_name(const char *default_name, int flag)
        int saved_record = ostream_record;
        char file_name[FILENAME_MAX + 1];
        zchar answer[4];
+       char *ext;
 
        /* Turn off playback and recording temporarily */
        istream_replay = 0;
        ostream_record = 0;
 
-       if (f_setup.restore_mode) {
+       if (f_setup.restore_mode || flag == FILE_NO_PROMPT) {
                file_name[0] = 0;
        } else {
                print_string("Enter a file name.\nDefault is \"");
@@ -260,6 +261,14 @@ char *os_read_file_name(const char *default_name, int flag)
        if (file_name[0] == 0)
                strcpy(file_name, default_name);
 
+       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;
+               }
+       }
+
        /* Warn if overwriting a file. */
        if ((flag == FILE_SAVE || flag == FILE_SAVE_AUX ||
            flag == FILE_RECORD || flag == FILE_SCRIPT)
index fc0589ab2b323db1aa0da1ee22482ab10a48d66b..c2b5958ca5e33673318f191b805faa452dbc332d 100644 (file)
@@ -258,6 +258,25 @@ const XFontStruct *get_font(int font, int style)
        return font_info_cache[style];
 }
 
+static int current_zfont = TEXT_FONT;
+static int current_style = 0;
+
+/*
+ * 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
@@ -270,9 +289,6 @@ const XFontStruct *get_font(int font, int style)
  *     FIXED_WIDTH_STYLE
  *
  */
-static int current_zfont = TEXT_FONT;
-static int current_style = 0;
-
 void os_set_text_style(int new_style)
 {
        if (new_style & REVERSE_STYLE)