unit fileunit; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Math; type tInputfile = class private zeile: longint; zeilen: tStringlist; public procedure anAnfang; function gibZeile(out s: string): boolean; function einlesen(fnam: string): boolean; function brauchenoch(bez: string): boolean; constructor create; destructor destroy; override; end; implementation uses typenunit; procedure tInputfile.anAnfang; begin zeile:=0; end; function tInputfile.gibZeile(out s: string): boolean; begin result:=false; if (zeile<0) or (zeile>=zeilen.count) then exit; s:=zeilen[zeile]; result:=true; inc(zeile); end; function tInputfile.einlesen(fnam: string): boolean; var f: textfile; i,j,k,l,Ebene: longint; s,t,u,v: string; SchleifenInhalt: tStringlist; istWahr,gefunden: boolean; const binops: array[0..8] of string = ('<=','>=','<>','≤','≥','=','≠','<','>'); begin result:=false; assignfile(f,fnam); reset(f); zeilen.clear; while not eof(f) do begin readln(f,s); zeilen.add(s); end; closefile(f); zeile:=0; i:=0; while i'$') then exit; SchleifenInhalt:=TStringlist.create; Ebene:=0; while (i0) or (zeilen[i]<>'!Schleifenende')) do begin SchleifenInhalt.Add(zeilen[i]); if zeilen[i]='!Schleifenende' then dec(Ebene); if pos('!Schleife:',zeilen[i])=1 then inc(Ebene); zeilen.delete(i); end; zeilen.delete(i); while length(s)>0 do begin u:=erstesArgument(s); for j:=0 to SchleifenInhalt.Count-1 do begin v:=SchleifenInhalt[j]; k:=length(v); while (pos(t,v)>0) and (k>0) do begin v:=copy(v,1,pos(t,v)-1)+u+copy(v,pos(t,v)+length(t),length(v)); dec(k); end; zeilen.insert(i,v); inc(i); end; end; SchleifenInhalt.Free; i:=l; continue; end; zeilen[i]:=s; inc(i); end; i:=0; while i0 then begin gefunden:=true; u:=trim(copy(t,1,pos(binops[j],t)-1)); delete(t,1,pos(binops[j],t)+length(binops[j])-1); t:=trim(t); case binops[j] of '≤','<=': istWahr:=strtofloat(u)<=strtofloat(t); '≥','>=': istWahr:=strtofloat(u)>=strtofloat(t); '=': try istWahr:=strtofloat(u)=strtofloat(t); except istWahr:=u=t; end; '≠','<>': try istWahr:=strtofloat(u)<>strtofloat(t); except istWahr:=u<>t; end; '<': istWahr:=strtofloat(u)': istWahr:=strtofloat(u)>strtofloat(t); else begin gibAus('Operator '''+binops[j]+''' ist nicht implementiert!',3); exit; end; end{of case}; if not istWahr then zeilen.delete(i); break; end; if not gefunden then begin gibAus('Ich kann keinen gültigen Operator in Bedingung '''+t+''' finden!',3); exit; end; if not istWahr then continue; zeilen[i]:=s; end; inc(i); end; i:=0; while i0 do begin t:=copy(s,1,pos(bez,s)+length(bez)); delete(s,1,pos(bez,s)+length(bez)-1); delete(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; end; constructor tInputfile.create; begin inherited create; zeilen:=tStringlist.create; zeile:=0; end; destructor tInputfile.destroy; begin zeilen.free; inherited destroy; end; end.