LineSum: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Added category links.)
m (Updated by user: Instructor (talk, contrib).)
Line 7: Line 7:
: http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost
: http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost


If function used without header then put function in script before call it  
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 13: Line 13:
____________________________________________________________________________
____________________________________________________________________________


                             LineSum v1.0
                             LineSum
____________________________________________________________________________
____________________________________________________________________________


2004 Shengalts Aleksander (Shengalts@mail.ru)
Thanks Afrow UK (Based on his Function "LineCount")
 
Thanks Afrow UK (Based on his idea of Function "LineCount" 2003-08-17)




Line 25: Line 23:


Syntax:
Syntax:
Push "file"   ; Input file
${LineSum} "[File]" $var
Call LineSum  ; Call function
 
Pop $var       ; Sum of lines
"[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




Example:
Example:
Section
Section
Push "C:\a.log"
${LineSum} "C:\a.log" $R0
Call LineSum
; $R0="54"
Pop $R0    ; $R0 now contain: "54"
SectionEnd*/
SectionEnd*/


;---------------------------------------------------------------------------


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 60:
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

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

/*
____________________________________________________________________________
 
                            LineSum
____________________________________________________________________________
 
Thanks Afrow UK (Based on his 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 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