diff options
-rw-r--r-- | badroff.c | 27 |
1 files changed, 23 insertions, 4 deletions
@@ -1,8 +1,9 @@ #include <stdio.h> -#include "buf.h" #include <string.h> #include <stdlib.h> +#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<len; i++){ // turn into a nested loop + if (i == ' ') ws = i; + if (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; |