diff xrogue/options.c @ 137:443c8bd3e290

xrogue: restrict changes to the save file location. When using the -n option, disallow changing file_name or whoami via options or dialogs.
author John "Elwin" Edwards
date Sat, 02 May 2015 07:31:14 -0400
parents ce0cf824c192
children aac28331e71d
line wrap: on
line diff
--- a/xrogue/options.c	Wed Apr 22 16:03:00 2015 -0400
+++ b/xrogue/options.c	Sat May 02 07:31:14 2015 -0400
@@ -51,6 +51,9 @@
         put_quest(),
     get_default();
 
+int get_str_prot(char *opt, WINDOW *win);
+bool allowchange(OPTION *op);
+
 OPTION  optlist[] = {
     {"terse",   "Terse output: ",
                 (int *) &terse,         put_bool,       get_bool        },
@@ -67,11 +70,11 @@
     {"overlay", "Overlay menu: ",
                 (int *) &menu_overlay,  put_bool,       get_bool        },
     {"name",    "Name: ",
-                (int *) whoami,         put_str,        get_str         },
+                (int *) whoami,         put_str,        get_str_prot    },
     {"file",    "Save file: ",
-                (int *) file_name,      put_str,        get_str         },
+                (int *) file_name,      put_str,        get_str_prot    },
     {"score",   "Score file: ",
-                (int *) score_file,     put_str,        get_str         },
+                (int *) score_file,     put_str,        get_str_prot    },
     {"class",   "Character type: ",
                 (int *) &char_type,     put_abil,       get_abil        },
     {"quest",   "Quest item: ",
@@ -407,8 +410,10 @@
                     strucpy(start, str, (char *) sp - str);
 
                     /* Put the value into the option field */
-                    if (op->o_putfunc != put_abil) 
-                        strcpy((char *)op->o_opt, value);
+                    if (op->o_putfunc != put_abil) {
+                        if (allowchange(op))
+                            strcpy((char *)op->o_opt, value);
+                    }
 
                     else if (*op->o_opt == -1) { /* Only init ability once */
                         register int len = strlen(value);
@@ -500,3 +505,32 @@
     waddstr(win, str);
 }
 
+/* Like get_str, but disallows changes when use_savedir is set. */
+int
+get_str_prot(char *opt, WINDOW *win)
+{
+    int oy, ox;
+
+    if (use_savedir) {
+        getyx(win, oy, ox);
+        waddstr(win, opt);
+        return get_ro(win, oy, ox);
+    }
+    else {
+        return get_str(opt, win);
+    }
+}
+
+bool
+allowchange(OPTION *op)
+{
+    if (!use_savedir)
+        return TRUE;
+    if (!strcmp(op->o_name, "name"))
+        return FALSE;
+    if (!strcmp(op->o_name, "file"))
+        return FALSE;
+    if (!strcmp(op->o_name, "score"))
+        return FALSE;
+    return TRUE;
+}