]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/paths.c
New macro ARRAY_SIZE()
[empserver] / src / lib / subs / paths.c
index eda00616781d400d86bfe471d8b4be38873a139b..23bd3bb5641cb9b69c4d7449a63ac7e29698921b 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
  *  paths.c: Routines associated with paths, directions, etc.
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2005-2011
+ *     Markus Armbruster, 2005-2020
  */
 
 #include <config.h>
 
-#include "file.h"
 #include "optlist.h"
 #include "path.h"
 #include "player.h"
@@ -66,15 +65,15 @@ direrr(char *stop_msg, char *view_msg, char *map_msg)
 }
 
 /*
- * Map direction DIR to a direction index DIR_STOP..DIR_LAST.
- * DIR must be a valid direction.
+ * Map direction @dir to a direction index DIR_STOP..DIR_LAST.
+ * @dir must be a valid direction.
  */
 int
 diridx(char dir)
 {
     unsigned i = dir - 'a';
 
-    if (CANT_HAPPEN(i >= sizeof(dirindex) / sizeof(*dirindex)
+    if (CANT_HAPPEN(i >= ARRAY_SIZE(dirindex)
                    || dirindex[i] < 0))
        return DIR_STOP;
     return dirindex[i];
@@ -143,7 +142,7 @@ more:
            break;
        }
        if (dir == DIR_STOP) {
-           p[1] = 0;
+           *p = 0;
            return buf;
        }
        ++p;
@@ -170,7 +169,7 @@ more:
     strcpy(p, bp);
     if (*bp)
        goto more;
-    return buf;
+    return buf[0] ? buf : NULL;
 }
 
 /*