aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-04-02 11:56:13 -0400
committerHolden Rohrer <hr@hrhr.dev>2020-04-02 11:56:13 -0400
commit1b6653ff69493802788caf9d473ab7feb216e673 (patch)
treecd3f3545c8a33a2ee352f671dcc43b989e29d9ee
parent7684f0844f02ed4f28e240bfe8e0baa1e1f58365 (diff)
added vert() and simplified wordset() framework
-rw-r--r--badroff.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/badroff.c b/badroff.c
index c86e29f..baed5a7 100644
--- a/badroff.c
+++ b/badroff.c
@@ -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;