mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
Added new fnction for manipulate vpath objects:
* vfs_path_append_vpath_new () * vfs_path_vtokens_get () Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
parent
133cf183b5
commit
fdedfb5d3b
@ -1151,6 +1151,46 @@ vfs_path_append_new (const vfs_path_t * vpath, const char *first_element, ...)
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Append vpath_t tokens to path object
|
||||
*
|
||||
* @param ... NULL-terminated vpath objects
|
||||
*
|
||||
* @return newly allocated path object
|
||||
*/
|
||||
|
||||
vfs_path_t *
|
||||
vfs_path_append_vpath_new (const vfs_path_t * first_vpath, ...)
|
||||
{
|
||||
va_list args;
|
||||
vfs_path_t *ret_vpath;
|
||||
const vfs_path_t *current_vpath = first_vpath;
|
||||
|
||||
if (first_vpath == NULL)
|
||||
return NULL;
|
||||
|
||||
ret_vpath = vfs_path_new ();
|
||||
|
||||
va_start (args, first_vpath);
|
||||
do
|
||||
{
|
||||
int vindex;
|
||||
|
||||
for (vindex = 0; vindex < vfs_path_elements_count (current_vpath); vindex++)
|
||||
ret_vpath->path =
|
||||
g_list_append (ret_vpath->path,
|
||||
vfs_path_element_clone (vfs_path_get_by_index
|
||||
(current_vpath, vindex)));
|
||||
current_vpath = va_arg (args, const vfs_path_t *);
|
||||
}
|
||||
while (current_vpath != NULL);
|
||||
va_end (args);
|
||||
|
||||
return ret_vpath;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* get tockens count in path.
|
||||
@ -1207,6 +1247,9 @@ vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, size_t le
|
||||
int element_index;
|
||||
size_t tokens_count = vfs_path_tokens_count (vpath);
|
||||
|
||||
if (vpath == NULL)
|
||||
return NULL;
|
||||
|
||||
if (length == 0)
|
||||
length = tokens_count;
|
||||
|
||||
@ -1266,3 +1309,30 @@ vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, size_t le
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Get subpath by tokens
|
||||
*
|
||||
* @param vpath path object
|
||||
* @param start_position first token for got/ Started from 0.
|
||||
* If negative, then position will be relative to end of path
|
||||
* @param length count of tokens
|
||||
*
|
||||
* @return newly allocated path object with path tokens separated by slash
|
||||
*/
|
||||
|
||||
vfs_path_t *
|
||||
vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, size_t length)
|
||||
{
|
||||
char *str_tokens;
|
||||
vfs_path_t *ret_vpath = NULL;
|
||||
|
||||
str_tokens = vfs_path_tokens_get (vpath, start_position, length);
|
||||
if (str_tokens != NULL)
|
||||
{
|
||||
ret_vpath = vfs_path_from_str_flags (str_tokens, VPF_NO_CANON);
|
||||
g_free (str_tokens);
|
||||
}
|
||||
return ret_vpath;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -58,9 +58,11 @@ char *vfs_path_to_str_elements_count (const vfs_path_t * path, int elements_coun
|
||||
vfs_path_t *vfs_path_from_str (const char *path_str);
|
||||
vfs_path_t *vfs_path_from_str_flags (const char *path_str, vfs_path_flag_t flags);
|
||||
vfs_path_t *vfs_path_build_filename (const char *first_element, ...);
|
||||
vfs_path_t *vfs_path_append_new (const vfs_path_t *, const char *first_element, ...);
|
||||
vfs_path_t *vfs_path_append_new (const vfs_path_t * vpath, const char *first_element, ...);
|
||||
vfs_path_t *vfs_path_append_vpath_new (const vfs_path_t * first_vpath, ...);
|
||||
size_t vfs_path_tokens_count (const vfs_path_t *);
|
||||
char *vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, size_t length);
|
||||
vfs_path_t *vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, size_t length);
|
||||
|
||||
vfs_path_element_t *vfs_path_get_by_index (const vfs_path_t * path, int element_index);
|
||||
vfs_path_element_t *vfs_path_element_clone (const vfs_path_element_t * element);
|
||||
|
@ -209,6 +209,28 @@ END_TEST
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
START_TEST (test_vfs_path_append_vpath)
|
||||
{
|
||||
vfs_path_t *vpath1, *vpath2, *vpath3;
|
||||
|
||||
vpath1 = vfs_path_from_str("/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/test2://#enc:KOI8-R/bla-bla/some/path/test3://111/22/33");
|
||||
vpath2 = vfs_path_from_str("/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/");
|
||||
|
||||
vpath3 = vfs_path_append_vpath_new (vpath1, vpath2, NULL);
|
||||
|
||||
fail_unless (vfs_path_elements_count(vpath3) == 6,
|
||||
"\nvpath elements count should be %d, actial is %d\n",
|
||||
6,
|
||||
vfs_path_elements_count(vpath3)
|
||||
);
|
||||
vfs_path_free (vpath1);
|
||||
vfs_path_free (vpath2);
|
||||
vfs_path_free (vpath3);
|
||||
|
||||
}
|
||||
END_TEST
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
main (void)
|
||||
@ -224,6 +246,7 @@ main (void)
|
||||
/* Add new tests here: *************** */
|
||||
tcase_add_test (tc_core, test_vfs_path_tokens_count);
|
||||
tcase_add_test (tc_core, test_vfs_path_tokens_get);
|
||||
tcase_add_test (tc_core, test_vfs_path_append_vpath);
|
||||
/* *********************************** */
|
||||
|
||||
suite_add_tcase (s, tc_core);
|
||||
|
Loading…
Reference in New Issue
Block a user