From: Timo Kokkonen Date: Sat, 9 Nov 2013 11:50:24 +0000 (+0200) Subject: Use the same config structure for command line and config file X-Git-Url: http://git.itanic.dy.fi/?p=log-plotter;a=commitdiff_plain;h=1c1f69155571479f903195eea242f0de4d96cb05 Use the same config structure for command line and config file We have now two redundant structures that hold the configuration data for log-plotter. Remove the redundant one and use only one structure for holding all configuration data. Signed-off-by: Timo Kokkonen --- diff --git a/config.h b/config.h index 9f817fc..37437ea 100644 --- a/config.h +++ b/config.h @@ -10,8 +10,10 @@ struct plotter_config { char *device_path; int baudrate; char *log_path; + char *config_file_path; }; +int read_args(int argc, char *argv[], struct plotter_config *cfg); int populate_config_data_from_file(const char *path, struct plotter_config *cfg); diff --git a/main.c b/main.c index 9356d91..a730cab 100644 --- a/main.c +++ b/main.c @@ -2,7 +2,6 @@ #include #include -#include "options.h" #include "config.h" #include "baud.h" #include "trace.h" @@ -14,26 +13,25 @@ struct log_plotter_status plotter_state; int main(int argc, char *argv[]) { - struct plotter_options options; struct plotter_config cfg; int fd, baud, ret = 0; bzero(&cfg, sizeof(cfg)); - if (read_args(argc, argv, &options)) + if (read_args(argc, argv, &cfg)) return 1; - if (options.config_file_path) - populate_config_data_from_file(options.config_file_path, &cfg); + if (cfg.config_file_path) + populate_config_data_from_file(cfg.config_file_path, &cfg); - baud = options.baud_rate; - fd = open_at_baud(options.device_path, &baud); + baud = cfg.baudrate; + fd = open_at_baud(cfg.device_path, &baud); if (fd < 0) return 1; - if (baud != options.baud_rate) { + if (baud != cfg.baudrate) { pr_err("Failed to set baudrate to %d, only got %d\n", - options.baud_rate, baud); + cfg.baudrate, baud); ret = 1; goto out; } diff --git a/options.c b/options.c index 18db9c5..582b4e7 100644 --- a/options.c +++ b/options.c @@ -3,7 +3,7 @@ #include #include -#include "options.h" +#include "config.h" #include "trace.h" void print_help_and_die(const char *exec_name) @@ -21,15 +21,15 @@ void print_help_and_die(const char *exec_name) exit(0); } -static void set_default_options(struct plotter_options *opts) +static void set_default_options(struct plotter_config *opts) { bzero(opts, sizeof(*opts)); - opts->baud_rate = 128000; + opts->baudrate = 128000; opts->device_path = "/dev/ttyUSB0"; } -int read_args(int argc, char *argv[], struct plotter_options *opts) +int read_args(int argc, char *argv[], struct plotter_config *opts) { int option_index = 0, c; static struct option long_options[] = { @@ -57,10 +57,10 @@ int read_args(int argc, char *argv[], struct plotter_options *opts) opts->device_path = optarg; break; case 'o': - opts->output_path = optarg; + opts->log_path = optarg; break; case 'b': - opts->baud_rate = atoi(optarg); + opts->baudrate = atoi(optarg); break; case 'v': trace_level++; diff --git a/options.h b/options.h deleted file mode 100644 index 8ec9abc..0000000 --- a/options.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _OPTIONS_H -#define _OPTIONS_H - -struct plotter_options { - char *device_path; - char *output_path; - int baud_rate; - char *config_file_path; -}; - -int read_args(int argc, char *argv[], struct plotter_options *opts); - -#endif