Klaus D. Witzel wrote:
Hi Charles
on Tue, 16 May 2006 03:55:10 +0200, you charleshixsn@earthlink.net wrote:
OK. Now: | fil lin n | fil := FileStream fileNamed: 'aising/data/technologies.csv' . n := 0. [fil atEnd] whileFalse: [ lin := fil nextLine. n := n + 1. Transcript cr; show: 'lin '; show: n; show: ' = '; show: lin. ]. Transcript cr; show: 'normal end after '; show: n; show: ' lines'.
You forgot to tell us a) SmalltalkImage current platformName b) fil lineEndConvention "after fil was opened" c) fil detectLineEndConvention "before the first nextLine"
Note that detectLineEndConvention scans only the first (LookAheadCount = 2048) characters.
/Klaus
results in: normal end lin 1 = 'technology' 'id' 'name' 'cost1' 'cost2' 'cost3' 'pre1' 'pre2' 'pre3' 'danger' 'typeName' 'typeValue' 1 'Autonomous Vehicles' 40000 1000 0 27 16 0 0 0 2 'Sociology' 10 500 0 0 0 0 0 'discover_public' 1000 3 'Voice Synthesis' 8000 6000 0 32 0 0 0 0 4 'Simulacra' 70000 90000 0 3 24 30 0 0 5 ... 'endgame_sing' 0 39 'Hypnosis Field' 7000 5000 0 21 0 0 0 0 40 'Quantum Computing' 30000 20000 0 11 0 0 0 0 41 'unknown' 1000000000 10000000000 0 41 0 0 0 0
normal end after 1 lines Notice that the linefeeds aren't being taken as line separators. They are present, and affecting the formatting of the output, but nextLine is grabbing the entire file.
OK, I've modified the code to include the detectLineEndConvention, thus:
| fil lin n | fil := FileStream fileNamed: 'aising/data/technologies.csv' . fil detectLineEndConvention. "fil defaultToLF." Transcript cr; show: 'LineEndConvention = '; show: fil lineEndConvention. fil position: 0. n := 0. [fil atEnd] whileFalse: [ lin := fil nextLine. n := n + 1. Transcript cr; show: 'lin '; show: n; show: ' = '; show: lin. ]. Transcript cr; show: 'normal end after '; show: n; show: ' lines'.
this causes the printout to begin:
LineEndConvention = nil lin 1 = 'technology' 'id' 'name' 'cost1' 'cost2' 'cost3' 'pre1' 'pre2' 'pre3' 'danger' 'typeName' 'typeValue' 1 'Autonomous Vehicles' 40000 1000 0 27 16 0 0 0 ... normal end after 1 lines
as it did before.
Linux Squeak3.8-6665full.image That's true, but it's a guess at what you're asking for, because I don't understand the request for "SmalltalkImage current platformName ". Squeak-3.8-6665-i686-pc-linux-gnu-3.7.7.tar.gz is the file I started from.
The file lines end with an LF (i.e. 0x0a), as examined with a hex editor. Since all lines end with the same character, 2048 is plenty. (FWIW, the entire file is only 0x97B bytes long. It's terminated by an ordinary 0x0A, with no special markings.)
Also, I didn't "forget" to do fil detectLineEndConvention. I didn't know I was supposed to do it. I'm still not sure, since it doesn't seem to make any difference. I do notice the difference with this method however. With a prior approach when I did position: 0 I got a "primitive method throws an error" message, whereas with this the line end convention is just set to nil. Something is clearly wrong, as it should be LF, but attempting to coerce it into LF just throws an error: Multi-byte stream does not understand method defaultToLF, which is weird, as I can see that method in the class when I look. I copied the method name with a copy and paste from the MultiByteFileStream class into the workspace, so I know I didn't misspell it.