forked from chocolatiers/doom-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
removectrlm.c
71 lines (55 loc) · 1.03 KB
/
removectrlm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <string.h>
void convertfile(char *filename)
{
FILE *f;
int len, rc;
char *file, *end;
f = fopen(filename, "r+");
if (!f)
{
fprintf(stderr, "Could not open [%s]\n", filename);
exit(-1);
}
fseek(f, 0, SEEK_END);
len = ftell(f);
fseek(f, 0, SEEK_SET);
file = (char *) malloc(len);
rc = fread(file, len, 1, f);
if (rc != 1)
{
fprintf(stderr, "Could not read [%s]\n", filename);
exit(-1);
}
end = file + len;
while (file != end)
{
if (*file == 13) *file = ' ';
file++;
}
file -= len;
rewind(f);
if (fwrite(file, len, 1, f) != 1)
{
fprintf(stderr, "Could not write back [%s]\n", filename);
return;
}
if (fclose(f))
{
fprintf(stderr, "Be worried. I couldn't fclose() [%s]\n", filename);
}
}
int main(int c, char **v)
{
int i, len;
for (i=1 ; i<c ; i++)
{
len = strlen(v[i]);
if (v[i][len-2] == '.')
{
if (v[i][len-1] == 'h' || v[i][len-1] == 'c')
convertfile(v[i]);
}
}
return 0;
}