edit: Accept interactive empty key argument again

Empty key arguments work fine when passed as command arguments, but
not interactively.  For example, 'edit s 42 R ""' clears the retreat
path, but in an interactive 'edit s 43', 'R ""' sets it to "".

In Empire 1, omitting the argument made it empty.  Empire 2 turned
that into an error without providing an alternative.

Switch to the common command parser, so that quoting works, and "" is
parsed as empty argument.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2013-01-20 23:39:03 +01:00
parent 33456b3371
commit c0f3a1e5e5
3 changed files with 40 additions and 10 deletions

View file

@ -399,22 +399,22 @@ print_ship(struct shpstr *ship)
static int
getin(char *buf, char **valp)
{
char line[1024];
char *argp[128];
char *p;
unsigned char thing;
p = getstarg(NULL, "%c xxxxx -- thing value : ", buf);
p = getstarg(NULL, "%c xxxxx -- thing value : ", line);
if (!p)
return -1;
for (; isspace(*p); p++) ;
if (!*p)
switch (parse(p, buf, argp, NULL, NULL, NULL)) {
case 0:
return 0;
thing = *p;
for (; *p && !isspace(*p); p++) ;
for (; isspace(*p); p++) ;
if (!*p)
case 1:
return -1;
*valp = p;
return thing;
default:
*valp = argp[1];
return argp[0][0];
}
}
#if 0 /* not needed right now */

View file

@ -301,6 +301,7 @@ unit_carrier('land', 'S', 'Y');
# interactive edit
iedit('ship', 0, 'M 2', 'm 1', 'f 1');
iedit('ship', 0, 'R n', 'R ""');
iedit('plane', 0, 'm 2', 'y -1');
iedit('land', 0, 'M 2', 'Y -1');

View file

@ -1194,6 +1194,35 @@
Play#0 output Play#0 1 c m u f s g p i d o l h r
Play#0 output Play#0 1 0 1 0 1 0 0 0 0 0 0 0 0 0
Play#0 output Play#0 6 0 640
Play#0 input edit s 0
Play#0 command edit
Play#0 output Play#0 1 POGO (#0) cs cargo ship (#0)
Play#0 output Play#0 1 UID <U>: 0
Play#0 output Play#0 1 Owner <O>: 0 Location <L>: 1,-1
Play#0 output Play#0 1 Tech <T>: 100 Efficiency <E>: 0
Play#0 output Play#0 1 Mobility <M>: 2 Fleet <F>:
Play#0 output Play#0 1 Retreat path <R>: '' Retreat Flags <W>: 0
Play#0 output Play#0 1 Plague Stage <a>: 0 Plague Time <b>: 0
Play#0 output Play#0 1 civ mil uw food shl gun pet irn dst oil lcm hcm rad
Play#0 output Play#0 1 c m u f s g p i d o l h r
Play#0 output Play#0 1 0 1 0 1 0 0 0 0 0 0 0 0 0
Play#0 output Play#0 4 %c xxxxx -- thing value :
Play#0 input R n
Play#0 output Play#0 4 %c xxxxx -- thing value :
Play#0 input R ""
Play#0 output Play#0 4 %c xxxxx -- thing value :
Play#0 input
Play#0 output Play#0 1 POGO (#0) cs cargo ship (#0)
Play#0 output Play#0 1 UID <U>: 0
Play#0 output Play#0 1 Owner <O>: 0 Location <L>: 1,-1
Play#0 output Play#0 1 Tech <T>: 100 Efficiency <E>: 0
Play#0 output Play#0 1 Mobility <M>: 2 Fleet <F>:
Play#0 output Play#0 1 Retreat path <R>: '' Retreat Flags <W>: 0
Play#0 output Play#0 1 Plague Stage <a>: 0 Plague Time <b>: 0
Play#0 output Play#0 1 civ mil uw food shl gun pet irn dst oil lcm hcm rad
Play#0 output Play#0 1 c m u f s g p i d o l h r
Play#0 output Play#0 1 0 1 0 1 0 0 0 0 0 0 0 0 0
Play#0 output Play#0 6 0 640
Play#0 input edit p 0
Play#0 command edit
Play#0 output Play#0 1 POGO (#0) f1 Sopwith Camel #0