code paths through x_monnam()

Reduce the number of early returns in x_monnam().  There shouldn't be
any change in observable behavior.
This commit is contained in:
PatR
2022-06-19 02:44:18 -07:00
parent 5e09a86766
commit f598acd1c9
+29 -27
View File
@@ -1,4 +1,4 @@
/* NetHack 3.7 do_name.c $NHDT-Date: 1655161562 2022/06/13 23:06:02 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.252 $ */ /* NetHack 3.7 do_name.c $NHDT-Date: 1655631843 2022/06/19 09:44:03 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.253 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Pasi Kallinen, 2018. */ /*-Copyright (c) Pasi Kallinen, 2018. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -1774,9 +1774,9 @@ x_monnam(
struct permonst *mdat = mtmp->data; struct permonst *mdat = mtmp->data;
const char *pm_name = mon_pmname(mtmp); const char *pm_name = mon_pmname(mtmp);
boolean do_hallu, do_invis, do_it, do_saddle, do_name, augment_it; boolean do_hallu, do_invis, do_it, do_saddle, do_name, augment_it;
boolean name_at_start, has_adjectives, boolean name_at_start, has_adjectives, insertbuf2,
falseCap = (*pm_name != lowc(*pm_name)); falseCap = (*pm_name != lowc(*pm_name));
char *bp; char *bp, buf2[BUFSZ];
if (mtmp == &g.youmonst) if (mtmp == &g.youmonst)
return strcpy(buf, "you"); /* ignore article, "invisible", &c */ return strcpy(buf, "you"); /* ignore article, "invisible", &c */
@@ -1808,7 +1808,6 @@ x_monnam(
/* priests and minions: don't even use this function */ /* priests and minions: don't even use this function */
if (mtmp->ispriest || mtmp->isminion) { if (mtmp->ispriest || mtmp->isminion) {
char priestnambuf[BUFSZ] = DUMMY;
char *name; char *name;
long save_prop = EHalluc_resistance; long save_prop = EHalluc_resistance;
unsigned save_invis = mtmp->minvis; unsigned save_invis = mtmp->minvis;
@@ -1818,14 +1817,14 @@ x_monnam(
EHalluc_resistance = 1L; EHalluc_resistance = 1L;
if (!do_invis) if (!do_invis)
mtmp->minvis = 0; mtmp->minvis = 0;
name = priestname(mtmp, article, priestnambuf); name = priestname(mtmp, article, buf2);
EHalluc_resistance = save_prop; EHalluc_resistance = save_prop;
mtmp->minvis = save_invis; mtmp->minvis = save_invis;
if (article == ARTICLE_NONE && !strncmp(name, "the ", 4)) if (article == ARTICLE_NONE && !strncmp(name, "the ", 4))
name += 4; name += 4;
return strcpy(buf, name); return strcpy(buf, name);
} }
#if 0 #if 0 /* [now handled by mon_pmname()] */
/* an "aligned priest" not flagged as a priest or minion should be /* an "aligned priest" not flagged as a priest or minion should be
"priest" or "priestess" (normally handled by priestname()) */ "priest" or "priestess" (normally handled by priestname()) */
if (mdat == &mons[PM_ALIGNED_CLERIC]) if (mdat == &mons[PM_ALIGNED_CLERIC])
@@ -1846,15 +1845,15 @@ x_monnam(
Strcpy(buf, "the "); Strcpy(buf, "the ");
Strcat(strcat(buf, adjective), " "); Strcat(strcat(buf, adjective), " ");
Strcat(buf, shkname(mtmp)); Strcat(buf, shkname(mtmp));
return buf; } else {
Strcat(buf, shkname(mtmp));
if (mdat != &mons[PM_SHOPKEEPER] || do_invis){
Strcat(buf, " the ");
if (do_invis)
Strcat(buf, "invisible ");
Strcat(buf, pm_name);
}
} }
Strcat(buf, shkname(mtmp));
if (mdat == &mons[PM_SHOPKEEPER] && !do_invis)
return buf;
Strcat(buf, " the ");
if (do_invis)
Strcat(buf, "invisible ");
Strcat(buf, pm_name);
return buf; return buf;
} }
@@ -1922,37 +1921,40 @@ x_monnam(
article = ARTICLE_THE; article = ARTICLE_THE;
} }
insertbuf2 = FALSE;
buf2[0] = '\0'; /* lint suppression */
if (article == ARTICLE_A && falseCap && !name_at_start) { if (article == ARTICLE_A && falseCap && !name_at_start) {
char buf2[BUFSZ], buf3[BUFSZ]; char buf3[BUFSZ];
/* some type names like "Archon", "Green-elf", and "Uruk-hai" fool /* some type names like "Archon", "Green-elf", and "Uruk-hai" fool
an() because of the capitalization and would result in "the " */ an() because of the capitalization and would result in "the " */
Strcpy(buf3, buf); Strcpy(buf3, buf);
*buf3 = lowc(*buf3); *buf3 = lowc(*buf3);
(void) just_an(buf2, buf3); (void) just_an(buf2, buf3);
Strcat(buf2, buf); insertbuf2 = TRUE;
return strcpy(buf, buf2);
} else { } else {
char buf2[BUFSZ];
switch (article) { switch (article) {
case ARTICLE_YOUR: case ARTICLE_YOUR:
Strcpy(buf2, "your "); Strcpy(buf2, "your ");
Strcat(buf2, buf); insertbuf2 = TRUE;
Strcpy(buf, buf2); break;
return buf;
case ARTICLE_THE: case ARTICLE_THE:
Strcpy(buf2, "the "); Strcpy(buf2, "the ");
Strcat(buf2, buf); insertbuf2 = TRUE;
Strcpy(buf, buf2); break;
return buf;
case ARTICLE_A: case ARTICLE_A:
return an(buf); buf = an(buf); /* (this consumes a 2nd mbuf[]) */
break;
case ARTICLE_NONE: case ARTICLE_NONE:
default: default:
return buf; break;
} }
} }
if (insertbuf2) {
Strcat(buf2, buf); /* buf2[] isn't viable to return, */
Strcpy(buf, buf2); /* so transfer the result to buf[] */
}
return buf;
} }
char * char *