Page 1 of 1

Preprocessor question

Posted: Mon Jun 15, 2015 8:18 pm
by srvet_claudio
Hi friends, i need your help.

With this syntax is:

Code: Select all

#xcommand MyCmd =>; 
          a:= 1;;
          b:= 2
the Harbour preprocessor generate this line of code (one line of code):

Code: Select all

a:= 1; b:= 2
My question is: what is the directive of the preprocessor that generate the previous code but in two lines different?, eg.

Code: Select all

a:= 1
b:= 2
This is very important for debug purpose.

Thanks in advance.

Re: Preprocessor question

Posted: Tue Jun 16, 2015 1:08 pm
by EduardoLuis
Hola Claudio:

No se si servirá, pero se me ocurre un lazo FOR - NEXT y una variable a la que pasarle referencias

alfa := 'var'
FOR i:= 1 to n
mix := '000' + ALLTRIM(STR(i)) // '000' = 1 digito mas que n
mix := RIGHT(mix,4)
alfa += mix
#xcommand MyCmd => ;
&alfa := i
next

En teoria deberían generarse tantas líneas como registros se coloquen en el lazo.

No estoy seguro pero supongo que podría funcionar.-
Un abrazo.
Eduardo

Re: Preprocessor question

Posted: Tue Jun 16, 2015 6:40 pm
by srvet_claudio
Eduardo,
lamentablemente no funciona, porque siempre se genera el código en la misma linea del texto, yo necesito que aparezca cada sentencia en una linea diferente del texto, ej:

linea 1: a := 1
linea 2: b := 2

Re: Preprocessor question

Posted: Tue Jun 16, 2015 9:38 pm
by srvet_claudio
Hi all,
I found a not very elegant solution but it works:

create a header file MyFile.ch:

MyFile.ch
// begin file

Func1()

// end file


define directve:
#command CallMyFunc() => #include "MyFile.ch"; Func2()


call CallMyFunc() generate the following code in two lines separated:
Func1()
Func2()

Re: Preprocessor question

Posted: Tue Jun 16, 2015 11:21 pm
by danielmaximiliano
Claudio, cuando se necesita atar con alambre se hace

Re: Preprocessor question

Posted: Wed Jun 17, 2015 3:55 am
by srvet_claudio
danielmaximiliano wrote:Claudio, cuando se necesita atar con alambre se hace
Mejor expresado imposible !!!

Preprocessor question

Posted: Wed Jun 17, 2015 6:15 pm
by Pablo César
srvet_claudio wrote:
danielmaximiliano wrote:Claudio, cuando se necesita atar con alambre se hace
Mejor expresado imposible !!!
+1 Cierto ! :lol:

Claudio, disculpame estuve viajando y no pude leer este mensaje antes.

Tenés otro ejemplo ?

Porque yo entiendo que cuando en xBase hay ";" sirve para mantenerse en la misma linea. Y no como ocurre en C.

Tampoco entiendo como seria empleado.
Necesitarias que se dividan en líneas cada comando ?

Re: Preprocessor question

Posted: Wed Jun 17, 2015 9:09 pm
by srvet_claudio
Pablo César wrote:Tampoco entiendo como seria empleado.
Necesitarias que se dividan en líneas cada comando ?
Yes Pablo, I needed for specific case that two functions of a #command appeared in two separate lines, this is explanation I posted in HB user forum:
The problem is that with #xcommand/#xtranslate the preprocessor always generates all the code in the same line of text separated by semicolon, for example.
a; b; c; d; etc.

Consider the following example:
line text n1: a; b; c
line text n2: d

where a, b, c and d are valid functions/sentences of Harbour.

In a debug step by step, the debugger stops at the line n1, then executes all sentences of this line (a, b, c), and after executing the last sentence (c) stops in the line n2, and so I can not make an individual debug of sentences a, b and c.

For individual debug of all sentences, I need that appears in the code:

line text n1: a
line text n2: b
line text n3: c
line text n4: d

My question is, as I do for that:

#xcommand MyCmd => a; b; c

Instead of generating:

line text n1: a; b; c

generates:

line text n1: a
line text n2: b
line text n3: c

Preprocessor question

Posted: Wed Jun 17, 2015 9:34 pm
by Pablo César
Claudio,

Esto StrTran( cText, ";", Chr( 10 ) ) iria substituir el punto y coma por quiebra de linea.

Tambien estas funciones te puedan ayudar:

hb_pp_tokenAdd
hb_pp_tokenAddNext
hb_pp_tokenAddCmdSep
hb_pp_tokenSetValue
hb_pp_pragmaStream

Las vas a encontrar en ppcore.c en el src del pp del core del Harbour.
(https://github.com/harbour/core/blob/ma ... p/ppcore.c)

Asi aLine := hb_ATokens( cLine, ";" ) vas a conseguir colocar facilmente cada comando en vector y lo puedes trabajar con hb_StrShrink(aLine,1).

Por favor prefiero que me escribas en castellano porque yo no te entiendo bien y perdemos mucho tiempo.
Quien se interese por el tema y no entienda: que pregunte ! :mrgreen:

Re: Preprocessor question

Posted: Thu Jun 18, 2015 12:34 am
by srvet_claudio
Pablo César wrote:Claudio,

Esto StrTran( cText, ";", Chr( 10 ) ) iria substituir el punto y coma por quiebra de linea.

Tambien estas funciones te puedan ayudar:

hb_pp_tokenAdd
hb_pp_tokenAddNext
hb_pp_tokenAddCmdSep
hb_pp_tokenSetValue
hb_pp_pragmaStream

Las vas a encontrar en ppcore.c en el src del pp del core del Harbour.
(https://github.com/harbour/core/blob/ma ... p/ppcore.c)

Asi aLine := hb_ATokens( cLine, ";" ) vas a conseguir colocar facilmente cada comando en vector y lo puedes trabajar con hb_StrShrink(aLine,1).

Por favor prefiero que me escribas en castellano porque yo no te entiendo bien y perdemos mucho tiempo.

Thanks, but not work!