From 9fe3f9a9389bb06cf645d33cbb2b45e1f63d737c Mon Sep 17 00:00:00 2001 From: "kay.sievers@vrfy.org" Date: Wed, 3 Mar 2004 18:16:35 -0800 Subject: [PATCH] cleanup mult field string handling Here I try to cleanup our various multifield iteration over the strings. Inspired by our nice list.h we now have a macro to iterate over the string and process the parts of it: It makes the code more readable and we don't change the string while we process it like the former strsep() does. Example: foreach_strpart(dev->symlink, " ", pos, len) { if (strncmp(&dev->symlink[pos], find_name, len) != 0) continue; ... } For the callout part selector %c{2} we separate now not only by space but also newline and return characters, cause some programs may give multiline values back. A possible RESULT match must contain wildcards for these characters. Also a bug in the recent udevinfo symlink query feature is fixed. --- udev.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'udev.h') diff --git a/udev.h b/udev.h index 5737c84c9d..9327e90913 100644 --- a/udev.h +++ b/udev.h @@ -97,6 +97,12 @@ do { \ snprintf((to) + strlen(to), maxsize - strlen(to)-1, "%u", i); \ } while (0) +#define foreach_strpart(str, separator, pos, len) \ + for(pos = 0, len = strcspn(str, separator); \ + (pos) < strlen(str); \ + pos = pos + (len) + 1, len = strcspn((str) + pos, separator)) \ + if (len > 0) + static inline char *get_action(void) { char *action; -- cgit v1.2.3-54-g00ecf