From 57717b5bc1ab5a3a8cc3fb2d28ca145845355d69 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 21 Mar 2009 09:24:45 +0100 Subject: [PATCH] Clean up unreadable assignments within if conditionals Pinpointed assignments within if conditionals with spatch -sp_file tests/bad_assign.cocci (from coccinelle-0.1.4). Cherry-picked diff hunks affecting conditionals split over multiple lines, and cleaned them up. --- src/lib/commands/buil.c | 8 ++++---- src/lib/commands/cede.c | 6 +++--- src/lib/commands/chan.c | 13 ++++++------- src/lib/commands/coll.c | 5 +++-- src/lib/commands/decl.c | 7 ++++--- src/lib/commands/demo.c | 5 +++-- src/lib/commands/edit.c | 7 ++++--- src/lib/commands/load.c | 40 +++++++++++++++++--------------------- src/lib/commands/lten.c | 3 +-- src/lib/commands/mfir.c | 6 +++--- src/lib/commands/miss.c | 14 ++++++------- src/lib/commands/reje.c | 6 +++--- src/lib/commands/setres.c | 7 ++++--- src/lib/commands/setsect.c | 7 ++++--- src/lib/subs/attsub.c | 16 +++++++-------- 15 files changed, 75 insertions(+), 75 deletions(-) diff --git a/src/lib/commands/buil.c b/src/lib/commands/buil.c index fadcb56c..a7a1cee2 100644 --- a/src/lib/commands/buil.c +++ b/src/lib/commands/buil.c @@ -86,10 +86,10 @@ buil(void) char buf[1024]; natp = getnatp(player->cnum); - if ((p = - getstarg(player->argp[1], - "Build (ship, nuke, bridge, plane, land unit, tower)? ", - buf)) == 0) + p = getstarg(player->argp[1], + "Build (ship, nuke, bridge, plane, land unit, tower)? ", + buf); + if (p == 0) return RET_SYN; what = *p; diff --git a/src/lib/commands/cede.c b/src/lib/commands/cede.c index bb35322f..656a2eb6 100644 --- a/src/lib/commands/cede.c +++ b/src/lib/commands/cede.c @@ -76,9 +76,9 @@ cede(void) if (is_sector && is_ship) { int type; - if ((p = - getstarg(player->argp[3], "Cede sectors or ships (se, sh)? ", - buf)) == 0) + p = getstarg(player->argp[3], "Cede sectors or ships (se, sh)? ", + buf); + if (p == 0) return RET_FAIL; if (strlen(p) > 4) p[2] = 0; diff --git a/src/lib/commands/chan.c b/src/lib/commands/chan.c index 90095689..21903f29 100644 --- a/src/lib/commands/chan.c +++ b/src/lib/commands/chan.c @@ -46,9 +46,8 @@ chan(void) char buf[1024]; struct natstr *us; - if ((p = - getstarg(player->argp[1], "country name or representative? ", - buf)) == 0) + p = getstarg(player->argp[1], "country name or representative? ", buf); + if (p == 0) return RET_SYN; us = getnatp(player->cnum); if (us->nat_stat == STAT_VIS) { @@ -76,8 +75,8 @@ chan(void) charge = us->nat_money / 10; } } - if ((p = - getstarg(player->argp[2], "New country name -- ", buf)) == 0) + p = getstarg(player->argp[2], "New country name -- ", buf); + if (p == 0) return RET_SYN; if (!check_nat_name(p)) return RET_FAIL; @@ -90,8 +89,8 @@ chan(void) case 'p': case 'r': pr("(note: these are stored in plain text.)\n"); - if ((p = getstarg(player->argp[2], - "New representative name -- ", buf)) == 0) + p = getstarg(player->argp[2], "New representative name -- ", buf); + if (p == 0) return RET_SYN; p[sizeof(us->nat_pnam) - 1] = 0; strcpy(us->nat_pnam, p); diff --git a/src/lib/commands/coll.c b/src/lib/commands/coll.c index 6d002744..667c2e1f 100644 --- a/src/lib/commands/coll.c +++ b/src/lib/commands/coll.c @@ -78,8 +78,9 @@ coll(void) } pr("You are owed $%.2f on that loan.\n", owed); - if (!(p = getstarg(player->argp[2], - "What sector do you wish to confiscate? ", buf))) + p = getstarg(player->argp[2], + "What sector do you wish to confiscate? ", buf); + if (!p) return RET_SYN; if (!check_loan_ok(&loan)) return RET_FAIL; diff --git a/src/lib/commands/decl.c b/src/lib/commands/decl.c index 62a1ee93..3401efc0 100644 --- a/src/lib/commands/decl.c +++ b/src/lib/commands/decl.c @@ -46,9 +46,10 @@ decl(void) char *p; char buf[1024]; - if (!(p = getstarg(player->argp[1], - "alliance, friendly, neutrality, hostility, or war? ", - buf))) + p = getstarg(player->argp[1], + "alliance, friendly, neutrality, hostility, or war? ", + buf); + if (!p) return RET_SYN; switch (*p) { case 'a': diff --git a/src/lib/commands/demo.c b/src/lib/commands/demo.c index 99221095..9daddc53 100644 --- a/src/lib/commands/demo.c +++ b/src/lib/commands/demo.c @@ -61,8 +61,9 @@ demo(void) if (!(p = getstarg(player->argp[2], "Number to de-mobilize : ", buf))) return RET_SYN; number = atoi(p); - if (!(p = getstarg(player->argp[3], - "New civilians on active reserve? (y/n) ", buf))) + p = getstarg(player->argp[3], + "New civilians on active reserve? (y/n) ", buf); + if (!p) return RET_SYN; if (*p != 'y' && *p != 'n') return RET_SYN; diff --git a/src/lib/commands/edit.c b/src/lib/commands/edit.c index 3a8656f7..6b370b3f 100644 --- a/src/lib/commands/edit.c +++ b/src/lib/commands/edit.c @@ -85,9 +85,10 @@ edit(void) char buf[1024]; char ewhat; - if ((what = getstarg(player->argp[1], - "Edit What (country, land, ship, plane, nuke, unit)? ", - buf)) == 0) + what = getstarg(player->argp[1], + "Edit What (country, land, ship, plane, nuke, unit)? ", + buf); + if (what == 0) return RET_SYN; ewhat = what[0]; switch (ewhat) { diff --git a/src/lib/commands/load.c b/src/lib/commands/load.c index 96af9887..c5e84cd9 100644 --- a/src/lib/commands/load.c +++ b/src/lib/commands/load.c @@ -166,23 +166,21 @@ load(void) switch (type) { case EF_PLANE: - if (0 != - (retval = - load_plane_ship(§, &ship, noisy, load_unload, - &nships))) + retval = load_plane_ship(§, &ship, noisy, load_unload, + &nships); + if (retval != 0) return retval; break; case EF_LAND: - if (0 != - (retval = - load_land_ship(§, &ship, noisy, load_unload, - &nships))) + retval = load_land_ship(§, &ship, noisy, load_unload, + &nships); + if (retval != 0) return retval; break; case EF_SECTOR: - if (0 != - (retval = - load_comm_ship(§, &ship, ich, load_unload, &nships))) + retval = load_comm_ship(§, &ship, ich, load_unload, + &nships); + if (retval != 0) return retval; } /* load/unload plague */ @@ -281,23 +279,21 @@ lload(void) switch (type) { case EF_LAND: - if (0 != - (retval = - load_land_land(§, &land, noisy, load_unload, - &nunits))) + retval = load_land_land(§, &land, noisy, load_unload, + &nunits); + if (retval != 0) return retval; break; case EF_PLANE: - if (0 != - (retval = - load_plane_land(§, &land, noisy, load_unload, - &nunits))) + retval = load_plane_land(§, &land, noisy, load_unload, + &nunits); + if (retval != 0) return retval; break; case EF_SECTOR: - if (0 != - (retval = - load_comm_land(§, &land, ich, load_unload, &nunits))) + retval = load_comm_land(§, &land, ich, load_unload, + &nunits); + if (retval != 0) return retval; } /* load/unload plague */ diff --git a/src/lib/commands/lten.c b/src/lib/commands/lten.c index 7341eb79..60b7008a 100644 --- a/src/lib/commands/lten.c +++ b/src/lib/commands/lten.c @@ -74,8 +74,7 @@ ltend(void) while (nxtitem(&tenders, &tender)) { if (!player->owner) continue; - if ((p = - getstarg(player->argp[3], "Amount to transfer? ", buf)) == 0) + if (!(p = getstarg(player->argp[3], "Amount to transfer? ", buf))) return RET_FAIL; if (!check_ship_ok(&tender)) return RET_FAIL; diff --git a/src/lib/commands/mfir.c b/src/lib/commands/mfir.c index e2f973c6..c4b89c4e 100644 --- a/src/lib/commands/mfir.c +++ b/src/lib/commands/mfir.c @@ -98,9 +98,9 @@ multifire(void) emp_initque(&fired); emp_initque(&defended); - if (!(p = getstarg(player->argp[1], - "Firing from ship(s), sect(s), or land unit(s)? ", - buf))) + p = getstarg(player->argp[1], + "Firing from ship(s), sect(s), or land unit(s)? ", buf); + if (!p) return RET_SYN; type = ef_byname_from(p, ef_with_guns); if (opt_NO_FORT_FIRE && type == EF_SECTOR) { diff --git a/src/lib/commands/miss.c b/src/lib/commands/miss.c index 7170de85..a1243860 100644 --- a/src/lib/commands/miss.c +++ b/src/lib/commands/miss.c @@ -62,9 +62,9 @@ mission(void) struct nstr_item ni; char buf[1024]; - if ((p = - getstarg(player->argp[1], "Ship, plane or land unit (p,sh,la)? ", - buf)) == 0) + p = getstarg(player->argp[1], "Ship, plane or land unit (p,sh,la)? ", + buf); + if (p == 0) return RET_SYN; type = ef_byname_from(p, ef_with_missions); if (type < 0) { @@ -74,10 +74,10 @@ mission(void) if (!snxtitem(&ni, type, player->argp[2], NULL)) return RET_SYN; - if ((p = - getstarg(player->argp[3], - "Mission (int, sup, osup, dsup, esc, res, air, query, clear)? ", - buf)) == 0) + p = getstarg(player->argp[3], + "Mission (int, sup, osup, dsup, esc, res, air, query, clear)? ", + buf); + if (p == 0) return RET_SYN; /* diff --git a/src/lib/commands/reje.c b/src/lib/commands/reje.c index 8452079f..4c165ca8 100644 --- a/src/lib/commands/reje.c +++ b/src/lib/commands/reje.c @@ -59,9 +59,9 @@ reje(void) pr("That's not one of the choices!\n"); return RET_SYN; } - if ((p = - getstarg(player->argp[2], - "mail, treaties, loans, or announcements? ", buf)) == 0) + p = getstarg(player->argp[2], + "mail, treaties, loans, or announcements? ", buf); + if (p == 0) return RET_SYN; switch (*p) { case 'a': diff --git a/src/lib/commands/setres.c b/src/lib/commands/setres.c index 383068da..0a3c1067 100644 --- a/src/lib/commands/setres.c +++ b/src/lib/commands/setres.c @@ -50,9 +50,10 @@ setres(void) struct nstr_sect nstr; char buf[1024]; - if ((what = getstarg(player->argp[1], - "Set What (iron, gold, oil, uranium, fertility)? ", - buf)) == 0) + what = getstarg(player->argp[1], + "Set What (iron, gold, oil, uranium, fertility)? ", + buf); + if (what == 0) return RET_SYN; switch (what[0]) { case 'i': diff --git a/src/lib/commands/setsect.c b/src/lib/commands/setsect.c index 9157636e..117e7315 100644 --- a/src/lib/commands/setsect.c +++ b/src/lib/commands/setsect.c @@ -54,9 +54,10 @@ setsector(void) char buf[1024]; char char0, char1; - if ((what = getstarg(player->argp[1], - "Give What (iron, gold, oil, uranium, fertility, owner, eff., mob., work, avail., oldown, mines)? ", - buf)) == 0) + what = getstarg(player->argp[1], + "Give What (iron, gold, oil, uranium, fertility, owner, eff., mob., work, avail., oldown, mines)? ", + buf); + if (what == 0) return RET_SYN; char0 = what[0]; char1 = what[1]; diff --git a/src/lib/subs/attsub.c b/src/lib/subs/attsub.c index 64b462bd..1e958a90 100644 --- a/src/lib/subs/attsub.c +++ b/src/lib/subs/attsub.c @@ -709,29 +709,29 @@ att_ask_support(int offset, int *fortp, int *shipp, int *landp, *fortp = *shipp = 0; *landp = *planep = 0; - if (!(p = getstarg(player->argp[offset], "Use fort support? ", - buf))) + p = getstarg(player->argp[offset], "Use fort support? ", buf); + if (!p) return RET_SYN; if ((*p == 'y') || (*p == 'Y')) *fortp = 1; - if (!(p = getstarg(player->argp[offset + 1], "Use ship support? ", - buf))) + p = getstarg(player->argp[offset + 1], "Use ship support? ", buf); + if (!p) return RET_SYN; if ((*p == 'y') || (*p == 'Y')) *shipp = 1; - if (!(p = getstarg(player->argp[offset + 2], "Use land support? ", - buf))) + p = getstarg(player->argp[offset + 2], "Use land support? ", buf); + if (!p) return RET_SYN; if ((*p == 'y') || (*p == 'Y')) *landp = 1; - if (!(p = getstarg(player->argp[offset + 3], "Use plane support? ", - buf))) + p = getstarg(player->argp[offset + 3], "Use plane support? ", buf); + if (!p) return RET_SYN; if ((*p == 'y') || (*p == 'Y'))