Page 1 of 1

Print / PrintN with Flag #PB_Ascii / #PB_UTF8 / #PB_Unicode

Posted: Fri Jan 19, 2018 3:25 pm
by Josh

Re: Print / PrintN with Flag #PB_Ascii / #PB_UTF8 / #PB_Unic

Posted: Fri Jan 19, 2018 3:50 pm
by kenmo
+1 This would be useful.

Here is a workaround :)

Code: Select all

Procedure _Print(Text.s, Format.i)
  If (Text)
    Protected Bytes.i, *Mem
    If (Format = #PB_Default)
      CompilerIf (#PB_Compiler_Unicode)
        Format = #PB_Unicode
      CompilerElse
        Format = #PB_Ascii
      CompilerEndIf
    EndIf
    Select (Format)
      Case #PB_Ascii
        Bytes = StringByteLength(Text, #PB_Ascii)
        *Mem = AllocateMemory(Bytes)
        If (*Mem)
          PokeS(*Mem, Text, -1, #PB_Ascii | #PB_String_NoZero)
        EndIf
      Case #PB_UTF8
        Bytes = StringByteLength(Text, #PB_UTF8)
        *Mem = AllocateMemory(Bytes)
        If (*Mem)
          PokeS(*Mem, Text, -1, #PB_UTF8 | #PB_String_NoZero)
        EndIf
      Case #PB_Unicode
        Bytes = StringByteLength(Text, #PB_Unicode)
        *Mem = AllocateMemory(Bytes)
        If (*Mem)
          PokeS(*Mem, Text, -1, #PB_Unicode | #PB_String_NoZero)
        EndIf
    EndSelect
    If (*Mem)
      WriteConsoleData(*Mem, Bytes)
      FreeMemory(*Mem)
    EndIf
  EndIf
EndProcedure

Macro Print(Text, Format = #PB_Default)
  _Print(Text, (Format))
EndMacro

Macro PrintN(Text, Format = #PB_Default)
  CompilerIf (#PB_Compiler_OS = #PB_OS_Windows)
    Print(Text + #CRLF$, (Format))
  CompilerElse
    Print(Text + #LF$, (Format))
  CompilerEndIf
EndMacro

Re: Print / PrintN with Flag #PB_Ascii / #PB_UTF8 / #PB_Unic

Posted: Fri Jan 19, 2018 4:28 pm
by ts-soft
And a Flag for OEM: Print("blabla", #PB_OEMtoCHAR)
Print("blabla", #PB_CHARtoOEM)

Re: Print / PrintN with Flag #PB_Ascii / #PB_UTF8 / #PB_Unic

Posted: Fri Jan 19, 2018 7:07 pm
by fryquez
Not only the Print() function, but all the Console related functions should get codepage options.

WriteProgramString
ConsoleError
ReadProgramError
...