diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-08-31 11:36:01 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-08-31 11:36:01 +0200 |
commit | bbc19baa50c513973c86a7f5c2fb7a31678d6cd5 (patch) | |
tree | 2ad82ce27b143d07eb9f5d6a079bcaaa1bf93ef9 /src/basic/util.c | |
parent | 6fb350fbe9f9946d34df0196ed501f1ee1565f2c (diff) | |
parent | 8ab00959fb9758510c7b88bb1e8cf03162361e15 (diff) |
Merge pull request #1083 from filbranden/configparse1
A few more tweaks to extract_first_word
Diffstat (limited to 'src/basic/util.c')
-rw-r--r-- | src/basic/util.c | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/basic/util.c b/src/basic/util.c index f752595ca1..a9071aa117 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -5754,40 +5754,39 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra switch (state) { case START: - if (c == 0) { - if (flags & EXTRACT_DONT_COALESCE_SEPARATORS) - if (!GREEDY_REALLOC(s, allocated, sz+1)) - return -ENOMEM; + if (flags & EXTRACT_DONT_COALESCE_SEPARATORS) + if (!GREEDY_REALLOC(s, allocated, sz+1)) + return -ENOMEM; + + if (c == 0) goto finish_force_terminate; - } else if (strchr(separators, c)) { + else if (strchr(separators, c)) { if (flags & EXTRACT_DONT_COALESCE_SEPARATORS) { - if (!GREEDY_REALLOC(s, allocated, sz+1)) - return -ENOMEM; (*p) ++; goto finish_force_next; } break; } + /* We found a non-blank character, so we will always + * want to return a string (even if it is empty), + * allocate it here. */ + if (!GREEDY_REALLOC(s, allocated, sz+1)) + return -ENOMEM; + state = VALUE; /* fallthrough */ case VALUE: if (c == 0) goto finish_force_terminate; - else if (c == '\'' && (flags & EXTRACT_QUOTES)) { - if (!GREEDY_REALLOC(s, allocated, sz+1)) - return -ENOMEM; - + else if (c == '\'' && (flags & EXTRACT_QUOTES)) state = SINGLE_QUOTE; - } else if (c == '\\') + else if (c == '\\') state = VALUE_ESCAPE; - else if (c == '\"' && (flags & EXTRACT_QUOTES)) { - if (!GREEDY_REALLOC(s, allocated, sz+1)) - return -ENOMEM; - + else if (c == '\"' && (flags & EXTRACT_QUOTES)) state = DOUBLE_QUOTE; - } else if (strchr(separators, c)) { + else if (strchr(separators, c)) { if (flags & EXTRACT_DONT_COALESCE_SEPARATORS) { (*p) ++; goto finish_force_next; @@ -5891,8 +5890,6 @@ end_escape: case SEPARATOR: if (c == 0) goto finish_force_terminate; - if (flags & EXTRACT_DONT_COALESCE_SEPARATORS) - goto finish_force_next; if (!strchr(separators, c)) goto finish; break; |