Fold character race/role/gender/align option parsing into single function
This commit is contained in:
138
src/options.c
138
src/options.c
@@ -1723,12 +1723,44 @@ count_menucolors()
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean
|
||||||
|
parse_role_opts(negated, fullname, opts, opp)
|
||||||
|
boolean negated;
|
||||||
|
char *fullname;
|
||||||
|
char *opts;
|
||||||
|
char **opp;
|
||||||
|
{
|
||||||
|
char *op = *opp;
|
||||||
|
if (negated) {
|
||||||
|
bad_negation(fullname, FALSE);
|
||||||
|
} else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) {
|
||||||
|
boolean val_negated = FALSE;
|
||||||
|
while ((*op == '!') || !strncmpi(op, "no", 2)) {
|
||||||
|
if (*op == '!')
|
||||||
|
op++;
|
||||||
|
else
|
||||||
|
op += 2;
|
||||||
|
val_negated = !val_negated;
|
||||||
|
}
|
||||||
|
if (val_negated) {
|
||||||
|
if (!setrolefilter(op))
|
||||||
|
badoption(opts);
|
||||||
|
} else {
|
||||||
|
if (duplicate_opt_detection(opts, 1))
|
||||||
|
complain_about_duplicate(opts, 1);
|
||||||
|
*opp = op;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
parseoptions(opts, tinitial, tfrom_file)
|
parseoptions(opts, tinitial, tfrom_file)
|
||||||
register char *opts;
|
register char *opts;
|
||||||
boolean tinitial, tfrom_file;
|
boolean tinitial, tfrom_file;
|
||||||
{
|
{
|
||||||
register char *op;
|
char *op;
|
||||||
unsigned num;
|
unsigned num;
|
||||||
boolean negated, val_negated, duplicate;
|
boolean negated, val_negated, duplicate;
|
||||||
int i;
|
int i;
|
||||||
@@ -1805,26 +1837,9 @@ boolean tinitial, tfrom_file;
|
|||||||
/* align:string */
|
/* align:string */
|
||||||
fullname = "align";
|
fullname = "align";
|
||||||
if (match_optname(opts, fullname, sizeof("align") - 1, TRUE)) {
|
if (match_optname(opts, fullname, sizeof("align") - 1, TRUE)) {
|
||||||
if (negated) {
|
if (parse_role_opts(negated, fullname, opts, &op)) {
|
||||||
bad_negation(fullname, FALSE);
|
if ((flags.initalign = str2align(op)) == ROLE_NONE)
|
||||||
} else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) {
|
badoption(opts);
|
||||||
val_negated = FALSE;
|
|
||||||
while ((*op == '!') || !strncmpi(op, "no", 2)) {
|
|
||||||
if (*op == '!')
|
|
||||||
op++;
|
|
||||||
else
|
|
||||||
op += 2;
|
|
||||||
val_negated = !val_negated;
|
|
||||||
}
|
|
||||||
if (val_negated) {
|
|
||||||
if (!setrolefilter(op))
|
|
||||||
badoption(opts);
|
|
||||||
} else {
|
|
||||||
if (duplicate_opt_detection(opts, 1))
|
|
||||||
complain_about_duplicate(opts, 1);
|
|
||||||
if ((flags.initalign = str2align(op)) == ROLE_NONE)
|
|
||||||
badoption(opts);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1833,28 +1848,11 @@ boolean tinitial, tfrom_file;
|
|||||||
fullname = "role";
|
fullname = "role";
|
||||||
if (match_optname(opts, fullname, 4, TRUE)
|
if (match_optname(opts, fullname, 4, TRUE)
|
||||||
|| match_optname(opts, (fullname = "character"), 4, TRUE)) {
|
|| match_optname(opts, (fullname = "character"), 4, TRUE)) {
|
||||||
if (negated) {
|
if (parse_role_opts(negated, fullname, opts, &op)) {
|
||||||
bad_negation(fullname, FALSE);
|
if ((flags.initrole = str2role(op)) == ROLE_NONE)
|
||||||
} else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) {
|
badoption(opts);
|
||||||
val_negated = FALSE;
|
else /* Backwards compatibility */
|
||||||
while ((*op == '!') || !strncmpi(op, "no", 2)) {
|
nmcpy(pl_character, op, PL_NSIZ);
|
||||||
if (*op == '!')
|
|
||||||
op++;
|
|
||||||
else
|
|
||||||
op += 2;
|
|
||||||
val_negated = !val_negated;
|
|
||||||
}
|
|
||||||
if (val_negated) {
|
|
||||||
if (!setrolefilter(op))
|
|
||||||
badoption(opts);
|
|
||||||
} else {
|
|
||||||
if (duplicate_opt_detection(opts, 1))
|
|
||||||
complain_about_duplicate(opts, 1);
|
|
||||||
if ((flags.initrole = str2role(op)) == ROLE_NONE)
|
|
||||||
badoption(opts);
|
|
||||||
else /* Backwards compatibility */
|
|
||||||
nmcpy(pl_character, op, PL_NSIZ);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1862,28 +1860,11 @@ boolean tinitial, tfrom_file;
|
|||||||
/* race:string */
|
/* race:string */
|
||||||
fullname = "race";
|
fullname = "race";
|
||||||
if (match_optname(opts, fullname, 4, TRUE)) {
|
if (match_optname(opts, fullname, 4, TRUE)) {
|
||||||
if (negated) {
|
if (parse_role_opts(negated, fullname, opts, &op)) {
|
||||||
bad_negation(fullname, FALSE);
|
if ((flags.initrace = str2race(op)) == ROLE_NONE)
|
||||||
} else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) {
|
badoption(opts);
|
||||||
val_negated = FALSE;
|
else /* Backwards compatibility */
|
||||||
while ((*op == '!') || !strncmpi(op, "no", 2)) {
|
pl_race = *op;
|
||||||
if (*op == '!')
|
|
||||||
op++;
|
|
||||||
else
|
|
||||||
op += 2;
|
|
||||||
val_negated = !val_negated;
|
|
||||||
}
|
|
||||||
if (val_negated) {
|
|
||||||
if (!setrolefilter(op))
|
|
||||||
badoption(opts);
|
|
||||||
} else {
|
|
||||||
if (duplicate_opt_detection(opts, 1))
|
|
||||||
complain_about_duplicate(opts, 1);
|
|
||||||
if ((flags.initrace = str2race(op)) == ROLE_NONE)
|
|
||||||
badoption(opts);
|
|
||||||
else /* Backwards compatibility */
|
|
||||||
pl_race = *op;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1891,28 +1872,11 @@ boolean tinitial, tfrom_file;
|
|||||||
/* gender:string */
|
/* gender:string */
|
||||||
fullname = "gender";
|
fullname = "gender";
|
||||||
if (match_optname(opts, fullname, 4, TRUE)) {
|
if (match_optname(opts, fullname, 4, TRUE)) {
|
||||||
if (negated) {
|
if (parse_role_opts(negated, fullname, opts, &op)) {
|
||||||
bad_negation(fullname, FALSE);
|
if ((flags.initgend = str2gend(op)) == ROLE_NONE)
|
||||||
} else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) {
|
badoption(opts);
|
||||||
val_negated = FALSE;
|
else
|
||||||
while ((*op == '!') || !strncmpi(op, "no", 2)) {
|
flags.female = flags.initgend;
|
||||||
if (*op == '!')
|
|
||||||
op++;
|
|
||||||
else
|
|
||||||
op += 2;
|
|
||||||
val_negated = !val_negated;
|
|
||||||
}
|
|
||||||
if (val_negated) {
|
|
||||||
if (!setrolefilter(op))
|
|
||||||
badoption(opts);
|
|
||||||
} else {
|
|
||||||
if (duplicate_opt_detection(opts, 1))
|
|
||||||
complain_about_duplicate(opts, 1);
|
|
||||||
if ((flags.initgend = str2gend(op)) == ROLE_NONE)
|
|
||||||
badoption(opts);
|
|
||||||
else
|
|
||||||
flags.female = flags.initgend;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user