aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-path.c
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2001-03-02 08:31:23 +0800
committerDan Winship <danw@src.gnome.org>2001-03-02 08:31:23 +0800
commitca443fec62a8a30820db652a49853974e799dcc5 (patch)
tree02f380875c2688c764cb0d9f0b43546479c084e0 /e-util/e-path.c
parent60aed2ad749fe5e0b4e8c5979ac1ce20da89e1d6 (diff)
downloadgsoc2013-evolution-ca443fec62a8a30820db652a49853974e799dcc5.tar.gz
gsoc2013-evolution-ca443fec62a8a30820db652a49853974e799dcc5.tar.zst
gsoc2013-evolution-ca443fec62a8a30820db652a49853974e799dcc5.zip
New function to turn foo/bar into foo/subfolders/bar. The inverse function
* e-path.c (e_path_to_physical): New function to turn foo/bar into foo/subfolders/bar. The inverse function doesn't exist yet because I didn't need it. Also, if the shell were going to use this, we'd need a few more tools... * Makefile.am (libeutil_la_SOURCES): Add e-path.[ch] svn path=/trunk/; revision=8467
Diffstat (limited to 'e-util/e-path.c')
-rw-r--r--e-util/e-path.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/e-util/e-path.c b/e-util/e-path.c
new file mode 100644
index 0000000000..d1da9abd38
--- /dev/null
+++ b/e-util/e-path.c
@@ -0,0 +1,118 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* e-path.c
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include <string.h>
+#include <glib.h>
+#include "e-path.h"
+
+#define SUBFOLDER_DIR_NAME "subfolders"
+#define SUBFOLDER_DIR_NAME_LEN 10
+
+/**
+ * e_path_to_physical:
+ * @prefix: a prefix to prepend to the path, or %NULL
+ * @path: the virtual path to convert to a filesystem path.
+ *
+ * This converts the "virtual" path @path into an expanded form that
+ * allows a given name to refer to both a file and a directory. The
+ * expanded path will have a "subfolders" directory inserted between
+ * each path component.
+ *
+ * If @prefix is non-%NULL, it will be prepended to the returned path.
+ *
+ * Return value: the expanded path
+ **/
+char *
+e_path_to_physical (const char *prefix, const char *vpath)
+{
+ const char *p, *newp;
+ char *dp;
+ char *ppath;
+ int ppath_len;
+ int prefix_len;
+
+ while (vpath == '/')
+ vpath++;
+ if (!prefix)
+ prefix = "";
+
+ /* Calculate the length of the real path. */
+ ppath_len = strlen (vpath);
+ ppath_len++; /* For the ending zero. */
+
+ prefix_len = strlen (prefix);
+ ppath_len += prefix_len;
+ ppath_len++; /* For the separating slash. */
+
+ /* Take account of the fact that we need to translate every
+ * separator into `subfolders/'.
+ */
+ p = vpath;
+ while (1) {
+ newp = strchr (p, '/');
+ if (newp == NULL)
+ break;
+
+ ppath_len += SUBFOLDER_DIR_NAME_LEN;
+ ppath_len++; /* For the separating slash. */
+
+ /* Skip consecutive slashes. */
+ while (*newp == '/')
+ newp++;
+
+ p = newp;
+ };
+
+ ppath = g_malloc (ppath_len);
+ dp = ppath;
+
+ memcpy (dp, prefix, prefix_len);
+ dp += prefix_len;
+ *(dp++) = '/';
+
+ /* Copy the mangled path. */
+ p = vpath;
+ while (1) {
+ newp = strchr (p, '/');
+ if (newp == NULL) {
+ strcpy (dp, p);
+ break;
+ }
+
+ memcpy (dp, p, newp - p + 1); /* `+ 1' to copy the slash too. */
+ dp += newp - p + 1;
+
+ memcpy (dp, SUBFOLDER_DIR_NAME, SUBFOLDER_DIR_NAME_LEN);
+ dp += SUBFOLDER_DIR_NAME_LEN;
+
+ *(dp++) = '/';
+
+ /* Skip consecutive slashes. */
+ while (*newp == '/')
+ newp++;
+
+ p = newp;
+ }
+
+ return ppath;
+}