changeset 919:3a939c88305c

Simplify parse_out_relatives().
author zas_
date Wed, 23 Jul 2008 10:21:37 +0000
parents 19b7349bb8c8
children 408879d2a660
files src/ui_fileops.c
diffstat 1 files changed, 23 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/ui_fileops.c	Wed Jul 23 09:10:41 2008 +0000
+++ b/src/ui_fileops.c	Wed Jul 23 10:21:37 2008 +0000
@@ -665,23 +665,32 @@
 
 	while (path[s] != '\0')
 		{
-		if (path[s] == G_DIR_SEPARATOR && path[s+1] == '.' && (path[s+2] == G_DIR_SEPARATOR || path[s+2] == '\0') )
-			{
-			s += 2;
-			}
-		else if (path[s] == G_DIR_SEPARATOR && path[s+1] == '.' && path[s+2] == '.' && (path[s+3] == G_DIR_SEPARATOR || path[s+3] == '\0') )
+		if (path[s] == G_DIR_SEPARATOR && path[s+1] == '.')
 			{
-			s += 3;
-			if (t > 0) t--;
-			while (path[t] != G_DIR_SEPARATOR && t > 0) t--;
+			/* /. occurence, let's see more */
+			gint p = s + 2;
+
+			if (path[p] == G_DIR_SEPARATOR || path[p] == '\0')
+				{
+				/* /./ or /., just skip this part */
+				s = p;
+				continue;
+				}
+			else if (path[p] == '.' && (path[p+1] == G_DIR_SEPARATOR || path[p+1] == '\0'))
+				{
+				/* /../ or /.., remove previous part, ie. /a/b/../ becomes /a/ */
+				s = p + 1;
+				if (t > 0) t--;
+				while (path[t] != G_DIR_SEPARATOR && t > 0) t--;
+				continue;
+				}
 			}
-		else
-			{
-			if (s != t) path[t] = path[s];
-			t++;
-			s++;
-			}
+	
+		if (s != t) path[t] = path[s];
+		t++;
+		s++;
 		}
+
 	if (t == 0 && path[t] == G_DIR_SEPARATOR) t++;
 	if (t > 1 && path[t-1] == G_DIR_SEPARATOR) t--;
 	path[t] = '\0';