diff --git a/mytools/Makefile b/mytools/Makefile index 092bc67..4e57705 100644 --- a/mytools/Makefile +++ b/mytools/Makefile @@ -1,11 +1,11 @@ -PROGS= showZobov +PROGS= showZobov buildObservedVoids CXX=g++ CC=gcc include config.mk -SOURCES= showZobov.cpp loadZobov.cpp zobovConf.c +SOURCES= showZobov.cpp loadZobov.cpp zobovConf.c buildObservedVoids.cpp LIBS= $(LDFLAGS) @@ -15,6 +15,8 @@ showZobov: showZobov.o loadZobov.o zobovConf.o testZobov: testZobov.o loadZobov.o +buildObservedVoids: buildObservedVoids.o loadZobov.o buildObservedVoids_conf.o + depend: $(SOURCES) @echo "[DEPENDS] $^" @$(CC) $(CPPFLAGS) -M -MM $^ > .mydepends @@ -36,7 +38,11 @@ clean: zobovConf.c zobovConf.h: showZobov.ggo Makefile @echo "[OPT] $@" - gengetopt -i $< -f zobovConf -a zobovConf_info -F zobovConf -C + @gengetopt -i $< -f zobovConf -a zobovConf_info -F zobovConf -C + +buildObservedVoids_conf.c buildObservedVoids_conf.h: buildObservedVoids.ggo Makefile + @echo "[OPT] $@" + @gengetopt -i $< -f buildObservedVoids_conf -a buildObservedVoids_info -F buildObservedVoids_conf -C %.o: %.c @echo "[C] $< ..." diff --git a/mytools/buildObservedVoids_conf.c b/mytools/buildObservedVoids_conf.c new file mode 100644 index 0000000..f763f3e --- /dev/null +++ b/mytools/buildObservedVoids_conf.c @@ -0,0 +1,1020 @@ +/* + File autogenerated by gengetopt version 2.22.2 + generated with the following command: + gengetopt -i buildObservedVoids.ggo -f buildObservedVoids_conf -a buildObservedVoids_info -F buildObservedVoids_conf -C + + The developers of gengetopt consider the fixed text that goes in all + gengetopt output files to be in the public domain: + we make no copyright claims on it. +*/ + +/* If we use autoconf. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#ifndef FIX_UNUSED +#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ +#endif + +#include "getopt.h" + +#include "buildObservedVoids_conf.h" + +const char *buildObservedVoids_info_purpose = ""; + +const char *buildObservedVoids_info_usage = "Usage: buildObservedVoids [OPTIONS]..."; + +const char *buildObservedVoids_info_description = ""; + +const char *buildObservedVoids_info_help[] = { + " -h, --help Print help and exit", + " -V, --version Print version and exit", + " -d, --desc=STRING The description file name for the voids (jozov \n generated)", + " -a, --adj=STRING Adjacent file name (jozov generated)", + " -v, --void=STRING Void/zone bind filename (jozov generated)", + " -m, --minProba=DOUBLE Minimal probability to accept (default=`0.0')", + " --densityThreshold=DOUBLE Density threshold to consider a stable void \n (default=`-0.8')", + " -b, --ramsesDir=STRING Ramses base output directory", + " -r, --ramsesId=INT Ramses output id", + " -f, --configFile=STRING Configuration file", + " -o, --output=STRING Output file (default=`void_info.txt')", + " -g, --gridOutput=STRING 3d grid output of voids \n (default=`all_voids.nc')", + " -q, --quiet Quiet output (default=off)", + 0 +}; + +typedef enum {ARG_NO + , ARG_FLAG + , ARG_STRING + , ARG_INT + , ARG_DOUBLE +} buildObservedVoids_conf_arg_type; + +static +void clear_given (struct buildObservedVoids_info *args_info); +static +void clear_args (struct buildObservedVoids_info *args_info); + +static int +buildObservedVoids_conf_internal (int argc, char * const *argv, struct buildObservedVoids_info *args_info, + struct buildObservedVoids_conf_params *params, const char *additional_error); + +static int +buildObservedVoids_conf_required2 (struct buildObservedVoids_info *args_info, const char *prog_name, const char *additional_error); +struct line_list +{ + char * string_arg; + struct line_list * next; +}; + +static struct line_list *cmd_line_list = 0; +static struct line_list *cmd_line_list_tmp = 0; + +static void +free_cmd_list(void) +{ + /* free the list of a previous call */ + if (cmd_line_list) + { + while (cmd_line_list) { + cmd_line_list_tmp = cmd_line_list; + cmd_line_list = cmd_line_list->next; + free (cmd_line_list_tmp->string_arg); + free (cmd_line_list_tmp); + } + } +} + + +static char * +gengetopt_strdup (const char *s); + +static +void clear_given (struct buildObservedVoids_info *args_info) +{ + args_info->help_given = 0 ; + args_info->version_given = 0 ; + args_info->desc_given = 0 ; + args_info->adj_given = 0 ; + args_info->void_given = 0 ; + args_info->minProba_given = 0 ; + args_info->densityThreshold_given = 0 ; + args_info->ramsesDir_given = 0 ; + args_info->ramsesId_given = 0 ; + args_info->configFile_given = 0 ; + args_info->output_given = 0 ; + args_info->gridOutput_given = 0 ; + args_info->quiet_given = 0 ; +} + +static +void clear_args (struct buildObservedVoids_info *args_info) +{ + FIX_UNUSED (args_info); + args_info->desc_arg = NULL; + args_info->desc_orig = NULL; + args_info->adj_arg = NULL; + args_info->adj_orig = NULL; + args_info->void_arg = NULL; + args_info->void_orig = NULL; + args_info->minProba_arg = 0.0; + args_info->minProba_orig = NULL; + args_info->densityThreshold_arg = -0.8; + args_info->densityThreshold_orig = NULL; + args_info->ramsesDir_arg = NULL; + args_info->ramsesDir_orig = NULL; + args_info->ramsesId_orig = NULL; + args_info->configFile_arg = NULL; + args_info->configFile_orig = NULL; + args_info->output_arg = gengetopt_strdup ("void_info.txt"); + args_info->output_orig = NULL; + args_info->gridOutput_arg = gengetopt_strdup ("all_voids.nc"); + args_info->gridOutput_orig = NULL; + args_info->quiet_flag = 0; + +} + +static +void init_args_info(struct buildObservedVoids_info *args_info) +{ + + + args_info->help_help = buildObservedVoids_info_help[0] ; + args_info->version_help = buildObservedVoids_info_help[1] ; + args_info->desc_help = buildObservedVoids_info_help[2] ; + args_info->adj_help = buildObservedVoids_info_help[3] ; + args_info->void_help = buildObservedVoids_info_help[4] ; + args_info->minProba_help = buildObservedVoids_info_help[5] ; + args_info->densityThreshold_help = buildObservedVoids_info_help[6] ; + args_info->ramsesDir_help = buildObservedVoids_info_help[7] ; + args_info->ramsesId_help = buildObservedVoids_info_help[8] ; + args_info->configFile_help = buildObservedVoids_info_help[9] ; + args_info->output_help = buildObservedVoids_info_help[10] ; + args_info->gridOutput_help = buildObservedVoids_info_help[11] ; + args_info->quiet_help = buildObservedVoids_info_help[12] ; + +} + +void +buildObservedVoids_conf_print_version (void) +{ + printf ("%s %s\n", + (strlen(BUILDOBSERVEDVOIDS_CONF_PACKAGE_NAME) ? BUILDOBSERVEDVOIDS_CONF_PACKAGE_NAME : BUILDOBSERVEDVOIDS_CONF_PACKAGE), + BUILDOBSERVEDVOIDS_CONF_VERSION); +} + +static void print_help_common(void) { + buildObservedVoids_conf_print_version (); + + if (strlen(buildObservedVoids_info_purpose) > 0) + printf("\n%s\n", buildObservedVoids_info_purpose); + + if (strlen(buildObservedVoids_info_usage) > 0) + printf("\n%s\n", buildObservedVoids_info_usage); + + printf("\n"); + + if (strlen(buildObservedVoids_info_description) > 0) + printf("%s\n\n", buildObservedVoids_info_description); +} + +void +buildObservedVoids_conf_print_help (void) +{ + int i = 0; + print_help_common(); + while (buildObservedVoids_info_help[i]) + printf("%s\n", buildObservedVoids_info_help[i++]); +} + +void +buildObservedVoids_conf_init (struct buildObservedVoids_info *args_info) +{ + clear_given (args_info); + clear_args (args_info); + init_args_info (args_info); +} + +void +buildObservedVoids_conf_params_init(struct buildObservedVoids_conf_params *params) +{ + if (params) + { + params->override = 0; + params->initialize = 1; + params->check_required = 1; + params->check_ambiguity = 0; + params->print_errors = 1; + } +} + +struct buildObservedVoids_conf_params * +buildObservedVoids_conf_params_create(void) +{ + struct buildObservedVoids_conf_params *params = + (struct buildObservedVoids_conf_params *)malloc(sizeof(struct buildObservedVoids_conf_params)); + buildObservedVoids_conf_params_init(params); + return params; +} + +static void +free_string_field (char **s) +{ + if (*s) + { + free (*s); + *s = 0; + } +} + + +static void +buildObservedVoids_conf_release (struct buildObservedVoids_info *args_info) +{ + + free_string_field (&(args_info->desc_arg)); + free_string_field (&(args_info->desc_orig)); + free_string_field (&(args_info->adj_arg)); + free_string_field (&(args_info->adj_orig)); + free_string_field (&(args_info->void_arg)); + free_string_field (&(args_info->void_orig)); + free_string_field (&(args_info->minProba_orig)); + free_string_field (&(args_info->densityThreshold_orig)); + free_string_field (&(args_info->ramsesDir_arg)); + free_string_field (&(args_info->ramsesDir_orig)); + free_string_field (&(args_info->ramsesId_orig)); + free_string_field (&(args_info->configFile_arg)); + free_string_field (&(args_info->configFile_orig)); + free_string_field (&(args_info->output_arg)); + free_string_field (&(args_info->output_orig)); + free_string_field (&(args_info->gridOutput_arg)); + free_string_field (&(args_info->gridOutput_orig)); + + + + clear_given (args_info); +} + + +static void +write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) +{ + FIX_UNUSED (values); + if (arg) { + fprintf(outfile, "%s=\"%s\"\n", opt, arg); + } else { + fprintf(outfile, "%s\n", opt); + } +} + + +int +buildObservedVoids_conf_dump(FILE *outfile, struct buildObservedVoids_info *args_info) +{ + int i = 0; + + if (!outfile) + { + fprintf (stderr, "%s: cannot dump options to stream\n", BUILDOBSERVEDVOIDS_CONF_PACKAGE); + return EXIT_FAILURE; + } + + if (args_info->help_given) + write_into_file(outfile, "help", 0, 0 ); + if (args_info->version_given) + write_into_file(outfile, "version", 0, 0 ); + if (args_info->desc_given) + write_into_file(outfile, "desc", args_info->desc_orig, 0); + if (args_info->adj_given) + write_into_file(outfile, "adj", args_info->adj_orig, 0); + if (args_info->void_given) + write_into_file(outfile, "void", args_info->void_orig, 0); + if (args_info->minProba_given) + write_into_file(outfile, "minProba", args_info->minProba_orig, 0); + if (args_info->densityThreshold_given) + write_into_file(outfile, "densityThreshold", args_info->densityThreshold_orig, 0); + if (args_info->ramsesDir_given) + write_into_file(outfile, "ramsesDir", args_info->ramsesDir_orig, 0); + if (args_info->ramsesId_given) + write_into_file(outfile, "ramsesId", args_info->ramsesId_orig, 0); + if (args_info->configFile_given) + write_into_file(outfile, "configFile", args_info->configFile_orig, 0); + if (args_info->output_given) + write_into_file(outfile, "output", args_info->output_orig, 0); + if (args_info->gridOutput_given) + write_into_file(outfile, "gridOutput", args_info->gridOutput_orig, 0); + if (args_info->quiet_given) + write_into_file(outfile, "quiet", 0, 0 ); + + + i = EXIT_SUCCESS; + return i; +} + +int +buildObservedVoids_conf_file_save(const char *filename, struct buildObservedVoids_info *args_info) +{ + FILE *outfile; + int i = 0; + + outfile = fopen(filename, "w"); + + if (!outfile) + { + fprintf (stderr, "%s: cannot open file for writing: %s\n", BUILDOBSERVEDVOIDS_CONF_PACKAGE, filename); + return EXIT_FAILURE; + } + + i = buildObservedVoids_conf_dump(outfile, args_info); + fclose (outfile); + + return i; +} + +void +buildObservedVoids_conf_free (struct buildObservedVoids_info *args_info) +{ + buildObservedVoids_conf_release (args_info); +} + +/** @brief replacement of strdup, which is not standard */ +char * +gengetopt_strdup (const char *s) +{ + char *result = 0; + if (!s) + return result; + + result = (char*)malloc(strlen(s) + 1); + if (result == (char*)0) + return (char*)0; + strcpy(result, s); + return result; +} + +int +buildObservedVoids_conf (int argc, char * const *argv, struct buildObservedVoids_info *args_info) +{ + return buildObservedVoids_conf2 (argc, argv, args_info, 0, 1, 1); +} + +int +buildObservedVoids_conf_ext (int argc, char * const *argv, struct buildObservedVoids_info *args_info, + struct buildObservedVoids_conf_params *params) +{ + int result; + result = buildObservedVoids_conf_internal (argc, argv, args_info, params, 0); + + if (result == EXIT_FAILURE) + { + buildObservedVoids_conf_free (args_info); + exit (EXIT_FAILURE); + } + + return result; +} + +int +buildObservedVoids_conf2 (int argc, char * const *argv, struct buildObservedVoids_info *args_info, int override, int initialize, int check_required) +{ + int result; + struct buildObservedVoids_conf_params params; + + params.override = override; + params.initialize = initialize; + params.check_required = check_required; + params.check_ambiguity = 0; + params.print_errors = 1; + + result = buildObservedVoids_conf_internal (argc, argv, args_info, ¶ms, 0); + + if (result == EXIT_FAILURE) + { + buildObservedVoids_conf_free (args_info); + exit (EXIT_FAILURE); + } + + return result; +} + +int +buildObservedVoids_conf_required (struct buildObservedVoids_info *args_info, const char *prog_name) +{ + int result = EXIT_SUCCESS; + + if (buildObservedVoids_conf_required2(args_info, prog_name, 0) > 0) + result = EXIT_FAILURE; + + if (result == EXIT_FAILURE) + { + buildObservedVoids_conf_free (args_info); + exit (EXIT_FAILURE); + } + + return result; +} + +int +buildObservedVoids_conf_required2 (struct buildObservedVoids_info *args_info, const char *prog_name, const char *additional_error) +{ + FIX_UNUSED (additional_error); + int error = 0; + + /* checks for required options */ + if (! args_info->desc_given) + { + fprintf (stderr, "%s: '--desc' ('-d') option required%s\n", prog_name, (additional_error ? additional_error : "")); + error = 1; + } + + if (! args_info->adj_given) + { + fprintf (stderr, "%s: '--adj' ('-a') option required%s\n", prog_name, (additional_error ? additional_error : "")); + error = 1; + } + + if (! args_info->void_given) + { + fprintf (stderr, "%s: '--void' ('-v') option required%s\n", prog_name, (additional_error ? additional_error : "")); + error = 1; + } + + + /* checks for dependences among options */ + + return error; +} + + +static char *package_name = 0; + +/** + * @brief updates an option + * @param field the generic pointer to the field to update + * @param orig_field the pointer to the orig field + * @param field_given the pointer to the number of occurrence of this option + * @param prev_given the pointer to the number of occurrence already seen + * @param value the argument for this option (if null no arg was specified) + * @param possible_values the possible values for this option (if specified) + * @param default_value the default value (in case the option only accepts fixed values) + * @param arg_type the type of this option + * @param check_ambiguity @see buildObservedVoids_conf_params.check_ambiguity + * @param override @see buildObservedVoids_conf_params.override + * @param no_free whether to free a possible previous value + * @param multiple_option whether this is a multiple option + * @param long_opt the corresponding long option + * @param short_opt the corresponding short option (or '-' if none) + * @param additional_error possible further error specification + */ +static +int update_arg(void *field, char **orig_field, + unsigned int *field_given, unsigned int *prev_given, + char *value, const char *possible_values[], + const char *default_value, + buildObservedVoids_conf_arg_type arg_type, + int check_ambiguity, int override, + int no_free, int multiple_option, + const char *long_opt, char short_opt, + const char *additional_error) +{ + FIX_UNUSED (field); + char *stop_char = 0; + const char *val = value; + int found; + char **string_field; + + stop_char = 0; + found = 0; + + if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) + { + if (short_opt != '-') + fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", + package_name, long_opt, short_opt, + (additional_error ? additional_error : "")); + else + fprintf (stderr, "%s: `--%s' option given more than once%s\n", + package_name, long_opt, + (additional_error ? additional_error : "")); + return 1; /* failure */ + } + + FIX_UNUSED (default_value); + + if (field_given && *field_given && ! override) + return 0; + if (prev_given) + (*prev_given)++; + if (field_given) + (*field_given)++; + if (possible_values) + val = possible_values[found]; + + switch(arg_type) { + case ARG_FLAG: + *((int *)field) = !*((int *)field); + break; + case ARG_INT: + if (val) *((int *)field) = strtol (val, &stop_char, 0); + break; + case ARG_DOUBLE: + if (val) *((double *)field) = strtod (val, &stop_char); + break; + case ARG_STRING: + if (val) { + string_field = (char **)field; + if (!no_free && *string_field) + free (*string_field); /* free previous string */ + *string_field = gengetopt_strdup (val); + } + break; + default: + break; + }; + + /* check numeric conversion */ + switch(arg_type) { + case ARG_INT: + case ARG_DOUBLE: + if (val && !(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); + return 1; /* failure */ + } + break; + default: + ; + }; + + /* store the original value */ + switch(arg_type) { + case ARG_NO: + case ARG_FLAG: + break; + default: + if (value && orig_field) { + if (no_free) { + *orig_field = value; + } else { + if (*orig_field) + free (*orig_field); /* free previous string */ + *orig_field = gengetopt_strdup (value); + } + } + }; + + return 0; /* OK */ +} + + +int +buildObservedVoids_conf_internal ( + int argc, char * const *argv, struct buildObservedVoids_info *args_info, + struct buildObservedVoids_conf_params *params, const char *additional_error) +{ + int c; /* Character of the parsed option. */ + + int error = 0; + struct buildObservedVoids_info local_args_info; + + int override; + int initialize; + int check_required; + int check_ambiguity; + + package_name = argv[0]; + + override = params->override; + initialize = params->initialize; + check_required = params->check_required; + check_ambiguity = params->check_ambiguity; + + if (initialize) + buildObservedVoids_conf_init (args_info); + + buildObservedVoids_conf_init (&local_args_info); + + optarg = 0; + optind = 0; + opterr = params->print_errors; + optopt = '?'; + + while (1) + { + int option_index = 0; + + static struct option long_options[] = { + { "help", 0, NULL, 'h' }, + { "version", 0, NULL, 'V' }, + { "desc", 1, NULL, 'd' }, + { "adj", 1, NULL, 'a' }, + { "void", 1, NULL, 'v' }, + { "minProba", 1, NULL, 'm' }, + { "densityThreshold", 1, NULL, 0 }, + { "ramsesDir", 1, NULL, 'b' }, + { "ramsesId", 1, NULL, 'r' }, + { "configFile", 1, NULL, 'f' }, + { "output", 1, NULL, 'o' }, + { "gridOutput", 1, NULL, 'g' }, + { "quiet", 0, NULL, 'q' }, + { 0, 0, 0, 0 } + }; + + c = getopt_long (argc, argv, "hVd:a:v:m:b:r:f:o:g:q", long_options, &option_index); + + if (c == -1) break; /* Exit from `while (1)' loop. */ + + switch (c) + { + case 'h': /* Print help and exit. */ + buildObservedVoids_conf_print_help (); + buildObservedVoids_conf_free (&local_args_info); + exit (EXIT_SUCCESS); + + case 'V': /* Print version and exit. */ + buildObservedVoids_conf_print_version (); + buildObservedVoids_conf_free (&local_args_info); + exit (EXIT_SUCCESS); + + case 'd': /* The description file name for the voids (jozov generated). */ + + + if (update_arg( (void *)&(args_info->desc_arg), + &(args_info->desc_orig), &(args_info->desc_given), + &(local_args_info.desc_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "desc", 'd', + additional_error)) + goto failure; + + break; + case 'a': /* Adjacent file name (jozov generated). */ + + + if (update_arg( (void *)&(args_info->adj_arg), + &(args_info->adj_orig), &(args_info->adj_given), + &(local_args_info.adj_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "adj", 'a', + additional_error)) + goto failure; + + break; + case 'v': /* Void/zone bind filename (jozov generated). */ + + + if (update_arg( (void *)&(args_info->void_arg), + &(args_info->void_orig), &(args_info->void_given), + &(local_args_info.void_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "void", 'v', + additional_error)) + goto failure; + + break; + case 'm': /* Minimal probability to accept. */ + + + if (update_arg( (void *)&(args_info->minProba_arg), + &(args_info->minProba_orig), &(args_info->minProba_given), + &(local_args_info.minProba_given), optarg, 0, "0.0", ARG_DOUBLE, + check_ambiguity, override, 0, 0, + "minProba", 'm', + additional_error)) + goto failure; + + break; + case 'b': /* Ramses base output directory. */ + + + if (update_arg( (void *)&(args_info->ramsesDir_arg), + &(args_info->ramsesDir_orig), &(args_info->ramsesDir_given), + &(local_args_info.ramsesDir_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "ramsesDir", 'b', + additional_error)) + goto failure; + + break; + case 'r': /* Ramses output id. */ + + + if (update_arg( (void *)&(args_info->ramsesId_arg), + &(args_info->ramsesId_orig), &(args_info->ramsesId_given), + &(local_args_info.ramsesId_given), optarg, 0, 0, ARG_INT, + check_ambiguity, override, 0, 0, + "ramsesId", 'r', + additional_error)) + goto failure; + + break; + case 'f': /* Configuration file. */ + + + if (update_arg( (void *)&(args_info->configFile_arg), + &(args_info->configFile_orig), &(args_info->configFile_given), + &(local_args_info.configFile_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "configFile", 'f', + additional_error)) + goto failure; + + break; + case 'o': /* Output file. */ + + + if (update_arg( (void *)&(args_info->output_arg), + &(args_info->output_orig), &(args_info->output_given), + &(local_args_info.output_given), optarg, 0, "void_info.txt", ARG_STRING, + check_ambiguity, override, 0, 0, + "output", 'o', + additional_error)) + goto failure; + + break; + case 'g': /* 3d grid output of voids. */ + + + if (update_arg( (void *)&(args_info->gridOutput_arg), + &(args_info->gridOutput_orig), &(args_info->gridOutput_given), + &(local_args_info.gridOutput_given), optarg, 0, "all_voids.nc", ARG_STRING, + check_ambiguity, override, 0, 0, + "gridOutput", 'g', + additional_error)) + goto failure; + + break; + case 'q': /* Quiet output. */ + + + if (update_arg((void *)&(args_info->quiet_flag), 0, &(args_info->quiet_given), + &(local_args_info.quiet_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "quiet", 'q', + additional_error)) + goto failure; + + break; + + case 0: /* Long option with no short option */ + /* Density threshold to consider a stable void. */ + if (strcmp (long_options[option_index].name, "densityThreshold") == 0) + { + + + if (update_arg( (void *)&(args_info->densityThreshold_arg), + &(args_info->densityThreshold_orig), &(args_info->densityThreshold_given), + &(local_args_info.densityThreshold_given), optarg, 0, "-0.8", ARG_DOUBLE, + check_ambiguity, override, 0, 0, + "densityThreshold", '-', + additional_error)) + goto failure; + + } + + break; + case '?': /* Invalid option. */ + /* `getopt_long' already printed an error message. */ + goto failure; + + default: /* bug: option not considered. */ + fprintf (stderr, "%s: option unknown: %c%s\n", BUILDOBSERVEDVOIDS_CONF_PACKAGE, c, (additional_error ? additional_error : "")); + abort (); + } /* switch */ + } /* while */ + + + + if (check_required) + { + error += buildObservedVoids_conf_required2 (args_info, argv[0], additional_error); + } + + buildObservedVoids_conf_release (&local_args_info); + + if ( error ) + return (EXIT_FAILURE); + + return 0; + +failure: + + buildObservedVoids_conf_release (&local_args_info); + return (EXIT_FAILURE); +} + +#ifndef CONFIG_FILE_LINE_SIZE +#define CONFIG_FILE_LINE_SIZE 2048 +#endif +#define ADDITIONAL_ERROR " in configuration file " + +#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3) +/* 3 is for "--" and "=" */ + +static int +_buildObservedVoids_conf_configfile (const char *filename, int *my_argc) +{ + FILE* file; + char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1]; + char linebuf[CONFIG_FILE_LINE_SIZE]; + int line_num = 0; + int result = 0, equal; + char *fopt, *farg; + char *str_index; + size_t len, next_token; + char delimiter; + + if ((file = fopen(filename, "r")) == 0) + { + fprintf (stderr, "%s: Error opening configuration file '%s'\n", + BUILDOBSERVEDVOIDS_CONF_PACKAGE, filename); + return EXIT_FAILURE; + } + + while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != 0) + { + ++line_num; + my_argv[0] = '\0'; + len = strlen(linebuf); + if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1)) + { + fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n", + BUILDOBSERVEDVOIDS_CONF_PACKAGE, filename, line_num); + result = EXIT_FAILURE; + break; + } + + /* find first non-whitespace character in the line */ + next_token = strspn (linebuf, " \t\r\n"); + str_index = linebuf + next_token; + + if ( str_index[0] == '\0' || str_index[0] == '#') + continue; /* empty line or comment line is skipped */ + + fopt = str_index; + + /* truncate fopt at the end of the first non-valid character */ + next_token = strcspn (fopt, " \t\r\n="); + + if (fopt[next_token] == '\0') /* the line is over */ + { + farg = 0; + equal = 0; + goto noarg; + } + + /* remember if equal sign is present */ + equal = (fopt[next_token] == '='); + fopt[next_token++] = '\0'; + + /* advance pointers to the next token after the end of fopt */ + next_token += strspn (fopt + next_token, " \t\r\n"); + + /* check for the presence of equal sign, and if so, skip it */ + if ( !equal ) + if ((equal = (fopt[next_token] == '='))) + { + next_token++; + next_token += strspn (fopt + next_token, " \t\r\n"); + } + str_index += next_token; + + /* find argument */ + farg = str_index; + if ( farg[0] == '\"' || farg[0] == '\'' ) + { /* quoted argument */ + str_index = strchr (++farg, str_index[0] ); /* skip opening quote */ + if (! str_index) + { + fprintf + (stderr, + "%s:%s:%d: unterminated string in configuration file\n", + BUILDOBSERVEDVOIDS_CONF_PACKAGE, filename, line_num); + result = EXIT_FAILURE; + break; + } + } + else + { /* read up the remaining part up to a delimiter */ + next_token = strcspn (farg, " \t\r\n#\'\""); + str_index += next_token; + } + + /* truncate farg at the delimiter and store it for further check */ + delimiter = *str_index, *str_index++ = '\0'; + + /* everything but comment is illegal at the end of line */ + if (delimiter != '\0' && delimiter != '#') + { + str_index += strspn(str_index, " \t\r\n"); + if (*str_index != '\0' && *str_index != '#') + { + fprintf + (stderr, + "%s:%s:%d: malformed string in configuration file\n", + BUILDOBSERVEDVOIDS_CONF_PACKAGE, filename, line_num); + result = EXIT_FAILURE; + break; + } + } + + noarg: + if (!strcmp(fopt,"include")) { + if (farg && *farg) { + result = _buildObservedVoids_conf_configfile(farg, my_argc); + } else { + fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n", + BUILDOBSERVEDVOIDS_CONF_PACKAGE, filename, line_num); + } + continue; + } + len = strlen(fopt); + strcat (my_argv, len > 1 ? "--" : "-"); + strcat (my_argv, fopt); + if (len > 1 && ((farg && *farg) || equal)) + strcat (my_argv, "="); + if (farg && *farg) + strcat (my_argv, farg); + ++(*my_argc); + + cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); + cmd_line_list_tmp->next = cmd_line_list; + cmd_line_list = cmd_line_list_tmp; + cmd_line_list->string_arg = gengetopt_strdup(my_argv); + } /* while */ + + if (file) + fclose(file); + return result; +} + +int +buildObservedVoids_conf_configfile ( + const char *filename, + struct buildObservedVoids_info *args_info, + int override, int initialize, int check_required) +{ + struct buildObservedVoids_conf_params params; + + params.override = override; + params.initialize = initialize; + params.check_required = check_required; + params.check_ambiguity = 0; + params.print_errors = 1; + + return buildObservedVoids_conf_config_file (filename, args_info, ¶ms); +} + +int +buildObservedVoids_conf_config_file (const char *filename, + struct buildObservedVoids_info *args_info, + struct buildObservedVoids_conf_params *params) +{ + int i, result; + int my_argc = 1; + char **my_argv_arg; + char *additional_error; + + /* store the program name */ + cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); + cmd_line_list_tmp->next = cmd_line_list; + cmd_line_list = cmd_line_list_tmp; + cmd_line_list->string_arg = gengetopt_strdup (BUILDOBSERVEDVOIDS_CONF_PACKAGE); + + result = _buildObservedVoids_conf_configfile(filename, &my_argc); + + if (result != EXIT_FAILURE) { + my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *)); + cmd_line_list_tmp = cmd_line_list; + + for (i = my_argc - 1; i >= 0; --i) { + my_argv_arg[i] = cmd_line_list_tmp->string_arg; + cmd_line_list_tmp = cmd_line_list_tmp->next; + } + + my_argv_arg[my_argc] = 0; + + additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1); + strcpy (additional_error, ADDITIONAL_ERROR); + strcat (additional_error, filename); + result = + buildObservedVoids_conf_internal (my_argc, my_argv_arg, args_info, + params, + additional_error); + + free (additional_error); + free (my_argv_arg); + } + + free_cmd_list(); + if (result == EXIT_FAILURE) + { + buildObservedVoids_conf_free (args_info); + exit (EXIT_FAILURE); + } + + return result; +} diff --git a/mytools/buildObservedVoids_conf.h b/mytools/buildObservedVoids_conf.h new file mode 100644 index 0000000..e73705b --- /dev/null +++ b/mytools/buildObservedVoids_conf.h @@ -0,0 +1,239 @@ +/** @file buildObservedVoids_conf.h + * @brief The header file for the command line option parser + * generated by GNU Gengetopt version 2.22.2 + * http://www.gnu.org/software/gengetopt. + * DO NOT modify this file, since it can be overwritten + * @author GNU Gengetopt by Lorenzo Bettini */ + +#ifndef BUILDOBSERVEDVOIDS_CONF_H +#define BUILDOBSERVEDVOIDS_CONF_H + +/* If we use autoconf. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include /* for FILE */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifndef BUILDOBSERVEDVOIDS_CONF_PACKAGE +/** @brief the program name (used for printing errors) */ +#define BUILDOBSERVEDVOIDS_CONF_PACKAGE "buildObservedVoids" +#endif + +#ifndef BUILDOBSERVEDVOIDS_CONF_PACKAGE_NAME +/** @brief the complete program name (used for help and version) */ +#define BUILDOBSERVEDVOIDS_CONF_PACKAGE_NAME "buildObservedVoids" +#endif + +#ifndef BUILDOBSERVEDVOIDS_CONF_VERSION +/** @brief the program version */ +#define BUILDOBSERVEDVOIDS_CONF_VERSION "0" +#endif + +/** @brief Where the command line options are stored */ +struct buildObservedVoids_info +{ + const char *help_help; /**< @brief Print help and exit help description. */ + const char *version_help; /**< @brief Print version and exit help description. */ + char * desc_arg; /**< @brief The description file name for the voids (jozov generated). */ + char * desc_orig; /**< @brief The description file name for the voids (jozov generated) original value given at command line. */ + const char *desc_help; /**< @brief The description file name for the voids (jozov generated) help description. */ + char * adj_arg; /**< @brief Adjacent file name (jozov generated). */ + char * adj_orig; /**< @brief Adjacent file name (jozov generated) original value given at command line. */ + const char *adj_help; /**< @brief Adjacent file name (jozov generated) help description. */ + char * void_arg; /**< @brief Void/zone bind filename (jozov generated). */ + char * void_orig; /**< @brief Void/zone bind filename (jozov generated) original value given at command line. */ + const char *void_help; /**< @brief Void/zone bind filename (jozov generated) help description. */ + double minProba_arg; /**< @brief Minimal probability to accept (default='0.0'). */ + char * minProba_orig; /**< @brief Minimal probability to accept original value given at command line. */ + const char *minProba_help; /**< @brief Minimal probability to accept help description. */ + double densityThreshold_arg; /**< @brief Density threshold to consider a stable void (default='-0.8'). */ + char * densityThreshold_orig; /**< @brief Density threshold to consider a stable void original value given at command line. */ + const char *densityThreshold_help; /**< @brief Density threshold to consider a stable void help description. */ + char * ramsesDir_arg; /**< @brief Ramses base output directory. */ + char * ramsesDir_orig; /**< @brief Ramses base output directory original value given at command line. */ + const char *ramsesDir_help; /**< @brief Ramses base output directory help description. */ + int ramsesId_arg; /**< @brief Ramses output id. */ + char * ramsesId_orig; /**< @brief Ramses output id original value given at command line. */ + const char *ramsesId_help; /**< @brief Ramses output id help description. */ + char * configFile_arg; /**< @brief Configuration file. */ + char * configFile_orig; /**< @brief Configuration file original value given at command line. */ + const char *configFile_help; /**< @brief Configuration file help description. */ + char * output_arg; /**< @brief Output file (default='void_info.txt'). */ + char * output_orig; /**< @brief Output file original value given at command line. */ + const char *output_help; /**< @brief Output file help description. */ + char * gridOutput_arg; /**< @brief 3d grid output of voids (default='all_voids.nc'). */ + char * gridOutput_orig; /**< @brief 3d grid output of voids original value given at command line. */ + const char *gridOutput_help; /**< @brief 3d grid output of voids help description. */ + int quiet_flag; /**< @brief Quiet output (default=off). */ + const char *quiet_help; /**< @brief Quiet output help description. */ + + unsigned int help_given ; /**< @brief Whether help was given. */ + unsigned int version_given ; /**< @brief Whether version was given. */ + unsigned int desc_given ; /**< @brief Whether desc was given. */ + unsigned int adj_given ; /**< @brief Whether adj was given. */ + unsigned int void_given ; /**< @brief Whether void was given. */ + unsigned int minProba_given ; /**< @brief Whether minProba was given. */ + unsigned int densityThreshold_given ; /**< @brief Whether densityThreshold was given. */ + unsigned int ramsesDir_given ; /**< @brief Whether ramsesDir was given. */ + unsigned int ramsesId_given ; /**< @brief Whether ramsesId was given. */ + unsigned int configFile_given ; /**< @brief Whether configFile was given. */ + unsigned int output_given ; /**< @brief Whether output was given. */ + unsigned int gridOutput_given ; /**< @brief Whether gridOutput was given. */ + unsigned int quiet_given ; /**< @brief Whether quiet was given. */ + +} ; + +/** @brief The additional parameters to pass to parser functions */ +struct buildObservedVoids_conf_params +{ + int override; /**< @brief whether to override possibly already present options (default 0) */ + int initialize; /**< @brief whether to initialize the option structure buildObservedVoids_info (default 1) */ + int check_required; /**< @brief whether to check that all required options were provided (default 1) */ + int check_ambiguity; /**< @brief whether to check for options already specified in the option structure buildObservedVoids_info (default 0) */ + int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ +} ; + +/** @brief the purpose string of the program */ +extern const char *buildObservedVoids_info_purpose; +/** @brief the usage string of the program */ +extern const char *buildObservedVoids_info_usage; +/** @brief all the lines making the help output */ +extern const char *buildObservedVoids_info_help[]; + +/** + * The command line parser + * @param argc the number of command line options + * @param argv the command line options + * @param args_info the structure where option information will be stored + * @return 0 if everything went fine, NON 0 if an error took place + */ +int buildObservedVoids_conf (int argc, char * const *argv, + struct buildObservedVoids_info *args_info); + +/** + * The command line parser (version with additional parameters - deprecated) + * @param argc the number of command line options + * @param argv the command line options + * @param args_info the structure where option information will be stored + * @param override whether to override possibly already present options + * @param initialize whether to initialize the option structure my_args_info + * @param check_required whether to check that all required options were provided + * @return 0 if everything went fine, NON 0 if an error took place + * @deprecated use buildObservedVoids_conf_ext() instead + */ +int buildObservedVoids_conf2 (int argc, char * const *argv, + struct buildObservedVoids_info *args_info, + int override, int initialize, int check_required); + +/** + * The command line parser (version with additional parameters) + * @param argc the number of command line options + * @param argv the command line options + * @param args_info the structure where option information will be stored + * @param params additional parameters for the parser + * @return 0 if everything went fine, NON 0 if an error took place + */ +int buildObservedVoids_conf_ext (int argc, char * const *argv, + struct buildObservedVoids_info *args_info, + struct buildObservedVoids_conf_params *params); + +/** + * Save the contents of the option struct into an already open FILE stream. + * @param outfile the stream where to dump options + * @param args_info the option struct to dump + * @return 0 if everything went fine, NON 0 if an error took place + */ +int buildObservedVoids_conf_dump(FILE *outfile, + struct buildObservedVoids_info *args_info); + +/** + * Save the contents of the option struct into a (text) file. + * This file can be read by the config file parser (if generated by gengetopt) + * @param filename the file where to save + * @param args_info the option struct to save + * @return 0 if everything went fine, NON 0 if an error took place + */ +int buildObservedVoids_conf_file_save(const char *filename, + struct buildObservedVoids_info *args_info); + +/** + * Print the help + */ +void buildObservedVoids_conf_print_help(void); +/** + * Print the version + */ +void buildObservedVoids_conf_print_version(void); + +/** + * Initializes all the fields a buildObservedVoids_conf_params structure + * to their default values + * @param params the structure to initialize + */ +void buildObservedVoids_conf_params_init(struct buildObservedVoids_conf_params *params); + +/** + * Allocates dynamically a buildObservedVoids_conf_params structure and initializes + * all its fields to their default values + * @return the created and initialized buildObservedVoids_conf_params structure + */ +struct buildObservedVoids_conf_params *buildObservedVoids_conf_params_create(void); + +/** + * Initializes the passed buildObservedVoids_info structure's fields + * (also set default values for options that have a default) + * @param args_info the structure to initialize + */ +void buildObservedVoids_conf_init (struct buildObservedVoids_info *args_info); +/** + * Deallocates the string fields of the buildObservedVoids_info structure + * (but does not deallocate the structure itself) + * @param args_info the structure to deallocate + */ +void buildObservedVoids_conf_free (struct buildObservedVoids_info *args_info); + +/** + * The config file parser (deprecated version) + * @param filename the name of the config file + * @param args_info the structure where option information will be stored + * @param override whether to override possibly already present options + * @param initialize whether to initialize the option structure my_args_info + * @param check_required whether to check that all required options were provided + * @return 0 if everything went fine, NON 0 if an error took place + * @deprecated use buildObservedVoids_conf_config_file() instead + */ +int buildObservedVoids_conf_configfile (const char *filename, + struct buildObservedVoids_info *args_info, + int override, int initialize, int check_required); + +/** + * The config file parser + * @param filename the name of the config file + * @param args_info the structure where option information will be stored + * @param params additional parameters for the parser + * @return 0 if everything went fine, NON 0 if an error took place + */ +int buildObservedVoids_conf_config_file (const char *filename, + struct buildObservedVoids_info *args_info, + struct buildObservedVoids_conf_params *params); + +/** + * Checks that all the required options were specified + * @param args_info the structure to check + * @param prog_name the name of the program that will be used to print + * possible errors + * @return + */ +int buildObservedVoids_conf_required (struct buildObservedVoids_info *args_info, + const char *prog_name); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* BUILDOBSERVEDVOIDS_CONF_H */ diff --git a/mytools/config.mk b/mytools/config.mk index d41d32c..641c21a 100644 --- a/mytools/config.mk +++ b/mytools/config.mk @@ -1,6 +1,6 @@ CC= gcc CXX= g++ -CPPFLAGS= -I$(HOME)/Science/Software/CosmoToolbox/install/include -LDFLAGS= -L$(HOME)/Science/Software/CosmoToolbox/install/lib -lCosmoTool -CXXFLAGS= $(CPPFLAGS) -ggdb -O0 -ffast-math -CFLAGS= $(CPPFLAGS) -ggdb -O0 -ffast-math +CPPFLAGS= +LDFLAGS= -lCosmoTool +CXXFLAGS= $(CPPFLAGS) -ggdb -O3 -ffast-math +CFLAGS= $(CPPFLAGS) -ggdb -O3 -ffast-math diff --git a/mytools/voidTree.hpp b/mytools/voidTree.hpp new file mode 100644 index 0000000..9b15ec6 --- /dev/null +++ b/mytools/voidTree.hpp @@ -0,0 +1,156 @@ +#ifndef _VOID_TREE_HPP +#define _VOID_TREE_HPP + +#include +#include +#include "loadZobov.hpp" +#include +#include +#include + +struct VoidNode +{ + int vid; + VoidNode *parent; + std::list children; +}; + +class VoidTree +{ +protected: + uint32_t totalNumNodes; + VoidNode *nodes; + VoidNode *rootNode; + ZobovRep& zobov; +public: + typedef std::list VoidList; + + int lookupParent(int voidId) + { + std::set sref; + sref.insert(zobov.allVoids[voidId].zId.begin(), zobov.allVoids[voidId].zId.end()); + + + std::vector sout(sref.size()); + int lastSize = 0x7fffffff; + int goodParent = voidId; + + // Voids are sorted according to volume + for (int i = voidId-1; i >= 0; i--) + { + std::set s1; + + int counter = 0; + s1.insert(zobov.allVoids[i].zId.begin(), zobov.allVoids[i].zId.end()); + for (std::set::iterator iter = s1.begin(), iter2 = sref.begin(); + iter != s1.end() && iter2 != sref.end(); + ++iter) + { + if (*iter == *iter2) + { + counter++; + ++iter2; + } + else while (*iter > *iter2 && iter2 != sref.end()) + ++iter2; + } + + if (counter == sref.size() && s1.size() < lastSize) + { + return i; + } + } + return -1; + } + + VoidTree(ZobovRep& rep) + : zobov(rep) + { + totalNumNodes = rep.allVoids.size(); + + nodes = new VoidNode[totalNumNodes]; + + for (int i = 0; i < rep.allVoids.size(); i++) + { + nodes[i].vid = i; + nodes[i].parent = 0; + nodes[i].children.clear(); + } + + std::cout << "Linking voids together..." << std::endl; + double volMin = 4*M_PI/3*pow(4.*512/500.,3); + int inserted = 0; + for (int i = rep.allVoids.size()-1; i>=0;i--) + { + if (rep.allVoids[i].volume < volMin) continue; + + int p = lookupParent(i); + + std::cout << i << std::endl; + + if (p < 0) + { + if (i != 0) + std::cerr << "Warning ! Voids without parent and it is not the root !" << std::endl; + continue; + } + + nodes[p].children.push_back(&nodes[i]); + nodes[i].parent = &nodes[p]; + inserted++; + } + + rootNode = 0; + for (int i = inserted; i < totalNumNodes; i++) + if (nodes[i].parent == 0) + { + if (rootNode != 0) + { + std::cerr << "Multiple root to the tree !!!" << std::endl; + abort(); + } + rootNode = &nodes[i]; + } + } + + ~VoidTree() + { + delete[] nodes; + } + + int getParent(int vid) const + { + assert(nodes[vid].parent != 0); + return nodes[vid].parent->vid; + } + + const VoidList& getChildren(int vid) const + { + return nodes[vid].children; + } + + + template + void walkNode(VoidNode *node, T& traverse) + { + VoidList::iterator i; + + if (!traverse(node)) + return; + + while (i != node->children.end()) + { + walkNode(*i, traverse); + ++i; + } + } + + template + void walk(T& traverse) + { + walkNode(rootNode, traverse); + } + +}; + +#endif diff --git a/mytools/zobovConf.c b/mytools/zobovConf.c index aee1f28..07b09e4 100644 --- a/mytools/zobovConf.c +++ b/mytools/zobovConf.c @@ -1,5 +1,5 @@ /* - File autogenerated by gengetopt version 2.22 + File autogenerated by gengetopt version 2.22.2 generated with the following command: gengetopt -i showZobov.ggo -f zobovConf -a zobovConf_info -F zobovConf -C @@ -17,6 +17,10 @@ #include #include +#ifndef FIX_UNUSED +#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ +#endif + #include "getopt.h" #include "zobovConf.h" @@ -119,6 +123,7 @@ void clear_given (struct zobovConf_info *args_info) static void clear_args (struct zobovConf_info *args_info) { + FIX_UNUSED (args_info); args_info->desc_arg = NULL; args_info->desc_orig = NULL; args_info->adj_arg = NULL; @@ -173,7 +178,9 @@ void init_args_info(struct zobovConf_info *args_info) void zobovConf_print_version (void) { - printf ("%s %s\n", ZOBOVCONF_PACKAGE, ZOBOVCONF_VERSION); + printf ("%s %s\n", + (strlen(ZOBOVCONF_PACKAGE_NAME) ? ZOBOVCONF_PACKAGE_NAME : ZOBOVCONF_PACKAGE), + ZOBOVCONF_VERSION); } static void print_help_common(void) { @@ -188,7 +195,7 @@ static void print_help_common(void) { printf("\n"); if (strlen(zobovConf_info_description) > 0) - printf("%s\n", zobovConf_info_description); + printf("%s\n\n", zobovConf_info_description); } void @@ -270,8 +277,9 @@ zobovConf_release (struct zobovConf_info *args_info) static void -write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[]) +write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) { + FIX_UNUSED (values); if (arg) { fprintf(outfile, "%s=\"%s\"\n", opt, arg); } else { @@ -361,7 +369,7 @@ zobovConf_free (struct zobovConf_info *args_info) char * gengetopt_strdup (const char *s) { - char *result = NULL; + char *result = 0; if (!s) return result; @@ -383,7 +391,7 @@ zobovConf_ext (int argc, char * const *argv, struct zobovConf_info *args_info, struct zobovConf_params *params) { int result; - result = zobovConf_internal (argc, argv, args_info, params, NULL); + result = zobovConf_internal (argc, argv, args_info, params, 0); if (result == EXIT_FAILURE) { @@ -406,7 +414,7 @@ zobovConf2 (int argc, char * const *argv, struct zobovConf_info *args_info, int params.check_ambiguity = 0; params.print_errors = 1; - result = zobovConf_internal (argc, argv, args_info, ¶ms, NULL); + result = zobovConf_internal (argc, argv, args_info, ¶ms, 0); if (result == EXIT_FAILURE) { @@ -422,7 +430,7 @@ zobovConf_required (struct zobovConf_info *args_info, const char *prog_name) { int result = EXIT_SUCCESS; - if (zobovConf_required2(args_info, prog_name, NULL) > 0) + if (zobovConf_required2(args_info, prog_name, 0) > 0) result = EXIT_FAILURE; if (result == EXIT_FAILURE) @@ -437,6 +445,7 @@ zobovConf_required (struct zobovConf_info *args_info, const char *prog_name) int zobovConf_required2 (struct zobovConf_info *args_info, const char *prog_name, const char *additional_error) { + FIX_UNUSED (additional_error); int error = 0; /* checks for required options */ @@ -500,13 +509,15 @@ static char *package_name = 0; static int update_arg(void *field, char **orig_field, unsigned int *field_given, unsigned int *prev_given, - char *value, char *possible_values[], const char *default_value, + char *value, const char *possible_values[], + const char *default_value, zobovConf_arg_type arg_type, int check_ambiguity, int override, int no_free, int multiple_option, const char *long_opt, char short_opt, const char *additional_error) { + FIX_UNUSED (field); char *stop_char = 0; const char *val = value; int found; @@ -528,6 +539,7 @@ int update_arg(void *field, char **orig_field, return 1; /* failure */ } + FIX_UNUSED (default_value); if (field_given && *field_given && ! override) return 0; @@ -595,7 +607,8 @@ int update_arg(void *field, char **orig_field, int -zobovConf_internal (int argc, char * const *argv, struct zobovConf_info *args_info, +zobovConf_internal ( + int argc, char * const *argv, struct zobovConf_info *args_info, struct zobovConf_params *params, const char *additional_error) { int c; /* Character of the parsed option. */ @@ -647,7 +660,7 @@ zobovConf_internal (int argc, char * const *argv, struct zobovConf_info *args_in { "galax", 0, NULL, 0 }, { "output", 1, NULL, 'o' }, { "interactive", 0, NULL, 0 }, - { NULL, 0, NULL, 0 } + { 0, 0, 0, 0 } }; c = getopt_long (argc, argv, "hVd:a:v:i:slm:b:r:f:qp:o:", long_options, &option_index); @@ -883,7 +896,7 @@ failure: /* 3 is for "--" and "=" */ static int -_zobovConf_configfile (char * const filename, int *my_argc) +_zobovConf_configfile (const char *filename, int *my_argc) { FILE* file; char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1]; @@ -895,14 +908,14 @@ _zobovConf_configfile (char * const filename, int *my_argc) size_t len, next_token; char delimiter; - if ((file = fopen(filename, "r")) == NULL) + if ((file = fopen(filename, "r")) == 0) { fprintf (stderr, "%s: Error opening configuration file '%s'\n", ZOBOVCONF_PACKAGE, filename); return EXIT_FAILURE; } - while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL) + while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != 0) { ++line_num; my_argv[0] = '\0'; @@ -929,7 +942,7 @@ _zobovConf_configfile (char * const filename, int *my_argc) if (fopt[next_token] == '\0') /* the line is over */ { - farg = NULL; + farg = 0; equal = 0; goto noarg; } @@ -1020,7 +1033,8 @@ _zobovConf_configfile (char * const filename, int *my_argc) } int -zobovConf_configfile (char * const filename, +zobovConf_configfile ( + const char *filename, struct zobovConf_info *args_info, int override, int initialize, int check_required) { @@ -1036,7 +1050,7 @@ zobovConf_configfile (char * const filename, } int -zobovConf_config_file (char * const filename, +zobovConf_config_file (const char *filename, struct zobovConf_info *args_info, struct zobovConf_params *params) { diff --git a/mytools/zobovConf.h b/mytools/zobovConf.h index fc9e7e9..0b15094 100644 --- a/mytools/zobovConf.h +++ b/mytools/zobovConf.h @@ -1,6 +1,6 @@ /** @file zobovConf.h * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.22 + * generated by GNU Gengetopt version 2.22.2 * http://www.gnu.org/software/gengetopt. * DO NOT modify this file, since it can be overwritten * @author GNU Gengetopt by Lorenzo Bettini */ @@ -20,10 +20,15 @@ extern "C" { #endif /* __cplusplus */ #ifndef ZOBOVCONF_PACKAGE -/** @brief the program name */ +/** @brief the program name (used for printing errors) */ #define ZOBOVCONF_PACKAGE "showZobov" #endif +#ifndef ZOBOVCONF_PACKAGE_NAME +/** @brief the complete program name (used for help and version) */ +#define ZOBOVCONF_PACKAGE_NAME "showZobov" +#endif + #ifndef ZOBOVCONF_VERSION /** @brief the program version */ #define ZOBOVCONF_VERSION "0" @@ -214,7 +219,7 @@ void zobovConf_free (struct zobovConf_info *args_info); * @return 0 if everything went fine, NON 0 if an error took place * @deprecated use zobovConf_config_file() instead */ -int zobovConf_configfile (char * const filename, +int zobovConf_configfile (const char *filename, struct zobovConf_info *args_info, int override, int initialize, int check_required); @@ -225,7 +230,7 @@ int zobovConf_configfile (char * const filename, * @param params additional parameters for the parser * @return 0 if everything went fine, NON 0 if an error took place */ -int zobovConf_config_file (char * const filename, +int zobovConf_config_file (const char *filename, struct zobovConf_info *args_info, struct zobovConf_params *params);