diff options
author | kay.sievers@vrfy.org <kay.sievers@vrfy.org> | 2004-03-03 18:16:35 -0800 |
---|---|---|
committer | Greg KH <gregkh@suse.de> | 2005-04-26 21:35:08 -0700 |
commit | 9fe3f9a9389bb06cf645d33cbb2b45e1f63d737c (patch) | |
tree | b433b3a99180227203027ec80f825ba94ac59869 /namedev.c | |
parent | [PATCH] 021 release (diff) | |
download | systemd-9fe3f9a9389bb06cf645d33cbb2b45e1f63d737c.tar.gz systemd-9fe3f9a9389bb06cf645d33cbb2b45e1f63d737c.tar.bz2 systemd-9fe3f9a9389bb06cf645d33cbb2b45e1f63d737c.zip |
[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.
Diffstat (limited to 'namedev.c')
-rw-r--r-- | namedev.c | 21 |
1 files changed, 8 insertions, 13 deletions
@@ -214,14 +214,12 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize, struct sysfs_device *sysfs_device) { char temp[NAME_SIZE]; - char temp1[NAME_SIZE]; char *tail; char *pos; - char *pos2; - char *pos3; char *attr; int len; int i; + int spos, slen; char c; struct sysfs_attribute *tmpattr; @@ -278,20 +276,17 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize, if (attr != NULL) i = atoi(attr); if (i > 0) { - strfieldcpy(temp1, udev->program_result); - pos2 = temp1; - while (i) { + foreach_strpart(udev->program_result, " \n\r", spos, slen) { i--; - pos3 = strsep(&pos2, " "); - if (pos3 == NULL) { - dbg("requested part of result string not found"); + if (i == 0) break; - } } - if (pos3) { - strnfieldcat(string, pos3, maxsize); - dbg("substitute part of result string '%s'", pos3); + if (i > 0) { + dbg("requested part of result string not found"); + break; } + strnfieldcat(string, udev->program_result + spos, slen+1); + dbg("substitute part of result string '%s'", pos); } else { strnfieldcat(string, udev->program_result, maxsize); dbg("substitute result string '%s'", udev->program_result); |