Page 1 of 2

new string constants

Posted: Wed Sep 07, 2005 12:24 pm
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:

Re: new string constants

Posted: Thu Sep 08, 2005 12:38 pm
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.

Posted: Thu Sep 08, 2005 2:41 pm
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 :?

Posted: Thu Sep 08, 2005 3:03 pm
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)

Posted: Thu Sep 08, 2005 3:06 pm
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.

Posted: Thu Sep 08, 2005 3:35 pm
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

Posted: Thu Sep 08, 2005 3:38 pm
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:

Posted: Thu Sep 08, 2005 3:52 pm
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.

Posted: Thu Sep 08, 2005 5:29 pm
by GeoTrail
Den skjønte jeg ikke bæret av, men men så kan jeg ikke fransk noe særlig heller

Posted: Thu Sep 08, 2005 5:31 pm
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?

Posted: Thu Sep 08, 2005 6:22 pm
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

Posted: Thu Sep 08, 2005 7:29 pm
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

Posted: Thu Sep 08, 2005 9:52 pm
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?

Posted: Thu Sep 08, 2005 11:15 pm
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.

Posted: Thu Sep 08, 2005 11:19 pm
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