2 * Copy a text file with end-of-line character transformation (EOL)
4 * Usage: rline input-file output-file
11 char* convert_path(char* origpath
)
16 newpath
= strdup(origpath
);
19 while (newpath
[i
] != 0)
22 if (newpath
[i
] == '\\')
28 if (newpath
[i
] == '/')
45 if (fh
< 0 || fstat (fh
, &st
) < 0)
47 return (int) st
.st_size
;
50 int main(int argc
, char* argv
[])
64 /* Terminate the line with windows EOL characters (CRLF) */
70 fprintf(stderr
, "Wrong argument count\n");
74 path1
= convert_path(argv
[1]);
75 path2
= convert_path(argv
[2]);
77 in
= fopen(path1
, "rb");
80 perror("Cannot open input file");
85 in_buf
= malloc(in_size
);
88 perror("Not enough free memory");
93 out
= fopen(path2
, "wb");
96 perror("Cannot open output file");
102 n_in
= fread(in_buf
, 1, in_size
, in
);
105 while (in_ptr
< in_size
)
109 while ((in_ptr
+ linelen
< in_size
) && (in_buf
[in_ptr
+ linelen
] != '\r') && (in_buf
[in_ptr
+ linelen
] != '\n'))
115 n_out
= fwrite(&in_buf
[in_ptr
], 1, linelen
, out
);
118 /* Terminate the line */
119 n_out
= fwrite(&eol_buf
[0], 1, sizeof(eol_buf
), out
);
121 if ((in_ptr
< in_size
) && (in_buf
[in_ptr
] == '\r'))
126 if ((in_ptr
< in_size
) && (in_buf
[in_ptr
] == '\n'))