2011-04-14 16:21:30 +04:00
|
|
|
/* Virtual File System path handlers
|
|
|
|
Copyright (C) 2011 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by:
|
|
|
|
Slava Zanko <slavazanko@gmail.com>, 2011
|
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
|
|
|
The Midnight Commander 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.
|
|
|
|
|
|
|
|
The Midnight Commander 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., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* \brief Source: Virtual File System: path handlers
|
|
|
|
* \author Slava Zanko
|
|
|
|
* \date 2011
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "lib/global.h"
|
|
|
|
|
2011-04-18 16:08:13 +04:00
|
|
|
#include "vfs.h"
|
|
|
|
#include "utilvfs.h"
|
2011-04-14 16:21:30 +04:00
|
|
|
#include "path.h"
|
|
|
|
|
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
char *
|
|
|
|
vfs_path_to_str (const vfs_path_t * path)
|
|
|
|
{
|
|
|
|
size_t element_index;
|
|
|
|
GString *buffer;
|
|
|
|
|
|
|
|
if (path == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
buffer = g_string_new ("");
|
|
|
|
|
|
|
|
for (element_index = 0; element_index < vfs_path_length (path); element_index++)
|
|
|
|
{
|
|
|
|
vfs_path_element_t *element = vfs_path_get_by_index (path, element_index);
|
|
|
|
g_string_append (buffer, element->path);
|
|
|
|
}
|
2011-04-18 16:08:13 +04:00
|
|
|
return g_string_free (buffer, FALSE);
|
2011-04-14 16:21:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
vfs_path_t *
|
2011-04-18 16:08:13 +04:00
|
|
|
vfs_path_from_str (const char *path_str)
|
2011-04-14 16:21:30 +04:00
|
|
|
{
|
|
|
|
vfs_path_t *path;
|
|
|
|
vfs_path_element_t *element;
|
|
|
|
|
|
|
|
if (path_str == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-04-18 16:08:13 +04:00
|
|
|
path = vfs_path_new ();
|
2011-04-20 16:59:06 +04:00
|
|
|
path->unparsed_encoding = g_strdup (vfs_get_encoding (path_str));
|
|
|
|
|
|
|
|
path->unparsed = vfs_canon_and_translate (path_str);
|
|
|
|
if (path->unparsed == NULL)
|
|
|
|
{
|
|
|
|
vfs_path_free (path);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-04-14 16:21:30 +04:00
|
|
|
|
2011-04-18 16:08:13 +04:00
|
|
|
element = g_new0 (vfs_path_element_t, 1);
|
2011-04-20 16:59:06 +04:00
|
|
|
element->class = vfs_get_class (path->unparsed);
|
2011-04-14 16:21:30 +04:00
|
|
|
|
2011-04-18 16:08:13 +04:00
|
|
|
g_ptr_array_add (path->path, element);
|
2011-04-14 16:21:30 +04:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
vfs_path_t *
|
2011-04-18 16:08:13 +04:00
|
|
|
vfs_path_new (void)
|
2011-04-14 16:21:30 +04:00
|
|
|
{
|
|
|
|
vfs_path_t *path;
|
2011-04-18 16:08:13 +04:00
|
|
|
path = g_new0 (vfs_path_t, 1);
|
2011-04-14 16:21:30 +04:00
|
|
|
path->path = g_ptr_array_new ();
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
size_t
|
2011-04-18 16:08:13 +04:00
|
|
|
vfs_path_length (const vfs_path_t * path)
|
2011-04-14 16:21:30 +04:00
|
|
|
{
|
|
|
|
return path->path->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
vfs_path_element_t *
|
2011-04-18 16:08:13 +04:00
|
|
|
vfs_path_get_by_index (const vfs_path_t * path, size_t element_index)
|
2011-04-14 16:21:30 +04:00
|
|
|
{
|
2011-04-18 16:08:13 +04:00
|
|
|
return g_ptr_array_index (path->path, element_index);
|
2011-04-14 16:21:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
2011-04-18 16:08:13 +04:00
|
|
|
vfs_path_element_free (vfs_path_element_t * element)
|
2011-04-14 16:21:30 +04:00
|
|
|
{
|
|
|
|
if (element == NULL)
|
|
|
|
return;
|
|
|
|
|
2011-04-18 16:08:13 +04:00
|
|
|
g_free (element->path);
|
|
|
|
g_free (element->encoding);
|
|
|
|
g_free (element);
|
2011-04-14 16:21:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
vfs_path_free (vfs_path_t * path)
|
|
|
|
{
|
|
|
|
if (path == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_ptr_array_foreach (path->path, (GFunc) vfs_path_element_free, NULL);
|
|
|
|
g_ptr_array_free (path->path, TRUE);
|
2011-04-18 16:08:13 +04:00
|
|
|
g_free (path->unparsed);
|
2011-04-20 16:59:06 +04:00
|
|
|
g_free (path->unparsed_encoding);
|
2011-04-18 16:08:13 +04:00
|
|
|
g_free (path);
|
2011-04-14 16:21:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|