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
This commit is contained in:
@ -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
|
||||
|
||||
@ -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 \
|
||||
|
||||
118
e-util/e-path.c
Normal file
118
e-util/e-path.c
Normal file
@ -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;
|
||||
}
|
||||
26
e-util/e-path.h
Normal file
26
e-util/e-path.h
Normal file
@ -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__ */
|
||||
Reference in New Issue
Block a user