|
Post by dw817 on Aug 17, 2015 13:52:50 GMT -5
Yep, I've been gone for a-while. Truly I have hung up my programmer's cape regarding videogames, yet I am working on this one project to merge SRT files from a 2-pack CD set.
As it is file intensive, I suspect many of you have run into this problem with READLINE().
If you are reading from one text file that has the following
1 Alpha 2 Beta
3 Charlie 4 Delta
5 Echo 6 Fox and use both READLINE and WRITELINE to save it to a new file, the results are
1 Alpha 2 Beta 3 Charlie 4 Delta 5 Echo 6 Fox Apparently Bagel skips right over blank lines as if they weren't there, you can't even look for them in your code !
So I wrote this little function to handle it for those of you who might be eluded to a solution.
function myreadline$(fp) dim a$,b$,c$ do a$=readchar(fp) c$=a$ if a$<>chr$(13)and a$<>chr$(10)then b$=b$+a$ endif loop while c$<>chr$(10)and endoffile(fp)=0 return b$ endfunction While not as fast as the original READLINE(), it is certainly more accurate. It does not insert a CR or LF in the text being read and it cleanly pulls out a single text line knowing where to end it from the next.
Hope This Helps !
|
|
|
Post by matthew on Aug 17, 2015 16:03:50 GMT -5
Hi dw, nice to see that you're still with us. ;-) I did some searching on Google and discovered that this problem with ReadLine() had been reported in the past here too. Your function is a neat solution. If anyone's interested, I took a quick look through the source for Basic4GL and here is the code for ReadChar() and ReadLine() respectively. char TBasic4GLv2MainForm::ReadChar (TFileStream& s) { char c; do { if (s.Read (&c, sizeof (c)) == 0) c = 0; } while (c == 10); // Skip newlines return c; }
void TBasic4GLv2MainForm::ReadLine(TFileStream& s) { m_line = ""; if (s.Position < s.Size) { char c = ReadChar (s); while (c != 13 && c != 0) { m_line = m_line + c; c = ReadChar (s); } m_done = false; } else m_done = true; }
|
|
|
Post by dw817 on Aug 17, 2015 17:18:32 GMT -5
Hi dw, nice to see that you're still with us. ;-) I did some searching on Google and discovered that this problem with ReadLine() had been reported in the past here too. Your function is a neat solution. If anyone's interested, I took a quick look through the source for Basic4GL and here is the code for ReadChar() and ReadLine() respectively. ... Hey, thanks for the welcome ! Yeah, it's been - well, too many years I guess. I was gonna tap this all in BlitzMAX, but I just do =NOT= like the fact that it takes nearly a full second to compile a program in there - whereas Bagel would always run your program the instant you executed it, like GFA. And unfortunately as you know, that's how I program. One tedious toothpick at a time, usually running my program well over 20-times to make sure it works, for even the small code that I have in it so far. Reading other peoples' solutions from the link you left, yep, it's definitely one for the books. Perhaps Bagel could update their main program and add readlinecr$() which will return a true blank line from an input file should one be found. I don't recommend changing readline$() itself as many programmers likely have taken alternative courses when a blank line is found and it could corrupt thousands of already existing codes out there that operate on this limitation.
|
|