Page 1 of 1

new file functions

Posted: Sun Aug 20, 2006 4:02 pm
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