https://wiki.preterhuman.net/index.php?title=DOS2UNIX.C&feed=atom&action=history
DOS2UNIX.C - Revision history
2024-03-28T22:50:44Z
Revision history for this page on the wiki
MediaWiki 1.35.0
https://wiki.preterhuman.net/index.php?title=DOS2UNIX.C&diff=14316&oldid=prev
Netfreak: Created page with "<pre> /* Converts DOS text file to UNIX/AMIGA format by removing CR's */ #include <stdio.h> #include <conio.h> #include <dir.h> #include <alloc.h> #include <io.h> char *fn..."
2020-07-23T18:45:25Z
<p>Created page with "<pre> <span dir="auto"><span class="autocomment">Converts DOS text file to UNIX/AMIGA format by removing CR's: </span> #include <stdio.h> #include <conio.h> #include <dir.h> #include <alloc.h> #include <io.h> char *fn..."</span></p>
<p><b>New page</b></p><div><pre><br />
/* Converts DOS text file to UNIX/AMIGA format by removing CR's */<br />
<br />
<br />
#include <stdio.h><br />
#include <conio.h><br />
#include <dir.h><br />
#include <alloc.h><br />
#include <io.h><br />
<br />
<br />
char *fnames[1024];<br />
<br />
<br />
main(int argc,char **argv)<br />
{<br />
static struct ffblk ffblk;<br />
int i, done, num_found = 0;<br />
<br />
if(argc < 2) {<br />
printf("DOS2UNIX converts DOS textfiles to UNIX/Amiga format\n");<br />
printf("usage: dos2unix <DOSFile>\n");<br />
printf("Wildcards allowed\n");<br />
exit(0);<br />
}<br />
<br />
done = findfirst(argv[1], &ffblk, 0);<br />
while (done == 0) {<br />
fnames[num_found] = malloc(strlen(ffblk.ff_name) + 1);<br />
strcpy(fnames[num_found++], ffblk.ff_name);<br />
done = findnext(&ffblk);<br />
}<br />
<br />
for(i = 0; i < num_found; i++)<br />
convert(fnames[i]);<br />
<br />
printf("OK.\n");<br />
<br />
for(i = 0; i < num_found; i++)<br />
free(fnames[i]);<br />
}<br />
<br />
<br />
convert(char *dosfname)<br />
{<br />
static unsigned char buffer[32768];<br />
FILE *unixf, *dosf;<br />
unsigned i, numread;<br />
<br />
dosf = fopen(dosfname, "rb");<br />
unixf = fopen("DOSTEMP.$$$", "wb");<br />
<br />
printf("Converting %s...\n", dosfname);<br />
<br />
do {<br />
numread = fread(buffer, 1, sizeof(buffer), dosf);<br />
for(i = 0; i < numread; i++) {<br />
if(buffer[i] != 0x0D)<br />
fwrite(&buffer[i], 1, 1, unixf);<br />
}<br />
} while(numread == sizeof(buffer));<br />
<br />
fclose(unixf);<br />
fclose(dosf);<br />
<br />
remove(dosfname);<br />
rename("DOSTEMP.$$$", dosfname);<br />
}<br />
</pre><br />
<br />
[[Category:Source Code]]</div>
Netfreak