The PureBasic file read command ReadString() supports Unix (0x0a <LF> end of line) and DOS (0x0d0x0a <CR><LF> end of line) file formats.
Mac-format text files use 0x0d <CR> as the line terminator. When I try to read a Mac file line-by-line in a loop, Eof() never becomes #True, so I can't tell when the end of file has been reached. Can anyone suggest a simple way to read Mac-format files? I guess I could read the entire file into memory and replace all the <CR> characters with <LF>, but I was hoping for something easier, if possible.
Thanks,
Eric
How To Read Mac Format Text Files
I don't have a Mac text file to test this with, but perhaps this works ?
Code: Select all
Procedure.s ReadMacString()
MacString$ = ""
linestop = #false
Repeat
f = ReadByte()
If f=0
linestop = #true
EndIf
If f = 13
linestop = #true
EndIf
If linestop = #false
MacString$+Chr(f)
EndIf
Until linestop = #true
ProcedureReturn MacString$
EndProcedure
rfile=ReadFile(#pb_any,"mactext.txt")
If rfile
Repeat
Debug ReadMacString()
Until Eof(Rfile)
CloseFile(rfile)
EndIfgriz,
Thanks for the suggestion, but I think that reading bytes will be a lot slower than reading each line. I think I remember some posts that showed how to read an entire file into memory. If I can find them, I should be able to read each line from memory. Can anyone point me in the right direction?
Thanks,
Eric
Thanks for the suggestion, but I think that reading bytes will be a lot slower than reading each line. I think I remember some posts that showed how to read an entire file into memory. If I can find them, I should be able to read each line from memory. Can anyone point me in the right direction?
Thanks,
Eric
Code: Select all
File$ = "yourfilehere.txt"
size.l = FileSize(File$)
*Buffer = AllocateMemory(size)
If ReadFile(0, File$)
ReadData(*Buffer, size)
CloseFile(0)
EndIf
{Home}.:|:.{Dialog Design0R}.:|:.{Codes}.:|:.{History Viewer Online}.:|:.{Send a Beer}

