Board index » delphi » unix to dos file format conversions

unix to dos file format conversions

Hi guys,

Just wondering if someone out there can help.

I manipulate large text files within VB but sometimes they are in the old
unix format, not DOS. Unix does not have a CR at the end of the line thereby
causing all sorts of problems with the LINE INPUT statement. Using INPUT is
out as I have to act on the contents of each line so it makes sense to read
in a full line and the work on it.

Some text editors (PFE for example) have a nice option to convert UNIX->DOS
and back again which is blindingly fast. I suspect these are C routines but
I was wondering if anybody knows how to achieve a similar thing using VB.

If not, does anyone know how to do this in C as I could write a small
program and shell out to it to do the convert.

Many Thanks

Andrew

 

Re:unix to dos file format conversions


To achieve that in VB you should open the file as binary and read it one
byte at a time writing it to an output file, every time you encounter a CR
you write CRLF to your output file.

I hope this helps,

W d'Anjos

Quote
"Andrew" <andm...@ozemail.com.au> wrote in message

news:%bev7.344$hO3.19530@ozemail.com.au...
Quote
> Hi guys,

> Just wondering if someone out there can help.

> I manipulate large text files within VB but sometimes they are in the old
> unix format, not DOS. Unix does not have a CR at the end of the line
thereby
> causing all sorts of problems with the LINE INPUT statement. Using INPUT
is
> out as I have to act on the contents of each line so it makes sense to
read
> in a full line and the work on it.

> Some text editors (PFE for example) have a nice option to convert
UNIX->DOS
> and back again which is blindingly fast. I suspect these are C routines
but
> I was wondering if anybody knows how to achieve a similar thing using VB.

> If not, does anyone know how to do this in C as I could write a small
> program and shell out to it to do the convert.

> Many Thanks

> Andrew

Re:unix to dos file format conversions


Hi,

The simplest method would be to read in a character at a time using fgetc().
If this character is a LR character (0x0a) then write out a CR (0x0d) before
it using fputc:

    int c;

    while( (c = fgetc(fpSrc)) != EOF )
    {
        if( c == 0x0a )
        {    fputc( fpDest, 0x0d );
              fputc( fpDest, 0x0a );
        }
        else
            fputc( fpDest, c );
    }

Wayne.

Quote
"Andrew" <andm...@ozemail.com.au> wrote in message

news:%bev7.344$hO3.19530@ozemail.com.au...
Quote
> Hi guys,

> Just wondering if someone out there can help.

> I manipulate large text files within VB but sometimes they are in the old
> unix format, not DOS. Unix does not have a CR at the end of the line
thereby
> causing all sorts of problems with the LINE INPUT statement. Using INPUT
is
> out as I have to act on the contents of each line so it makes sense to
read
> in a full line and the work on it.

> Some text editors (PFE for example) have a nice option to convert
UNIX->DOS
> and back again which is blindingly fast. I suspect these are C routines
but
> I was wondering if anybody knows how to achieve a similar thing using VB.

> If not, does anyone know how to do this in C as I could write a small
> program and shell out to it to do the convert.

> Many Thanks

> Andrew

Other Threads