From: David Griffith Date: Sat, 29 Apr 2023 04:31:28 +0000 (-0700) Subject: Added save-restore prompt option to x11 interface with restriction to .aux. X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=ad726c566901be001ec16ed47f225a799facea59;p=liskon_frotz.git Added save-restore prompt option to x11 interface with restriction to .aux. --- diff --git a/src/x11/x_init.c b/src/x11/x_init.c index a75559a..fdbbb3a 100644 --- a/src/x11/x_init.c +++ b/src/x11/x_init.c @@ -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 * diff --git a/src/x11/x_input.c b/src/x11/x_input.c index 44f48aa..ea53910 100644 --- a/src/x11/x_input.c +++ b/src/x11/x_input.c @@ -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) diff --git a/src/x11/x_text.c b/src/x11/x_text.c index fc0589a..c2b5958 100644 --- a/src/x11/x_text.c +++ b/src/x11/x_text.c @@ -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)