diff --git a/src/ChangeLog b/src/ChangeLog index 2f62212e5..188127fca 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ +2001-06-09 Pavel Roskin + + * util.c (load_mc_home_file): New function. Load file from + mc_home, but try localized version of that file first. + * util.h: Declare load_mc_home_file(). + * help.c (interactive_display): Use load_mc_home_file(). If the + first argument is NULL assume mc.hlp. + * dlg.c (dialog_handle_key): Use interactive_display() without + specifying the help file. + * tree.c (tree_copy): Likewise. + * cmd.c (help_cmd): Likewise. + (get_random_hint): Use load_mc_home_file(). + 2001-06-07 Andrew V. Samoilov * charsets.h: Define CHARSETS_INDEX without leading LIBDIR. diff --git a/src/cmd.c b/src/cmd.c index 7d71155bd..66e96dfe1 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1201,9 +1201,7 @@ void other_symlink_cmd (void) void help_cmd (void) { - char *hlpfile = concat_dir_and_file (mc_home, _("mc.hlp")); - interactive_display (hlpfile, "[main]"); - g_free (hlpfile); + interactive_display (NULL, "[main]"); } void view_panel_cmd (void) @@ -1269,8 +1267,6 @@ char *guess_message_value (unsigned want_info) char *get_random_hint (void) { char *data, *result, *eol; - char *hintfile_base, *hintfile; - char *lang; int len; int start; @@ -1294,24 +1290,7 @@ char *get_random_hint (void) last_sec = tv.tv_sec; #endif - hintfile_base = concat_dir_and_file (mc_home, MC_HINT); - lang = guess_message_value (0); - - hintfile = g_strdup_printf ("%s.%s", hintfile_base, lang); - data = load_file (hintfile); - g_free (hintfile); - - if (!data) { - hintfile = g_strdup_printf ("%s.%.2s", hintfile_base, lang); - data = load_file (hintfile); - g_free (hintfile); - - if (!data) - data = load_file (hintfile_base); - } - - g_free (lang); - g_free (hintfile_base); + data = load_mc_home_file (MC_HINT, NULL); if (!data) return 0; diff --git a/src/dlg.c b/src/dlg.c index 85b09c0d5..87291293b 100644 --- a/src/dlg.c +++ b/src/dlg.c @@ -630,8 +630,6 @@ void dlg_stop (Dlg_head *h) static INLINE void dialog_handle_key (Dlg_head *h, int d_key) { - char *hlpfile; - switch (d_key){ case KEY_LEFT: case KEY_UP: @@ -644,9 +642,7 @@ static INLINE void dialog_handle_key (Dlg_head *h, int d_key) break; case KEY_F(1): - hlpfile = concat_dir_and_file (mc_home, _("mc.hlp")); - interactive_display (hlpfile, h->help_ctx); - g_free (hlpfile); + interactive_display (NULL, h->help_ctx); do_refresh (); break; diff --git a/src/help.c b/src/help.c index 26909d22d..3d5558945 100644 --- a/src/help.c +++ b/src/help.c @@ -755,14 +755,26 @@ interactive_display_finish (void) void interactive_display (char *filename, char *node) { - WButtonBar *help_bar; - Widget *md; - - if ((data = load_file (filename)) == 0){ + WButtonBar *help_bar; + Widget *md; + char *hlpfile = filename; + + if (filename) + data = load_file (filename); + else + data = load_mc_home_file ("mc.hlp", &hlpfile); + + if (data == NULL){ message (1, MSG_ERROR, _(" Can't open file %s \n %s "), - filename, unix_error_string (errno)); - return; + hlpfile, unix_error_string (errno)); } + + if (!filename) + g_free (hlpfile); + + if (!data) + return; + if (!(main_node = search_string (data, node))){ message (1, MSG_ERROR, _(" Can't find node %s in help file "), node); interactive_display_finish (); diff --git a/src/tree.c b/src/tree.c index 2e923d7f0..e266f74df 100644 --- a/src/tree.c +++ b/src/tree.c @@ -651,9 +651,7 @@ void tree_copy (WTree *tree, char *default_dest) static void tree_help_cmd (void) { - char *hlpfile = concat_dir_and_file (mc_home, _("mc.hlp")); - interactive_display (hlpfile, "[Directory Tree]"); - g_free (hlpfile); + interactive_display (NULL, "[Directory Tree]"); } static int tree_copy_cmd (WTree *tree) diff --git a/src/util.c b/src/util.c index 2e1d50803..2f69a0a59 100644 --- a/src/util.c +++ b/src/util.c @@ -74,6 +74,8 @@ #include "global.h" #include "profile.h" #include "user.h" /* expand_format */ +#include "main.h" /* mc_home */ +#include "cmd.h" /* guess_message_value */ #include "../vfs/vfs.h" #ifdef HAVE_CHARSET @@ -607,6 +609,43 @@ char *load_file (char *filename) } } +char *load_mc_home_file (const char *filename, char ** allocated_filename) +{ + char *hintfile_base, *hintfile; + char *lang; + char *data; + + hintfile_base = concat_dir_and_file (mc_home, filename); + lang = guess_message_value (0); + + hintfile = g_strdup_printf ("%s.%s", hintfile_base, lang); + data = load_file (hintfile); + + if (!data) { + g_free (hintfile); + hintfile = g_strdup_printf ("%s.%.2s", hintfile_base, lang); + data = load_file (hintfile); + + if (!data) { + g_free (hintfile); + hintfile = hintfile_base; + data = load_file (hintfile_base); + } + } + + g_free (lang); + + if (hintfile != hintfile_base) + g_free (hintfile_base); + + if (allocated_filename) + *allocated_filename = hintfile; + else + g_free (hintfile); + + return data; +} + /* Check strftime() results. Some systems (i.e. Solaris) have different short-month-name sizes for different locales */ size_t i18n_checktimelength (void) diff --git a/src/util.h b/src/util.h index 6b0e53b84..4615c5455 100644 --- a/src/util.h +++ b/src/util.h @@ -46,6 +46,7 @@ int set_int (char *, char *, int); int get_int (char *, char *, int); char *load_file (char *filename); +char *load_mc_home_file (const char *filename, char ** allocated_filename); #include "fs.h" #ifndef S_ISLNK diff --git a/src/view.c b/src/view.c index e5c5dbb30..b886cb1a2 100644 --- a/src/view.c +++ b/src/view.c @@ -1825,9 +1825,7 @@ static void do_normal_search (void *xview, char *text) /* Real view only */ static void help_cmd (void) { - char *hlpfile = concat_dir_and_file (mc_home, _("mc.hlp")); - interactive_display (hlpfile, "[Internal File Viewer]"); - g_free (hlpfile); + interactive_display (NULL, "[Internal File Viewer]"); /* view_refresh (0); */