WordAdd: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Wikipedia python library) |
Instructor (talk | contribs) No edit summary |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{PageAuthor|Instructor}} | |||
{{User:Instructor/Headers/Template}} | |||
== Function Description == | |||
<highlight-nsis> | |||
____________________________________________________________________________ | |||
WordAdd v1.8 (add or delete) | |||
____________________________________________________________________________ | |||
Add words to string1 from string2 if not exist or | Add words to string1 from string2 if not exist or delete words if exist. | ||
delete words if exist. | |||
Syntax: | Syntax: | ||
${WordAdd} "[string1]" "[delimiter]" "[E][options]" $var | |||
"[string1]" ;[string1] | |||
; string for addition or removing | |||
"[delimiter]" ;[delimiter] | |||
; one or several symbols | |||
"[E][options]" ;[options] | |||
; +string2 : words to add | |||
; -string2 : words to delete | |||
; | |||
;[E] | |||
; with errorlevel output | |||
; IfErrors: | |||
; $var=1 delimiter is empty | |||
; $var=3 syntax error (use: +text,-text) | |||
;[] | |||
; no errorlevel output (default) | |||
; If some errors found then (result=input string) | |||
; | |||
$var ;output (result) | |||
</highlight-nsis> | |||
Example (add): | <b>Example (add):</b> | ||
Section | <highlight-nsis>Section | ||
${WordAdd} "C:\io.sys C:\WINDOWS" " " "+C:\WINDOWS C:\config.sys" $R0 | |||
; $R0="C:\io.sys C:\WINDOWS C:\config.sys" | |||
SectionEnd | SectionEnd | ||
</highlight-nsis> | |||
Example (delete): | <b>Example (delete):</b> | ||
Section | <highlight-nsis>Section | ||
${WordAdd} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "-C:\WINDOWS C:\config.sys C:\IO.SYS" $R0 | |||
; $R0="C:\logo.sys" | |||
SectionEnd | SectionEnd | ||
</highlight-nsis> | |||
Example (add to one): | <b>Example (add to one):</b> | ||
Section | <highlight-nsis>Section | ||
${WordAdd} "C:\io.sys" " " "+C:\WINDOWS C:\config.sys C:\IO.SYS" $R0 | |||
; $R0="C:\io.sys C:\WINDOWS C:\config.sys" | |||
SectionEnd | SectionEnd | ||
</highlight-nsis> | |||
Example (delete one): | <b>Example (delete one):</b> | ||
Section | <highlight-nsis>Section | ||
${WordAdd} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "-C:\WINDOWS" $R0 | |||
; $R0="C:\io.sys C:\logo.sys" | |||
SectionEnd | SectionEnd | ||
</highlight-nsis> | |||
Example (No new words found): | <b>Example (No new words found):</b> | ||
Section | <highlight-nsis>Section | ||
${WordAdd} "C:\io.sys C:\logo.sys" " " "+C:\logo.sys" $R0 | |||
StrCmp $R0 "C:\io.sys C:\logo.sys" 0 +2 | StrCmp $R0 "C:\io.sys C:\logo.sys" 0 +2 | ||
MessageBox MB_OK "No new words found to add" | MessageBox MB_OK "No new words found to add" | ||
SectionEnd | SectionEnd | ||
</highlight-nsis> | |||
Example (No words deleted): | <b>Example (No words deleted):</b> | ||
Section | <highlight-nsis>Section | ||
${WordAdd} "C:\io.sys C:\logo.sys" " " "-C:\config.sys" $R0 | |||
StrCmp $R0 "C:\io.sys C:\logo.sys" 0 +2 | StrCmp $R0 "C:\io.sys C:\logo.sys" 0 +2 | ||
MessageBox MB_OK "No words found to delete" | MessageBox MB_OK "No words found to delete" | ||
SectionEnd | SectionEnd | ||
</highlight-nsis> | |||
Example (With errorlevel output): | <b>Example (With errorlevel output):</b> | ||
Section | <highlight-nsis>Section | ||
${WordAdd} "C:\io.sys C:\logo.sys" "" "E-C:\logo.sys" $R0 | |||
; $R0="1" (delimiter is empty "") | |||
IfErrors 0 noerrors | IfErrors 0 noerrors | ||
Line 118: | Line 95: | ||
end: | end: | ||
SectionEnd | SectionEnd | ||
</highlight-nsis> | |||
== Function Code == | |||
<highlight-nsis> | |||
Function WordAdd | Function WordAdd | ||
!define WordAdd `!insertmacro WordAddCall` | |||
!macro WordAddCall _STRING1 _DELIMITER _STRING2 _RESULT | |||
Push `${_STRING1}` | |||
Push `${_DELIMITER}` | |||
Push `${_STRING2}` | |||
Call WordAdd | |||
Pop ${_RESULT} | |||
!macroend | |||
Exch $1 | Exch $1 | ||
Exch | Exch | ||
Line 233: | Line 222: | ||
</highlight-nsis> | </highlight-nsis> | ||
[[Category:String Functions]] | |||
Latest revision as of 11:25, 30 November 2005
Author: Instructor (talk, contrib) |
Page for NSIS 2.07 and below users
You can use the latest version of headers (recommended) or the following function code (put the function code in your script before calling it)
Function Description
____________________________________________________________________________ WordAdd v1.8 (add or delete) ____________________________________________________________________________ Add words to string1 from string2 if not exist or delete words if exist. Syntax: ${WordAdd} "[string1]" "[delimiter]" "[E][options]" $var "[string1]" ;[string1] ; string for addition or removing "[delimiter]" ;[delimiter] ; one or several symbols "[E][options]" ;[options] ; +string2 : words to add ; -string2 : words to delete ; ;[E] ; with errorlevel output ; IfErrors: ; $var=1 delimiter is empty ; $var=3 syntax error (use: +text,-text) ;[] ; no errorlevel output (default) ; If some errors found then (result=input string) ; $var ;output (result)
Example (add):
Section ${WordAdd} "C:\io.sys C:\WINDOWS" " " "+C:\WINDOWS C:\config.sys" $R0 ; $R0="C:\io.sys C:\WINDOWS C:\config.sys" SectionEnd
Example (delete):
Section ${WordAdd} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "-C:\WINDOWS C:\config.sys C:\IO.SYS" $R0 ; $R0="C:\logo.sys" SectionEnd
Example (add to one):
Section ${WordAdd} "C:\io.sys" " " "+C:\WINDOWS C:\config.sys C:\IO.SYS" $R0 ; $R0="C:\io.sys C:\WINDOWS C:\config.sys" SectionEnd
Example (delete one):
Section ${WordAdd} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "-C:\WINDOWS" $R0 ; $R0="C:\io.sys C:\logo.sys" SectionEnd
Example (No new words found):
Section ${WordAdd} "C:\io.sys C:\logo.sys" " " "+C:\logo.sys" $R0 StrCmp $R0 "C:\io.sys C:\logo.sys" 0 +2 MessageBox MB_OK "No new words found to add" SectionEnd
Example (No words deleted):
Section ${WordAdd} "C:\io.sys C:\logo.sys" " " "-C:\config.sys" $R0 StrCmp $R0 "C:\io.sys C:\logo.sys" 0 +2 MessageBox MB_OK "No words found to delete" SectionEnd
Example (With errorlevel output):
Section ${WordAdd} "C:\io.sys C:\logo.sys" "" "E-C:\logo.sys" $R0 ; $R0="1" (delimiter is empty "") IfErrors 0 noerrors MessageBox MB_OK 'Errorlevel=$R0' IDOK end noerrors: MessageBox MB_OK 'No errors' end: SectionEnd
Function Code
Function WordAdd !define WordAdd `!insertmacro WordAddCall` !macro WordAddCall _STRING1 _DELIMITER _STRING2 _RESULT Push `${_STRING1}` Push `${_DELIMITER}` Push `${_STRING2}` Call WordAdd Pop ${_RESULT} !macroend Exch $1 Exch Exch $0 Exch Exch 2 Exch $R0 Exch 2 Push $2 Push $3 Push $4 Push $5 Push $6 Push $7 Push $R1 ClearErrors StrCpy $7 '' StrCpy $2 $1 1 StrCmp $2 'E' 0 +4 StrCpy $7 E StrCpy $1 $1 '' 1 goto -4 StrCpy $5 0 StrCpy $R1 $R0 StrCpy $2 $1 '' 1 StrCpy $1 $1 1 StrCmp $1 '+' +2 StrCmp $1 '-' 0 error3 StrCmp $0 '' error1 StrCmp $2 '' end StrCmp $R0 '' 0 +5 StrCmp $1 '-' end StrCmp $1 '+' 0 +3 StrCpy $R0 $2 goto end loop: IntOp $5 $5 + 1 Push `$2` Push `$0` Push `E+$5` Call WordFind Pop $3 IfErrors 0 /word StrCmp $3 2 +4 StrCmp $3$5 11 0 +3 StrCpy $3 $2 goto /word StrCmp $1 '-' end preend /word: Push `$R0` Push `$0` Push `E/$3` Call WordFind Pop $4 IfErrors +2 StrCmp $1 '-' delete loop StrCmp $1$4 '-1' +2 StrCmp $1 '-' loop +4 StrCmp $R0 $3 0 loop StrCpy $R0 '' goto end StrCmp $1$4 '+1' 0 +2 StrCmp $R0 $3 loop StrCmp $R0 $R1 +3 StrCpy $R1 '$R1$0$3' goto loop StrLen $6 $0 StrCpy $6 $R0 '' -$6 StrCmp $6 $0 0 -4 StrCpy $R1 '$R1$3' goto loop delete: Push `$R0` Push `$0` Push `E+$4{}` Call WordFind Pop $R0 goto /word error3: StrCpy $R1 3 goto error error1: StrCpy $R1 1 error: StrCmp $7 'E' 0 end SetErrors preend: StrCpy $R0 $R1 end: Pop $R1 Pop $7 Pop $6 Pop $5 Pop $4 Pop $3 Pop $2 Pop $1 Pop $0 Exch $R0 FunctionEnd