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/client.c | 25 +- src/config/config_file.c | 149 ++-------- src/config/parameters.c | 344 ----------------------- src/config/parameters/parameters.c | 406 +++++++++++++++++++++++++++ src/config/parameters/parameters_accessors.c | 60 ++++ src/device/axis/axis.c | 34 +++ src/device/axis/axis_filter.c | 131 +++++++++ src/server/server.c | 45 ++- 8 files changed, 689 insertions(+), 505 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 create mode 100644 src/device/axis/axis.c create mode 100644 src/device/axis/axis_filter.c (limited to 'src') diff --git a/src/client.c b/src/client.c index d03a768..b0459af 100644 --- a/src/client.c +++ b/src/client.c @@ -20,8 +20,8 @@ /******************************************************************************/ static int open_socket ( - FILE * s [const restrict static 1], - const char socket_name [const restrict static 1] + const char socket_name [const restrict static 1], + FILE * s [const restrict static 1] ) { const int old_errno = errno; @@ -113,9 +113,16 @@ static int send_commands // TODO: error } + if (relabsd_parameters_argument_count_for(argv[i], &j) < 0) + { + RELABSD_FATAL("Unknown option '%s'.", argv[i]); + relabsd_parameters_print_usage(argv[0]); + + return -1; + } + for ( - j = relabsd_parameters_argument_count_for(argv[i]), i++; ((j > 0) && (i < argc)); j++, i-- @@ -161,14 +168,22 @@ int relabsd_client ( const int argc, const char * argv [const restrict static argc], - struct relabsd_parameters params [const restrict static 1] + struct relabsd_parameters parameters [const restrict static 1] ) { FILE * socket; RELABSD_S_DEBUG(RELABSD_DEBUG_PROGRAM_FLOW, "Started client mode."); - if (open_socket(&socket, relabsd_parameters_get_node(params)) < 0) + if + ( + open_socket + ( + relabsd_parameters_get_communication_node_name(parameters), + &socket + ) + < 0 + ) { return -1; } 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 [