comparison rogue4/options.c @ 14:e7dc81b41168

rogue4: prevent changing name or save file when using system savedir
author edwarj4
date Sat, 31 Oct 2009 13:20:00 +0000
parents 9535a08ddc39
children 1b73a8641b37
comparison
equal deleted inserted replaced
13:63b9fd7d70ce 14:e7dc81b41168
31 int (*o_putfunc)(); /* function to print value */ 31 int (*o_putfunc)(); /* function to print value */
32 int (*o_getfunc)(); /* function to get value interactively */ 32 int (*o_getfunc)(); /* function to get value interactively */
33 }; 33 };
34 34
35 typedef struct optstruct OPTION; 35 typedef struct optstruct OPTION;
36
37 int allowchange(OPTION *opt);
36 38
37 int put_bool(), get_bool(), put_str(), get_str(); 39 int put_bool(), get_bool(), put_str(), get_str();
38 40
39 OPTION optlist[] = { 41 OPTION optlist[] = {
40 {"terse", "Terse output: ", 42 {"terse", "Terse output: ",
70 /* 72 /*
71 * Display current values of options 73 * Display current values of options
72 */ 74 */
73 for (op = optlist; op < &optlist[NUM_OPTS]; op++) 75 for (op = optlist; op < &optlist[NUM_OPTS]; op++)
74 { 76 {
75 waddstr(hw, op->o_prompt); 77 if (allowchange(op))
76 (*op->o_putfunc)(op->o_opt); 78 {
77 waddch(hw, '\n'); 79 waddstr(hw, op->o_prompt);
80 (*op->o_putfunc)(op->o_opt);
81 waddch(hw, '\n');
82 }
78 } 83 }
79 /* 84 /*
80 * Set values 85 * Set values
81 */ 86 */
82 wmove(hw, 0, 0); 87 wmove(hw, 0, 0);
83 for (op = optlist; op < &optlist[NUM_OPTS]; op++) 88 for (op = optlist; op < &optlist[NUM_OPTS]; op++)
84 { 89 {
90 if (!allowchange(op))
91 continue;
85 waddstr(hw, op->o_prompt); 92 waddstr(hw, op->o_prompt);
86 if ((retval = (*op->o_getfunc)(op->o_opt, hw))) 93 if ((retval = (*op->o_getfunc)(op->o_opt, hw)))
94 {
87 if (retval == QUIT) 95 if (retval == QUIT)
88 break; 96 break;
97 #if 0 /* disable MINUS */
89 else if (op > optlist) { /* MINUS */ 98 else if (op > optlist) { /* MINUS */
90 wmove(hw, (op - optlist) - 1, 0); 99 wmove(hw, (op - optlist) - 1, 0);
91 op -= 2; 100 op -= 2;
92 } 101 }
93 else /* trying to back up beyond the top */ 102 else /* trying to back up beyond the top */
94 { 103 {
95 putchar('\007'); 104 putchar('\007');
96 wmove(hw, 0, 0); 105 wmove(hw, 0, 0);
97 op--; 106 op--;
98 } 107 }
108 #else
109 break;
110 #endif
111 }
99 } 112 }
100 /* 113 /*
101 * Switch back to original screen 114 * Switch back to original screen
102 */ 115 */
103 mvwaddstr(hw, LINES-1, 0, "--Press space to continue--"); 116 mvwaddstr(hw, LINES-1, 0, "--Press space to continue--");
299 len = sp - str; 312 len = sp - str;
300 /* 313 /*
301 * Look it up and deal with it 314 * Look it up and deal with it
302 */ 315 */
303 for (op = optlist; op < &optlist[NUM_OPTS]; op++) 316 for (op = optlist; op < &optlist[NUM_OPTS]; op++)
317 {
318 /* If using system savefiles, changing your name or the
319 save file is not allowed. */
320 if (!allowchange(op))
321 continue;
304 if (EQSTR(str, op->o_name, len)) 322 if (EQSTR(str, op->o_name, len))
305 { 323 {
306 if (op->o_putfunc == put_bool) /* if option is a boolean */ 324 if (op->o_putfunc == put_bool) /* if option is a boolean */
307 *(bool *)op->o_opt = TRUE; 325 *(bool *)op->o_opt = TRUE;
308 else /* string option */ 326 else /* string option */
338 && EQSTR(str, "no", 2) && EQSTR(str + 2, op->o_name, len - 2)) 356 && EQSTR(str, "no", 2) && EQSTR(str + 2, op->o_name, len - 2))
339 { 357 {
340 *(bool *)op->o_opt = FALSE; 358 *(bool *)op->o_opt = FALSE;
341 break; 359 break;
342 } 360 }
361 }
343 362
344 /* 363 /*
345 * skip to start of next option name 364 * skip to start of next option name
346 */ 365 */
347 while (*sp && !isalpha(*sp)) 366 while (*sp && !isalpha(*sp))
366 *s1++ = *s2; 385 *s1++ = *s2;
367 s2++; 386 s2++;
368 } 387 }
369 *s1 = '\0'; 388 *s1 = '\0';
370 } 389 }
390
391 /* Tells whether the player is allowed to change the option. */
392 int allowchange(OPTION *opt)
393 {
394 if (!use_savedir)
395 return 1;
396 if (!strcmp(opt->o_name, "name"))
397 return 0;
398 if (!strcmp(opt->o_name, "file"))
399 return 0;
400 return 1;
401 }
402