From: plugwash Date: Fri, 17 Aug 2012 01:12:50 +0000 (+0000) Subject: make readtxt2 work with pipes X-Git-Url: http://www.lcore.org/git/lcore.git/commitdiff_plain/a0c30435e596b1c65a89113c1bbcef1320876336 make readtxt2 work with pipes git-svn-id: file:///svnroot/lcore/trunk@120 b1de8a11-f9be-4011-bde0-cc7ace90066a --- 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;