diff options
author | Holden Rohrer <hr@hrhr.dev> | 2020-04-02 11:56:13 -0400 |
---|---|---|
committer | Holden Rohrer <hr@hrhr.dev> | 2020-04-02 11:56:13 -0400 |
commit | 1b6653ff69493802788caf9d473ab7feb216e673 (patch) | |
tree | cd3f3545c8a33a2ee352f671dcc43b989e29d9ee | |
parent | 7684f0844f02ed4f28e240bfe8e0baa1e1f58365 (diff) |
added vert() and simplified wordset() framework
-rw-r--r-- | badroff.c | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -146,11 +146,15 @@ char* finlineset(char* txt){ endlineset = true; return str; } +char* vert(char* txt){ + int ln; sscanf(txt, "%d", &ln); + return chrmult('\n', ln); +} char* cmds[] = // MUST be sorted alphabetically - {"CT ", "ELS", "FIL ", "LD ", "LS", "W "}; + {"CT ", "ELS", "FIL ", "LD ", "LS", "V ", "W "}; char* (*call[])(char* txt) = - {center, finlineset, fillline, leader, lineset, setwidth}; + {center, finlineset, fillline, leader, lineset, vert, setwidth}; char* cmd(void){ char* dat = popstrbuf(inbuf, chrfill('\n')); @@ -209,9 +213,8 @@ char* wordset(char* txt){ } -char* typeset(void){ - size_t len = chrfill('\n'); - return wordset(popstrbuf(inbuf, len)); +char* norm(void){ + return popstrbuf(inbuf, chrfill('\n')); } // a parser to choose when to typeset and when to run a command @@ -221,14 +224,14 @@ char* line(void){ if ( (sz = fillbuf(2)) == 0) return ""; char* twobytes = peekstrbuf(inbuf, 0, 2); // .., .\n, or ^.? - if (sz == 1 || twobytes[1] == '\n') return typeset(); + if (sz == 1 || twobytes[1] == '\n') return norm(); if (twobytes[0] == '.') popchrbuf(inbuf); if (twobytes[0] == '.' && twobytes[1] != '.'){ char* data = cmd(); if (data) return data; return line(); } else { - return typeset(); + return norm(); } } @@ -244,8 +247,8 @@ int main(int argc, char** argv){ } char* out; while ( (out = line())[0] != '\0'){ - printf("%s",out); - // free(out); + printf("%s",wordset(out)); + free(out); } fclose(in); return 0; |