aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <swo-dev@marcschink.de>2015-05-03 21:02:57 +0200
committerMarc Schink <swo-dev@marcschink.de>2015-05-25 17:30:45 +0200
commit8500284ad7281582c0d38b1e610c585940abc4d9 (patch)
treedd214a31bdbcc12b8d1aa1b1e597dae23e3f6f3a
parentb07364db0eb9c830cab29f3f2f34aa08514139c5 (diff)
Add option to show version information.
This patch adds the command-line option --version to show the program and libswo version.
-rw-r--r--man/swodec.14
-rw-r--r--src/main.c17
2 files changed, 21 insertions, 0 deletions
diff --git a/man/swodec.1 b/man/swodec.1
index 5fdf03c..572d36f 100644
--- a/man/swodec.1
+++ b/man/swodec.1
@@ -15,6 +15,10 @@ is a command-line utility to decode SWO trace data.
Show a help text and exit.
.TP
+.B \-V, \-\-version
+Show version information and exit.
+
+.TP
.BR "\-i, \-\-input\-file " <filename>
Load trace data from a file instead of using standard input.
diff --git a/src/main.c b/src/main.c
index 1279f63..f5d9023 100644
--- a/src/main.c
+++ b/src/main.c
@@ -25,8 +25,11 @@
#include <libswo/libswo.h>
+#include "config.h"
+
#define BUFFER_SIZE 1024
+static gboolean opt_version;
static gchar *input_file = NULL;
static uint16_t packet_type_filter;
static uint32_t inst_address_filter;
@@ -185,6 +188,8 @@ static gboolean parse_inst_filter_option(const gchar *option_name,
}
static GOptionEntry entries[] = {
+ {"version", 'V', 0, G_OPTION_ARG_NONE, &opt_version,
+ "Show version information", NULL},
{"input-file", 'i', 0, G_OPTION_ARG_FILENAME, &input_file,
"Load trace data from file", NULL},
{"filter", 'f', 0, G_OPTION_ARG_CALLBACK, &parse_filter_option,
@@ -365,6 +370,12 @@ static int packet_cb(struct libswo_context *ctx,
return 0;
}
+static void show_version(void)
+{
+ printf("%s\n", PACKAGE_STRING);
+ printf("Using libswo %s\n", libswo_version_package_get_string());
+}
+
static int parse_options(int *argc, char ***argv)
{
GError *error;
@@ -397,6 +408,7 @@ int main(int argc, char **argv)
GIOStatus iostat;
gsize num;
+ opt_version = FALSE;
opt_dump_inst = FALSE;
opt_decode_dwt = FALSE;
@@ -417,6 +429,11 @@ int main(int argc, char **argv)
if (!parse_options(&argc, &argv))
return EXIT_FAILURE;
+ if (opt_version) {
+ show_version();
+ return EXIT_SUCCESS;
+ }
+
if (opt_dump_inst)
packet_type_filter = (1 << LIBSWO_PACKET_TYPE_INST);