From: Markus Armbruster Date: Sat, 21 Feb 2009 14:30:13 +0000 (+0100) Subject: Clean up poorly chosen loop control variable names X-Git-Tag: v4.3.23~110 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=a61e673a075e678f0e992546248037e52ff05ab3 Clean up poorly chosen loop control variable names Calling a counting loop's control variable q or x is tasteless bordering on actively misleading. --- diff --git a/src/lib/commands/trad.c b/src/lib/commands/trad.c index 310ae402e..02f3794fe 100644 --- a/src/lib/commands/trad.c +++ b/src/lib/commands/trad.c @@ -72,7 +72,7 @@ trad(void) int bid; double tleft; double tally; - int q; + int i; char buf[1024]; if (!opt_MARKET) { @@ -164,13 +164,13 @@ trad(void) return RET_OK; } tally = 0.0; - for (q = 0; gettrade(q, &tmpt); q++) { + for (i = 0; gettrade(i, &tmpt); i++) { if (tmpt.trd_maxbidder == player->cnum && tmpt.trd_unitid >= 0 && tmpt.trd_owner != player->cnum) { tally += tmpt.trd_price * tradetax; } } - for (q = 0; getcomm(q, &comt); q++) { + for (i = 0; getcomm(i, &comt); i++) { if (comt.com_maxbidder == player->cnum && comt.com_owner != 0 && comt.com_owner != player->cnum) { tally += (comt.com_price * comt.com_amount) * buytax; diff --git a/src/lib/common/path.c b/src/lib/common/path.c index 41bd0473e..43124c168 100644 --- a/src/lib/common/path.c +++ b/src/lib/common/path.c @@ -182,7 +182,7 @@ bp_neighbors(struct as_coord c, struct as_coord *cp, void *pp) struct bestp *bp = pp; coord x, y; coord nx, ny; - int n = 0, q; + int n = 0, i; struct sctstr *sp, *from, **ssp; /* Six pointers, just in case our cache isn't there */ struct sctstr *tsp[] = { NULL, NULL, NULL, NULL, NULL, NULL }; @@ -199,11 +199,11 @@ bp_neighbors(struct as_coord c, struct as_coord *cp, void *pp) ssp = (struct sctstr **)&tsp[0]; else ssp = (struct sctstr **)&neighsects[offset * 6]; - for (q = 1; q <= 6; q++, ssp++) { + for (i = 1; i <= 6; i++, ssp++) { if (*ssp == NULL) { /* We haven't cached this neighbor yet */ - nx = x + diroff[q][0]; - ny = y + diroff[q][1]; + nx = x + diroff[i][0]; + ny = y + diroff[i][1]; sx = XNORM(nx); sy = YNORM(ny); offset = XYOFFSET(sx, sy); diff --git a/src/lib/subs/show.c b/src/lib/subs/show.c index ebab905ed..c39e1b665 100644 --- a/src/lib/subs/show.c +++ b/src/lib/subs/show.c @@ -458,33 +458,33 @@ show_land_stats(int tlev) void show_sect_build(int foo) { - int x, first; + int i, first; pr("sector type cost to des cost for 1%% eff lcms for 1%% hcms for 1%%\n"); - for (x = 0; dchr[x].d_name; x++) { - if (dchr[x].d_mnem == 0) + for (i = 0; dchr[i].d_name; i++) { + if (dchr[i].d_mnem == 0) continue; - if (dchr[x].d_cost < 0) + if (dchr[i].d_cost < 0) continue; - if ((dchr[x].d_cost > 0) || (dchr[x].d_build != 1) || - (dchr[x].d_lcms > 0) || (dchr[x].d_hcms > 0)) { + if ((dchr[i].d_cost > 0) || (dchr[i].d_build != 1) || + (dchr[i].d_lcms > 0) || (dchr[i].d_hcms > 0)) { pr("%-14c %-14d %-17d %-14d %d\n", - dchr[x].d_mnem, dchr[x].d_cost, dchr[x].d_build, - dchr[x].d_lcms, dchr[x].d_hcms); + dchr[i].d_mnem, dchr[i].d_cost, dchr[i].d_build, + dchr[i].d_lcms, dchr[i].d_hcms); } } pr("other 0 1 0 0\n"); first = 1; - for (x = 0; intrchr[x].in_name; x++) { - if (!intrchr[x].in_enable) + for (i = 0; intrchr[i].in_name; i++) { + if (!intrchr[i].in_enable) continue; if (first) pr("\nInfrastructure building - adding 1 point of efficiency costs:\n" " type lcms hcms mobility $$$$\n"); pr("%-20s %4d %4d %8d %4d\n", - intrchr[x].in_name, intrchr[x].in_lcms, intrchr[x].in_hcms, - intrchr[x].in_mcost, intrchr[x].in_dcost); + intrchr[i].in_name, intrchr[i].in_lcms, intrchr[i].in_hcms, + intrchr[i].in_mcost, intrchr[i].in_dcost); first = 0; } } @@ -492,41 +492,41 @@ show_sect_build(int foo) void show_sect_stats(int foo) { - int x; + int i; struct natstr *natp = getnatp(player->cnum); pr(" mob cost max max naviga packing max\n"); pr(" sector type 0%% 100%% off def bility bonus pop\n"); - for (x = 0; dchr[x].d_name; x++) { - if (dchr[x].d_mnem == 0) + for (i = 0; dchr[i].d_name; i++) { + if (dchr[i].d_mnem == 0) continue; - pr("%c %-21.21s", dchr[x].d_mnem, dchr[x].d_name); - if (dchr[x].d_mob0 < 0) + pr("%c %-21.21s", dchr[i].d_mnem, dchr[i].d_name); + if (dchr[i].d_mob0 < 0) pr(" no way "); else - pr(" %3.1f %3.1f", dchr[x].d_mob0, dchr[x].d_mob1); + pr(" %3.1f %3.1f", dchr[i].d_mob0, dchr[i].d_mob1); pr(" %5.2f %5.2f %7.7s %10.10s %5d\n", - dchr[x].d_ostr, dchr[x].d_dstr, - symbol_by_value(dchr[x].d_nav, sector_navigation), - symbol_by_value(dchr[x].d_pkg, packing), - max_population(natp->nat_level[NAT_RLEV], x, 100)); + dchr[i].d_ostr, dchr[i].d_dstr, + symbol_by_value(dchr[i].d_nav, sector_navigation), + symbol_by_value(dchr[i].d_pkg, packing), + max_population(natp->nat_level[NAT_RLEV], i, 100)); } } void show_sect_capab(int foo) { - int x; + int i; pr(" sector type product p.e.\n"); - for (x = 0; dchr[x].d_name; x++) { - if (dchr[x].d_mnem == 0 || dchr[x].d_prd < 0) + for (i = 0; dchr[i].d_name; i++) { + if (dchr[i].d_mnem == 0 || dchr[i].d_prd < 0) continue; pr("%c %-23s %-7s %4d%%\n", - dchr[x].d_mnem, dchr[x].d_name, pchr[dchr[x].d_prd].p_sname, - dchr[x].d_peffic); + dchr[i].d_mnem, dchr[i].d_name, pchr[dchr[i].d_prd].p_sname, + dchr[i].d_peffic); } } diff --git a/src/lib/update/main.c b/src/lib/update/main.c index 3a5522470..03345930e 100644 --- a/src/lib/update/main.c +++ b/src/lib/update/main.c @@ -57,7 +57,7 @@ update_main(void) { int etu = etu_per_update; int n; - int x; + int i; struct bp *bp; int cn, cn2, rel; struct natstr *cnp; @@ -100,32 +100,32 @@ update_main(void) prepare_sects(etu, bp); logerror("done preparing sectors."); logerror("producing for countries..."); - for (x = 0; x < MAXNOC; x++) { + for (i = 0; i < MAXNOC; i++) { long p_sect[SCT_TYPE_MAX+2][2]; memset(p_sect, 0, sizeof(p_sect)); - if (!(np = getnatp(x))) + if (!(np = getnatp(i))) continue; if (np->nat_stat == STAT_SANCT) { #ifdef DEBUG - logerror("Country %i is in sanctuary and did not update", x); + logerror("Country %i is in sanctuary and did not update", i); #endif continue; } np->nat_money += (int)(np->nat_reserve * money_res * etu); /* maintain units */ - prod_ship(etu, x, bp, 0); - prod_plane(etu, x, bp, 0); - prod_land(etu, x, bp, 0); + prod_ship(etu, i, bp, 0); + prod_plane(etu, i, bp, 0); + prod_land(etu, i, bp, 0); /* produce all sects */ - produce_sect(x, etu, bp, p_sect); + produce_sect(i, etu, bp, p_sect); /* build units */ - prod_ship(etu, x, bp, 1); - prod_plane(etu, x, bp, 1); - prod_land(etu, x, bp, 1); + prod_ship(etu, i, bp, 1); + prod_plane(etu, i, bp, 1); + prod_land(etu, i, bp, 1); } logerror("done producing for countries."); diff --git a/src/util/files.c b/src/util/files.c index 964e9f29e..c247bc9f8 100644 --- a/src/util/files.c +++ b/src/util/files.c @@ -174,8 +174,8 @@ main(int argc, char *argv[]) printf("Can't make telegram directory\n"); exit(1); } - for (x = MAXNOC - 1; x >= 0; x--) { - filename = mailbox(buf, x); + for (i = 0; i < MAXNOC; i++) { + filename = mailbox(buf, i); close(creat(filename, S_IRWUG)); } close(creat(annfil, S_IRWUG));