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

Function consume_words

ccan/ccan/opt/usage.c:52–81  ·  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

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