vbgunz
25th February 2005 13:16 UTC
2 Part Q. 1. Line Jump Bug in 2.0.5? 2. How to Concatenate Several Lines of Code?
I've come across something wierd. A numbered line jump doesn't behave like it should. I've noticed this a few times so heres a small example. The following works.
!insertmacro FileSearch 'C:\test.txt' 'Value o'
StrCmp $1 No 0 replace
!insertmacro WriteEnd 'C:\test.txt' 'Value x'
Goto end
replace:
!insertmacro ReplaceBefore 'Value o' '%RBPH%' 'C:\test.txt'
!insertmacro ReplaceLineStr 'C:\test.txt' '%RBPH%' 'Value x'
end:
The following code slightly modified to jump based on a numerical value does not:
!insertmacro FileSearch 'C:\test.txt' 'Value o'
StrCmp $1 No 0 +3
!insertmacro WriteEnd 'C:\test.txt' 'Value x'
Goto end
!insertmacro ReplaceBefore 'Value o' '%RBPH%' 'C:\test.txt'
!insertmacro ReplaceLineStr 'C:\test.txt' '%RBPH%' 'Value x'
end:
$1 returns Yes or No. This isn't the end of the world but I've tried raising and lowering the jump number and regardless, the last two of three lines are always skipped. Is this a bug or am I doing something wrong?
My 2nd question is, it is possible to break up long lines of code into several lines by simply adding a \ at the end. OK. What is the opposite of this so to compress several lines of short code into one line? is this an option? Just curious.
Thank you for your time!
kichik
25th February 2005 13:37 UTC
For an answer to your first question, see this thread.
To "compress" several lines into one, use macros.
vbgunz
25th February 2005 14:01 UTC
Thanks Kichik!
In relpy to your response
1. Thanks for that link. I am happy it's no bug.
2. I had a funny feeling you were going to say that.
3. I have a new question regarding question number 2.
I've turned the working code into a macro
!macro FWOR In Find Temp Replace
!insertmacro FileSearch '${In}' '${Find}'
StrCmp $1 No 0 replace
!insertmacro WriteEnd '${In}' '${Replace}'
Goto end
replace:
!insertmacro ReplaceBefore '${Find}' '${Temp}' '${In}'
!insertmacro ReplaceLineStr '${In}' '${Temp}' '${Replace}'
end:
!macroend
Heres my question. How do I escape the labels? Because if I simply use the following !insertmacro once in a section it works:
!macro FWOR 'C:\test.txt' 'Value o' '%RBPH%' 'Value x'
Yet if I do this
!macro FWOR 'C:\test.txt' 'Value o' '%RBPH%' 'Value x'
!macro FWOR 'C:\test.txt' 'Value o' '%RBPH%' 'Value x'
I am confronted with a compile time error:
Error: label "replace:" already declared in section/function
I've seen other scripts able to call the same label several times, yet I am trying to figure it out to no avail. Can you share a trick?
Thank you Kichik!
kichik
25th February 2005 14:03 UTC
See Afrow UK's Tutorial: Using labels in macro's.
vbgunz
25th February 2005 14:35 UTC
Thank you again Kichik... I browse his pages on the regular looking for goodies and I can't believe I missed it. It works like a charm. Thanks!