From e51413c3520f46d2488ed566390cacb5de92897d Mon Sep 17 00:00:00 2001
From: Holden Rohrer
Date: Fri, 29 May 2020 02:10:29 -0400
Subject: badroff can now handle tiny widths
---
README | 5 ++---
badroff.c | 14 ++++++++++++--
phrase-circuit.src | 2 +-
3 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/README b/README
index 843ffbf..47fb9b8 100644
--- a/README
+++ b/README
@@ -43,9 +43,8 @@ mainloop.
# Bugs
-It mostly segfaults on line overfill (i.e. trying to center oversized
-text or unfoldable lines are completely unhandled). Error handling
-should probably be used, but that is a nontrivial addition.
+Graceful folding of over-long lines isn't implemented. It is just left
+as-is.
# Return Value
diff --git a/badroff.c b/badroff.c
index e19bf03..6f767bb 100644
--- a/badroff.c
+++ b/badroff.c
@@ -123,12 +123,22 @@ static char* leader(char* txt){
end = repeat;
repeat = " . ";
}
+ int startlen = strlen(start);
+ int endlen = strlen(end);
+ int rptln = strlen(repeat);
+ if (startlen + endlen > width) {
+ fin = malloc(sizeof(char)*(startlen+endlen+2));
+ memcpy(fin, start, startlen);
+ fin[startlen] = ' ';
+ memcpy(fin+startlen+1, end, endlen+1);
+ return fin;
+ }
fin = malloc(sizeof(char)*(width+2));
fin[width] = '\n'; fin[width+1] = 0;
strcpy(fin, start);
- size_t max = width-strlen(end); size_t rptln = strlen(repeat);
+ size_t max = width-endlen+1;
strcpy(fin+max, end);
- for (int i=strlen(start); i