From c0f3a1e5e580529e3d15dc25864cc659a98cd62b Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 20 Jan 2013 23:39:03 +0100 Subject: [PATCH] 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 --- src/lib/commands/edit.c | 20 ++++++++++---------- tests/actofgod/geninput.pl | 1 + tests/actofgod/journal.log | 29 +++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/lib/commands/edit.c b/src/lib/commands/edit.c index 85103fa56..c72544a9a 100644 --- a/src/lib/commands/edit.c +++ b/src/lib/commands/edit.c @@ -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 */ diff --git a/tests/actofgod/geninput.pl b/tests/actofgod/geninput.pl index 56c9895f1..7433b804b 100755 --- a/tests/actofgod/geninput.pl +++ b/tests/actofgod/geninput.pl @@ -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'); diff --git a/tests/actofgod/journal.log b/tests/actofgod/journal.log index bab150780..a0103d125 100644 --- a/tests/actofgod/journal.log +++ b/tests/actofgod/journal.log @@ -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 : 0 + Play#0 output Play#0 1 Owner : 0 Location : 1,-1 + Play#0 output Play#0 1 Tech : 100 Efficiency : 0 + Play#0 output Play#0 1 Mobility : 2 Fleet : + Play#0 output Play#0 1 Retreat path : '' Retreat Flags : 0 + Play#0 output Play#0 1 Plague Stage : 0 Plague Time : 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 : 0 + Play#0 output Play#0 1 Owner : 0 Location : 1,-1 + Play#0 output Play#0 1 Tech : 100 Efficiency : 0 + Play#0 output Play#0 1 Mobility : 2 Fleet : + Play#0 output Play#0 1 Retreat path : '' Retreat Flags : 0 + Play#0 output Play#0 1 Plague Stage : 0 Plague Time : 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 -- 2.43.0