From 99211441f7905cb24ceab3fc8991adcc6c4ee834 Mon Sep 17 00:00:00 2001 From: Andreas Gattringer <gattringera@a772-cvl-ws23.biodiv.univie.ac.at> Date: Mon, 9 Jan 2023 15:37:10 +0100 Subject: [PATCH] fixed command line parsing --- src/cats/command_line/command_line_options.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cats/command_line/command_line_options.c b/src/cats/command_line/command_line_options.c index d49f242..88c30cb 100644 --- a/src/cats/command_line/command_line_options.c +++ b/src/cats/command_line/command_line_options.c @@ -24,6 +24,7 @@ #include "cats_global.h" #include <string.h> +#include <assert.h> #include "command_line_options.h" #include "command_line_info.h" @@ -91,17 +92,17 @@ struct program_options check_cats_main_arguments(int argc, char **argv) int opt; int error = 0; - + int option_index = 0; // FIXME unify error messages, start with Error: while ((opt = getopt_long(argc, argv, "qs:r:l:v:ho:", - longopts, &optind)) != -1) { + longopts, &option_index)) != -1) { bool success; bool conversion_success; float value; bool bool_value; switch (opt) { - case 'o': + case 'o': options.output_directory = strdup(optarg); break; case 'r': @@ -288,9 +289,9 @@ struct program_options check_cats_main_arguments(int argc, char **argv) exit_cats(EXIT_FAILURE); } - for (int index = optind; index < argc; index++) { - options.configuration_file = argv[index]; - break; + assert(optind < argc); + if (options.configuration_file == NULL && options.need_conf == true) { + options.configuration_file = strdup(argv[optind]); } if (options.configuration_file == NULL && options.need_conf == true) { -- GitLab