Code: Select all
;=========== TEST file start ====================================================
If CreateFile(0, "c:\test.txt")
sLine.s = "abcdefghijklmnopqrstuvwxyz and that is all the letters I can think of"
ilen.i = Len(sLine)
For i = 1 To 31234
WriteStringN(0,sLine)
Next
FlushFileBuffers(0)
CloseFile(0)
EndIf
;=========== TEST file End =====================================================
Procedure.i CountFileLines(sFile.s)
;----------------------------------
Protected filesize.i = 0
EnableASM
If ReadFile(0,sFile)
*loc = AllocateMemory(Lof(0))
ReadData(0, *loc, Lof(0))
filesize = Lof(0)
CloseFile(0)
EndIf
cnt = 0
!xor ecx, ecx ; linecount = 0
!mov edx, [p.p_loc] ; readpointer = *loc
!mov eax, [p.v_filesize] ; remainingbytes = filesize
!loopstart: ; While remainingbytes > 0
!cmp word [edx], 0xA0D ; If word at readpointer <> #CRLF$
!jnz skip ; GOTO skip
!inc ecx ; Else, increment the linecount
!skip: ;
!inc edx ; readpointer + 1
!dec eax ; remainingbytes - 1
!jnz loopstart ; Wend
!mov [p.v_cnt], eax
DisableASM
FreeMemory(*loc)
ProcedureReturn
EndProcedure
LineCnt.i = CountFileLines("c:\test.txt")
MessageRequester("", Str(LineCnt) + " lines reported")