opt: accept newline in help strings
authorLuke Dashjr <luke-jr+git@utopios.org>
Fri, 7 Feb 2014 16:41:03 +0000 (16:41 +0000)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 11 Feb 2014 02:39:25 +0000 (13:09 +1030)
This correctly continues on the next line indented.

Signed-off-by: Luke Dashjr <luke-jr+git@utopios.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/opt/usage.c

index ff0545591ed4050a5153aa5c8d6db2041a1295e4..494b179bfde97ccb93c8969ce066f1b5860b5097 100644 (file)
@@ -47,7 +47,7 @@ static size_t consume_words(const char *words, size_t maxlen, size_t *prefix)
        size_t oldlen, len;
 
        /* Swallow leading whitespace. */
        size_t oldlen, len;
 
        /* Swallow leading whitespace. */
-       *prefix = strspn(words, " ");
+       *prefix = strspn(words, " \n");
        words += *prefix;
 
        /* Use at least one word, even if it takes us over maxlen. */
        words += *prefix;
 
        /* Use at least one word, even if it takes us over maxlen. */
@@ -55,7 +55,9 @@ static size_t consume_words(const char *words, size_t maxlen, size_t *prefix)
        while (len <= maxlen) {
                oldlen = len;
                len += strspn(words+len, " ");
        while (len <= maxlen) {
                oldlen = len;
                len += strspn(words+len, " ");
-               len += strcspn(words+len, " ");
+               if (words[len] == '\n')
+                       break;
+               len += strcspn(words+len, " \n");
                if (len == oldlen)
                        break;
        }
                if (len == oldlen)
                        break;
        }