diff arogue7/options.c @ 129:9c4e50b5825c

arogue7: prevent changing protected options. When using the savedir, whoami, file_name, and score_file cannot be changed.
author John "Elwin" Edwards
date Mon, 11 May 2015 19:41:46 -0400
parents b786053d2f37
children aac28331e71d
line wrap: on
line diff
--- a/arogue7/options.c	Mon May 11 16:46:00 2015 -0400
+++ b/arogue7/options.c	Mon May 11 19:41:46 2015 -0400
@@ -49,6 +49,9 @@
 	get_quest(),
 	put_quest();
 
+int get_str_prot(char *opt, WINDOW *win);
+bool allowchange(OPTION *op);
+
 OPTION	optlist[] = {
     {"terse",	 "Terse output: ",
 		 (int *) &terse,	put_bool,	get_bool	},
@@ -65,11 +68,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 class: ",
 		(int *)&char_type,	put_abil,	get_abil	},
     {"quest",	"Quest item: ",
@@ -381,7 +384,10 @@
 
 		    /* Put the value into the option field */
 		    if (op->o_putfunc != put_abil) 
-			strcpy((char *)op->o_opt, (char *)value);
+		    {
+			if (allowchange(op))
+			    strcpy((char *)op->o_opt, (char *)value);
+		    }
 
 		    else if (*op->o_opt == -1) { /* Only init ability once */
 			register int len = strlen(value);
@@ -463,3 +469,33 @@
 {
     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;
+}