From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Sun, 25 Apr 2021 17:37:35 +0000 (+0100) Subject: Add command line arguments -h -v -vv -vvv and -V. Bump version number. X-Git-Tag: 1.1-dev~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22579e9f33ca6c40ac039dea6fd7e4cb71651075;p=thirdparty%2Fnqptp.git Add command line arguments -h -v -vv -vvv and -V. Bump version number. --- diff --git a/configure.ac b/configure.ac index fd0e004..4cabb95 100644 --- a/configure.ac +++ b/configure.ac @@ -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 6798339..f3504eb 100644 --- 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 8dbedd8..0e0d1d5 100644 --- 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