diff options
Diffstat (limited to 'badroff.c')
-rw-r--r-- | badroff.c | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -66,6 +66,12 @@ size_t chrnfill(char chr, size_t sz){//fills to first of chr or sz return len; } +static void consumews(char* str) { + char* pos = str; + while (*pos == ' ') pos++; + memmove(str, pos, strlen(pos)+1); +} + // typesetting config and commands to change. static int width = 80; static char nbsp = 0; @@ -89,7 +95,7 @@ static char* center(char* txt){ return str; } static char* setwidth(char* txt){ - sscanf(txt, "%d", &width); + if (isdigit(*txt)) sscanf(txt, "%d", &width); return NULL; } static char* fillline(char* txt){ @@ -100,7 +106,7 @@ static char* fillline(char* txt){ } static char* token(char* txt, char c) { char* end = strchr(txt, c); - *end = 0; + if (end) *end = 0; return end+1; } static char* leader(char* txt){ @@ -262,7 +268,7 @@ static char* merge(char* txt){ // merges until an endgroup } static char* cmds[] = // MUST be sorted alphabetically - {"CT ", "EG", "FIL ", "LD ", "LS", "MRG", "NBSP", "V ", "W "}; + {"CT", "EG", "FIL", "LD", "LS", "MRG", "NBSP", "V", "W"}; static char* (*call[])(char* txt) = {center, fingroup, fillline, leader, lineset, merge, nbrkspc, vert, setwidth}; @@ -282,15 +288,19 @@ static char* cmd(void){ else if (cmp > 0) low = mid + 1; else{ + int len = strlen(mval); found = true; - proc = call[mid](dat+strlen(mval)); + consumews(dat+len); + proc = call[mid](dat+len); break; } } - free(dat); - if (found) return proc; + if (found) { + free(dat); + return proc; + } else { - fprintf(stderr, "SYNTAX ERROR\n"); + fprintf(stderr, "INVALID COMMAND .%s\n",dat); exit(1); } } |