diff options
author | Erich Eckner <git@eckner.net> | 2015-11-18 20:39:22 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2015-11-19 08:34:59 +0100 |
commit | 5628995719e0c825b3e163c4f3e69a9515d5849c (patch) | |
tree | b3d6535c4f09c6527e4696821655b227662ee76d /mystringlistunit.pas | |
parent | 421750275f6e81adda2833b0aeb57abbad817538 (diff) | |
download | units-5628995719e0c825b3e163c4f3e69a9515d5849c.tar.xz |
mystringlistunit.pas verwendet jetzt fileunit.pas
Diffstat (limited to 'mystringlistunit.pas')
-rw-r--r-- | mystringlistunit.pas | 134 |
1 files changed, 17 insertions, 117 deletions
diff --git a/mystringlistunit.pas b/mystringlistunit.pas index e6fc565..96ba264 100644 --- a/mystringlistunit.pas +++ b/mystringlistunit.pas @@ -8,17 +8,6 @@ uses Classes, SysUtils, RegExpr, Process, protokollunit; type - tMyStringlist = class; - - tInputThread = class (tThread) - fertig: boolean; - inhalt: tMyStringList; - proc: tProcess; - constructor create(p: tProcess; sl: tMyStringList); - destructor destroy; override; - procedure execute; override; - end; - tMyStringlist = class (tStringlist) private line: longint; @@ -40,44 +29,11 @@ type end; procedure _del(var s: string; p,c: longint); inline; // identisch zu delete(s,p,c) -- lediglich um delete innerhalb von tMyStringlist verfügbar zu haben +procedure _mov(const source;var dest;count:SizeInt); implementation -uses Math, lowlevelunit, systemunit; - -// tInputThread **************************************************************** - -constructor tInputThread.create(p: tProcess; sl: tMyStringList); -begin - inherited create(true); - fertig:=false; - inhalt:=sl; - proc:=p; - suspended:=false; -end; - -destructor tInputThread.destroy; -begin - inhalt:=nil; - proc:=nil; - inherited destroy; -end; - -procedure tInputThread.execute; -var - wb,cwb: longint; -begin - wb:=0; - while wb<length(inhalt.text) do begin - cwb:=proc.input.write(inhalt.text[wb+1],length(inhalt.text)-wb); - if cwb=0 then - sleep(1) - else - wb:=wb+cwb; - end; - proc.CloseInput; - fertig:=true; -end; +uses Math, lowlevelunit, systemunit, fileUnit; // tMyStringlist *************************************************************** @@ -110,40 +66,18 @@ begin end; procedure tMyStringlist.loadFromGz(const s: ansiString); -var p: tProcess; - buf: ansiString; - rb,br: longint; +var + len: longint; + pt: pointer; + buf: ansistring; begin - p:=tProcess.create(nil); - p.executable:='zcat'; - p.parameters.add(s); - p.options:=p.options + [poUsePipes]; - setlength(buf,0); - br:=0; - p.execute; - while p.running do begin - rb:=p.output.numBytesAvailable; - if rb>0 then begin - if length(buf)<br+rb then - setlength(buf,br+rb+1048576); - rb:=p.output.read(buf[br+1],rb); - br:=br+rb; - end - else sleep(1); - end; - setlength(buf,br); - rb:=p.output.numBytesAvailable; - while rb>0 do begin - setlength(buf,br+rb); - rb:=p.output.read(buf[br+1],rb); - br:=br+rb; - rb:=p.output.numBytesAvailable; - end; + fileunit.loadFromGz(s,pt,len); + setlength(buf,len); + _mov(pt^,buf[1],len); text:=buf; setlength(buf,0); - p.free; - for rb:=0 to count-1 do - self[rb]:=trim(self[rb]); + for len:=0 to count-1 do + self[len]:=trim(self[len]); line:=0; if assigned(prot) then prot.schreibe(inttostr(count)+' Zeilen eingelesen') @@ -152,47 +86,8 @@ begin end; procedure tMyStringlist.saveToGz(const s: ansiString); -var - p: tProcess; - buf: array of byte; - f: file; - rb: longint; - it: tInputThread; - datNam: string; -const - outBufLen = 1024*1024; begin - if fileexists(s) then - datNam:=mkTemp(s+'.XXXXXX') - else - datNam:=s; - p:=tProcess.create(nil); - p.executable:='gzip'; - p.parameters.add('--best'); - p.parameters.add('-c'); - p.options:=p.options + [poUsePipes]; - p.execute; - setlength(buf,outBufLen); - fillchar(buf[0],length(buf)*sizeof(buf[0]),$0); - it:=tInputThread.create(p,self); - assignfile(f,datNam); - rewrite(f,1); - while p.running or (not it.fertig) or (p.output.numBytesAvailable>0) do begin - rb:=min(length(buf),p.output.numBytesAvailable); - if rb>0 then begin - rb:=p.output.read(buf[0],rb); - blockwrite(f,buf[0],rb); - end - else - sleep(1); // nix zu Schreiben, nix zu Lesen, also warten wir - end; - p.free; - it.free; - closefile(f); - if s<>datNam then begin - deleteFile(s); - rename(f,s); - end; + fileunit.saveToGz(s,@(text[1]),length(text)); end; function tMyStringlist.readln(out s: string): boolean; @@ -481,5 +376,10 @@ begin delete(s,p,c); end; +procedure _mov(const source;var dest;count:SizeInt); +begin + move(source,dest,count); +end; + end. |