improved GetParent, GetParameters

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3012 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
joostverburg 2003-10-12 12:52:57 +00:00
parent 4a5e2b7904
commit 1a3af33dd9

View file

@ -13,25 +13,32 @@
\c ; Pop $R0 \c ; Pop $R0
\c ; ; at this point $R0 will equal "C:\Program Files\Directory" \c ; ; at this point $R0 will equal "C:\Program Files\Directory"
\c \c
\c Function GetParent \c Function GetParent
\c Exch $R0 ; old $R0 is on top of stack \c
\c Push $R1 \c Exch $R0
\c Push $R2 \c Push $R1
\c Push $R3 \c Push $R2
\c StrLen $R3 $R0 \c Push $R3
\c loop: \c
\c IntOp $R1 $R1 - 1 \c StrCpy $R1 0
\c IntCmp $R1 -$R3 exit exit \c StrLen $R2 $R0
\c StrCpy $R2 $R0 1 $R1 \c
\c StrCmp $R2 "\" exit \c loop:
\c Goto loop \c IntOp $R1 $R1 + 1
\c exit: \c IntCmp $R1 $R2 get 0 get
\c StrCpy $R0 $R0 $R1 \c StrCpy $R3 $R0 1 -$R1
\c Pop $R3 \c StrCmp $R3 "\" get
\c Pop $R2 \c Goto loop
\c Pop $R1 \c
\c Exch $R0 ; put $R0 on top of stack, restore $R0 to original value \c get:
\c FunctionEnd \c StrCpy $R0 $R0 -$R1
\c
\c Pop $R3
\c Pop $R2
\c Pop $R1
\c Exch $R0
\c
\c FunctionEnd
\H{trimnewlines} Trim newlines \H{trimnewlines} Trim newlines
@ -68,34 +75,43 @@
\c ; input, none \c ; input, none
\c ; output, top of stack (replaces, with e.g. whatever) \c ; output, top of stack (replaces, with e.g. whatever)
\c ; modifies no other variables. \c ; modifies no other variables.
\c \c
\c Function GetParameters \c Function GetParameters
\c Push $R0 \c
\c Push $R1 \c Push $R0
\c Push $R2 \c Push $R1
\c Push $R3 \c Push $R2
\c StrCpy $R0 $CMDLINE 1 \c Push $R3
\c StrCpy $R1 '"' \c
\c StrCpy $R2 1 \c StrCpy $R2 1
\c StrLen $R3 $CMDLINE \c StrLen $R3 $CMDLINE
\c StrCmp $R0 '"' loop \c
\c StrCpy $R1 ' ' ; we're scanning for a space instead of a quote \c ;Check for quote or space
\c loop: \c StrCpy $R0 $CMDLINE $R2
\c StrCpy $R0 $CMDLINE 1 $R2 \c StrCmp $R0 '"' 0 +3
\c StrCmp $R0 $R1 loop2 \c StrCpy $R1 '"'
\c StrCmp $R2 $R3 loop2 \c Goto loop
\c IntOp $R2 $R2 + 1 \c StrCpy $R1 " "
\c Goto loop \c
\c loop2: \c loop:
\c IntOp $R2 $R2 + 1 \c IntOp $R2 $R2 + 1
\c StrCpy $R0 $CMDLINE 1 $R2 \c StrCpy $R0 $CMDLINE 1 $R2
\c StrCmp $R0 " " loop2 \c StrCmp $R0 $R1 get
\c StrCpy $R0 $CMDLINE "" $R2 \c StrCmp $R2 $R3 get
\c Pop $R3 \c Goto loop
\c Pop $R2 \c
\c Pop $R1 \c get:
\c Exch $R0 \c IntOp $R2 $R2 + 1
\c FunctionEnd \c StrCpy $R0 $CMDLINE 1 $R2
\c StrCmp $R0 " " get
\c StrCpy $R0 $CMDLINE "" $R2
\c
\c Pop $R3
\c Pop $R2
\c Pop $R1
\c Exch $R0
\c
\c FunctionEnd
\H{strstr} Search in a string \H{strstr} Search in a string