aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/interestingtimes.c4
-rw-r--r--lib/linestack.c15
2 files changed, 12 insertions, 7 deletions
diff --git a/lib/interestingtimes.c b/lib/interestingtimes.c
index 636964aa..c3ed9f9a 100644
--- a/lib/interestingtimes.c
+++ b/lib/interestingtimes.c
@@ -216,8 +216,8 @@ int scan_key(char *scratch, int miliwait)
// Read 1 byte so we don't overshoot sequence match. (We can deviate
// and fail to match, but match consumes entire buffer.)
- if (toys.signal || 1 != read(0, scratch+1+*scratch, 1))
- return toys.signal ? -3 : -1;
+ if (toys.signal>0 || 1 != read(0, scratch+1+*scratch, 1))
+ return (toys.signal>0) ? -3 : -1;
++*scratch;
}
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<col) break;
if (out) fwrite(end, bytes, 1, out);
@@ -108,8 +112,9 @@ int crunch_str(char **str, int width, FILE *out, char *escmore,
}
col = width-columns;
if (col<1) break;
- if (escout) col = escout(out, col, wc);
- else if (out) fwrite(end, bytes, 1, out);
+ if (escout) {
+ if ((col = escout(out, col, wc))<0) break;
+ } else if (out) fwrite(end, 1, bytes, out);
}
*str = end;