diff --git a/src/screen_keydef.c b/src/screen_keydef.c
index ad78c383d48b235ec6a12bc9f1ab8659c8821819..31c3582e4d61de964eb242669df8c9f357a286dd 100644 (file)
--- a/src/screen_keydef.c
+++ b/src/screen_keydef.c
/* ncmpc (Ncurses MPD Client)
/* ncmpc (Ncurses MPD Client)
- * (c) 2004-2010 The Music Player Daemon Project
+ * (c) 2004-2017 The Music Player Daemon Project
* Project homepage: http://musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* Project homepage: http://musicpd.org
*
* This program is free software; you can redistribute it and/or modify
#include "conf.h"
#include "screen.h"
#include "screen_utils.h"
#include "conf.h"
#include "screen.h"
#include "screen_utils.h"
+#include "options.h"
#include "Compiler.h"
#include <assert.h>
#include "Compiler.h"
#include <assert.h>
static int
save_keys(void)
{
static int
save_keys(void)
{
- FILE *f;
- char *filename;
+ char *allocated = NULL;
+ const char *filename = options.key_file;
+ if (filename == NULL) {
+ if (!check_user_conf_dir()) {
+ screen_status_printf(_("Error: Unable to create directory ~/.ncmpc - %s"),
+ strerror(errno));
+ screen_bell();
+ return -1;
+ }
- if (check_user_conf_dir()) {
- screen_status_printf(_("Error: Unable to create directory ~/.ncmpc - %s"),
- strerror(errno));
- screen_bell();
- return -1;
+ filename = allocated = build_user_key_binding_filename();
}
}
- filename = build_user_key_binding_filename();
-
- if ((f = fopen(filename,"w")) == NULL) {
+ FILE *f = fopen(filename, "w");
+ if (f == NULL) {
screen_status_printf(_("Error: %s - %s"), filename, strerror(errno));
screen_bell();
screen_status_printf(_("Error: %s - %s"), filename, strerror(errno));
screen_bell();
- g_free(filename);
+ g_free(allocated);
return -1;
}
if (write_key_bindings(f, KEYDEF_WRITE_HEADER))
return -1;
}
if (write_key_bindings(f, KEYDEF_WRITE_HEADER))
- screen_status_printf(_("Error: %s - %s"), filename, strerror(errno));
- else
screen_status_printf(_("Wrote %s"), filename);
screen_status_printf(_("Wrote %s"), filename);
+ else
+ screen_status_printf(_("Error: %s - %s"), filename, strerror(errno));
- g_free(filename);
+ g_free(allocated);
return fclose(f);
}
return fclose(f);
}
static void
overwrite_key(int cmd_index, int key_index)
{
static void
overwrite_key(int cmd_index, int key_index)
{
- int key;
- char *buf;
- command_t cmd;
-
assert(key_index < MAX_COMMAND_KEYS);
assert(key_index < MAX_COMMAND_KEYS);
- buf = g_strdup_printf(_("Enter new key for %s: "), cmds[cmd_index].name);
- key = screen_getch(buf);
+ char *buf = g_strdup_printf(_("Enter new key for %s: "),
+ cmds[cmd_index].name);
+ const int key = screen_getch(buf);
g_free(buf);
if (key == ERR) {
g_free(buf);
if (key == ERR) {
return;
}
return;
}
- cmd = find_key_command(key, cmds);
+ const command_t cmd = find_key_command(key, cmds);
if (cmd != CMD_NONE) {
screen_status_printf(_("Error: key %s is already used for %s"),
key2str(key), get_key_command_name(cmd));
if (cmd != CMD_NONE) {
screen_status_printf(_("Error: key %s is already used for %s"),
key2str(key), get_key_command_name(cmd));
{
if (cmds == NULL) {
command_definition_t *current_cmds = get_command_definitions();
{
if (cmds == NULL) {
command_definition_t *current_cmds = get_command_definitions();
- size_t cmds_size;
-
command_n_commands = 0;
while (current_cmds[command_n_commands].name)
command_n_commands++;
/* +1 for the terminator element */
command_n_commands = 0;
while (current_cmds[command_n_commands].name)
command_n_commands++;
/* +1 for the terminator element */
- cmds_size = (command_n_commands + 1) * sizeof(command_definition_t);
+ size_t cmds_size = (command_n_commands + 1)
+ * sizeof(command_definition_t);
cmds = g_malloc0(cmds_size);
memcpy(cmds, current_cmds, cmds_size);
}
cmds = g_malloc0(cmds_size);
memcpy(cmds, current_cmds, cmds_size);
}