summaryrefslogtreecommitdiff
path: root/systemunit.pas
diff options
context:
space:
mode:
Diffstat (limited to 'systemunit.pas')
-rw-r--r--systemunit.pas95
1 files changed, 67 insertions, 28 deletions
diff --git a/systemunit.pas b/systemunit.pas
index c99d05a..9b054ca 100644
--- a/systemunit.pas
+++ b/systemunit.pas
@@ -13,6 +13,8 @@ function momentanFreieCpus: int64;
function belegterSpeicher: int64;
function minCache: int64;
function shellSubst(s: string): string;
+function homeVerzeichnis: string; overload;
+function homeVerzeichnis(user: string): string; overload;
function shellExpand(s: string): string; overload;
procedure shellExpand(s: string; out sa: tMyStringList); overload;
procedure shellExpand(var sa: tMyStringList); overload;
@@ -84,17 +86,18 @@ var
f: textFile;
s: string;
begin
- s:='/proc/'+intToStr(getProcessId)+'/smaps';
- result:=0;
- if not fileExists(s) then exit;
- assignFile(f,s);
- reset(f);
- while not eof(f) do begin
- readln(f,s);
- if startetMit('Rss:',s) and (endetMit('kB',s) or endetMit('KB',s)) then
- result:=result+strToInt(s);
- end;
- closeFile(f);
+ s:='/proc/'+intToStr(getProcessId)+'/smaps';
+ result:=0;
+ if not fileExists(s) then
+ exit;
+ assignFile(f,s);
+ reset(f);
+ while not eof(f) do begin
+ readln(f,s);
+ if startetMit('Rss:',s) and (endetMit('kB',s) or endetMit('KB',s)) then
+ result:=result+strToInt(s);
+ end;
+ closeFile(f);
end;
function minCache: int64;
@@ -102,19 +105,21 @@ var
f: textFile;
s: string;
begin
- s:='/proc/cpuinfo';
- result:=0;
- if not fileExists(s) then exit;
- assignFile(f,s);
- reset(f);
- while not eof(f) do begin
- readln(f,s);
- if startetMit('cache',s) and startetMit('size',s) and startetMit(':',s) and (endetMit('KB',s) or endetMit('kB',s)) then begin
- if result=0 then result:=strToInt(s)
- else result:=min(result,strToInt(s));
- end;
- end;
- closeFile(f);
+ s:='/proc/cpuinfo';
+ result:=0;
+ if not fileExists(s) then exit;
+ assignFile(f,s);
+ reset(f);
+ while not eof(f) do begin
+ readln(f,s);
+ if startetMit('cache',s) and startetMit('size',s) and startetMit(':',s) and (endetMit('KB',s) or endetMit('kB',s)) then begin
+ if result=0 then
+ result:=strToInt(s)
+ else
+ result:=min(result,strToInt(s));
+ end;
+ end;
+ closeFile(f);
end;
function shellSubst(s: string): string;
@@ -129,6 +134,28 @@ begin
end;
end;
+function homeVerzeichnis: string;
+begin
+ result:=shellSubst('${HOME}');
+end;
+
+function homeVerzeichnis(user: string): string;
+var
+ params: array of string;
+ i: longint;
+begin
+ setLength(params,2);
+ params[0]:='passwd';
+ params[1]:=user;
+ if runCommand('getent',params,result) then begin
+ for i:=0 to 4 do
+ erstesArgument(result,':',false);
+ result:=erstesArgument(result,':',false);
+ end
+ else
+ result:='';
+end;
+
function shellExpand(s: string): string;
var
sa: tMyStringList;
@@ -221,11 +248,23 @@ begin
else
inc(i);
for i:=0 to sa.count-1 do begin
- s:=sa[i];
- if startetMit('~/',s) then
- s:=getEnvironmentVariable('HOME')+'/'+s
- else
+ if leftStr(sa[i],1)<>'~' then
continue;
+ s:=sa[i];
+ delete(s,1,1);
+ if (s='') or (leftStr(s,1)='/') or (leftStr(s,1)=' ') then
+ s:=homeVerzeichnis+s
+ else begin
+ if pos(' ',s+' ')<pos('/',s+'/') then
+ ende:=' '
+ else
+ ende:='/';
+ start:=erstesArgument(s,ende,false);
+ start:=homeVerzeichnis(start);
+ if start='' then
+ continue;
+ s:=start+ende+s;
+ end;
sa[i]:=s;
end;
end;