(add): When an argument is bad, do not loop prompting, just fail.
That's what the vast majority of commands do. (add): Do not silently truncate country number argument. (add): Diagnostics were confusing because they lacked context.
This commit is contained in:
parent
cea58c40b0
commit
69582d0d15
1 changed files with 47 additions and 58 deletions
|
@ -58,10 +58,9 @@ add(void)
|
||||||
char pname[sizeof(natp->nat_pnam)];
|
char pname[sizeof(natp->nat_pnam)];
|
||||||
natid coun;
|
natid coun;
|
||||||
natid freecn;
|
natid freecn;
|
||||||
s_char prompt[128];
|
char prompt[128];
|
||||||
s_char buf[1024];
|
char buf[1024];
|
||||||
s_char *p;
|
char *p;
|
||||||
s_char loopflag;
|
|
||||||
int stat;
|
int stat;
|
||||||
struct nstr_item ni;
|
struct nstr_item ni;
|
||||||
struct lndstr land;
|
struct lndstr land;
|
||||||
|
@ -74,45 +73,40 @@ add(void)
|
||||||
sprintf(prompt, "New country number? (%d is unused) ", freecn);
|
sprintf(prompt, "New country number? (%d is unused) ", freecn);
|
||||||
else
|
else
|
||||||
strcpy(prompt, "New country number? (they all seem to be used) ");
|
strcpy(prompt, "New country number? (they all seem to be used) ");
|
||||||
while ((p = getstarg(player->argp[1], prompt, buf)) && *p) {
|
p = getstarg(player->argp[1], prompt, buf);
|
||||||
coun = atoi(p);
|
|
||||||
if (coun < MAXNOC)
|
|
||||||
break;
|
|
||||||
pr("Max # countries is %d\n", MAXNOC);
|
|
||||||
player->argp[1] = 0;
|
|
||||||
}
|
|
||||||
if (p == 0 || *p == 0)
|
if (p == 0 || *p == 0)
|
||||||
|
return RET_SYN;
|
||||||
|
i = atoi(p);
|
||||||
|
if (i >= MAXNOC) {
|
||||||
|
pr("Max # countries is %d\n", MAXNOC);
|
||||||
return RET_FAIL;
|
return RET_FAIL;
|
||||||
|
}
|
||||||
|
coun = i;
|
||||||
if (coun == 0) {
|
if (coun == 0) {
|
||||||
pr("Not allowed to add country #0\n");
|
pr("Not allowed to add country #0\n");
|
||||||
return RET_FAIL;
|
return RET_FAIL;
|
||||||
}
|
}
|
||||||
natp = getnatp(coun);
|
natp = getnatp(coun);
|
||||||
while ((p = getstarg(player->argp[2], "Country Name? ", buf)) && *p) {
|
p = getstarg(player->argp[2], "Country Name? ", buf);
|
||||||
if (strlen(p) < sizeof(cntryname)) {
|
|
||||||
(void)strcpy(cntryname, p);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
pr("Too long.\n");
|
|
||||||
player->argp[2] = 0;
|
|
||||||
}
|
|
||||||
if (p == 0 || *p == 0)
|
if (p == 0 || *p == 0)
|
||||||
return RET_OK;
|
return RET_SYN;
|
||||||
while ((p = getstarg(player->argp[3], "Representative? ", buf)) && *p) {
|
if (strlen(p) >= sizeof(cntryname)) {
|
||||||
if (strlen(p) < sizeof(pname)) {
|
pr("Country name too long\n");
|
||||||
(void)strcpy(pname, p);
|
return RET_FAIL;
|
||||||
break;
|
|
||||||
}
|
|
||||||
pr("Too long.\n");
|
|
||||||
player->argp[3] = 0;
|
|
||||||
}
|
}
|
||||||
|
strcpy(cntryname, p);
|
||||||
|
p = getstarg(player->argp[3], "Representative? ", buf);
|
||||||
if (p == 0 || *p == 0)
|
if (p == 0 || *p == 0)
|
||||||
return RET_OK;
|
return RET_SYN;
|
||||||
loopflag = 1;
|
if (strlen(p) >= sizeof(pname)) {
|
||||||
stat = natp->nat_stat;
|
pr("Representative too long\n");
|
||||||
strcpy(prompt, "Status? (visitor, new, active, god, delete) ");
|
return RET_FAIL;
|
||||||
while (loopflag && (p = getstarg(player->argp[4], prompt, buf))) {
|
}
|
||||||
loopflag = 0;
|
strcpy(pname, p);
|
||||||
|
p = getstarg(player->argp[4],
|
||||||
|
"Status? (visitor, new, active, god, delete) ", buf);
|
||||||
|
if (p == 0 || *p == 0)
|
||||||
|
return RET_SYN;
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case 'v':
|
case 'v':
|
||||||
stat = STAT_INUSE;
|
stat = STAT_INUSE;
|
||||||
|
@ -130,18 +124,13 @@ add(void)
|
||||||
stat = 0;
|
stat = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
pr("Illegal selection\n");
|
pr("Illegal status\n");
|
||||||
loopflag = 1;
|
return RET_SYN;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
player->argp[4] = 0;
|
|
||||||
}
|
|
||||||
if (p == 0)
|
|
||||||
return RET_OK;
|
|
||||||
p = getstarg(player->argp[5],
|
p = getstarg(player->argp[5],
|
||||||
"Check, wipe, or ignore existing sectors (c|w|i) ", buf);
|
"Check, wipe, or ignore existing sectors (c|w|i) ", buf);
|
||||||
if (p == 0)
|
if (p == 0)
|
||||||
return RET_OK;
|
return RET_SYN;
|
||||||
snxtitem_all(&ni, EF_LAND);
|
snxtitem_all(&ni, EF_LAND);
|
||||||
while (nxtitem(&ni, &land)) {
|
while (nxtitem(&ni, &land)) {
|
||||||
if (land.lnd_own == coun) {
|
if (land.lnd_own == coun) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue