expand_path: handle parent (..) elements;
authorwenzelm
Thu, 25 Jun 2009 16:34:08 +0200
changeset 31803 4aabae982988
parent 31802 a36b5e02c1ab
child 31806 5fb98777c3a6
expand_path: handle parent (..) elements;
src/Pure/System/isabelle_system.scala
--- a/src/Pure/System/isabelle_system.scala	Thu Jun 25 13:40:03 2009 +0200
+++ b/src/Pure/System/isabelle_system.scala	Thu Jun 25 16:34:08 2009 +0200
@@ -144,11 +144,25 @@
     def append(path: String)
     {
       init(path)
-      for (p <- path.split("/") if p != "") {
-        val len = result_path.length
-        if (len > 0 && result_path(len - 1) != '/')
-          result_path += '/'
-        result_path ++= p
+      for (p <- path.split("/") if p != "" && p != ".") {
+        if (p == "..") {
+          val result = result_path.toString
+          val i = result.lastIndexOf("/")
+          if (result == "")
+            result_path ++= ".."
+          else if (result.substring(i + 1) == "..")
+            result_path ++= "/.."
+          else if (i < 1)
+            result_path.length = i + 1
+          else
+            result_path.length = i
+        }
+        else {
+          val len = result_path.length
+          if (len > 0 && result_path(len - 1) != '/')
+            result_path += '/'
+          result_path ++= p
+        }
       }
     }
     init(source_path)