SyntaxBomb - Indie Coders

Languages & Coding => SmallBASIC => Topic started by: jsalai on February 16, 2024, 09:43:09

Title: Tsave-Tload bug???
Post by: jsalai on February 16, 2024, 09:43:09
IIRC. ages ago there were some discussions about TSAVE/TLOAD; now a humble contribution:

SBasicg Version 12.26 SDL win-64

color 15,0:cls
a=[]:b=
:c=["c"]
tsave "a.txt",a:tsave "b.txt",b:tsave "c.txt",c
for i=1 to 10
  tload "a.txt",a:tload "b.txt",b:tload "c.txt",c
  tsave "a.txt",a:tsave "b.txt",b:tsave "c.txt",c
next
tload "a.txt",a:?a:?len(a) 'tload as array
tload "b.txt",b:?b:?len(b)
tload "c.txt",c:?c:?len(c)
'tload "a.txt",a,1:?a,len(a)
tload "b.txt",b,1:?b:?len(b) 'tload as string
tload "c.txt",c,1:?c:?len(c)
pause
end

So far, so good!

Now, the empty a[], remains empty all the time - and I like it so - except that the (commented) tload "a.txt",a,1 - as string - is yelling that  a.txt does not exist - what is a lie - it should give a="", with len(a)=0. Uncomment and see...

What the b[] and c[] concerns, they grow, and grow, because TSAVE every time appends an idiotic CRLF.
As every modern editor refuses to add anything at the and of files (neither CRLF nor EOF), it would be nice when TSAVE would behave so.

Thanks! And wish you all the best in this "best of all possible worlds"!
Title: Re: Tsave-Tload bug???
Post by: chrisws on February 17, 2024, 00:40:03
I see... loading a zero length file as a string is inconsistent with loading it as an array. 
Title: Re: Tsave-Tload bug???
Post by: jsalai on February 17, 2024, 10:33:41
It is OK,
but my main complain is about appending the CRLF at the end of TSAVEd file.

IMHO, after succeeding TLOAD I should get an IDENTICAL array (or string), but unfortunately it increases by one EMPTY item of array, or two bytes (CRLF) in length as string. Of course, it is possible to delete the extra items but that is anniying anyway.

So, if possible, please, omit the CRLF at the end of TSAVEd file.

Thanks!

Title: Re: Tsave-Tload bug???
Post by: J7M on February 19, 2024, 21:46:48
Hi jsalai, I fixed both problems. TSAVE will not append a CRLF at the end of the file and TLOAD will not complain anymore, when reading an empty file. It will return an empty string instead.See https://github.com/smallbasic/SmallBASIC/pull/206
Title: Re: Tsave-Tload bug???
Post by: jsalai on February 20, 2024, 08:13:46
Quote from: J7M on February 19, 2024, 21:46:48Hi jsalai, I fixed both problems. TSAVE will not append a CRLF at the end of the file and TLOAD will not complain anymore, when reading an empty file. It will return an empty string instead.See https://github.com/smallbasic/SmallBASIC/pull/206

Thanks! It is a handy method for temporary storing big arrays 8)
And a big THANKS to you and chrisws for your efforts!!!
Title: Re: Tsave-Tload bug???
Post by: Tinine on February 20, 2024, 08:43:18
Quote from: jsalai on February 20, 2024, 08:13:46And a big THANKS to you and chrisws for your efforts!!!

+1
Such a great product, puts a smile on my face every time  :D

Craig