]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/stmtch.c
Update copyright notice
[empserver] / src / lib / common / stmtch.c
index 819cda1579dbdb36c51815b5045a0715a3485ef5..351adb38b7e570d2d51ce56a0f77fc2f358c8126 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-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
  * Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are
  * several.
  * Each array element has a pointer to its name stored at offset OFFS.
- * Search stops when this name is a null pointer or empty.
+ * Search stops when this name is a null pointer.
+ * It ignores elements with an empty name.
  * NEEDLE is compared to element names with mineq(NEEDLE, NAME).
- * ELT_SIZE gives the size of an array element.
+ * SIZE gives the size of an array element.
  */
 int
-stmtch(char *needle, void *haystack, ptrdiff_t offs, size_t elt_size)
+stmtch(char *needle, void *haystack, ptrdiff_t offs, size_t size)
 {
-#define ELT_NAME(i) (*(char **)((char *)haystack + (i)*elt_size + offs))
     int i, res;
+    char *name;
 
     res = M_NOTFOUND;
-    for (i = 0; ELT_NAME(i) && ELT_NAME(i)[0] != 0; i++) {
-       switch (mineq(needle, ELT_NAME(i))) {
+    for (i = 0;; i++) {
+       name = *(char **)((char *)haystack + i * size + offs);
+       if (!name)
+           break;
+       if (!*name)
+           continue;
+       switch (mineq(needle, name)) {
        case ME_MISMATCH:
            break;
        case ME_PARTIAL:
@@ -65,7 +71,6 @@ stmtch(char *needle, void *haystack, ptrdiff_t offs, size_t elt_size)
        }
     }
     return res;
-#undef ELT_NAME
 }
 
 /*