1 /* fromdos.c : strip the stupid ^M characters without mistakes! */
3 /* this can do in-place conversion or be used as a pipe... */
10 int main(int argc
, char** argv
) {
14 fprintf(stderr
,"usage : %s <files>\nStrips ^M characters.\nCan do in-place conversion of many files or can be used in a pipe\n",argv
[0]);
21 if (c
!= '\n') putchar(c
);
28 for (f
= 1; f
< argc
; f
++) {
29 char* fname
= argv
[f
];
31 FILE* in
= fopen(fname
,"rb");
35 fprintf(stderr
,"%s : %s\n", fname
, strerror(errno
));
38 strcpy(tempname
, fname
);
39 strcat(tempname
, ".temp");
40 out
= fopen(tempname
, "wb");
42 fprintf(stderr
,"%s : %s\n", fname
, strerror(errno
));
49 if (c
== '\n') mod
=1; else putc(c
,out
);
57 fprintf(stderr
,"%s : no change\n", fname
);
59 } else if (rename(tempname
, fname
)) {
60 fprintf(stderr
,"Can't mv %s %s : %s\n",tempname
,fname
,strerror(errno
));