CR LF Problem in Windows XP

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

CR LF Problem in Windows XP

Ron Teitelbaum

All,

 

On WinXP 

Image: Squeak 3.8-6665

 

dir := FileDirectory default.

(fileStream := dir fileNamed: 'test.txt') ascii.

fileStream nextPutAll: 'a\b' withCRs.

fileStream flush; close.

 

I get in bytes in hex  61  OD  62.  I need   61  OA OD  62.

 

I wanted to make sure that this is a bug and not just me doing something wrong.

 

Is there a proper way to get this to work?

 

Thanks,

 

Ron Teitelbaum

[hidden email]



Reply | Threaded
Open this post in threaded view
|

Re: CR LF Problem in Windows XP

Chris Muller-2
Hi Ron, I think CRLFFileStream can detect the underlying platform and
write CRLF's appropriately..

dir := FileDirectory default.
fileStream := CrLfFileStream fileNamed: (dir fullNameFor: 'test.txt').
[ fileStream nextPutAll: 'a\b' withCRs.
fileStream flush; close ] ensure: [ fileStream close ]

 - Chris

--- Ron Teitelbaum <[hidden email]> wrote:

> All,
>
>  
>
> On WinXP
>
> Image: Squeak 3.8-6665
>
>  
>
> dir := FileDirectory default.
>
> (fileStream := dir fileNamed: 'test.txt') ascii.
>
> fileStream nextPutAll: 'a\b' withCRs.
>
> fileStream flush; close.
>
>  
>
> I get in bytes in hex  61  OD  62.  I need   61  OA OD  62.
>
>  
>
> I wanted to make sure that this is a bug and not just me doing
> something
> wrong.
>
>  
>
> Is there a proper way to get this to work?
>
>  
>
> Thanks,
>
>  
>
> Ron Teitelbaum
>
> [hidden email]
>
> >
>


Reply | Threaded
Open this post in threaded view
|

RE: CR LF Problem in Windows XP

Ron Teitelbaum
Thanks Chris,

I saw the CRLF stream but figured there was some magic way to get the file
to use it.  I saw ascii and all those flags for #crlf and wantsEndConversion
or something like that but nothing worked.  

I'm surprised at how few file writing and reading methods there are.  I
tried to add some collection methods earlier and was told there were already
too many methods on collection.  In VW I had outputToFilename: on string and
on collection (created as string with a cr between each item).  Also
outputToFilenameUsingBlock: , not to mention toClipboard.  I would think it
would be nice to add those methods.  How do people feel about adding those
methods before I post a patch that only spawns arguments?

Thanks,

Ron Teitelbaum

> -----Original Message-----
> From: [hidden email] [mailto:squeak-dev-
> [hidden email]] On Behalf Of Chris Muller
> Sent: Tuesday, April 04, 2006 4:02 PM
> To: [hidden email]; The general-purpose Squeak developers list
> Subject: Re: CR LF Problem in Windows XP
>
> Hi Ron, I think CRLFFileStream can detect the underlying platform and
> write CRLF's appropriately..
>
> dir := FileDirectory default.
> fileStream := CrLfFileStream fileNamed: (dir fullNameFor: 'test.txt').
> [ fileStream nextPutAll: 'a\b' withCRs.
> fileStream flush; close ] ensure: [ fileStream close ]
>
>  - Chris
>
> --- Ron Teitelbaum <[hidden email]> wrote:
>
> > All,
> >
> >
> >
> > On WinXP
> >
> > Image: Squeak 3.8-6665
> >
> >
> >
> > dir := FileDirectory default.
> >
> > (fileStream := dir fileNamed: 'test.txt') ascii.
> >
> > fileStream nextPutAll: 'a\b' withCRs.
> >
> > fileStream flush; close.
> >
> >
> >
> > I get in bytes in hex  61  OD  62.  I need   61  OA OD  62.
> >
> >
> >
> > I wanted to make sure that this is a bug and not just me doing
> > something
> > wrong.
> >
> >
> >
> > Is there a proper way to get this to work?
> >
> >
> >
> > Thanks,
> >
> >
> >
> > Ron Teitelbaum
> >
> > [hidden email]
> >
> > >
> >
>
>



Reply | Threaded
Open this post in threaded view
|

Re: CR LF Problem in Windows XP

Yoshiki Ohshima
  Ron,

> I saw the CRLF stream but figured there was some magic way to get the file
> to use it.  I saw ascii and all those flags for #crlf and wantsEndConversion
> or something like that but nothing worked.  

  Didn't a code snippet like following work?

f _ FileStream newFileNamed: 'foo.txt'.
f wantsLineEndConversion: true.
f nextPutAll: 'abc\def' withCRs
f close.

To specify it explicitly:

f _ FileStream newFileNamed: 'foo.txt'.
f wantsLineEndConversion: true.
f lineEndConvention: #crlf.
f nextPutAll: 'abc\def' withCRs.
f close.

should work, too.

-- Yoshiki

Reply | Threaded
Open this post in threaded view
|

RE: CR LF Problem in Windows XP

Ron Teitelbaum
I went back to see what I did.  I only set

lineEndConvention: #crlf.

But then saw the wantsLineEndConversion: wasn't set.  So I figured I was
doing it wrong.  Shouldn't this be automatic for each platform?  

I'll try just setting wantsLineEndConversion: true like you suggested and
see what it does.

Ron Teitelbaum

> -----Original Message-----
> From: [hidden email] [mailto:squeak-dev-
> [hidden email]] On Behalf Of Yoshiki Ohshima
> Sent: Tuesday, April 04, 2006 4:57 PM
> To: The general-purpose Squeak developers list
> Subject: Re: CR LF Problem in Windows XP
>
>   Ron,
>
> > I saw the CRLF stream but figured there was some magic way to get the
> file
> > to use it.  I saw ascii and all those flags for #crlf and
> wantsEndConversion
> > or something like that but nothing worked.
>
>   Didn't a code snippet like following work?
>
> f _ FileStream newFileNamed: 'foo.txt'.
> f wantsLineEndConversion: true.
> f nextPutAll: 'abc\def' withCRs
> f close.
>
> To specify it explicitly:
>
> f _ FileStream newFileNamed: 'foo.txt'.
> f wantsLineEndConversion: true.
> f lineEndConvention: #crlf.
> f nextPutAll: 'abc\def' withCRs.
> f close.
>
> should work, too.
>
> -- Yoshiki



Reply | Threaded
Open this post in threaded view
|

Re: CR LF Problem in Windows XP

Yoshiki Ohshima
  Ron,

> I went back to see what I did.  I only set
>
> lineEndConvention: #crlf.
>
> But then saw the wantsLineEndConversion: wasn't set.  So I figured I was
> doing it wrong.  Shouldn't this be automatic for each platform?

  Note that the instance creation methods of CrLfFileStream and
FileStream both creates an instance of MultiByteFileStream with
different initial setting.  When creating an instance through
CrLfFileStream, it should set automatically, but through FileStream,
it shouldn't.

-- Yoshiki

Reply | Threaded
Open this post in threaded view
|

RE: CR LF Problem in Windows XP

Ron Teitelbaum
Yoshiki,

Don't you think it should set this automatically for Windows systems?  The
method I would like to see is 'this/that' withCRs toFilename: 'test.txt'.
Or (Array with: this with: that) toFilename: 'test.txt'.  It should set
#crlf automatically for windows systems.

Ron

> From: Yoshiki Ohshima
> Sent: Wednesday, April 05, 2006 11:58 AM
>
>   Ron,
>
> > I went back to see what I did.  I only set
> >
> > lineEndConvention: #crlf.
> >
> > But then saw the wantsLineEndConversion: wasn't set.  So I figured I was
> > doing it wrong.  Shouldn't this be automatic for each platform?
>
>   Note that the instance creation methods of CrLfFileStream and
> FileStream both creates an instance of MultiByteFileStream with
> different initial setting.  When creating an instance through
> CrLfFileStream, it should set automatically, but through FileStream,
> it shouldn't.
>
> -- Yoshiki
>



Reply | Threaded
Open this post in threaded view
|

Re: CR LF Problem in Windows XP

Yoshiki Ohshima
  Ron,

> Don't you think it should set this automatically for Windows systems?  The
> method I would like to see is 'this/that' withCRs toFilename: 'test.txt'.
> Or (Array with: this with: that) toFilename: 'test.txt'.  It should set
> #crlf automatically for windows systems.

  Ah, no, I don't think so.  In general, any data that Squeak stores
should be platform independent, and should stick to the Squeak's
convention.  Squeak happens to have chosen #cr as the line end
convention for it, so we should stick to it on any platform.  Think
about the fileouts.  You won't be able to send code around easily.

  On this one, it should do smart things only when the user requests.

-- Yoshiki