]> git.pond.sub.org Git - empserver/commitdiff
edit: Accept interactive empty key argument again
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 20 Jan 2013 22:39:03 +0000 (23:39 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 6 Jun 2013 17:54:58 +0000 (19:54 +0200)
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>
src/lib/commands/edit.c
tests/actofgod/geninput.pl
tests/actofgod/journal.log

index 85103fa56b3c34688f09940fa38d3eacb76e06ac..c72544a9a7bc80d74930cb1830e8d5c2e664eaac 100644 (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 */
index 56c9895f14cfe57159cf1a47cfeb66b85c662221..7433b804b6ccbc127cd52e34bff932008eabb34a 100755 (executable)
@@ -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');
 
index bab150780a82cc9a08228456125e86608a6cf590..a0103d125fdbd9dfde6259f15b309928a1a8e218 100644 (file)
     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