LineRead: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Adding new author and category links.) |
Instructor (talk | contribs) 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 function used without header | 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 idea of Function "ReadFileLine") | |||
Thanks Afrow UK (Based on his idea of Function "ReadFileLine" | |||
Line 37: | Line 37: | ||
-Error flag if input file isn't exists | -Error flag if input file isn't exists | ||
-Error flag if line number not found | -Error flag if line number not found | ||
</highlight-nsis> | |||
Example: | <b>Example:</b> | ||
Section | <highlight-nsis>Section | ||
${LineRead} "C:\a.log" "-1" $R0 | ${LineRead} "C:\a.log" "-1" $R0 | ||
; $R0="Last line$\r$\n" | ; $R0="Last line$\r$\n" | ||
SectionEnd | SectionEnd | ||
</highlight-nsis> | |||
== The Function Code== | |||
<highlight-nsis> | |||
Function LineRead | Function LineRead | ||
!define LineRead `!insertmacro LineReadCall` | !define LineRead `!insertmacro LineReadCall` |
Revision as of 14:23, 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
____________________________________________________________________________ LineRead v1.2 ____________________________________________________________________________ Thanks Afrow UK (Based on his idea of Function "ReadFileLine") Get line in file specified with number. Syntax: ${LineRead} "[File]" "[LineNumber]" $var "[File]" ; Input text file ; "[LineNumber]" ; [No|-No] ; 3 line number from start ; -5 line number from end ; $var ; Result: Line Note: -Error flag if input file isn't exists -Error flag if line number not found
Example:
Section ${LineRead} "C:\a.log" "-1" $R0 ; $R0="Last line$\r$\n" SectionEnd
The Function Code
Function LineRead !define LineRead `!insertmacro LineReadCall` !macro LineReadCall _FILE _NUMBER _RESULT Push `${_FILE}` Push `${_NUMBER}` Call LineRead Pop ${_RESULT} !macroend Exch $1 Exch Exch $0 Exch Push $2 Push $3 Push $4 ClearErrors IfFileExists $0 0 error IntOp $1 $1 + 0 IntCmp $1 0 error 0 plus StrCpy $4 0 FileOpen $2 $0 r IfErrors error FileRead $2 $3 IfErrors +3 IntOp $4 $4 + 1 Goto -3 FileClose $2 IntOp $1 $4 + $1 IntOp $1 $1 + 1 IntCmp $1 0 error error plus: FileOpen $2 $0 r IfErrors error StrCpy $3 0 IntOp $3 $3 + 1 FileRead $2 $0 IfErrors +4 StrCmp $3 $1 0 -3 FileClose $2 goto end FileClose $2 error: SetErrors StrCpy $0 '' end: Pop $4 Pop $3 Pop $2 Pop $1 Exch $0 FunctionEnd