Updates by Instructor

1. "WordReplace"
   -Added options "{", "}", "{*", "}*"

2. "GetOptions"
   -Now sets error flag if option does not found

3. "ConfigRead"
   -Now sets error flag if entry does not found

4. New case sensitive functions:
      "WordFindS", "WordFind2XS", "WordFind3XS", "WordReplaceS",
      "WordAddS", "WordInsertS", "StrFilterS", "TextCompareS",
      "ConfigReadS", "ConfigWriteS", "GetOptionsS"


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4517 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2006-02-10 10:46:57 +00:00
parent 082160fb3e
commit aa43f0c349
9 changed files with 1534 additions and 572 deletions

View file

@ -1,10 +1,10 @@
/*
_____________________________________________________________________________
Text Functions Header v2.1
Text Functions Header v2.2
_____________________________________________________________________________
2005 Shengalts Aleksander aka Instructor (Shengalts@mail.ru)
2006 Shengalts Aleksander aka Instructor (Shengalts@mail.ru)
See documentation for more information about the following functions.
@ -17,12 +17,13 @@ _____________________________________________________________________________
TextFunction=[LineFind|LineRead|FileReadFromEnd|LineSum|FileJoin|
TextCompare|ConfigRead|ConfigWrite|FileRecode|TrimNewLines]
TextCompare|TextCompareS|ConfigRead|ConfigReadS|
ConfigWrite|ConfigWriteS|FileRecode|TrimNewLines]
un.TextFunction=[un.LineFind|un.LineRead|un.FileReadFromEnd|un.LineSum|
un.FileJoin|un.TextCompare|un.ConfigRead|un.ConfigWrite|
un.FileRecode|un.TrimNewLines]
un.FileJoin|un.TextCompare|un.TextCompareS|un.ConfigRead|
un.ConfigReadS|un.ConfigWrite|un.ConfigWriteS|un.FileRecode|
un.TrimNewLines]
_____________________________________________________________________________
@ -66,6 +67,7 @@ TrimNewLines
!verbose ${_TEXTFUNC_VERBOSE}
!define TEXTFUNC_VERBOSE `!insertmacro TEXTFUNC_VERBOSE`
!define _TEXTFUNC_UN
!define _TEXTFUNC_S
!verbose pop
!macro TEXTFUNC_VERBOSE _VERBOSE
@ -73,12 +75,12 @@ TrimNewLines
!verbose 3
!undef _TEXTFUNC_VERBOSE
!define _TEXTFUNC_VERBOSE ${_VERBOSE}
!verbose 4
!echo `"verbosity=${_VERBOSE}"`
!verbose pop
!macroend
# Install. Case insensitive. #
!macro LineFindCall _INPUT _OUTPUT _RANGE _FUNC
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
@ -432,8 +434,6 @@ TrimNewLines
Pop $0
FunctionEnd
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
@ -493,8 +493,6 @@ TrimNewLines
Exch $0
FunctionEnd
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
@ -560,8 +558,6 @@ TrimNewLines
Pop $0
FunctionEnd
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
@ -600,8 +596,6 @@ TrimNewLines
Exch $0
FunctionEnd
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
@ -680,19 +674,17 @@ TrimNewLines
Pop $0
FunctionEnd
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
!macro TextCompare
!ifndef ${_TEXTFUNC_UN}TextCompare
!ifndef ${_TEXTFUNC_UN}TextCompare${_TEXTFUNC_S}
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
!define ${_TEXTFUNC_UN}TextCompare `!insertmacro ${_TEXTFUNC_UN}TextCompareCall`
!define ${_TEXTFUNC_UN}TextCompare${_TEXTFUNC_S} `!insertmacro ${_TEXTFUNC_UN}TextCompare${_TEXTFUNC_S}Call`
Function ${_TEXTFUNC_UN}TextCompare
Function ${_TEXTFUNC_UN}TextCompare${_TEXTFUNC_S}
Exch $3
Exch
Exch $2
@ -729,31 +721,31 @@ TrimNewLines
StrCpy $8 0
nextline:
StrCmp $4 '' fast
StrCmp${_TEXTFUNC_S} $4 '' fast
IntOp $8 $8 + 1
FileRead $4 $9
IfErrors 0 +4
FileClose $4
StrCpy $4 ''
StrCmp $5 '' end
StrCmp${_TEXTFUNC_S} $5 '' end
StrCmp $2 'FastDiff' fast
StrCmp $2 'FastEqual' fast slow
fast:
StrCmp $5 '' call
StrCmp${_TEXTFUNC_S} $5 '' call
IntOp $6 $6 + 1
FileRead $5 $7
IfErrors 0 +5
FileClose $5
StrCpy $5 ''
StrCmp $4 '' end
StrCmp${_TEXTFUNC_S} $4 '' end
StrCmp $2 'FastDiff' call close
StrCmp $2 'FastDiff' 0 +2
StrCmp $7 $9 nextline call
StrCmp $7 $9 call nextline
StrCmp${_TEXTFUNC_S} $7 $9 nextline call
StrCmp${_TEXTFUNC_S} $7 $9 call nextline
slow:
StrCmp $4 '' close
StrCmp${_TEXTFUNC_S} $4 '' close
StrCpy $6 ''
DetailPrint '$8. $9'
FileSeek $5 0
@ -763,9 +755,9 @@ TrimNewLines
IfErrors 0 +2
StrCmp $2 'SlowDiff' call nextline
StrCmp $2 'SlowDiff' 0 +2
StrCmp $7 $9 nextline slownext
StrCmp${_TEXTFUNC_S} $7 $9 nextline slownext
IntOp $6 $6 + 1
StrCmp $7 $9 0 slownext
StrCmp${_TEXTFUNC_S} $7 $9 0 slownext
call:
Push $2
@ -810,19 +802,17 @@ TrimNewLines
Pop $0
FunctionEnd
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
!macro ConfigRead
!ifndef ${_TEXTFUNC_UN}ConfigRead
!ifndef ${_TEXTFUNC_UN}ConfigRead${_TEXTFUNC_S}
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
!define ${_TEXTFUNC_UN}ConfigRead `!insertmacro ${_TEXTFUNC_UN}ConfigReadCall`
!define ${_TEXTFUNC_UN}ConfigRead${_TEXTFUNC_S} `!insertmacro ${_TEXTFUNC_UN}ConfigRead${_TEXTFUNC_S}Call`
Function ${_TEXTFUNC_UN}ConfigRead
Function ${_TEXTFUNC_UN}ConfigRead${_TEXTFUNC_S}
Exch $1
Exch
Exch $0
@ -835,24 +825,22 @@ TrimNewLines
FileOpen $2 $0 r
IfErrors error
StrLen $0 $1
StrCmp $0 0 error
StrCmp${_TEXTFUNC_S} $0 0 error
readnext:
FileRead $2 $3
IfErrors empty
IfErrors error
StrCpy $4 $3 $0
StrCmp $4 $1 0 readnext
StrCmp${_TEXTFUNC_S} $4 $1 0 readnext
StrCpy $0 $3 '' $0
StrCpy $4 $0 1 -1
StrCmp $4 '$\r' +2
StrCmp $4 '$\n' 0 close
StrCmp${_TEXTFUNC_S} $4 '$\r' +2
StrCmp${_TEXTFUNC_S} $4 '$\n' 0 close
StrCpy $0 $0 -1
goto -4
error:
SetErrors
empty:
StrCpy $0 ''
close:
@ -865,19 +853,17 @@ TrimNewLines
Exch $0
FunctionEnd
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
!macro ConfigWrite
!ifndef ${_TEXTFUNC_UN}ConfigWrite
!ifndef ${_TEXTFUNC_UN}ConfigWrite${_TEXTFUNC_S}
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
!define ${_TEXTFUNC_UN}ConfigWrite `!insertmacro ${_TEXTFUNC_UN}ConfigWriteCall`
!define ${_TEXTFUNC_UN}ConfigWrite${_TEXTFUNC_S} `!insertmacro ${_TEXTFUNC_UN}ConfigWrite${_TEXTFUNC_S}Call`
Function ${_TEXTFUNC_UN}ConfigWrite
Function ${_TEXTFUNC_UN}ConfigWrite${_TEXTFUNC_S}
Exch $2
Exch
Exch $1
@ -896,7 +882,7 @@ TrimNewLines
IfErrors error
StrLen $0 $1
StrCmp $0 0 0 readnext
StrCmp${_TEXTFUNC_S} $0 0 0 readnext
StrCpy $0 ''
goto close
@ -904,20 +890,20 @@ TrimNewLines
FileRead $3 $4
IfErrors add
StrCpy $5 $4 $0
StrCmp $5 $1 0 readnext
StrCmp${_TEXTFUNC_S} $5 $1 0 readnext
StrCpy $5 0
IntOp $5 $5 - 1
StrCpy $6 $4 1 $5
StrCmp $6 '$\r' -2
StrCmp $6 '$\n' -3
StrCmp${_TEXTFUNC_S} $6 '$\r' -2
StrCmp${_TEXTFUNC_S} $6 '$\n' -3
StrCpy $6 $4
StrCmp $5 -1 +3
StrCmp${_TEXTFUNC_S} $5 -1 +3
IntOp $5 $5 + 1
StrCpy $6 $4 $5
StrCmp $2 '' change
StrCmp $6 '$1$2' 0 change
StrCmp${_TEXTFUNC_S} $2 '' change
StrCmp${_TEXTFUNC_S} $6 '$1$2' 0 change
StrCpy $0 SAME
goto close
@ -933,26 +919,26 @@ TrimNewLines
FileSeek $3 $5 SET
System::Call 'kernel32::ReadFile(i r3, i r0, i $6, t.,)'
FileSeek $3 $4 SET
StrCmp $2 '' +2
StrCmp${_TEXTFUNC_S} $2 '' +2
FileWrite $3 '$1$2$\r$\n'
System::Call 'kernel32::WriteFile(i r3, i r0, i $6, t.,)'
System::Call 'kernel32::SetEndOfFile(i r3)'
System::Free $0
StrCmp $2 '' +3
StrCmp${_TEXTFUNC_S} $2 '' +3
StrCpy $0 CHANGED
goto close
StrCpy $0 DELETED
goto close
add:
StrCmp $2 '' 0 +3
StrCmp${_TEXTFUNC_S} $2 '' 0 +3
StrCpy $0 SAME
goto close
FileSeek $3 -1 END
FileRead $3 $4
IfErrors +4
StrCmp $4 '$\r' +3
StrCmp $4 '$\n' +2
StrCmp${_TEXTFUNC_S} $4 '$\r' +3
StrCmp${_TEXTFUNC_S} $4 '$\n' +2
FileWrite $3 '$\r$\n'
FileWrite $3 '$1$2$\r$\n'
StrCpy $0 ADDED
@ -975,8 +961,6 @@ TrimNewLines
Exch $0
FunctionEnd
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
@ -1026,8 +1010,6 @@ TrimNewLines
Pop $0
FunctionEnd
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
@ -1057,12 +1039,13 @@ TrimNewLines
Exch $0
FunctionEnd
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
# Uninstall. Case insensitive. #
!macro un.LineFindCall _INPUT _OUTPUT _RANGE _FUNC
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
@ -1180,6 +1163,8 @@ TrimNewLines
!insertmacro LineFind
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
@ -1193,6 +1178,8 @@ TrimNewLines
!insertmacro LineRead
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
@ -1206,6 +1193,8 @@ TrimNewLines
!insertmacro FileReadFromEnd
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
@ -1219,6 +1208,8 @@ TrimNewLines
!insertmacro LineSum
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
@ -1232,6 +1223,8 @@ TrimNewLines
!insertmacro FileJoin
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
@ -1245,6 +1238,8 @@ TrimNewLines
!insertmacro TextCompare
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
@ -1258,6 +1253,8 @@ TrimNewLines
!insertmacro ConfigRead
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
@ -1271,6 +1268,8 @@ TrimNewLines
!insertmacro ConfigWrite
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
@ -1284,6 +1283,8 @@ TrimNewLines
!insertmacro FileRecode
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
@ -1297,6 +1298,186 @@ TrimNewLines
!insertmacro TrimNewLines
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!verbose pop
!endif
!macroend
# Install. Case sensitive. #
!macro TextCompareSCall _FILE1 _FILE2 _OPTION _FUNC
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
Push $0
Push `${_FILE1}`
Push `${_FILE2}`
Push `${_OPTION}`
GetFunctionAddress $0 `${_FUNC}`
Push `$0`
Call TextCompareS
Pop $0
!verbose pop
!macroend
!macro ConfigReadSCall _FILE _ENTRY _RESULT
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
Push `${_FILE}`
Push `${_ENTRY}`
Call ConfigReadS
Pop ${_RESULT}
!verbose pop
!macroend
!macro ConfigWriteSCall _FILE _ENTRY _VALUE _RESULT
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
Push `${_FILE}`
Push `${_ENTRY}`
Push `${_VALUE}`
Call ConfigWriteS
Pop ${_RESULT}
!verbose pop
!macroend
!macro TextCompareS
!ifndef TextCompareS
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
!undef _TEXTFUNC_S
!define _TEXTFUNC_S `S`
!insertmacro TextCompare
!undef _TEXTFUNC_S
!define _TEXTFUNC_S
!verbose pop
!endif
!macroend
!macro ConfigReadS
!ifndef ConfigReadS
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
!undef _TEXTFUNC_S
!define _TEXTFUNC_S `S`
!insertmacro ConfigRead
!undef _TEXTFUNC_S
!define _TEXTFUNC_S
!verbose pop
!endif
!macroend
!macro ConfigWriteS
!ifndef ConfigWriteS
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
!undef _TEXTFUNC_S
!define _TEXTFUNC_S `S`
!insertmacro ConfigWrite
!undef _TEXTFUNC_S
!define _TEXTFUNC_S
!verbose pop
!endif
!macroend
# Uninstall. Case sensitive. #
!macro un.TextCompareSCall _FILE1 _FILE2 _OPTION _FUNC
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
Push $0
Push `${_FILE1}`
Push `${_FILE2}`
Push `${_OPTION}`
GetFunctionAddress $0 `${_FUNC}`
Push `$0`
Call un.TextCompareS
Pop $0
!verbose pop
!macroend
!macro un.ConfigReadSCall _FILE _ENTRY _RESULT
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
Push `${_FILE}`
Push `${_ENTRY}`
Call un.ConfigReadS
Pop ${_RESULT}
!verbose pop
!macroend
!macro un.ConfigWriteSCall _FILE _ENTRY _VALUE _RESULT
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
Push `${_FILE}`
Push `${_ENTRY}`
Push `${_VALUE}`
Call un.ConfigWriteS
Pop ${_RESULT}
!verbose pop
!macroend
!macro un.TextCompareS
!ifndef un.TextCompareS
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN `un.`
!undef _TEXTFUNC_S
!define _TEXTFUNC_S `S`
!insertmacro TextCompare
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!undef _TEXTFUNC_S
!define _TEXTFUNC_S
!verbose pop
!endif
!macroend
!macro un.ConfigReadS
!ifndef un.ConfigReadS
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN `un.`
!undef _TEXTFUNC_S
!define _TEXTFUNC_S `S`
!insertmacro ConfigRead
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!undef _TEXTFUNC_S
!define _TEXTFUNC_S
!verbose pop
!endif
!macroend
!macro un.ConfigWriteS
!ifndef un.ConfigWriteS
!verbose push
!verbose ${_TEXTFUNC_VERBOSE}
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN `un.`
!undef _TEXTFUNC_S
!define _TEXTFUNC_S `S`
!insertmacro ConfigWrite
!undef _TEXTFUNC_UN
!define _TEXTFUNC_UN
!undef _TEXTFUNC_S
!define _TEXTFUNC_S
!verbose pop
!endif
!macroend