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.
This commit is contained in:
John "Elwin" Edwards 2016-03-06 14:45:18 -05:00
parent 0a354903e0
commit 35bea2ba0d
4 changed files with 87 additions and 84 deletions

View file

@ -28,8 +28,8 @@
struct optstruct { struct optstruct {
char *o_name; /* option name */ char *o_name; /* option name */
char *o_prompt; /* prompt for interactive entry */ char *o_prompt; /* prompt for interactive entry */
int *o_opt; /* pointer to thing to set */ void *o_opt; /* pointer to thing to set */
int (*o_putfunc)(); /* function to print value */ void (*o_putfunc)(); /* function to print value */
int (*o_getfunc)(); /* function to get value interactively */ int (*o_getfunc)(); /* function to get value interactively */
}; };
@ -39,38 +39,38 @@ int get_ro(WINDOW *win, int oy, int ox);
int get_restr(char *optstr, WINDOW *win); int get_restr(char *optstr, WINDOW *win);
int get_score(char *optstr, WINDOW *win); int get_score(char *optstr, WINDOW *win);
void put_abil(int *ability, WINDOW *win); void put_abil(int *ability, WINDOW *win);
void get_abil(int *abil, WINDOW *win); int get_abil(int *abil, WINDOW *win);
void put_quest(int *quest, WINDOW *win); void put_quest(int *quest, WINDOW *win);
void get_quest(int *quest, WINDOW *win); int get_quest(int *quest, WINDOW *win);
void put_bool(bool *b, WINDOW *win); void put_bool(bool *b, WINDOW *win);
int get_bool(bool *bp, WINDOW *win); int get_bool(bool *bp, WINDOW *win);
void put_str(char *str, WINDOW *win); void put_str(char *str, WINDOW *win);
OPTION optlist[] = { OPTION optlist[] = {
{"terse", "Terse output: ", {"terse", "Terse output: ",
(int *) &terse, put_bool, get_bool }, (void *) &terse, put_bool, get_bool },
{"flush", "Flush typeahead during battle: ", {"flush", "Flush typeahead during battle: ",
(int *) &fight_flush, put_bool, get_bool }, (void *) &fight_flush, put_bool, get_bool },
{"jump", "Show position only at end of run: ", {"jump", "Show position only at end of run: ",
(int *) &jump, put_bool, get_bool }, (void *) &jump, put_bool, get_bool },
{"step", "Do inventories one line at a time: ", {"step", "Do inventories one line at a time: ",
(int *) &slow_invent, put_bool, get_bool }, (void *) &slow_invent, put_bool, get_bool },
{"askme", "Ask me about unidentified things: ", {"askme", "Ask me about unidentified things: ",
(int *) &askme, put_bool, get_bool }, (void *) &askme, put_bool, get_bool },
{"pickup", "Pick things up automatically: ", {"pickup", "Pick things up automatically: ",
(int *) &auto_pickup, put_bool, get_bool }, (void *) &auto_pickup, put_bool, get_bool },
{"name", "Name: ", {"name", "Name: ",
(int *) whoami, put_str, get_restr }, (void *) whoami, put_str, get_restr },
{"fruit", "Fruit: ", {"fruit", "Fruit: ",
(int *) fruit, put_str, get_str }, (void *) fruit, put_str, get_str },
{"file", "Save file: ", {"file", "Save file: ",
(int *) file_name, put_str, get_restr }, (void *) file_name, put_str, get_restr },
{"score", "Score file: ", {"score", "Score file: ",
(int *) score_file, put_str, get_score }, (void *) score_file, put_str, get_score },
{"class", "Character class: ", {"class", "Character class: ",
(int *)&char_type, put_abil, get_abil }, (void *)&char_type, put_abil, get_abil },
{"quest", "Quest item: ", {"quest", "Quest item: ",
(int *) &quest_item, put_quest, get_quest } (void *) &quest_item, put_quest, get_quest }
}; };
/* For fields that would be restricted if use_savedir is set. */ /* For fields that would be restricted if use_savedir is set. */
@ -111,27 +111,27 @@ int get_score(char *optstr, WINDOW *win)
/* /*
* The ability field is read-only * The ability field is read-only
*/ */
void int
get_abil(int *abil, WINDOW *win) get_abil(int *abil, WINDOW *win)
{ {
register int oy, ox; register int oy, ox;
getyx(win, oy, ox); getyx(win, oy, ox);
put_abil(abil, win); put_abil(abil, win);
get_ro(win, oy, ox); return get_ro(win, oy, ox);
} }
/* /*
* The quest field is read-only * The quest field is read-only
*/ */
void int
get_quest(int *quest, WINDOW *win) get_quest(int *quest, WINDOW *win)
{ {
register int oy, ox; register int oy, ox;
getyx(win, oy, ox); getyx(win, oy, ox);
waddstr(win, rel_magic[*quest].mi_name); waddstr(win, rel_magic[*quest].mi_name);
get_ro(win, oy, ox); return get_ro(win, oy, ox);
} }
/* /*
@ -416,18 +416,19 @@ parse_opts(char *str)
if (op->o_putfunc != put_abil) if (op->o_putfunc != put_abil)
strcpy((char *)op->o_opt, value); strcpy((char *)op->o_opt, value);
else if (*op->o_opt == -1) { /* Only init ability once */ else if (*(int *)op->o_opt == -1) {
/* Only init ability once */
register int len = strlen(value); register int len = strlen(value);
if (isupper(value[0])) value[0] = tolower(value[0]); if (isupper(value[0])) value[0] = tolower(value[0]);
if (EQSTR(value, "fighter", len)) if (EQSTR(value, "fighter", len))
*op->o_opt = C_FIGHTER; *(int *)op->o_opt = C_FIGHTER;
else if (EQSTR(value, "magic", min(len, 5))) else if (EQSTR(value, "magic", min(len, 5)))
*op->o_opt = C_MAGICIAN; *(int *)op->o_opt = C_MAGICIAN;
else if (EQSTR(value, "cleric", len)) else if (EQSTR(value, "cleric", len))
*op->o_opt = C_CLERIC; *(int *)op->o_opt = C_CLERIC;
else if (EQSTR(value, "thief", len)) else if (EQSTR(value, "thief", len))
*op->o_opt = C_THIEF; *(int *)op->o_opt = C_THIEF;
} }
} }
break; break;

View file

@ -33,8 +33,8 @@
struct optstruct { struct optstruct {
char *o_name; /* option name */ char *o_name; /* option name */
char *o_prompt; /* prompt for interactive entry */ char *o_prompt; /* prompt for interactive entry */
int *o_opt; /* pointer to thing to set */ void *o_opt; /* pointer to thing to set */
int (*o_putfunc)(); /* function to print value */ void (*o_putfunc)(); /* function to print value */
int (*o_getfunc)(); /* function to get value interactively */ int (*o_getfunc)(); /* function to get value interactively */
}; };
@ -45,9 +45,9 @@ int get_bool(bool *bp, WINDOW *win);
void put_str(char *str, WINDOW *win); void put_str(char *str, WINDOW *win);
int get_str(char *opt, WINDOW *win); int get_str(char *opt, WINDOW *win);
void put_abil(int *ability, WINDOW *win); void put_abil(int *ability, WINDOW *win);
void get_abil(int *abil, WINDOW *win); int get_abil(int *abil, WINDOW *win);
void put_quest(int *quest, WINDOW *win); void put_quest(int *quest, WINDOW *win);
void get_quest(int *quest, WINDOW *win); int get_quest(int *quest, WINDOW *win);
int get_ro(WINDOW *win, int oy, int ox); int get_ro(WINDOW *win, int oy, int ox);
int get_str_prot(char *opt, WINDOW *win); int get_str_prot(char *opt, WINDOW *win);
@ -56,55 +56,55 @@ bool allowchange(OPTION *op);
OPTION optlist[] = { OPTION optlist[] = {
{"terse", "Terse output: ", {"terse", "Terse output: ",
(int *) &terse, put_bool, get_bool }, (void *) &terse, put_bool, get_bool },
{"flush", "Flush typeahead during battle: ", {"flush", "Flush typeahead during battle: ",
(int *) &fight_flush, put_bool, get_bool }, (void *) &fight_flush, put_bool, get_bool },
{"jump", "Show position only at end of run: ", {"jump", "Show position only at end of run: ",
(int *) &jump, put_bool, get_bool }, (void *) &jump, put_bool, get_bool },
{"step", "Do inventories one line at a time: ", {"step", "Do inventories one line at a time: ",
(int *) &slow_invent, put_bool, get_bool }, (void *) &slow_invent, put_bool, get_bool },
{"askme", "Ask me about unidentified things: ", {"askme", "Ask me about unidentified things: ",
(int *) &askme, put_bool, get_bool }, (void *) &askme, put_bool, get_bool },
{"pickup", "Pick things up automatically: ", {"pickup", "Pick things up automatically: ",
(int *) &auto_pickup, put_bool, get_bool }, (void *) &auto_pickup, put_bool, get_bool },
{"overlay", "Overlay menu: ", {"overlay", "Overlay menu: ",
(int *) &menu_overlay, put_bool, get_bool }, (void *) &menu_overlay, put_bool, get_bool },
{"name", "Name: ", {"name", "Name: ",
(int *) whoami, put_str, get_str_prot }, (void *) whoami, put_str, get_str_prot },
{"file", "Save file: ", {"file", "Save file: ",
(int *) file_name, put_str, get_str_prot }, (void *) file_name, put_str, get_str_prot },
{"score", "Score file: ", {"score", "Score file: ",
(int *) score_file, put_str, get_score }, (void *) score_file, put_str, get_score },
{"class", "Character class: ", {"class", "Character class: ",
(int *)&char_type, put_abil, get_abil }, (void *)&char_type, put_abil, get_abil },
{"quest", "Quest item: ", {"quest", "Quest item: ",
(int *) &quest_item, put_quest, get_quest } (void *) &quest_item, put_quest, get_quest }
}; };
/* /*
* The ability field is read-only * The ability field is read-only
*/ */
void int
get_abil(int *abil, WINDOW *win) get_abil(int *abil, WINDOW *win)
{ {
register int oy, ox; register int oy, ox;
getyx(win, oy, ox); getyx(win, oy, ox);
put_abil(abil, win); put_abil(abil, win);
get_ro(win, oy, ox); return get_ro(win, oy, ox);
} }
/* /*
* The quest field is read-only * The quest field is read-only
*/ */
void int
get_quest(int *quest, WINDOW *win) get_quest(int *quest, WINDOW *win)
{ {
register int oy, ox; register int oy, ox;
getyx(win, oy, ox); getyx(win, oy, ox);
waddstr(win, rel_magic[*quest].mi_name); waddstr(win, rel_magic[*quest].mi_name);
get_ro(win, oy, ox); return get_ro(win, oy, ox);
} }
/* /*
@ -387,14 +387,15 @@ parse_opts(char *str)
strcpy((char *)op->o_opt, (char *)value); strcpy((char *)op->o_opt, (char *)value);
} }
else if (*op->o_opt == -1) { /* Only init ability once */ else if (*(int *)op->o_opt == -1) {
/* Only init ability once */
register int len = strlen(value); register int len = strlen(value);
register int i; register int i;
if (isupper(value[0])) value[0] = tolower(value[0]); if (isupper(value[0])) value[0] = tolower(value[0]);
for (i=0; i<NUM_CHARTYPES-1; i++) { for (i=0; i<NUM_CHARTYPES-1; i++) {
if (EQSTR(value, char_class[i].name, len)) { if (EQSTR(value, char_class[i].name, len)) {
*op->o_opt = i; *(int *)op->o_opt = i;
break; break;
} }
} }

View file

@ -27,8 +27,8 @@
struct optstruct { struct optstruct {
char *o_name; /* option name */ char *o_name; /* option name */
char *o_prompt; /* prompt for interactive entry */ char *o_prompt; /* prompt for interactive entry */
int *o_opt; /* pointer to thing to set */ void *o_opt; /* pointer to thing to set */
int (*o_putfunc)(); /* function to print value */ void (*o_putfunc)(); /* function to print value */
int (*o_getfunc)(); /* function to get value interactively */ int (*o_getfunc)(); /* function to get value interactively */
}; };
@ -43,23 +43,23 @@ int get_str(char *opt, WINDOW *win);
OPTION optlist[] = { OPTION optlist[] = {
{"terse", "Terse output: ", {"terse", "Terse output: ",
(int *) &terse, put_bool, get_bool }, (void *) &terse, put_bool, get_bool },
{"flush", "Flush typeahead during battle: ", {"flush", "Flush typeahead during battle: ",
(int *) &fight_flush, put_bool, get_bool }, (void *) &fight_flush, put_bool, get_bool },
{"jump", "Show position only at end of run: ", {"jump", "Show position only at end of run: ",
(int *) &jump, put_bool, get_bool }, (void *) &jump, put_bool, get_bool },
{"step", "Do inventories one line at a time: ", {"step", "Do inventories one line at a time: ",
(int *) &slow_invent, put_bool, get_bool }, (void *) &slow_invent, put_bool, get_bool },
{"askme", "Ask me about unidentified things: ", {"askme", "Ask me about unidentified things: ",
(int *) &askme, put_bool, get_bool }, (void *) &askme, put_bool, get_bool },
{"passgo", "Follow turnings in passageways: ", {"passgo", "Follow turnings in passageways: ",
(int *) &passgo, put_bool, get_bool }, (void *) &passgo, put_bool, get_bool },
{"name", "Name: ", {"name", "Name: ",
(int *) whoami, put_str, get_str }, (void *) whoami, put_str, get_str },
{"fruit", "Fruit: ", {"fruit", "Fruit: ",
(int *) fruit, put_str, get_str }, (void *) fruit, put_str, get_str },
{"file", "Save file: ", {"file", "Save file: ",
(int *) file_name, put_str, get_str } (void *) file_name, put_str, get_str }
}; };
/* /*

View file

@ -34,8 +34,8 @@
struct optstruct { struct optstruct {
char *o_name; /* option name */ char *o_name; /* option name */
char *o_prompt; /* prompt for interactive entry */ char *o_prompt; /* prompt for interactive entry */
int *o_opt; /* pointer to thing to set */ void *o_opt; /* pointer to thing to set */
int (*o_putfunc)(); /* function to print value */ void (*o_putfunc)(); /* function to print value */
int (*o_getfunc)(); /* function to get value interactively */ int (*o_getfunc)(); /* function to get value interactively */
}; };
@ -47,83 +47,83 @@ int get_bool(bool *bp, WINDOW *win);
void put_str(char *str, WINDOW *win); void put_str(char *str, WINDOW *win);
int get_str(char *opt, WINDOW *win); int get_str(char *opt, WINDOW *win);
void put_abil(int *ability, WINDOW *win); void put_abil(int *ability, WINDOW *win);
void get_abil(int *abil, WINDOW *win); int get_abil(int *abil, WINDOW *win);
void put_quest(int *quest, WINDOW *win); void put_quest(int *quest, WINDOW *win);
void get_quest(int *quest, WINDOW *win); int get_quest(int *quest, WINDOW *win);
void get_default(bool *bp, WINDOW *win); int get_default(bool *bp, WINDOW *win);
int get_str_prot(char *opt, WINDOW *win); int get_str_prot(char *opt, WINDOW *win);
int get_score(char *opt, WINDOW *win); int get_score(char *opt, WINDOW *win);
bool allowchange(OPTION *op); bool allowchange(OPTION *op);
OPTION optlist[] = { OPTION optlist[] = {
{"terse", "Terse output: ", {"terse", "Terse output: ",
(int *) &terse, put_bool, get_bool }, (void *) &terse, put_bool, get_bool },
{"flush", "Flush typeahead during battle: ", {"flush", "Flush typeahead during battle: ",
(int *) &fight_flush, put_bool, get_bool }, (void *) &fight_flush, put_bool, get_bool },
{"jump", "Show position only at end of run: ", {"jump", "Show position only at end of run: ",
(int *) &jump, put_bool, get_bool }, (void *) &jump, put_bool, get_bool },
{"step", "Do inventories one line at a time: ", {"step", "Do inventories one line at a time: ",
(int *) &slow_invent, put_bool, get_bool }, (void *) &slow_invent, put_bool, get_bool },
{"askme", "Ask me about unidentified things: ", {"askme", "Ask me about unidentified things: ",
(int *) &askme, put_bool, get_bool }, (void *) &askme, put_bool, get_bool },
{"pickup", "Pick things up automatically: ", {"pickup", "Pick things up automatically: ",
(int *) &auto_pickup, put_bool, get_bool }, (void *) &auto_pickup, put_bool, get_bool },
{"overlay", "Overlay menu: ", {"overlay", "Overlay menu: ",
(int *) &menu_overlay, put_bool, get_bool }, (void *) &menu_overlay, put_bool, get_bool },
{"name", "Name: ", {"name", "Name: ",
(int *) whoami, put_str, get_str_prot }, (void *) whoami, put_str, get_str_prot },
{"file", "Save file: ", {"file", "Save file: ",
(int *) file_name, put_str, get_str_prot }, (void *) file_name, put_str, get_str_prot },
{"score", "Score file: ", {"score", "Score file: ",
(int *) score_file, put_str, get_score }, (void *) score_file, put_str, get_score },
{"class", "Character type: ", {"class", "Character type: ",
(int *) &char_type, put_abil, get_abil }, (void *) &char_type, put_abil, get_abil },
{"quest", "Quest item: ", {"quest", "Quest item: ",
(int *) &quest_item, put_quest, get_quest }, (void *) &quest_item, put_quest, get_quest },
{"default", "Default Attributes: ", {"default", "Default Attributes: ",
(int *) &def_attr, put_bool, get_default } (void *) &def_attr, put_bool, get_default }
}; };
/* /*
* The default attribute field is read-only * The default attribute field is read-only
*/ */
void int
get_default(bool *bp, WINDOW *win) get_default(bool *bp, WINDOW *win)
{ {
register int oy, ox; register int oy, ox;
getyx(win, oy, ox); getyx(win, oy, ox);
put_bool(bp, win); put_bool(bp, win);
get_ro(win, oy, ox); return get_ro(win, oy, ox);
} }
/* /*
* The ability (class) field is read-only * The ability (class) field is read-only
*/ */
void int
get_abil(int *abil, WINDOW *win) get_abil(int *abil, WINDOW *win)
{ {
register int oy, ox; register int oy, ox;
getyx(win, oy, ox); getyx(win, oy, ox);
put_abil(abil, win); put_abil(abil, win);
get_ro(win, oy, ox); return get_ro(win, oy, ox);
} }
/* /*
* The quest field is read-only * The quest field is read-only
*/ */
void int
get_quest(int *quest, WINDOW *win) get_quest(int *quest, WINDOW *win)
{ {
register int oy, ox; register int oy, ox;
getyx(win, oy, ox); getyx(win, oy, ox);
waddstr(win, rel_magic[*quest].mi_name); waddstr(win, rel_magic[*quest].mi_name);
get_ro(win, oy, ox); return get_ro(win, oy, ox);
} }
/* /*
@ -411,13 +411,14 @@ parse_opts(char *str)
strcpy((char *)op->o_opt, value); strcpy((char *)op->o_opt, value);
} }
else if (*op->o_opt == -1) { /* Only init ability once */ else if (*(int *)op->o_opt == -1) {
/* Only init ability once */
register int len = strlen(value); register int len = strlen(value);
register int i; register int i;
for (i=0; i<NUM_CHARTYPES-1; i++) { for (i=0; i<NUM_CHARTYPES-1; i++) {
if (EQSTR(value, char_class[i].name, len)) { if (EQSTR(value, char_class[i].name, len)) {
*op->o_opt = i; *(int *)op->o_opt = i;
break; break;
} }
} }