From: PatR Date: Tue, 2 Oct 2018 23:53:22 +0000 (-0700) Subject: formatting cleanup src/*.c X-Git-Tag: NetHack-3.6.2_Released~190^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=14bef9a02d93ec9d62992316276b14c65af8d649;p=nethack formatting cleanup src/*.c Remove trailing spaces, and remove tabs from the files that had trailing spaces. Also, rndorcname() was using a random value to terminate a loop and was recalculating a new one each iteration. --- diff --git a/src/allmain.c b/src/allmain.c index 2c1364d75..d0b2c5302 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -793,44 +793,42 @@ enum earlyarg e_arg; userea = &argv[i][1]; } match = match_optname(userea, earlyopts[idx].name, - earlyopts[idx].minlength, earlyopts[idx].valallowed); + earlyopts[idx].minlength, + earlyopts[idx].valallowed); if (match) break; } if (match) { - const char *extended_opt = index(userea,':'); + const char *extended_opt = index(userea, ':'); if (!extended_opt) extended_opt = index(userea, '='); switch(e_arg) { - case ARG_DEBUG: - if (extended_opt) { - extended_opt++; - debug_fields(extended_opt); - } - return 1; - break; - case ARG_VERSION: { - boolean insert_into_pastebuf = FALSE; - - if (extended_opt) { - extended_opt++; - if (match_optname(extended_opt, "paste", - 5, FALSE)) { - insert_into_pastebuf = TRUE; - } else { - raw_printf( - "-%sversion can only be extended with -%sversion:paste.\n", - dashdash, dashdash); - return TRUE; - } - } - early_version_info(insert_into_pastebuf); - return 2; - break; + case ARG_DEBUG: + if (extended_opt) { + extended_opt++; + debug_fields(extended_opt); } - default: - break; + return 1; + case ARG_VERSION: { + boolean insert_into_pastebuf = FALSE; + + if (extended_opt) { + extended_opt++; + if (match_optname(extended_opt, "paste", 5, FALSE)) { + insert_into_pastebuf = TRUE; + } else { + raw_printf( + "-%sversion can only be extended with -%sversion:paste.\n", + dashdash, dashdash); + return TRUE; + } + } + early_version_info(insert_into_pastebuf); + return 2; + } + default: + break; } }; return FALSE; @@ -843,7 +841,7 @@ enum earlyarg e_arg; * are documented is right here. No gameplay is altered. * * test - test whether this parser is working - * ttystatus - TTY: + * ttystatus - TTY: * immediateflips - WIN32: turn off display performance * optimization so that display output * can be debugged without buffering. diff --git a/src/botl.c b/src/botl.c index 721ad2316..fde46e2fb 100644 --- a/src/botl.c +++ b/src/botl.c @@ -799,7 +799,7 @@ boolean *valsetlist; * all of the fields when context.botlx is set. The tty port in * particular has a problem if that isn't done, since the core sets * context.botlx when a menu or text display obliterates the status - * line. + * line. * * For those situations, to trigger the full update of every field * whether changed or not, call status_update() with BL_RESET. @@ -817,7 +817,7 @@ boolean *valsetlist; else if ((windowprocs.wincap2 & WC2_FLUSH_STATUS) != 0L) status_update(BL_FLUSH, (genericptr_t) 0, 0, 0, NO_COLOR, &cond_hilites[0]); - + context.botl = context.botlx = 0; update_all = FALSE; } diff --git a/src/do_name.c b/src/do_name.c index b6decaa86..aa688765a 100644 --- a/src/do_name.c +++ b/src/do_name.c @@ -175,7 +175,7 @@ const char *goal; } /* disgusting hack; the alternate selection characters work for any getpos call, but only matter for dowhatis (and doquickwhatis) */ - doing_what_is = (goal == what_is_an_unknown_object); + doing_what_is = (goal == what_is_an_unknown_object); if (doing_what_is) { Sprintf(kbuf, "'%s' or '%s' or '%s' or '%s'", visctrl(Cmd.spkeys[NHKF_GETPOS_PICK]), @@ -2071,20 +2071,17 @@ char * rndorcname(s) char *s; { - int i; - const char *v[] = {"a", "ai", "og", "u"}; - const char *snd[] = {"gor", "gris", "un", "bane", "ruk", - "oth","ul", "z", "thos","akh","hai"}; - int vstart = rn2(2); - + static const char *v[] = { "a", "ai", "og", "u" }; + static const char *snd[] = { "gor", "gris", "un", "bane", "ruk", + "oth","ul", "z", "thos","akh","hai" }; + int i, iend = rn1(2, 3), vstart = rn2(2); + if (s) { *s = '\0'; - for (i = 0; i < rn2(2) + 3; ++i) { + for (i = 0; i < iend; ++i) { vstart = 1 - vstart; /* 0 -> 1, 1 -> 0 */ - if (!rn2(30) && i > 0) - (void) strcat(s, "-"); - (void) sprintf(eos(s), "%s", vstart ? v[rn2(SIZE(v))] : - snd[rn2(SIZE(snd))]); + Sprintf(eos(s), "%s%s", (i > 0 && !rn2(30)) ? "-" : "", + vstart ? v[rn2(SIZE(v))] : snd[rn2(SIZE(snd))]); } } return s; diff --git a/src/dog.c b/src/dog.c index 1dc4018b9..e5767103a 100644 --- a/src/dog.c +++ b/src/dog.c @@ -412,7 +412,7 @@ boolean with_you; if (migrating_objs) deliver_obj_to_mon(mtmp, 0, DF_ALL); } - + if (xlocale && wander) { /* monster moved a bit; pick a nearby location */ /* mnearto() deals w/stone, et al */ diff --git a/src/dokick.c b/src/dokick.c index 99858a62f..1bea20ab6 100644 --- a/src/dokick.c +++ b/src/dokick.c @@ -1694,7 +1694,7 @@ unsigned long deliverflags; where = (int) (otmp->owornmask & 0x7fffL); /* destination code */ if ((where & MIGR_TO_SPECIES) == 0) continue; - + if ((mtmp->data->mflags2 & otmp->corpsenm) != 0) { obj_extract_self(otmp); otmp->owornmask = 0L; diff --git a/src/dothrow.c b/src/dothrow.c index 5a559ae4e..8dd71a8f2 100644 --- a/src/dothrow.c +++ b/src/dothrow.c @@ -1292,7 +1292,7 @@ boolean twoweap; /* used to restore twoweapon mode if wielded weapon returns */ if ((obj->oartifact == ART_MJOLLNIR && Role_if(PM_VALKYRIE)) || tethered_weapon) { if (rn2(100)) { - if (tethered_weapon) + if (tethered_weapon) tmp_at(DISP_END, BACKTRACK); else sho_obj_return_to_u(obj); /* display its flight */ diff --git a/src/engrave.c b/src/engrave.c index abd531abf..39c4005be 100644 --- a/src/engrave.c +++ b/src/engrave.c @@ -690,7 +690,7 @@ doengrave() xcrypt(blengr(), buf); } dengr = TRUE; - } + } break; case WAN_NOTHING: case WAN_UNDEAD_TURNING: diff --git a/src/files.c b/src/files.c index c122c3794..77ff211c8 100644 --- a/src/files.c +++ b/src/files.c @@ -666,7 +666,7 @@ void really_close() { int fd; - + if (lftrack.init) { fd = lftrack.fd; @@ -2156,24 +2156,27 @@ char sep; return (char *) 0; while (*str) { - if (*str == sep) nsep++; - str++; + if (*str == sep) + nsep++; + str++; } csep = rn2(nsep); str = begin; while ((csep > 0) && *str) { - str++; - if (*str == sep) csep--; + str++; + if (*str == sep) + csep--; } if (*str) { - if (*str == sep) str++; - begin = str; - while (*str && *str != sep) { - str++; - len++; - } - *str = '\0'; - if (len) + if (*str == sep) + str++; + begin = str; + while (*str && *str != sep) { + str++; + len++; + } + *str = '\0'; + if (len) return begin; } return (char *) 0; @@ -3582,7 +3585,7 @@ const char *reason; /* explanation */ void testinglog(filenm, type, reason) const char *filenm; /* ad hoc file name */ -const char *type; +const char *type; const char *reason; /* explanation */ { FILE *lfile; diff --git a/src/invent.c b/src/invent.c index 84e6367df..34b784475 100644 --- a/src/invent.c +++ b/src/invent.c @@ -2592,7 +2592,7 @@ long *out_cnt; int unid_cnt; char prompt[QBUFSZ]; - unid_cnt = count_unidentified(invent); + unid_cnt = count_unidentified(invent); Sprintf(prompt, "Debug Identify"); /* 'title' rather than 'prompt' */ if (unid_cnt) Sprintf(eos(prompt), diff --git a/src/makemon.c b/src/makemon.c index ee87d332e..a589d65b7 100644 --- a/src/makemon.c +++ b/src/makemon.c @@ -1391,8 +1391,8 @@ int mmflags; } if (allow_minvent && migrating_objs) - deliver_obj_to_mon(mtmp, 1, DF_NONE); /* in case there's waiting items */ - + deliver_obj_to_mon(mtmp, 1, DF_NONE); /* in case of waiting items */ + if (!in_mklev) newsym(mtmp->mx, mtmp->my); /* make sure the mon shows up */ diff --git a/src/mhitm.c b/src/mhitm.c index dfff12b26..ba322a8ca 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -782,13 +782,13 @@ struct attack *mattk; /* Kill off aggressor if it didn't die. */ if (!(result & MM_AGR_DIED)) { - boolean was_leashed = (magr->mleashed); + boolean was_leashed = (magr->mleashed != 0); mondead(magr); if (!DEADMONSTER(magr)) return result; /* life saved */ result |= MM_AGR_DIED; - + /* mondead() -> m_detach() -> m_unleash() always suppresses the m_unleash() slack message, so deliver it here instead */ if (was_leashed) diff --git a/src/mkmaze.c b/src/mkmaze.c index be6fcfd7f..1c2aca8da 100644 --- a/src/mkmaze.c +++ b/src/mkmaze.c @@ -801,11 +801,10 @@ stolen_booty(VOID_ARGS) mtyp = rn2((PM_ORC_SHAMAN - PM_ORC) + 1) + PM_ORC; mtmp = makemon(&mons[mtyp], 0, 0, MM_NONAME); if (mtmp) { - shiny_orc_stuff(mtmp); + shiny_orc_stuff(mtmp); migrate_orc(mtmp, 0UL); } } - ransacked = 0; } diff --git a/src/mon.c b/src/mon.c index 72f3df1a6..49ab5ac6a 100644 --- a/src/mon.c +++ b/src/mon.c @@ -462,7 +462,7 @@ unsigned corpseflags; * underneath it, you could be told the corpse type of a * monster that you never knew was there without this. * The code in hitmu() substitutes the word "something" - * if the corpses obj->dknown is 0. + * if the corpse's obj->dknown is 0. */ if (Blind && !sensemon(mtmp)) obj->dknown = 0; diff --git a/src/monmove.c b/src/monmove.c index fc32ebfb8..5694a31b8 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -255,14 +255,12 @@ struct monst *mon; } } -#define flees_light(mon) ((mon)->data == &mons[PM_GREMLIN] && \ - (uwep && artifact_light(uwep) && uwep->lamplit)) - +#define flees_light(mon) ((mon)->data == &mons[PM_GREMLIN] \ + && (uwep && artifact_light(uwep) && uwep->lamplit)) /* we could include this in the above macro, but probably overkill/overhead */ -/* (!((which_armor((mon), W_ARMC) != 0) && ((which_armor((mon), W_ARMH) != 0))) && */ - +/* && (!(which_armor((mon), W_ARMC) != 0 */ +/* && which_armor((mon), W_ARMH) != 0)) */ - /* monster begins fleeing for the specified time, 0 means untimed flee * if first, only adds fleetime if monster isn't already fleeing * if fleemsg, prints a message about new flight, otherwise, caller should */ diff --git a/src/pager.c b/src/pager.c index 4515ea8e8..c1824d2f8 100644 --- a/src/pager.c +++ b/src/pager.c @@ -1390,7 +1390,7 @@ boolean without_asking; } display_nhwindow(datawin, FALSE); destroy_nhwindow(datawin), datawin = WIN_ERR; - } + } } } @@ -1470,7 +1470,7 @@ doidtrap() commands: basic letters vs digits, 'g' vs 'G' for '5', phone keypad vs normal layout of digits, and QWERTZ keyboard swap between y/Y/^Y/M-y/M-Y/M-^Y and z/Z/^Z/M-z/M-Z/M-^Z.) - + The interpretor understands '&#' for comment, '&? option' for 'if' (also '&? !option' @@ -1481,7 +1481,7 @@ doidtrap() '&:' for 'else' (also '&: #comment'; 0 or 1 instance for a given 'if'), and '&.' for 'endif' (also '&. #comment'; required for each 'if'). - + The option handling is a bit of a mess, with no generality for which options to deal with and only a comma separated list of integer values for the '=value' part. number_pad is the only diff --git a/src/version.c b/src/version.c index 5055e8df6..9b3763841 100644 --- a/src/version.c +++ b/src/version.c @@ -57,7 +57,7 @@ char *buf; Sprintf(eos(buf), " ("); #if defined(RUNTIME_PORT_ID) - tmp = get_port_id(tmpbuf); + tmp = get_port_id(tmpbuf); if (tmp) Sprintf(eos(buf), "%s%s", c++ ? "," : "", tmp); #endif