Skip to content
Myr

trailing_whitespace.c

This file

Path

tools/trailing_whitespace.c

32 lines · 790 bytes · C

Last changed by

Fix trailing whitespaceSean Barrettbefore adoption2bb4a0a

History of this file

Take it

1#define STB_DEFINE2#include "stb.h"34int main(int argc, char **argv)5{6   int i;7   for (i=1; i < argc; ++i) {8      int len;9      FILE *f;10      char *s = stb_file(argv[i], &len);11      char *end, *src, *dest;12      if (s == NULL) {13         printf("Couldn't read file '%s'.\n", argv[i]);14         continue; 15      }16      end = s + len;17      src = dest = s;18      while (src < end) {19         char *start=0;20         while (src < end && *src != '\n' && *src != '\r')21            *dest++ = *src++;22         while (dest-1 > s && (dest[-1] == ' ' || dest[-1] == '\t'))23            --dest;24         while (src < end && (*src == '\n' || *src == '\r'))25            *dest++ = *src++;26      }27      f = fopen(argv[i], "wb");28      fwrite(s, 1, dest-s, f);29      fclose(f);30   }31    return 0;32}