Removing 'ASCII' switch from PureBasic

Developed or developing a new product in PureBasic? Tell the world about it.
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Removing 'ASCII' switch from PureBasic

Post by Lebostein »

What about reading binary files? I have many structures like that:

http://wiki.multimedia.cx/index.php?tit ... tive_Voice

Code: Select all

Structure voc_file

  header.s{19} ; "Creative Voice File"
  printing.b
  totelsize.w
  version.w
  validity.w
  ;...

EndStructure

test.voc_file

ReadData(file, @test, SizeOf(voc_file))
How I convert this to unicode? Now be 38 bytes read for the header string?
Last edited by Lebostein on Thu Aug 07, 2014 9:58 am, edited 1 time in total.
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Removing 'ASCII' switch from PureBasic

Post by Danilo »

Code: Select all

Structure voc_file

  header.a[19]
  [...]
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Removing 'ASCII' switch from PureBasic

Post by Lebostein »

Yes, but I need extra operations to compare this byte array. I see a lot of work to convert my sources, includes and so on.... :cry:
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Removing 'ASCII' switch from PureBasic

Post by Danilo »

Lebostein wrote:Yes, but I need extra operations to compare this byte array. I see a lot of work to convert my sources, includes and so on.... :cry:
Don't blame me. It is same if you incorrectly code 32bit only and move to 64bit.
You assume the type .s contains always ASCII data, and that's a wrong assumption. Sorry.

To be honest, the PB team had also some problems converting the IDE to Unicode. Transition is not always
that easy as it may sound at first, and can lead to bugs, if you didn't have Unicode in mind when writing codes.

Good thing is, you have time to make your stuff Unicode compatible. No need to do everything today,
as PB 5.4x is still many month away. That's why the PB team is talking about it now, to prevent surprises,
and give developers enough time to make the transition.

Maybe somebody should make a transition guide, or we collect important stuff here or in a new (sticky) topic.
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Removing 'ASCII' switch from PureBasic

Post by Lebostein »

That could work:

Code: Select all

;==============================================================================
; Convert ASCII-Array to UNICODE-String
;==============================================================================

Procedure.s ATS(*pointer.Ascii, length): Protected unicode.s, i

  For i = 1 To length: unicode + Chr(*pointer\a): *pointer + 1: Next i
  ProcedureReturn unicode

EndProcedure

;==============================================================================
; Convert UNICODE-String to ASCII-Array
;==============================================================================

Procedure STA(*pointer.Ascii, unicode.s): Protected *zeiger.Unicode = @unicode

  While *zeiger\u: *pointer\a = *zeiger\u: *pointer + 1: *zeiger + SizeOf(Unicode): Wend

EndProcedure

;==============================================================================

Structure SC_HEAD

  name.a[4]
  size.l

EndStructure

test.SC_HEAD

STA(@test\name, "TeSt")
Debug ATS(@test\name, 4)
Fred
Administrator
Administrator
Posts: 16618
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Removing 'ASCII' switch from PureBasic

Post by Fred »

You could use PeekS/PokeS as well, no ?
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Removing 'ASCII' switch from PureBasic

Post by luis »

Danilo wrote:That's why the PB team is talking about it now, to prevent surprises,
and give developers enough time to make the transition.
I thought it was to decide whether to do it or not.
"Have you tried turning it off and on again ?"
A little PureBasic review
Fred
Administrator
Administrator
Posts: 16618
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Removing 'ASCII' switch from PureBasic

Post by Fred »

It's not decided for now
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Removing 'ASCII' switch from PureBasic

Post by DK_PETER »

I got no problem with going unicode. I got the unicode switch on all the time anyways.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Removing 'ASCII' switch from PureBasic

Post by Lebostein »

Fred wrote:You could use PeekS/PokeS as well, no ?
Yes! It works. It don't work without the #PB_String_NoZero flag. Without #PB_String_NoZero I get -5120. The NULL string overwrites the size.w

Code: Select all

Macro ATS(pointer, length) ; Convert ASCII-Array to UNICODE-String
  PeekS(pointer, length, #PB_Ascii)
EndMacro

Macro STA(pointer, string) ; Convert UNICODE-String to ASCII-Array
  PokeS(pointer, string, -1, #PB_Ascii | #PB_String_NoZero)
EndMacro

Structure fileheader
  name.a[4]
  size.w
EndStructure

test.fileheader

test\size = -5000
STA(@test\name, "TeSt")

Debug ATS(@test\name, 4)
Debug test\size
User avatar
Didelphodon
PureBasic Expert
PureBasic Expert
Posts: 448
Joined: Sat Dec 18, 2004 11:56 am
Location: Vienna - Austria
Contact:

Re: Removing 'ASCII' switch from PureBasic

Post by Didelphodon »

As PokeS has already been mentioned a couple of times - and I use it frequently - what about the (optional) "Length" parameter? Is it really (as the documentation says) treated in terms of "characters" or does it mean effective bytes? I hope it's a mistake in the documentation as it wouldn't really make sense to restrict that operation by the means of "characters" in the presence of Unicode and UTF-8 as it's mainly focused on preventing the memory block from overflowing, imho.

UPDATE: Just read the description of the return value - so, actually it really means "characters". Well in terms of securing the underlying memory buffer I definitely have to keep this fact in mind. 8-O

UPDATE 2: However, I think I have to become good friends with StringByteLength()
Go, tell it on the mountains.
juror
Enthusiast
Enthusiast
Posts: 228
Joined: Mon Jul 09, 2007 4:47 pm
Location: Courthouse

Re: Removing 'ASCII' switch from PureBasic

Post by juror »

While "modernizing" why not eliminate 32 bit also?
Fred
Administrator
Administrator
Posts: 16618
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Removing 'ASCII' switch from PureBasic

Post by Fred »

juror wrote:While "modernizing" why not eliminate 32 bit also?
Will be one day, as 16bit dev is gone since a long time. But it's a bit too soon for that, as many users still have a 32-bit Windows :)
marroh
User
User
Posts: 72
Joined: Wed Aug 06, 2008 8:21 am

Re: Removing 'ASCII' switch from PureBasic

Post by marroh »

juror wrote:While "modernizing" why not eliminate 32 bit also?
:lol: :wink:

[Sarcasm On]
And also stop Mac and Linux support! Has only 6.62% (Mac) and 1.68% (Linux) desktop market share.
Source OS desktop market share
[Sarcasm Off]

Not intended for discussion, only to read. ;)
PureBASIC v5.41 LTS , Windows v8.1 x64
Forget UNICODE - Keep it BASIC !
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Removing 'ASCII' switch from PureBasic

Post by wilbert »

@Marroh,
Mac is so modern that one single 64 bit unicode version would probably be good enough for most Mac users :D
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply