comparison arogue5/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 56e748983fa8
children e940e6c00751
comparison
equal deleted inserted replaced
228:b67b99f6c92b 229:50b89f165a34
26 * description of an option and what to do with it 26 * description of an option and what to do with it
27 */ 27 */
28 struct optstruct { 28 struct optstruct {
29 char *o_name; /* option name */ 29 char *o_name; /* option name */
30 char *o_prompt; /* prompt for interactive entry */ 30 char *o_prompt; /* prompt for interactive entry */
31 int *o_opt; /* pointer to thing to set */ 31 void *o_opt; /* pointer to thing to set */
32 int (*o_putfunc)(); /* function to print value */ 32 void (*o_putfunc)(); /* function to print value */
33 int (*o_getfunc)(); /* function to get value interactively */ 33 int (*o_getfunc)(); /* function to get value interactively */
34 }; 34 };
35 35
36 typedef struct optstruct OPTION; 36 typedef struct optstruct OPTION;
37 37
38 int get_ro(WINDOW *win, int oy, int ox); 38 int get_ro(WINDOW *win, int oy, int ox);
39 int get_restr(char *optstr, WINDOW *win); 39 int get_restr(char *optstr, WINDOW *win);
40 int get_score(char *optstr, WINDOW *win); 40 int get_score(char *optstr, WINDOW *win);
41 void put_abil(int *ability, WINDOW *win); 41 void put_abil(int *ability, WINDOW *win);
42 void get_abil(int *abil, WINDOW *win); 42 int get_abil(int *abil, WINDOW *win);
43 void put_quest(int *quest, WINDOW *win); 43 void put_quest(int *quest, WINDOW *win);
44 void get_quest(int *quest, WINDOW *win); 44 int get_quest(int *quest, WINDOW *win);
45 void put_bool(bool *b, WINDOW *win); 45 void put_bool(bool *b, WINDOW *win);
46 int get_bool(bool *bp, WINDOW *win); 46 int get_bool(bool *bp, WINDOW *win);
47 void put_str(char *str, WINDOW *win); 47 void put_str(char *str, WINDOW *win);
48 48
49 OPTION optlist[] = { 49 OPTION optlist[] = {
50 {"terse", "Terse output: ", 50 {"terse", "Terse output: ",
51 (int *) &terse, put_bool, get_bool }, 51 (void *) &terse, put_bool, get_bool },
52 {"flush", "Flush typeahead during battle: ", 52 {"flush", "Flush typeahead during battle: ",
53 (int *) &fight_flush, put_bool, get_bool }, 53 (void *) &fight_flush, put_bool, get_bool },
54 {"jump", "Show position only at end of run: ", 54 {"jump", "Show position only at end of run: ",
55 (int *) &jump, put_bool, get_bool }, 55 (void *) &jump, put_bool, get_bool },
56 {"step", "Do inventories one line at a time: ", 56 {"step", "Do inventories one line at a time: ",
57 (int *) &slow_invent, put_bool, get_bool }, 57 (void *) &slow_invent, put_bool, get_bool },
58 {"askme", "Ask me about unidentified things: ", 58 {"askme", "Ask me about unidentified things: ",
59 (int *) &askme, put_bool, get_bool }, 59 (void *) &askme, put_bool, get_bool },
60 {"pickup", "Pick things up automatically: ", 60 {"pickup", "Pick things up automatically: ",
61 (int *) &auto_pickup, put_bool, get_bool }, 61 (void *) &auto_pickup, put_bool, get_bool },
62 {"name", "Name: ", 62 {"name", "Name: ",
63 (int *) whoami, put_str, get_restr }, 63 (void *) whoami, put_str, get_restr },
64 {"fruit", "Fruit: ", 64 {"fruit", "Fruit: ",
65 (int *) fruit, put_str, get_str }, 65 (void *) fruit, put_str, get_str },
66 {"file", "Save file: ", 66 {"file", "Save file: ",
67 (int *) file_name, put_str, get_restr }, 67 (void *) file_name, put_str, get_restr },
68 {"score", "Score file: ", 68 {"score", "Score file: ",
69 (int *) score_file, put_str, get_score }, 69 (void *) score_file, put_str, get_score },
70 {"class", "Character class: ", 70 {"class", "Character class: ",
71 (int *)&char_type, put_abil, get_abil }, 71 (void *)&char_type, put_abil, get_abil },
72 {"quest", "Quest item: ", 72 {"quest", "Quest item: ",
73 (int *) &quest_item, put_quest, get_quest } 73 (void *) &quest_item, put_quest, get_quest }
74 }; 74 };
75 75
76 /* For fields that would be restricted if use_savedir is set. */ 76 /* For fields that would be restricted if use_savedir is set. */
77 int get_restr(char *optstr, WINDOW *win) 77 int get_restr(char *optstr, WINDOW *win)
78 { 78 {
109 } 109 }
110 110
111 /* 111 /*
112 * The ability field is read-only 112 * The ability field is read-only
113 */ 113 */
114 void 114 int
115 get_abil(int *abil, WINDOW *win) 115 get_abil(int *abil, WINDOW *win)
116 { 116 {
117 register int oy, ox; 117 register int oy, ox;
118 118
119 getyx(win, oy, ox); 119 getyx(win, oy, ox);
120 put_abil(abil, win); 120 put_abil(abil, win);
121 get_ro(win, oy, ox); 121 return get_ro(win, oy, ox);
122 } 122 }
123 123
124 /* 124 /*
125 * The quest field is read-only 125 * The quest field is read-only
126 */ 126 */
127 void 127 int
128 get_quest(int *quest, WINDOW *win) 128 get_quest(int *quest, WINDOW *win)
129 { 129 {
130 register int oy, ox; 130 register int oy, ox;
131 131
132 getyx(win, oy, ox); 132 getyx(win, oy, ox);
133 waddstr(win, rel_magic[*quest].mi_name); 133 waddstr(win, rel_magic[*quest].mi_name);
134 get_ro(win, oy, ox); 134 return get_ro(win, oy, ox);
135 } 135 }
136 136
137 /* 137 /*
138 * get_ro: 138 * get_ro:
139 * "Get" a read-only value. 139 * "Get" a read-only value.
414 414
415 /* Put the value into the option field */ 415 /* Put the value into the option field */
416 if (op->o_putfunc != put_abil) 416 if (op->o_putfunc != put_abil)
417 strcpy((char *)op->o_opt, value); 417 strcpy((char *)op->o_opt, value);
418 418
419 else if (*op->o_opt == -1) { /* Only init ability once */ 419 else if (*(int *)op->o_opt == -1) {
420 /* Only init ability once */
420 register int len = strlen(value); 421 register int len = strlen(value);
421 422
422 if (isupper(value[0])) value[0] = tolower(value[0]); 423 if (isupper(value[0])) value[0] = tolower(value[0]);
423 if (EQSTR(value, "fighter", len)) 424 if (EQSTR(value, "fighter", len))
424 *op->o_opt = C_FIGHTER; 425 *(int *)op->o_opt = C_FIGHTER;
425 else if (EQSTR(value, "magic", min(len, 5))) 426 else if (EQSTR(value, "magic", min(len, 5)))
426 *op->o_opt = C_MAGICIAN; 427 *(int *)op->o_opt = C_MAGICIAN;
427 else if (EQSTR(value, "cleric", len)) 428 else if (EQSTR(value, "cleric", len))
428 *op->o_opt = C_CLERIC; 429 *(int *)op->o_opt = C_CLERIC;
429 else if (EQSTR(value, "thief", len)) 430 else if (EQSTR(value, "thief", len))
430 *op->o_opt = C_THIEF; 431 *(int *)op->o_opt = C_THIEF;
431 } 432 }
432 } 433 }
433 break; 434 break;
434 } 435 }
435 /* 436 /*