diff options
-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')); |