new string constants

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 string constants

Post by Dr. Dri »

is it possible to add a new kind of constant similar to 'THIS' ?
it would be `THIS` and would equal to 'SIHT'

It could be very useful for files manipulations (for example) with a more "readable" source code...

Dri :idea:
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: new string constants

Post by PB »

I don't know what you mean. Can you post some code as an example of
what you want to achieve, so we can see it in context? Thanks.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

a lot a file formats use 3 or 4 ascii chars in their header(s)

for example bitmap can start with "BM" and if you use a bitmap structure you can identify this "BM" with the first field (a word)

Code: Select all

Structure BITMAPFILEHEADER
  bfType.w
  bfSize.l
  bfReserved1.w
  bfReserved2.w
  bfOffBits.l
EndStructure
So you can check the type (not necessary BM) with a constant... a 'MB' constant is more readable than it's numeric equivalent and what i am asking for (`BM`) would be even more readable...

They are a lot of examples... like *.wav which have this kind of identifiers like "RIFF" "WAVE" "data" and so on...

this code shows what i'm trying to explain (sorry i'm french ^^)

Code: Select all

Procedure.s WordToString(w.w)
  Protected s.s
  s = Space( SizeOf(Word) )
  PokeW(@s, w)
  ProcedureReturn s
EndProcedure

Procedure.s LongToString(l.l)
  Protected s.s
  s = Space( SizeOf(Long) )
  PokeL(@s, l)
  ProcedureReturn s
EndProcedure

Debug LongToString('SIHT')
Debug "---"
Debug LongToString('EVAW')
Debug LongToString('FFIR')
Debug LongToString('atad')
Debug "---"
Debug WordToString('MB')

;this would be more readable

; Debug LongToString(`THIS`)
; Debug "---"
; Debug LongToString(`WAVE`)
; Debug LongToString(`RIFF`)
; Debug LongToString(`data`)
; Debug "---"
; Debug WordToString(`BM`)
Dri :?
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

The following works in the meanwhile :

Code: Select all

Procedure.s LongToString_1(Address.l)
  ProcedureReturn PeekS(Address)
EndProcedure

a.l = 'SIHT'
Debug LongToString_1(@a)
a.l = 'EVAW'
Debug LongToString_1(@a)
a.l = 'FFIR'
Debug LongToString_1(@a)
a.l = 'atad'
Debug LongToString_1(@a)
a.l = 'MB'
Debug LongToString_1(@a)
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Begger. Too slow. ;)

But as I wrote it I am going to post it! :)

Code: Select all

CreateFile(0,"C:\code\pb\3.94\Junk\sig.txt")
WriteString("SIHT")
CloseFile(0)


Structure sig4
    byte4.b[4]
EndStructure
sigChk.sig4
OpenFile(1,"C:\code\pb\3.94\Junk\sig.txt")
 ReadData(@sigChk,4)
CloseFile(1)
For i=3 To 0 Step -1
  w.s + Chr(sigChk\byte4[i])
Next
Debug w
Another way. :)


Edit:

Neat stuff, fweil! Way to go.
@}--`--,-- A rose by any other name ..
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

fweil wrote:The following works in the meanwhile :

Code: Select all

Procedure.s LongToString_1(Address.l)
  ProcedureReturn PeekS(Address)
EndProcedure

a.l = 'SIHT'
Debug LongToString_1(@a)
a.l = 'EVAW'
Debug LongToString_1(@a)
a.l = 'FFIR'
Debug LongToString_1(@a)
a.l = 'atad'
Debug LongToString_1(@a)
a.l = 'MB'
Debug LongToString_1(@a)
sur ce coup là je comprend pas ce que t'a&s voulu dire fweil :oops:
en plus ton code est assez risqué...

Code: Select all

Procedure.s LongToString_1(Address.l)
  ProcedureReturn PeekS(Address)
EndProcedure

a.l = 'SIHT'
b.l = $FFFFFFFF

Debug LongToString_1(@a)
a.l = 'EVAW'
Debug LongToString_1(@a)
a.l = 'FFIR'
Debug LongToString_1(@a)
a.l = 'atad'
Debug LongToString_1(@a)
a.l = 'MB'
Debug LongToString_1(@a)
tout ce que je demande c'est si on pourrait avoir de nouvelles constantes ^^
je sais bien qu'il y a 1001 facons de lire un identifiant "ascii" dans un fichier et la plus simple que j'ai trouvée c'est bien le 'isht' mais dans l'espoir d'avoir encore plus simple je laisse une suggestion sur le forum... :?

Dri
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Dr. Dri wrote: sur ce coup là je comprend pas ce que t'a&s voulu dire fweil :oops:
en plus ton code est assez risqué...
[...]
tout ce que je demande c'est si on pourrait avoir de nouvelles constantes ^^
je sais bien qu'il y a 1001 facons de lire un identifiant "ascii" dans un fichier et la plus simple que j'ai trouvée c'est bien le 'isht' mais dans l'espoir d'avoir encore plus simple je laisse une suggestion sur le forum... :?
:?: :?: :?: :oops:
Good programmers don't comment their code. It was hard to write, should be hard to read.
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

I agree about the suggestion, just I proposed the fastest way I could imagine, obviously it requires just more code to key in.
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Den skjønte jeg ikke bæret av, men men så kan jeg ikke fransk noe særlig heller
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

GeoTrail wrote:Den skjønte jeg ikke bæret av, men men så kan jeg ikke fransk noe særlig heller
nej det blev jeg ikke klogere af heller. Selvom jeg godt kan tale lidt fransk.
Det kan da ikke passe at vi skal til at bruge Google Translater for at lære noget her?
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

AFAIK in Norway and Denmark people have some good french speaking skills. Just because I can't read fluently what you wrote !!!

Having a good german level I can understand some parts but not really the full meaning ...

What Europe are we building since Roma agreements ? Big issue since we don't have a common mother tongue.

... this should have been posted in the Off area
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

sorry but i answered fweil like if we were on the french forum :lol:
i completely forgot i was on the official forum :oops:

i said this :
i don't understand what you said fweil
and your code is not safe
(+ code that shows the problem of his code)

all i want is this new kind of constant ^^
i also know there is a lot of ways to read an ascii id et the more simple i found is to use 'txet' constants... but i hope it will be possible to write it `text` in PB...

Dri
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

fweil wrote:

Code: Select all

a.l = 'SIHT'
Debug LongToString_1(@a)
a.l = 'EVAW'
Debug LongToString_1(@a)
a.l = 'FFIR'
Debug LongToString_1(@a)
a.l = 'atad'
Debug LongToString_1(@a)
a.l = 'MB'
Debug LongToString_1(@a)
Why are they all backwards?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

Post by FloHimself »

don't know what this is all about, but maybe you're just talking about
the byte order?

Code: Select all

a.l = 'SHIT' 
Debug Hex(a)
Debug PeekS(@a)
!MOV EAX, [v_a]
!BSWAP EAX
!MOV [v_a], EAX
Debug Hex(a)
Debug PeekS(@a)
even if not, i don't understand the relation to constants.
My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

I never had french in school, neither did I have german, I focused on english.

Personally I'd think it would be great if every country took on english as their native language and if they wanted, kept their native as a second tounge hehehe
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Post Reply