From 4c1b1fc6a32061e86dedd6f34ed352cfda380feb Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Thu, 30 Jul 2020 14:37:46 -0400 Subject: Replace catf with something that tracks len Also the old catf would be broken with -DNDEBUG oops! --- ui.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'ui.c') diff --git a/ui.c b/ui.c index c92fb01..b6aaafc 100644 --- a/ui.c +++ b/ui.c @@ -465,45 +465,38 @@ static void statusUpdate(void) { if (window->heat > others.heat) others.heat = window->heat; } char buf[256] = ""; + struct Cat cat = { buf, sizeof(buf), 0 }; catf( - buf, sizeof(buf), "\3%d%s %u ", + &cat, "\3%d%s %u ", idColors[window->id], (num == windows.show ? "\26" : ""), num ); if (!window->ignore || window->mute) { - catf( - buf, sizeof(buf), "%s%s ", - &"-"[window->ignore], &"="[!window->mute] - ); + catf(&cat, "%s%s ", &"-"[window->ignore], &"="[!window->mute]); } - catf(buf, sizeof(buf), "%s ", idNames[window->id]); + catf(&cat, "%s ", idNames[window->id]); if (window->mark && window->unreadWarm) { catf( - buf, sizeof(buf), "\3%d+%d\3%d%s", + &cat, "\3%d+%d\3%d%s", (window->heat > Warm ? White : idColors[window->id]), window->unreadWarm, idColors[window->id], (window->scroll ? "" : " ") ); } if (window->scroll) { - catf(buf, sizeof(buf), "~%d ", window->scroll); + catf(&cat, "~%d ", window->scroll); } statusAdd(buf); } wclrtoeol(status); + struct Cat cat = { title, sizeof(title), 0 }; const struct Window *window = windows.ptrs[windows.show]; - snprintf(title, sizeof(title), "%s %s", network.name, idNames[window->id]); + catf(&cat, "%s %s", network.name, idNames[window->id]); if (window->mark && window->unreadWarm) { - catf( - title, sizeof(title), " +%d%s", - window->unreadWarm, &"!"[window->heat < Hot] - ); + catf(&cat, " +%d%s", window->unreadWarm, &"!"[window->heat < Hot]); } if (others.unread) { - catf( - title, sizeof(title), " (+%d%s)", - others.unread, &"!"[others.heat < Hot] - ); + catf(&cat, " (+%d%s)", others.unread, &"!"[others.heat < Hot]); } } @@ -638,10 +631,11 @@ static void notify(uint id, const char *str) { struct Util util = uiNotifyUtil; utilPush(&util, idNames[id]); char buf[1024] = ""; + struct Cat cat = { buf, sizeof(buf), 0 }; while (*str) { struct Style style = Reset; size_t len = styleParse(&style, &str); - catf(buf, sizeof(buf), "%.*s", (int)len, str); + catf(&cat, "%.*s", (int)len, str); str += len; } utilPush(&util, buf); -- cgit 1.4.1