diff options
author | Dan Winship <danw@src.gnome.org> | 2001-03-02 08:31:23 +0800 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2001-03-02 08:31:23 +0800 |
commit | ca443fec62a8a30820db652a49853974e799dcc5 (patch) | |
tree | 02f380875c2688c764cb0d9f0b43546479c084e0 /e-util | |
parent | 60aed2ad749fe5e0b4e8c5979ac1ce20da89e1d6 (diff) | |
download | gsoc2013-evolution-ca443fec62a8a30820db652a49853974e799dcc5.tar gsoc2013-evolution-ca443fec62a8a30820db652a49853974e799dcc5.tar.gz gsoc2013-evolution-ca443fec62a8a30820db652a49853974e799dcc5.tar.bz2 gsoc2013-evolution-ca443fec62a8a30820db652a49853974e799dcc5.tar.lz gsoc2013-evolution-ca443fec62a8a30820db652a49853974e799dcc5.tar.xz 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')
-rw-r--r-- | e-util/ChangeLog | 9 | ||||
-rw-r--r-- | e-util/Makefile.am | 2 | ||||
-rw-r--r-- | e-util/e-path.c | 118 | ||||
-rw-r--r-- | e-util/e-path.h | 26 |
4 files changed, 155 insertions, 0 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 35cd88d2c1..8cf1b9c216 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,12 @@ +2001-03-01 Dan Winship <danw@ximian.com> + + * 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] + 2001-03-01 Not Zed <NotZed@Ximian.com> * e-sexp.c (e_sexp_encode_string): Make it handle a NULL string as diff --git a/e-util/Makefile.am b/e-util/Makefile.am index f2743b3673..fd9364ccd4 100644 --- a/e-util/Makefile.am +++ b/e-util/Makefile.am @@ -35,6 +35,8 @@ libeutil_la_SOURCES = \ e-memory.h \ e-msgport.c \ e-msgport.h \ + e-path.c \ + e-path.h \ e-sexp.c \ e-sexp.h \ e-dbhash.c \ 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; +} diff --git a/e-util/e-path.h b/e-util/e-path.h new file mode 100644 index 0000000000..808b666d9e --- /dev/null +++ b/e-util/e-path.h @@ -0,0 +1,26 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2001 Ximian, Inc. + * + * This library 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 library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __E_PATH__ +#define __E_PATH__ + +char *e_path_to_physical (const char *prefix, const char *vpath); + +#endif /* __E_PATH__ */ |