Browse Source

+ rawbytestring version of PathConv()

git-svn-id: branches/cpstrrtl@25041 -
Jonas Maebe 12 years ago
parent
commit
6dbcb7db80
2 changed files with 70 additions and 0 deletions
  1. 35 0
      rtl/amiga/sysos.inc
  2. 35 0
      rtl/morphos/sysos.inc

+ 35 - 0
rtl/amiga/sysos.inc

@@ -146,3 +146,38 @@ begin
   PathConv:=path;
 end;
 
+{ Converts an Unix-like path to Amiga-like path }
+function PathConv(const path: rawbytestring): rawbytestring;
+var tmppos: longint;
+begin
+  { check for short paths }
+  if length(path)<=2 then begin
+    if (path='.') or (path='./') then PathConv:='' else
+    if path='..' then PathConv:='/' else
+    if path='*' then PathConv:='#?'
+    else PathConv:=path;
+  end else begin
+    { convert parent directories }
+    PathConv:=path;
+    tmppos:=pos('../',PathConv);
+    while tmppos<>0 do begin
+      { delete .. to have / as parent dir sign }
+      delete(PathConv,tmppos,2);
+      tmppos:=pos('../',PathConv);
+    end;
+    { convert current directories }
+    tmppos:=pos('./',PathConv);
+    while tmppos<>0 do begin
+      { delete ./ since we doesn't need to sign current directory }
+      delete(PathConv,tmppos,2);
+      tmppos:=pos('./',PathConv);
+    end;
+    { convert wildstart to #? }
+    tmppos:=pos('*',PathConv);
+    while tmppos<>0 do begin
+      delete(PathConv,tmppos,1);
+      insert('#?',PathConv,tmppos);
+      tmppos:=pos('*',PathConv);
+    end;
+  end;
+end;

+ 35 - 0
rtl/morphos/sysos.inc

@@ -137,5 +137,40 @@ begin
 end;
 
 
+{ Converts an Unix-like path to Amiga-like path }
+function PathConv(const path: rawbytestring): rawbytestring;
+var tmppos: longint;
+begin
+  { check for short paths }
+  if length(path)<=2 then begin
+    if (path='.') or (path='./') then PathConv:='' else
+    if path='..' then PathConv:='/' else
+    if path='*' then PathConv:='#?'
+    else PathConv:=path;
+  end else begin
+    { convert parent directories }
+    PathConv:=path;
+    tmppos:=pos('../',PathConv);
+    while tmppos<>0 do begin
+      { delete .. to have / as parent dir sign }
+      delete(PathConv,tmppos,2);
+      tmppos:=pos('../',PathConv);
+    end;
+    { convert current directories }
+    tmppos:=pos('./',PathConv);
+    while tmppos<>0 do begin
+      { delete ./ since we doesn't need to sign current directory }
+      delete(PathConv,tmppos,2);
+      tmppos:=pos('./',PathConv);
+    end;
+    { convert wildstart to #? }
+    tmppos:=pos('*',PathConv);
+    while tmppos<>0 do begin
+      delete(PathConv,tmppos,1);
+      insert('#?',PathConv,tmppos);
+      tmppos:=pos('*',PathConv);
+    end;
+  end;
+end;