MCPcopy Create free account
hub / github.com/ElementsProject/lightning / consume_words

Function consume_words

ccan/ccan/opt/usage.c:49–77  ·  view source on GitHub ↗

Return number of chars of words to put on this line. * Prefix is set to number to skip at start, maxlen is max width, returns * length (after prefix) to put on this line. * start is set if we start a new line in the source description. */

Source from the content-addressed store, hash-verified

47 * length (after prefix) to put on this line.
48 * start is set if we start a new line in the source description. */
49static size_t consume_words(const char *words, size_t maxlen, size_t *prefix,
50 bool *start)
51{
52 size_t oldlen, len;
53
54 /* Always swollow leading whitespace. */
55 *prefix = strspn(words, " \n");
56 words += *prefix;
57
58 /* Leading whitespace at start of line means literal. */
59 if (*start && *prefix) {
60 oldlen = strcspn(words, "\n");
61 } else {
62 /* Use at least one word, even if it takes us over maxlen. */
63 oldlen = len = strcspn(words, " ");
64 while (len <= maxlen) {
65 oldlen = len;
66 len += strspn(words+len, " ");
67 if (words[len] == '\n')
68 break;
69 len += strcspn(words+len, " \n");
70 if (len == oldlen)
71 break;
72 }
73 }
74
75 *start = (words[oldlen - 1] == '\n');
76 return oldlen;
77}
78
79static char *add_str_len(char *base, size_t *len, size_t *max,
80 const char *str, size_t slen)

Callers 2

add_descFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by 1

mainFunction · 0.68