comparison arogue7/options.c @ 229:50b89f165a34

Use uniform return types for functions related to options. Functions for printing options now return void. Functions for setting options now return int. Argument types still vary, though converting all the option pointers to void* would be possible.
author John "Elwin" Edwards
date Sun, 06 Mar 2016 14:45:18 -0500
parents f9ef86cf22b2
children e940e6c00751
comparison
equal deleted inserted replaced
228:b67b99f6c92b 229:50b89f165a34
31 * description of an option and what to do with it 31 * description of an option and what to do with it
32 */ 32 */
33 struct optstruct { 33 struct optstruct {
34 char *o_name; /* option name */ 34 char *o_name; /* option name */
35 char *o_prompt; /* prompt for interactive entry */ 35 char *o_prompt; /* prompt for interactive entry */
36 int *o_opt; /* pointer to thing to set */ 36 void *o_opt; /* pointer to thing to set */
37 int (*o_putfunc)(); /* function to print value */ 37 void (*o_putfunc)(); /* function to print value */
38 int (*o_getfunc)(); /* function to get value interactively */ 38 int (*o_getfunc)(); /* function to get value interactively */
39 }; 39 };
40 40
41 typedef struct optstruct OPTION; 41 typedef struct optstruct OPTION;
42 42
43 void put_bool(bool *b, WINDOW *win); 43 void put_bool(bool *b, WINDOW *win);
44 int get_bool(bool *bp, WINDOW *win); 44 int get_bool(bool *bp, WINDOW *win);
45 void put_str(char *str, WINDOW *win); 45 void put_str(char *str, WINDOW *win);
46 int get_str(char *opt, WINDOW *win); 46 int get_str(char *opt, WINDOW *win);
47 void put_abil(int *ability, WINDOW *win); 47 void put_abil(int *ability, WINDOW *win);
48 void get_abil(int *abil, WINDOW *win); 48 int get_abil(int *abil, WINDOW *win);
49 void put_quest(int *quest, WINDOW *win); 49 void put_quest(int *quest, WINDOW *win);
50 void get_quest(int *quest, WINDOW *win); 50 int get_quest(int *quest, WINDOW *win);
51 int get_ro(WINDOW *win, int oy, int ox); 51 int get_ro(WINDOW *win, int oy, int ox);
52 52
53 int get_str_prot(char *opt, WINDOW *win); 53 int get_str_prot(char *opt, WINDOW *win);
54 int get_score(char *opt, WINDOW *win); 54 int get_score(char *opt, WINDOW *win);
55 bool allowchange(OPTION *op); 55 bool allowchange(OPTION *op);
56 56
57 OPTION optlist[] = { 57 OPTION optlist[] = {
58 {"terse", "Terse output: ", 58 {"terse", "Terse output: ",
59 (int *) &terse, put_bool, get_bool }, 59 (void *) &terse, put_bool, get_bool },
60 {"flush", "Flush typeahead during battle: ", 60 {"flush", "Flush typeahead during battle: ",
61 (int *) &fight_flush, put_bool, get_bool }, 61 (void *) &fight_flush, put_bool, get_bool },
62 {"jump", "Show position only at end of run: ", 62 {"jump", "Show position only at end of run: ",
63 (int *) &jump, put_bool, get_bool }, 63 (void *) &jump, put_bool, get_bool },
64 {"step", "Do inventories one line at a time: ", 64 {"step", "Do inventories one line at a time: ",
65 (int *) &slow_invent, put_bool, get_bool }, 65 (void *) &slow_invent, put_bool, get_bool },
66 {"askme", "Ask me about unidentified things: ", 66 {"askme", "Ask me about unidentified things: ",
67 (int *) &askme, put_bool, get_bool }, 67 (void *) &askme, put_bool, get_bool },
68 {"pickup", "Pick things up automatically: ", 68 {"pickup", "Pick things up automatically: ",
69 (int *) &auto_pickup, put_bool, get_bool }, 69 (void *) &auto_pickup, put_bool, get_bool },
70 {"overlay", "Overlay menu: ", 70 {"overlay", "Overlay menu: ",
71 (int *) &menu_overlay, put_bool, get_bool }, 71 (void *) &menu_overlay, put_bool, get_bool },
72 {"name", "Name: ", 72 {"name", "Name: ",
73 (int *) whoami, put_str, get_str_prot }, 73 (void *) whoami, put_str, get_str_prot },
74 {"file", "Save file: ", 74 {"file", "Save file: ",
75 (int *) file_name, put_str, get_str_prot }, 75 (void *) file_name, put_str, get_str_prot },
76 {"score", "Score file: ", 76 {"score", "Score file: ",
77 (int *) score_file, put_str, get_score }, 77 (void *) score_file, put_str, get_score },
78 {"class", "Character class: ", 78 {"class", "Character class: ",
79 (int *)&char_type, put_abil, get_abil }, 79 (void *)&char_type, put_abil, get_abil },
80 {"quest", "Quest item: ", 80 {"quest", "Quest item: ",
81 (int *) &quest_item, put_quest, get_quest } 81 (void *) &quest_item, put_quest, get_quest }
82 }; 82 };
83 83
84 /* 84 /*
85 * The ability field is read-only 85 * The ability field is read-only
86 */ 86 */
87 void 87 int
88 get_abil(int *abil, WINDOW *win) 88 get_abil(int *abil, WINDOW *win)
89 { 89 {
90 register int oy, ox; 90 register int oy, ox;
91 91
92 getyx(win, oy, ox); 92 getyx(win, oy, ox);
93 put_abil(abil, win); 93 put_abil(abil, win);
94 get_ro(win, oy, ox); 94 return get_ro(win, oy, ox);
95 } 95 }
96 96
97 /* 97 /*
98 * The quest field is read-only 98 * The quest field is read-only
99 */ 99 */
100 void 100 int
101 get_quest(int *quest, WINDOW *win) 101 get_quest(int *quest, WINDOW *win)
102 { 102 {
103 register int oy, ox; 103 register int oy, ox;
104 104
105 getyx(win, oy, ox); 105 getyx(win, oy, ox);
106 waddstr(win, rel_magic[*quest].mi_name); 106 waddstr(win, rel_magic[*quest].mi_name);
107 get_ro(win, oy, ox); 107 return get_ro(win, oy, ox);
108 } 108 }
109 109
110 /* 110 /*
111 * get_ro: 111 * get_ro:
112 * "Get" a read-only value. 112 * "Get" a read-only value.
385 { 385 {
386 if (allowchange(op)) 386 if (allowchange(op))
387 strcpy((char *)op->o_opt, (char *)value); 387 strcpy((char *)op->o_opt, (char *)value);
388 } 388 }
389 389
390 else if (*op->o_opt == -1) { /* Only init ability once */ 390 else if (*(int *)op->o_opt == -1) {
391 /* Only init ability once */
391 register int len = strlen(value); 392 register int len = strlen(value);
392 register int i; 393 register int i;
393 394
394 if (isupper(value[0])) value[0] = tolower(value[0]); 395 if (isupper(value[0])) value[0] = tolower(value[0]);
395 for (i=0; i<NUM_CHARTYPES-1; i++) { 396 for (i=0; i<NUM_CHARTYPES-1; i++) {
396 if (EQSTR(value, char_class[i].name, len)) { 397 if (EQSTR(value, char_class[i].name, len)) {
397 *op->o_opt = i; 398 *(int *)op->o_opt = i;
398 break; 399 break;
399 } 400 }
400 } 401 }
401 } 402 }
402 } 403 }