diff options
Diffstat (limited to 'mystringlistunit.pas')
-rw-r--r-- | mystringlistunit.pas | 210 |
1 files changed, 145 insertions, 65 deletions
diff --git a/mystringlistunit.pas b/mystringlistunit.pas index 96ba264..7483e36 100644 --- a/mystringlistunit.pas +++ b/mystringlistunit.pas @@ -8,28 +8,35 @@ uses Classes, SysUtils, RegExpr, Process, protokollunit; type - tMyStringlist = class (tStringlist) + tMyStringList = class (tStringList) private - line: longint; - prot: tProtokollant; + line: longint; + prot: tProtokollant; + srNoGo,srBuff: tMyStringList; // Liste der in SubRoutinen verbotenen Zeilenanfänge, sowie der aufgeschobenen Zeilen public constructor create; overload; constructor create(protokollant: tProtokollant; name: string); overload; + destructor destroy; override; procedure loadFromFile(const s: ansiString); override; procedure loadFromGz(const s: ansiString); procedure saveToGz(const s: ansiString); - function readln(out s: string): boolean; + function readln(out s: string): boolean; inline; + function metaReadln(out s: string; subRoutine: boolean): boolean; inline; procedure grep(expr: string); + function hatZeile(zeile: string): boolean; // invers zu "grep -c" function eof: boolean; procedure rewind; function stillNeed(bez: string): boolean; + function needInLine(bez: string; lin: longint): boolean; + procedure insert(index: longint; const s: ansistring); override; function unfoldMacros: boolean; procedure subst(regex,ersatz: string); procedure dump(pro: tProtokollant; prefix: string); + procedure nichtInSubRoutine(s: string); 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); +procedure _mov(const source;var dest;count:SizeInt); // identisch zu move(source,dest,count) -- lediglich um move innerhalb von tMyStringlist verfügbar zu haben implementation @@ -39,30 +46,40 @@ uses Math, lowlevelunit, systemunit, fileUnit; constructor tMyStringlist.create; begin - create(nil,''); + create(nil,''); end; constructor tMyStringlist.create(protokollant: tProtokollant; name: string); begin - inherited create; - if assigned(protokollant) then - prot:=tProtokollant.create(protokollant,name) - else - prot:=nil; - line:=0; + inherited create; + if assigned(protokollant) then + prot:=tProtokollant.create(protokollant,name) + else + prot:=nil; + srNoGo:=nil; + srBuff:=nil; + line:=0; +end; + +destructor tMyStringlist.destroy; +begin + srNoGo.free; + srBuff.free; + inherited destroy; end; procedure tMyStringlist.loadFromFile(const s: ansiString); -var i: longint; +var + i: longint; begin - inherited loadFromFile(s); - for i:=0 to count-1 do - self[i]:=trim(self[i]); - line:=0; - if assigned(prot) then - prot.schreibe(inttostr(count)+' Zeilen eingelesen') - else - gibAus(inttostr(count)+' Zeilen eingelesen',1); + inherited loadFromFile(s); + for i:=0 to count-1 do + self[i]:=trim(self[i]); + line:=0; + if assigned(prot) then + prot.schreibe(inttostr(count)+' Zeilen eingelesen') + else + gibAus(inttostr(count)+' Zeilen eingelesen',1); end; procedure tMyStringlist.loadFromGz(const s: ansiString); @@ -71,34 +88,54 @@ var pt: pointer; buf: ansistring; begin - fileunit.loadFromGz(s,pt,len); - setlength(buf,len); - _mov(pt^,buf[1],len); - text:=buf; - setlength(buf,0); - for len:=0 to count-1 do - self[len]:=trim(self[len]); - line:=0; - if assigned(prot) then - prot.schreibe(inttostr(count)+' Zeilen eingelesen') - else - gibAus(inttostr(count)+' Zeilen eingelesen',1); + fileunit.loadFromGz(s,pt,len); + setlength(buf,len); + _mov(pt^,buf[1],len); + text:=buf; + setlength(buf,0); + for len:=0 to count-1 do + self[len]:=trim(self[len]); + line:=0; + if assigned(prot) then + prot.schreibe(inttostr(count)+' Zeilen eingelesen') + else + gibAus(inttostr(count)+' Zeilen eingelesen',1); end; procedure tMyStringlist.saveToGz(const s: ansiString); begin - fileunit.saveToGz(s,@(text[1]),length(text)); + fileunit.saveToGz(s,@(text[1]),length(text)); end; function tMyStringlist.readln(out s: string): boolean; begin - result:=not eof; - if not result then begin - s:=''; - exit; - end; - s:=self[line]; - inc(line); + result:=not eof; + if not result then begin + s:=''; + exit; + end; + s:=self[line]; + inc(line); +end; + +function tMyStringlist.metaReadln(out s: string; subRoutine: boolean): boolean; +begin + if assigned(srNoGo) then begin + if subRoutine then begin + repeat + result:=readln(s); + if not srNoGo.hatZeile(s) then exit; + srBuff.add(s); + until false; + end + else if srBuff.count>0 then begin + result:=true; + s:=srBuff[0]; + srBuff.delete(0); + exit; + end; + end; + result:=readln(s); end; procedure tMyStringlist.grep(expr: string); @@ -107,48 +144,82 @@ var i: longint; begin re:=tRegExpr.create; - re.Expression:=expr; + re.expression:=expr; for i:=count-1 downto 0 do - if not re.Exec(self[i]) then + if not re.exec(self[i]) then delete(i); re.free; end; +function tMyStringlist.hatZeile(zeile: string): boolean; +var + re: tRegExpr; + i: longint; +begin + re:=tRegExpr.create; + result:=true; + for i:=0 to count-1 do begin + re.expression:=self[i]; + if re.exec(zeile) then begin + re.free; + exit; + end; + end; + re.free; + result:=false; +end; + function tMyStringlist.eof: boolean; begin - result:=line>=count; + result:=line>=count; end; procedure tMyStringlist.rewind; begin - line:=0; + line:=0; end; function tMyStringlist.stillNeed(bez: string): boolean; -var i: longint; - s,t: string; +var + i: longint; begin + result:=true; + for i:=max(0,line-1) to count-1 do + if needInLine(bez,i) then + exit; result:=false; - for i:=max(0,line-1) to count-1 do begin - s:=' '+self[i]+' '; - while pos(bez,s)>0 do begin - t:=copy(s,1,pos(bez,s)+length(bez)); - _del(s,1,pos(bez,s)+length(bez)-1); - _del(t,1,length(t)-length(bez)-2); - if (t[1] in [' ',#9,':','[']) and (t[length(t)] in [' ',#9,':',']']) and (copy(t,2,length(bez))=bez) then begin - result:=true; - exit; - end; - end; +end; + +function tMyStringlist.needInLine(bez: string; lin: longint): boolean; +var + s,t: string; +begin + result:=true; + s:=' '+self[lin]+' '; + while pos(bez,s)>0 do begin + t:=copy(s,1,pos(bez,s)+length(bez)); + _del(s,1,pos(bez,s)+length(bez)-1); + _del(t,1,length(t)-length(bez)-2); + if (t[1] in [' ',#9,':','[']) and (t[length(t)] in [' ',#9,':',']']) and (copy(t,2,length(bez))=bez) then + exit; end; + result:=false; +end; + +procedure tMyStringlist.insert(index: longint; const s: ansistring); +begin + inherited insert(index,s); + if index<=line then inc(line); end; function tMyStringlist.unfoldMacros: boolean; -var i,j,k,l,Ebene: longint; - s,t,u,v: string; - SchleifenInhalt: tMyStringlist; - istWahr,gefunden,wasGefunden: boolean; -const binops: array[0..12] of string = +var + i,j,k,l,Ebene: longint; + s,t,u,v: string; + SchleifenInhalt: tMyStringlist; + istWahr,gefunden,wasGefunden: boolean; +const + binops: array[0..12] of string = ('<=','>=','<>','≤','≥','=','≠','<','>','in','∈','notIn','∉'); begin result:=false; @@ -369,16 +440,25 @@ begin pro.schreibe(prefix+self[i]); end; +procedure tMyStringList.nichtInSubRoutine(s: string); +begin + if not assigned(srNoGo) then begin + srNoGo:=tMyStringList.create; + srBuff:=tMyStringList.create; + end; + srNoGo.add(s); +end; + // allgemeine Funktionen ******************************************************* procedure _del(var s: string; p,c: longint); begin - delete(s,p,c); + delete(s,p,c); end; procedure _mov(const source;var dest;count:SizeInt); begin - move(source,dest,count); + move(source,dest,count); end; end. |