|
Post by C128Man on Apr 27, 2015 15:14:20 GMT
Hi,
I'm trying to code a program that list a sequential file. I'm trying to detect the EOF with the "ST" variable. Which values can take this "ST"?
My test show: -Everything good ST=0 -EOF (with last record)=64 -EOF (after last record)=66
Best Ben
|
|
|
Post by donno128 on Apr 27, 2015 15:37:34 GMT
Usually I find the value of ST is either 64 or 0, so IF ST THEN CLOSE (or whatever) (FILENUMBER). The value of ST will indicate EOF for PRG files too. Not sure about USR and DEL files. The 66 value seems good for determining where to add new data to the end of the file. I have never used it though, or even noticed it. ST is a system variable and will not accept values from user input. At least not from this user. Short program to list SEQ file in 128 mode.
10 OPEN 8,8,8,"INTERESTING.TXT":DO UNTIL ST:GET#8,A$:PRINT A$;:LOOP:CLOSE 8:END You could add S,R after the filename but those are default parameters so left out if just reading a SEQ file.
|
|
|
Post by C128Man on Apr 28, 2015 7:37:48 GMT
Yes, but the problem is, the ST value is 64 with the last record. If you read once again, the value is 66 Here is my code 10 dopen #1,"lstnom.dat,s" 15 print st,ds$ 20 input#1,li$ 30 do while (st=0) 40 print li$ 50 input#1,li$ 55 print st,ds$ 60 loop 70 dclose #1 But, with this code, there is a problem when the file is empty. The system freeze on line 20. May be it's a bug in the system
|
|
|
Post by hydrophilic on Apr 28, 2015 8:07:55 GMT
I (always?) check for end-of-file with any value of "ST AND 64 <> 0".
Most simple example I can imagine (BASIC 3.5/4.X/7.0)...
10 U=8:D=0: REM UNIT 8, DRIVE 0 20 OPEN 3, U, 3, STR$(D)+":FILENAME" : REM OPEN "FILENAME" 30 DO: GET#3, Q$ 40 PRINT Q$; 44 REM LOOP UNTIL (ST AND 64) <> 0 --- SLOW/LAME CODE 50 LOOP UNTIL ST AND 64 : REM FAST CODE 60 CLOSE 3
NOTE: as an alternative, you can "un-REM" line 44 and delete line 50... either method will work, but the test (ST AND 64) <> 0 (line 44) is slower than than line 50 (test "ST AND 64")... in short, the "un-REM" method just described is worse than my code shown above!
Best to delete line 44 completely (and all REMs)!
|
|
|
Post by C128Man on Apr 28, 2015 8:20:49 GMT
But with a "Do...until", the system execute at least one time the loop. Even if the file is empty
May be this code is better
10 dopen #1,"lstnom.dat,s" 15 print st 20 input#1,li$ 30 do while (st<>66) 40 print li$ 50 input#1,li$ 55 print st 60 loop 70 dclose #1 It print all records on screen, but freeze on empty file
|
|
|
Post by hydrophilic on Apr 28, 2015 10:12:34 GMT
I have never seen a "real" 0-byte file on a CBM disk... in fact, I believe (call me hopelessly religious), it is impossible to create an empty CBM file (0 bytes).
If you have a D64/G64/D71/D81/D1M/D2M/D4M file to contradict this assumption, I think many of us would love to see it (well, at least me).
Slightly off-topic, what is up with line 30... you are testing ST against 66 (test 64 [not open] + 2 [? ... serial read error ? ])
I'm not saying line 30 is wrong... just never used it myself, and don't recall ever reading anything like that in the documentation I have seen... Please explain... thank you!
|
|
|
Post by donno128 on Apr 28, 2015 14:51:59 GMT
I think you do not go through the loop an extra time when you use UNTIL like this. 10 OPEN 8,8,8,"INTERESTING.TXT":DO UNTIL ST:GET#8,A$:SP=ST:PRINT A$;:LOOP:PRINT SP:CLOSE 8:END will print the seq file to screen and then print SP. It will read 64. It would read 66 if the program ran through one extra time. The program will not LOOP if ST has any value other than 0.
|
|
|
Post by C128Man on Apr 29, 2015 6:49:51 GMT
With code:
dopen #1,"test.dat,s",w:dclose#1
You create an empty file and you can not read it. The first "INPUT" freeze.
Is it maybe a little strange to do that, but, it's not normal that the "INPUT" freeze the computer.
|
|