diff options
-rw-r--r-- | badroff.c | 50 |
1 files changed, 22 insertions, 28 deletions
@@ -11,6 +11,7 @@ static char* line(void); static char* wordset(char* txt); static void wsclean(char* txt); +static char* norm(void); static FILE* getfile(int argc, char** argv){ if (argc >= 2) @@ -238,43 +239,30 @@ static char* nbrkspc(char* txt){ nbsp = txt[0]; else nbsp = 0; + return NULL; } +static char* join = NULL; static char* merge(char* txt){ // merges until an endgroup - // gather lines - size_t ct; - llnode* head = accumlines(&ct)->next; - // count total length (for malloc) - size_t len = 0; - for (size_t i = 0; i < ct; i++, head = head->next){ - size_t slen = strlen(head->str)-1; - head->str[slen] = 0; // remove the nl character at the end - len += slen; // add the (new) length of string - } - char *str, *pos; - pos = str = malloc(sizeof(char)*(len+2)); - str[len] = '\n'; str[len+1] = 0; // str = "***********\n" - for (size_t i = 0; i < ct; i++){ - wsclean(head->str); - size_t slen = strlen(head->str); - memcpy(pos, head->str, slen); - pos += slen; - llnode* tmp = head; - head = head->next; - free(tmp->str); - free(tmp); + for (char* pos = txt; *pos != '\0'; pos++) { + if (*pos != '\\') txt++; + *pos = *txt; } - return str; + return NULL; +} +static char* nomrg(char* txt){ + join = NULL; + return NULL; } static char* cmds[] = // MUST be sorted alphabetically - {"CT", "EG", "FIL", "LD", "LS", "MRG", "NBSP", "V", "W"}; + {"CT", "EG", "FIL", "LD", "LS", "MRG", "NBSP", "NMRG", "V", "W"}; static char* (*call[])(char* txt) = - {center, fingroup, fillline, leader, lineset, merge, nbrkspc, + {center, fingroup, fillline, leader, lineset, merge, nbrkspc, nomrg, vert, setwidth}; static char* cmd(void){ - char* dat = popstrbuf(inbuf, chrfill('\n')); + char* dat = norm(); int low = 0; int high = sizeof(cmds)/sizeof(*cmds); //len char* proc = NULL; bool found = false; @@ -346,7 +334,14 @@ char* wordset(char* txt){ static char* norm(void){ - return popstrbuf(inbuf, chrfill('\n')); + int len = chrfill('\n'); + char* out = popstrbuf(inbuf,len); + if (join) { + out = realloc(out, len+strlen(join)-1); + strcpy(out+len-1, /* \n loc */ join); + } + wsclean(out); + return out; } // a parser to choose when to typeset and when to run a command @@ -375,7 +370,6 @@ char* line(void){ out = norm(); } nbspsub(out); - wsclean(out); return out; } |