From f5e156742cc38c698b2fcec550f186fc252bc0cf Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Sun, 24 May 2020 18:37:09 -0400 Subject: wsclean clarified (i think) --- badroff.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/badroff.c b/badroff.c index 5324aae..ab6fb69 100644 --- a/badroff.c +++ b/badroff.c @@ -279,17 +279,14 @@ char* cmd(void){ // normal typesetting void wsclean(char* txt){ - size_t disp = 0; - size_t firstws = 0; - for (size_t i = 0; i == 0 || txt[i-1] != 0; i++){ - if ( (txt[i] == ' ' || txt[i] == '\n') && txt[i-1] != ' '){ - firstws = i; - } - if (txt[i] == '\n'){ - disp += i-firstws; - } - txt[i-disp] = txt[i]; + int nl = 0; // count of newlines + size_t i; + for (i = strlen(txt); i > 0; i--) { // start at end [i-1] and dec + if (txt[i-1] == '\n') nl++; // count up newlines + else if (txt[i-1] != ' ') break; // and break on unpadded text } + memset(txt+i, '\n', nl); // add #nl newlines at [i, i+nl) + txt[i+nl] = 0; // finish string } #define nbspchr (char) 255 void nbspclean(char* txt){ -- cgit