]> git.pond.sub.org Git - empserver/commitdiff
Fix do_map()'s misuse of snxtsct() for testing argument syntax
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 9 Apr 2011 12:57:42 +0000 (14:57 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 14 Apr 2011 18:21:22 +0000 (20:21 +0200)
It assumes snxtsct() fails only when the argument can't be parsed.  It
can also fail when the condition argument has errors.  `map # ?xxx'
first complains about xxx, then maps around ship#0.  Broken since
Chainsaw 2 introduced smap, pmap and lmap.

Use sarg_type() to recognize sectors vs. unit argument.  `map # ?xxx'
now fails as it should.

Subtle side effect: do_map() no longer prompts for argument "",
because snxtsct() is now guarded by sarg_type().  Impact on callers:

* display_region_map() is not affected, because it never passes "".

* map() passes on "" arguments.  Change it to prompt in that case.
  Consistent with how other commands behave.  No functional change.

* do_unit_move() passes on "" arguments.  Keep it that way.  This
  changes navigate and march sub-commands 'M' and 'B' not to prompt
  for "" arguments, which is consistent with sub-command 'm' of move,
  test and transport.

src/lib/commands/map.c
src/lib/subs/maps.c

index ae995c2957b735795af39f22dbcd559c03776b89..cbce5548ee3646ab62d13bb8e3693e32f85d0f9e 100644 (file)
@@ -73,7 +73,7 @@ map(void)
        }
     }
 
-    if (player->argp[1] == NULL) {
+    if (!player->argp[1] || !*player->argp[1]) {
        if (unit_type == EF_BAD) {
            str = getstring("(sects)? ", buf);
        } else {
index b109b453d8aabf88b0777b2b3da263e117461eda..0f2475950c4db642214381d1480f9e554bbe2061 100644 (file)
@@ -76,7 +76,14 @@ do_map(int bmap, int unit_type, char *arg, char *map_flags_arg)
     char *b;
     int map_flags = 0;
 
-    if (!snxtsct(&ns, arg)) {
+    switch (sarg_type(arg)) {
+    case NS_DIST:
+    case NS_AREA:
+    case NS_ALL:
+       if (!snxtsct(&ns, arg))
+           return RET_SYN;
+       break;
+    default:
        if (unit_map(unit_type, atoi(arg), &ns, &origin))
            return RET_FAIL;
     }