From 8562a215beb808c5d0a13a86fb9553676fc5e1be 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 @@ -1134,22 +1134,6 @@ diff_two_paths (const vfs_path_t * vpath1, const vfs_path_t * vpath2) return buf; } -/* --------------------------------------------------------------------------------------------- */ -/** - * 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 fc4aa8c0a..40fc20281 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" @@ -143,7 +143,7 @@ vfs_canon (const char *path) char *local, *result, *curr_dir; 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); result = vfs_canon (local); 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 c834b51a5..28ade03ee 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" @@ -366,15 +366,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 a703c9ba4..f515e8dc2 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -1045,7 +1045,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) { @@ -2047,7 +2047,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 { @@ -2116,7 +2116,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); @@ -2124,7 +2124,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 @@ -2139,7 +2139,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); } @@ -2243,7 +2243,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); @@ -2859,7 +2859,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); @@ -2960,7 +2960,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 a5630bbc9..d859cf46c 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -2506,7 +2506,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)) @@ -2677,7 +2677,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 63537ec4b..cb45f9127 100644 --- a/src/filemanager/usermenu.c +++ b/src/filemanager/usermenu.c @@ -954,19 +954,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 a3fc67923..da15e2cf5 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 c94824785..77f4c2448 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; } @@ -1680,8 +1680,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, '@');