diff options
author | kay.sievers@vrfy.org <kay.sievers@vrfy.org> | 2004-12-20 07:38:33 +0100 |
---|---|---|
committer | Greg KH <gregkh@suse.de> | 2005-04-26 23:19:09 -0700 |
commit | 9f8dfa19cfd2b502bf794f39a421cbb7c4cc0404 (patch) | |
tree | b91b9ebebd7a08a722d60495af2a2b594dd50d0e /udev_utils.c | |
parent | [PATCH] add OnStream tape drive rules (diff) | |
download | systemd-9f8dfa19cfd2b502bf794f39a421cbb7c4cc0404.tar.gz systemd-9f8dfa19cfd2b502bf794f39a421cbb7c4cc0404.tar.bz2 systemd-9f8dfa19cfd2b502bf794f39a421cbb7c4cc0404.zip |
[PATCH] allow multiline rules by backslash at the end of the line
On Sun, 2004-12-19 at 18:31 +0100, Marco d'Itri wrote:
> > On Dec 19, Kay Sievers <kay.sievers@vrfy.org> wrote:
>
> > (Feature request: would it be possible to extend the rules files parser
> > to support continuation lines? I'd like it to consider lines starting
> > with white space as part of the previous line.)
>
> How about the usual backslash at the end of the line. Here is a simple
> patch.
Diffstat (limited to 'udev_utils.c')
-rw-r--r-- | udev_utils.c | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/udev_utils.c b/udev_utils.c index 0b730d565..fe18892de 100644 --- a/udev_utils.c +++ b/udev_utils.c @@ -25,6 +25,7 @@ #include <unistd.h> #include <fcntl.h> #include <errno.h> +#include <ctype.h> #include <dirent.h> #include <sys/stat.h> #include <sys/mman.h> @@ -111,6 +112,41 @@ int create_path(const char *path) return mkdir(p, 0755); } +int parse_get_pair(char **orig_string, char **left, char **right) +{ + char *temp; + char *string = *orig_string; + + if (!string) + return -ENODEV; + + /* eat any whitespace */ + while (isspace(*string) || *string == ',') + ++string; + + /* split based on '=' */ + temp = strsep(&string, "="); + *left = temp; + if (!string) + return -ENODEV; + + /* take the right side and strip off the '"' */ + while (isspace(*string)) + ++string; + if (*string == '"') + ++string; + else + return -ENODEV; + + temp = strsep(&string, "\""); + if (!string || *temp == '\0') + return -ENODEV; + *right = temp; + *orig_string = string; + + return 0; +} + int file_map(const char *filename, char **buf, size_t *bufsize) { struct stat stats; @@ -143,11 +179,21 @@ void file_unmap(char *buf, size_t bufsize) munmap(buf, bufsize); } -size_t buf_get_line(char *buf, size_t buflen, size_t cur) +/* return number of chars until the next newline, skip escaped newline */ +size_t buf_get_line(const char *buf, size_t buflen, size_t cur) { - size_t count = 0; + int escape = 0; + size_t count; + + for (count = cur; count < buflen; count++) { + if (!escape && buf[count] == '\n') + break; - for (count = cur; count < buflen && buf[count] != '\n'; count++); + if (buf[count] == '\\') + escape = 1; + else + escape = 0; + } return count - cur; } |