From 493a8ce96d2c22b133820ea22722fb1fde37e331 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Wed, 9 Nov 2011 00:10:51 +0300 Subject: [PATCH] Code refactoring: removed concat_dir_and_file() function. Signed-off-by: Slava Zanko --- lib/util.c | 16 ---------------- lib/util.h | 1 - lib/vfs/direntry.c | 2 +- lib/vfs/path.c | 4 ++-- lib/widget/input_complete.c | 4 ++-- src/cons.handler.c | 8 ++++---- src/editor/editwidget.c | 10 ++++++---- src/filemanager/ext.c | 4 ++-- src/filemanager/file.c | 16 ++++++++-------- src/filemanager/filenot.c | 2 +- src/filemanager/panel.c | 4 ++-- src/filemanager/usermenu.c | 13 +++++++------ src/setup.c | 4 ++-- src/vfs/ftpfs/ftpfs.c | 6 ++++-- src/vfs/smbfs/smbfs.c | 7 ++++--- 15 files changed, 45 insertions(+), 56 deletions(-) diff --git a/lib/util.c b/lib/util.c index 38f74fcaf..473c70881 100644 --- a/lib/util.c +++ b/lib/util.c @@ -1136,22 +1136,6 @@ diff_two_paths (const vfs_path_t * vpath1, const vfs_path_t * vpath2) /* --------------------------------------------------------------------------------------------- */ /** - * If filename is NULL, then we just append PATH_SEP to the dir - */ - -char * -concat_dir_and_file (const char *dir, const char *file) -{ - int i = strlen (dir); - - if (dir[i - 1] == PATH_SEP) - return g_strconcat (dir, file, (char *) NULL); - else - return g_strconcat (dir, PATH_SEP_STR, file, (char *) NULL); -} - -/* --------------------------------------------------------------------------------------------- */ -/** * Append text to GList, remove all entries with the same text */ diff --git a/lib/util.h b/lib/util.h index 3e8c71467..195c34b9b 100644 --- a/lib/util.h +++ b/lib/util.h @@ -116,7 +116,6 @@ char *strip_password (char *path, int has_prefix); const char *strip_home_and_password (const char *dir); const char *extension (const char *); -char *concat_dir_and_file (const char *dir, const char *file); const char *unix_error_string (int error_num); const char *skip_separators (const char *s); const char *skip_numbers (const char *s); diff --git a/lib/vfs/direntry.c b/lib/vfs/direntry.c index 664bab659..b493b67e7 100644 --- a/lib/vfs/direntry.c +++ b/lib/vfs/direntry.c @@ -67,7 +67,7 @@ #include "lib/global.h" #include "lib/tty/tty.h" /* enable/disable interrupt key */ -#include "lib/util.h" /* concat_dir_and_file */ +#include "lib/util.h" /* custom_canonicalize_pathname() */ #if 0 #include "lib/widget.h" /* message() */ #endif diff --git a/lib/vfs/path.c b/lib/vfs/path.c index 45a0d7345..72d3ffcc9 100644 --- a/lib/vfs/path.c +++ b/lib/vfs/path.c @@ -35,7 +35,7 @@ #include "lib/global.h" #include "lib/strutil.h" -#include "lib/util.h" /* concat_dir_and_file */ +#include "lib/util.h" /* mc_build_filename() */ #include "lib/serialize.h" #include "vfs.h" @@ -149,7 +149,7 @@ vfs_canon (const char *path) g_free (local); curr_dir = vfs_get_current_dir (); - local = concat_dir_and_file (curr_dir, path); + local = mc_build_filename (curr_dir, path, NULL); g_free (curr_dir); } diff --git a/lib/widget/input_complete.c b/lib/widget/input_complete.c index 12043c200..486dcb248 100644 --- a/lib/widget/input_complete.c +++ b/lib/widget/input_complete.c @@ -646,7 +646,7 @@ command_completion_function (const char *_text, int state, input_complete_t flag if (cur_path >= path_end) break; expanded = tilde_expand (*cur_path ? cur_path : "."); - cur_word = concat_dir_and_file (expanded, text); + cur_word = mc_build_filename (expanded, text, NULL); g_free (expanded); canonicalize_pathname (cur_word); cur_path = strchr (cur_path, 0) + 1; @@ -986,7 +986,7 @@ try_complete (char *text, int *lc_start, int *lc_end, input_complete_t flags) *s = 0; if (*cdpath) { - r = concat_dir_and_file (cdpath, word); + r = mc_build_filename (cdpath, word, NULL); SHOW_C_CTX ("try_complete:filename_subst_2"); matches = completion_matches (r, filename_completion_function, flags); g_free (r); diff --git a/src/cons.handler.c b/src/cons.handler.c index 01a051593..c2a523ca6 100644 --- a/src/cons.handler.c +++ b/src/cons.handler.c @@ -44,7 +44,7 @@ #include "lib/tty/tty.h" #include "lib/skin.h" /* tty_set_normal_attrs */ #include "lib/tty/win.h" -#include "lib/util.h" /* concat_dir_and_file() */ +#include "lib/util.h" /* mc_build_filename() */ #include "consaver/cons.saver.h" @@ -205,7 +205,7 @@ handle_console_linux (console_action_t action) if (tty_name) { /* Exec the console save/restore handler */ - mc_conssaver = concat_dir_and_file (SAVERDIR, "cons.saver"); + mc_conssaver = mc_build_filename (SAVERDIR, "cons.saver", NULL); execl (mc_conssaver, "cons.saver", tty_name, (char *) NULL); } /* Console is not a tty or execl() failed */ @@ -383,8 +383,8 @@ console_save (void) for (i = 0; i < screen_shot.xsize * screen_shot.ysize; i++) { screen_shot.buf[i] = - (screen_shot.buf[i] & 0xff00) | (unsigned char) revmap.scrmap[screen_shot. - buf[i] & 0xff]; + (screen_shot.buf[i] & 0xff00) | (unsigned char) revmap. + scrmap[screen_shot.buf[i] & 0xff]; } } diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c index 09c8daab0..dd60c30a9 100644 --- a/src/editor/editwidget.c +++ b/src/editor/editwidget.c @@ -49,7 +49,7 @@ #include "lib/tty/color.h" /* tty_setcolor() */ #include "lib/skin.h" /* EDITOR_NORMAL_COLOR */ #include "lib/strutil.h" /* str_term_trim() */ -#include "lib/util.h" /* concat_dir_and_file() */ +#include "lib/util.h" /* mc_build_filename() */ #include "lib/widget.h" #include "lib/mcconfig.h" @@ -369,15 +369,17 @@ edit_file (const vfs_path_t * _file_vpath, int line) if (!made_directory) { - char *dir = concat_dir_and_file (mc_config_get_cache_path (), EDIT_DIR); + char *dir; + + dir = mc_build_filename (mc_config_get_cache_path (), EDIT_DIR, NULL); made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST); g_free (dir); - dir = concat_dir_and_file (mc_config_get_path (), EDIT_DIR); + dir = mc_build_filename (mc_config_get_path (), EDIT_DIR, NULL); made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST); g_free (dir); - dir = concat_dir_and_file (mc_config_get_data_path (), EDIT_DIR); + dir = mc_build_filename (mc_config_get_data_path (), EDIT_DIR, NULL); made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST); g_free (dir); } diff --git a/src/filemanager/ext.c b/src/filemanager/ext.c index ddd909643..99e8aa8c9 100644 --- a/src/filemanager/ext.c +++ b/src/filemanager/ext.c @@ -662,11 +662,11 @@ regex_command (const char *filename, const char *action, int *move_dir) { g_free (extension_file); check_stock_mc_ext: - extension_file = concat_dir_and_file (mc_global.sysconfig_dir, MC_LIB_EXT); + extension_file = mc_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, NULL); if (!exist_file (extension_file)) { g_free (extension_file); - extension_file = concat_dir_and_file (mc_global.share_data_dir, MC_LIB_EXT); + extension_file = mc_build_filename (mc_global.share_data_dir, MC_LIB_EXT, NULL); } mc_user_ext = 0; } diff --git a/src/filemanager/file.c b/src/filemanager/file.c index 0a3a03fca..21ccb094f 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -1047,7 +1047,7 @@ recursive_erase (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s) continue; if (!strcmp (next->d_name, "..")) continue; - path = concat_dir_and_file (s, next->d_name); + path = mc_build_filename (s, next->d_name, NULL); tmp_vpath = vfs_path_from_str (path); if (mc_lstat (tmp_vpath, &buf) != 0) { @@ -2049,7 +2049,7 @@ copy_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con /* Dive into subdir if exists */ if (toplevel && ctx->dive_into_subdirs) { - dest_dir = concat_dir_and_file (d, x_basename (s)); + dest_dir = mc_build_filename (d, x_basename (s), NULL); } else { @@ -2118,7 +2118,7 @@ copy_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con continue; /* get the filename and add it to the src directory */ - path = concat_dir_and_file (s, next->d_name); + path = mc_build_filename (s, next->d_name, NULL); tmp_vpath = vfs_path_from_str (path); (*ctx->stat_func) (tmp_vpath, &buf); @@ -2126,7 +2126,7 @@ copy_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con { char *mdpath; - mdpath = concat_dir_and_file (dest_dir, next->d_name); + mdpath = mc_build_filename (dest_dir, next->d_name, NULL); /* * From here, we just intend to recursively copy subdirs, not * the double functionality of copying different when the target @@ -2141,7 +2141,7 @@ copy_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con { char *dest_file; - dest_file = concat_dir_and_file (dest_dir, x_basename (path)); + dest_file = mc_build_filename (dest_dir, x_basename (path), NULL); return_status = copy_file_file (tctx, ctx, path, dest_file); g_free (dest_file); } @@ -2245,7 +2245,7 @@ move_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con move_over = TRUE; } else - destdir = concat_dir_and_file (d, x_basename (s)); + destdir = mc_build_filename (d, x_basename (s), NULL); destdir_vpath = vfs_path_from_str (destdir); @@ -2861,7 +2861,7 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl char *repl_dest, *temp2; repl_dest = mc_search_prepare_replace_str2 (ctx->search_handle, dest); - temp2 = concat_dir_and_file (repl_dest, temp); + temp2 = mc_build_filename (repl_dest, temp, NULL); g_free (temp); g_free (repl_dest); g_free (dest); @@ -2962,7 +2962,7 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl char *temp2, *temp3, *repl_dest; repl_dest = mc_search_prepare_replace_str2 (ctx->search_handle, dest); - temp2 = concat_dir_and_file (repl_dest, temp); + temp2 = mc_build_filename (repl_dest, temp, NULL); g_free (temp); g_free (repl_dest); temp3 = source_with_path_str; diff --git a/src/filemanager/filenot.c b/src/filemanager/filenot.c index a04fa61f1..721ab2152 100644 --- a/src/filemanager/filenot.c +++ b/src/filemanager/filenot.c @@ -105,7 +105,7 @@ my_mkdir_rec (char *s, mode_t mode) return -1; } - p = concat_dir_and_file (s, ".."); + p = mc_build_filename (s, "..", NULL); { vfs_path_t *vpath; diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index 4a169ae10..715863050 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -2431,7 +2431,7 @@ do_enter_on_file_entry (file_entry * fe) char *tmp_path; tmp_path = vfs_path_to_str (current_panel->cwd_vpath); - full_name = concat_dir_and_file (tmp_path, fe->fname); + full_name = mc_build_filename (tmp_path, fe->fname, NULL); g_free (tmp_path); } if (!is_exe (fe->st.st_mode) || !if_link_is_exe (full_name, fe)) @@ -2602,7 +2602,7 @@ chdir_to_readlink (WPanel * panel) char *tmp_path; tmp_path = vfs_path_to_str (panel->cwd_vpath); - new_dir = concat_dir_and_file (tmp_path, buffer); + new_dir = mc_build_filename (tmp_path, buffer, NULL); g_free (tmp_path); } diff --git a/src/filemanager/usermenu.c b/src/filemanager/usermenu.c index bf0e7feed..36957f598 100644 --- a/src/filemanager/usermenu.c +++ b/src/filemanager/usermenu.c @@ -953,19 +953,20 @@ user_menu_cmd (struct WEdit * edit_widget, const char *menu_file, int selected_e { g_free (menu); menu = - concat_dir_and_file (mc_config_get_home_dir (), - edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU); + mc_build_filename (mc_config_get_home_dir (), + edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU, NULL); if (!exist_file (menu)) { g_free (menu); menu = - concat_dir_and_file (mc_global.sysconfig_dir, - edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU); + mc_build_filename (mc_global.sysconfig_dir, + edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU, NULL); if (!exist_file (menu)) { g_free (menu); - menu = concat_dir_and_file - (mc_global.share_data_dir, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU); + menu = mc_build_filename + (mc_global.share_data_dir, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU, + NULL); } } } diff --git a/src/setup.c b/src/setup.c index 1606a26ac..791a2bc84 100644 --- a/src/setup.c +++ b/src/setup.c @@ -827,7 +827,7 @@ setup_init (void) profile = mc_config_get_full_path (MC_CONFIG_FILE); if (!exist_file (profile)) { - inifile = concat_dir_and_file (mc_global.sysconfig_dir, "mc.ini"); + inifile = mc_build_filename (mc_global.sysconfig_dir, "mc.ini", NULL); if (exist_file (inifile)) { g_free (profile); @@ -836,7 +836,7 @@ setup_init (void) else { g_free (inifile); - inifile = concat_dir_and_file (mc_global.share_data_dir, "mc.ini"); + inifile = mc_build_filename (mc_global.share_data_dir, "mc.ini", NULL); if (exist_file (inifile)) { g_free (profile); diff --git a/src/vfs/ftpfs/ftpfs.c b/src/vfs/ftpfs/ftpfs.c index fe788db00..8897ad67a 100644 --- a/src/vfs/ftpfs/ftpfs.c +++ b/src/vfs/ftpfs/ftpfs.c @@ -65,7 +65,7 @@ What to do with this? int f = !strcmp( remote_path, "/~" ); if (f || !strncmp( remote_path, "/~/", 3 )) { char *s; - s = concat_dir_and_file( qhome (*bucket), remote_path +3-f ); + s = mc_build_filename ( qhome (*bucket), remote_path +3-f, NULL ); g_free (remote_path); remote_path = s; } @@ -1682,8 +1682,10 @@ ftpfs_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path sock = ftpfs_open_data_connection (me, super, "LIST -la", 0, TYPE_ASCII, 0); else { + char *path; + /* Trailing "/." is necessary if remote_path is a symlink */ - char *path = concat_dir_and_file (remote_path, "."); + path = mc_build_filename (remote_path, ".", NULL); sock = ftpfs_open_data_connection (me, super, "LIST -la", path, TYPE_ASCII, 0); g_free (path); } diff --git a/src/vfs/smbfs/smbfs.c b/src/vfs/smbfs/smbfs.c index 9d2979601..9246d16de 100644 --- a/src/vfs/smbfs/smbfs.c +++ b/src/vfs/smbfs/smbfs.c @@ -1360,7 +1360,8 @@ smbfs_get_path (smbfs_connection ** sc, const vfs_path_t * vpath) if (f != 0 || strncmp (remote_path, "/~/", 3) == 0) { char *s; - s = concat_dir_and_file ((*sc)->home, remote_path + 3 - f); + + s = mc_build_filename ((*sc)->home, remote_path + 3 - f, NULL); g_free (remote_path); remote_path = s; } @@ -1728,8 +1729,8 @@ smbfs_stat (const vfs_path_t * vpath, struct stat *buf) if (path_element->class != &vfs_smbfs_ops) return -1; - while (*p == '/') /* '/' leading server name */ - p++; /* probably came from server browsing */ + while (*p == '/') /* '/' leading server name */ + p++; /* probably came from server browsing */ pp = strchr (p, '/'); /* advance past next '/' */ at = strchr (p, '@'); -- 2.11.4.GIT