]> git.itanic.dy.fi Git - log-plotter/blobdiff - options.c
Add missing initialization
[log-plotter] / options.c
index 38b29a3abd48f645c378713e5c0e850c75897da4..706d8556981ad73bd018cd1aea4d68ebdc622018 100644 (file)
--- a/options.c
+++ b/options.c
@@ -4,6 +4,21 @@
 #include <string.h>
 
 #include "options.h"
+#include "debug.h"
+
+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("  -h, --help              show this help\n");
+
+       exit(0);
+}
 
 static void set_default_options(struct plotter_options *opts)
 {
@@ -19,9 +34,12 @@ int read_args(int argc, char *argv[], struct plotter_options *opts)
        static struct option long_options[] = {
                { .val = 'd', .name = "device", .has_arg = 1, },
                { .val = 'o', .name = "output", .has_arg = 1 },
-               { .val = 'o', .name = "baud", .has_arg = 1 },
+               { .val = 'b', .name = "baud", .has_arg = 1 },
+               { .val = 'v', .name = "verbose", .has_arg = 2 },
+               { .val = 'q', .name = "quiet", },
+               { .val = 'h', .name = "help", },
        };
-       char short_options[] = "d:o:b:";
+       char short_options[] = "d:o:b:vqh";
 
        set_default_options(opts);
 
@@ -42,6 +60,17 @@ int read_args(int argc, char *argv[], struct plotter_options *opts)
                case 'b':
                        opts->baud_rate = atoi(optarg);
                        break;
+               case 'v':
+                       trace_level++;
+                       pr_debug("Increased trace level to %d\n", trace_level);
+                       break;
+               case 'q':
+                       trace_level--;
+                       pr_debug("Degreased trace level to %d\n", trace_level);
+                       break;
+               case 'h':
+                       print_help_and_die(argv[0]);
+                       break;
                case '?':
                        return -1;
                }