diff options
author | Holden Rohrer <hr@hrhr.dev> | 2020-05-24 18:37:09 -0400 |
---|---|---|
committer | Holden Rohrer <hr@hrhr.dev> | 2020-05-24 18:37:09 -0400 |
commit | f5e156742cc38c698b2fcec550f186fc252bc0cf (patch) | |
tree | 4c9400e4b6f9eb50aabb8c7cb720b9c5c156186c | |
parent | b9ad59c4b247708e76a58073c809f85d45d2f3d4 (diff) |
wsclean clarified (i think)
-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){ |