WordAdd: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Added category links.)
m (Updated by user: Instructor (talk, contrib).)
Line 6: Line 6:
; Latest version of headers "nsh.zip":
; Latest version of headers "nsh.zip":
: http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost
: http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost
If a function is used without an header, you should put the function below in your script before calling it.


== The Function ==
== The Function ==
Line 14: Line 16:
______________________________________________________________________________
______________________________________________________________________________


2004 Shengalts Aleksander (Shengalts@mail.ru)
WordFind required
 
Function "WordFind" required.




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


Push "[string1]"          ;[string1]
"[string1]"          ;[string1]
                          ;  string for addition or removing
                    ;  string for addition or removing
Push "[delimiter]"        ;[delimiter]
"[delimiter]"        ;[delimiter]
                          ;  one or several symbols
                    ;  one or several symbols
Push "[E][+-string2]"     ;[+-string2]
"[E][options]"       ;[options]
                          ;  +string2 : words to add
                    ;  +string2 : words to add
                          ;  -string2 : words to delete
                    ;  -string2 : words to delete
                          ;
                    ;
                          ;[E]
                    ;[E]
                          ;  with errorlevel output
                    ;  with errorlevel output
                          ;  IfErrors:
                    ;  IfErrors:
                          ;    $var=1  delimiter is empty
                    ;    $var=1  delimiter is empty
                          ;    $var=3  syntax error (use: +text,-text)
                    ;    $var=3  syntax error (use: +text,-text)
                          ;[]
                    ;[]
                          ;  no errorlevel output (default)
                    ;  no errorlevel output (default)
                          ;  If some errors found then (result=input string)
                    ;  If some errors found then (result=input string)
                          ;
                    ;
Call WordAdd              ;call function
$var                 ;output (result)
                          ;
Pop $var                 ;output (result)




Example (add):
Example (add):
Section
Section
Push "C:\io.sys C:\WINDOWS"
${WordAdd} "C:\io.sys C:\WINDOWS" " " "+C:\WINDOWS C:\config.sys" $R0
Push " "
; $R0="C:\io.sys C:\WINDOWS C:\config.sys"
Push "+C:\WINDOWS C:\config.sys"
Call WordAdd
Pop $R0     ;now contain: "C:\io.sys C:\WINDOWS C:\config.sys"
SectionEnd
SectionEnd


Example (delete):
Example (delete):
Section
Section
Push "C:\io.sys C:\logo.sys C:\WINDOWS"
${WordAdd} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "-C:\WINDOWS C:\config.sys C:\IO.SYS" $R0
Push " "
; $R0="C:\logo.sys"
Push "-C:\WINDOWS C:\config.sys C:\IO.SYS"
Call WordAdd
Pop $R0     ;now contain: "C:\logo.sys"
SectionEnd
SectionEnd


Example (add to one):
Example (add to one):
Section
Section
Push "C:\io.sys"
${WordAdd} "C:\io.sys" " " "+C:\WINDOWS C:\config.sys C:\IO.SYS" $R0
Push " "
; $R0="C:\io.sys C:\WINDOWS C:\config.sys"
Push "+C:\WINDOWS C:\config.sys C:\IO.SYS"
Call WordAdd
Pop $R0     ;now contain: "C:\io.sys C:\WINDOWS C:\config.sys"
SectionEnd
SectionEnd


Example (delete one):
Example (delete one):
Section
Section
Push "C:\io.sys C:\logo.sys C:\WINDOWS"
${WordAdd} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "-C:\WINDOWS" $R0
Push " "
; $R0="C:\io.sys C:\logo.sys"
Push "-C:\WINDOWS"
Call WordAdd
Pop $R0     ;now contain: "C:\io.sys C:\logo.sys"
SectionEnd
SectionEnd


Example (No new words found):
Example (No new words found):
Section
Section
Push "C:\io.sys C:\logo.sys"
${WordAdd} "C:\io.sys C:\logo.sys" " " "+C:\logo.sys" $R0
Push " "
Push "+C:\logo.sys"
Call WordAdd
Pop $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"
Line 97: Line 78:
Example (No words deleted):
Example (No words deleted):
Section
Section
Push "C:\io.sys C:\logo.sys"
${WordAdd} "C:\io.sys C:\logo.sys" " " "-C:\config.sys" $R0
Push " "
Push "-C:\config.sys"
Call WordAdd
Pop $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"
Line 109: Line 85:
Example (With errorlevel output):
Example (With errorlevel output):
Section
Section
Push "C:\io.sys C:\logo.sys"
${WordAdd} "C:\io.sys C:\logo.sys" "" "E-C:\logo.sys" $R0
Push ""
; $R0="1" (delimiter is empty "")
Push "E-C:\logo.sys"
Call WordAdd
Pop $R0     ;now contain: "1" (delimiter is empty "")


IfErrors 0 noerrors
IfErrors 0 noerrors
Line 126: Line 99:


;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
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

Revision as of 09:41, 24 June 2005

Author: Instructor (talk, contrib)


Links

Latest version of headers "nsh.zip"
http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost

If a function is used without an header, you should put the function below in your script before calling it.

The Function

/*
______________________________________________________________________________
 
                         WordAdd v1.8 (add or delete)
______________________________________________________________________________
 
 WordFind required
 
 
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 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