gvfs r1213 - in trunk: . common



Author: alexl
Date: Thu Jan 31 15:40:36 2008
New Revision: 1213
URL: http://svn.gnome.org/viewvc/gvfs?rev=1213&view=rev

Log:
2008-01-31  Alexander Larsson  <alexl redhat com>

        * common/gmountspec.[ch]:
        Add shared path canonicalization:
	g_mount_spec_canonicalize_path()



Modified:
   trunk/ChangeLog
   trunk/common/gmountspec.c
   trunk/common/gmountspec.h

Modified: trunk/common/gmountspec.c
==============================================================================
--- trunk/common/gmountspec.c	(original)
+++ trunk/common/gmountspec.c	Thu Jan 31 15:40:36 2008
@@ -465,3 +465,63 @@
 
   return g_string_free (str, FALSE);
 }
+
+char *
+g_mount_spec_canonicalize_path (const char *path)
+{
+  char *canon, *start, *p, *q;
+
+  if (*path != '/')
+    canon = g_strconcat ("/", path, NULL);
+  else
+    canon = g_strdup (path);
+
+  /* Skip initial slash */
+  start = canon + 1;
+
+  p = start;
+  while (*p != 0)
+    {
+      if (p[0] == '.' && (p[1] == 0 || p[1] == '/'))
+	{
+	  memmove (p, p+1, strlen (p+1)+1);
+	}
+      else if (p[0] == '.' && p[1] == '.' && (p[2] == 0 || p[2] == '/'))
+	{
+	  q = p + 2;
+	  /* Skip previous separator */
+	  p = p - 2;
+	  if (p < start)
+	    p = start;
+	  while (p > start && *p != '/')
+	    p--;
+	  if (*p == '/')
+	    p++;
+	  memmove (p, q, strlen (q)+1);
+	}
+      else
+	{
+	  /* Skip until next separator */
+	  while (*p != 0 && *p != '/')
+	    p++;
+
+	  /* Keep one separator */
+	  if (*p != 0)
+	    p++;
+	}
+
+      /* Remove additional separators */
+      q = p;
+      while (*q && *q == '/')
+	q++;
+
+      if (p != q)
+	memmove (p, q, strlen (q)+1);
+    }
+
+  /* Remove trailing slashes */
+  if (p > start && *(p-1) == '/')
+    *(p-1) = 0;
+  
+  return canon;
+}

Modified: trunk/common/gmountspec.h
==============================================================================
--- trunk/common/gmountspec.h	(original)
+++ trunk/common/gmountspec.h	Thu Jan 31 15:40:36 2008
@@ -95,6 +95,8 @@
 /* For debugging */
 char *      g_mount_spec_to_string         (GMountSpec      *spec);
 
+char *      g_mount_spec_canonicalize_path (const char      *path);
+
 G_END_DECLS
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]