From 9492c7fce507cd5cd5172d6e2bf2b86573198806 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 10 Oct 2018 06:36:12 -0500 Subject: Rewrite of watch. --- lib/linestack.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lib/linestack.c') diff --git a/lib/linestack.c b/lib/linestack.c index 99807ccf..fb6cc1e4 100644 --- a/lib/linestack.c +++ b/lib/linestack.c @@ -1,6 +1,11 @@ #include "toys.h" -// A linestack is an array of struct ptr_len. +// The design idea here is indexing a big blob of (potentially mmaped) data +// instead of copying the data into a zillion seperate malloc()s. + +// A linestack is an array of struct ptr_len, with a currently used len +// and max tracking the memory allocation. This indexes existing string data, +// the lifetime of which is tracked externally. // Insert one stack into another before position in old stack. // (Does not copy contents of strings, just shuffles index array contents.) @@ -92,8 +97,7 @@ int crunch_str(char **str, int width, FILE *out, char *escmore, for (end = start = *str; *end; columns += col, end += bytes) { wchar_t wc; - if ((bytes = utf8towc(&wc, end, 4))>0 && (col = wcwidth(wc))>=0) - { + if ((bytes = utf8towc(&wc, end, 4))>0 && (col = wcwidth(wc))>=0) { if (!escmore || wc>255 || !strchr(escmore, wc)) { if (width-columns