diff --git a/lib/vfs/path.c b/lib/vfs/path.c index 9e49b1698..a5b61bfa0 100644 --- a/lib/vfs/path.c +++ b/lib/vfs/path.c @@ -1532,20 +1532,20 @@ vfs_path_element_build_pretty_path_str (const vfs_path_element_t * element) * @return integer value like to strcmp. */ -int -vfs_path_cmp (const vfs_path_t * vpath1, const vfs_path_t * vpath2) +gboolean +vfs_path_equal (const vfs_path_t * vpath1, const vfs_path_t * vpath2) { char *path1; char *path2; - int ret_val; + gboolean ret_val; if (vpath1 == NULL || vpath2 == NULL) - return -1; + return FALSE; path1 = vfs_path_to_str (vpath1); path2 = vfs_path_to_str (vpath2); - ret_val = strcmp (path1, path2); + ret_val = strcmp (path1, path2) == 0; g_free (path1); g_free (path2); @@ -1564,20 +1564,20 @@ vfs_path_cmp (const vfs_path_t * vpath1, const vfs_path_t * vpath2) * @return integer value like to strcmp. */ -int -vfs_path_ncmp (const vfs_path_t * vpath1, const vfs_path_t * vpath2, size_t len) +gboolean +vfs_path_equal_len (const vfs_path_t * vpath1, const vfs_path_t * vpath2, size_t len) { char *path1; char *path2; - int ret_val; + gboolean ret_val; if (vpath1 == NULL || vpath2 == NULL) - return -1; + return FALSE; path1 = vfs_path_to_str (vpath1); path2 = vfs_path_to_str (vpath2); - ret_val = strncmp (path1, path2, len); + ret_val = strncmp (path1, path2, len) == 0; g_free (path1); g_free (path2); diff --git a/lib/vfs/path.h b/lib/vfs/path.h index 2f962ebad..c45ec1e85 100644 --- a/lib/vfs/path.h +++ b/lib/vfs/path.h @@ -92,8 +92,8 @@ char *vfs_path_build_url_params_str (const vfs_path_element_t * element, gboolea char *vfs_path_element_build_pretty_path_str (const vfs_path_element_t * element); size_t vfs_path_len (const vfs_path_t * vpath); -int vfs_path_cmp (const vfs_path_t * vpath1, const vfs_path_t * vpath2); -int vfs_path_ncmp (const vfs_path_t * vpath1, const vfs_path_t * vpath2, size_t len); +gboolean vfs_path_equal (const vfs_path_t * vpath1, const vfs_path_t * vpath2); +gboolean vfs_path_equal_len (const vfs_path_t * vpath1, const vfs_path_t * vpath2, size_t len); vfs_path_t *vfs_path_to_absolute (const vfs_path_t * vpath); /*** inline functions ****************************************************************************/ diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 0b7c70ae4..70a308d83 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -1663,7 +1663,7 @@ edit_save_as_cmd (WEdit * edit) { int rv; - if (vfs_path_cmp (edit->filename_vpath, exp_vpath) != 0) + if (!vfs_path_equal (edit->filename_vpath, exp_vpath)) { int file; struct stat sb; diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index fb937ff1e..d54736629 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -1044,7 +1044,7 @@ reread_cmd (void) panel_update_flags_t flag = UP_ONLY_CURRENT; if (get_current_type () == view_listing && get_other_type () == view_listing && - vfs_path_cmp (current_panel->cwd_vpath, other_panel->cwd_vpath) == 0) + vfs_path_equal (current_panel->cwd_vpath, other_panel->cwd_vpath)) flag = UP_OPTIMIZE; update_panels (UP_RELOAD | flag, UP_KEEPSEL); diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index 6c0532d65..86fd21fdf 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -4812,7 +4812,7 @@ do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum exact) size_t new_vpath_len; new_vpath_len = vfs_path_len (new_dir_vpath); - if (vfs_path_ncmp (new_dir_vpath, panelized_panel.root_vpath, new_vpath_len) == 0) + if (vfs_path_equal_len (new_dir_vpath, panelized_panel.root_vpath, new_vpath_len)) _new_dir_vpath = panelized_panel.root_vpath; } diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c index 5c39a7dc5..e99e7f9f0 100644 --- a/src/filemanager/panelize.c +++ b/src/filemanager/panelize.c @@ -418,7 +418,7 @@ do_panelize_cd (struct WPanel *panel) panel->count = panelized_panel.count; panel->is_panelized = TRUE; - panelized_same = (vfs_path_cmp (panelized_panel.root_vpath, panel->cwd_vpath) == 0); + panelized_same = (vfs_path_equal (panelized_panel.root_vpath, panel->cwd_vpath)); for (i = 0; i < panelized_panel.count; i++) { diff --git a/src/filemanager/tree.c b/src/filemanager/tree.c index 628e12070..bba6a12cc 100644 --- a/src/filemanager/tree.c +++ b/src/filemanager/tree.c @@ -314,13 +314,13 @@ show_tree (WTree * tree) if (current->sublevel < tree->selected_ptr->sublevel) { - if (vfs_path_cmp (current->name, tree->selected_ptr->name) == 0) + if (vfs_path_equal (current->name, tree->selected_ptr->name)) i++; } else if (current->sublevel == tree->selected_ptr->sublevel) { for (j = strlen (current_name) - 1; current_name[j] != PATH_SEP; j--); - if (vfs_path_ncmp (current->name, tree->selected_ptr->name, j) == 0) + if (vfs_path_equal_len (current->name, tree->selected_ptr->name, j)) i++; } else @@ -328,8 +328,8 @@ show_tree (WTree * tree) if (current->sublevel == tree->selected_ptr->sublevel + 1 && vfs_path_len (tree->selected_ptr->name) > 1) { - if (vfs_path_ncmp (current->name, tree->selected_ptr->name, - vfs_path_len (tree->selected_ptr->name)) == 0) + if (vfs_path_equal_len (current->name, tree->selected_ptr->name, + vfs_path_len (tree->selected_ptr->name))) i++; } } @@ -406,8 +406,8 @@ show_tree (WTree * tree) { if (current->sublevel < tree->selected_ptr->sublevel) { - if (vfs_path_ncmp (current->name, tree->selected_ptr->name, - vfs_path_len (current->name)) == 0) + if (vfs_path_equal_len (current->name, tree->selected_ptr->name, + vfs_path_len (current->name))) break; } else if (current->sublevel == tree->selected_ptr->sublevel) @@ -418,14 +418,14 @@ show_tree (WTree * tree) for (j = strlen (current_name) - 1; current_name[j] != PATH_SEP; j--) ; g_free (current_name); - if (vfs_path_ncmp (current->name, tree->selected_ptr->name, j) == 0) + if (vfs_path_equal_len (current->name, tree->selected_ptr->name, j)) break; } else if (current->sublevel == tree->selected_ptr->sublevel + 1 && vfs_path_len (tree->selected_ptr->name) > 1) { - if (vfs_path_ncmp (current->name, tree->selected_ptr->name, - vfs_path_len (tree->selected_ptr->name)) == 0) + if (vfs_path_equal_len (current->name, tree->selected_ptr->name, + vfs_path_len (tree->selected_ptr->name))) break; } current = current->next; diff --git a/src/filemanager/treestore.c b/src/filemanager/treestore.c index 15942ff00..e3e512d08 100644 --- a/src/filemanager/treestore.c +++ b/src/filemanager/treestore.c @@ -727,7 +727,7 @@ tree_store_remove_entry (const vfs_path_t * name_vpath) len = vfs_path_len (base->name); current = base->next; - while (current != NULL && vfs_path_ncmp (current->name, base->name, len) == 0) + while (current != NULL && vfs_path_equal_len (current->name, base->name, len)) { char *current_name; gboolean ok; @@ -794,7 +794,7 @@ tree_store_mark_checked (const char *subname) len = vfs_path_len (base->name); base->mark = 0; current = base->next; - while (current != NULL && vfs_path_ncmp (current->name, base->name, len) == 0) + while (current != NULL && vfs_path_equal_len (current->name, base->name, len)) { gboolean ok; @@ -851,7 +851,7 @@ tree_store_start_check (const vfs_path_t * vpath) len = vfs_path_len (ts.check_name); current = ts.check_start; - while (current != NULL && vfs_path_ncmp (current->name, ts.check_name, len) == 0) + while (current != NULL && vfs_path_equal_len (current->name, ts.check_name, len)) { char *current_name; gboolean ok; @@ -887,7 +887,7 @@ tree_store_end_check (void) len = vfs_path_len (ts.check_name); current = ts.check_start; - while (current != NULL && vfs_path_ncmp (current->name, ts.check_name, len) == 0) + while (current != NULL && vfs_path_equal_len (current->name, ts.check_name, len)) { char *current_name; gboolean ok; diff --git a/tests/lib/vfs/path_cmp.c b/tests/lib/vfs/path_cmp.c index 1cd1540da..b110b4c47 100644 --- a/tests/lib/vfs/path_cmp.c +++ b/tests/lib/vfs/path_cmp.c @@ -66,10 +66,10 @@ teardown (void) #define path_cmp_one_check(input1, input2, etalon_condition) {\ vpath1 = vfs_path_from_str (input1);\ vpath2 = vfs_path_from_str (input2);\ - result = vfs_path_cmp (vpath1, vpath2);\ + result = vfs_path_equal (vpath1, vpath2);\ vfs_path_free (vpath1); \ vfs_path_free (vpath2); \ - fail_unless ( result etalon_condition, "\ninput1: %s\ninput2: %s\nexpected: %d\nactual: %d\n",\ + fail_unless ( result == etalon_condition, "\ninput1: %s\ninput2: %s\nexpected: %d\nactual: %d\n",\ input1, input2, #etalon_condition, result); \ } @@ -80,16 +80,18 @@ START_TEST (test_path_compare) vfs_path_t *vpath1, *vpath2; int result; - path_cmp_one_check ("/тестовый/путь", "/тестовый/путь", == 0); + path_cmp_one_check ("/тестовый/путь", "/тестовый/путь", TRUE); #ifdef HAVE_CHARSET - path_cmp_one_check ("/#enc:KOI8-R/тестовый/путь", "/тестовый/путь", <0); - path_cmp_one_check ("/тестовый/путь", "/#enc:KOI8-R/тестовый/путь", >0); + path_cmp_one_check ("/#enc:KOI8-R/тестовый/путь", "/тестовый/путь", + FALSE); + path_cmp_one_check ("/тестовый/путь", "/#enc:KOI8-R/тестовый/путь", + FALSE); #endif - path_cmp_one_check (NULL, "/тестовый/путь", -1); - path_cmp_one_check ("/тестовый/путь", NULL, -1); - path_cmp_one_check (NULL, NULL, -1); + path_cmp_one_check (NULL, "/тестовый/путь", FALSE); + path_cmp_one_check ("/тестовый/путь", NULL, FALSE); + path_cmp_one_check (NULL, NULL, FALSE); } /* *INDENT-OFF* */ END_TEST @@ -101,10 +103,10 @@ END_TEST #define path_cmp_one_check(input1, input2, len, etalon_condition) {\ vpath1 = vfs_path_from_str (input1);\ vpath2 = vfs_path_from_str (input2);\ - result = vfs_path_ncmp (vpath1, vpath2, len);\ + result = vfs_path_equal_len (vpath1, vpath2, len);\ vfs_path_free (vpath1); \ vfs_path_free (vpath2); \ - fail_unless ( result etalon_condition, "\ninput1: %s\ninput2: %s\nexpected: %d\nactual: %d\n",\ + fail_unless ( result == etalon_condition, "\ninput1: %s\ninput2: %s\nexpected: %d\nactual: %d\n",\ input1, input2, #etalon_condition, result); \ } @@ -115,17 +117,17 @@ START_TEST (test_path_compare_len) vfs_path_t *vpath1, *vpath2; int result; - path_cmp_one_check ("/тестовый/путь", "/тестовый/путь", 10, == 0); + path_cmp_one_check ("/тестовый/путь", "/тестовый/путь", 10, TRUE); - path_cmp_one_check ("/тест/овый/путь", "/тестовый/путь", 10, <0); + path_cmp_one_check ("/тест/овый/путь", "/тестовый/путь", 10, FALSE); - path_cmp_one_check ("/тестовый/путь", "/тест/овый/путь", 10, >0); + path_cmp_one_check ("/тестовый/путь", "/тест/овый/путь", 10, FALSE); - path_cmp_one_check ("/тест/овый/путь", "/тестовый/путь", 9, == 0); + path_cmp_one_check ("/тест/овый/путь", "/тестовый/путь", 9, TRUE); - path_cmp_one_check (NULL, "/тестовый/путь", 0, <0); - path_cmp_one_check ("/тестовый/путь", NULL, 0, <0); - path_cmp_one_check (NULL, NULL, 0, <0); + path_cmp_one_check (NULL, "/тестовый/путь", 0, FALSE); + path_cmp_one_check ("/тестовый/путь", NULL, 0, FALSE); + path_cmp_one_check (NULL, NULL, 0, FALSE); } /* *INDENT-OFF* */ END_TEST