diff options
author | Christian Pointner <equinox@helsinki.at> | 2009-11-04 04:13:13 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2009-11-04 04:13:13 (GMT) |
commit | 300483ff8651af328adeb83834dac0dc3442407d (patch) | |
tree | e0f90c21fd3342f7337e564cf3398d17242ad0b8 | |
parent | 1f1a372856ff1efe9d1ea5333bb1e7f2f1d56281 (diff) |
added parser for switchctl config file
-rw-r--r-- | options.c | 30 | ||||
-rw-r--r-- | options.h | 2 |
2 files changed, 32 insertions, 0 deletions
@@ -27,6 +27,7 @@ #include <stdio.h> #include <string.h> #include <ctype.h> +#include <errno.h> #include "log.h" @@ -187,6 +188,32 @@ int options_parse_post(options_t* opt) return -1; // nothing to do + FILE* conf_file = fopen(opt->conf_file_, "r"); + if(conf_file) { + char buf[100]; + while(fgets(buf, 100, conf_file) != NULL) { + char* tmp, *key, *value; + for(tmp = buf;*tmp == ' '; ++tmp); + if(*(key = tmp) == 0) continue; + for(;*tmp != ' ' && *tmp != 0;++tmp); + if(*tmp == 0) continue; + *tmp=0; + ++tmp; + for(;*tmp == ' ';++tmp); + if(*(value = tmp) == 0) continue; + for(;*tmp != ' ' && *tmp != 0 && *tmp != '\n';++tmp); + *tmp = 0; + + if(key_value_storage_add(&opt->alias_table_, key, value)) + return -2; + } + fclose(conf_file); + } + else { + log_printf(ERROR,"unable to open conf file (%s): %s", opt->conf_file_, strerror(errno)); + return -1; + } + return 0; } @@ -206,6 +233,7 @@ void options_default(options_t* opt) opt->conf_file_ = strdup("/etc/rhctl/switchctl.conf"); opt->command_sock_ = strdup("/var/run/rhctl/switchctl.sock"); opt->switch_dev_ = strdup("/dev/audioswitch"); + key_value_storage_init(&opt->alias_table_); } void options_clear(options_t* opt) @@ -231,6 +259,7 @@ void options_clear(options_t* opt) free(opt->command_sock_); if(opt->switch_dev_) free(opt->switch_dev_); + key_value_storage_clear(&opt->alias_table_); } void options_print_usage() @@ -266,4 +295,5 @@ void options_print(options_t* opt) printf("conf_file: '%s'\n", opt->conf_file_); printf("command_sock: '%s'\n", opt->command_sock_); printf("switch_dev: '%s'\n", opt->switch_dev_); + key_value_storage_print(&opt->alias_table_); } @@ -23,6 +23,7 @@ #define _OPTIONS_H_ #include "string_list.h" +#include "key_value_storage.h" struct options_struct { char* progname_; @@ -36,6 +37,7 @@ struct options_struct { char* conf_file_; char* command_sock_; char* switch_dev_; + key_value_storage_t alias_table_; }; typedef struct options_struct options_t; |