Mercurial > hg > early-roguelike
comparison xrogue/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 | f54901b9c39b |
children | e940e6c00751 |
comparison
equal
deleted
inserted
replaced
228:b67b99f6c92b | 229:50b89f165a34 |
---|---|
32 * description of an option and what to do with it | 32 * description of an option and what to do with it |
33 */ | 33 */ |
34 struct optstruct { | 34 struct optstruct { |
35 char *o_name; /* option name */ | 35 char *o_name; /* option name */ |
36 char *o_prompt; /* prompt for interactive entry */ | 36 char *o_prompt; /* prompt for interactive entry */ |
37 int *o_opt; /* pointer to thing to set */ | 37 void *o_opt; /* pointer to thing to set */ |
38 int (*o_putfunc)(); /* function to print value */ | 38 void (*o_putfunc)(); /* function to print value */ |
39 int (*o_getfunc)(); /* function to get value interactively */ | 39 int (*o_getfunc)(); /* function to get value interactively */ |
40 }; | 40 }; |
41 | 41 |
42 typedef struct optstruct OPTION; | 42 typedef struct optstruct OPTION; |
43 | 43 |
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 int get_str(char *opt, WINDOW *win); | 48 int get_str(char *opt, WINDOW *win); |
49 void put_abil(int *ability, WINDOW *win); | 49 void put_abil(int *ability, WINDOW *win); |
50 void get_abil(int *abil, WINDOW *win); | 50 int get_abil(int *abil, WINDOW *win); |
51 void put_quest(int *quest, WINDOW *win); | 51 void put_quest(int *quest, WINDOW *win); |
52 void get_quest(int *quest, WINDOW *win); | 52 int get_quest(int *quest, WINDOW *win); |
53 void get_default(bool *bp, WINDOW *win); | 53 int get_default(bool *bp, WINDOW *win); |
54 int get_str_prot(char *opt, WINDOW *win); | 54 int get_str_prot(char *opt, WINDOW *win); |
55 int get_score(char *opt, WINDOW *win); | 55 int get_score(char *opt, WINDOW *win); |
56 bool allowchange(OPTION *op); | 56 bool allowchange(OPTION *op); |
57 | 57 |
58 OPTION optlist[] = { | 58 OPTION optlist[] = { |
59 {"terse", "Terse output: ", | 59 {"terse", "Terse output: ", |
60 (int *) &terse, put_bool, get_bool }, | 60 (void *) &terse, put_bool, get_bool }, |
61 {"flush", "Flush typeahead during battle: ", | 61 {"flush", "Flush typeahead during battle: ", |
62 (int *) &fight_flush, put_bool, get_bool }, | 62 (void *) &fight_flush, put_bool, get_bool }, |
63 {"jump", "Show position only at end of run: ", | 63 {"jump", "Show position only at end of run: ", |
64 (int *) &jump, put_bool, get_bool }, | 64 (void *) &jump, put_bool, get_bool }, |
65 {"step", "Do inventories one line at a time: ", | 65 {"step", "Do inventories one line at a time: ", |
66 (int *) &slow_invent, put_bool, get_bool }, | 66 (void *) &slow_invent, put_bool, get_bool }, |
67 {"askme", "Ask me about unidentified things: ", | 67 {"askme", "Ask me about unidentified things: ", |
68 (int *) &askme, put_bool, get_bool }, | 68 (void *) &askme, put_bool, get_bool }, |
69 {"pickup", "Pick things up automatically: ", | 69 {"pickup", "Pick things up automatically: ", |
70 (int *) &auto_pickup, put_bool, get_bool }, | 70 (void *) &auto_pickup, put_bool, get_bool }, |
71 {"overlay", "Overlay menu: ", | 71 {"overlay", "Overlay menu: ", |
72 (int *) &menu_overlay, put_bool, get_bool }, | 72 (void *) &menu_overlay, put_bool, get_bool }, |
73 {"name", "Name: ", | 73 {"name", "Name: ", |
74 (int *) whoami, put_str, get_str_prot }, | 74 (void *) whoami, put_str, get_str_prot }, |
75 {"file", "Save file: ", | 75 {"file", "Save file: ", |
76 (int *) file_name, put_str, get_str_prot }, | 76 (void *) file_name, put_str, get_str_prot }, |
77 {"score", "Score file: ", | 77 {"score", "Score file: ", |
78 (int *) score_file, put_str, get_score }, | 78 (void *) score_file, put_str, get_score }, |
79 {"class", "Character type: ", | 79 {"class", "Character type: ", |
80 (int *) &char_type, put_abil, get_abil }, | 80 (void *) &char_type, put_abil, get_abil }, |
81 {"quest", "Quest item: ", | 81 {"quest", "Quest item: ", |
82 (int *) &quest_item, put_quest, get_quest }, | 82 (void *) &quest_item, put_quest, get_quest }, |
83 {"default", "Default Attributes: ", | 83 {"default", "Default Attributes: ", |
84 (int *) &def_attr, put_bool, get_default } | 84 (void *) &def_attr, put_bool, get_default } |
85 }; | 85 }; |
86 | 86 |
87 /* | 87 /* |
88 * The default attribute field is read-only | 88 * The default attribute field is read-only |
89 */ | 89 */ |
90 | 90 |
91 void | 91 int |
92 get_default(bool *bp, WINDOW *win) | 92 get_default(bool *bp, WINDOW *win) |
93 { | 93 { |
94 register int oy, ox; | 94 register int oy, ox; |
95 | 95 |
96 getyx(win, oy, ox); | 96 getyx(win, oy, ox); |
97 put_bool(bp, win); | 97 put_bool(bp, win); |
98 get_ro(win, oy, ox); | 98 return get_ro(win, oy, ox); |
99 } | 99 } |
100 | 100 |
101 /* | 101 /* |
102 * The ability (class) field is read-only | 102 * The ability (class) field is read-only |
103 */ | 103 */ |
104 | 104 |
105 void | 105 int |
106 get_abil(int *abil, WINDOW *win) | 106 get_abil(int *abil, WINDOW *win) |
107 { | 107 { |
108 register int oy, ox; | 108 register int oy, ox; |
109 | 109 |
110 getyx(win, oy, ox); | 110 getyx(win, oy, ox); |
111 put_abil(abil, win); | 111 put_abil(abil, win); |
112 get_ro(win, oy, ox); | 112 return get_ro(win, oy, ox); |
113 } | 113 } |
114 | 114 |
115 /* | 115 /* |
116 * The quest field is read-only | 116 * The quest field is read-only |
117 */ | 117 */ |
118 | 118 |
119 void | 119 int |
120 get_quest(int *quest, WINDOW *win) | 120 get_quest(int *quest, WINDOW *win) |
121 { | 121 { |
122 register int oy, ox; | 122 register int oy, ox; |
123 | 123 |
124 getyx(win, oy, ox); | 124 getyx(win, oy, ox); |
125 waddstr(win, rel_magic[*quest].mi_name); | 125 waddstr(win, rel_magic[*quest].mi_name); |
126 get_ro(win, oy, ox); | 126 return get_ro(win, oy, ox); |
127 } | 127 } |
128 | 128 |
129 /* | 129 /* |
130 * get_ro: | 130 * get_ro: |
131 * "Get" a read-only value. | 131 * "Get" a read-only value. |
409 if (op->o_putfunc != put_abil) { | 409 if (op->o_putfunc != put_abil) { |
410 if (allowchange(op)) | 410 if (allowchange(op)) |
411 strcpy((char *)op->o_opt, value); | 411 strcpy((char *)op->o_opt, value); |
412 } | 412 } |
413 | 413 |
414 else if (*op->o_opt == -1) { /* Only init ability once */ | 414 else if (*(int *)op->o_opt == -1) { |
415 /* Only init ability once */ | |
415 register int len = strlen(value); | 416 register int len = strlen(value); |
416 register int i; | 417 register int i; |
417 | 418 |
418 for (i=0; i<NUM_CHARTYPES-1; i++) { | 419 for (i=0; i<NUM_CHARTYPES-1; i++) { |
419 if (EQSTR(value, char_class[i].name, len)) { | 420 if (EQSTR(value, char_class[i].name, len)) { |
420 *op->o_opt = i; | 421 *(int *)op->o_opt = i; |
421 break; | 422 break; |
422 } | 423 } |
423 } | 424 } |
424 } | 425 } |
425 } | 426 } |