From 6be5ba5d405381aca554f1701a44cc9ebb36dbdf Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 29 Oct 2005 06:18:41 +0000 Subject: [PATCH] (ef_byname): Old version didn't work when a table name was followed by 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 | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/lib/common/file.c b/src/lib/common/file.c index c647a337..5229a2bc 100644 --- a/src/lib/common/file.c +++ b/src/lib/common/file.c @@ -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[])