diff options
-rw-r--r-- | badroff.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -338,17 +338,18 @@ static void nbspclean(char* txt){ } } -static char* wsadd(char* txt, int lnct) { - int len = strlen(txt) + lnct*indlevel; - txt = realloc(txt, sizeof(char)*(len+1)); - char* end = txt + len; - char *nl, *last; nl = last = txt; - while ( (nl = memchr(nl, '\n', end-nl))[1] ) { - memmove(last+indlevel, last, nl-last); - memset(last, ' ', indlevel); - last = nl+1; +static void wsadd(char** txt, int lnct) { + int len = strlen(*txt); + *txt = realloc(*txt, sizeof(char)*(len + lnct*indlevel + 1)); + char* nl = *txt; + while (*nl) { + nl += indlevel; + memmove(nl, nl-indlevel, len+1); + memset(nl-indlevel, ' ', indlevel); + char* last = nl; + nl = (char*)memchr(nl, '\n', len)+1; + len -= nl-last; } - return txt; } char* wordset(char* txt){ @@ -367,7 +368,7 @@ char* wordset(char* txt){ } } - orig = wsadd(orig, ln); + wsadd(&orig, ln); wsclean(orig); // remove trailing whitespace nbspclean(orig); |