PokeS without NULL-Termination

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Andras
User
User
Posts: 34
Joined: Wed Oct 27, 2004 6:58 am
Location: Germany

PokeS without NULL-Termination

Post by Andras »

Hi,

I'd like to have an optional PokeS-Parameter for writing a string without adding a terminating NULL-Char...
Undank ist der Welten Lohn
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

basically, you only need to use a copymemory

CopyMemory(@string,addr,Length)

Code: Select all

Procedure x_pokes(addr.l,string.s,Length.l)
  Protected n
  ;
  ; *** as pokes() but will not write a terminating zero if the string is too long to fit
  ;
  n = Len(string)
  If n < Length
    PokeS(addr,string)
  Else
    CopyMemory(@string,addr,Length)
  EndIf
EndProcedure
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

well, oh, strings in structs, probably? :-)

that's why i'd love to have fixed length strings as well...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Blueznl, i've got this from current pb help:
Syntax

PokeS(*MemoryBuffer, Text$ [, Length])
Description

For advanced programmers only. Write a string (including the ending '0') to the specified memory address.

An optional length parameter (in bytes) can be specified that defines the length of the string itself, a zero will still be placed in memory after the poked string (ie. specifying 6 will write 7 bytes, 6 for the string, and the last byte will be zero)
Supported OS

Windows, AmigaOS, Linux
Perhaps, what Andras resquests is another optional parameter for PokeS instruction to tell it what is the byte value which delimitates the string.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Andras
User
User
Posts: 34
Joined: Wed Oct 27, 2004 6:58 am
Location: Germany

Post by Andras »

Thanks@Blueznl: You are right - CopyMemory should do what I wanted. The only advantage of PokeS would be, that you don't need to know, where a string is located... For example if the string is in a structure you need to know the offset...
Undank ist der Welten Lohn
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Hey, PokeS() takes a pointer, just same as CopyMemory(). 8)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

psycho, the problem is the zero

i'm pretty sure he's trying to fill up the string part of a struct... it's something i have ran into a few times before as well

all i want to do is:

structwhatever/fieldwhatever.c = "12345"

instead of overwiting a bunch of bytes with poke or copymemory
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: PokeS without NULL-Termination

Post by Foz »

Can I do a little resurrecting of this (antique) thread?

+1

When I *have* to use PokeS because I'm changing the type of the string to the desired format (i.e. going from unicode to an ascii structure), I have to do a bunny hop of pokeing into temporary memory, then copying the temporary memory (minus the 0) into the correct field.
User_Russian
Addict
Addict
Posts: 1519
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: PokeS without NULL-Termination

Post by User_Russian »

I agree.
It should be possible, disable the terminating null byte.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: PokeS without NULL-Termination

Post by blueznl »

+1

I had to cook up my own PokeS just to get rid of that trailing zero...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply