-
Notifications
You must be signed in to change notification settings - Fork 0
/
u2d.c
71 lines (52 loc) · 1.59 KB
/
u2d.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
/* U2D.COM is a simplfied UNIX2DOS clone for CP/M */
/* Written by Dean Jenkins */
/* 23rd October 2023 */
/* License: MIT */
#include <stdio.h>
char *filename_in = NULL;
char *filename_out = "NEWDOS.TXT";
int main(int argc, char *argv[])
{
FILE *fp_in;
FILE *fp_out;
char buf[2];
int mode = 1; /* Insert CR */
printf("U2D.COM is a UNIX2DOS clone\n");
printf("Written by Dean Jenkins v0.3 07/11/2023\n");
printf("U2D <input filename>\n");
if (argc != 2)
{
printf("Please specify an input filename\n");
exit(1);
}
filename_in = argv[1];
fp_in = fopen(filename_in, "rb");
if (!fp_in)
{
printf("File '%s' failed to open\n", filename_in);
exit(1);
}
printf("Input file '%s' was opened\n", filename_in);
fp_out = fopen(filename_out, "wb");
if (!fp_out)
{
printf("File '%s' failed to open\n", filename_out);
close(fp_in);
exit(1);
}
printf("Output file '%s' was opened\n", filename_out);
while (fgets(buf, 2, fp_in) != NULL)
{
if (buf[0] == 0x1A) /* EOF marker padding */
break;
if (buf[0] == 0x00) /* NUL marker padding */
break;
if (buf[0] == 0x0D) /* CR */
mode = 0; /* File is already in DOS format */
if (buf[0] == 0x0A && mode == 1) /* LF */
fputc(0x0D, fp_out); /* Inject a CR */
fputc(buf[0], fp_out); /* Write to new file */
}
fclose(fp_in);
fclose(fp_out);
}