LineSum: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.) |
Instructor (talk | contribs) No edit summary |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{ | {{PageAuthor|Instructor}} | ||
{{User:Instructor/Headers/Template}} | |||
== | == Function Description== | ||
<highlight-nsis> | |||
<highlight-nsis> | |||
____________________________________________________________________________ | ____________________________________________________________________________ | ||
LineSum | LineSum | ||
____________________________________________________________________________ | ____________________________________________________________________________ | ||
Thanks Afrow UK (Based on his idea of Function "LineCount") | |||
Thanks Afrow UK (Based on his idea of Function "LineCount" | |||
Line 25: | Line 18: | ||
Syntax: | Syntax: | ||
${LineSum} "[File]" $var | |||
"[File]" ; Input file | |||
$var ; Result: Sum of lines | |||
Note: | Note: | ||
-Error flag if input file isn't exists | -Error flag if input file isn't exists | ||
</highlight-nsis> | |||
<b>Example:</b> | |||
<highlight-nsis>Section | |||
${LineSum} "C:\a.log" $R0 | |||
; $R0="54" | |||
SectionEnd | |||
</highlight-nsis> | |||
== Function Code == | |||
<highlight-nsis> | |||
Function LineSum | Function LineSum | ||
!define LineSum `!insertmacro LineSumCall` | |||
!macro LineSumCall _FILE _RESULT | |||
Push `${_FILE}` | |||
Call LineSum | |||
Pop ${_RESULT} | |||
!macroend | |||
Exch $0 | Exch $0 | ||
Push $1 | Push $1 | ||
Line 51: | Line 57: | ||
StrCpy $2 0 | StrCpy $2 0 | ||
FileOpen $0 $0 r | FileOpen $0 $0 r | ||
IfErrors error | |||
FileRead $0 $1 | FileRead $0 $1 | ||
IfErrors +3 | IfErrors +3 | ||
Line 69: | Line 76: | ||
FunctionEnd | FunctionEnd | ||
</highlight-nsis> | </highlight-nsis> | ||
[[Category:Text Files Manipulation Functions]] |
Latest revision as of 11:30, 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
____________________________________________________________________________ LineSum ____________________________________________________________________________ Thanks Afrow UK (Based on his idea of Function "LineCount") Get sum of lines in text file. Syntax: ${LineSum} "[File]" $var "[File]" ; Input file $var ; Result: Sum of lines Note: -Error flag if input file isn't exists
Example:
Section ${LineSum} "C:\a.log" $R0 ; $R0="54" SectionEnd
Function Code
Function LineSum !define LineSum `!insertmacro LineSumCall` !macro LineSumCall _FILE _RESULT Push `${_FILE}` Call LineSum Pop ${_RESULT} !macroend Exch $0 Push $1 Push $2 ClearErrors IfFileExists $0 0 error StrCpy $2 0 FileOpen $0 $0 r IfErrors error FileRead $0 $1 IfErrors +3 IntOp $2 $2 + 1 Goto -3 FileClose $0 StrCpy $0 $2 goto end error: SetErrors StrCpy $0 '' end: Pop $2 Pop $1 Exch $0 FunctionEnd