Merge branch '394_history_file'
* 394_history_file: History: don't drop valid keys after 1st invalid one. REBASE: Need to join to previous commit Fixed return value of mc_config_new() function Ticket #394: handle the empty ~/.mc/history file correctly.
Этот коммит содержится в:
Коммит
b72e83193a
@ -19,8 +19,14 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "global.h"
|
||||
|
||||
#include "../../vfs/vfs.h" /* mc_stat */
|
||||
|
||||
#include "mcconfig.h"
|
||||
|
||||
/*** global variables **************************************************/
|
||||
@ -42,6 +48,7 @@ mc_config_t *
|
||||
mc_config_init (const gchar * ini_path)
|
||||
{
|
||||
mc_config_t *mc_config;
|
||||
struct stat st;
|
||||
|
||||
mc_config = g_try_malloc0 (sizeof (mc_config_t));
|
||||
|
||||
@ -59,13 +66,13 @@ mc_config_init (const gchar * ini_path)
|
||||
return mc_config;
|
||||
}
|
||||
|
||||
if (!g_key_file_load_from_file
|
||||
(mc_config->handle, ini_path, G_KEY_FILE_KEEP_COMMENTS, NULL))
|
||||
if (!mc_stat (ini_path, &st) && st.st_size)
|
||||
{
|
||||
g_key_file_free (mc_config->handle);
|
||||
g_free (mc_config);
|
||||
return NULL;
|
||||
/* file present and not empty */
|
||||
g_key_file_load_from_file
|
||||
(mc_config->handle, ini_path, G_KEY_FILE_KEEP_COMMENTS, NULL);
|
||||
}
|
||||
|
||||
mc_config->ini_path = g_strdup (ini_path);
|
||||
return mc_config;
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ mc_config_get_groups (mc_config_t * mc_config, gsize * len)
|
||||
if (!mc_config)
|
||||
{
|
||||
ret = g_try_malloc0 (sizeof (gchar **));
|
||||
*len=0;
|
||||
return ret;
|
||||
}
|
||||
ret = g_key_file_get_groups (mc_config->handle, len);
|
||||
@ -62,6 +63,7 @@ mc_config_get_keys (mc_config_t * mc_config, const gchar * group, gsize * len)
|
||||
if (!mc_config || !group)
|
||||
{
|
||||
ret = g_try_malloc0 (sizeof (gchar **));
|
||||
*len=0;
|
||||
return ret;
|
||||
}
|
||||
ret = g_key_file_get_keys (mc_config->handle, group, len, NULL);
|
||||
|
36
src/widget.c
36
src/widget.c
@ -891,39 +891,39 @@ GList *
|
||||
history_get (const char *input_name)
|
||||
{
|
||||
int i;
|
||||
GList *hist;
|
||||
GList *hist = NULL;
|
||||
char *profile;
|
||||
mc_config_t *cfg;
|
||||
char **keys;
|
||||
size_t keys_num = 0;
|
||||
char *this_entry;
|
||||
|
||||
hist = NULL;
|
||||
|
||||
if (!num_history_items_recorded) /* this is how to disable */
|
||||
return NULL;
|
||||
if (!input_name)
|
||||
return NULL;
|
||||
if (!*input_name)
|
||||
if (!input_name || !*input_name)
|
||||
return NULL;
|
||||
|
||||
profile = concat_dir_and_file (home_dir, HISTORY_FILE_NAME);
|
||||
cfg = mc_config_init(profile);
|
||||
for (i = 0;; i++) {
|
||||
cfg = mc_config_init (profile);
|
||||
|
||||
/* get number of keys */
|
||||
keys = mc_config_get_keys (cfg, input_name, &keys_num);
|
||||
g_strfreev (keys);
|
||||
|
||||
for (i = 0; i < keys_num; i++) {
|
||||
char key_name[BUF_TINY];
|
||||
g_snprintf (key_name, sizeof (key_name), "%d", i);
|
||||
this_entry = mc_config_get_string(cfg, input_name, key_name, "");
|
||||
if (!*this_entry){
|
||||
g_free(this_entry);
|
||||
break;
|
||||
}
|
||||
this_entry = mc_config_get_string (cfg, input_name, key_name, "");
|
||||
|
||||
hist = list_append_unique (hist, this_entry);
|
||||
if (this_entry && *this_entry)
|
||||
hist = list_append_unique (hist, this_entry);
|
||||
}
|
||||
mc_config_deinit(cfg);
|
||||
|
||||
mc_config_deinit (cfg);
|
||||
g_free (profile);
|
||||
|
||||
/* return pointer to the last entry in the list */
|
||||
hist = g_list_last (hist);
|
||||
|
||||
return hist;
|
||||
return g_list_last (hist);
|
||||
}
|
||||
|
||||
void
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user