new file functions

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

new file functions

Post by Dr. Dri »

it' just a small wish but maybe these functions could be native File functions...

Code: Select all

Procedure.w ReadBigEndianW(File)
  ReadWord(File)
  !BSWAP eax
  !SHR   eax, 16
  ProcedureReturn
EndProcedure

Procedure.l ReadBigEndianL(File)
  ReadLong(File)
  !BSWAP eax
  ProcedureReturn
EndProcedure
(and also WriteBigEndian functions)

Code: Select all

CompilerIf #PB_Compiler_Unicode
  #PB_String = #PB_UTF8
CompilerElse
  #PB_String = #PB_Ascii
CompilerEndIf

Procedure.s ReadStringN(File.l, Length = #PB_Default, Flags = #PB_String)
  Protected String.s
  
  If Length <= 0
    String = ReadString(File, Flags)
  Else
    String = Space(Length)
    Length = ReadData(File, @String, Length)
    String = Mid(String, 1, Length)
  EndIf
  
  ProcedureReturn String
EndProcedure

Macro ReadString(File, Length = #PB_Default, Flags = #PB_String)
  ReadStringN(File, Length, Flags)
EndMacro
(maybe could the #PB_String constant also become native...)

Dri