diff options
author | Erich Eckner <git@eckner.net> | 2016-03-10 13:58:48 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2016-03-15 13:01:16 +0100 |
commit | 671edf5cd4e3d6ed645cae071e252fac45bcce7b (patch) | |
tree | 4ebce129d25884de0879965653fe9e7b7b671e4c | |
parent | 80946c08e4ecc4b26cc5ca5f8aa31efc30ae4fd9 (diff) | |
download | units-671edf5cd4e3d6ed645cae071e252fac45bcce7b.tar.xz |
shellExpand neu in systemunit.pas
-rw-r--r-- | systemunit.pas | 100 |
1 files changed, 98 insertions, 2 deletions
diff --git a/systemunit.pas b/systemunit.pas index d4ec24b..5341b39 100644 --- a/systemunit.pas +++ b/systemunit.pas @@ -5,7 +5,7 @@ unit systemunit; interface uses - Classes, SysUtils, Math; + Classes, SysUtils, Math, lowlevelunit, mystringlistunit; function cpuUtilization: extended; function numCpus: int64; @@ -13,13 +13,16 @@ function momentanFreieCpus: int64; function belegterSpeicher: int64; function minCache: int64; function shellSubst(s: string): string; +function shellExpand(s: string): string; overload; +procedure shellExpand(s: string; out sa: tMyStringList); overload; +procedure shellExpand(var sa: tMyStringList); overload; function mkTemp(s: string): string; function myReadLink(s: string): string; implementation uses - process, lowlevelunit; + process; var _cpuLastUsed,_cpuLastIdle: int64; @@ -125,6 +128,99 @@ begin end; end; +function shellExpand(s: string): string; +var + sa: tMyStringList; + i: longint; +begin + shellExpand(s,sa); + result:=''; + for i:=0 to sa.count-1 do + result:=result+sa[i]+' '; + delete(result,length(result),1); + sa.free; +end; + +procedure shellExpand(s: string; out sa: tMyStringList); +begin + sa:=tMyStringList.create; + while s<>'' do + sa.add(erstesArgument(s)); + shellExpand(sa); +end; + +procedure shellExpand(var sa: tMyStringList); +var + start,ende,s: string; + i,j,ebene,iStart,iStopp,insOff: longint; +begin + i:=0; + while i<sa.count do + if pos('{',sa[i])>0 then begin + s:=sa[i]; + start:=erstesArgument(s,'{',false); + j:=1; + ebene:=0; + while (j<=length(s)) and ((s[j]<>'}') or (ebene>0)) do begin + case s[j] of + '{': inc(ebene); + '}': dec(ebene); + end{of case}; + inc(j); + end; + if (ebene<>0) or (j>length(s)) then + fehler('Geschweifte Klammern sind in '''+sa[i]+''' nicht ausgewogen!'); + + ende:=rightStr(s,length(s)-j); + s:=leftStr(s,j-1)+','; + + sa.delete(i); + + iStart:=low(longint); + insOff:=0; + j:=1; + ebene:=0; + while (j<=length(s)) do begin + case s[j] of + '{': inc(ebene); + '}': dec(ebene); + '.': + if (ebene=0) and (copy(s,j,2)='..') then begin + if iStart<>low(longint) then + fehler('''..'' darf nicht mehrmals hintereinander auftauchen - in '''+sa[i]+''' ist das aber der Fall!'); + iStart:=strtoint(trim(leftStr(s,j-1))); + delete(s,1,j+1); + j:=1; + continue; + end; + ',': + if ebene=0 then begin + if iStart=low(longint) then begin // keine Zähliteration + sa.insert(i+insOff,start+leftStr(s,j-1)+ende); + inc(insOff); + delete(s,1,j); + j:=1; + continue; + end + else begin // eine Zähliteration + iStopp:=strtoint(trim(leftStr(s,j-1))); + delete(s,1,j); + for j:=iStart to iStopp do + sa.insert(i+insOff+j-iStart,start+inttostr(j)+ende); + inc(insOff,iStopp-iStart+1); + iStart:=low(longint); + j:=1; + continue; + end; + end; + end{of case}; + inc(j); + end; + end + else + inc(i); +end; + function mkTemp(s: string): string; var args: array of string; |