aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-04-01 13:51:38 -0400
committerHolden Rohrer <hr@hrhr.dev>2020-04-01 15:17:10 -0400
commit7ab511a476822ac1769c9be64b1ca315af6f983f (patch)
tree2da9ff9c927405284fc4fe7b5c4d35518e77fe6d
parentef71654b996bcbdb769fe53f63f54afd54b741b7 (diff)
partial migration of typeset
-rw-r--r--badroff.c27
1 files 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 <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;