mirror of
https://github.com/nothings/stb
synced 2024-12-11 18:53:58 +03:00
Fix trailing whitespace
This commit is contained in:
parent
7a69424f15
commit
2bb4a0accd
32
tools/trailing_whitespace.c
Normal file
32
tools/trailing_whitespace.c
Normal file
@ -0,0 +1,32 @@
|
||||
#define STB_DEFINE
|
||||
#include "stb.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
for (i=1; i < argc; ++i) {
|
||||
int len;
|
||||
FILE *f;
|
||||
char *s = stb_file(argv[i], &len);
|
||||
char *end, *src, *dest;
|
||||
if (s == NULL) {
|
||||
printf("Couldn't read file '%s'.\n", argv[i]);
|
||||
continue;
|
||||
}
|
||||
end = s + len;
|
||||
src = dest = s;
|
||||
while (src < end) {
|
||||
char *start=0;
|
||||
while (src < end && *src != '\n' && *src != '\r')
|
||||
*dest++ = *src++;
|
||||
while (dest-1 > s && (dest[-1] == ' ' || dest[-1] == '\t'))
|
||||
--dest;
|
||||
while (src < end && (*src == '\n' || *src == '\r'))
|
||||
*dest++ = *src++;
|
||||
}
|
||||
f = fopen(argv[i], "wb");
|
||||
fwrite(s, 1, dest-s, f);
|
||||
fclose(f);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user