Factor out table walk into a separate function
This commit is contained in:
parent
979444a4c9
commit
296af80dba
40
logger.c
40
logger.c
@ -10,44 +10,30 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static int
|
static int
|
||||||
decodefac(char *fac)
|
decodetable(CODE *table, char *name)
|
||||||
{
|
{
|
||||||
CODE *c;
|
CODE *c;
|
||||||
int facility = -1;
|
|
||||||
|
|
||||||
for (c = facilitynames; c->c_name; c++)
|
for (c = table; c->c_name; c++)
|
||||||
if (!strcasecmp(fac, c->c_name))
|
if (!strcasecmp(name, c->c_name))
|
||||||
facility = c->c_val;
|
return c->c_val;
|
||||||
if (facility == -1)
|
eprintf("invalid priority name: %s\n", name);
|
||||||
eprintf("invalid facility name: %s\n", fac);
|
/* NOTREACHED */
|
||||||
return facility & LOG_FACMASK;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
decodelev(char *lev)
|
|
||||||
{
|
|
||||||
CODE *c;
|
|
||||||
int level = -1;
|
|
||||||
|
|
||||||
for (c = prioritynames; c->c_name; c++)
|
|
||||||
if (!strcasecmp(lev, c->c_name))
|
|
||||||
level = c->c_val;
|
|
||||||
if (level == -1)
|
|
||||||
eprintf("invalid level name: %s\n", lev);
|
|
||||||
return level & LOG_PRIMASK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
decodepri(char *pri)
|
decodepri(char *pri)
|
||||||
{
|
{
|
||||||
char *p;
|
char *lev, *fac = pri;
|
||||||
|
|
||||||
if (!(p = strchr(pri, '.')))
|
if (!(lev = strchr(pri, '.')))
|
||||||
eprintf("invalid priority name: %s\n", pri);
|
eprintf("invalid priority name: %s\n", pri);
|
||||||
*p++ = '\0';
|
*lev++ = '\0';
|
||||||
if (!*p)
|
if (!*lev)
|
||||||
eprintf("invalid priority name: %s\n", pri);
|
eprintf("invalid priority name: %s\n", pri);
|
||||||
return decodefac(pri) | decodelev(p);
|
return (decodetable(facilitynames, fac) & LOG_FACMASK) |
|
||||||
|
(decodetable(prioritynames, lev) & LOG_PRIMASK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user