]> git.pond.sub.org Git - empserver/commitdiff
(ef_byname): Old version didn't work when a table name was followed by
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 29 Oct 2005 06:18:41 +0000 (06:18 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 29 Oct 2005 06:18:41 +0000 (06:18 +0000)
one of its prefixes.  src/lib/global/file.c rev. 1.18 added such table
entries, and file.h rev. 1.34 made them visible to ef_byname().
Simply use stmtch().  This also rejects ambiguous abbreviations: "s"
used to return EF_SECTOR, it now returns M_NOTUNIQUE.

src/lib/common/file.c

index c647a337a12d750cff48c74cab443aaa792d31a0..5229a2bc560838ea6ebec8c3647231247baef430 100644 (file)
@@ -431,31 +431,22 @@ ef_mtime(int type)
 }
 
 /*
- * Search empfile[0..EF_MAX-1] for element named NAME.
- * Return its index in empfile[] if found, else -1.
+ * Search for a table matching NAME, return its table type.
+ * Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are
+ * several.
  */
 int
 ef_byname(char *name)
 {
-    /* FIXME should use stmtch() */
-    struct empfile *ef;
-    int i;
-    int len;
-
-    len = strlen(name);
-    for (i = 0; i < EF_MAX; i++) {
-       ef = &empfile[i];
-       if (strncmp(ef->name, name, min(len, strlen(ef->name))) == 0)
-           return i;
-    }
-    return -1;
+    return stmtch(name, empfile, offsetof(struct empfile, name),
+                 sizeof(empfile[0]));
 }
 
 /*
- * Search CHOICES[] for a table ID matching NAME.
- * CHOICES[] contains indexes in empfile[] and is terminated with a
- * negative value.
- * Return the matching index if there is one, else -1.
+ * Search CHOICES[] for a table type matching NAME, return it.
+ * Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are
+ * several.
+ * CHOICES[] must be terminated with a negative value.
  */
 int
 ef_byname_from(char *name, int choices[])