From 918dea1056d3d1acc62282db59ac855e92c4a476 Mon Sep 17 00:00:00 2001
From: silverweed <silverweed14@proton.me>
Date: Mon, 4 Nov 2024 13:48:47 +0100
Subject: [PATCH] add print version flag

---
 src/argparse.cpp  | 32 ++++++++++++++++++++++++++++++++
 src/rntviewer.cpp |  6 +++++-
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/src/argparse.cpp b/src/argparse.cpp
index e2b966d..beb12ab 100644
--- a/src/argparse.cpp
+++ b/src/argparse.cpp
@@ -11,6 +11,7 @@ void print_help(const char *argv0)
     "\n\t-w: display WIDTH bytes per column"
     "\n\t-e: display some extended info(*) (may slow down the startup)"
     "\n\t-n: list the names of the RNTuples found in the file and exit"
+    "\n\t-v: print version and copyright info"
     "\n"
     "\nNOTES:"
     "\n- if `ntuple_name' is not passed, rntviewer will look for the first RNTuple in the TFile."
@@ -20,9 +21,38 @@ void print_help(const char *argv0)
   , argv0);
 }
 
+internal
+void print_version_and_copyright()
+{
+  printf(
+    "\n-----------------------------------------------------------------------------"
+    "\n rntviewer v" V_MAJOR "." V_MINOR
+    "\n"
+    "\n A graphical interactive RNTuple visualizer"
+    "\n-----------------------------------------------------------------------------"
+    "\n"
+    "\nCopyright (C) 2024 silverweed"
+    "\n"
+    "\nThis program is free software: you can redistribute it and/or modify it"
+    "\nunder the terms of the GNU General Public License as published by the "
+    "\nFree Software Foundation, either version 3 of the License, or (at your option)"
+    "\nany later version."
+    "\n"
+    "\nThis program is distributed in the hope that it will be useful, but"
+    "\nWITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY"
+    "\nor FITNESS FOR A PARTICULAR PURPOSE."
+    "\nSee the GNU General Public License for more details."
+    "\n"
+    "\nYou should have received a copy of the GNU General Public License along"
+    "\nwith this program. If not, see <https://www.gnu.org/licenses/>."
+    "\n\n"
+  );
+}
+
 struct Cmdline_Args {
   b8 print_to_terminal;
   b8 show_help_and_exit;
+  b8 show_version_and_exit;
   u64 start_addr;
   u64 nbytes_displayed;
   u16 n_cols;
@@ -116,6 +146,8 @@ Cmdline_Args parse_args(i32 argc, char **argv)
           parse_int_arg(i, argc, argv, args.nbytes_displayed);
         else if (arg[1] == 'n')
           args.only_print_rntuple_names = true;
+        else if (arg[1] == 'v')
+          args.show_version_and_exit = true;
         else if (arg[1] == 'w') {
           u64 n_cols = 0;
           parse_int_arg(i, argc, argv, n_cols);
diff --git a/src/rntviewer.cpp b/src/rntviewer.cpp
index 30c429e..6894d36 100644
--- a/src/rntviewer.cpp
+++ b/src/rntviewer.cpp
@@ -2,7 +2,7 @@
 // 
 //  rntviewer
 // 
-//  A graphical RNTuple visualizer 
+//  A graphical interactive RNTuple visualizer 
 // 
 //  @author silverweed, 2024
 // 
@@ -124,6 +124,10 @@ int main(int argc, char **argv)
 
   // Parse cmdline
   Cmdline_Args args = parse_args(argc, argv);
+  if (args.show_version_and_exit) {
+    print_version_and_copyright();
+    return 0;
+  }
   if (args.show_help_and_exit || !args.file_name.size) {
     print_help(argv[0]);
     return 1;