X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/b3b93191002f92b19c069b9815a8261d6edbc5ec..a0c30435e596b1c65a89113c1bbcef1320876336:/readtxt2.pas

diff --git a/readtxt2.pas b/readtxt2.pas
index ee65736..12bea5a 100644
--- a/readtxt2.pas
+++ b/readtxt2.pas
@@ -44,6 +44,7 @@ type
     currenteol,preveol:integer;
     fileeof,reachedeof:boolean;
     eoltype:integer;
+    procedure checkandread;
   end;
 
 implementation
@@ -54,7 +55,7 @@ begin
   sourcestream := asourcestream;
   destroysourcestream := adestroysourcestream;
 
-  if sourcestream.Position >= sourcestream.size then fileeof := true;
+  //if sourcestream.Position >= sourcestream.size then fileeof := true;
   bufpointer := bufsize;
 end;
 
@@ -64,6 +65,16 @@ begin
 end;
 
 
+procedure treadtxt.checkandread;
+begin
+  if bufpointer >= numread then begin
+    numread := sourcestream.read(buf,bufsize);
+    bufpointer := 0;
+    if numread = 0 then fileeof := true;
+      
+  end;
+end;
+
 function treadtxt.readline;
 var
   a,b,c,d:integer;
@@ -71,11 +82,7 @@ begin
 
   result := '';
   repeat
-    if bufpointer >= bufsize then begin
-      numread := sourcestream.read(buf,bufsize);
-      bufpointer := 0;
-      if sourcestream.Position >= sourcestream.size then fileeof := true;
-    end;
+    checkandread;
     b := numread-1;
 
     {core search loop begin}
@@ -96,7 +103,8 @@ begin
       setlength(result,c+b);
       move(buf[bufpointer],result[c+1],b);
       bufpointer := numread;
-      if numread < bufsize then begin
+      if fileeof then begin
+        {we reached the end of the file, return what we have}
         reachedeof := true;
         exit;
       end;
@@ -133,8 +141,8 @@ end;
 
 function treadtxt.eof:boolean;
 begin
-
-  result := ((bufpointer >= bufsize) and fileeof) or reachedeof;
+  checkandread;
+  result := ((bufpointer >= numread) and fileeof) or reachedeof;
 end;
 
 destructor treadtxt.destroy;