From c87638ad3076f5e7e0c80067631561c356148b79 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 27 Jul 2011 16:41:21 +0200 Subject: include: [strutils.c] add list parsers Signed-off-by: Karel Zak --- sys-utils/dmesg.c | 47 ++++++----------------------------------------- 1 file changed, 6 insertions(+), 41 deletions(-) (limited to 'sys-utils/dmesg.c') diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index 7123c7fb6..d9beb9c5d 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -311,45 +311,6 @@ static double time_diff(struct timeval *a, struct timeval *b) return (a->tv_sec - b->tv_sec) + (a->tv_usec - b->tv_usec) / 1E6; } -/* - * LIST ::= [, ] - * - * The is translated to 'id' by name2id() function and the 'id' is used - * as a possition in the 'ary' bit array. It means that the 'id' has to be in - * range <0..N> where N < sizeof(ary) * NBBY. - */ -static int list_to_bitarray(const char *list, - int (*name2id)(const char *name, size_t namesz), - char *ary) -{ - const char *begin = NULL, *p; - - for (p = list; p && *p; p++) { - const char *end = NULL; - int id; - - if (!begin) - begin = p; /* begin of the level name */ - if (*p == ',') - end = p; /* terminate the name */ - if (*(p + 1) == '\0') - end = p + 1; /* end of string */ - if (!begin || !end) - continue; - if (end <= begin) - return -1; - - id = name2id(begin, end - begin); - if (id < 0) - return id; - setbit(ary, id); - begin = NULL; - if (end && !*end) - break; - } - return 0; -} - static int get_buffer_size() { int n = klogctl(SYSLOG_ACTION_SIZE_BUFFER, NULL, 0); @@ -674,7 +635,9 @@ int main(int argc, char *argv[]) break; case 'f': ctl.fltr_fac = 1; - list_to_bitarray(optarg, parse_facility, ctl.facilities); + if (string_to_bitarray(optarg, + ctl.facilities, parse_facility) < 0) + return EXIT_FAILURE; break; case 'h': usage(stdout); @@ -685,7 +648,9 @@ int main(int argc, char *argv[]) break; case 'l': ctl.fltr_lev= 1; - list_to_bitarray(optarg, parse_level, ctl.levels); + if (string_to_bitarray(optarg, + ctl.levels, parse_level) < 0) + return EXIT_FAILURE; break; case 'n': cmd = SYSLOG_ACTION_CONSOLE_LEVEL; -- cgit v1.2.3-55-g7522