aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-05-29 02:10:29 -0400
committerHolden Rohrer <hr@hrhr.dev>2020-05-29 02:12:32 -0400
commite51413c3520f46d2488ed566390cacb5de92897d (patch)
treedb2e2fbff7df4f29abce679854aa2c3b58fa449b
parent99dee0124378fc66e1db94d3d010786bcbb15725 (diff)
badroff can now handle tiny widths
-rw-r--r--README5
-rw-r--r--badroff.c14
-rw-r--r--phrase-circuit.src2
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<width-strlen(end); i++)
+ for (int i=startlen; i<max; i++)
fin[i] = repeat[i % rptln];
return fin;
}
diff --git a/phrase-circuit.src b/phrase-circuit.src
index 020c97f..8e90cf2 100644
--- a/phrase-circuit.src
+++ b/phrase-circuit.src
@@ -1,4 +1,4 @@
-.W 34
+.W 40
.V 10
.CT Holden Rohrer
.V 2