aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-03-31 23:19:35 -0400
committerHolden Rohrer <hr@hrhr.dev>2020-03-31 23:19:35 -0400
commitef71654b996bcbdb769fe53f63f54afd54b741b7 (patch)
tree487053402bf514a7d004e8651147b47c7c1a94c8
parenta8003259532cabfb88dfb2db6de1c35a37fe766e (diff)
added leader command
-rw-r--r--badroff.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/badroff.c b/badroff.c
index 123deba..c28e153 100644
--- a/badroff.c
+++ b/badroff.c
@@ -86,9 +86,25 @@ char* fillline(char* txt){
memset(str, txt[0], width);
return str;
}
+char* leader(char* txt){
+ char* cnxt;
+ char* start = strtok_r(txt, "|", &cnxt);
+ char* repeat = strtok_r(NULL, "|", &cnxt);
+ char* end = strtok_r(NULL, "|", &cnxt);
+ char* 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);
+ strcpy(fin+max, end);
+ for (int i=strlen(start); i<width-strlen(end); i++)
+ fin[i] = repeat[i % rptln];
+ return fin;
+}
-char* cmds[] = {"CT ", "FIL ", "W "}; // MUST be sorted alphabetically
-char* (*call[])(char* txt) = {center, fillline, setwidth};
+char* cmds[] =
+ {"CT ", "FIL ", "LD ", "W "}; // MUST be sorted alphabetically
+char* (*call[])(char* txt) =
+ {center, fillline, leader, setwidth};
char* cmd(void){
char* dat = popstrbuf(inbuf, chrfill('\n'));