LineSum: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Adding new author and category links.)
No edit summary
Line 2: Line 2:


== Links ==
== Links ==
; 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.
If a function is used without header, put the function code in your script before calling it.


== The Function ==
== The Function Description==
<highlight-nsis>/*
 
<highlight-nsis>
____________________________________________________________________________
____________________________________________________________________________


Line 14: Line 16:
____________________________________________________________________________
____________________________________________________________________________


Thanks Afrow UK (Based on his Function "LineCount")
Thanks Afrow UK (Based on his idea of Function "LineCount")




Line 29: Line 31:
Note:
Note:
-Error flag if input file isn't exists
-Error flag if input file isn't exists
</highlight-nsis>






Example:
<b>Example:</b>
Section
<highlight-nsis>Section
${LineSum} "C:\a.log" $R0
${LineSum} "C:\a.log" $R0
; $R0="54"
; $R0="54"
SectionEnd*/
SectionEnd
 
</highlight-nsis>


;---------------------------------------------------------------------------
== The Function Code==


<highlight-nsis>
Function LineSum
Function LineSum
!define LineSum `!insertmacro LineSumCall`
!define LineSum `!insertmacro LineSumCall`

Revision as of 14:25, 4 July 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 header, put the function code in your script before calling it.

The 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

The 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