comparison srogue/options.c @ 38:8a9525231fb6

Prevent changing name or savefile when SAVEDIR is used.
author elwin
date Sat, 27 Nov 2010 16:22:30 +0000
parents 34d7a614855e
children 3aa87373c908
comparison
equal deleted inserted replaced
37:34d7a614855e 38:8a9525231fb6
38 { "name", "Name: ", whoami }, 38 { "name", "Name: ", whoami },
39 { "fruit", "Fruit: ", fruit }, 39 { "fruit", "Fruit: ", fruit },
40 { "file", "Save file: ", file_name } 40 { "file", "Save file: ", file_name }
41 }; 41 };
42 #define NUM_OPTS (sizeof optlist / sizeof (OPTION)) 42 #define NUM_OPTS (sizeof optlist / sizeof (OPTION))
43 OPTION safeoptlist[] = {
44 { "fruit", "Fruit: ", fruit },
45 };
46 #define NUM_SOPTS (sizeof safeoptlist / sizeof (OPTION))
43 47
44 /* 48 /*
45 * print and then set options from the terminal 49 * print and then set options from the terminal
46 */ 50 */
47 option() 51 option()
48 { 52 {
49 reg OPTION *op; 53 reg OPTION *op;
50 reg int wh; 54 reg int wh;
55 OPTION *olist;
56 int olen;
57
58 if (use_savedir) {
59 olist = safeoptlist;
60 olen = NUM_SOPTS;
61 }
62 else {
63 olist = optlist;
64 olen = NUM_OPTS;
65 }
51 66
52 wclear(hw); 67 wclear(hw);
53 touchwin(hw); 68 touchwin(hw);
54 /* 69 /*
55 * Display current values of options 70 * Display current values of options
56 */ 71 */
57 for (op = optlist; op < &optlist[NUM_OPTS]; op++) { 72 for (op = olist; op < &olist[olen]; op++) {
58 wh = op - optlist; 73 wh = op - olist;
59 mvwaddstr(hw, wh, 0, op->o_prompt); 74 mvwaddstr(hw, wh, 0, op->o_prompt);
60 mvwaddstr(hw, wh, 16, op->o_opt); 75 mvwaddstr(hw, wh, 16, op->o_opt);
61 } 76 }
62 /* 77 /*
63 * Set values 78 * Set values
64 */ 79 */
65 wmove(hw, 0, 0); 80 wmove(hw, 0, 0);
66 for (op = optlist; op < &optlist[NUM_OPTS]; op++) { 81 for (op = olist; op < &olist[olen]; op++) {
67 wmove(hw, op - optlist, 16); 82 wmove(hw, op - olist, 16);
68 if ((wh = get_str(op->o_opt, hw))) { 83 if ((wh = get_str(op->o_opt, hw))) {
69 if (wh == QUIT) 84 if (wh == QUIT)
70 break; 85 break;
71 else if (op > optlist) { 86 else if (op > olist) {
72 wmove(hw, op - optlist, 0); 87 wmove(hw, op - olist, 0);
73 op -= 2; 88 op -= 2;
74 } 89 }
75 else { 90 else {
76 putchar(7); 91 putchar(7);
77 wmove(hw, 0, 0); 92 wmove(hw, 0, 0);