Revert "Replace self-made code for work with ini-files to glib native code"

This reverts commit 4648ad8bf9.
This commit is contained in:
Sergei Trofimovich 2009-05-19 10:22:24 +03:00
parent df5160aaf3
commit fd55b916de
25 changed files with 978 additions and 885 deletions

View File

@ -566,7 +566,6 @@ misc/Makefile
misc/mc.ext
src/Makefile
src/mcconfig/Makefile
src/search/Makefile
edit/Makefile

View File

@ -1,4 +1,4 @@
SUBDIRS = mcconfig search
SUBDIRS = search
AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) $(PCRE_CFLAGS)
@ -37,7 +37,7 @@ endif
endif
mc_LDADD = $(EDITLIB) $(SLANGLIB) $(VFSLIB) \
$(INTLLIBS) $(GLIB_LIBS) $(MCLIBS) $(LIBICONV) search/libsearch.la mcconfig/libmcconfig.la
$(INTLLIBS) $(GLIB_LIBS) $(MCLIBS) $(LIBICONV) search/libsearch.la
CHARSET_SRC = charsets.c charsets.h selcodepage.c selcodepage.h
@ -56,7 +56,7 @@ SRCS = achown.c achown.h background.c background.h boxes.c boxes.h \
menu.c menu.h mountlist.c mountlist.h mouse.c mouse.h myslang.h \
option.c option.h panel.h panelize.c panelize.h poptalloca.h \
popt.c poptconfig.c popt.h popthelp.c poptint.h poptparse.c \
rxvt.c screen.c setup.c setup.h \
profile.c profile.h rxvt.c screen.c setup.c setup.h \
slint.c subshell.c subshell.h textconf.c textconf.h \
tree.c tree.h treestore.c treestore.h timefmt.h tty.c tty.h user.c \
user.h util.c util.h utilunix.c view.c view.h vfsdummy.h widget.c \

View File

@ -1,7 +1,7 @@
/* Some misc dialog boxes for the program.
Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2006, 2009 Free Software Foundation, Inc.
2005, 2006 Free Software Foundation, Inc.
Authors: 1994, 1995 Miguel de Icaza
1995 Jakub Jelinek
@ -42,7 +42,7 @@
#include "widget.h" /* The widgets for the nice dialog manager */
#include "wtools.h"
#include "setup.h" /* For profile_name */
#include "../src/mcconfig/mcconfig.h"
#include "profile.h" /* Load/save user formats */
#include "key.h" /* XCTRL and ALT macros */
#include "command.h" /* For cmdline */
#include "dir.h"
@ -236,7 +236,7 @@ display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int n
for (i = 0; i < LIST_TYPES; i++)
panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
section = g_strconcat ("Temporal:", p, (char *) NULL);
if (! mc_config_has_group (mc_profile, section)) {
if (!profile_has_section (section, profile_name)) {
g_free (section);
section = g_strdup (p);
}

View File

@ -2,7 +2,7 @@
They normally operate on the current panel.
Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2006, 2007, 2009 Free Software Foundation, Inc.
2005, 2006, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -65,7 +65,7 @@
#include "ext.h" /* regex_command() */
#include "boxes.h" /* cd_dialog() */
#include "setup.h" /* save_setup() */
#include "../src/mcconfig/mcconfig.h"
#include "profile.h" /* PROFILE_NAME */
#include "execute.h" /* toggle_panels() */
#include "history.h"
#include "strutil.h"
@ -1281,7 +1281,7 @@ void
save_setup_cmd (void)
{
save_setup ();
mc_config_save_file (mc_profile);
sync_profiles ();
message (D_NORMAL, _(" Setup "), _(" Setup saved to ~/%s"), PROFILE_NAME);
}

View File

@ -1,6 +1,6 @@
/* Directory hotlist -- for the Midnight Commander
Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2003, 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
Written by:
1994 Radek Doulik
@ -46,7 +46,7 @@
#include "dialog.h"
#include "widget.h"
#include "setup.h" /* For profile_bname */
#include "../src/mcconfig/mcconfig.h"
#include "profile.h" /* Load/save directories hotlist */
#include "wtools.h" /* QuickDialog */
#include "panel.h" /* current_panel */
#include "main.h" /* repaint_screen */
@ -612,7 +612,9 @@ init_hotlist (int list_type)
do_refresh ();
hotlist_state.expanded = mc_config_get_int (mc_profile, "HotlistConfig", "expanded_view_of_groups", 0);
hotlist_state.expanded =
GetPrivateProfileInt ("HotlistConfig", "expanded_view_of_groups",
0, profile_name);
if (list_type == LIST_VFSLIST) {
title = _("Active VFS directories");
@ -1164,43 +1166,29 @@ char *hotlist_cmd (int vfs_or_hotlist)
static void
load_group (struct hotlist *grp)
{
gchar **profile_keys, **keys;
gsize len;
void *profile_keys;
char *key, *value;
char *group_section;
struct hotlist *current = 0;
group_section = find_group_section (grp);
keys = mc_config_get_keys (mc_profile, group_section, &len);
profile_keys = profile_init_iterator (group_section, profile_name);
current_group = grp;
profile_keys = keys;
while (*profile_keys)
{
add2hotlist (
mc_config_get_string(mc_profile,group_section,*profile_keys,""),
g_strdup (*profile_keys),
HL_TYPE_GROUP,
0);
profile_keys++;
while (profile_keys){
profile_keys = profile_iterator_next (profile_keys, &key, &value);
add2hotlist (g_strdup (value), g_strdup (key), HL_TYPE_GROUP, 0);
}
g_free (group_section);
g_strfreev(keys);
keys = mc_config_get_keys (mc_profile, grp->directory,&len);
profile_keys = keys;
profile_keys = profile_init_iterator (grp->directory, profile_name);
while (*profile_keys)
{
add2hotlist (
mc_config_get_string(mc_profile,group_section,*profile_keys,""),
g_strdup (*profile_keys),
HL_TYPE_ENTRY,
0);
profile_keys++;
while (profile_keys){
profile_keys = profile_iterator_next (profile_keys, &key, &value);
add2hotlist (g_strdup (value),g_strdup (key), HL_TYPE_ENTRY, 0);
}
g_strfreev(keys);
for (current = grp->head; current; current = current->next)
load_group (current);
@ -1411,27 +1399,20 @@ static void
clean_up_hotlist_groups (const char *section)
{
char *grp_section;
gchar **profile_keys, **keys;
gsize len;
void *profile_keys;
char *key, *value;
grp_section = g_strconcat (section, ".Group", (char *) NULL);
if (profile_has_section (section, profile_name))
profile_clean_section (section, profile_name);
if (profile_has_section (grp_section, profile_name)) {
profile_keys = profile_init_iterator (grp_section, profile_name);
if (mc_config_has_group(mc_profile, section))
mc_config_del_group (mc_profile, section);
if (mc_config_has_group(mc_profile, grp_section))
{
keys = mc_config_get_keys (mc_profile, grp_section,&len);
profile_keys = keys;
while (*profile_keys)
{
clean_up_hotlist_groups (*profile_keys);
profile_keys++;
while (profile_keys) {
profile_keys = profile_iterator_next (profile_keys, &key, &value);
clean_up_hotlist_groups (key);
}
g_strfreev(keys);
mc_config_del_group (mc_profile, grp_section);
profile_clean_section (grp_section, profile_name);
}
g_free (grp_section);
}
@ -1490,7 +1471,7 @@ load_hotlist (void)
if (remove_old_list) {
clean_up_hotlist_groups ("Hotlist");
mc_config_save_file (mc_profile);
sync_profiles ();
}
stat (hotlist_file_name, &stat_buf);

View File

@ -1,6 +1,6 @@
/* Panel layout module for the Midnight Commander
Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006, 2007, 2009 Free Software Foundation, Inc.
2006, 2007 Free Software Foundation, Inc.
Written: 1995 Janne Kukonlehto
1995 Miguel de Icaza
@ -54,7 +54,7 @@
#include "dialog.h"
#include "widget.h"
#include "command.h"
#include "../src/mcconfig/mcconfig.h"
#include "profile.h" /* For sync_profiles() */
#include "mouse.h"
#include "main-widgets.h"
#include "main.h"
@ -538,7 +538,7 @@ void layout_cmd (void)
}
if (result == B_EXIT){
save_layout ();
mc_config_save_file (mc_profile);
sync_profiles ();
}
destroy_dlg (layout_dlg);

View File

@ -1,6 +1,6 @@
/* Learn keys
Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2007, 2009 Free Software Foundation, Inc.
2007 Free Software Foundation, Inc.
Written by: 1995 Jakub Jelinek
@ -40,7 +40,7 @@
#include "color.h"
#include "dialog.h"
#include "widget.h"
#include "../src/mcconfig/mcconfig.h"
#include "profile.h" /* Save profile */
#include "key.h"
#include "setup.h"
#include "main.h"
@ -318,8 +318,8 @@ learn_save (void)
for (i = 0; i < learn_total; i++) {
if (learnkeys [i].sequence != NULL) {
profile_changed = 1;
mc_config_set_string ( mc_profile, section,
key_name_conv_tab [i].name, learnkeys [i].sequence);
WritePrivateProfileString (section, key_name_conv_tab [i].name,
learnkeys [i].sequence, profile_name);
}
}
@ -330,7 +330,7 @@ learn_save (void)
* disk is much worse.
*/
if (profile_changed)
mc_config_save_file (mc_profile);
sync_profiles ();
g_free (section);
}

View File

@ -1,9 +1,7 @@
/*
Provides a log file to ease tracing the program.
Copyright (C) 2006,2009 Free Software Foundation, Inc.
Written: 2006 Roland Illig <roland.illig@gmx.de>.
Copyright (C) 2006 Roland Illig <roland.illig@gmx.de>.
This file is part of the Midnight Commander.
@ -35,8 +33,6 @@
#include "global.h"
#include "logging.h"
#include "setup.h"
#include "../src/mcconfig/mcconfig.h"
/*** file scope functions **********************************************/
@ -50,7 +46,7 @@ is_logging_enabled(void)
if (!logging_initialized) {
mc_ini = g_strdup_printf("%s/%s", home_dir, PROFILE_NAME);
logging_enabled =
mc_config_get_int (mc_profile, mc_ini, "development.enable_logging", FALSE);
get_int(mc_ini, "development.enable_logging", FALSE);
g_free(mc_ini);
logging_initialized = TRUE;
}

View File

@ -1,6 +1,6 @@
/* Main program for the Midnight Commander
Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2003, 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
Written by: 1994, 1995, 1996, 1997 Miguel de Icaza
1994, 1995 Janne Kukonlehto
@ -54,7 +54,7 @@
#include "subshell.h"
#include "key.h" /* For init_key() and mi_getch() */
#include "setup.h" /* save_setup() */
#include "../src/mcconfig/mcconfig.h"
#include "profile.h" /* free_profiles() */
#include "boxes.h" /* sort_box() */
#include "layout.h"
#include "cmd.h" /* Normal commands */
@ -1474,9 +1474,11 @@ done_mc (void)
static void
done_mc_profile (void)
{
if (auto_save_setup)
mc_config_save_file (mc_profile);
if (!auto_save_setup)
profile_forget_profile (profile_name);
sync_profiles ();
done_setup ();
free_profiles ();
}
static cb_ret_t

View File

@ -1,13 +0,0 @@
noinst_LTLIBRARIES = libmcconfig.la
libmcconfig_la_SOURCES = \
../mcconfig.h \
common.c \
get.c \
set.c
libmcconfig_la_CFLAGS=-I../ -I$(top_srcdir)/src \
$(GLIB_CFLAGS) \
-DDATADIR=\""$(pkgdatadir)/"\" -DLOCALEDIR=\""$(localedir)"\"

View File

@ -1,153 +0,0 @@
/* Configure module for the Midnight Commander
Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
2007, 2009 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include "global.h"
#include "mcconfig.h"
/*** global variables **************************************************/
/*** file scope macro definitions **************************************/
/*** file scope type declarations **************************************/
/*** file scope variables **********************************************/
/*** file scope functions **********************************************/
/*** public functions **************************************************/
mc_config_t *
mc_config_init (const gchar * ini_path)
{
mc_config_t *mc_config;
if (!ini_path || !exist_file (ini_path))
{
return NULL;
}
mc_config = g_try_malloc0 (sizeof (mc_config_t));
if (mc_config == NULL)
return NULL;
mc_config->handle = g_key_file_new ();
if (mc_config->handle == NULL)
{
g_free (mc_config);
return NULL;
}
if (!g_key_file_load_from_file
(mc_config->handle, ini_path, G_KEY_FILE_KEEP_COMMENTS, NULL))
{
g_key_file_free (mc_config->handle);
g_free (mc_config);
return NULL;
}
mc_config->ini_path = g_strdup (ini_path);
return mc_config;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void
mc_config_deinit (mc_config_t * mc_config)
{
if (!mc_config)
return;
g_free (mc_config->ini_path);
g_key_file_free (mc_config->handle);
g_free (mc_config);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
gboolean
mc_config_has_param (mc_config_t * mc_config, const char *group,
const gchar * param)
{
if (!mc_config || !group || !param)
return FALSE;
return g_key_file_has_key (mc_config->handle, group, param, NULL);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
gboolean
mc_config_has_group (mc_config_t * mc_config, const char *group)
{
if (!mc_config || !group)
return FALSE;
return g_key_file_has_group (mc_config->handle, group);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
gboolean
mc_config_del_param (mc_config_t * mc_config, const char *group,
const gchar * param)
{
if (!mc_config || !group || !param)
return FALSE;
return g_key_file_remove_key (mc_config->handle, group, param, NULL);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
gboolean
mc_config_del_group (mc_config_t * mc_config, const char *group)
{
if (!mc_config || !group)
return FALSE;
return g_key_file_remove_group (mc_config->handle, group, NULL);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
gboolean
mc_config_save_file (mc_config_t * mc_config)
{
gchar *data;
gsize len;
gboolean ret;
if (mc_config == NULL){
return FALSE;
}
data = g_key_file_to_data (mc_config->handle,&len,NULL);
if (exist_file(mc_config->ini_path))
{
mc_unlink (mc_config->ini_path);
}
ret = g_file_set_contents(mc_config->ini_path,data,len,NULL);
g_free(data);
return ret;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

View File

@ -1,152 +0,0 @@
/* Configure module for the Midnight Commander
Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
2007, 2009 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include "global.h"
#include "mcconfig.h"
/*** global variables **************************************************/
/*** file scope macro definitions **************************************/
/*** file scope type declarations **************************************/
/*** file scope variables **********************************************/
/*** file scope functions **********************************************/
/*** public functions **************************************************/
gchar **
mc_config_get_keys (mc_config_t * mc_config, const gchar * group, gsize * len)
{
gchar **ret;
if (!mc_config || !group)
{
ret = g_try_malloc0 (sizeof (gchar **));
return ret;
}
ret = g_key_file_get_keys (mc_config->handle, group, &len, NULL);
if (ret == NULL)
{
ret = g_try_malloc0 (sizeof (gchar **));
}
return ret;
}
gchar *
mc_config_get_string (mc_config_t * mc_config, const gchar * group,
const gchar * param, const gchar * def)
{
gchar *ret;
if (!mc_config || !group || !param)
return def ? g_strdup (def) : NULL;
if (! mc_config_has_param(mc_config, group, param))
{
mc_config_set_string (mc_config, group, param, def ? def : "");
return def ? g_strdup (def) : NULL;
}
ret = g_key_file_get_string (mc_config->handle, group, param, NULL);
if (!ret)
ret = def ? g_strdup (def) : NULL;
return ret;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
gboolean
mc_config_get_bool (mc_config_t * mc_config, const gchar * group,
const gchar * param, gboolean def)
{
if (!mc_config || !group || !param)
return def;
if (! mc_config_has_param(mc_config, group, param))
{
mc_config_set_bool (mc_config, group, param, def);
return def;
}
return g_key_file_get_boolean (mc_config->handle, group, param, NULL);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
int
mc_config_get_int (mc_config_t * mc_config, const gchar * group,
const gchar * param, int def)
{
if (!mc_config || !group || !param)
return def;
if (! mc_config_has_param(mc_config, group, param))
{
mc_config_set_int (mc_config, group, param, def);
return def;
}
return g_key_file_get_integer (mc_config->handle, group, param, NULL);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
gchar **
mc_config_get_string_list (mc_config_t * mc_config, const gchar * group,
const gchar * param, gsize * length)
{
if (!mc_config || !group || !param)
return NULL;
return g_key_file_get_string_list (mc_config->handle, group, param,
length, NULL);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
gboolean *
mc_config_get_bool_list (mc_config_t * mc_config, const gchar * group,
const gchar * param, gsize * length)
{
if (!mc_config || !group || !param)
return NULL;
return g_key_file_get_boolean_list (mc_config->handle, group, param,
length, NULL);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
int *
mc_config_get_int_list (mc_config_t * mc_config, const gchar * group,
const gchar * param, gsize * length)
{
if (!mc_config || !group || !param)
return NULL;
return g_key_file_get_integer_list (mc_config->handle, group, param,
length, NULL);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

View File

@ -1,88 +0,0 @@
#ifndef MC_CONFIG_H
#define MC_CONFIG_H
/*** typedefs(not structures) and defined constants ********************/
#define CONFIG_APP_SECTION "Midnight-Commander"
/*** enums *************************************************************/
/*** structures declarations (and typedefs of structures)***************/
typedef struct mc_config_struct
{
GKeyFile *handle;
gchar *ini_path;
} mc_config_t;
/*** global variables defined in .c file *******************************/
/*** declarations of public functions **********************************/
/* mcconfig/common.c: */
mc_config_t *mc_config_init (const gchar *);
void mc_config_deinit (mc_config_t *);
gboolean mc_config_del_param (mc_config_t *, const char *, const gchar *);
gboolean mc_config_del_group (mc_config_t *, const char *);
gboolean mc_config_has_param (mc_config_t *, const char *, const gchar *);
gboolean mc_config_has_group (mc_config_t *, const char *);
gboolean mc_config_save_file (mc_config_t *);
/* mcconfig/get.c: */
gchar **mc_config_get_keys (mc_config_t *, const gchar *, gsize *);
gchar *mc_config_get_string (mc_config_t *, const gchar *, const gchar *,
const gchar *);
gboolean mc_config_get_bool (mc_config_t *, const gchar *, const gchar *,
gboolean);
int mc_config_get_int (mc_config_t *, const gchar *, const gchar *, int);
gchar **mc_config_get_string_list (mc_config_t *, const gchar *,
const gchar *, gsize *);
gboolean *mc_config_get_bool_list (mc_config_t *, const gchar *,
const gchar *, gsize *);
int *mc_config_get_int_list (mc_config_t *, const gchar *,
const gchar *, gsize *);
/* mcconfig/set.c: */
void
mc_config_set_string (mc_config_t *, const gchar *,
const gchar *, const gchar *);
void
mc_config_set_bool (mc_config_t *, const gchar *, const gchar *, gboolean);
void mc_config_set_int (mc_config_t *, const gchar *, const gchar *, int);
void
mc_config_set_string_list (mc_config_t *, const gchar *,
const gchar *, const gchar * const[], gsize);
void
mc_config_set_bool_list (mc_config_t *, const gchar *,
const gchar *, gboolean[], gsize);
void
mc_config_set_int_list (mc_config_t *, const gchar *,
const gchar *, int[], gsize);
/* mcconfig/dialog.c: */
void mc_config_show_dialog (void);
#endif

View File

@ -1,113 +0,0 @@
/* Configure module for the Midnight Commander
Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
2007, 2009 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include "global.h"
#include "mcconfig.h"
/*** global variables **************************************************/
/*** file scope macro definitions **************************************/
/*** file scope type declarations **************************************/
/*** file scope variables **********************************************/
/*** file scope functions **********************************************/
/*** public functions **************************************************/
void
mc_config_set_string (mc_config_t * mc_config, const gchar * group,
const gchar * param, const gchar * value)
{
if (!mc_config || !group || !param || !value)
return;
g_key_file_set_string (mc_config->handle, group, param, value);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void
mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
const gchar * param, gboolean value)
{
if (!mc_config || !group || !param )
return;
g_key_file_set_boolean (mc_config->handle, group, param, value);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void
mc_config_set_int (mc_config_t * mc_config, const gchar * group,
const gchar * param, int value)
{
if (!mc_config || !group || !param )
return;
g_key_file_set_integer (mc_config->handle, group, param, value);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void
mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
const gchar * param, const gchar * const value[],
gsize length)
{
if (!mc_config || !group || !param || !value || length == 0)
return;
g_key_file_set_string_list (mc_config->handle, group, param, value,
length);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void
mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
const gchar * param, gboolean value[], gsize length)
{
if (!mc_config || !group || !param || !value || length == 0)
return;
g_key_file_set_boolean_list (mc_config->handle, group, param, value,
length);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void
mc_config_set_int_list (mc_config_t * mc_config, const gchar * group,
const gchar * param, int value[], gsize length)
{
if (!mc_config || !group || !param || !value || length == 0)
return;
g_key_file_set_integer_list (mc_config->handle, group, param, value,
length);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

View File

@ -38,7 +38,7 @@
#include "widget.h"
#include "setup.h" /* For save_setup() */
#include "main.h"
#include "../src/mcconfig/mcconfig.h"
#include "profile.h" /* For sync_profiles */
#include "strutil.h"
#include "panel.h" /* Needed for the externs */
@ -243,7 +243,7 @@ void configure_box (void)
/* If they pressed the save button */
if (result == B_EXIT){
save_configure ();
mc_config_save_file (mc_profile);
sync_profiles ();
}
destroy_dlg (conf_dlg);

View File

@ -1,6 +1,6 @@
/* External panelize
Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2007, 2009 Free Software Foundation, Inc.
2007 Free Software Foundation, Inc.
Written by: 1995 Janne Kukonlehto
1995 Jakub Jelinek
@ -41,7 +41,7 @@
#include "widget.h"
#include "wtools.h" /* For common_dialog_repaint() */
#include "setup.h" /* For profile_bname */
#include "../src/mcconfig/mcconfig.h"
#include "profile.h" /* Load/save directories panelize */
#include "dir.h"
#include "panel.h" /* current_panel */
#include "main.h" /* repaint_screen */
@ -312,11 +312,10 @@ external_panelize (void)
void load_panelize (void)
{
gchar **profile_keys, **keys;
gsize len;
keys = mc_config_get_keys (mc_profile, panelize_section,&len);
profile_keys = keys;
void *profile_keys;
char *key, *value;
profile_keys = profile_init_iterator (panelize_section, profile_name);
add2panelize (g_strdup (_("Other command")), g_strdup (""));
@ -327,29 +326,25 @@ void load_panelize (void)
return;
}
while (*profile_keys)
{
add2panelize (
g_strdup (*profile_keys),
mc_config_get_string(mc_profile,panelize_section,*profile_keys,"")
);
profile_keys++;
while (profile_keys){
profile_keys = profile_iterator_next (profile_keys, &key, &value);
add2panelize (g_strdup (key), g_strdup (value));
}
g_strfreev(keys);
}
void save_panelize (void)
{
struct panelize *current = panelize;
mc_config_del_group (mc_profile, panelize_section);
for (;current; current = current->next)
{
if (strcmp (current->label, _("Other command")))
mc_config_set_string(mc_profile,panelize_section,current->label,current->command);
profile_clean_section (panelize_section, profile_name);
for (;current; current = current->next){
if (strcmp (current->label, _("Other command")))
WritePrivateProfileString (panelize_section,
current->label,
current->command,
profile_name);
}
mc_config_save_file (mc_profile);
sync_profiles ();
}
void done_panelize (void)

561
src/profile.c Normal file
View File

@ -0,0 +1,561 @@
/*
* Initialization-File Functions.
*
* From the Wine project
Copyright (C) 1993, 1994, 1998, 1999, 2000, 2002, 2003, 2004, 2005,
2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/** \file profile.c
* \brief Source: Initialization-files(ini) functions.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "global.h"
#include "profile.h"
#include "strutil.h"
#define STRSIZE 4096
#define overflow (next == &CharBuffer [STRSIZE-1])
enum { FirstBrace, OnSecHeader, IgnoreToEOL, KeyDef, KeyDefOnKey, KeyValue };
typedef struct TKeys {
char *KeyName;
char *Value;
struct TKeys *link;
} TKeys;
typedef struct TSecHeader {
char *AppName;
TKeys *Keys;
struct TSecHeader *link;
} TSecHeader;
typedef struct TProfile {
char *FileName;
TSecHeader *Section;
struct TProfile *link;
} TProfile;
static TProfile *Base = 0;
static TProfile *
find_loaded (const char *FileName, TSecHeader ** section)
{
TProfile *p = Base;
while (p) {
if (!str_casecmp (FileName, p->FileName)) {
*section = p->Section;
return p;
}
p = p->link;
}
return NULL;
}
#define TRANSLATION_CHAR '\200'
static char *
str_untranslate_newline_dup (char *s)
{
int l = 0;
char *p = s, *q;
g_return_val_if_fail(s, NULL);
while (*p) {
l++;
l += (*p == '\n' || *p == TRANSLATION_CHAR);
p++;
}
q = p = g_malloc (l + 1);
if (!q)
return 0;
for (;;) {
switch (*s) {
case '\n':
*p++ = TRANSLATION_CHAR;
*p++ = 'n';
break;
case TRANSLATION_CHAR:
if (s[1] == 'n' || s[1] == TRANSLATION_CHAR)
*p++ = TRANSLATION_CHAR;
*p++ = TRANSLATION_CHAR;
break;
case '\0':
*p = '\0';
return q;
break;
default:
*p++ = *s;
}
s++;
}
return 0; /* not reached */
}
static char *
str_translate_newline_dup (char *s)
{
char *p, *q;
g_return_val_if_fail(s,NULL);
q = p = g_malloc (strlen (s) + 1);
if (!q)
return 0;
while (*s) {
if (*s == TRANSLATION_CHAR) {
switch (*(++s)) {
case 'n':
*p++ = '\n';
break;
case TRANSLATION_CHAR:
*p++ = TRANSLATION_CHAR;
break;
case '\0':
*p++ = TRANSLATION_CHAR;
*p++ = '\0';
return q;
default:
*p++ = TRANSLATION_CHAR;
*p++ = *s;
}
} else {
*p++ = *s;
}
s++;
}
*p = '\0';
return q; /* not reached */
}
static TSecHeader *load (const char *file)
{
FILE *f;
int state;
TSecHeader *SecHeader = 0;
char CharBuffer [STRSIZE];
char *next = NULL; /* Not needed */
int c;
if ((f = fopen (file, "r"))==NULL)
return NULL;
state = FirstBrace;
while ((c = getc (f)) != EOF){
if (c == '\r') /* Ignore Carriage Return */
continue;
switch (state){
case OnSecHeader:
if (c == ']' || overflow){
*next = '\0';
next = CharBuffer;
SecHeader->AppName = g_strdup (CharBuffer);
state = IgnoreToEOL;
} else
*next++ = c;
break;
case IgnoreToEOL:
if (c == '\n'){
state = KeyDef;
next = CharBuffer;
}
break;
case FirstBrace:
case KeyDef:
case KeyDefOnKey:
if (c == '['){
TSecHeader *temp;
temp = SecHeader;
SecHeader = g_new (TSecHeader, 1);
SecHeader->link = temp;
SecHeader->Keys = 0;
state = OnSecHeader;
next = CharBuffer;
break;
}
if (state == FirstBrace) /* On first pass, don't allow dangling keys */
break;
if ((c == ' ' && state != KeyDefOnKey) || c == '\t')
break;
if (c == '\n' || overflow) {
/* Abort Definition */
next = CharBuffer;
break;
}
if (c == '=' || overflow){
TKeys *temp;
temp = SecHeader->Keys;
*next = '\0';
SecHeader->Keys =g_new (TKeys, 1);
SecHeader->Keys->link = temp;
SecHeader->Keys->KeyName = g_strdup (CharBuffer);
state = KeyValue;
next = CharBuffer;
} else {
*next++ = c;
state = KeyDefOnKey;
}
break;
case KeyValue:
if (overflow || c == '\n'){
*next = '\0';
SecHeader->Keys->Value = str_translate_newline_dup (CharBuffer);
state = c == '\n' ? KeyDef : IgnoreToEOL;
next = CharBuffer;
#ifdef DEBUG
printf ("[%s] (%s)=%s\n", SecHeader->AppName,
SecHeader->Keys->KeyName, SecHeader->Keys->Value);
#endif
} else
*next++ = c;
break;
} /* switch */
} /* while ((c = getc (f)) != EOF) */
switch (state) {
case KeyValue:
*next = '\0';
SecHeader->Keys->Value = str_translate_newline_dup (CharBuffer);
break;
case OnSecHeader: { /* Broken initialization file */
TSecHeader *link = SecHeader->link;
g_free (SecHeader);
SecHeader = link;
fprintf (stderr, "Warning: Corrupted initialization file `%s'\n",
file);
break;
}
}
fclose (f);
return SecHeader;
}
static void new_key (TSecHeader *section, const char *KeyName, const char *Value)
{
TKeys *key;
key = g_new (TKeys, 1);
key->KeyName = g_strdup (KeyName);
key->Value = g_strdup (Value);
key->link = section->Keys;
section->Keys = key;
}
static const char *
GetSetProfileChar (int set, const char *AppName, const char *KeyName,
const char *Default, const char *FileName)
{
TProfile *Current;
TSecHeader *section;
TKeys *key;
Current = find_loaded (FileName, &section);
if (!Current) {
Current = g_new (TProfile, 1);
Current->link = Base;
Current->FileName = g_strdup (FileName);
Current->Section = load (FileName);
Base = Current;
section = Current->Section;
}
/* Start search */
for (; section; section = section->link){
if (section->AppName == 0 || str_casecmp (section->AppName, AppName))
continue;
for (key = section->Keys; key; key = key->link){
if (str_casecmp (key->KeyName, KeyName))
continue;
if (set){
g_free (key->Value);
key->Value = g_strdup (Default);
}
return key->Value;
}
/* If getting the information, then don't write the information
to the INI file, need to run a couple of tests with windog */
/* No key found */
if (set){
new_key (section, KeyName, Default);
return 0;
}
}
/* Non existent section */
if (set && Default){
section = g_new (TSecHeader, 1);
section->AppName = g_strdup (AppName);
section->Keys = 0;
new_key (section, KeyName, Default);
section->link = Current->Section;
Current->Section = section;
}
return Default;
}
static short GetSetProfile (int set, const char * AppName, const char * KeyName,
const char * Default, char * ReturnedString,
short Size, const char * FileName)
{
const char *s;
s = GetSetProfileChar (set, AppName, KeyName, Default, FileName);
if (!set)
g_strlcpy (ReturnedString, s, Size);
return 1;
}
short GetPrivateProfileString (const char * AppName, const char * KeyName,
const char * Default, char * ReturnedString,
short Size, const char * FileName)
{
return (GetSetProfile (0, AppName, KeyName, Default, ReturnedString, Size, FileName));
}
const char *get_profile_string (const char *AppName, const char *KeyName, const char *Default,
const char *FileName)
{
return GetSetProfileChar (0, AppName, KeyName, Default, FileName);
}
int GetPrivateProfileInt (const char * AppName, const char * KeyName, int Default,
const char * File)
{
char IntBuf [BUF_TINY];
char buf [BUF_TINY];
g_snprintf (buf, sizeof (buf), "%d", Default);
/* Check the exact semantic with the SDK */
GetPrivateProfileString (AppName, KeyName, buf, IntBuf, BUF_TINY, File);
if (!str_casecmp (IntBuf, "true"))
return 1;
if (!str_casecmp (IntBuf, "yes"))
return 1;
return (int) atol (IntBuf);
}
int WritePrivateProfileString (const char * AppName, const char * KeyName, const char * String,
const char * FileName)
{
return GetSetProfile (1, AppName, KeyName, String, NULL, 0, FileName);
}
static void dump_keys (FILE * profile, TKeys * p)
{
char *t;
if (!p)
return;
dump_keys (profile, p->link);
t = str_untranslate_newline_dup (p->Value);
fprintf (profile, "%s=%s\n", p->KeyName, t);
g_free (t);
}
static void dump_sections (FILE *profile, TSecHeader *p)
{
if (!p)
return;
dump_sections (profile, p->link);
if (p->AppName [0]){
fprintf (profile, "\n[%s]\n", p->AppName);
dump_keys (profile, p->Keys);
}
}
static void dump_profile (TProfile *p)
{
FILE *profile;
if (!p)
return;
dump_profile (p->link);
/* .ado: p->FileName can be empty, it's better to jump over */
if (p->FileName[0] != (char) 0)
if ((profile = fopen (p->FileName, "w")) != NULL){
dump_sections (profile, p->Section);
fclose (profile);
}
}
/*
* Must be called at the end of wine run
*/
void sync_profiles (void)
{
dump_profile (Base);
}
static void free_keys (TKeys *p)
{
if (!p)
return;
free_keys (p->link);
g_free (p->KeyName);
g_free (p->Value);
g_free (p);
}
static void free_sections (TSecHeader *p)
{
if (!p)
return;
free_sections (p->link);
free_keys (p->Keys);
g_free (p->AppName);
p->link = 0;
p->Keys = 0;
g_free (p);
}
static void free_profile (TProfile *p)
{
if (!p)
return;
free_profile (p->link);
free_sections (p->Section);
g_free (p->FileName);
g_free (p);
}
void free_profile_name (const char *s)
{
TProfile *p;
if (!s)
return;
for (p = Base; p; p = p->link){
if (strcmp (s, p->FileName) == 0){
free_sections (p->Section);
p->Section = 0;
p->FileName [0] = 0;
return;
}
}
}
void free_profiles (void)
{
free_profile (Base);
}
void *profile_init_iterator (const char *appname, const char *file)
{
TProfile *Current;
TSecHeader *section;
Current = find_loaded (file, &section);
if (!Current) {
Current = g_new (TProfile, 1);
Current->link = Base;
Current->FileName = g_strdup (file);
Current->Section = load (file);
Base = Current;
section = Current->Section;
}
for (; section; section = section->link){
if (str_casecmp (section->AppName, appname))
continue;
return section->Keys;
}
return 0;
}
void *profile_iterator_next (void *s, char **key, char **value)
{
TKeys *keys = (TKeys *) s;
if (keys){
*key = keys->KeyName;
*value = keys->Value;
keys = keys->link;
}
return keys;
}
void profile_clean_section (const char *appname, const char *file)
{
TSecHeader *section;
/* We assume the user has called one of the other initialization funcs */
if (!find_loaded (file, &section)){
fprintf (stderr,"Warning: profile_clean_section called before init\n");
return;
}
/* We only disable the section, so it will still be freed, but it */
/* won't be find by further walks of the structure */
for (; section; section = section->link){
if (str_casecmp (section->AppName, appname))
continue;
section->AppName [0] = 0;
}
}
int profile_has_section (const char *section_name, const char *profile)
{
TSecHeader *section;
/* We assume the user has called one of the other initialization funcs */
if (!find_loaded (profile, &section)){
return 0;
}
for (; section; section = section->link){
if (str_casecmp (section->AppName, section_name))
continue;
return 1;
}
return 0;
}
void profile_forget_profile (const char *file)
{
TProfile *p;
for (p = Base; p; p = p->link){
if (str_casecmp (file, p->FileName))
continue;
p->FileName [0] = 0;
}
}

53
src/profile.h Normal file
View File

@ -0,0 +1,53 @@
/** \file profile.h
* \brief Header: Initialization-files(ini) functions.
*/
#ifndef MC_PROFILE_H
#define MC_PROFILE_H
/* Prototypes for the profile management functions */
short GetPrivateProfileString (const char * AppName, const char * KeyName,
const char * Default, char * ReturnedString,
short Size, const char * FileName);
int GetProfileString (const char * AppName, const char * KeyName, const char * Default,
char * ReturnedString, int Size);
int GetPrivateProfileInt (const char * AppName, const char * KeyName, int Default,
const char * File);
int GetProfileInt (const char * AppName, const char * KeyName, int Default);
int WritePrivateProfileString (const char * AppName, const char * KeyName, const char * String,
const char * FileName);
int WriteProfileString (const char * AppName, const char * KeyName, const char * String);
void sync_profiles (void);
void free_profiles (void);
const char *get_profile_string (const char *AppName, const char *KeyName, const char *Default,
const char *FileName);
/* New profile functions */
/* Returns a pointer for iterating on appname section, on profile file */
void *profile_init_iterator (const char *appname, const char *file);
/* Returns both the key and the value of the current section. */
/* You pass the current iterating pointer and it returns the new pointer */
void *profile_iterator_next (void *s, char **key, char **value);
/* Removes all the definitions from section appname on file */
void profile_clean_section (const char *appname, const char *file);
int profile_has_section (const char *section_name, const char *profile);
/* Forgets about a .ini file, to disable updating of it */
void profile_forget_profile (const char *file);
/* Removes information from a profile */
void free_profile_name (const char *s);
#endif

View File

@ -1,6 +1,6 @@
/* Panel managing.
Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2006, 2007, 2009 Free Software Foundation, Inc.
2005, 2006, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -46,7 +46,7 @@
#include "key.h" /* XCTRL and ALT macros */
#include "setup.h" /* For loading/saving panel options */
#include "user.h"
#include "../src/mcconfig/mcconfig.h"
#include "profile.h"
#include "execute.h"
#include "widget.h"
#include "menu.h" /* menubar_visible */
@ -1142,7 +1142,7 @@ panel_new (const char *panel_name)
panel->search_buffer[0] = 0;
panel->frame_size = frame_half;
section = g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
if (!mc_config_has_group (mc_profile, section)) {
if (!profile_has_section (section, profile_name)) {
g_free (section);
section = g_strdup (panel->panel_name);
}

View File

@ -1,6 +1,6 @@
/* Setup loading/saving.
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006, 2007, 2009 Free Software Foundation, Inc.
2006, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -33,7 +33,7 @@
#include "panel.h"
#include "main.h"
#include "tree.h" /* xtree_mode */
#include "../src/mcconfig/mcconfig.h"
#include "profile.h"
#include "setup.h"
#include "mouse.h" /* To make view.h happy */
#include "view.h" /* For the externs */
@ -65,18 +65,21 @@
#include "../src/strutil.h" /* str_isutf8 () */
/*** global variables **************************************************/
extern char *find_ignore_dirs;
extern int num_history_items_recorded;
mc_config_t *mc_profile; /* .mc/ini */
mc_config_t *mc_global_profile;/* mc.lib */
char *profile_name; /* .mc/ini */
char *global_profile_name; /* mc.lib */
char *setup_color_string;
char *term_color_string;
char *color_terminal_string;
char setup_color_string [4096];
char term_color_string [4096];
char color_terminal_string [512];
#define load_int(a,b,c) GetPrivateProfileInt(a,b,c,profile_name)
#define load_string(a,b,c,d,e) GetPrivateProfileString(a,b,c,d,e,profile_name)
#define save_string WritePrivateProfileString
int startup_left_mode;
int startup_right_mode;
@ -85,12 +88,6 @@ int startup_right_mode;
/* default panel values */
int saving_setup;
/*** file scope macro definitions **************************************/
/*** file scope type declarations **************************************/
/*** file scope variables **********************************************/
static const struct {
const char *key;
sortfn *sort_type;
@ -249,46 +246,81 @@ static const struct {
{ NULL, NULL, NULL }
};
/*** file scope functions **********************************************/
static void
setup__panel_save (struct WPanel *panel, const char *section)
void
panel_save_setup (struct WPanel *panel, const char *section)
{
char buffer [BUF_TINY];
int i;
g_snprintf (buffer, sizeof (buffer), "%d", panel->reverse);
mc_config_set_string (mc_profile, section, "reverse", buffer);
save_string (section, "reverse", buffer, profile_name);
g_snprintf (buffer, sizeof (buffer), "%d", panel->case_sensitive);
mc_config_set_string (mc_profile, section, "case_sensitive", buffer);
save_string (section, "case_sensitive", buffer, profile_name);
g_snprintf (buffer, sizeof (buffer), "%d", panel->exec_first);
mc_config_set_string (mc_profile, section, "exec_first", buffer);
save_string (section, "exec_first", buffer, profile_name);
for (i = 0; sort_names [i].key; i++)
if (sort_names [i].sort_type == (sortfn *) panel->sort_type){
mc_config_set_string (mc_profile, section, "sort_order", sort_names [i].key);
save_string (section, "sort_order",
sort_names [i].key, profile_name);
break;
}
for (i = 0; list_types [i].key; i++)
if (list_types [i].list_type == panel->list_type){
mc_config_set_string (mc_profile, section, "list_mode", list_types [i].key);
save_string (section, "list_mode", list_types [i].key, profile_name);
break;
}
mc_config_set_string (mc_profile, section, "user_format", panel->user_format);
save_string (section, "user_format",
panel->user_format, profile_name);
for (i = 0; i < LIST_TYPES; i++){
g_snprintf (buffer, sizeof (buffer), "user_status%d", i);
mc_config_set_string (mc_profile, section, buffer,
panel->user_status_format [i]);
save_string (section, buffer,
panel->user_status_format [i], profile_name);
}
g_snprintf (buffer, sizeof (buffer), "%d", panel->user_mini_status);
mc_config_set_string (mc_profile,section, "user_mini_status", buffer);
save_string (section, "user_mini_status", buffer,
profile_name);
}
void
save_layout (void)
{
char *profile;
int i;
char buffer [BUF_TINY];
profile = concat_dir_and_file (home_dir, PROFILE_NAME);
/* Save integer options */
for (i = 0; layout [i].opt_name; i++){
g_snprintf (buffer, sizeof (buffer), "%d", *layout [i].opt_addr);
save_string ("Layout", layout [i].opt_name, buffer, profile);
}
g_free (profile);
}
void
save_configure (void)
{
char *profile;
int i;
profile = concat_dir_and_file (home_dir, PROFILE_NAME);
/* Save integer options */
for (i = 0; int_options[i].opt_name; i++)
set_int (profile, int_options[i].opt_name, *int_options[i].opt_addr);
/* Save string options */
for (i = 0; str_options[i].opt_name != NULL; i++)
set_config_string (profile, str_options[i].opt_name,
*str_options[i].opt_addr);
g_free (profile);
}
static void
@ -298,145 +330,44 @@ panel_save_type (const char *section, int type)
for (i = 0; panel_types [i].opt_name; i++)
if (panel_types [i].opt_type == type){
mc_config_set_string(mc_profile, section, "display", panel_types[i].opt_name);
save_string (section, "display", panel_types [i].opt_name,
profile_name);
break;
}
}
static void
save_panel_types ()
save_panel_types (void)
{
int type;
type = get_display_type (0);
panel_save_type ( "New Left Panel", type);
panel_save_type ("New Left Panel", type);
if (type == view_listing)
setup__panel_save (left_panel, left_panel->panel_name);
panel_save_setup (left_panel, left_panel->panel_name);
type = get_display_type (1);
panel_save_type ( "New Right Panel", type);
panel_save_type ("New Right Panel", type);
if (type == view_listing)
setup__panel_save (right_panel, right_panel->panel_name);
}
static void
load_layout (void)
{
int i;
for (i = 0; layout [i].opt_name; i++)
*layout [i].opt_addr =
mc_config_get_int(mc_profile,"Layout", layout [i].opt_name, *layout [i].opt_addr);
}
static int
load_mode (const char *section)
{
char *buffer;
int i;
int mode = view_listing;
/* Load the display mode */
buffer = mc_config_get_string(mc_profile, section, "display", "listing");
for (i = 0; panel_types [i].opt_name; i++)
if ( g_strcasecmp (panel_types [i].opt_name, buffer) == 0){
mode = panel_types [i].opt_type;
break;
}
g_free(buffer);
return mode;
}
static void
load_keys_from_section (const char *terminal, mc_config_t *cfg)
{
char *section_name;
char **profile_keys, **keys;
gsize len;
char *valcopy, *value;
int key_code;
if (!terminal)
return;
section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
keys = mc_config_get_keys (cfg, section_name,&len);
profile_keys = keys;
while (*profile_keys){
value = mc_config_get_string(cfg, section_name, *profile_keys, "");
/* copy=other causes all keys from [terminal:other] to be loaded. */
if (g_strcasecmp (*profile_keys, "copy") == 0) {
load_keys_from_section (value, cfg);
continue;
}
key_code = lookup_key (*profile_keys);
if (key_code){
valcopy = convert_controls (value);
define_sequence (key_code, valcopy, MCKEY_NOACTION);
g_free (valcopy);
}
g_free(value);
profile_keys++;
}
g_free (section_name);
g_strfreev(keys);
}
/*** public functions **************************************************/
void
panel_save_setup ( struct WPanel *panel, const char *section)
{
g_free(mc_profile->ini_path);
mc_profile->ini_path = concat_dir_and_file (home_dir, PROFILE_NAME);
setup__panel_save ( panel, section);
mc_config_save_file(mc_profile);
}
void
save_layout (void)
{
int i;
/* Save integer options */
for (i = 0; layout [i].opt_name; i++){
mc_config_set_int(mc_profile, "Layout", layout [i].opt_name, *layout [i].opt_addr);
}
}
void
save_configure (void)
{
int i;
/* Save integer options */
for (i = 0; int_options[i].opt_name; i++)
mc_config_set_int (mc_profile, CONFIG_APP_SECTION, int_options[i].opt_name, *int_options[i].opt_addr);
/* Save string options */
for (i = 0; str_options[i].opt_name != NULL; i++)
mc_config_set_string (mc_profile, CONFIG_APP_SECTION, str_options[i].opt_name, *str_options[i].opt_addr);
panel_save_setup (right_panel, right_panel->panel_name);
}
void
save_setup (void)
{
char *profile;
saving_setup = 1;
g_free(mc_profile->ini_path);
mc_profile->ini_path = concat_dir_and_file (home_dir, PROFILE_NAME);
profile = concat_dir_and_file (home_dir, PROFILE_NAME);
save_configure ();
save_layout ();
mc_config_set_string(mc_profile, "Dirs", "other_dir",
get_other_type () == view_listing ? other_panel->cwd : ".");
save_string ("Dirs", "other_dir",
get_other_type () == view_listing
? other_panel->cwd : ".", profile);
if (current_panel != NULL)
mc_config_set_string(mc_profile,"Dirs", "current_is_left", get_current_index () == 0 ? "1" : "0");
WritePrivateProfileString ("Dirs", "current_is_left",
get_current_index () == 0 ? "1" : "0", profile);
save_hotlist ();
save_panelize ();
@ -444,16 +375,21 @@ save_setup (void)
/* directory_history_save (); */
#if defined(USE_VFS) && defined (USE_NETCODE)
mc_config_set_string(mc_profile, "Misc", "ftpfs_password", ftpfs_anonymous_passwd);
WritePrivateProfileString ("Misc", "ftpfs_password",
ftpfs_anonymous_passwd, profile);
if (ftpfs_proxy_host)
mc_config_set_string(mc_profile, "Misc", "ftp_proxy_host", ftpfs_proxy_host);
WritePrivateProfileString ("Misc", "ftp_proxy_host",
ftpfs_proxy_host, profile);
#endif /* USE_VFS && USE_NETCODE */
#ifdef HAVE_CHARSET
mc_config_set_string(mc_profile, "Misc", "display_codepage", get_codepage_id( display_codepage ));
mc_config_set_string(mc_profile, "Misc", "source_codepage", get_codepage_id( source_codepage ));
save_string( "Misc", "display_codepage",
get_codepage_id( display_codepage ), profile_name );
save_string( "Misc", "source_codepage",
get_codepage_id( source_codepage ), profile_name );
#endif /* HAVE_CHARSET */
g_free (profile);
saving_setup = 0;
}
@ -461,56 +397,102 @@ void
panel_load_setup (WPanel *panel, const char *section)
{
int i;
char *buff;
char buffer [BUF_TINY];
panel->reverse = mc_config_get_int(mc_profile, section, "reverse", 0);
panel->case_sensitive = mc_config_get_int(mc_profile, section, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT);
panel->exec_first = mc_config_get_int(mc_profile, section, "exec_first", 0);
panel->reverse = load_int (section, "reverse", 0);
panel->case_sensitive = load_int (section, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT);
panel->exec_first = load_int (section, "exec_first", 0);
/* Load sort order */
buff = mc_config_get_string(mc_profile, section, "sort_order", "name");
load_string (section, "sort_order", "name", buffer, sizeof (buffer));
panel->sort_type = (sortfn *) sort_name;
for (i = 0; sort_names [i].key; i++)
if ( g_strcasecmp (sort_names [i].key, buff) == 0){
if ( g_strcasecmp (sort_names [i].key, buffer) == 0){
panel->sort_type = sort_names [i].sort_type;
break;
}
g_free(buff);
/* Load the listing mode */
buff = mc_config_get_string(mc_profile, section, "list_mode", "full");
load_string (section, "list_mode", "full", buffer, sizeof (buffer));
panel->list_type = list_full;
for (i = 0; list_types [i].key; i++)
if ( g_strcasecmp (list_types [i].key, buff) == 0){
if ( g_strcasecmp (list_types [i].key, buffer) == 0){
panel->list_type = list_types [i].list_type;
break;
}
g_free(buff);
/* User formats */
g_free (panel->user_format);
panel->user_format = mc_config_get_string(mc_profile, section, "user_format", DEFAULT_USER_FORMAT);
panel->user_format = g_strdup (get_profile_string (section, "user_format",
DEFAULT_USER_FORMAT,
profile_name));
for (i = 0; i < LIST_TYPES; i++){
g_free (panel->user_status_format [i]);
buff = g_strdup_printf("user_status%d", i);
panel->user_status_format [i] =
mc_config_get_string (mc_profile, section, buff, DEFAULT_USER_FORMAT);
g_free(buff);
g_snprintf (buffer, sizeof (buffer), "user_status%d", i);
panel->user_status_format [i] =
g_strdup (get_profile_string (section, buffer,
DEFAULT_USER_FORMAT, profile_name));
}
panel->user_mini_status =
mc_config_get_int(mc_profile, section, "user_mini_status", 0);
load_int (section, "user_mini_status", 0);
}
mc_config_t *
static void
load_layout (char *profile_name)
{
int i;
for (i = 0; layout [i].opt_name; i++)
*layout [i].opt_addr =
load_int ("Layout", layout [i].opt_name,
*layout [i].opt_addr);
}
static int
load_mode (const char *section)
{
char buffer [20];
int i;
int mode = view_listing;
/* Load the display mode */
load_string (section, "display", "listing", buffer, sizeof (buffer));
for (i = 0; panel_types [i].opt_name; i++)
if ( g_strcasecmp (panel_types [i].opt_name, buffer) == 0){
mode = panel_types [i].opt_type;
break;
}
return mode;
}
#ifdef USE_NETCODE
static char *
do_load_string (const char *s, const char *ss, const char *def)
{
char *buffer = g_malloc (BUF_SMALL);
char *p;
load_string (s, ss, def, buffer, BUF_SMALL);
p = g_strdup (buffer);
g_free (buffer);
return p;
}
#endif /* !USE_NETCODE */
char *
setup_init (void)
{
char *profile;
char *inifile;
if (mc_profile)
return mc_profile;
if (profile_name)
return profile_name;
profile = concat_dir_and_file (home_dir, PROFILE_NAME);
if (!exist_file (profile)){
@ -521,47 +503,35 @@ setup_init (void)
} else
g_free (inifile);
}
mc_profile = mc_config_init(profile);
if (mc_profile == NULL){
gchar *init_data;
profile_name = profile;
init_data = g_strdup_printf ("[%s]\n",CONFIG_APP_SECTION);
if (!g_file_set_contents(profile, init_data,strlen(init_data),NULL))
{
g_free(init_data);
return NULL;
}
g_free(init_data);
mc_profile = mc_config_init(profile);
}
return mc_profile;
return profile;
}
void
load_setup (void)
{
char *gp_name;
char *profile;
int i;
setup_init ();
profile = setup_init ();
/* mc.lib is common for all users, but has priority lower than
~/.mc/ini. FIXME: it's only used for keys and treestore now */
gp_name = concat_dir_and_file (mc_home, "mc.lib");
mc_global_profile = mc_config_init(gp_name);
global_profile_name = concat_dir_and_file (mc_home, "mc.lib");
/* Load integer boolean options */
for (i = 0; int_options[i].opt_name; i++)
*int_options[i].opt_addr =
mc_config_get_int(mc_profile, CONFIG_APP_SECTION, int_options[i].opt_name, *int_options[i].opt_addr);
get_int (profile, int_options[i].opt_name, *int_options[i].opt_addr);
/* Load string options */
for (i = 0; str_options[i].opt_name != NULL; i++)
*str_options[i].opt_addr =
mc_config_get_string (mc_profile, CONFIG_APP_SECTION, str_options[i].opt_name, str_options[i].opt_defval);
*str_options[i].opt_addr = get_config_string (profile,
str_options[i].opt_name, str_options[i].opt_defval);
load_layout ();
load_layout (profile);
load_panelize ();
@ -575,56 +545,61 @@ load_setup (void)
if (!other_dir){
char *buffer;
buffer = mc_config_get_string(mc_profile, "Dirs", "other_dir", ".");
buffer = (char*) g_malloc (MC_MAXPATHLEN);
load_string ("Dirs", "other_dir", ".", buffer,
MC_MAXPATHLEN);
if (vfs_file_is_local (buffer))
other_dir = buffer;
else
g_free (buffer);
}
boot_current_is_left = mc_config_get_int( mc_profile, "Dirs", "current_is_left", 1);
boot_current_is_left =
GetPrivateProfileInt ("Dirs", "current_is_left", 1, profile);
#ifdef USE_NETCODE
ftpfs_proxy_host = mc_config_get_string(mc_profile, "Misc", "ftp_proxy_host", "gate");
ftpfs_proxy_host = do_load_string ("Misc", "ftp_proxy_host", "gate");
#endif
setup_color_string = mc_config_get_string(mc_profile, "Misc", "find_ignore_dirs", "");
if (setup_color_string[0])
load_string ("Misc", "find_ignore_dirs", "", setup_color_string,
sizeof (setup_color_string));
if (setup_color_string [0])
find_ignore_dirs = g_strconcat (":", setup_color_string, ":", (char *) NULL);
g_free(setup_color_string);
/* The default color and the terminal dependent color */
setup_color_string = mc_config_get_string(mc_profile, "Colors", "base_color", "");
term_color_string = mc_config_get_string(mc_profile, "Colors", getenv ("TERM"), "");
color_terminal_string = mc_config_get_string(mc_profile, "Colors", "color_terminals", "");
load_string ("Colors", "base_color", "", setup_color_string,
sizeof (setup_color_string));
load_string ("Colors", getenv ("TERM"), "",
term_color_string, sizeof (term_color_string));
load_string ("Colors", "color_terminals", "",
color_terminal_string, sizeof (color_terminal_string));
/* Load the directory history */
/* directory_history_load (); */
/* Remove the temporal entries */
mc_config_del_group (mc_profile, "Temporal:New Left Panel");
mc_config_del_group (mc_profile, "Temporal:New Right Panel");
profile_clean_section ("Temporal:New Left Panel", profile_name);
profile_clean_section ("Temporal:New Right Panel", profile_name);
#if defined(USE_VFS) && defined (USE_NETCODE)
ftpfs_init_passwd ();
#endif /* USE_VFS && USE_NETCODE */
#ifdef HAVE_CHARSET
if ( load_codepages_list() > 0 ) {
char *cpname;
cpname = mc_config_get_string(mc_profile, "Misc", "display_codepage", "");
char cpname[128];
load_string( "Misc", "display_codepage", "",
cpname, sizeof(cpname) );
if ( cpname[0] != '\0' )
{
display_codepage = get_codepage_index( cpname );
cp_display = get_codepage_id (display_codepage);
}
g_free(cpname);
cpname = mc_config_get_string(mc_profile, "Misc", "source_codepage", "");
load_string( "Misc", "source_codepage", "",
cpname, sizeof(cpname) );
if ( cpname[0] != '\0' )
{
source_codepage = get_codepage_index( cpname );
cp_source = get_codepage_id (source_codepage);
}
g_free(cpname);
}
init_translation_table( source_codepage, display_codepage );
if ( get_codepage_id( display_codepage ) )
@ -636,40 +611,68 @@ load_setup (void)
char *
load_anon_passwd ()
{
char *buffer;
char *ret;
char buffer [255];
buffer = mc_config_get_string(mc_profile, "Misc", "ftpfs_password", "");
load_string ("Misc", "ftpfs_password", "", buffer, sizeof (buffer));
if (buffer [0])
ret = g_strdup (buffer);
return g_strdup (buffer);
else
ret = NULL;
g_free(buffer);
return ret;
return 0;
}
#endif /* USE_VFS && USE_NETCODE */
void done_setup (void)
{
g_free(color_terminal_string);
g_free(term_color_string);
g_free(setup_color_string);
mc_config_deinit(mc_profile);
mc_config_deinit(mc_global_profile);
g_free (profile_name);
g_free (global_profile_name);
done_hotlist ();
done_panelize ();
/* directory_history_free (); */
}
static void
load_keys_from_section (const char *terminal, const char *profile_name)
{
char *section_name;
void *profile_keys;
char *key, *value, *valcopy;
int key_code;
if (!terminal)
return;
section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
profile_keys = profile_init_iterator (section_name, profile_name);
g_free (section_name);
while (profile_keys){
profile_keys = profile_iterator_next (profile_keys, &key, &value);
/* copy=other causes all keys from [terminal:other] to be loaded. */
if (g_strcasecmp (key, "copy") == 0) {
load_keys_from_section (value, profile_name);
continue;
}
key_code = lookup_key (key);
if (key_code){
valcopy = convert_controls (value);
define_sequence (key_code, valcopy, MCKEY_NOACTION);
g_free (valcopy);
}
}
}
void load_key_defs (void)
{
/*
* Load keys from mc.lib before ~/.mc/ini, so that the user
* definitions override global settings.
*/
load_keys_from_section ("general", mc_global_profile);
load_keys_from_section (getenv ("TERM"), mc_global_profile);
load_keys_from_section ("general", mc_profile);
load_keys_from_section (getenv ("TERM"), mc_profile);
load_keys_from_section ("general", global_profile_name);
load_keys_from_section (getenv ("TERM"), global_profile_name);
load_keys_from_section ("general", profile_name);
load_keys_from_section (getenv ("TERM"), profile_name);
/* We don't want a huge database loaded in core */
free_profile_name (global_profile_name);
}

View File

@ -7,11 +7,10 @@
#define MC_SETUP_H
#include "panel.h"
struct mc_config_struct;
struct mc_config_struct *setup_init (void);
void save_configure (void);
char *setup_init (void);
void save_layout (void);
void save_configure (void);
void load_setup (void);
void save_setup (void);
void done_setup (void);
@ -21,12 +20,12 @@ char *load_anon_passwd (void);
void panel_save_setup (struct WPanel *panel, const char *section);
void panel_load_setup (struct WPanel *panel, const char *section);
extern struct mc_config_struct *mc_profile;
extern struct mc_config_struct *mc_global_profile;
extern char *profile_name;
extern char *global_profile_name;
extern char *setup_color_string;
extern char *term_color_string;
extern char *color_terminal_string;
extern char setup_color_string[];
extern char term_color_string[];
extern char color_terminal_string[];
extern int startup_left_mode;
extern int startup_right_mode;

View File

@ -3,8 +3,8 @@
*
* Contains a storage of the file system tree representation
*
Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007,
2009 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007
Free Software Foundation, Inc.
Written: 1994, 1996 Janne Kukonlehto
1997 Norbert Warmuth
@ -49,7 +49,7 @@
#include "global.h"
#include "treestore.h"
#include "../src/mcconfig/mcconfig.h"
#include "profile.h"
#include "setup.h"
#define TREE_SIGNATURE "Midnight Commander TreeStore v 2.0"
@ -729,22 +729,17 @@ static void
process_special_dirs(GList ** special_dirs, char *file)
{
char *token;
char *buffer;
char *buffer = g_malloc(4096);
char *s;
mc_config_t *cfg;
cfg = mc_config_init(file);
if (cfg == NULL)
return;
buffer = mc_config_get_string(cfg, "Special dirs", "list", "");
GetPrivateProfileString("Special dirs", "list",
"", buffer, 4096, file);
s = buffer;
while ((token = strtok(s, ",")) != NULL) {
*special_dirs = g_list_prepend(*special_dirs, g_strdup(token));
s = NULL;
}
g_free(buffer);
mc_config_deinit(cfg);
}
static gboolean
@ -757,8 +752,8 @@ should_skip_directory(const char *dir)
if (loaded == 0) {
loaded = 1;
setup_init();
process_special_dirs(&special_dirs, mc_profile->ini_path);
process_special_dirs(&special_dirs, mc_global_profile->ini_path);
process_special_dirs(&special_dirs, profile_name);
process_special_dirs(&special_dirs, global_profile_name);
}
for (l = special_dirs; l; l = l->next) {

View File

@ -1,6 +1,6 @@
/* Various utilities
Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2007, 2009 Free Software Foundation, Inc.
2004, 2005, 2007 Free Software Foundation, Inc.
Written 1994, 1995, 1996 by:
Miguel de Icaza, Janne Kukonlehto, Dugan Porter,
Jakub Jelinek, Mauricio Plaza.
@ -39,7 +39,7 @@
#include <unistd.h>
#include "global.h"
#include "../src/mcconfig/mcconfig.h"
#include "profile.h"
#include "main.h" /* mc_home */
#include "cmd.h" /* guess_message_value */
#include "mountlist.h"
@ -497,6 +497,35 @@ extension (const char *filename)
return (d != NULL) ? d + 1 : "";
}
int
get_int (const char *file, const char *key, int def)
{
return GetPrivateProfileInt (app_text, key, def, file);
}
int
set_int (const char *file, const char *key, int value)
{
char buffer [BUF_TINY];
g_snprintf (buffer, sizeof (buffer), "%d", value);
return WritePrivateProfileString (app_text, key, buffer, file);
}
extern char *
get_config_string (const char *file, const char *key, const char *defval)
{
char buffer[1024];
(void)GetPrivateProfileString (app_text, key, defval, buffer, sizeof(buffer), file);
return g_strdup (buffer);
}
extern void
set_config_string (const char *file, const char *key, const char *val)
{
(void)WritePrivateProfileString (app_text, key, val, file);
}
int
exist_file (const char *name)
{

View File

@ -92,6 +92,12 @@ char *diff_two_paths (const char *first, const char *second);
/* Returns the basename of fname. The result is a pointer into fname. */
const char *x_basename (const char *fname);
/* Profile managing functions */
int set_int (const char *, const char *, int);
int get_int (const char *, const char *, int);
extern char * get_config_string (const char *, const char *, const char *);
extern void set_config_string (const char *, const char *, const char *);
char *load_file (const char *filename);
char *load_mc_home_file (const char *filename, char ** allocated_filename);

View File

@ -1,7 +1,7 @@
/* Widgets for the Midnight Commander
Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
2004, 2005, 2006, 2007 Free Software Foundation, Inc.
Authors: 1994, 1995 Radek Doulik
1994, 1995 Miguel de Icaza
@ -46,7 +46,7 @@
#include "widget.h"
#include "win.h"
#include "key.h" /* XCTRL and ALT macros */
#include "../src/mcconfig/mcconfig.h"
#include "profile.h" /* for history loading and saving */
#include "wtools.h" /* For common_dialog_repaint() */
#include "main.h" /* for `slow_terminal' */
#include "strutil.h"
@ -892,8 +892,6 @@ history_get (const char *input_name)
int i;
GList *hist;
char *profile;
mc_config_t *cfg;
char *this_entry;
hist = NULL;
@ -904,19 +902,17 @@ history_get (const char *input_name)
if (!*input_name)
return NULL;
profile = concat_dir_and_file (home_dir, HISTORY_FILE_NAME);
cfg = mc_config_init(profile);
for (i = 0;; i++) {
char key_name[BUF_TINY];
char this_entry[BUF_LARGE];
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);
GetPrivateProfileString (input_name, key_name, "", this_entry,
sizeof (this_entry), profile);
if (!*this_entry)
break;
}
hist = list_append_unique (hist, this_entry);
hist = list_append_unique (hist, g_strdup (this_entry));
}
mc_config_deinit(cfg);
g_free (profile);
/* return pointer to the last entry in the list */
@ -930,7 +926,6 @@ history_put (const char *input_name, GList *h)
{
int i;
char *profile;
mc_config_t *cfg;
if (!input_name)
return;
@ -962,10 +957,8 @@ history_put (const char *input_name, GList *h)
for (i = 0; i < num_history_items_recorded - 1 && h->prev; i++)
h = g_list_previous (h);
cfg = mc_config_init(profile);
if (input_name)
mc_config_del_group(cfg,input_name);
profile_clean_section (input_name, profile);
/* dump histories into profile */
for (i = 0; h; h = g_list_next (h)) {
@ -977,11 +970,11 @@ history_put (const char *input_name, GList *h)
if (text && *text) {
char key_name[BUF_TINY];
g_snprintf (key_name, sizeof (key_name), "%d", i++);
mc_config_set_string(cfg,input_name, key_name, text);
WritePrivateProfileString (input_name, key_name, text,
profile);
}
}
mc_config_deinit(cfg);
g_free (profile);
}