(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.
This commit is contained in:
Markus Armbruster 2005-10-29 06:18:41 +00:00
parent 7c93f70ee4
commit 6be5ba5d40

View file

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