Added function mc_build_filename() for processing URL-paths as well
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Этот коммит содержится в:
родитель
1eb91d7921
Коммит
1beaecdf12
@ -5,6 +5,7 @@ LIBS=@CHECK_LIBS@ $(top_builddir)/lib/libmc.la
|
||||
|
||||
TESTS = \
|
||||
library_independ \
|
||||
mc_build_filename \
|
||||
serialize \
|
||||
x_basename
|
||||
|
||||
@ -13,6 +14,9 @@ check_PROGRAMS = $(TESTS)
|
||||
library_independ_SOURCES = \
|
||||
library_independ.c
|
||||
|
||||
mc_build_filename_SOURCES = \
|
||||
mc_build_filename.c
|
||||
|
||||
serialize_SOURCES = \
|
||||
serialize.c
|
||||
|
||||
|
100
lib/tests/mc_build_filename.c
Обычный файл
100
lib/tests/mc_build_filename.c
Обычный файл
@ -0,0 +1,100 @@
|
||||
/* lib/vfs - mc_build_filename() function testing
|
||||
|
||||
Copyright (C) 2011 Free Software Foundation, Inc.
|
||||
|
||||
Written by:
|
||||
Slava Zanko <slavazanko@gmail.com>, 2011
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library 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 Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library 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.
|
||||
*/
|
||||
|
||||
#define TEST_SUITE_NAME "/lib"
|
||||
|
||||
#include <check.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "lib/strutil.h"
|
||||
#include "lib/util.h"
|
||||
|
||||
|
||||
static void
|
||||
setup (void)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
teardown (void)
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
#define check_mc_build_filename( inargs, etalon ) \
|
||||
{ \
|
||||
result = mc_build_filename inargs; \
|
||||
fail_unless( strcmp (result, etalon) == 0, \
|
||||
"\nactial (%s) not equal to\netalon (%s)", result, etalon); \
|
||||
g_free (result); \
|
||||
}
|
||||
|
||||
START_TEST (test_mc_build_filename)
|
||||
{
|
||||
char *result;
|
||||
|
||||
check_mc_build_filename(("test", "path", NULL), "/test/path");
|
||||
|
||||
check_mc_build_filename(("/test", "path/", NULL), "/test/path");
|
||||
|
||||
check_mc_build_filename(("/test", "pa/th", NULL), "/test/pa/th");
|
||||
|
||||
check_mc_build_filename(("/test", "#vfsprefix:", "path ", NULL), "/test/#vfsprefix:/path ");
|
||||
|
||||
check_mc_build_filename(("/test", "vfsprefix://", "path ", NULL), "/test/vfsprefix://path ");
|
||||
|
||||
check_mc_build_filename(("/test", "vfs/../prefix:///", "p\\///ath", NULL), "/test/prefix://p\\/ath");
|
||||
|
||||
check_mc_build_filename(("/test", "path", "..", "/test", "path/", NULL), "/test/test/path");
|
||||
|
||||
}
|
||||
END_TEST
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int number_failed;
|
||||
|
||||
Suite *s = suite_create (TEST_SUITE_NAME);
|
||||
TCase *tc_core = tcase_create ("Core");
|
||||
SRunner *sr;
|
||||
|
||||
tcase_add_checked_fixture (tc_core, setup, teardown);
|
||||
|
||||
/* Add new tests here: *************** */
|
||||
tcase_add_test (tc_core, test_mc_build_filename);
|
||||
/* *********************************** */
|
||||
|
||||
suite_add_tcase (s, tc_core);
|
||||
sr = srunner_create (s);
|
||||
srunner_set_log (sr, "mc_build_filename.log");
|
||||
srunner_run_all (sr, CK_NORMAL);
|
||||
number_failed = srunner_ntests_failed (sr);
|
||||
srunner_free (sr);
|
||||
return (number_failed == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
@ -205,6 +205,8 @@ gboolean mc_util_unlink_backup_if_possible (const char *, const char *);
|
||||
|
||||
char *guess_message_value (void);
|
||||
|
||||
char *mc_build_filename (const char *first_element, ...);
|
||||
|
||||
/*** inline functions **************************************************/
|
||||
|
||||
static inline gboolean
|
||||
|
@ -1016,3 +1016,55 @@ get_user_permissions (struct stat *st)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Build filename from arguments.
|
||||
* Like to g_build_filename(), but respect VFS_PATH_URL_DELIMITER
|
||||
*/
|
||||
|
||||
char *
|
||||
mc_build_filename (const char *first_element, ...)
|
||||
{
|
||||
va_list args;
|
||||
const char *element = first_element;
|
||||
GString *path;
|
||||
char *ret;
|
||||
|
||||
if (element == NULL)
|
||||
return NULL;
|
||||
|
||||
path = g_string_new ("");
|
||||
va_start (args, first_element);
|
||||
|
||||
do
|
||||
{
|
||||
char *tmp_element;
|
||||
size_t len;
|
||||
const char *start;
|
||||
|
||||
tmp_element = g_strdup (element);
|
||||
|
||||
element = va_arg (args, char *);
|
||||
|
||||
canonicalize_pathname (tmp_element);
|
||||
len = strlen (tmp_element);
|
||||
start = (tmp_element[0] == PATH_SEP) ? tmp_element + 1 : tmp_element;
|
||||
|
||||
g_string_append (path, start);
|
||||
if (tmp_element[len - 1] != PATH_SEP && element != NULL)
|
||||
g_string_append_c (path, PATH_SEP);
|
||||
|
||||
g_free (tmp_element);
|
||||
}
|
||||
while (element != NULL);
|
||||
|
||||
va_end (args);
|
||||
|
||||
g_string_prepend_c (path, PATH_SEP);
|
||||
|
||||
ret = g_string_free (path, FALSE);
|
||||
canonicalize_pathname (ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -4275,7 +4275,7 @@ edit_unlock_file (WEdit * edit)
|
||||
char *fullpath;
|
||||
unsigned int ret;
|
||||
|
||||
fullpath = g_build_filename (edit->dir, edit->filename, (char *) NULL);
|
||||
fullpath = mc_build_filename (edit->dir, edit->filename, (char *) NULL);
|
||||
ret = unlock_file (fullpath);
|
||||
g_free (fullpath);
|
||||
|
||||
@ -4290,7 +4290,7 @@ edit_lock_file (WEdit * edit)
|
||||
char *fullpath;
|
||||
unsigned int ret;
|
||||
|
||||
fullpath = g_build_filename (edit->dir, edit->filename, (char *) NULL);
|
||||
fullpath = mc_build_filename (edit->dir, edit->filename, (char *) NULL);
|
||||
ret = lock_file (fullpath);
|
||||
g_free (fullpath);
|
||||
|
||||
|
@ -492,7 +492,7 @@ edit_load_file_from_filename (WEdit * edit, char *exp)
|
||||
{
|
||||
char *fullpath;
|
||||
|
||||
fullpath = g_build_filename (edit->dir, prev_filename, (char *) NULL);
|
||||
fullpath = mc_build_filename (edit->dir, prev_filename, (char *) NULL);
|
||||
unlock_file (fullpath);
|
||||
g_free (fullpath);
|
||||
}
|
||||
@ -3193,7 +3193,7 @@ edit_get_match_keyword_cmd (WEdit * edit)
|
||||
g_free (path);
|
||||
path = ptr;
|
||||
g_free (tagfile);
|
||||
tagfile = g_build_filename (path, TAGS_NAME, (char *) NULL);
|
||||
tagfile = mc_build_filename (path, TAGS_NAME, (char *) NULL);
|
||||
if (exist_file (tagfile))
|
||||
break;
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ etags_set_definition_hash (const char *tagfile, const char *start_path,
|
||||
if (num < MAX_DEFINITIONS - 1)
|
||||
{
|
||||
def_hash[num].filename_len = strlen (filename);
|
||||
def_hash[num].fullpath = g_build_filename (start_path, filename, (char *) NULL);
|
||||
def_hash[num].fullpath = mc_build_filename (start_path, filename, (char *) NULL);
|
||||
|
||||
canonicalize_pathname (def_hash[num].fullpath);
|
||||
def_hash[num].filename = g_strdup (filename);
|
||||
|
@ -2547,7 +2547,7 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl
|
||||
if (g_path_is_absolute (source))
|
||||
source_with_path = g_strdup (source);
|
||||
else
|
||||
source_with_path = g_build_filename (panel->cwd, source, (char *) NULL);
|
||||
source_with_path = mc_build_filename (panel->cwd, source, (char *) NULL);
|
||||
#endif /* WITH_FULL_PATHS */
|
||||
|
||||
if (panel_operate_init_totals (operation, panel, source_with_path, ctx) == FILE_CONT)
|
||||
@ -2641,7 +2641,7 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl
|
||||
if (g_path_is_absolute (source))
|
||||
source_with_path = g_strdup (source);
|
||||
else
|
||||
source_with_path = g_build_filename (panel->cwd, source, (char *) NULL);
|
||||
source_with_path = mc_build_filename (panel->cwd, source, (char *) NULL);
|
||||
#endif /* WITH_FULL_PATHS */
|
||||
|
||||
if (operation == OP_DELETE)
|
||||
|
@ -714,7 +714,7 @@ find_parameters (char **start_dir, char **ignore_dirs, char **pattern, char **co
|
||||
else if (g_path_is_absolute (*start_dir))
|
||||
*start_dir = g_strdup (*start_dir);
|
||||
else
|
||||
*start_dir = g_build_filename (current_panel->cwd, *start_dir, (char *) NULL);
|
||||
*start_dir = mc_build_filename (current_panel->cwd, *start_dir, (char *) NULL);
|
||||
|
||||
canonicalize_pathname (*start_dir);
|
||||
|
||||
@ -1246,7 +1246,7 @@ do_search (Dlg_head * h)
|
||||
{
|
||||
char *tmp_name;
|
||||
|
||||
tmp_name = g_build_filename (directory, dp->d_name, (char *) NULL);
|
||||
tmp_name = mc_build_filename (directory, dp->d_name, (char *) NULL);
|
||||
|
||||
if (mc_lstat (tmp_name, &tmp_stat) == 0 && S_ISDIR (tmp_stat.st_mode))
|
||||
{
|
||||
|
@ -437,7 +437,7 @@ mcview_lock_file (mcview_t * view)
|
||||
char *fullpath;
|
||||
gboolean ret;
|
||||
|
||||
fullpath = g_build_filename (view->workdir, view->filename, (char *) NULL);
|
||||
fullpath = mc_build_filename (view->workdir, view->filename, (char *) NULL);
|
||||
ret = lock_file (fullpath);
|
||||
g_free (fullpath);
|
||||
|
||||
@ -452,7 +452,7 @@ mcview_unlock_file (mcview_t * view)
|
||||
char *fullpath;
|
||||
gboolean ret;
|
||||
|
||||
fullpath = g_build_filename (view->workdir, view->filename, (char *) NULL);
|
||||
fullpath = mc_build_filename (view->workdir, view->filename, (char *) NULL);
|
||||
ret = unlock_file (fullpath);
|
||||
g_free (fullpath);
|
||||
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user