Browse Source

Added function mc_config_get_full_path() for search user's config files by short names.

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Slava Zanko 13 years ago
parent
commit
6c32fa3b84
10 changed files with 80 additions and 43 deletions
  1. 1 1
      lib/filehighlight/ini-file-read.c
  2. 1 1
      lib/logging.c
  3. 2 0
      lib/mcconfig.h
  4. 38 7
      lib/mcconfig/paths.c
  5. 2 2
      lib/util.c
  6. 2 2
      lib/widget/dialog.c
  7. 2 2
      lib/widget/history.c
  8. 4 4
      src/clipboard.c
  9. 4 4
      src/editor/edit.c
  10. 24 20
      src/editor/editcmd.c

+ 1 - 1
lib/filehighlight/ini-file-read.c

@@ -199,7 +199,7 @@ mc_fhl_init_from_standard_files (mc_fhl_t * fhl)
     gboolean ok;
 
     /* ${XDG_CONFIG_HOME}/mc/filehighlight.ini */
-    name = g_build_filename (mc_config_get_data_path (), MC_FHL_INI_FILE, (char *) NULL);
+    name = mc_config_get_full_path (MC_FHL_INI_FILE);
     ok = mc_fhl_read_ini_file (fhl, name);
     g_free (name);
     if (ok)

+ 1 - 1
lib/logging.c

@@ -104,7 +104,7 @@ get_log_filename (void)
     if (mc_config_has_param (mc_main_config, CONFIG_GROUP_NAME, CONFIG_KEY_NAME_FILE))
         return mc_config_get_string (mc_main_config, CONFIG_GROUP_NAME, CONFIG_KEY_NAME_FILE, NULL);
 
-    return g_build_filename (mc_config_get_cache_path (), "mc.log", NULL);
+    return mc_config_get_full_path ("mc.log");
 }
 
 /* --------------------------------------------------------------------------------------------- */

+ 2 - 0
lib/mcconfig.h

@@ -108,6 +108,8 @@ const char *mc_config_get_path (void);
 
 const char *mc_config_get_home_dir (void);
 
+char *mc_config_get_full_path (const char *config_name);
+
 
 /*** inline functions ****************************************************************************/
 

+ 38 - 7
lib/mcconfig/paths.c

@@ -60,7 +60,7 @@ static const struct
 
     char **new_basedir;
     const char *new_filename;
-} mc_config_migrate_rules[] =
+} mc_config_files_reference[] =
 {
     /* *INDENT-OFF* */
     /* config */
@@ -74,8 +74,9 @@ static const struct
     { "cedit" PATH_SEP_STR "edit.indent.rc",   &mc_config_str, EDIT_DIR PATH_SEP_STR "edit.indent.rc"},
     { "cedit" PATH_SEP_STR "edit.spell.rc",    &mc_config_str, EDIT_DIR PATH_SEP_STR "edit.spell.rc"},
     { "panels.ini",                            &mc_config_str, MC_PANELS_FILE},
+
     /* User should move this file with applying some changes in file */
-/*  { "bindings",                              &mc_config_str, MC_FILEBIND_FILE}, */
+    { "",                                      &mc_config_str, MC_FILEBIND_FILE},
 
     /* data */
     { "skins",                                 &mc_data_str, MC_SKINS_SUBDIR},
@@ -86,6 +87,7 @@ static const struct
     { "history",                               &mc_data_str, MC_HISTORY_FILE},
     { "filepos",                               &mc_data_str, MC_FILEPOS_FILE},
     { "cedit" PATH_SEP_STR "cooledit.clip",    &mc_data_str, EDIT_CLIP_FILE},
+    { "",                                      &mc_data_str, MC_MACRO_FILE},
 
     /* cache */
     { "log",                                   &mc_cache_str, "mc.log"},
@@ -239,7 +241,7 @@ mc_config_fix_migrated_rules (void)
             char *new_name;
 
             new_name = g_build_filename (*mc_config_migrate_rules_fix[rule_index].new_basedir,
-                                         mc_config_migrate_rules[rule_index].new_filename, NULL);
+                                         mc_config_files_reference[rule_index].new_filename, NULL);
 
             rename (old_name, new_name);
 
@@ -394,19 +396,21 @@ mc_config_migrate_from_old_place (GError ** error)
     g_free (mc_config_init_one_config_path (mc_data_str, EDIT_DIR, error));
 #endif /* MC_HOMEDIR_XDG */
 
-    for (rule_index = 0; mc_config_migrate_rules[rule_index].old_filename != NULL; rule_index++)
+    for (rule_index = 0; mc_config_files_reference[rule_index].old_filename != NULL; rule_index++)
     {
         char *old_name;
+        if (*mc_config_files_reference[rule_index].old_filename == '\0')
+            continue;
 
         old_name =
-            g_build_filename (old_dir, mc_config_migrate_rules[rule_index].old_filename, NULL);
+            g_build_filename (old_dir, mc_config_files_reference[rule_index].old_filename, NULL);
 
         if (g_file_test (old_name, G_FILE_TEST_EXISTS))
         {
             char *new_name;
 
-            new_name = g_build_filename (*mc_config_migrate_rules[rule_index].new_basedir,
-                                         mc_config_migrate_rules[rule_index].new_filename, NULL);
+            new_name = g_build_filename (*mc_config_files_reference[rule_index].new_basedir,
+                                         mc_config_files_reference[rule_index].new_filename, NULL);
 
             mc_config_copy (old_name, new_name, error);
 
@@ -451,3 +455,30 @@ mc_config_deprecated_dir_present (void)
 }
 
 /* --------------------------------------------------------------------------------------------- */
+/**
+ * Get full path to config file by short name.
+ *
+ * @param config_name short name
+ * @return full path to config file
+ */
+
+char *
+mc_config_get_full_path (const char *config_name)
+{
+    size_t rule_index;
+
+    if (config_name == NULL)
+        return NULL;
+
+    for (rule_index = 0; mc_config_files_reference[rule_index].old_filename != NULL; rule_index++)
+    {
+        if (strcmp (config_name, mc_config_files_reference[rule_index].new_filename) == 0)
+        {
+            return g_build_filename (*mc_config_files_reference[rule_index].new_basedir,
+                                     mc_config_files_reference[rule_index].new_filename, NULL);
+        }
+    }
+    return NULL;
+}
+
+/* --------------------------------------------------------------------------------------------- */

+ 2 - 2
lib/util.c

@@ -1277,7 +1277,7 @@ load_file_position (const char *filename, long *line, long *column, off_t * offs
     *offset = 0;
 
     /* open file with positions */
-    fn = g_build_filename (mc_config_get_cache_path (), MC_FILEPOS_FILE, NULL);
+    fn = mc_config_get_full_path (MC_FILEPOS_FILE);
     f = fopen (fn, "r");
     g_free (fn);
     if (f == NULL)
@@ -1367,7 +1367,7 @@ save_file_position (const char *filename, long line, long column, off_t offset,
         filepos_max_saved_entries = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
                                                        "filepos_max_saved_entries", 1024);
 
-    fn = g_build_filename (mc_config_get_cache_path (), MC_FILEPOS_FILE, NULL);
+    fn = mc_config_get_full_path (MC_FILEPOS_FILE);
     if (fn == NULL)
         goto early_error;
 

+ 2 - 2
lib/widget/dialog.c

@@ -165,7 +165,7 @@ dlg_read_history (Dlg_head * h)
     if (num_history_items_recorded == 0)        /* this is how to disable */
         return;
 
-    profile = g_build_filename (mc_config_get_cache_path (), MC_HISTORY_FILE, NULL);
+    profile = mc_config_get_full_path (MC_HISTORY_FILE);
     event_data.cfg = mc_config_init (profile);
     event_data.receiver = NULL;
 
@@ -1192,7 +1192,7 @@ dlg_save_history (Dlg_head * h)
     if (num_history_items_recorded == 0)        /* this is how to disable */
         return;
 
-    profile = g_build_filename (mc_config_get_cache_path (), MC_HISTORY_FILE, (char *) NULL);
+    profile = mc_config_get_full_path (MC_HISTORY_FILE);
     i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
     if (i != -1)
         close (i);

+ 2 - 2
lib/widget/history.c

@@ -150,7 +150,7 @@ history_get (const char *input_name)
     if ((input_name == NULL) || (*input_name == '\0'))
         return NULL;
 
-    profile = g_build_filename (mc_config_get_cache_path (), MC_HISTORY_FILE, NULL);
+    profile = mc_config_get_full_path (MC_HISTORY_FILE);
     cfg = mc_config_init (profile);
 
     hist = history_load (cfg, input_name);
@@ -303,7 +303,7 @@ history_put (const char *input_name, GList * h)
     if (h == NULL)
         return;
 
-    profile = g_build_filename (mc_config_get_cache_path (), MC_HISTORY_FILE, (char *) NULL);
+    profile = mc_config_get_full_path (MC_HISTORY_FILE);
 
     i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
     if (i != -1)

+ 4 - 4
src/clipboard.c

@@ -77,7 +77,7 @@ clipboard_file_to_ext_clip (const gchar * event_group_name, const gchar * event_
     if (d == NULL || clipboard_store_path == NULL || clipboard_store_path[0] == '\0')
         return TRUE;
 
-    tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE);
+    tmp = mc_config_get_full_path (EDIT_CLIP_FILE);
     cmd = g_strconcat (clipboard_store_path, " ", tmp, " 2>/dev/null", (char *) NULL);
 
     if (cmd != NULL)
@@ -107,7 +107,7 @@ clipboard_file_from_ext_clip (const gchar * event_group_name, const gchar * even
     if (d == NULL || clipboard_paste_path == NULL || clipboard_paste_path[0] == '\0')
         return TRUE;
 
-    tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE);
+    tmp = mc_config_get_full_path (EDIT_CLIP_FILE);
     cmd = g_strconcat (clipboard_paste_path, " > ", tmp, " 2>/dev/null", (char *) NULL);
 
     if (cmd != NULL)
@@ -138,7 +138,7 @@ clipboard_text_to_file (const gchar * event_group_name, const gchar * event_name
     if (text == NULL)
         return FALSE;
 
-    fname = g_build_filename (mc_config_get_cache_path (), EDIT_CLIP_FILE, NULL);
+    fname = mc_config_get_full_path (EDIT_CLIP_FILE);
     file = mc_open (fname, O_CREAT | O_WRONLY | O_TRUNC,
                     S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_BINARY);
     g_free (fname);
@@ -169,7 +169,7 @@ clipboard_text_from_file (const gchar * event_group_name, const gchar * event_na
     (void) event_name;
     (void) init_data;
 
-    fname = g_build_filename (mc_config_get_cache_path (), EDIT_CLIP_FILE, NULL);
+    fname = mc_config_get_full_path (EDIT_CLIP_FILE);
     f = fopen (fname, "r");
     g_free (fname);
 

+ 4 - 4
src/editor/edit.c

@@ -714,10 +714,10 @@ edit_get_prev_utf (WEdit * edit, long byte_index, int *char_width)
     cursor_buf_ptr = utf8_buf + (2 * UTF8_CHAR_LEN);
     str = g_utf8_find_prev_char (utf8_buf, cursor_buf_ptr);
 
-    if (str == NULL || g_utf8_next_char(str) != cursor_buf_ptr)
+    if (str == NULL || g_utf8_next_char (str) != cursor_buf_ptr)
     {
         *char_width = 1;
-        return *(cursor_buf_ptr-1);
+        return *(cursor_buf_ptr - 1);
     }
     else
     {
@@ -726,7 +726,7 @@ edit_get_prev_utf (WEdit * edit, long byte_index, int *char_width)
         if (res < 0)
         {
             *char_width = 1;
-            return *(cursor_buf_ptr-1);
+            return *(cursor_buf_ptr - 1);
         }
         else
         {
@@ -1833,7 +1833,7 @@ user_menu (WEdit * edit, const char *menu_file, int selected_entry)
     long start_mark, end_mark;
     struct stat status;
 
-    block_file = concat_dir_and_file (mc_config_get_cache_path (), EDIT_BLOCK_FILE);
+    block_file = mc_config_get_full_path (EDIT_BLOCK_FILE);
     curs = edit->curs1;
     nomark = eval_marks (edit, &start_mark, &end_mark);
     if (nomark == 0)

+ 24 - 20
src/editor/editcmd.c

@@ -525,7 +525,7 @@ edit_load_syntax_file (WEdit * edit)
     {
         char *buffer;
 
-        buffer = concat_dir_and_file (mc_config_get_data_path (), EDIT_SYNTAX_FILE);
+        buffer = mc_config_get_full_path (EDIT_SYNTAX_FILE);
         check_for_default (extdir, buffer);
         edit_load_file_from_filename (edit, buffer);
         g_free (buffer);
@@ -566,7 +566,7 @@ edit_load_menu_file (WEdit * edit)
         break;
 
     case 1:
-        buffer = concat_dir_and_file (mc_config_get_data_path (), EDIT_HOME_MENU);
+        buffer = mc_config_get_full_path (EDIT_HOME_MENU);
         check_for_default (menufile, buffer);
         break;
 
@@ -937,7 +937,7 @@ edit_save_block_to_clip_file (WEdit * edit, long start, long finish)
 {
     int ret;
     gchar *tmp;
-    tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE);
+    tmp = mc_config_get_full_path (EDIT_CLIP_FILE);
     ret = edit_save_block (edit, tmp, start, finish);
     g_free (tmp);
     return ret;
@@ -1311,7 +1311,7 @@ edit_delete_macro (WEdit * edit, int hotkey)
         edit_macro_sort_by_hotkey ();
     }
 
-    macros_fname = g_build_filename (mc_config_get_data_path (), MC_MACRO_FILE, (char *) NULL);
+    macros_fname = mc_config_get_full_path (MC_MACRO_FILE);
     macros_config = mc_config_init (macros_fname);
     g_free (macros_fname);
 
@@ -1645,7 +1645,7 @@ edit_store_macro_cmd (WEdit * edit)
 
     edit_delete_macro (edit, hotkey);
 
-    macros_fname = g_build_filename (mc_config_get_data_path (), MC_MACRO_FILE, (char *) NULL);
+    macros_fname = mc_config_get_full_path (MC_MACRO_FILE);
     macros_config = mc_config_init (macros_fname);
     g_free (macros_fname);
 
@@ -1749,7 +1749,7 @@ edit_load_macro_cmd (WEdit * edit)
 
     (void) edit;
 
-    macros_fname = g_build_filename (mc_config_get_data_path (), MC_MACRO_FILE, (char *) NULL);
+    macros_fname = mc_config_get_full_path (MC_MACRO_FILE);
     macros_config = mc_config_init (macros_fname);
     g_free (macros_fname);
 
@@ -2683,7 +2683,7 @@ edit_paste_from_X_buf_cmd (WEdit * edit)
     gchar *tmp;
     /* try use external clipboard utility */
     mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_file_from_ext_clip", NULL);
-    tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE);
+    tmp = mc_config_get_full_path (EDIT_CLIP_FILE);
     edit_insert_file (edit, tmp);
     g_free (tmp);
 }
@@ -2744,7 +2744,7 @@ edit_save_block_cmd (WEdit * edit)
     if (eval_marks (edit, &start_mark, &end_mark))
         return 1;
 
-    tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE);
+    tmp = mc_config_get_full_path (EDIT_CLIP_FILE);
     exp =
         input_expand_dialog (_("Save block"), _("Enter file name:"),
                              MC_HISTORY_EDIT_SAVE_BLOCK, tmp);
@@ -2786,7 +2786,7 @@ edit_insert_file_cmd (WEdit * edit)
     gchar *tmp;
     char *exp;
 
-    tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE);
+    tmp = mc_config_get_full_path (EDIT_CLIP_FILE);
     exp = input_expand_dialog (_("Insert file"), _("Enter file name:"),
                                MC_HISTORY_EDIT_INSERT_FILE, tmp);
     g_free (tmp);
@@ -2824,7 +2824,7 @@ int
 edit_sort_cmd (WEdit * edit)
 {
     static char *old = 0;
-    char *exp, *tmp;
+    char *exp, *tmp, *tmp_edit_block_name, *tmp_edit_temp_name;
     long start_mark, end_mark;
     int e;
 
@@ -2834,7 +2834,7 @@ edit_sort_cmd (WEdit * edit)
         return 0;
     }
 
-    tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_BLOCK_FILE);
+    tmp = mc_config_get_full_path (EDIT_BLOCK_FILE);
     edit_save_block (edit, tmp, start_mark, end_mark);
     g_free (tmp);
 
@@ -2846,10 +2846,14 @@ edit_sort_cmd (WEdit * edit)
         return 1;
     g_free (old);
     old = exp;
+    tmp_edit_block_name = mc_config_get_full_path (EDIT_BLOCK_FILE);
+    tmp_edit_temp_name = mc_config_get_full_path (EDIT_TEMP_FILE);
     tmp =
-        g_strconcat (" sort ", exp, " ", mc_config_get_cache_path (), PATH_SEP_STR EDIT_BLOCK_FILE,
-                     " > ", mc_config_get_cache_path (), PATH_SEP_STR EDIT_TEMP_FILE,
-                     (char *) NULL);
+        g_strconcat (" sort ", exp, " ", tmp_edit_block_name,
+                     " > ", tmp_edit_temp_name, (char *) NULL);
+    g_free (tmp_edit_temp_name);
+    g_free (tmp_edit_block_name);
+
     e = system (tmp);
     g_free (tmp);
     if (e)
@@ -2873,7 +2877,7 @@ edit_sort_cmd (WEdit * edit)
 
     if (edit_block_delete_cmd (edit))
         return 1;
-    tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_TEMP_FILE);
+    tmp = mc_config_get_full_path (EDIT_TEMP_FILE);
     edit_insert_file (edit, tmp);
     g_free (tmp);
     return 0;
@@ -2888,7 +2892,7 @@ edit_sort_cmd (WEdit * edit)
 int
 edit_ext_cmd (WEdit * edit)
 {
-    char *exp, *tmp;
+    char *exp, *tmp, *tmp_edit_temp_file;
     int e;
 
     exp =
@@ -2898,9 +2902,9 @@ edit_ext_cmd (WEdit * edit)
     if (!exp)
         return 1;
 
-    tmp =
-        g_strconcat (exp, " > ", mc_config_get_cache_path (), PATH_SEP_STR EDIT_TEMP_FILE,
-                     (char *) NULL);
+    tmp_edit_temp_file = mc_config_get_full_path (EDIT_TEMP_FILE);
+    tmp = g_strconcat (exp, " > ", tmp_edit_temp_file, (char *) NULL);
+    g_free (tmp_edit_temp_file);
     e = system (tmp);
     g_free (tmp);
     g_free (exp);
@@ -2912,7 +2916,7 @@ edit_ext_cmd (WEdit * edit)
     }
 
     edit->force |= REDRAW_COMPLETELY;
-    tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_TEMP_FILE);
+    tmp = mc_config_get_full_path (EDIT_TEMP_FILE);
     edit_insert_file (edit, tmp);
     g_free (tmp);
     return 0;

Some files were not shown because too many files changed in this diff