diff options
author | Holden Rohrer <hr@hrhr.dev> | 2020-05-29 02:10:29 -0400 |
---|---|---|
committer | Holden Rohrer <hr@hrhr.dev> | 2020-05-29 02:12:32 -0400 |
commit | e51413c3520f46d2488ed566390cacb5de92897d (patch) | |
tree | db2e2fbff7df4f29abce679854aa2c3b58fa449b /badroff.c | |
parent | 99dee0124378fc66e1db94d3d010786bcbb15725 (diff) |
badroff can now handle tiny widths
Diffstat (limited to 'badroff.c')
-rw-r--r-- | badroff.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -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; } |