-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDOS2UNIX.C
52 lines (48 loc) · 1.28 KB
/
DOS2UNIX.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
#include <stdio.h>
#include <string.h>
/* A very simple dos-to-unix text file translator.
* Johan. K. Reinalda, WG7J 930625
*/
void main(int argc,char *argv[]) {
int i;
if(argc == 1)
return;
for(i=1;i<argc;i++) {
FILE *fpo,*fpn;
char *cp;
char back[128];
char buf[128];
strcpy(back,argv[i]);
if((cp=strchr(back,'.')) != NULL)
*cp = '\0';
strcat(back,".&&&");
unlink(back);
if(rename(argv[i],back) != 0) {
printf("Cannot rename %s to %s\n",argv[i],back);
continue;
}
if((fpo=fopen(back,"rb")) == NULL) {
printf("Cannot open %s\n",back);
continue;
}
if((fpn=fopen(argv[i],"wb")) == NULL) {
printf("Cannot write %s\n",argv[i]);
continue;
}
while(fgets(buf,sizeof(buf),fpo) != NULL) {
cp = buf;
while(*cp) {
if(*cp == 0xd || *cp == 0xa) {
*cp = '\0';
break;
}
cp++;
}
fprintf(fpn,"%s\n",buf);
}
fclose(fpo);
fclose(fpn);
unlink(back);
}
return;
}