aboutsummaryrefslogtreecommitdiff
path: root/archived/wrap.c
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-11-29 17:21:47 +0100
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-11-29 17:21:47 +0100
commitbc4dbc02d2ffeca03ed728f3f1f31d7cc969f655 (patch)
treec0a429fb8a419b3bab00834c0a4d30130b42520f /archived/wrap.c
parent51de26be505c781dd17e4c1ff90dd1f4c46899b9 (diff)
checkpoint
Diffstat (limited to 'archived/wrap.c')
-rw-r--r--archived/wrap.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/archived/wrap.c b/archived/wrap.c
new file mode 100644
index 0000000..57506b8
--- /dev/null
+++ b/archived/wrap.c
@@ -0,0 +1,52 @@
+// 1. Search backwards for whitespace
+// - found?
+// y) wrap
+// n) break at limit
+// - end?
+// y) terminate
+// n) goto 1. with offset += limit
+void
+wrap(u8* Text, u32 Len, u32 XLimit, u32 YLimit)
+{
+ u32 SearchingOffset = XLimit;
+ u32 X = SearchingOffset;
+ u32 Y = 0;
+ u8 t;
+ u32 PrevX = 0;
+
+ while (X < Len)
+ {
+ // Search for whitespace to break on
+ while (1)
+ {
+ if (is_whitespace(Text[X])) break;
+
+ X--;
+
+ // if we got back to the previous position break on Text[SearchingOffset]
+ if (X == PrevX)
+ {
+ X = XLimit;
+ break;
+ }
+ }
+
+ // break
+ t = Text[X];
+ *(Text + X) = '\0';
+ tb_printf(0, Y, 0, 0, "%s", Text + PrevX);
+ Text[X] = t;
+ Y++;
+ if (Y >= YLimit) break;
+
+ // consume leading whitespace
+ while (is_whitespace(Text[X])) X++;
+
+ PrevX = X;
+ X += XLimit;
+ }
+
+ tb_printf(0, Y, 0, 0, "%s", Text + PrevX);
+
+ return;
+}