diff options
-rw-r--r-- | badroff.c | 17 |
1 files changed, 7 insertions, 10 deletions
@@ -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){ |