Merge branch '2848_keymap_load'

* 2848_keymap_load:
  Allow define keymap file without .keymap extension
  Optimization of ini files load.
  mc.keymap.default, mc.keymap.emacs: comment out unassigned commands.
  Ticket #2848: fixup of user-defined keymap load.
This commit is contained in:
Andrew Borodin 2012-07-31 14:50:33 +04:00
commit 849fe8e4b1
18 changed files with 293 additions and 264 deletions

View File

@ -66,7 +66,7 @@ Display configure options.
Reset softkeys to their default from the termcap/terminfo Reset softkeys to their default from the termcap/terminfo
database. Only useful on HP terminals when the function keys don't work. database. Only useful on HP terminals when the function keys don't work.
.TP .TP
.I \-K file .I \-K file, \-\-keymap=file
Specify a name of keymap file in the command line. Specify a name of keymap file in the command line.
.TP .TP
.I \-\-nokeymap .I \-\-nokeymap
@ -325,7 +325,13 @@ the input lines in the query dialogs.
.\"NODE " Keys_redefine" .\"NODE " Keys_redefine"
.SH " Redefine hotkey bindings" .SH " Redefine hotkey bindings"
Hotkey bindings may be read from external file (keymap\-file). Hotkey bindings may be read from external file (keymap\-file).
A keymap\-file is searched on the following algorithm (to the first one found): Initially, Mignight Commander creates key bindings using keymap defined
in the source code. Then, two files
.B %prefix%/share/mc/mc.keymap
and
.B %sysconfdir%/mc/mc.keymap
are loaded always, sequentially reassigned key bindings defined earlier.
User\-defined keymap\-file is searched on the following algorithm (to the first one found):
.IP .IP
.br .br
1) command line option 1) command line option
@ -345,11 +351,6 @@ of config file.
4) File 4) File
.B ~/.config/mc/mc.keymap .B ~/.config/mc/mc.keymap
.br .br
5) File
.B %sysconfdir%/mc/mc.keymap
.br
6) File
.B %prefix%/share/mc/mc.keymap
.PP .PP
Command line option, environment variable and parameter in config file may Command line option, environment variable and parameter in config file may
contain the absolute path to the keymap\-file (with the extension \.keymap contain the absolute path to the keymap\-file (with the extension \.keymap

View File

@ -79,7 +79,7 @@ UNIX\-подобных операционных системах.
termcap/terminfo. Этот ключ используется только на терминалах HP, где termcap/terminfo. Этот ключ используется только на терминалах HP, где
функциональные клавиши не работают. функциональные клавиши не работают.
.TP .TP
.I \-K файл .I \-K файл, \-\-keymap=файл
Задаёт файл клавиатурных команд для переопределения привязки клавиатурных Задаёт файл клавиатурных команд для переопределения привязки клавиатурных
комбинаций к действиям. комбинаций к действиям.
.TP .TP
@ -320,8 +320,14 @@ S\-<символ> означает, что нужно держать в нажа
.\"NODE " Keys_redefine" .\"NODE " Keys_redefine"
.SH " Переопределение клавиатурных команд" .SH " Переопределение клавиатурных команд"
Клавиатурные команды могут быть прочитаны из внешнего файла. Клавиатурные команды могут быть прочитаны из внешнего файла.
Поиск файла клавиатурных команд производится по следующему алгоритму Сначала Midnight Commander создаёт карту клавиатурных команд из списка,
(до первого нахождения файла): определённого в исходном коде. Затем всегда загружаются два файла
.B %sysconfdir%/mc/mc.keymap
и
.B %prefix%/share/mc/mc.keymap ,
последовательно переопределяя ранее загруженные команды.
Поиск файла клавиатурных команд, определённого пользователем, производится
по следующему алгоритму (до первого нахождения файла):
.IP .IP
.br .br
1) параметр командной строки 1) параметр командной строки
@ -341,12 +347,6 @@ S\-<символ> означает, что нужно держать в нажа
4) файл 4) файл
.B ~/.config/mc/mc.keymap .B ~/.config/mc/mc.keymap
.br .br
5) файл
.B %sysconfdir%/mc/mc.keymap
.br
6) файл
.B %prefix%/share/mc/mc.keymap
.PP .PP
Параметры в трёх первых случаях могут содержать абсолютный путь к файлу Параметры в трёх первых случаях могут содержать абсолютный путь к файлу
клавиатурных команд либо просто название схемы привязки (с расширением клавиатурных команд либо просто название схемы привязки (с расширением

View File

@ -184,9 +184,9 @@ mc_fhl_read_ini_file (mc_fhl_t * fhl, const gchar * filename)
return FALSE; return FALSE;
if (fhl->config != NULL) if (fhl->config != NULL)
return mc_config_read_file (fhl->config, filename, FALSE); return mc_config_read_file (fhl->config, filename, TRUE, FALSE);
fhl->config = mc_config_init (filename); fhl->config = mc_config_init (filename, TRUE);
return (fhl->config != NULL); return (fhl->config != NULL);
} }

View File

@ -29,8 +29,8 @@ extern mc_config_t *mc_panels_config;
/* mcconfig/common.c: */ /* mcconfig/common.c: */
mc_config_t *mc_config_init (const gchar *); mc_config_t *mc_config_init (const gchar * ini_path, gboolean read_only);
void mc_config_deinit (mc_config_t *); void mc_config_deinit (mc_config_t * mc_config);
gboolean mc_config_del_key (mc_config_t *, const char *, const gchar *); gboolean mc_config_del_key (mc_config_t *, const char *, const gchar *);
gboolean mc_config_del_group (mc_config_t *, const char *); gboolean mc_config_del_group (mc_config_t *, const char *);
@ -38,7 +38,7 @@ gboolean mc_config_del_group (mc_config_t *, const char *);
gboolean mc_config_has_param (const mc_config_t *, const char *, const gchar *); gboolean mc_config_has_param (const mc_config_t *, const char *, const gchar *);
gboolean mc_config_has_group (mc_config_t *, const char *); gboolean mc_config_has_group (mc_config_t *, const char *);
gboolean mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean read_only,
gboolean remove_empty); gboolean remove_empty);
gboolean mc_config_save_file (mc_config_t * config, GError ** error); gboolean mc_config_save_file (mc_config_t * config, GError ** error);

View File

@ -102,7 +102,7 @@ mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path,
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
mc_config_t * mc_config_t *
mc_config_init (const gchar * ini_path) mc_config_init (const gchar * ini_path, gboolean read_only)
{ {
mc_config_t *mc_config; mc_config_t *mc_config;
struct stat st; struct stat st;
@ -128,8 +128,13 @@ mc_config_init (const gchar * ini_path)
vpath = vfs_path_from_str (ini_path); vpath = vfs_path_from_str (ini_path);
if (mc_stat (vpath, &st) == 0 && st.st_size != 0) if (mc_stat (vpath, &st) == 0 && st.st_size != 0)
{ {
GKeyFileFlags flags = G_KEY_FILE_NONE;
if (!read_only)
flags |= G_KEY_FILE_KEEP_COMMENTS;
/* file exists and not empty */ /* file exists and not empty */
g_key_file_load_from_file (mc_config->handle, ini_path, G_KEY_FILE_KEEP_COMMENTS, NULL); g_key_file_load_from_file (mc_config->handle, ini_path, flags, NULL);
} }
vfs_path_free (vpath); vfs_path_free (vpath);
} }
@ -207,7 +212,8 @@ mc_config_del_group (mc_config_t * mc_config, const char *group)
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
gboolean gboolean
mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean remove_empty) mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean read_only,
gboolean remove_empty)
{ {
mc_config_t *tmp_config; mc_config_t *tmp_config;
gchar **groups, **curr_grp; gchar **groups, **curr_grp;
@ -217,7 +223,7 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean r
if (mc_config == NULL) if (mc_config == NULL)
return FALSE; return FALSE;
tmp_config = mc_config_init (ini_path); tmp_config = mc_config_init (ini_path, read_only);
if (tmp_config == NULL) if (tmp_config == NULL)
return FALSE; return FALSE;

View File

@ -281,7 +281,7 @@ mc_deserialize_config (const char *data, GError ** error)
{ {
char *current_group = NULL, *current_param = NULL, *current_value = NULL; char *current_group = NULL, *current_param = NULL, *current_value = NULL;
size_t current_position = 0; size_t current_position = 0;
mc_config_t *ret_data = mc_config_init (NULL); mc_config_t *ret_data;
enum automat_status enum automat_status
{ {
WAIT_GROUP, WAIT_GROUP,
@ -289,6 +289,8 @@ mc_deserialize_config (const char *data, GError ** error)
WAIT_VALUE WAIT_VALUE
} current_status = WAIT_GROUP; } current_status = WAIT_GROUP;
ret_data = mc_config_init (NULL, FALSE);
while (data != NULL) while (data != NULL)
{ {
if ((current_status == WAIT_GROUP) && (*data == 'p') && (current_group != NULL)) if ((current_status == WAIT_GROUP) && (*data == 'p') && (current_group != NULL))

View File

@ -51,7 +51,7 @@ mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir
file_name = g_build_filename (base_dir, MC_SKINS_SUBDIR, mc_skin->name, NULL); file_name = g_build_filename (base_dir, MC_SKINS_SUBDIR, mc_skin->name, NULL);
if (exist_file (file_name)) if (exist_file (file_name))
{ {
mc_skin->config = mc_config_init (file_name); mc_skin->config = mc_config_init (file_name, TRUE);
g_free (file_name); g_free (file_name);
return (mc_skin->config != NULL); return (mc_skin->config != NULL);
} }
@ -63,7 +63,7 @@ mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir
if (exist_file (file_name)) if (exist_file (file_name))
{ {
mc_skin->config = mc_config_init (file_name); mc_skin->config = mc_config_init (file_name, TRUE);
g_free (file_name); g_free (file_name);
return (mc_skin->config != NULL); return (mc_skin->config != NULL);
} }
@ -89,7 +89,7 @@ mc_skin_ini_file_load (mc_skin_t * mc_skin)
g_free (file_name); g_free (file_name);
if (!g_path_is_absolute (mc_skin->name)) if (!g_path_is_absolute (mc_skin->name))
return FALSE; return FALSE;
mc_skin->config = mc_config_init (mc_skin->name); mc_skin->config = mc_config_init (mc_skin->name, TRUE);
return (mc_skin->config != NULL); return (mc_skin->config != NULL);
} }
g_free (file_name); g_free (file_name);
@ -127,7 +127,7 @@ mc_skin_ini_file_parse (mc_skin_t * mc_skin)
void void
mc_skin_set_hardcoded_skin (mc_skin_t * mc_skin) mc_skin_set_hardcoded_skin (mc_skin_t * mc_skin)
{ {
mc_skin->config = mc_config_init (NULL); mc_skin->config = mc_config_init (NULL, TRUE);
mc_config_set_string (mc_skin->config, "skin", "description", "hardcoded skin"); mc_config_set_string (mc_skin->config, "skin", "description", "hardcoded skin");

View File

@ -1053,7 +1053,7 @@ vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element)
char * char *
vfs_path_serialize (const vfs_path_t * vpath, GError ** error) vfs_path_serialize (const vfs_path_t * vpath, GError ** error)
{ {
mc_config_t *cpath = mc_config_init (NULL); mc_config_t *cpath;
ssize_t element_index; ssize_t element_index;
char *ret_value; char *ret_value;
@ -1063,6 +1063,9 @@ vfs_path_serialize (const vfs_path_t * vpath, GError ** error)
return NULL; return NULL;
} }
cpath = mc_config_init (NULL, FALSE);
for (element_index = 0; element_index < vfs_path_elements_count (vpath); element_index++) for (element_index = 0; element_index < vfs_path_elements_count (vpath); element_index++)
{ {
char *groupname; char *groupname;
@ -1106,10 +1109,11 @@ vfs_path_serialize (const vfs_path_t * vpath, GError ** error)
vfs_path_t * vfs_path_t *
vfs_path_deserialize (const char *data, GError ** error) vfs_path_deserialize (const char *data, GError ** error)
{ {
mc_config_t *cpath = mc_deserialize_config (data, error); mc_config_t *cpath;
size_t element_index = 0; size_t element_index = 0;
vfs_path_t *vpath; vfs_path_t *vpath;
cpath = mc_deserialize_config (data, error);
if (cpath == NULL) if (cpath == NULL)
return NULL; return NULL;

View File

@ -165,7 +165,7 @@ dlg_read_history (Dlg_head * h)
return; return;
profile = mc_config_get_full_path (MC_HISTORY_FILE); profile = mc_config_get_full_path (MC_HISTORY_FILE);
event_data.cfg = mc_config_init (profile); event_data.cfg = mc_config_init (profile, TRUE);
event_data.receiver = NULL; event_data.receiver = NULL;
/* create all histories in dialog */ /* create all histories in dialog */
@ -1335,7 +1335,7 @@ dlg_save_history (Dlg_head * h)
{ {
ev_history_load_save_t event_data; ev_history_load_save_t event_data;
event_data.cfg = mc_config_init (profile); event_data.cfg = mc_config_init (profile, FALSE);
event_data.receiver = NULL; event_data.receiver = NULL;
/* get all histories in dialog */ /* get all histories in dialog */

View File

@ -151,7 +151,7 @@ history_get (const char *input_name)
return NULL; return NULL;
profile = mc_config_get_full_path (MC_HISTORY_FILE); profile = mc_config_get_full_path (MC_HISTORY_FILE);
cfg = mc_config_init (profile); cfg = mc_config_init (profile, TRUE);
hist = history_load (cfg, input_name); hist = history_load (cfg, input_name);

View File

@ -2,9 +2,9 @@
Help = f1 Help = f1
UserMenu = f2 UserMenu = f2
View = f3 View = f3
ViewFile = # ViewFile =
Edit = f4 Edit = f4
EditForceInternal = # EditForceInternal =
Copy = f5 Copy = f5
Move = f6 Move = f6
MakeDir = f7 MakeDir = f7
@ -21,9 +21,9 @@ DirSize = ctrl-space
Suspend = ctrl-z Suspend = ctrl-z
Swap = ctrl-u Swap = ctrl-u
History = alt-h History = alt-h
PanelListing = # PanelListing =
PanelListingSwitch = alt-t PanelListingSwitch = alt-t
PanelListingChange = # PanelListingChange =
ShowHidden = alt-dot ShowHidden = alt-dot
SplitVertHoriz = alt-comma SplitVertHoriz = alt-comma
SplitEqual = alt-equal SplitEqual = alt-equal
@ -37,20 +37,20 @@ Select = kpplus
Unselect = kpminus Unselect = kpminus
SelectInvert = kpasterisk SelectInvert = kpasterisk
ScreenList = alt-prime ScreenList = alt-prime
OptionsLayout = # OptionsLayout =
OptionsPanel = # OptionsPanel =
OptionsConfirm = # OptionsConfirm =
OptionsDisplayBits = # OptionsDisplayBits =
OptionsVfs = # OptionsVfs =
LearnKeys = # LearnKeys =
SaveSetup = # SaveSetup =
EditExtensionsFile = # EditExtensionsFile =
EditFileHighlightFile = # EditFileHighlightFile =
Filter = # Filter =
ConnectFish = # ConnectFish =
ConnectFtp = # ConnectFtp =
ConnectSmb = # ConnectSmb =
Undelete = # Undelete =
ExtendedKeyMap = ctrl-x ExtendedKeyMap = ctrl-x
[main:xmap] [main:xmap]
@ -80,8 +80,8 @@ Search = ctrl-s; alt-s
Mark = insert; ctrl-t Mark = insert; ctrl-t
MarkUp = shift-up MarkUp = shift-up
MarkDown = shift-down MarkDown = shift-down
MarkLeft = # MarkLeft =
MarkRight = # MarkRight =
Down = down; ctrl-n Down = down; ctrl-n
Up = up; ctrl-p Up = up; ctrl-p
Left = left Left = left
@ -101,8 +101,8 @@ Unselect = alt-minus
SelectInvert = alt-asterisk SelectInvert = alt-asterisk
CdChild = ctrl-pgdn CdChild = ctrl-pgdn
CdParent = ctrl-pgup CdParent = ctrl-pgup
CdParentSmart = # CdParentSmart =
Panelize = # Panelize =
History = alt-shift-h History = alt-shift-h
HistoryNext = alt-u HistoryNext = alt-u
HistoryPrev = alt-y HistoryPrev = alt-y
@ -113,16 +113,16 @@ PanelOtherSync = alt-i
SelectCodepage = alt-e SelectCodepage = alt-e
Top = alt-lt; home; a1 Top = alt-lt; home; a1
Bottom = alt-gt; end; c1 Bottom = alt-gt; end; c1
Sort = # Sort =
SortPrev = # SortPrev =
SortNext = # SortNext =
SortReverse = # SortReverse =
SortByName = # SortByName =
SortByExt = # SortByExt =
SortBySize = # SortBySize =
SortByMTime = # SortByMTime =
ScrollLeft = # ScrollLeft =
ScrollRight = # ScrollRight =
[dialog] [dialog]
Ok = enter Ok = enter
@ -149,18 +149,18 @@ Backspace = backspace; ctrl-h
Delete = delete; ctrl-d Delete = delete; ctrl-d
DeleteToWordBegin = alt-backspace DeleteToWordBegin = alt-backspace
DeleteToWordEnd = alt-d DeleteToWordEnd = alt-d
Mark = # Mark =
Remove = ctrl-w Remove = ctrl-w
Cut = # Cut =
Store = alt-w Store = alt-w
Paste = # Paste =
Yank = ctrl-y Yank = ctrl-y
DeleteToEnd = ctrl-k DeleteToEnd = ctrl-k
HistoryPrev = alt-p; ctrl-down HistoryPrev = alt-p; ctrl-down
HistoryNext = alt-n; ctrl-up HistoryNext = alt-n; ctrl-up
History = alt-h History = alt-h
Complete = alt-tab Complete = alt-tab
Clear = # Clear =
MarkLeft = shift-left MarkLeft = shift-left
MarkRight = shift-right MarkRight = shift-right
MarkToWordBegin = ctrl-shift-left MarkToWordBegin = ctrl-shift-left
@ -247,26 +247,26 @@ DeleteToWordBegin = alt-backspace
DeleteToWordEnd = alt-d DeleteToWordEnd = alt-d
DeleteLine = ctrl-y DeleteLine = ctrl-y
DeleteToEnd = ctrl-k DeleteToEnd = ctrl-k
DeleteToHome = # DeleteToHome =
ParagraphUp = # ParagraphUp =
ParagraphDown = # ParagraphDown =
Save = f2 Save = f2
EditFile = # EditFile =
EditNew = ctrl-n EditNew = ctrl-n
SaveAs = f12; ctrl-f2 SaveAs = f12; ctrl-f2
Close = # Close =
Mark = f3 Mark = f3
Copy = f5 Copy = f5
Move = f6 Move = f6
Remove = f8 Remove = f8
MarkLine = # MarkLine =
MarkWord = # MarkWord =
MarkAll = # MarkAll =
Unmark = # Unmark =
Search = f7 Search = f7
SearchContinue = f17 SearchContinue = f17
BlockShiftLeft = # BlockShiftLeft =
BlockShiftRight = # BlockShiftRight =
MarkPageUp = shift-pgup MarkPageUp = shift-pgup
MarkPageDown = shift-pgdn MarkPageDown = shift-pgdn
MarkLeft = shift-left MarkLeft = shift-left
@ -283,18 +283,18 @@ MarkToPageBegin = ctrl-shift-pgup
MarkToPageEnd = ctrl-shift-pgdn MarkToPageEnd = ctrl-shift-pgdn
MarkScrollUp = ctrl-shift-up MarkScrollUp = ctrl-shift-up
MarkScrollDown = ctrl-shift-down MarkScrollDown = ctrl-shift-down
MarkParagraphUp = # MarkParagraphUp =
MarkParagraphDown = # MarkParagraphDown =
MarkColumnPageUp = alt-pgup MarkColumnPageUp = alt-pgup
MarkColumnPageDown = alt-pgdn MarkColumnPageDown = alt-pgdn
MarkColumnLeft = alt-left MarkColumnLeft = alt-left
MarkColumnRight = alt-right MarkColumnRight = alt-right
MarkColumnUp = alt-up MarkColumnUp = alt-up
MarkColumnDown = alt-down MarkColumnDown = alt-down
MarkColumnScrollUp = # MarkColumnScrollUp =
MarkColumnScrollDown = # MarkColumnScrollDown =
MarkColumnParagraphUp = # MarkColumnParagraphUp =
MarkColumnParagraphDown = # MarkColumnParagraphDown =
BlockSave = ctrl-f BlockSave = ctrl-f
MarkColumn = f13 MarkColumn = f13
Replace = f4 Replace = f4
@ -304,7 +304,7 @@ InsertFile = f15
Quit = f10; esc Quit = f10; esc
InsertOverwrite = insert InsertOverwrite = insert
Help = f1 Help = f1
Date = # Date =
Refresh = ctrl-l Refresh = ctrl-l
Goto = alt-l Goto = alt-l
Sort = alt-t Sort = alt-t
@ -318,36 +318,36 @@ Bookmark = alt-k
BookmarkFlush = alt-o BookmarkFlush = alt-o
BookmarkNext = alt-j BookmarkNext = alt-j
BookmarkPrev = alt-i BookmarkPrev = alt-i
History = # History =
Shell = ctrl-o Shell = ctrl-o
InsertLiteral = ctrl-q InsertLiteral = ctrl-q
MacroStartRecord = # MacroStartRecord =
MacroStopRecord = # MacroStopRecord =
MacroStartStopRecord = ctrl-r MacroStartStopRecord = ctrl-r
MacroDelete = # MacroDelete =
ShowNumbers = alt-n ShowNumbers = alt-n
ShowTabTws = alt-underline ShowTabTws = alt-underline
SyntaxOnOff = ctrl-s SyntaxOnOff = ctrl-s
SyntaxChoose = # SyntaxChoose =
ShowMargin = # ShowMargin =
Find = alt-enter Find = alt-enter
FilePrev = alt-minus FilePrev = alt-minus
FileNext = alt-plus FileNext = alt-plus
RepeatStartStopRecord = # RepeatStartStopRecord =
SelectCodepage = alt-e SelectCodepage = alt-e
Options = # Options =
OptionsSaveMode = # OptionsSaveMode =
SpellCheck = # SpellCheck =
SpellCheckCurrentWord = ctrl-p SpellCheckCurrentWord = ctrl-p
SpellCheckSelectLang = # SpellCheckSelectLang =
LearnKeys = # LearnKeys =
WindowMove = # WindowMove =
WindowResize = # WindowResize =
WindowFullscreen = # WindowFullscreen =
WindowList = # WindowList =
WindowNext = # WindowNext =
WindowPrev = # WindowPrev =
ExtendedKeyMap = # ExtendedKeyMap =
[viewer] [viewer]
Help = f1 Help = f1

View File

@ -2,9 +2,9 @@
Help = f1 Help = f1
UserMenu = f2 UserMenu = f2
View = f3 View = f3
ViewFile = # ViewFile =
Edit = f4 Edit = f4
EditForceInternal = # EditForceInternal =
Copy = f5 Copy = f5
Move = f6 Move = f6
MakeDir = f7 MakeDir = f7
@ -21,9 +21,9 @@ DirSize = ctrl-space
Suspend = ctrl-z Suspend = ctrl-z
Swap = ctrl-u Swap = ctrl-u
History = alt-h History = alt-h
PanelListing = # PanelListing =
PanelListingSwitch = alt-t PanelListingSwitch = alt-t
PanelListingChange = # PanelListingChange =
ShowHidden = alt-dot ShowHidden = alt-dot
SplitVertHoriz = alt-comma SplitVertHoriz = alt-comma
SplitEqual = alt-equal SplitEqual = alt-equal
@ -37,21 +37,20 @@ Select = kpplus
Unselect = kpminus Unselect = kpminus
SelectInvert = kpasterisk SelectInvert = kpasterisk
ScreenList = alt-prime ScreenList = alt-prime
Options = # OptionsLayout =
OptionsLayout = # OptionsPanel =
OptionsPanel = # OptionsConfirm =
OptionsConfirm = # OptionsDisplayBits =
OptionsDisplayBits = # OptionsVfs =
OptionsVfs = # LearnKeys =
LearnKeys = # SaveSetup =
SaveSetup = # EditExtensionsFile =
EditExtensionsFile = # EditFileHighlightFile =
EditFileHighlightFile = # Filter =
Filter = # ConnectFish =
ConnectFish = # ConnectFtp =
ConnectFtp = # ConnectSmb =
ConnectSmb = # Undelete =
Undelete =
ExtendedKeyMap = ctrl-x ExtendedKeyMap = ctrl-x
[main:xmap] [main:xmap]
@ -81,8 +80,8 @@ Search = ctrl-s; alt-s
Mark = insert; ctrl-t Mark = insert; ctrl-t
MarkUp = shift-up MarkUp = shift-up
MarkDown = shift-down MarkDown = shift-down
MarkLeft = # MarkLeft =
MarkRight = # MarkRight =
Down = down; ctrl-n Down = down; ctrl-n
Up = up; ctrl-p Up = up; ctrl-p
Left = left Left = left
@ -102,8 +101,8 @@ Unselect = alt-minus
SelectInvert = alt-asterisk SelectInvert = alt-asterisk
CdChild = ctrl-pgdn CdChild = ctrl-pgdn
CdParent = ctrl-pgup CdParent = ctrl-pgup
Panelize = # CdParentSmart =
CdParentSmart = # Panelize =
History = alt-shift-h History = alt-shift-h
HistoryNext = alt-u HistoryNext = alt-u
HistoryPrev = alt-y HistoryPrev = alt-y
@ -114,16 +113,16 @@ PanelOtherSync = alt-i
SelectCodepage = alt-e SelectCodepage = alt-e
Top = alt-lt; home; a1 Top = alt-lt; home; a1
Bottom = alt-gt; end; c1 Bottom = alt-gt; end; c1
Sort = # Sort =
SortPrev = # SortPrev =
SortNext = # SortNext =
SortReverse = # SortReverse =
SortByName = # SortByName =
SortByExt = # SortByExt =
SortBySize = # SortBySize =
SortByMTime = # SortByMTime =
ScrollLeft = # ScrollLeft =
ScrollRight = # ScrollRight =
[dialog] [dialog]
Ok = enter Ok = enter
@ -150,24 +149,24 @@ Backspace = backspace
Delete = delete Delete = delete
DeleteToWordBegin = alt-backspace DeleteToWordBegin = alt-backspace
DeleteToWordEnd = alt-d DeleteToWordEnd = alt-d
Mark = # Mark =
Remove = ctrl-w Remove = ctrl-w
Cut = # Cut =
Store = alt-w Store = alt-w
Paste = # Paste =
Yank = ctrl-y Yank = ctrl-y
DeleteToEnd = ctrl-k DeleteToEnd = ctrl-k
HistoryPrev = alt-p; ctrl-down HistoryPrev = alt-p; ctrl-down
HistoryNext = alt-n; ctrl-up HistoryNext = alt-n; ctrl-up
History = alt-h History = alt-h
Complete = alt-tab Complete = alt-tab
Clear = # Clear =
MarkLeft = # MarkLeft =
MarkRight = # MarkRight =
MarkToWordBegin = # MarkToWordBegin =
MarkToWordEnd = # MarkToWordEnd =
MarkToHome = # MarkToHome =
MarkToEnd = # MarkToEnd =
[listbox] [listbox]
Up = up; ctrl-p Up = up; ctrl-p
@ -237,7 +236,7 @@ Home = home; ctrl-a
End = end; ctrl-e End = end; ctrl-e
Tab = tab Tab = tab
Undo = ctrl-u Undo = ctrl-u
Redo = # Redo =
Top = ctrl-home; alt-lt Top = ctrl-home; alt-lt
Bottom = ctrl-end; alt-gt Bottom = ctrl-end; alt-gt
ScrollUp = ctrl-up ScrollUp = ctrl-up
@ -248,25 +247,25 @@ DeleteToWordBegin = alt-backspace
DeleteToWordEnd = alt-d DeleteToWordEnd = alt-d
DeleteLine = ctrl-y DeleteLine = ctrl-y
DeleteToEnd = ctrl-k DeleteToEnd = ctrl-k
DeleteToHome = # DeleteToHome =
ParagraphUp = # ParagraphUp =
ParagraphDown = # ParagraphDown =
Save = f2 Save = f2
EditFile = # EditFile =
SaveAs = f12; ctrl-f2 SaveAs = f12; ctrl-f2
Close = # Close =
Mark = f3; ctrl-at Mark = f3; ctrl-at
Copy = f5 Copy = f5
Move = f6 Move = f6
Remove = f8 Remove = f8
MarkLine = # MarkLine =
MarkWord = # MarkWord =
MarkAll = # MarkAll =
Unmark = # Unmark =
Search = f7; ctrl-s Search = f7; ctrl-s
SearchContinue = f17 SearchContinue = f17
BlockShiftLeft = # BlockShiftLeft =
BlockShiftRight = # BlockShiftRight =
MarkPageUp = shift-pgup MarkPageUp = shift-pgup
MarkPageDown = shift-pgdn MarkPageDown = shift-pgdn
MarkLeft = shift-left MarkLeft = shift-left
@ -283,19 +282,19 @@ MarkToPageBegin = ctrl-shift-pgup
MarkToPageEnd = ctrl-shift-pgdn MarkToPageEnd = ctrl-shift-pgdn
MarkScrollUp = ctrl-shift-up MarkScrollUp = ctrl-shift-up
MarkScrollDown = ctrl-shift-down MarkScrollDown = ctrl-shift-down
MarkParagraphUp = # MarkParagraphUp =
MarkParagraphDown = # MarkParagraphDown =
MarkColumnPageUp = alt-pgup MarkColumnPageUp = alt-pgup
MarkColumnPageDown = alt-pgdn MarkColumnPageDown = alt-pgdn
MarkColumnLeft = alt-left MarkColumnLeft = alt-left
MarkColumnRight = alt-right MarkColumnRight = alt-right
MarkColumnUp = alt-up MarkColumnUp = alt-up
MarkColumnDown = alt-down MarkColumnDown = alt-down
MarkColumnScrollUp = # MarkColumnScrollUp =
MarkColumnScrollDown = # MarkColumnScrollDown =
MarkColumnParagraphUp = # MarkColumnParagraphUp =
MarkColumnParagraphDown = # MarkColumnParagraphDown =
BlockSave = # BlockSave =
MarkColumn = f13 MarkColumn = f13
Replace = f4 Replace = f4
ReplaceContinue = f14 ReplaceContinue = f14
@ -304,49 +303,49 @@ InsertFile = f15
Quit = f10; esc Quit = f10; esc
InsertOverwrite = insert InsertOverwrite = insert
Help = f1 Help = f1
Date = # Date =
Refresh = ctrl-l Refresh = ctrl-l
Goto = alt-l Goto = alt-l
Sort = alt-t Sort = alt-t
Mail = # Mail =
ParagraphFormat = alt-p ParagraphFormat = alt-p
MatchBracket = # MatchBracket =
ExternalCommand = alt-u ExternalCommand = alt-u
UserMenu = f11 UserMenu = f11
Menu = f9 Menu = f9
Bookmark = # Bookmark =
BookmarkFlush = # BookmarkFlush =
BookmarkNext = # BookmarkNext =
BookmarkPrev = # BookmarkPrev =
History = # History =
Shell = ctrl-o Shell = ctrl-o
InsertLiteral = ctrl-q InsertLiteral = ctrl-q
MacroStartRecord = # MacroStartRecord =
MacroStopRecord = # MacroStopRecord =
MacroStartStopRecord = ctrl-r MacroStartStopRecord = ctrl-r
MacroDelete = # MacroDelete =
ShowNumbers = alt-n ShowNumbers = alt-n
ShowTabTws = alt-underline ShowTabTws = alt-underline
SyntaxOnOff = ctrl-s SyntaxOnOff = ctrl-s
SyntaxChoose = # SyntaxChoose =
ShowMargin = # ShowMargin =
Find = alt-enter Find = alt-enter
FilePrev = alt-minus FilePrev = alt-minus
FileNext = alt-plus FileNext = alt-plus
RepeatStartStopRecord = # RepeatStartStopRecord =
SelectCodepage = alt-e SelectCodepage = alt-e
Options = # Options =
OptionsSaveMode = # OptionsSaveMode =
SpellCheck = # SpellCheck =
SpellCheckCurrentWord = # SpellCheckCurrentWord =
SpellCheckSelectLang = # SpellCheckSelectLang =
LearnKeys = # LearnKeys =
WindowMove = # WindowMove =
WindowResize = # WindowResize =
WindowFullscreen = # WindowFullscreen =
WindowList = # WindowList =
WindowNext = # WindowNext =
WindowPrev = # WindowPrev =
ExtendedKeyMap = ctrl-x ExtendedKeyMap = ctrl-x
[editor:xmap] [editor:xmap]

View File

@ -1416,7 +1416,7 @@ edit_delete_macro (WEdit * edit, int hotkey)
} }
macros_fname = mc_config_get_full_path (MC_MACRO_FILE); macros_fname = mc_config_get_full_path (MC_MACRO_FILE);
macros_config = mc_config_init (macros_fname); macros_config = mc_config_init (macros_fname, FALSE);
g_free (macros_fname); g_free (macros_fname);
if (macros_config == NULL) if (macros_config == NULL)
@ -1835,7 +1835,7 @@ edit_store_macro_cmd (WEdit * edit)
edit_delete_macro (edit, hotkey); edit_delete_macro (edit, hotkey);
macros_fname = mc_config_get_full_path (MC_MACRO_FILE); macros_fname = mc_config_get_full_path (MC_MACRO_FILE);
macros_config = mc_config_init (macros_fname); macros_config = mc_config_init (macros_fname, FALSE);
g_free (macros_fname); g_free (macros_fname);
if (macros_config == NULL) if (macros_config == NULL)
@ -1939,7 +1939,7 @@ edit_load_macro_cmd (WEdit * edit)
(void) edit; (void) edit;
macros_fname = mc_config_get_full_path (MC_MACRO_FILE); macros_fname = mc_config_get_full_path (MC_MACRO_FILE);
macros_config = mc_config_init (macros_fname); macros_config = mc_config_init (macros_fname, TRUE);
g_free (macros_fname); g_free (macros_fname);
if (macros_config == NULL) if (macros_config == NULL)

View File

@ -565,7 +565,7 @@ process_special_dirs (GList ** special_dirs, char *file)
mc_config_t *cfg; mc_config_t *cfg;
gsize buffers_len; gsize buffers_len;
cfg = mc_config_init (file); cfg = mc_config_init (file, TRUE);
if (cfg == NULL) if (cfg == NULL)
return; return;

View File

@ -578,7 +578,7 @@ create_default_keymap (void)
{ {
mc_config_t *keymap; mc_config_t *keymap;
keymap = mc_config_init (NULL); keymap = mc_config_init (NULL, TRUE);
create_default_keymap_section (keymap, KEYMAP_SECTION_MAIN, default_main_keymap); create_default_keymap_section (keymap, KEYMAP_SECTION_MAIN, default_main_keymap);
create_default_keymap_section (keymap, KEYMAP_SECTION_MAIN_EXT, default_main_x_keymap); create_default_keymap_section (keymap, KEYMAP_SECTION_MAIN_EXT, default_main_x_keymap);

View File

@ -371,33 +371,36 @@ static const struct
/** /**
Get name of config file. Get name of config file.
\param subdir @param subdir If not NULL, config is also searched in specified subdir.
if not NULL, then config also search into specified subdir. @param config_file_name If relative, file if searched in standard paths.
@returns Newly allocated string with config name or NULL if file is not found.
\param config_file_name
If specified filename is relative, then will search in standart patches.
\return
Newly allocated path to config name or NULL if file not found.
If config_file_name is a relative path, then search config in stantart paths.
*/ */
static char * static char *
load_setup_get_full_config_name (const char *subdir, const char *config_file_name) load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
{ {
/* /*
TODO: IMHO, in future this function must be placed into mc_config module. TODO: IMHO, in future, this function shall be placed in mcconfig module.
*/ */
char *lc_basename, *ret; char *lc_basename, *ret;
char *file_name;
if (config_file_name == NULL) if (config_file_name == NULL)
return NULL; return NULL;
if (g_path_is_absolute (config_file_name)) /* check for .keymap suffix */
return g_strdup (config_file_name); if (g_str_has_suffix (config_file_name, ".keymap"))
file_name = g_strdup (config_file_name);
else
file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);
canonicalize_pathname (file_name);
if (g_path_is_absolute (file_name))
return file_name;
lc_basename = g_path_get_basename (file_name);
g_free (file_name);
lc_basename = g_path_get_basename (config_file_name);
if (lc_basename == NULL) if (lc_basename == NULL)
return NULL; return NULL;
@ -409,6 +412,7 @@ load_setup_get_full_config_name (const char *subdir, const char *config_file_nam
if (exist_file (ret)) if (exist_file (ret))
{ {
g_free (lc_basename); g_free (lc_basename);
canonicalize_pathname (ret);
return ret; return ret;
} }
g_free (ret); g_free (ret);
@ -421,6 +425,7 @@ load_setup_get_full_config_name (const char *subdir, const char *config_file_nam
if (exist_file (ret)) if (exist_file (ret))
{ {
g_free (lc_basename); g_free (lc_basename);
canonicalize_pathname (ret);
return ret; return ret;
} }
g_free (ret); g_free (ret);
@ -433,11 +438,13 @@ load_setup_get_full_config_name (const char *subdir, const char *config_file_nam
g_free (lc_basename); g_free (lc_basename);
if (exist_file (ret)) if (exist_file (ret))
{
canonicalize_pathname (ret);
return ret; return ret;
}
g_free (ret); g_free (ret);
return NULL; return NULL;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -464,7 +471,7 @@ setup__move_panels_config_into_separate_file (const char *profile)
if (!exist_file (profile)) if (!exist_file (profile))
return; return;
tmp_cfg = mc_config_init (profile); tmp_cfg = mc_config_init (profile, FALSE);
if (!tmp_cfg) if (!tmp_cfg)
return; return;
@ -485,7 +492,7 @@ setup__move_panels_config_into_separate_file (const char *profile)
mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL); mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
mc_config_deinit (tmp_cfg); mc_config_deinit (tmp_cfg);
tmp_cfg = mc_config_init (profile); tmp_cfg = mc_config_init (profile, FALSE);
if (!tmp_cfg) if (!tmp_cfg)
{ {
g_strfreev (groups); g_strfreev (groups);
@ -516,17 +523,17 @@ setup__move_panels_config_into_separate_file (const char *profile)
*/ */
static void static void
load_setup_init_config_from_file (mc_config_t ** config, const char *fname) load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only)
{ {
/* /*
TODO: IMHO, in future this function must be placed into mc_config module. TODO: IMHO, in future, this function shall be placed in mcconfig module.
*/ */
if (exist_file (fname)) if (exist_file (fname))
{ {
if (*config != NULL) if (*config != NULL)
mc_config_read_file (*config, fname, TRUE); mc_config_read_file (*config, fname, read_only, TRUE);
else else
*config = mc_config_init (fname); *config = mc_config_init (fname, read_only);
} }
} }
@ -676,9 +683,10 @@ static mc_config_t *
load_setup_get_keymap_profile_config (gboolean load_from_file) load_setup_get_keymap_profile_config (gboolean load_from_file)
{ {
/* /*
TODO: IMHO, in future this function must be placed into mc_config module. TODO: IMHO, in future, this function shall be placed in mcconfig module.
*/ */
mc_config_t *keymap_config; mc_config_t *keymap_config;
char *share_keymap, *sysconfig_keymap;
char *fname, *fname2; char *fname, *fname2;
/* 0) Create default keymap */ /* 0) Create default keymap */
@ -686,47 +694,56 @@ load_setup_get_keymap_profile_config (gboolean load_from_file)
if (!load_from_file) if (!load_from_file)
return keymap_config; return keymap_config;
/* load and merge global keymaps */
/* 1) /usr/share/mc (mc_global.share_data_dir) */ /* 1) /usr/share/mc (mc_global.share_data_dir) */
fname = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, NULL); share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, NULL);
load_setup_init_config_from_file (&keymap_config, fname); load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE);
g_free (fname);
/* 2) /etc/mc (mc_global.sysconfig_dir) */ /* 2) /etc/mc (mc_global.sysconfig_dir) */
fname = g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL); sysconfig_keymap = g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL);
load_setup_init_config_from_file (&keymap_config, fname); load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE);
g_free (fname);
/* 3) ${XDG_CONFIG_HOME}/mc */ /* then load and merge one of user-defined keymap */
fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
load_setup_init_config_from_file (&keymap_config, fname);
g_free (fname);
/* 4) main config; [Midnight Commander] -> keymap */ /* 3) --keymap=<keymap> */
fname2 =
mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, "keymap", GLOBAL_KEYMAP_FILE);
fname = load_setup_get_full_config_name (NULL, fname2);
if (fname != NULL)
{
load_setup_init_config_from_file (&keymap_config, fname);
g_free (fname);
}
g_free (fname2);
/* 5) getenv("MC_KEYMAP") */
fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
if (fname != NULL)
{
load_setup_init_config_from_file (&keymap_config, fname);
g_free (fname);
}
/* 6) --keymap=<keymap> */
fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file); fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
if (fname != NULL) if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
{ {
load_setup_init_config_from_file (&keymap_config, fname); load_setup_init_config_from_file (&keymap_config, fname, TRUE);
g_free (fname); goto done;
} }
g_free (fname);
/* 4) getenv("MC_KEYMAP") */
fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
{
load_setup_init_config_from_file (&keymap_config, fname, TRUE);
goto done;
}
g_free (fname);
/* 5) main config; [Midnight Commander] -> keymap */
fname2 = mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, "keymap", NULL);
if (fname2 != NULL && *fname2 != '\0')
fname = load_setup_get_full_config_name (NULL, fname2);
g_free (fname2);
if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
{
load_setup_init_config_from_file (&keymap_config, fname, TRUE);
goto done;
}
g_free (fname);
/* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
load_setup_init_config_from_file (&keymap_config, fname, TRUE);
done:
g_free (fname);
g_free (sysconfig_keymap);
g_free (share_keymap);
return keymap_config; return keymap_config;
} }
@ -880,12 +897,12 @@ load_setup (void)
panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE); panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
mc_main_config = mc_config_init (profile); mc_main_config = mc_config_init (profile, FALSE);
if (!exist_file (panels_profile_name)) if (!exist_file (panels_profile_name))
setup__move_panels_config_into_separate_file (profile); setup__move_panels_config_into_separate_file (profile);
mc_panels_config = mc_config_init (panels_profile_name); mc_panels_config = mc_config_init (panels_profile_name, FALSE);
/* Load integer boolean options */ /* Load integer boolean options */
for (i = 0; int_options[i].opt_name != NULL; i++) for (i = 0; int_options[i].opt_name != NULL; i++)
@ -1144,7 +1161,7 @@ load_key_defs (void)
*/ */
mc_config_t *mc_global_config; mc_config_t *mc_global_config;
mc_global_config = mc_config_init (global_profile_name); mc_global_config = mc_config_init (global_profile_name, FALSE);
if (mc_global_config != NULL) if (mc_global_config != NULL)
{ {
load_keys_from_section ("general", mc_global_config); load_keys_from_section ("general", mc_global_config);

View File

@ -69,7 +69,7 @@ START_TEST (create_ini_file)
ini_filename = g_build_filename(WORKDIR, "test-create_ini_file.ini",NULL); ini_filename = g_build_filename(WORKDIR, "test-create_ini_file.ini",NULL);
unlink(ini_filename); unlink(ini_filename);
mc_config = mc_config_init (ini_filename); mc_config = mc_config_init (ini_filename, FALSE);
if (mc_config == NULL) if (mc_config == NULL)
{ {
fail("unable to create mc_congif_t object!"); fail("unable to create mc_congif_t object!");
@ -91,7 +91,7 @@ START_TEST (create_ini_file)
} }
mc_config_deinit (mc_config); mc_config_deinit (mc_config);
mc_config = mc_config_init (ini_filename); mc_config = mc_config_init (ini_filename, FALSE);
actual_value = mc_config_get_string(mc_config, "group-not-exists", "param-not_exists", NULL); actual_value = mc_config_get_string(mc_config, "group-not-exists", "param-not_exists", NULL);
fail_unless(actual_value == NULL, "return value for nonexistent ini-parameters isn't NULL (default value)!"); fail_unless(actual_value == NULL, "return value for nonexistent ini-parameters isn't NULL (default value)!");
@ -139,7 +139,7 @@ START_TEST (emulate__learn_save)
ini_filename = g_build_filename(WORKDIR, "test-emulate__learn_save.ini",NULL); ini_filename = g_build_filename(WORKDIR, "test-emulate__learn_save.ini",NULL);
unlink(ini_filename); unlink(ini_filename);
mc_config = mc_config_init (ini_filename); mc_config = mc_config_init (ini_filename, FALSE);
if (mc_config == NULL) if (mc_config == NULL)
{ {
fail("unable to create mc_congif_t object!"); fail("unable to create mc_congif_t object!");
@ -157,7 +157,7 @@ START_TEST (emulate__learn_save)
} }
mc_config_deinit (mc_config); mc_config_deinit (mc_config);
mc_config = mc_config_init (ini_filename); mc_config = mc_config_init (ini_filename, FALSE);
actual_value = mc_config_get_string_raw( mc_config, "test-group1", "test-param1", "not-exists"); actual_value = mc_config_get_string_raw( mc_config, "test-group1", "test-param1", "not-exists");
fail_unless_strcmp("T\\;E\\X\\;T-FOR-\\T\\;E\\;S\\TI\\;N'G"); fail_unless_strcmp("T\\;E\\X\\;T-FOR-\\T\\;E\\;S\\TI\\;N'G");

View File

@ -117,7 +117,7 @@ START_TEST (test_serialize_config)
GError *error = NULL; GError *error = NULL;
char *actual; char *actual;
test_data = mc_config_init (NULL); test_data = mc_config_init (NULL, FALSE);
mc_config_set_string_raw (test_data, "group1", "param1", "some value"); mc_config_set_string_raw (test_data, "group1", "param1", "some value");
mc_config_set_string (test_data, "group1", "param2", "some value "); mc_config_set_string (test_data, "group1", "param2", "some value ");