From 63016ce5c71019de315434de3e91adbf535d4986 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Tue, 31 Dec 2019 15:51:05 +0100 Subject: Still working on it... --- src/config/config_file.c | 149 ++-------- src/config/parameters.c | 344 ----------------------- src/config/parameters/parameters.c | 406 +++++++++++++++++++++++++++ src/config/parameters/parameters_accessors.c | 60 ++++ 4 files changed, 488 insertions(+), 471 deletions(-) delete mode 100644 src/config/parameters.c create mode 100644 src/config/parameters/parameters.c create mode 100644 src/config/parameters/parameters_accessors.c (limited to 'src/config') diff --git a/src/config/config_file.c b/src/config/config_file.c index ad060a5..2e5ef0c 100644 --- a/src/config/config_file.c +++ b/src/config/config_file.c @@ -1,3 +1,4 @@ +/**** POSIX *******************************************************************/ #include #include #include @@ -6,38 +7,27 @@ #include -#include "error.h" -#include "pervasive.h" -#include "axis.h" -#include "config.h" +/**** RELABSD *****************************************************************/ +#include + +#include #ifndef RELABSD_OPTION_MAX_SIZE #define RELABSD_OPTION_MAX_SIZE 64 #endif -/* - * "errno is never set to zero by any system call or library function." - * This file makes use of this, by setting it to zero and checking if - * it was modified after calling an function (I'm guessing this is common - * practice, but I think it's worth explaining). - * Following the principle of least astonishment, if a function sets errno to - * zero, it will not return before setting it back either to its previous - * value or to a arbitrary nonzero value. - */ +/******************************************************************************/ +/**** LOCAL FUNCTIONS *********************************************************/ +/******************************************************************************/ /* * Returns -1 on (fatal) error, * 0 on EOF, * 1 on newline. */ -static int reach_next_line_or_eof (FILE * const f) +static int reach_next_line_or_eof (FILE f [const restrict static 1]) { - int prev_errno; char c; - prev_errno = errno; - - errno = 0; - c = (char) getc(f); while ((c != '\n') && c != EOF) @@ -45,21 +35,22 @@ static int reach_next_line_or_eof (FILE * const f) c = (char) getc(f); } - if (errno != 0) + if (ferror(f)) { - RELABSD_FATAL + /* + * The 'ferror' function's manual specifically states that it does not + * sets errno. There is no mention of errno in the 'getc' function's + * either, so I am assuming that errno cannot be used to indicate the + * error. + */ + RELABSD_S_FATAL ( - "[CONFIG] Error while attempting to reach EOF or next line: %s.", - strerror(errno) + "[CONFIG] Error while attempting to reach EOF or next line: %s." ); - errno = prev_errno; - return -1; } - errno = prev_errno; - if (c == EOF) { return 0; @@ -643,6 +634,7 @@ static int parse_options return 0; } + int relabsd_config_parse ( struct relabsd_config * const conf, @@ -681,106 +673,6 @@ int relabsd_config_parse return 0; } -static int direct_filter -( - struct relabsd_config_axis * const axis, - int * const value -) -{ - if (abs(*value - axis->previous_value) <= axis->fuzz) - { - if (axis->option[RELABSD_REAL_FUZZ_OPTION]) - { - axis->previous_value = *value; - } - - return -1; - } - - if (*value < axis->min) - { - *value = axis->min; - } - else if (*value > axis->max) - { - *value = axis->max; - } - else if (abs(*value) <= axis->flat) - { - *value = 0; - } - - if (*value == axis->previous_value) - { - return -1; - } - - axis->previous_value = *value; - - return 1; -} - -static int rel_to_abs_filter -( - struct relabsd_config_axis * const axis, - int * const value -) -{ - long int guard; - - guard = (((long int) axis->previous_value) + ((long int) *value)); - - if (guard < ((long int) INT_MIN)) - { - guard = ((long int) INT_MIN); - } - else if (guard > ((long int) INT_MAX)) - { - guard = ((long int) INT_MAX); - } - - *value = (int) guard; - - if (axis->option[RELABSD_FRAMED_OPTION]) - { - if (*value < axis->min) - { - *value = axis->min; - } - else if (*value > axis->max) - { - *value = axis->max; - } - - if (*value == axis->previous_value) - { - return 0; - } - - axis->previous_value = *value; - - return 1; - } - else - { - if (*value == axis->previous_value) - { - return 0; - } - - axis->previous_value = *value; - - if ((*value < axis->min) || (*value > axis->max)) - { - return 0; - } - else - { - return 1; - } - } -} - int relabsd_config_filter ( struct relabsd_config * const conf, @@ -805,6 +697,9 @@ int relabsd_config_filter } } +/******************************************************************************/ +/**** EXPORTED FUNCTIONS ******************************************************/ +/******************************************************************************/ void relabsd_config_get_absinfo ( const struct relabsd_config * const conf, diff --git a/src/config/parameters.c b/src/config/parameters.c deleted file mode 100644 index 5e79fa2..0000000 --- a/src/config/parameters.c +++ /dev/null @@ -1,344 +0,0 @@ -/**** POSIX *******************************************************************/ -#include - -/**** RELABSD *****************************************************************/ -#include -#include - -#include - -#include - -#include - -/******************************************************************************/ -/**** LOCAL FUNCTIONS *********************************************************/ -/******************************************************************************/ -static void print_usage (const char exec [const restrict static 1]) -{ - printf - ( - "USAGE: %s [