From b30b93f67212c8d4c172972fd3399cabb8d1be6e Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sat, 8 Feb 2020 23:29:32 -0500 Subject: Use fmemopen to build colored mentions string --- handle.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'handle.c') diff --git a/handle.c b/handle.c index b4601e4..cf0e853 100644 --- a/handle.c +++ b/handle.c @@ -406,34 +406,25 @@ static const char *colorMentions(size_t id, struct Message *msg) { } static char buf[1024]; - size_t len = 0; + FILE *str = fmemopen(buf, sizeof(buf), "w"); + if (!str) err(EX_OSERR, "fmemopen"); + while (*mention) { size_t skip = strspn(mention, ", "); - int n = snprintf( - &buf[len], sizeof(buf) - len, - "%.*s", (int)skip, mention - ); - assert(n >= 0 && len + n < sizeof(buf)); - len += n; + fwrite(mention, skip, 1, str); mention += skip; - size_t word = strcspn(mention, ", "); - char punct = mention[word]; - mention[word] = '\0'; - - n = snprintf( - &buf[len], sizeof(buf) - len, - "\3%02d%s\3", completeColor(id, mention), mention - ); - assert(n > 0 && len + n < sizeof(buf)); - len += n; - - mention[word] = punct; - mention += word; + size_t len = strcspn(mention, ", "); + char punct = mention[len]; + mention[len] = '\0'; + fprintf(str, "\3%02d%s\3", completeColor(id, mention), mention); + mention[len] = punct; + mention += len; } - assert(len + 1 < sizeof(buf)); - buf[len++] = final; - buf[len] = '\0'; + fputc(final, str); + + fclose(str); + buf[sizeof(buf) - 1] = '\0'; return buf; } -- cgit 1.4.0 ea504673de90ef20ffe97330a0'/>
path: root/etc/code.map (unfollow)
Commit message (Collapse)Author
2019-02-12Use a proper fread-realloc loop in hiJune McEnroe
2019-02-12Don't match Rust raw strings inside other stringsJune McEnroe
2019-02-12Add Rust to hiJune McEnroe
This also fixes the block comment pattern to match /* **/ correctly.
2019-02-12Call setlocale in hiJune McEnroe
2019-02-11Install html with -CJune McEnroe
2019-02-10Avoid excessive tags in ttpreJune McEnroe
2019-02-10Generate html for binsJune McEnroe
2019-02-10Use italic for underline in nvim man modeJune McEnroe
This doesn't yet work in Terminal.app: <https://github.com/neovim/neovim/issues/9598>.
2019-02-10Add plain text "language" to hiJune McEnroe
2019-02-10Don't match DQ string inside SQ stringJune McEnroe
2019-02-10Skip only one character if a match fails due to parentJune McEnroe
Really it should skip forward until the parent changes, but this is simpler.
2019-02-10Remove pattend from hiJune McEnroe
2019-02-10Replace uses of pattend with newline patternsJune McEnroe
2019-02-10Add hi debug outputJune McEnroe
2019-02-10Actually do HTML &quot; escapingJune McEnroe
2019-02-10Set git commit.verboseJune McEnroe
2019-02-10Add back missing static keywordJune McEnroe