From 3a1936aadeae97daa953ce1b6669bbf77c18db63 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Thu, 14 Apr 2011 15:21:30 +0300 Subject: [PATCH] Added vfs_path_t structure Signed-off-by: Slava Zanko --- lib/vfs/Makefile.am | 6 ++- lib/vfs/path.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/vfs/path.h | 45 ++++++++++++++++ 3 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 lib/vfs/path.c create mode 100644 lib/vfs/path.h diff --git a/lib/vfs/Makefile.am b/lib/vfs/Makefile.am index 4d2d51915..a868e4849 100644 --- a/lib/vfs/Makefile.am +++ b/lib/vfs/Makefile.am @@ -3,11 +3,13 @@ noinst_LTLIBRARIES = libmcvfs.la AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) libmcvfs_la_SOURCES = \ + direntry.c \ + gc.c gc.h \ interface.c interface.h \ + path.c path.h \ vfs.c vfs.h \ - direntry.c xdirentry.h \ utilvfs.c utilvfs.h \ - gc.c gc.h + xdirentry.h if ENABLE_VFS_NET libmcvfs_la_SOURCES += netutil.c netutil.h diff --git a/lib/vfs/path.c b/lib/vfs/path.c new file mode 100644 index 000000000..b254b2704 --- /dev/null +++ b/lib/vfs/path.c @@ -0,0 +1,148 @@ +/* Virtual File System path handlers + Copyright (C) 2011 Free Software Foundation, Inc. + + Written by: + Slava Zanko , 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 + +#include "lib/global.h" + +#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); + } + return g_string_free(buffer, FALSE); +} + +/* --------------------------------------------------------------------------------------------- */ + +vfs_path_t * +vfs_path_from_str (const char * path_str) +{ + vfs_path_t *path; + vfs_path_element_t *element; + + if (path_str == NULL) + return NULL; + + path = vfs_path_new(); + + element = g_new0(vfs_path_element_t,1); + element->path = g_strdup(path_str); // FIXME!!! + + g_ptr_array_add(path->path,element); + + return path; +} + +/* --------------------------------------------------------------------------------------------- */ + +vfs_path_t * +vfs_path_new(void) +{ + vfs_path_t *path; + path = g_new0(vfs_path_t,1); + path->path = g_ptr_array_new (); + return path; +} + +/* --------------------------------------------------------------------------------------------- */ + +size_t +vfs_path_length (const vfs_path_t *path) +{ + return path->path->len; +} + +/* --------------------------------------------------------------------------------------------- */ + +vfs_path_element_t * +vfs_path_get_by_index (const vfs_path_t *path, size_t element_index) +{ + return g_ptr_array_index(path->path, element_index); +} + +/* --------------------------------------------------------------------------------------------- */ + +void +vfs_path_element_free(vfs_path_element_t *element) +{ + if (element == NULL) + return; + + g_free(element->path); + g_free(element->encoding); + g_free(element); +} + +/* --------------------------------------------------------------------------------------------- */ + +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); + g_free(path->unparsed); + g_free(path); +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/vfs/path.h b/lib/vfs/path.h new file mode 100644 index 000000000..4dea54aa1 --- /dev/null +++ b/lib/vfs/path.h @@ -0,0 +1,45 @@ +#ifndef MC__VFS_PATH_H +#define MC__VFS_PATH_H + +/*** typedefs(not structures) and defined constants **********************************************/ + +//typedef GPtrArray vfs_path_t; + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +struct vfs_class; + +typedef struct { + GPtrArray *path; + char *unparsed; +} vfs_path_t; + +typedef struct { + char *path; + struct vfs_class *class; + char *encoding; +#ifdef ENABLE_VFS_NET + vfs_url_t *url; +#endif /* ENABLE_VFS_NET */ +} vfs_path_element_t; + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +vfs_path_t *vfs_path_new(void); +void vfs_path_free (vfs_path_t * path); +size_t vfs_path_length (const vfs_path_t *path); + +char *vfs_path_to_str (const vfs_path_t * path); +vfs_path_t * vfs_path_from_str (const char * path_str); + +vfs_path_element_t *vfs_path_get_by_index (const vfs_path_t *path, size_t element_index); +void vfs_path_element_free(vfs_path_element_t *element); + + +/*** inline functions ****************************************************************************/ + +#endif -- 2.11.4.GIT