Fix extra prompt after abort due to misuse of snxtitem()

The old code used getstarg() to get an argument with a different
prompt than snxtitem() uses, then passed the value to snxtitem()
unchecked.  If the player aborts, getstarg() returns a null pointer,
and snxtitem() prompts again.  Affected:

* load/lload plane/land third argument; load_plane_ship(),
  load_land_ship(), load_plane_land(), load_land_land()

* bomb, drop, fly, paradrop, recon and sweep second argument;
  get_planes()

* tend and ltend second and fourth argument; ltend(), tend(),
  tend_land()

* mission second argument; mission()

Fix by making snxtitem() taking a prompt argument, null pointer
requests the old prompt.

Use that to simplify multifire() and torp().  Change the other callers
to pass NULL.
This commit is contained in:
Markus Armbruster 2008-07-26 21:35:00 -04:00
parent 9f4ce71a54
commit 3cc8de8aef
67 changed files with 108 additions and 113 deletions

View file

@ -666,7 +666,7 @@ extern void shp_missdef(struct shpstr *, natid);
extern double shp_mobcost(struct shpstr *); extern double shp_mobcost(struct shpstr *);
extern void shp_set_tech(struct shpstr *, int); extern void shp_set_tech(struct shpstr *, int);
/* snxtitem.c */ /* snxtitem.c */
extern int snxtitem(struct nstr_item *, int, char *); extern int snxtitem(struct nstr_item *, int, char *, char *);
extern void snxtitem_area(struct nstr_item *, int, extern void snxtitem_area(struct nstr_item *, int,
struct range *); struct range *);
extern void snxtitem_dist(struct nstr_item *, int, int, int, int); extern void snxtitem_dist(struct nstr_item *, int, int, int, int);

View file

@ -55,7 +55,7 @@ arm(void)
char buf[1024]; char buf[1024];
char prompt[128]; char prompt[128];
if (!snxtitem(&ni, EF_PLANE, player->argp[1])) if (!snxtitem(&ni, EF_PLANE, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&ni, &pl)) { while (nxtitem(&ni, &pl)) {
if (!player->owner if (!player->owner
@ -138,7 +138,7 @@ disarm(void)
struct sctstr sect; struct sctstr sect;
char buf[128]; char buf[128];
if (!snxtitem(&ni, EF_PLANE, player->argp[1])) if (!snxtitem(&ni, EF_PLANE, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&ni, &pl)) { while (nxtitem(&ni, &pl)) {
if (!player->owner) if (!player->owner)

View file

@ -59,7 +59,7 @@ army(void)
} }
if (c == '~') if (c == '~')
c = 0; c = 0;
if (!snxtitem(&nstr, EF_LAND, player->argp[2])) if (!snxtitem(&nstr, EF_LAND, player->argp[2], NULL))
return RET_SYN; return RET_SYN;
count = 0; count = 0;
while (nxtitem(&nstr, &land)) { while (nxtitem(&nstr, &land)) {

View file

@ -45,7 +45,7 @@ carg(void)
struct nstr_item ni; struct nstr_item ni;
struct shpstr ship; struct shpstr ship;
if (!snxtitem(&ni, EF_SHIP, player->argp[1])) if (!snxtitem(&ni, EF_SHIP, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
nships = 0; nships = 0;
while (nxtitem(&ni, &ship)) { while (nxtitem(&ni, &ship)) {
@ -94,7 +94,7 @@ lcarg(void)
struct nstr_item ni; struct nstr_item ni;
struct lndstr land; struct lndstr land;
if (!snxtitem(&ni, EF_LAND, player->argp[1])) if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
nunits = 0; nunits = 0;
while (nxtitem(&ni, &land)) { while (nxtitem(&ni, &land)) {

View file

@ -67,7 +67,7 @@ cede(void)
return RET_SYN; return RET_SYN;
if (snxtsct(&ns, p)) if (snxtsct(&ns, p))
is_sector = 1; is_sector = 1;
if (snxtitem(&ni, EF_SHIP, p)) if (snxtitem(&ni, EF_SHIP, p, NULL))
is_ship = 1; is_ship = 1;
if (!is_sector && !is_ship) if (!is_sector && !is_ship)
return RET_SYN; return RET_SYN;

View file

@ -44,7 +44,7 @@ coun(void)
struct nstr_item ni; struct nstr_item ni;
struct natstr nat; struct natstr nat;
if (!snxtitem(&ni, EF_NATION, player->argp[1])) if (!snxtitem(&ni, EF_NATION, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
prdate(); prdate();
pr(" # last access %sstatus country name\n", pr(" # last access %sstatus country name\n",

View file

@ -85,7 +85,7 @@ decl(void)
return RET_SYN; return RET_SYN;
} }
if (!snxtitem(&ni, EF_NATION, player->argp[2])) if (!snxtitem(&ni, EF_NATION, player->argp[2], NULL))
return RET_SYN; return RET_SYN;
who = player->cnum; who = player->cnum;
if (player->god) { if (player->god) {

View file

@ -53,7 +53,7 @@ fina(void)
pr("Loans are not enabled.\n"); pr("Loans are not enabled.\n");
return RET_FAIL; return RET_FAIL;
} }
if (!snxtitem(&ni, EF_LOAN, "*")) if (!snxtitem(&ni, EF_LOAN, "*", NULL))
return RET_SYN; return RET_SYN;
(void)time(&now); (void)time(&now);
pr("\n"); pr("\n");

View file

@ -59,7 +59,7 @@ flee(void)
} }
if (c == '~') if (c == '~')
c = 0; c = 0;
if (!snxtitem(&nstr, EF_SHIP, player->argp[2])) if (!snxtitem(&nstr, EF_SHIP, player->argp[2], NULL))
return RET_SYN; return RET_SYN;
count = 0; count = 0;
while (nxtitem(&nstr, &ship)) { while (nxtitem(&nstr, &ship)) {

View file

@ -51,7 +51,7 @@ foll(void)
pr("The SAIL option is not enabled, so this command is not valid.\n"); pr("The SAIL option is not enabled, so this command is not valid.\n");
return RET_FAIL; return RET_FAIL;
} }
if (!snxtitem(&nstr, EF_SHIP, player->argp[1])) if (!snxtitem(&nstr, EF_SHIP, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
cp = getstarg(player->argp[2], "leader? ", buf); cp = getstarg(player->argp[2], "leader? ", buf);
if (cp == 0) if (cp == 0)

View file

@ -47,7 +47,7 @@ fort(void)
char *p; char *p;
char buf[1024]; char buf[1024];
if (!snxtitem(&ni, EF_LAND, player->argp[1])) if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
p = getstarg(player->argp[2], "Amount: ", buf); p = getstarg(player->argp[2], "Amount: ", buf);
if (p == 0 || *p == 0) if (p == 0 || *p == 0)

View file

@ -56,7 +56,7 @@ hard(void)
long cash; long cash;
struct natstr *natp; struct natstr *natp;
if (!snxtitem(&ni, EF_PLANE, player->argp[1])) if (!snxtitem(&ni, EF_PLANE, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
if ((p = getstarg(player->argp[2], "Increase by? ", buf)) == 0 if ((p = getstarg(player->argp[2], "Increase by? ", buf)) == 0
|| *p == 0) || *p == 0)

View file

@ -44,7 +44,7 @@ land(void)
struct nstr_item ni; struct nstr_item ni;
struct lndstr land; struct lndstr land;
if (!snxtitem(&ni, EF_LAND, player->argp[1])) if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
nunits = noff = 0; nunits = noff = 0;

View file

@ -62,7 +62,7 @@ laun(void)
struct plchrstr *pcp; struct plchrstr *pcp;
int retval, gone; int retval, gone;
if (!snxtitem(&nstr, EF_PLANE, player->argp[1])) if (!snxtitem(&nstr, EF_PLANE, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&nstr, &plane)) { while (nxtitem(&nstr, &plane)) {
if (plane.pln_own != player->cnum) if (plane.pln_own != player->cnum)

View file

@ -49,7 +49,7 @@ ldump(void)
struct natstr *np; struct natstr *np;
time_t now; time_t now;
if (!snxtitem(&ni, EF_LAND, player->argp[1])) if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
prdate(); prdate();
nunits = 0; nunits = 0;

View file

@ -48,7 +48,7 @@ ledg(void)
pr("Loans are not enabled.\n"); pr("Loans are not enabled.\n");
return RET_FAIL; return RET_FAIL;
} }
if (!snxtitem(&nstr, EF_LOAN, player->argp[1])) if (!snxtitem(&nstr, EF_LOAN, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
pr("\n... %s Ledger ...\n", cname(player->cnum)); pr("\n... %s Ledger ...\n", cname(player->cnum));
nloan = 0; nloan = 0;

View file

@ -102,7 +102,7 @@ load(void)
noisy = isdigit(*p); noisy = isdigit(*p);
if (!snxtitem(&nbst, EF_SHIP, p)) if (!snxtitem(&nbst, EF_SHIP, p, NULL))
return RET_SYN; return RET_SYN;
load_unload = **player->argp == 'l' ? LOAD : UNLOAD; load_unload = **player->argp == 'l' ? LOAD : UNLOAD;
@ -237,7 +237,7 @@ lload(void)
noisy = isdigit(*p); noisy = isdigit(*p);
if (!snxtitem(&nbst, EF_LAND, p)) if (!snxtitem(&nbst, EF_LAND, p, NULL))
return RET_SYN; return RET_SYN;
load_unload = player->argp[0][1] == 'l' ? LOAD : UNLOAD; load_unload = player->argp[0][1] == 'l' ? LOAD : UNLOAD;
@ -370,8 +370,10 @@ load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
} }
sprintf(prompt, "Plane(s) to %s %s? ", sprintf(prompt, "Plane(s) to %s %s? ",
load_unload == LOAD ? "load onto" : "unload from", prship(sp)); load_unload == LOAD ? "load onto" : "unload from", prship(sp));
if (!snxtitem(&ni, EF_PLANE, p = getstarg(player->argp[3], prompt, buf);
p = getstarg(player->argp[3], prompt, buf))) if (!p)
return RET_SYN;
if (!snxtitem(&ni, EF_PLANE, p, NULL))
return RET_SYN; return RET_SYN;
if (!still_ok_ship(sectp, sp)) if (!still_ok_ship(sectp, sp))
@ -505,8 +507,10 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
} }
sprintf(prompt, "Land unit(s) to %s %s? ", sprintf(prompt, "Land unit(s) to %s %s? ",
load_unload == LOAD ? "load onto" : "unload from", prship(sp)); load_unload == LOAD ? "load onto" : "unload from", prship(sp));
if (!snxtitem(&ni, EF_LAND, p = getstarg(player->argp[3], prompt, buf);
p = getstarg(player->argp[3], prompt, buf))) if (!p)
return RET_SYN;
if (!snxtitem(&ni, EF_LAND, p, NULL))
return RET_SYN; return RET_SYN;
if (!still_ok_ship(sectp, sp)) if (!still_ok_ship(sectp, sp))
@ -767,8 +771,10 @@ load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
} }
sprintf(prompt, "Plane(s) to %s %s? ", sprintf(prompt, "Plane(s) to %s %s? ",
load_unload == LOAD ? "load onto" : "unload from", prland(lp)); load_unload == LOAD ? "load onto" : "unload from", prland(lp));
if (!snxtitem(&ni, EF_PLANE, p = getstarg(player->argp[3], prompt, buf);
p = getstarg(player->argp[3], prompt, buf))) if (!p)
return RET_SYN;
if (!snxtitem(&ni, EF_PLANE, p, NULL))
return RET_SYN; return RET_SYN;
if (!still_ok_land(sectp, lp)) if (!still_ok_land(sectp, lp))
@ -958,8 +964,10 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
} }
sprintf(prompt, "Land unit(s) to %s %s? ", sprintf(prompt, "Land unit(s) to %s %s? ",
load_unload == LOAD ? "load onto" : "unload from", prland(lp)); load_unload == LOAD ? "load onto" : "unload from", prland(lp));
if (!snxtitem(&ni, EF_LAND, p = getstarg(player->argp[3], prompt, buf);
p = getstarg(player->argp[3], prompt, buf))) if (!p)
return RET_SYN;
if (!snxtitem(&ni, EF_LAND, p, NULL))
return RET_SYN; return RET_SYN;
if (!still_ok_land(sectp, lp)) if (!still_ok_land(sectp, lp))

View file

@ -70,7 +70,7 @@ do_look(short type)
if (CANT_HAPPEN(type != EF_LAND && type != EF_SHIP)) if (CANT_HAPPEN(type != EF_LAND && type != EF_SHIP))
type = EF_SHIP; type = EF_SHIP;
if (!snxtitem(&ni, type, player->argp[1])) if (!snxtitem(&ni, type, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
if ((bitmap = malloc((WORLD_X * WORLD_Y) / 8)) == 0) { if ((bitmap = malloc((WORLD_X * WORLD_Y) / 8)) == 0) {
logerror("malloc failed in do_look\n"); logerror("malloc failed in do_look\n");

View file

@ -44,7 +44,9 @@ lost(void)
struct loststr lost; struct loststr lost;
time_t now; time_t now;
if (!snxtitem(&ni, EF_LOST, player->argp[1] ? player->argp[1] : "*")) if (!snxtitem(&ni, EF_LOST,
player->argp[1] ? player->argp[1] : "*",
NULL))
return RET_SYN; return RET_SYN;
prdate(); prdate();

View file

@ -44,7 +44,7 @@ lsta(void)
struct lndstr land; struct lndstr land;
struct lchrstr *lcp; struct lchrstr *lcp;
if (!snxtitem(&ni, EF_LAND, player->argp[1])) if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
nunits = 0; nunits = 0;

View file

@ -69,8 +69,7 @@ ltend(void)
if (!(ip = whatitem(player->argp[1], "Transfer what commodity? "))) if (!(ip = whatitem(player->argp[1], "Transfer what commodity? ")))
return RET_SYN; return RET_SYN;
if (!snxtitem(&tenders, EF_SHIP, if (!snxtitem(&tenders, EF_SHIP, player->argp[2], "Tender(s)? "))
getstarg(player->argp[2], "Tender(s)? ", buf)))
return RET_SYN; return RET_SYN;
while (nxtitem(&tenders, &tender)) { while (nxtitem(&tenders, &tender)) {
if (!player->owner) if (!player->owner)
@ -95,8 +94,7 @@ ltend(void)
return RET_FAIL; return RET_FAIL;
} }
if (!snxtitem(&targets, EF_LAND, if (!snxtitem(&targets, EF_LAND,
getstarg(player->argp[4], "Units to be tended? ", player->argp[4], "Units to be tended? "))
buf)))
return RET_SYN; return RET_SYN;
if (!check_ship_ok(&tender)) if (!check_ship_ok(&tender))
return RET_FAIL; return RET_FAIL;

View file

@ -50,7 +50,7 @@ march(void)
double minmob, maxmob; double minmob, maxmob;
int together; int together;
if (!snxtitem(&ni_land, EF_LAND, player->argp[1])) if (!snxtitem(&ni_land, EF_LAND, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
lnd_sel(&ni_land, &land_list); lnd_sel(&ni_land, &land_list);
lnd_mar(&land_list, &minmob, &maxmob, &together, player->cnum); lnd_mar(&land_list, &minmob, &maxmob, &together, player->cnum);

View file

@ -111,11 +111,7 @@ multifire(void)
pr("Ships, land units or sectors only!\n"); pr("Ships, land units or sectors only!\n");
return RET_SYN; return RET_SYN;
} }
if ((ptr = getstarg(player->argp[2], "Firing from? ", buf)) == 0 if (!snxtitem(&nbst, type, player->argp[2], "Firing from? "))
|| *ptr == '\0')
return RET_SYN;
if (!snxtitem(&nbst, type, ptr))
return RET_SYN; return RET_SYN;
while (nxtitem(&nbst, &item)) { while (nxtitem(&nbst, &item)) {

View file

@ -52,7 +52,7 @@ mine(void)
int shells; int shells;
int mines_avail; int mines_avail;
if (!snxtitem(&ni, EF_SHIP, player->argp[1])) if (!snxtitem(&ni, EF_SHIP, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
mines = onearg(player->argp[2], mines = onearg(player->argp[2],
"Drop how many mines from each ship? "); "Drop how many mines from each ship? ");
@ -101,7 +101,7 @@ landmine(void)
int total_mines_laid; int total_mines_laid;
char prompt[128]; char prompt[128];
if (!snxtitem(&ni, EF_LAND, player->argp[1])) if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&ni, &land)) { while (nxtitem(&ni, &land)) {
if (!player->owner) if (!player->owner)

View file

@ -57,7 +57,6 @@ mission(void)
struct empobj *gp; struct empobj *gp;
int num = 0, mobmax, mobused, dist; int num = 0, mobmax, mobused, dist;
struct nstr_item ni; struct nstr_item ni;
char prompt[128];
char buf[1024]; char buf[1024];
if ((p = if ((p =
@ -69,9 +68,7 @@ mission(void)
pr("Ships, land units or planes only! (s, l, p)\n"); pr("Ships, land units or planes only! (s, l, p)\n");
return RET_SYN; return RET_SYN;
} }
sprintf(prompt, "%s(s)? ", ef_nameof(type)); if (!snxtitem(&ni, type, player->argp[2], NULL))
p = getstarg(player->argp[2], prompt, buf);
if (!snxtitem(&ni, type, p))
return RET_SYN; return RET_SYN;
if ((p = if ((p =

View file

@ -51,7 +51,7 @@ mobq(void)
pr("The SAIL option is not enabled, so this command is not valid.\n"); pr("The SAIL option is not enabled, so this command is not valid.\n");
return RET_FAIL; return RET_FAIL;
} }
if (!snxtitem(&nstr, EF_SHIP, player->argp[1])) if (!snxtitem(&nstr, EF_SHIP, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
oldmq = player->argp[2]; oldmq = player->argp[2];
if (oldmq) { if (oldmq) {

View file

@ -48,7 +48,7 @@ morale(void)
char mess[128]; char mess[128];
char buf[1024]; char buf[1024];
if (!snxtitem(&np, EF_LAND, player->argp[1])) if (!snxtitem(&np, EF_LAND, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&np, &land)) { while (nxtitem(&np, &land)) {
if (!player->owner || land.lnd_own == 0) if (!player->owner || land.lnd_own == 0)

View file

@ -49,7 +49,7 @@ name(void)
struct nstr_item nb; struct nstr_item nb;
char buf[1024]; char buf[1024];
if (!snxtitem(&nb, EF_SHIP, player->argp[1])) if (!snxtitem(&nb, EF_SHIP, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&nb, &ship)) { while (nxtitem(&nb, &ship)) {
if (!player->owner) if (!player->owner)

View file

@ -53,7 +53,7 @@ navi(void)
double minmob, maxmob; double minmob, maxmob;
int together; int together;
if (!snxtitem(&ni_ship, EF_SHIP, player->argp[1])) if (!snxtitem(&ni_ship, EF_SHIP, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
shp_sel(&ni_ship, &ship_list); shp_sel(&ni_ship, &ship_list);
shp_nav(&ship_list, &minmob, &maxmob, &together, player->cnum); shp_nav(&ship_list, &minmob, &maxmob, &together, player->cnum);
@ -199,7 +199,7 @@ do_unit_move(struct emp_qelem *ulist, int *together,
*/ */
case 'M': case 'M':
do_map(bmap_flag, leader->ef_type, player->argp[1], do_map(bmap_flag, leader->ef_type, player->argp[1],
player->argp[2]); player->argp[2]);
skip = 1; skip = 1;
continue; continue;
case 'f': case 'f':

View file

@ -45,7 +45,7 @@ ndump(void)
time_t now; time_t now;
int nnukes; int nnukes;
if (!snxtitem(&nstr, EF_NUKE, player->argp[1])) if (!snxtitem(&nstr, EF_NUKE, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
prdate(); prdate();
if (player->god) if (player->god)

View file

@ -61,7 +61,7 @@ news(void)
char num[128]; char num[128];
char *verb; char *verb;
if (!snxtitem(&nstr, EF_NEWS, "*")) if (!snxtitem(&nstr, EF_NEWS, "*", NULL))
return RET_SYN; return RET_SYN;
memset(page_has_news, 0, sizeof(page_has_news)); memset(page_has_news, 0, sizeof(page_has_news));
memset(sectors_taken, 0, sizeof(sectors_taken)); memset(sectors_taken, 0, sizeof(sectors_taken));

View file

@ -46,7 +46,7 @@ nuke(void)
struct nukstr nuk; struct nukstr nuk;
struct plnstr plane; struct plnstr plane;
if (!snxtitem(&nstr, EF_NUKE, player->argp[1])) if (!snxtitem(&nstr, EF_NUKE, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
nnukes = noff = 0; nnukes = noff = 0;
while (nxtitem(&nstr, &nuk)) { while (nxtitem(&nstr, &nuk)) {

View file

@ -73,7 +73,7 @@ orde(void)
char buf[1024]; char buf[1024];
char prompt[128]; char prompt[128];
if (!snxtitem(&nb, EF_SHIP, player->argp[1])) if (!snxtitem(&nb, EF_SHIP, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
while (!player->aborted && nxtitem(&nb, (&ship))) { while (!player->aborted && nxtitem(&nb, (&ship))) {
if (!player->owner || ship.shp_own == 0) if (!player->owner || ship.shp_own == 0)
@ -357,7 +357,7 @@ qorde(void)
struct nstr_item nb; struct nstr_item nb;
struct shpstr ship; struct shpstr ship;
if (!snxtitem(&nb, EF_SHIP, player->argp[1])) if (!snxtitem(&nb, EF_SHIP, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&nb, (&ship))) { while (nxtitem(&nb, (&ship))) {
if (!player->owner || ship.shp_own == 0) if (!player->owner || ship.shp_own == 0)
@ -419,7 +419,7 @@ sorde(void)
struct shpstr ship; struct shpstr ship;
char buf[1024]; char buf[1024];
if (!snxtitem(&nb, EF_SHIP, player->argp[1])) if (!snxtitem(&nb, EF_SHIP, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&nb, (&ship))) { while (nxtitem(&nb, (&ship))) {
if (!player->owner || ship.shp_own == 0) if (!player->owner || ship.shp_own == 0)

View file

@ -52,7 +52,7 @@ payo(void)
pr("Tradeships are not enabled.\n"); pr("Tradeships are not enabled.\n");
return RET_FAIL; return RET_FAIL;
} }
if (!snxtitem(&ni, EF_SHIP, player->argp[1])) if (!snxtitem(&ni, EF_SHIP, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
nships = 0; nships = 0;

View file

@ -43,7 +43,7 @@ pboa(void)
struct nstr_item np; struct nstr_item np;
struct plnstr plane; struct plnstr plane;
if (!snxtitem(&np, EF_PLANE, player->argp[1])) if (!snxtitem(&np, EF_PLANE, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&np, &plane)) { while (nxtitem(&np, &plane)) {
getsect(plane.pln_x, plane.pln_y, &sect); getsect(plane.pln_x, plane.pln_y, &sect);

View file

@ -50,7 +50,7 @@ pdump(void)
int n, i; int n, i;
time_t now; time_t now;
if (!snxtitem(&np, EF_PLANE, player->argp[1])) if (!snxtitem(&np, EF_PLANE, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
prdate(); prdate();

View file

@ -47,7 +47,7 @@ plan(void)
struct nstr_item np; struct nstr_item np;
struct plnstr plane; struct plnstr plane;
if (!snxtitem(&np, EF_PLANE, player->argp[1])) if (!snxtitem(&np, EF_PLANE, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
nplanes = noff = 0; nplanes = noff = 0;
while (nxtitem(&np, &plane)) { while (nxtitem(&np, &plane)) {

View file

@ -94,7 +94,7 @@ powe(void)
if (player->argp[i]) { if (player->argp[i]) {
if (player->argp[i][0] == 'c') { if (player->argp[i][0] == 'c') {
if (!snxtitem(&ni, EF_NATION, player->argp[i + 1])) if (!snxtitem(&ni, EF_NATION, player->argp[i + 1], NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&ni, &nat)) { while (nxtitem(&ni, &nat)) {
if (nat.nat_stat == STAT_UNUSED) if (nat.nat_stat == STAT_UNUSED)

View file

@ -43,7 +43,7 @@ pstat(void)
struct nstr_item np; struct nstr_item np;
struct plnstr plane; struct plnstr plane;
if (!snxtitem(&np, EF_PLANE, player->argp[1])) if (!snxtitem(&np, EF_PLANE, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
nplanes = 0; nplanes = 0;
while (nxtitem(&np, &plane)) { while (nxtitem(&np, &plane)) {

View file

@ -90,7 +90,7 @@ radar(short type)
case NS_LIST: case NS_LIST:
case NS_GROUP: case NS_GROUP:
/* assumes a NS_LIST return is a unit no */ /* assumes a NS_LIST return is a unit no */
if (!snxtitem(&ni, type, cp)) { if (!snxtitem(&ni, type, cp, NULL)) {
pr("Specify at least one %s\n", ef_nameof(type)); pr("Specify at least one %s\n", ef_nameof(type));
return RET_SYN; return RET_SYN;
} }

View file

@ -46,7 +46,7 @@ range(void)
char *p; char *p;
char buf[1024]; char buf[1024];
if (!snxtitem(&np, EF_PLANE, player->argp[1])) if (!snxtitem(&np, EF_PLANE, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&np, &plane)) { while (nxtitem(&np, &plane)) {
if (!player->owner || plane.pln_own == 0) if (!player->owner || plane.pln_own == 0)
@ -79,7 +79,7 @@ lrange(void)
char prompt[128]; char prompt[128];
char buf[1024]; char buf[1024];
if (!snxtitem(&np, EF_LAND, player->argp[1])) if (!snxtitem(&np, EF_LAND, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&np, &land)) { while (nxtitem(&np, &land)) {
if (!player->owner || land.lnd_own == 0) if (!player->owner || land.lnd_own == 0)

View file

@ -80,7 +80,7 @@ reje(void)
pr("That's not one of the choices!\n"); pr("That's not one of the choices!\n");
return RET_SYN; return RET_SYN;
} }
if (!snxtitem(&ni, EF_NATION, player->argp[3])) if (!snxtitem(&ni, EF_NATION, player->argp[3], NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&ni, &nat)) { while (nxtitem(&ni, &nat)) {
if (nat.nat_stat == STAT_GOD) { if (nat.nat_stat == STAT_GOD) {

View file

@ -50,7 +50,7 @@ repo(void)
struct natstr nat; struct natstr nat;
struct nstr_item ni; struct nstr_item ni;
if (!snxtitem(&ni, EF_NATION, player->argp[1])) if (!snxtitem(&ni, EF_NATION, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
prdate(); prdate();
natp = getnatp(player->cnum); natp = getnatp(player->cnum);

View file

@ -83,7 +83,7 @@ retreat(short type)
type = EF_SHIP; type = EF_SHIP;
rflagsc = type == EF_SHIP ? shp_rflagsc : lnd_rflagsc; rflagsc = type == EF_SHIP ? shp_rflagsc : lnd_rflagsc;
if (!snxtitem(&ni, type, player->argp[1])) if (!snxtitem(&ni, type, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
nunits = 0; nunits = 0;
if (player->argp[2] != NULL) if (player->argp[2] != NULL)

View file

@ -45,7 +45,7 @@ sabo(void)
double odds; double odds;
int dam; int dam;
if (!snxtitem(&ni, EF_LAND, player->argp[1])) if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&ni, &land)) { while (nxtitem(&ni, &land)) {

View file

@ -144,7 +144,7 @@ sail(void)
pr("The SAIL option is not enabled, so this command is not valid.\n"); pr("The SAIL option is not enabled, so this command is not valid.\n");
return RET_FAIL; return RET_FAIL;
} }
if (!snxtitem(&nstr, EF_SHIP, player->argp[1])) if (!snxtitem(&nstr, EF_SHIP, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
cp = player->argp[2]; cp = player->argp[2];
if (*player->argp[0] == 'u' || (cp && !strcmp(cp, "-"))) if (*player->argp[0] == 'u' || (cp && !strcmp(cp, "-")))

View file

@ -77,7 +77,7 @@ scra(void)
sprintf(prompt, "%s(s)? ", ef_nameof(type)); sprintf(prompt, "%s(s)? ", ef_nameof(type));
if ((p = getstarg(player->argp[2], prompt, buf)) == 0) if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
return RET_SYN; return RET_SYN;
if (!snxtitem(&ni, type, p)) if (!snxtitem(&ni, type, p, NULL))
return RET_SYN; return RET_SYN;
if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p) if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p)
|| islist(p))) { || islist(p))) {

View file

@ -70,7 +70,7 @@ scut(void)
sprintf(prompt, "%s(s)? ", ef_nameof(type)); sprintf(prompt, "%s(s)? ", ef_nameof(type));
if ((p = getstarg(player->argp[2], prompt, buf)) == 0) if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
return RET_SYN; return RET_SYN;
if (!snxtitem(&ni, type, p)) if (!snxtitem(&ni, type, p, NULL))
return RET_SYN; return RET_SYN;
if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p) if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p)
|| islist(p))) { || islist(p))) {

View file

@ -50,7 +50,7 @@ sdump(void)
int n, i; int n, i;
time_t now; time_t now;
if (!snxtitem(&ni, EF_SHIP, player->argp[1])) if (!snxtitem(&ni, EF_SHIP, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
prdate(); prdate();

View file

@ -79,7 +79,7 @@ set(void)
pr("You can sell only ships, planes, land units or nukes\n"); pr("You can sell only ships, planes, land units or nukes\n");
return RET_SYN; return RET_SYN;
} }
if (!snxtitem(&ni, type, player->argp[2])) if (!snxtitem(&ni, type, player->argp[2], NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&ni, &item)) { while (nxtitem(&ni, &item)) {
if (!player->owner && !player->god) if (!player->owner && !player->god)

View file

@ -45,7 +45,7 @@ shi(void)
struct nstr_item ni; struct nstr_item ni;
struct shpstr ship; struct shpstr ship;
if (!snxtitem(&ni, EF_SHIP, player->argp[1])) if (!snxtitem(&ni, EF_SHIP, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
nships = noff = 0; nships = noff = 0;

View file

@ -70,7 +70,7 @@ sona(void)
static signed char **vis = NULL; static signed char **vis = NULL;
static signed char *visbuf = NULL; static signed char *visbuf = NULL;
if (!snxtitem(&ni, EF_SHIP, player->argp[1])) if (!snxtitem(&ni, EF_SHIP, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
if (!radbuf) if (!radbuf)
radbuf = malloc((WORLD_Y * (WORLD_X + 1))); radbuf = malloc((WORLD_Y * (WORLD_X + 1)));

View file

@ -44,7 +44,7 @@ sstat(void)
struct nstr_item ni; struct nstr_item ni;
struct shpstr ship; struct shpstr ship;
if (!snxtitem(&ni, EF_SHIP, player->argp[1])) if (!snxtitem(&ni, EF_SHIP, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
nships = 0; nships = 0;

View file

@ -157,7 +157,7 @@ start_stop_unit(int type, char *arg, int off)
int nunit; int nunit;
struct nstr_item nstr; struct nstr_item nstr;
if (!snxtitem(&nstr, type, arg)) if (!snxtitem(&nstr, type, arg, NULL))
return RET_SYN; return RET_SYN;
prdate(); prdate();
nunit = 0; nunit = 0;

View file

@ -170,7 +170,7 @@ starv_ships(char *range)
int nship = 0; int nship = 0;
int s; int s;
if (!snxtitem(&ni, EF_SHIP, range)) if (!snxtitem(&ni, EF_SHIP, range, NULL))
return; return;
while (nxtitem(&ni, &ship)) { while (nxtitem(&ni, &ship)) {
@ -218,7 +218,7 @@ starv_units(char *range)
int nunit = 0; int nunit = 0;
int s; int s;
if (!snxtitem(&ni, EF_LAND, range)) if (!snxtitem(&ni, EF_LAND, range, NULL))
return; return;
while (nxtitem(&ni, &land)) { while (nxtitem(&ni, &land)) {

View file

@ -43,7 +43,7 @@ supp(void)
struct nstr_item ni; struct nstr_item ni;
struct lndstr land; struct lndstr land;
if (!snxtitem(&ni, EF_LAND, player->argp[1])) if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
nunits = 0; nunits = 0;

View file

@ -80,8 +80,7 @@ tend(void)
return RET_SYN; return RET_SYN;
} }
if (!snxtitem(&tenders, EF_SHIP, if (!snxtitem(&tenders, EF_SHIP, player->argp[2], "Tender(s)? "))
getstarg(player->argp[2], "Tender(s)? ", buf)))
return RET_SYN; return RET_SYN;
while (nxtitem(&tenders, &tender)) { while (nxtitem(&tenders, &tender)) {
@ -127,8 +126,7 @@ tend(void)
break; break;
} }
if (!snxtitem(&targets, EF_SHIP, if (!snxtitem(&targets, EF_SHIP,
getstarg(player->argp[4], "Ships to be tended? ", player->argp[4], "Ships to be tended? "))
buf)))
return RET_SYN; return RET_SYN;
if (!check_ship_ok(&tender)) if (!check_ship_ok(&tender))
return RET_SYN; return RET_SYN;
@ -213,7 +211,7 @@ tend_land(struct shpstr *tenderp, char *units)
struct nstr_item pni; struct nstr_item pni;
char buf[1024]; char buf[1024];
if (!snxtitem(&lni, EF_LAND, units)) if (!snxtitem(&lni, EF_LAND, units, NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&lni, &land)) { while (nxtitem(&lni, &land)) {
@ -229,8 +227,7 @@ tend_land(struct shpstr *tenderp, char *units)
continue; continue;
} }
if (!snxtitem(&targets, EF_SHIP, if (!snxtitem(&targets, EF_SHIP,
getstarg(player->argp[4], "Ship to be tended? ", player->argp[4], "Ship to be tended? "))
buf)))
return RET_SYN; return RET_SYN;
if (!check_land_ok(&land)) if (!check_land_ok(&land))
return RET_SYN; return RET_SYN;

View file

@ -62,13 +62,10 @@ torp(void)
char *ptr; char *ptr;
struct nstr_item nbst; struct nstr_item nbst;
char buf[1024]; char buf[1024];
char *p;
int ntorping = 0; int ntorping = 0;
char prompt[128]; char prompt[128];
if (!(p = getstarg(player->argp[1], "From ship(s)? ", buf))) if (!snxtitem(&nbst, EF_SHIP, player->argp[1], "From ship(s)? "))
return RET_SYN;
if (!snxtitem(&nbst, EF_SHIP, p))
return RET_SYN; return RET_SYN;
while (nxtitem(&nbst, &sub)) { while (nxtitem(&nbst, &sub)) {
if (sub.shp_own != player->cnum) if (sub.shp_own != player->cnum)

View file

@ -77,7 +77,7 @@ tran_nuke(void)
weight = 0; weight = 0;
count = 0; count = 0;
if (!snxtitem(&nstr, EF_NUKE, player->argp[2])) if (!snxtitem(&nstr, EF_NUKE, player->argp[2], NULL))
return RET_SYN; return RET_SYN;
while (nxtitem(&nstr, &nuke)) { while (nxtitem(&nstr, &nuke)) {
if (!player->owner) if (!player->owner)
@ -156,7 +156,7 @@ tran_plane(void)
weight = 0; weight = 0;
count = 0; count = 0;
if (!snxtitem(&nstr, EF_PLANE, player->argp[2])) if (!snxtitem(&nstr, EF_PLANE, player->argp[2], NULL))
return RET_SYN; return RET_SYN;
/* /*
* First do some sanity checks: make sure that they are all in the, * First do some sanity checks: make sure that they are all in the,

View file

@ -43,7 +43,7 @@ trea(void)
struct nstr_item nstr; struct nstr_item nstr;
int ntreaty; int ntreaty;
if (!snxtitem(&nstr, EF_TREATY, player->argp[1])) if (!snxtitem(&nstr, EF_TREATY, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
pr("\t... %s Treaty Report ...\n", cname(player->cnum)); pr("\t... %s Treaty Report ...\n", cname(player->cnum));
ntreaty = 0; ntreaty = 0;

View file

@ -87,7 +87,7 @@ lupgr(void)
int rel; int rel;
long cash; long cash;
if (!snxtitem(&ni, EF_LAND, player->argp[2])) if (!snxtitem(&ni, EF_LAND, player->argp[2], NULL))
return RET_SYN; return RET_SYN;
natp = getnatp(player->cnum); natp = getnatp(player->cnum);
cash = natp->nat_money; cash = natp->nat_money;
@ -170,7 +170,7 @@ supgr(void)
int rel; int rel;
long cash; long cash;
if (!snxtitem(&ni, EF_SHIP, player->argp[2])) if (!snxtitem(&ni, EF_SHIP, player->argp[2], NULL))
return RET_SYN; return RET_SYN;
natp = getnatp(player->cnum); natp = getnatp(player->cnum);
cash = natp->nat_money; cash = natp->nat_money;
@ -252,7 +252,7 @@ pupgr(void)
int rel; int rel;
long cash; long cash;
if (!snxtitem(&ni, EF_PLANE, player->argp[2])) if (!snxtitem(&ni, EF_PLANE, player->argp[2], NULL))
return RET_SYN; return RET_SYN;
natp = getnatp(player->cnum); natp = getnatp(player->cnum);
cash = natp->nat_money; cash = natp->nat_money;

View file

@ -57,7 +57,7 @@ wing(void)
} }
if (c == '~') if (c == '~')
c = 0; c = 0;
if (!snxtitem(&nstr, EF_PLANE, player->argp[2])) if (!snxtitem(&nstr, EF_PLANE, player->argp[2], NULL))
return RET_SYN; return RET_SYN;
count = 0; count = 0;
while (nxtitem(&nstr, &plane)) { while (nxtitem(&nstr, &plane)) {

View file

@ -51,7 +51,7 @@ work(void)
coord donex = 0, doney = 1; coord donex = 0, doney = 1;
char buf[1024]; char buf[1024];
if (!snxtitem(&ni, EF_LAND, player->argp[1])) if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
return RET_SYN; return RET_SYN;
p = getstarg(player->argp[2], "Amount: ", buf); p = getstarg(player->argp[2], "Amount: ", buf);
if (p == 0 || *p == 0) if (p == 0 || *p == 0)

View file

@ -129,7 +129,7 @@ xditem(struct xdstr *xd, int type, char *arg)
if (!ca) if (!ca)
return RET_SYN; return RET_SYN;
if (!snxtitem(&ni, type, arg)) if (!snxtitem(&ni, type, arg, NULL))
return RET_SYN; return RET_SYN;
xdhdr(xd, ef_nameof(type), 0); xdhdr(xd, ef_nameof(type), 0);

View file

@ -70,12 +70,9 @@ int
get_planes(struct nstr_item *ni_bomb, struct nstr_item *ni_esc, get_planes(struct nstr_item *ni_bomb, struct nstr_item *ni_esc,
char *input_bomb, char *input_esc) char *input_bomb, char *input_esc)
{ {
char buf[1024]; if (!snxtitem(ni_bomb, EF_PLANE, input_bomb, NULL))
if (!snxtitem(ni_bomb, EF_PLANE, input_bomb))
return -1; return -1;
if (!snxtitem(ni_esc, EF_PLANE, if (!snxtitem(ni_esc, EF_PLANE, input_esc, "escort(s)? ")) {
getstarg(input_esc, "escort(s)? ", buf))) {
if (player->aborted) if (player->aborted)
return -1; return -1;
pr("No escorts...\n"); pr("No escorts...\n");

View file

@ -145,7 +145,7 @@ satmap(int x, int y, int eff, int range, int flags, int type)
if ((type == EF_BAD || type == EF_SHIP) && if ((type == EF_BAD || type == EF_SHIP) &&
(flags & P_S || flags & P_I)) { (flags & P_S || flags & P_I)) {
if (type == EF_SHIP) if (type == EF_SHIP)
snxtitem(&ni, EF_SHIP, selection); snxtitem(&ni, EF_SHIP, selection, NULL);
else else
snxtitem_dist(&ni, EF_SHIP, x, y, range); snxtitem_dist(&ni, EF_SHIP, x, y, range);
@ -190,7 +190,7 @@ satmap(int x, int y, int eff, int range, int flags, int type)
if ((type == EF_BAD || type == EF_LAND) && if ((type == EF_BAD || type == EF_LAND) &&
(flags & P_S || flags & P_I)) { (flags & P_S || flags & P_I)) {
if (type == EF_LAND) if (type == EF_LAND)
snxtitem(&ni, EF_LAND, selection); snxtitem(&ni, EF_LAND, selection, NULL);
else else
snxtitem_dist(&ni, EF_LAND, x, y, range); snxtitem_dist(&ni, EF_LAND, x, y, range);

View file

@ -51,7 +51,7 @@
* instead. * instead.
*/ */
int int
snxtitem(struct nstr_item *np, int type, char *str) snxtitem(struct nstr_item *np, int type, char *str, char *prompt)
{ {
struct range range; struct range range;
int list[NS_LSIZE]; int list[NS_LSIZE];
@ -59,13 +59,16 @@ snxtitem(struct nstr_item *np, int type, char *str)
coord cx, cy; coord cx, cy;
int dist; int dist;
int flags; int flags;
char prompt[128]; char promptbuf[128];
char buf[1024]; char buf[1024];
np->type = EF_BAD; np->type = EF_BAD;
np->sel = NS_UNDEF; np->sel = NS_UNDEF;
if (str == 0) { if (str == 0) {
sprintf(prompt, "%s(s)? ", ef_nameof(type)); if (!prompt) {
sprintf(promptbuf, "%s(s)? ", ef_nameof(type));
prompt = promptbuf;
}
str = getstring(prompt, buf); str = getstring(prompt, buf);
if (str == 0) if (str == 0)
return 0; return 0;