From 7ab511a476822ac1769c9be64b1ca315af6f983f Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Wed, 1 Apr 2020 13:51:38 -0400 Subject: partial migration of typeset --- badroff.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/badroff.c b/badroff.c index c28e153..a06fb30 100644 --- a/badroff.c +++ b/badroff.c @@ -1,8 +1,9 @@ #include -#include "buf.h" #include #include +#include "buf.h" + typedef enum { false, true @@ -147,8 +148,26 @@ size_t nextws(size_t start){//searches for \n or [^ \n]-1 in buffer return len; } +char* wordtypeset(char* txt){ // always ends with \n + size_t len = strlen(txt); + size_t ws = width; + for (size_t i=0; i width){ + txt[ws] = '\n'; + txt += ws; + len -= ws; + ws = width; + } + } + + return txt; +} + char* typeset(void){ - size_t len = chrnfill('\n', width+1); //+1 for \n on 81-char lines + size_t len = chrfill('\n'); + return wordtypeset(popstrbuf(inbuf, len)); + /*size_t len = chrnfill('\n', width+1); //+1 for \n on 81-char lines char* next = peekstrbuf(inbuf, 0, len); size_t wsend = 0; if (next[--len] == '\n'){ @@ -167,7 +186,7 @@ char* typeset(void){ free(next); char* ln = popstrbuf(inbuf, wsend+1); ln[len+1] = '\n'; ln[len+2] = 0; - return ln; + return ln;*/ } // a parser to choose when to typeset and when to run a command @@ -201,7 +220,7 @@ int main(int argc, char** argv){ char* out; while ( (out = line())[0] != '\0'){ printf("%s",out); - free(out); + // free(out); } fclose(in); return 0; -- cgit