]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
Add command line arguments -h -v -vv -vvv and -V. Bump version number.
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Sun, 25 Apr 2021 17:37:35 +0000 (18:37 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Sun, 25 Apr 2021 17:37:35 +0000 (18:37 +0100)
configure.ac
nqptp.c
nqptp.h

index fd0e00467e1ddb58c47d6e6f21816583afba2258..4cabb953c7f156e243835f069b447cd6d4e2f915 100644 (file)
@@ -2,7 +2,7 @@
 # Process this file with autoconf to produce a configure script.
 
 AC_PREREQ([2.68])
-AC_INIT([nqptp], [1.0d0], [4265913+mikebrady@users.noreply.github.com])
+AC_INIT([nqptp], [1.0d1], [4265913+mikebrady@users.noreply.github.com])
 AM_INIT_AUTOMAKE
 AC_CONFIG_SRCDIR([nqptp.c])
 AC_CONFIG_HEADERS([config.h])
@@ -27,4 +27,4 @@ AC_FUNC_MALLOC
 AC_CHECK_FUNCS([clock_gettime inet_ntoa memset select socket strerror])
 
 AC_CONFIG_FILES([Makefile nqptp.service])
-AC_OUTPUT
\ No newline at end of file
+AC_OUTPUT
diff --git a/nqptp.c b/nqptp.c
index 6798339316cb6c468f20bfdf39a79633cfc3cccf..f3504eb9f6cb9ea98168daf48d2e06c2c235788f 100644 (file)
--- a/nqptp.c
+++ b/nqptp.c
@@ -16,7 +16,7 @@
  *
  * Commercial licensing is also available.
  */
-
+#include "config.h"
 #include "nqptp.h"
 #include "debug.h"
 #include "general-utilities.h"
@@ -115,8 +115,37 @@ void termHandler(__attribute__((unused)) int k) {
   exit(EXIT_SUCCESS);
 }
 
-int main(void) {
-  debug_init(DEBUG_LEVEL, 0, 1, 1);
+int main(int argc, char **argv) {
+
+  int debug_level = 0;
+  int i;
+  for( i = 1; i < argc; ++i ) {
+    if( argv[i][0] == '-' ) {
+      if(strcmp(argv[i] + 1,  "V") == 0) {
+        fprintf(stdout, "%s\n",PACKAGE_STRING);
+        exit(EXIT_SUCCESS);
+      } else if(strcmp(argv[i] + 1,  "vvv") == 0 ) {
+        debug_level = 3;
+      } else if( strcmp(argv[i] + 1,  "vv" ) == 0 ) {
+        debug_level = 2;
+      } else if( strcmp(argv[i] + 1,  "v" ) == 0 ) {
+        debug_level = 1;
+      } else if( strcmp(argv[i] + 1,  "h" ) == 0 ) {
+        fprintf(stdout,
+          "    -V     print version,\n"
+          "    -v     verbose log,\n"
+          "    -vv    more verbose log,\n"
+          "    -vvv   very verbose log,\n"
+          "    -h     this help text.\n");
+        exit(EXIT_SUCCESS);
+      } else {
+        fprintf(stdout, "%s -- unknown option. Program terminated.\n", argv[0]);
+        exit(EXIT_FAILURE);
+      }
+    }
+  }
+
+  debug_init(debug_level, 0, 1, 1);
   debug(1, "startup");
   atexit(goodbye);
 
diff --git a/nqptp.h b/nqptp.h
index 8dbedd8f900bab6fe91e9035a51e431f9fb8bf8c..0e0d1d5dfc6e3f436b94ad926d5ed35d09d6a451 100644 (file)
--- a/nqptp.h
+++ b/nqptp.h
@@ -20,9 +20,6 @@
 #ifndef NQPTP_H
 #define NQPTP_H
 
-// 0 means no debug messages. 3 means lots!
-#define DEBUG_LEVEL 1
-
 #include "nqptp-shm-structures.h"
 
 #define MAX_OPEN_SOCKETS 16