Transform CodeBlocks in strings

Harbour, MingW related news.

Moderator: Rathinagiri

User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Transform CodeBlocks in strings

Post by esgici »

srvet_claudio wrote: Thanks for the info.
Thanks to interest and like, Claudio :oops:

Another quotation about code block de-serialization:
Code block deserialize
Code block deserialize
code block deserialize.JPG (24.4 KiB) Viewed 11858 times
IMO de/serialization isn't simply a de/crypt method and is a high level subject that far for ordinary / casual programmers like me ;)

Viva HMG :D
Viva INTERNATIONAL HMG :D
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Transform CodeBlocks in strings

Post by Pablo César »

Rick Spence, I like much his articles. Thank you Esgici for your indications and material arrangement. I read all and I have no problem with CodeBlocks except how I get what the CodeBlock has contained and I wish in string type. I will try to explain a little bit more with samples.

We have this demo, which is an almost perfect example or at least simulates what we now have as IDE. Where the actions are being inputed by users, stored into a string variable and passed to the text file (FMG file created by the IDE):

Code: Select all

#include <hmg.ch>

Function Main()
LOCAL cBlock, bBlock

SET WINDOW MAIN OFF
cBlock:=InputBox("Confirm your ACTION (function):","Define your action","MsgInfo('Action test')")
SET WINDOW MAIN ON

bBlock:={||MemVarBlock(cBlock)}

MsgDebugTitle("Types of variables") ; MsgDebug(' cBlock type = ( '+ValType(cBlock)+' ) ',' bBlock type = ( '+ValType(bBlock)+' ) ')

MsgDebugTitle("Content of variables") ; MsgDebug( cBlock, bBlock )

EVAL(bBlock)
Return Nil
On the other hand, we have the inverse situation of creating FMG file by IDE. Where we already have a PRG made by the user and we want to transform what is being executed (in memory running) into standard FMG text file.

Code: Select all

#include <hmg.ch>

Function Main()
LOCAL cBlock, bBlock

bBlock:={||MsgInfo('Action test')}

cBlock := hb_ValToExp( bBlock ) // I want this: "MsgInfo('Action test')", but seems in Harbour there is no way...

MsgDebugTitle("Types of variables") ; MsgDebug(' cBlock type = ( '+ValType(cBlock)+' ) ',' bBlock type = ( '+ValType(bBlock)+' ) ')

MsgDebugTitle("Content of variables") ; MsgDebug( cBlock, bBlock )

EVAL(bBlock)
Return Nil
What would be the difference between these examples ?

I need to get the function or the (nested) functions that are inside {|| ...} (what's in red color)

How to get cBlock with full information (not just "...") :?:

This is the big question. If I have FMG file, I could read directly from the file, because is a text file.

Regarding this:

Image
I believe that in my case with Prg2Fmg project, the compiler would have it because Prg2Fmg will only works by re-building the application with the user app. So Harbour, will have all the functions defined as ACTIONs. Otherwise, user's app would not be compiled with some error in their codes.
So in this case CodeBlock deserialize will never contradict the mandatory for Prg2Fmg because always will running and compiling at same time.


Claudio, could you tell me if it is possible to read (perhaps in the C language) the contents of a temporary variable and replace "{||" And "}" by quotes ? Or let say to replace "{" by "[" and "}" by "]" ? Which it would transform block for string ?
Last edited by Pablo César on Mon Nov 14, 2016 8:28 pm, edited 1 time in total.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Transform CodeBlocks in strings

Post by srvet_claudio »

It is not possible because Harbour when create the CB transforms in pcode and refers to the local symbol table, would be necessary reverse engineering.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Transform CodeBlocks in strings

Post by Pablo César »

I've Understood. I read about it, but I did not think it would turn the cb into P-Code at the same time.

I was dreaming with hb_struBlock and hb_execFromArray...

Thank you Claudio

One POV:

However, if HMG would it may store these CodeBlocks that are currently stored as type "B" (Block) and instead would store as type "C" (character) in _HMG_SYSDATA structure, It would provide that same information with the same result. Of course to treat it at the time of execution will need to transform from string to block type. ;)
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Transform CodeBlocks in strings

Post by srvet_claudio »

Pablo César wrote: One POV:

However, if HMG would it may store these CodeBlocks that are currently stored as type "B" (Block) and instead would store as type "C" (character) in _HMG_SYSDATA structure, It would provide that same information with the same result. Of course to treat it at the time of execution will need to transform from string to block type. ;)
This is not as simple as it sounds when cb strings contain local variables. This is the same problem that happens with macrosubstitution with local variables. The cb was create to overcome the limitations of the macrostitution.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Transform CodeBlocks in strings

Post by Pablo César »

Ahh yes, I read about LOCAL and STATIC variables is not visible at macrosubstitution... :|

Do you believe Claudio that I could overwrite HMG instructions by an own include file and make all actions be converted in string instead a block when compiled with Prg2Fmg ?

I saw in HMG like as:

#xcommand ACTION <action> => _HMG_SYSDATA \[ 419 \] := <{action}>

probably by removing "{}" ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Transform CodeBlocks in strings

Post by srvet_claudio »

Pablo César wrote:Ahh yes, I read about LOCAL and STATIC variables is not visible at macrosubstitution... :|

Do you believe Claudio that I could overwrite HMG instructions by an own include file and make all actions be converted in string instead a block when compiled with Prg2Fmg ?

I saw in HMG like as:

#xcommand ACTION <action> => _HMG_SYSDATA \[ 419 \] := <{action}>

probably by removing "{}" ?
No, this can cause many problems with local variables and it does not make sense to do so.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Transform CodeBlocks in strings

Post by Pablo César »

Let me explain to you...

The usage of Prg2Fmg, will be only with the propose to create a non existing fmg file of user app. And the only way to use it is to compile Prg2Fmg together just for fmg files creation. Prg2Fmg do not need to execute any action like as OnChange... OnClick... so on...

After user usage, they will re-compile and back again what their normal app behaviour.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Transform CodeBlocks in strings

Post by Pablo César »

Por tu silencio Claudio, creo que no me llegaste a entender o no te interesó más mi ultima propuesta. Acabo de probarlo y parece funcionar perfectamente para atender a mi objetivo. Pero antes de decir que no haberá problemas, iré chequear los ejemplos. La propuesta, no es para cambiar nada en HMG, sinó que voy a poder convertir las ACTIONs en strings sobreponiendo las directivas, solo para un propósito: generar archivo FMG.

Después lo muestro con la próxima version de Prg2Fmg.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Transform CodeBlocks in strings

Post by srvet_claudio »

Ok, no problem.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
Post Reply