From 90fe1b64c2203f9e82646cb41c8a85f0a31125bb Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 1 Aug 2021 18:12:36 -0400 Subject: Factor out command line version printing --- src/console.c | 19 +++++++++++++++++++ src/console.h | 3 +++ src/serdi.c | 21 ++------------------- 3 files changed, 24 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/console.c b/src/console.c index a15c8e7d..4a127c3e 100644 --- a/src/console.c +++ b/src/console.c @@ -3,6 +3,8 @@ #include "console.h" +#include "serd/serd.h" + #ifdef _WIN32 # ifdef _MSC_VER # define WIN32_LEAN_AND_MEAN 1 @@ -20,3 +22,20 @@ serd_set_stream_utf8_mode(FILE* const stream) (void)stream; #endif } + +int +serd_print_version(const char* const program) +{ + printf("%s %d.%d.%d \n", + program, + SERD_MAJOR_VERSION, + SERD_MINOR_VERSION, + SERD_MICRO_VERSION); + + printf("Copyright 2011-2023 David Robillard .\n" + "License: \n" + "This is free software; you are free to change and redistribute it.\n" + "There is NO WARRANTY, to the extent permitted by law.\n"); + + return 0; +} diff --git a/src/console.h b/src/console.h index ff21e442..65b041ba 100644 --- a/src/console.h +++ b/src/console.h @@ -5,3 +5,6 @@ void serd_set_stream_utf8_mode(FILE* stream); + +int +serd_print_version(const char* program); diff --git a/src/serdi.c b/src/serdi.c index bc68e591..fd7fdb15 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -13,7 +13,6 @@ #include "serd/stream.h" #include "serd/string_view.h" #include "serd/syntax.h" -#include "serd/version.h" #include "serd/world.h" #include "serd/writer.h" @@ -28,22 +27,6 @@ #define MAX_DEPTH 128U -static int -print_version(void) -{ - printf("serdi %d.%d.%d \n", - SERD_MAJOR_VERSION, - SERD_MINOR_VERSION, - SERD_MICRO_VERSION); - - printf("Copyright 2011-2023 David Robillard .\n" - "License ISC: .\n" - "This is free software; you are free to change and redistribute it." - "\nThere is NO WARRANTY, to the extent permitted by law.\n"); - - return 0; -} - static int print_usage(const char* const name, const bool error) { @@ -120,7 +103,7 @@ main(int argc, char** argv) } if (!strcmp(argv[a], "--version")) { - return print_version(); + return serd_print_version(argv[0]); } for (int o = 1; argv[a][o]; ++o) { @@ -144,7 +127,7 @@ main(int argc, char** argv) } else if (opt == 't') { writer_flags |= SERD_WRITE_TERSE; } else if (opt == 'v') { - return print_version(); + return serd_print_version(argv[0]); } else if (opt == 's') { from_string = true; break; -- cgit v1.2.1