commit 1ae5a90793ca55b1047fd99ef95e341ef1aefc03
parent a9e092bc39cecbe144a6d718120b43e7028ac454
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 1 Sep 2017 16:33:27 +0200
Add the --version command line option
Diffstat:
4 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -95,14 +95,17 @@ configure_file(${SOLSTICE_SOURCE_DIR}/solstice_args.h.in
configure_file(${SOLSTICE_SOURCE_DIR}/../doc/solstice.1.txt.in
${CMAKE_CURRENT_BINARY_DIR}/doc/solstice.1.txt @ONLY)
-################################################################################
-# Configure and define targets
-################################################################################
set(VERSION_MAJOR 0)
set(VERSION_MINOR 2)
set(VERSION_PATCH 3)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
+configure_file(${SOLSTICE_SOURCE_DIR}/solstice_version.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/solstice_version.h @ONLY)
+
+################################################################################
+# Configure and define targets
+################################################################################
set(SOLSTICE_FILES_SRC
solstice.c
solstice_args.c
@@ -121,7 +124,8 @@ set(SOLSTICE_FILES_INC
solstice.h
solstice_args.h.in
solstice_c.h
- solstice_sun_spectrum.h)
+ solstice_sun_spectrum.h
+ solstice_version.h.in)
set(SOLSTICE_FILES_DOC COPYING README.md)
# Prepend each file in the `SOLSTICE_FILES_<SRC|INC>' list by `SOLSTICE_SOURCE_DIR'
diff --git a/doc/solstice.1.txt.in b/doc/solstice.1.txt.in
@@ -177,6 +177,9 @@ OPTIONS
*-v*::
Make solstice more verbose.
+*--version*::
+ Output version information and exit.
+
EXAMPLES
--------
diff --git a/src/solstice_args.c b/src/solstice_args.c
@@ -16,6 +16,7 @@
#define _POSIX_C_SOURCE 2
#include "solstice_args.h"
+#include "solstice_version.h"
#include <rsys/cstr.h>
#include <rsys/double3.h>
@@ -69,6 +70,8 @@ print_help(const char* program)
" many threads as CPU cores.\n");
printf(
" -v make the program more verbose.\n");
+ printf(
+" --version display version information and exit.\n");
printf("\n");
printf(
"Solstice (C) 2016-2017 CNRS. This is a free software released under the GNU GPL\n"
@@ -486,11 +489,23 @@ res_T
solstice_args_init(struct solstice_args* args, const int argc, char** argv)
{
int opt;
+ int i;
res_T res = RES_OK;
ASSERT(args && argc && argv);
*args = SOLSTICE_ARGS_DEFAULT;
+ FOR_EACH(i, 1, argc) {
+ if(!strcmp(argv[i], "--version")) {
+ printf("Solstice %d.%d.%d\n",
+ SOLSTICE_VERSION_MAJOR,
+ SOLSTICE_VERSION_MINOR,
+ SOLSTICE_VERSION_PATCH);
+ args->quit = 1;
+ goto exit;
+ }
+ }
+
optind = 0;
while((opt = getopt(argc, argv, "D:fg:hn:o:p:qR:r:t:v")) != -1) {
switch(opt) {
diff --git a/src/solstice_version.h.in b/src/solstice_version.h.in
@@ -0,0 +1,24 @@
+/* Copyright (C) CNRS 2016-2017
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef SOLSTICE_VERSION_H
+#define SOLSTICE_VERSION_H
+
+#define SOLSTICE_VERSION_MAJOR @VERSION_MAJOR@
+#define SOLSTICE_VERSION_MINOR @VERSION_MINOR@
+#define SOLSTICE_VERSION_PATCH @VERSION_PATCH@
+
+#endif /* SOLSTICE_VERSION_H */
+