From 200daf7dbbce90d4006d7dbf53affa48a110ed00 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 28 Oct 2018 13:29:42 +0100 Subject: Import syslog utility program Signed-off-by: David Oberhollenzer --- protomap.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'protomap.c') diff --git a/protomap.c b/protomap.c index 1ace2bb..60e2c6a 100644 --- a/protomap.c +++ b/protomap.c @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: ISC */ #include "syslogd.h" +#include + typedef struct { const char *name; int id; @@ -54,12 +56,30 @@ static const char *enum_to_name(const enum_map_t *map, int id) return map->name; } +static int enum_by_name(const enum_map_t *map, const char *name) +{ + while (map->name != NULL && strcmp(map->name, name) != 0) + ++map; + + return map->name == NULL ? -1 : map->id; +} + const char *level_id_to_string(int level) { return enum_to_name(levels, level); } -const char *facility_id_to_string(int level) +const char *facility_id_to_string(int id) +{ + return enum_to_name(facilities, id); +} + +int level_id_from_string(const char *level) +{ + return enum_by_name(levels, level); +} + +int facility_id_from_string(const char *fac) { - return enum_to_name(facilities, level); + return enum_by_name(facilities, fac); } -- cgit v1.2.3