summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2017-07-18 09:24:33 +0200
committerErich Eckner <git@eckner.net>2017-07-18 09:24:33 +0200
commit5455777a06c449be92a2090f00cb63f748e05a5c (patch)
treee65214ad3f388c7682b1bd85bd11207b9dd5a4e8
parenta7c625c353ff06fe6c757d710ee75c02d882273d (diff)
downloadunits-5455777a06c449be92a2090f00cb63f748e05a5c.tar.xz
mystringlistunit.pas: istDasBefehl neu
-rw-r--r--mystringlistunit.pas137
1 files changed, 75 insertions, 62 deletions
diff --git a/mystringlistunit.pas b/mystringlistunit.pas
index e3c54fe..48bde05 100644
--- a/mystringlistunit.pas
+++ b/mystringlistunit.pas
@@ -36,7 +36,7 @@ type
procedure stepBack;
function stillNeed(bez: string): boolean;
function needInLine(bez: string; lin: longint): boolean;
- procedure insert(index: longint; const s: ansistring); override;
+ procedure insert(index: longint; const s: ansiString); override;
function unfoldMacros(kvs: tKnownValues = nil; cbgv: tCallBackGetValue = nil): boolean;
procedure subst(regex,ersatz: string);
procedure dump(pro: tProtokollant; prefix: string);
@@ -44,22 +44,23 @@ type
procedure addWithLineBreaks(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); // identisch zu move(source,dest,count) -- lediglich um move innerhalb von tMyStringlist verfügbar zu haben
+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); // identisch zu move(source,dest,count) -- lediglich um move innerhalb von tMyStringList verfügbar zu haben
function numerischerVergleich(list: tStringList; index1,index2: integer): integer;
+function istDasBefehl(befehl: string; var s: string; var bekannteBefehle: tMyStringList; hatParameter: boolean): boolean;
implementation
uses Math, lowlevelunit, systemunit, fileUnit;
-// tMyStringlist ***************************************************************
+// tMyStringList ***************************************************************
-constructor tMyStringlist.create;
+constructor tMyStringList.create;
begin
create(nil,'');
end;
-constructor tMyStringlist.create(protokollant: tProtokollant; name: string);
+constructor tMyStringList.create(protokollant: tProtokollant; name: string);
begin
inherited create;
if assigned(protokollant) then
@@ -71,14 +72,14 @@ begin
line:=0;
end;
-destructor tMyStringlist.destroy;
+destructor tMyStringList.destroy;
begin
srNoGo.free;
srBuff.free;
inherited destroy;
end;
-procedure tMyStringlist.gibAus(s: string; ausgaben: byte);
+procedure tMyStringList.gibAus(s: string; ausgaben: byte);
begin
if assigned(prot) then
prot.schreibe(s,odd(ausgaben shr 1))
@@ -86,7 +87,7 @@ begin
lowlevelunit.gibAus(s,ausgaben);
end;
-procedure tMyStringlist.loadFromFile(const s: ansiString);
+procedure tMyStringList.loadFromFile(const s: ansiString);
var
i: longint;
begin
@@ -94,31 +95,31 @@ begin
for i:=0 to count-1 do
self[i]:=trim(self[i]);
line:=0;
- gibAus(inttostr(count)+' Zeilen eingelesen',1);
+ gibAus(intToStr(count)+' Zeilen eingelesen',1);
end;
-procedure tMyStringlist.loadFromGz(const s: ansiString);
+procedure tMyStringList.loadFromGz(const s: ansiString);
var
len: longint;
pt: pointer;
- buf: ansistring;
+ buf: ansiString;
begin
fileunit.loadFromGz(s,pt,len);
- setlength(buf,len);
+ setLength(buf,len);
_mov(pt^,buf[1],len);
text:=buf;
- setlength(buf,0);
+ setLength(buf,0);
for len:=0 to count-1 do
self[len]:=trim(self[len]);
line:=0;
- gibAus(inttostr(count)+' Zeilen eingelesen',1);
+ gibAus(intToStr(count)+' Zeilen eingelesen',1);
end;
-procedure tMyStringlist.loadFromPipe(s: ansiString);
+procedure tMyStringList.loadFromPipe(s: ansiString);
var
len: longint;
pt: pointer;
- buf: ansistring;
+ buf: ansiString;
pr: tProcess;
begin
while max(pos(#13,s),pos(#10,s))>0 do
@@ -128,24 +129,24 @@ begin
while s<>'' do
pr.parameters.add(erstesArgument(s));
fileunit.loadFromProcess(pr,pt,len);
- setlength(buf,len);
+ setLength(buf,len);
_mov(pt^,buf[1],len);
text:=buf;
- setlength(buf,0);
+ setLength(buf,0);
for len:=0 to count-1 do
self[len]:=trim(self[len]);
line:=0;
- gibAus(inttostr(count)+' Zeilen eingelesen',1);
+ gibAus(intToStr(count)+' Zeilen eingelesen',1);
end;
-procedure tMyStringlist.loadFromResource(const s: ansiString);
+procedure tMyStringList.loadFromResource(const s: ansiString);
var
st: tResourceStream;
- buf: ansistring;
+ buf: ansiString;
i: longint;
begin
st:=tResourceStream.create(hInstance,s,RT_RCDATA);
- setlength(buf,st.size);
+ setLength(buf,st.size);
st.readBuffer(buf[1],length(buf));
st.free;
text:=buf;
@@ -153,12 +154,12 @@ begin
self[i]:=trim(self[i]);
end;
-procedure tMyStringlist.saveToGz(const s: ansiString);
+procedure tMyStringList.saveToGz(const s: ansiString);
begin
fileunit.saveToGz(s,@(text[1]),length(text));
end;
-function tMyStringlist.readln(out s: string): boolean;
+function tMyStringList.readln(out s: string): boolean;
begin
result:=not eof;
if not result then begin
@@ -169,7 +170,7 @@ begin
inc(line);
end;
-function tMyStringlist.metaReadln(out s: string; subRoutine: boolean): boolean;
+function tMyStringList.metaReadln(out s: string; subRoutine: boolean): boolean;
begin
if assigned(srNoGo) then begin
if subRoutine then begin
@@ -189,7 +190,7 @@ begin
result:=readln(s);
end;
-procedure tMyStringlist.grep(expr: string; invert: boolean);
+procedure tMyStringList.grep(expr: string; invert: boolean);
var
tl: tMyStringList;
re: tRegExpr;
@@ -212,7 +213,7 @@ begin
tl.free;
end;
-function tMyStringlist.grepFirst(expr: string): string;
+function tMyStringList.grepFirst(expr: string): string;
var
re: tRegExpr;
i: longint;
@@ -229,7 +230,7 @@ begin
result:='';
end;
-procedure tMyStringlist.replace(von,nach: string);
+procedure tMyStringList.replace(von,nach: string);
var
tl: tMyStringList;
re: tRegExpr;
@@ -248,7 +249,7 @@ begin
tl.free;
end;
-procedure tMyStringlist.uniq(c: char);
+procedure tMyStringList.uniq(c: char);
var
i: longint;
tl: tMyStringList;
@@ -288,7 +289,7 @@ begin
tl.free;
end;
-procedure tMyStringlist.append(sl: tMyStringList);
+procedure tMyStringList.append(sl: tMyStringList);
var
i: longint;
begin
@@ -296,7 +297,7 @@ begin
add(sl[i]);
end;
-function tMyStringlist.hatZeile(zeile: string): boolean;
+function tMyStringList.hatZeile(zeile: string): boolean;
var
re: tRegExpr;
i: longint;
@@ -314,23 +315,23 @@ begin
result:=false;
end;
-function tMyStringlist.eof: boolean;
+function tMyStringList.eof: boolean;
begin
result:=line>=count;
end;
-procedure tMyStringlist.rewind;
+procedure tMyStringList.rewind;
begin
line:=0;
end;
-procedure tMyStringlist.stepBack;
+procedure tMyStringList.stepBack;
begin
dec(line);
if line<0 then line:=0;
end;
-function tMyStringlist.stillNeed(bez: string): boolean;
+function tMyStringList.stillNeed(bez: string): boolean;
var
i: longint;
begin
@@ -341,7 +342,7 @@ begin
result:=false;
end;
-function tMyStringlist.needInLine(bez: string; lin: longint): boolean;
+function tMyStringList.needInLine(bez: string; lin: longint): boolean;
var
s,t: string;
begin
@@ -357,17 +358,17 @@ begin
result:=false;
end;
-procedure tMyStringlist.insert(index: longint; const s: ansistring);
+procedure tMyStringList.insert(index: longint; const s: ansiString);
begin
inherited insert(index,s);
if index<=line then inc(line);
end;
-function tMyStringlist.unfoldMacros(kvs: tKnownValues; cbgv: tCallBackGetValue): boolean;
+function tMyStringList.unfoldMacros(kvs: tKnownValues; cbgv: tCallBackGetValue): boolean;
var
- i,j,k,l,Ebene: longint;
+ i,j,k,l,ebene: longint;
s,t,u,v: string;
- SchleifenInhalt: tMyStringlist;
+ schleifenInhalt: tMyStringList;
wasGefunden: boolean;
const
kommentarKlammern: array[0..2,boolean] of string = (
@@ -394,16 +395,16 @@ begin
while i<count do begin // mehrzeilige Kommentare löschen
for j:=0 to length(kommentarKlammern)-1 do
if self[i]=kommentarKlammern[j,false] then begin
- Ebene:=0;
+ ebene:=0;
delete(i);
- while (i<count) and (Ebene>=0) do begin
+ while (i<count) and (ebene>=0) do begin
if self[i]=kommentarKlammern[j,false] then
- inc(Ebene);
+ inc(ebene);
if self[i]=kommentarKlammern[j,true] then
- dec(Ebene);
+ dec(ebene);
delete(i);
end;
- if Ebene>=0 then begin
+ if ebene>=0 then begin
gibAus('Klammern '''+kommentarKlammern[j,false]+'''-'''+kommentarKlammern[j,true]+''' nicht ausgeglichen!',3);
exit;
end;
@@ -438,7 +439,7 @@ begin
while i<count do begin // Übersprünge überspringen, alles nach 'Dateiende' löschen
s:=self[i];
if startetMit('!überspringe:',s) then begin
- for j:=0 to strtoint(s) do
+ for j:=0 to strToInt(s) do
delete(i);
continue;
end;
@@ -507,19 +508,19 @@ begin
exit;
end;
- SchleifenInhalt:=tMyStringlist.create(nil,''); // Schleifenkörper merken
- Ebene:=0;
- while (i<Count) and ((Ebene<>0) or (self[i]<>'!Schleifenende')) do begin
- SchleifenInhalt.Add(self[i]);
- if self[i]='!Schleifenende' then dec(Ebene);
- if pos('!Schleife:',self[i])=1 then inc(Ebene);
+ schleifenInhalt:=tMyStringList.create(nil,''); // Schleifenkörper merken
+ ebene:=0;
+ while (i<count) and ((ebene<>0) or (self[i]<>'!Schleifenende')) do begin
+ schleifenInhalt.add(self[i]);
+ if self[i]='!Schleifenende' then dec(ebene);
+ if pos('!Schleife:',self[i])=1 then inc(ebene);
delete(i);
end;
if i>=count then begin
gibAus('Ich kann kein zugehöriges Schleifenende zu Schleife über Variable '''+t+''' finden!',3);
gibAus(' ich habe hier noch:',3);
- for i:=0 to SchleifenInhalt.count-1 do
- gibAus(SchleifenInhalt[i],3);
+ for i:=0 to schleifenInhalt.count-1 do
+ gibAus(schleifenInhalt[i],3);
exit;
end;
@@ -536,8 +537,8 @@ begin
while length(s)>0 do begin // Schleifenzähler laufen lassen
u:=unEscape(erstesArgument(s));
- for j:=0 to SchleifenInhalt.Count-1 do begin // Schleifenkörper ...
- v:=SchleifenInhalt[j];
+ for j:=0 to schleifenInhalt.count-1 do begin // Schleifenkörper ...
+ v:=schleifenInhalt[j];
k:=length(v);
while (pos(t,v)>0) and (k>0) do begin // ... nach Ersetzung ...
v:=copy(v,1,pos(t,v)-1)+u+copy(v,pos(t,v)+length(t),length(v));
@@ -548,7 +549,7 @@ begin
end;
end;
- SchleifenInhalt.free;
+ schleifenInhalt.free;
i:=l;
continue;
end;
@@ -576,7 +577,7 @@ begin
result:=true;
end;
-procedure tMyStringlist.subst(regex,ersatz: string);
+procedure tMyStringList.subst(regex,ersatz: string);
var
i,cnt: longint;
re: tRegExpr;
@@ -590,12 +591,12 @@ begin
inc(cnt);
for i:=0 to count-1 do begin
re.exec(self[i]);
- self[i]:=re.substitute('$1'+ersatz+'$'+inttostr(cnt));
+ self[i]:=re.substitute('$1'+ersatz+'$'+intToStr(cnt));
end;
re.free;
end;
-procedure tMyStringlist.dump(pro: tProtokollant; prefix: string);
+procedure tMyStringList.dump(pro: tProtokollant; prefix: string);
var
i: longint;
begin
@@ -625,7 +626,7 @@ begin
delete(s,p,c);
end;
-procedure _mov(const source;var dest;count:SizeInt);
+procedure _mov(const source;var dest;count:sizeInt);
begin
move(source,dest,count);
end;
@@ -656,5 +657,17 @@ begin
result:=result*(1-2*byte(neg));
end;
+function istDasBefehl(befehl: string; var s: string; var bekannteBefehle: tMyStringList; hatParameter: boolean): boolean;
+begin
+ if hatParameter then begin
+ bekannteBefehle.add(''''+befehl+' ...''');
+ result:=startetMit(befehl+' ',s);
+ end
+ else begin
+ bekannteBefehle.add(''''+befehl+'''');
+ result:=s=befehl;
+ end;
+end;
+
end.