diff options
author | Holden Rohrer <hr@hrhr.dev> | 2020-03-31 23:19:35 -0400 |
---|---|---|
committer | Holden Rohrer <hr@hrhr.dev> | 2020-03-31 23:19:35 -0400 |
commit | ef71654b996bcbdb769fe53f63f54afd54b741b7 (patch) | |
tree | 487053402bf514a7d004e8651147b47c7c1a94c8 | |
parent | a8003259532cabfb88dfb2db6de1c35a37fe766e (diff) |
added leader command
-rw-r--r-- | badroff.c | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -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')); |