From: PatR Date: Sun, 19 Jun 2022 09:44:18 +0000 (-0700) Subject: code paths through x_monnam() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f598acd1c9927aba8857725d4a06ef0ec0c5f0a9;p=nethack code paths through x_monnam() Reduce the number of early returns in x_monnam(). There shouldn't be any change in observable behavior. --- diff --git a/src/do_name.c b/src/do_name.c index b0f08b448..628963c04 100644 --- a/src/do_name.c +++ b/src/do_name.c @@ -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) Pasi Kallinen, 2018. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1774,9 +1774,9 @@ x_monnam( struct permonst *mdat = mtmp->data; const char *pm_name = mon_pmname(mtmp); 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)); - char *bp; + char *bp, buf2[BUFSZ]; if (mtmp == &g.youmonst) return strcpy(buf, "you"); /* ignore article, "invisible", &c */ @@ -1808,7 +1808,6 @@ x_monnam( /* priests and minions: don't even use this function */ if (mtmp->ispriest || mtmp->isminion) { - char priestnambuf[BUFSZ] = DUMMY; char *name; long save_prop = EHalluc_resistance; unsigned save_invis = mtmp->minvis; @@ -1818,14 +1817,14 @@ x_monnam( EHalluc_resistance = 1L; if (!do_invis) mtmp->minvis = 0; - name = priestname(mtmp, article, priestnambuf); + name = priestname(mtmp, article, buf2); EHalluc_resistance = save_prop; mtmp->minvis = save_invis; if (article == ARTICLE_NONE && !strncmp(name, "the ", 4)) name += 4; 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 "priest" or "priestess" (normally handled by priestname()) */ if (mdat == &mons[PM_ALIGNED_CLERIC]) @@ -1846,15 +1845,15 @@ x_monnam( Strcpy(buf, "the "); Strcat(strcat(buf, adjective), " "); 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; } @@ -1922,37 +1921,40 @@ x_monnam( article = ARTICLE_THE; } + insertbuf2 = FALSE; + buf2[0] = '\0'; /* lint suppression */ 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 an() because of the capitalization and would result in "the " */ Strcpy(buf3, buf); *buf3 = lowc(*buf3); (void) just_an(buf2, buf3); - Strcat(buf2, buf); - return strcpy(buf, buf2); + insertbuf2 = TRUE; } else { - char buf2[BUFSZ]; - switch (article) { case ARTICLE_YOUR: Strcpy(buf2, "your "); - Strcat(buf2, buf); - Strcpy(buf, buf2); - return buf; + insertbuf2 = TRUE; + break; case ARTICLE_THE: Strcpy(buf2, "the "); - Strcat(buf2, buf); - Strcpy(buf, buf2); - return buf; + insertbuf2 = TRUE; + break; case ARTICLE_A: - return an(buf); + buf = an(buf); /* (this consumes a 2nd mbuf[]) */ + break; case ARTICLE_NONE: 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 *