]> git.itanic.dy.fi Git - log-plotter/blobdiff - options.c
data.c: Reset time stamp when starting new log
[log-plotter] / options.c
index 28021f7b4a9a6a9c15a37b6f32f0264dce20e219..582b4e73627c86f5547b56e7896b6bba97a00f71 100644 (file)
--- a/options.c
+++ b/options.c
@@ -3,18 +3,33 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "options.h"
-#include "debug.h"
+#include "config.h"
+#include "trace.h"
 
-static void set_default_options(struct plotter_options *opts)
+void print_help_and_die(const char *exec_name)
+{
+       pr_info("Usage: %s [option]\n", exec_name);
+       pr_info("  -d, --device=DEVICE     path to the serial device\n");
+       pr_info("                          default: /dev/ttyUSB0\n");
+       pr_info("  -b, --baud=BAUD         device baud rate, default 128000\n");
+       pr_info("  -o, --output            logfile path, stdout only if omited\n");
+       pr_info("  -v, --verbose           increase verbosity\n");
+       pr_info("  -q, --quiet             decrease verbosity\n");
+       pr_info("  -c, --config=PATH       config file path\n");
+       pr_info("  -h, --help              show this help\n");
+
+       exit(0);
+}
+
+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[] = {
@@ -23,8 +38,10 @@ int read_args(int argc, char *argv[], struct plotter_options *opts)
                { .val = 'b', .name = "baud", .has_arg = 1 },
                { .val = 'v', .name = "verbose", .has_arg = 2 },
                { .val = 'q', .name = "quiet", },
+               { .val = 'c', .name = "config", .has_arg = 1 },
+               { .val = 'h', .name = "help", },
        };
-       char short_options[] = "d:o:b:vq";
+       char short_options[] = "d:o:b:vqc:h";
 
        set_default_options(opts);
 
@@ -40,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++;
@@ -53,6 +70,12 @@ int read_args(int argc, char *argv[], struct plotter_options *opts)
                        trace_level--;
                        pr_debug("Degreased trace level to %d\n", trace_level);
                        break;
+               case 'c':
+                       opts->config_file_path = optarg;
+                       break;
+               case 'h':
+                       print_help_and_die(argv[0]);
+                       break;
                case '?':
                        return -1;
                }