]> git.itanic.dy.fi Git - log-plotter/commitdiff
Use the same config structure for command line and config file
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sat, 9 Nov 2013 11:50:24 +0000 (13:50 +0200)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sat, 9 Nov 2013 11:51:47 +0000 (13:51 +0200)
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 <timo.t.kokkonen@iki.fi>
config.h
main.c
options.c
options.h [deleted file]

index 9f817fc7166d88aac450c34920e50bf69b6b370c..37437ea1a52cdf4f262577387c60fe3216e5a11e 100644 (file)
--- 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 9356d91b2ee7d7aa8097f6747d705c0a549dbe94..a730cab1bee10559b9c63626b54ab20396ca85b8 100644 (file)
--- a/main.c
+++ b/main.c
@@ -2,7 +2,6 @@
 #include <unistd.h>
 #include <string.h>
 
-#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;
        }
index 18db9c5e44e173ba1b24f70f4a44a44079187d6b..582b4e73627c86f5547b56e7896b6bba97a00f71 100644 (file)
--- a/options.c
+++ b/options.c
@@ -3,7 +3,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#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 (file)
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