diff options
author | Holden Rohrer <hr@hrhr.dev> | 2020-05-27 21:43:44 -0400 |
---|---|---|
committer | Holden Rohrer <hr@hrhr.dev> | 2020-05-27 21:43:44 -0400 |
commit | 4949aeea4d490736c79703470930990560c344cf (patch) | |
tree | d67423e24eaa9d70397daac9244040e4135e4aaf | |
parent | af41badc960e98dea393c8c6441709591bbc767e (diff) |
wsclean removes trailing nl's, easing printing
-rw-r--r-- | nodelink.c | 4 | ||||
-rw-r--r-- | read.c | 12 |
2 files changed, 7 insertions, 9 deletions
@@ -19,9 +19,9 @@ link* newlink(node* to) { static void printlink(char* name, link* conn) { if (conn->desc[0]) - printf("Link to %s: %s", name, conn->desc); + printf("Link to %s: %s\n", name, conn->desc); else - printf("Link to %s", name); + printf("Link to %s\n", name); } static void printeach(strbstnode* loc, char reprint) { @@ -15,15 +15,13 @@ void consumespaces(FILE* file) { ungetc(c, file); } -void wsclean(char* txt, size_t sz){ // "string \n \n" -> "string\n\n" - int nl = 0; // count of newlines +void wsclean(char* txt, size_t sz){ // "string \n \n" -> "string" size_t i; - for (i = sz-1; i >= 0; i--) { // start at end [i-1] and dec - if (txt[i] == '\n') nl++; // count up newlines - else if (txt[i] != ' ') break; // and break on unpadded text + for (i = sz; i > 0; i--) { // start at end [i-1] and dec + // break on non-nl, non-space char + if (txt[i-1] != ' ' && txt[i-1] != '\n') break; } - memset(txt+i, '\n', nl); // add #nl newlines at [i, i+nl) - txt[i+nl] = 0; // finish string + txt[i] = 0; // finish string } char* empty(void) { |