From: David Griffith Date: Wed, 3 May 2023 04:28:58 +0000 (-0700) Subject: Added save-restore prompt option to dumb interface with restriction to .aux. X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=6c65ac8eef2e98e801dbc358e7068d834aa269a2;p=liskon_frotz.git Added save-restore prompt option to dumb interface with restriction to .aux. --- diff --git a/src/dumb/dinit.c b/src/dumb/dinit.c index 2a9cd4c..e6b7fab 100644 --- a/src/dumb/dinit.c +++ b/src/dumb/dinit.c @@ -19,6 +19,8 @@ * Or visit http://www.fsf.org/ */ +#include + #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) diff --git a/src/dumb/dinput.c b/src/dumb/dinput.c index 3f405ec..9018117 100644 --- a/src/dumb/dinput.c +++ b/src/dumb/dinput.c @@ -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) { diff --git a/src/dumb/doutput.c b/src/dumb/doutput.c index 7a25b0b..f8214b2 100644 --- a/src/dumb/doutput.c +++ b/src/dumb/doutput.c @@ -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;