Open files in binary mode to convert DOS to Unix

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28192 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart 2004-07-07 08:24:50 +00:00
parent 3c6e3872b3
commit c69291e99a

View File

@ -69,14 +69,14 @@ main(int argc, char *argv[])
char tmpFile[512]; char tmpFile[512];
sprintf(tmpFile, "%s.tmp", argv[i]); sprintf(tmpFile, "%s.tmp", argv[i]);
fp = fopen(argv[i], "r"); fp = fopen(argv[i], "rb");
if (!fp) if (!fp)
{ {
fprintf(stderr, "Cannot open %s.\n", argv[i]); fprintf(stderr, "Cannot open %s.\n", argv[i]);
i ++; i ++;
continue; continue;
} }
outFile = fopen(tmpFile, "w"); outFile = fopen(tmpFile, "wb");
if (!outFile) if (!outFile)
{ {
fprintf(stderr, "Cannot open %s.\n", tmpFile); fprintf(stderr, "Cannot open %s.\n", tmpFile);
@ -112,20 +112,28 @@ void translate(FILE *ifp, FILE *ofp, int unix2Dos)
int c,d; int c,d;
if (!unix2Dos) if (!unix2Dos)
{
/* DOS2Unix */ /* DOS2Unix */
while ((c = getc(ifp)) != EOF){ while ((c = getc(ifp)) != EOF)
{
if (c == CR) if (c == CR)
switch(d = getc(ifp)){ /* check to see if LF follows */ {
case LF: switch(d = getc(ifp))
putc(d,ofp); /* if so, ignore CR */ { /* check to see if LF follows */
break; case LF:
default: putc(d,ofp); /* if so, ignore CR */
putc(c,ofp); /* if not, output CR and following char */ break;
putc(d,ofp); default:
} else putc(c, ofp); /* c is not a CR */ putc(c,ofp); /* if not, output CR and following char */
putc(d,ofp);
}
}
else
putc(c, ofp); /* c is not a CR */
} }
}
else else
{
/* Unix2DOS */ /* Unix2DOS */
while ((c = getc(ifp)) != EOF){ while ((c = getc(ifp)) != EOF){
if (c == CR) if (c == CR)
@ -134,6 +142,7 @@ void translate(FILE *ifp, FILE *ofp, int unix2Dos)
putc(CR, ofp); /* add CR before each LF */ putc(CR, ofp); /* add CR before each LF */
putc(c, ofp); putc(c, ofp);
} }
}
} }
void usage() void usage()