From 4856b0b4af47f316c497ecaaf740186f23dd11fd Mon Sep 17 00:00:00 2001 From: Kalle Wallin Date: Wed, 14 Apr 2004 18:55:48 +0000 Subject: [PATCH] relocated configuration file to ~/.ncmpc/config and added support for key bindings in ~/.ncmpc/keys. git-svn-id: https://svn.musicpd.org/ncmpc/trunk@751 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- conf.c | 214 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- conf.h | 2 +- 2 files changed, 208 insertions(+), 8 deletions(-) diff --git a/conf.c b/conf.c index 6def7b6..80f40db 100644 --- a/conf.c +++ b/conf.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -13,6 +14,7 @@ #include "config.h" #include "options.h" #include "support.h" +#include "command.h" #include "conf.h" #ifdef DEBUG @@ -38,7 +40,15 @@ #define CONF_COLOR_PROGRESS "progress_color" #define CONF_COLOR_STATUS "status_color" #define CONF_COLOR_ALERT "alert_color" +#define CONF_KEY_DEFINITION "key" +typedef enum { + KEY_PARSER_UNKNOWN, + KEY_PARSER_CHAR, + KEY_PARSER_DEC, + KEY_PARSER_HEX, + KEY_PARSER_DONE +} key_parser_state_t; static int str2bool(char *str) @@ -72,7 +82,134 @@ str2color(char *str) return -1; } -int +static int +parse_key_value(char *str, size_t len, char **end) +{ + int i, value; + key_parser_state_t state; + + i=0; + value=0; + state=KEY_PARSER_UNKNOWN; + *end = str; + + while( i str+len ) + *end = str+len; + + return value; +} + +static int +parse_key_definition(char *str) +{ + char buf[MAX_LINE_LENGTH]; + char *p, *end; + size_t len = strlen(str); + int i,j,key; + int keys[MAX_COMMAND_KEYS]; + command_t cmd; + + /* get the command name */ + i=0; + j=0; + memset(buf, 0, MAX_LINE_LENGTH); + while( i=0 ) + { + keys[i++] = key; + while( penable_colors = str2bool(value); match_found = 1; @@ -247,7 +386,68 @@ read_rc_file(char *filename, options_t *options) } +int +read_configuration(options_t *options) +{ + char *filename = NULL; + + /* check for user configuration ~/.ncmpc/config */ + filename = g_build_filename(g_get_home_dir(), "." PACKAGE, "config", NULL); + if( !g_file_test(filename, G_FILE_TEST_IS_REGULAR) ) + { + g_free(filename); + filename = NULL; + } + /* check for global configuration SYSCONFDIR/ncmpc/config */ + if( filename == NULL ) + { + filename = g_build_filename(SYSCONFDIR, PACKAGE, "config", NULL); + if( !g_file_test(filename, G_FILE_TEST_IS_REGULAR) ) + { + g_free(filename); + filename = NULL; + } + } + + /* load configuration */ + if( filename ) + { + read_rc_file(filename, options); + g_free(filename); + filename = NULL; + } + + /* check for user key bindings ~/.ncmpc/keys */ + filename = g_build_filename(g_get_home_dir(), "." PACKAGE, "keys", NULL); + if( !g_file_test(filename, G_FILE_TEST_IS_REGULAR) ) + { + g_free(filename); + filename = NULL; + } + + /* check for global key bindings SYSCONFDIR/ncmpc/keys */ + if( filename == NULL ) + { + filename = g_build_filename(SYSCONFDIR, PACKAGE, "keys", NULL); + if( !g_file_test(filename, G_FILE_TEST_IS_REGULAR) ) + { + g_free(filename); + filename = NULL; + } + } + + /* load key bindings */ + if( filename ) + { + read_rc_file(filename, options); + g_free(filename); + filename = NULL; + //write_key_bindings(stderr); + } + + return 0; +} diff --git a/conf.h b/conf.h index ee7656e..5f91410 100644 --- a/conf.h +++ b/conf.h @@ -1,3 +1,3 @@ -int read_rc_file(char *filename, options_t *options); +int read_configuration(options_t *options); -- 2.30.2