| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2015-09-03 11:25:52 +0200 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2015-09-03 11:25:52 +0200 |
| commit | 480288ca001564fa8c9fbdd72be442bbe7ee3d97 (patch) | |
| tree | 9235fe315e5a8d885abfd64cd8c356757de4508c | |
| parent | 5867bb8f12f3841a06eed3cd253365be0728c0af (diff) | |
Adds compilation options, renames preprocessor macros to avoid collisions.
| -rw-r--r-- | CMakeLists.txt | 62 | ||||
| -rw-r--r-- | src/axis.c | 34 | ||||
| -rw-r--r-- | src/config.c | 20 | ||||
| -rw-r--r-- | src/error.h | 113 | ||||
| -rw-r--r-- | src/input.c | 12 | ||||
| -rw-r--r-- | src/main.c | 8 | ||||
| -rw-r--r-- | src/pervasive.h | 8 | ||||
| -rw-r--r-- | src/relabsd_device.c | 6 |
8 files changed, 164 insertions, 99 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c788ce..3d274bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,20 +4,72 @@ project("relabsd") include(FindPkgConfig) -add_subdirectory(src) - # ${SRC_FILES} is recursively defined in the subdirectories. -# Each subdirectory only adds the source files that are present at its level. - +# Each subdirectory adds only the source files that are present at its level. +add_subdirectory(src) add_executable(relabsd ${SRC_FILES}) +# Language parameters. +enable_language(C) +target_compile_features(relabsd PUBLIC c_variadic_macros) + +# We require libevdev. pkg_search_module(LIBEVDEV REQUIRED libevdev) include_directories(${LIBEVDEV_INCLUDE_DIRS}) target_link_libraries(relabsd ${LIBEVDEV_LIBRARIES}) -target_compile_features(relabsd PUBLIC c_variadic_macros) +# Be loud about dubious code. if (CMAKE_COMPILER_IS_GNUCC) message(STATUS "CMake is using GNUCC. Verbose flags are activated.") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic -Wextra") endif (CMAKE_COMPILER_IS_GNUCC) +# Highest debug level is defined here to be able to access it in CMake. +set(RELABSD_HIGHEST_DEBUG_LEVEL 100) +target_compile_definitions( + relabsd + PUBLIC + "-DRELABSD_HIGHEST_DEBUG_LVL=${RELABSD_HIGHEST_DEBUG_LEVEL}" +) +message( + STATUS + "[CONST] Highest debug level set to ${RELABSD_HIGHEST_DEBUG_LEVEL}." +) + +set( + RELABSD_DEBUG_LEVEL + "0" + CACHE + INTEGER + "Debug verbosity level[0-${RELABSD_HIGHEST_DEBUG_LEVEL}]." +) +target_compile_definitions( + relabsd + PUBLIC + "-DRELABSD_DEBUG_LVL=${RELABSD_DEBUG_LEVEL}" +) +message(STATUS "[OPTION] Debug level set to ${RELABSD_DEBUG_LEVEL}.") + +option( + RELABSD_ENABLE_ERROR_LOCATION + "Debug/error messages contain source file and line information." + OFF +) +if (RELABSD_ENABLE_ERROR_LOCATION) + target_compile_definitions(relabsd PUBLIC RELABSD_ENABLE_ERROR_LOCATION) + message(STATUS "[OPTION] Debug/error messages display source file and line.") +else () + message( + STATUS + "[OPTION] Debug/error messages do not display source file and line." + ) +endif (RELABSD_ENABLE_ERROR_LOCATION) + + +option(RELABSD_REAL_FUZZ "Fuzz is relative to the real device's events." ON) +if (RELABSD_REAL_FUZZ) + target_compile_definitions(relabsd PUBLIC RELABSD_REAL_FUZZ) + message(STATUS "[OPTION] Fuzz is relative to the real device's events.") +else () + message(STATUS "[OPTION] Fuzz is relative to the emulated device's events.") +endif (RELABSD_REAL_FUZZ) @@ -6,41 +6,41 @@ #include "error.h" /* - * Implementation note: _IS_PREFIX, as its name implies, is checking for a + * Implementation note: RELABSD_IS_PREFIX, as its name implies, is checking for a * prefix, not an equal value. This could cause issues if there were axes * with name prefixed by another axis name. */ enum relabsd_axis relabsd_axis_from_name (const char * const name) { - if (_IS_PREFIX("X", name)) + if (RELABSD_IS_PREFIX("X", name)) { return RELABSD_X; } - else if (_IS_PREFIX("Y", name)) + else if (RELABSD_IS_PREFIX("Y", name)) { return RELABSD_Y; } - else if (_IS_PREFIX("Z", name)) + else if (RELABSD_IS_PREFIX("Z", name)) { return RELABSD_Z; } - else if (_IS_PREFIX("RX", name)) + else if (RELABSD_IS_PREFIX("RX", name)) { return RELABSD_RX; } - else if (_IS_PREFIX("RY", name)) + else if (RELABSD_IS_PREFIX("RY", name)) { return RELABSD_RY; } - else if (_IS_PREFIX("RZ", name)) + else if (RELABSD_IS_PREFIX("RZ", name)) { return RELABSD_RZ; } - else if (_IS_PREFIX("WL", name)) + else if (RELABSD_IS_PREFIX("WL", name)) { return RELABSD_WHEEL; } - else if (_IS_PREFIX("MC", name)) + else if (RELABSD_IS_PREFIX("MC", name)) { return RELABSD_MISC; } @@ -83,7 +83,7 @@ char * relabsd_axis_to_name (enum relabsd_axis const e) break; } - _S_PROG_ERROR("relabsd_axis_to_name is missing at least 1 case."); + RELABSD_S_PROG_ERROR("relabsd_axis_to_name is missing at least 1 case."); return ".."; } @@ -162,14 +162,17 @@ unsigned int relabsd_axis_to_rel (enum relabsd_axis const e) return REL_MISC; case RELABSD_UNKNOWN: - _S_PROG_ERROR("relabsd_axis_to_rel(RELABSD_UNKNOWN) is forbidden."); + RELABSD_S_PROG_ERROR + ( + "relabsd_axis_to_rel(RELABSD_UNKNOWN) is forbidden." + ); return REL_MAX; default: break; } - _S_PROG_ERROR("relabsd_axis_to_rel is missing at least 1 case."); + RELABSD_S_PROG_ERROR("relabsd_axis_to_rel is missing at least 1 case."); return REL_MAX; } @@ -203,14 +206,17 @@ unsigned int relabsd_axis_to_abs (enum relabsd_axis const e) return ABS_MISC; case RELABSD_UNKNOWN: - _S_PROG_ERROR("relabsd_axis_to_abs(RELABSD_UNKNOWN) is forbidden."); + RELABSD_S_PROG_ERROR + ( + "relabsd_axis_to_abs(RELABSD_UNKNOWN) is forbidden." + ); return ABS_MAX; default: break; } - _S_PROG_ERROR("relabsd_axis_to_rel is missing at least 1 case."); + RELABSD_S_PROG_ERROR("relabsd_axis_to_abs is missing at least 1 case."); return REL_MAX; } diff --git a/src/config.c b/src/config.c index e84737a..59974b5 100644 --- a/src/config.c +++ b/src/config.c @@ -1,5 +1,6 @@ #include <errno.h> #include <string.h> +#include <stdio.h> #include <stdlib.h> #include "error.h" @@ -73,7 +74,7 @@ static int parse_axis_configuration_line if (axis == RELABSD_UNKNOWN) { - _FATAL + RELABSD_FATAL ( "[CONFIG] Unknown axis '%s'.", buffer @@ -101,7 +102,7 @@ static int parse_axis_configuration_line { if (errno == 0) { - _FATAL + RELABSD_FATAL ( "[CONFIG] Unexpected end of file while reading axis '%s'.", buffer @@ -109,7 +110,7 @@ static int parse_axis_configuration_line } else { - _FATAL + RELABSD_FATAL ( "[CONFIG] An error occured while reading axis '%s': %s.", buffer, @@ -123,7 +124,7 @@ static int parse_axis_configuration_line } else if (valc < 5) { - _FATAL + RELABSD_FATAL ( "[CONFIG] Invalid parameter count for axis '%s'.", buffer @@ -154,7 +155,7 @@ static int read_config_line const char * const prefix ) { - if (!_IS_PREFIX("#", prefix)) + if (!RELABSD_IS_PREFIX("#", prefix)) { if (parse_axis_configuration_line(conf, f, prefix) < 0) { @@ -186,7 +187,7 @@ static int read_config_file if (f == (FILE *) NULL) { - _FATAL + RELABSD_FATAL ( "[CONFIG] Could not open file: %s.", strerror(errno) @@ -225,8 +226,7 @@ static int read_config_file if (errno != 0) { /* An error happened in the while loop condition. */ - - _FATAL + RELABSD_FATAL ( "[CONFIG] Error while reading file: %s, last read '%s'.", strerror(errno), @@ -259,7 +259,7 @@ static int check_usage { if ((argc < 3) || (argc > 4)) { - _FATAL + RELABSD_FATAL ( "Usage: %s input_device config_file [<relabsd_device_name>]", argv[0] @@ -328,7 +328,9 @@ int relabsd_config_filter if (abs(*value - conf->axis[axis].previous_value) <= conf->axis[axis].fuzz) { +#ifdef RELABSD_REAL_FUZZ conf->axis[axis].previous_value = *value; +#endif return -1; } diff --git a/src/error.h b/src/error.h index c3f67b6..4aec255 100644 --- a/src/error.h +++ b/src/error.h @@ -6,117 +6,122 @@ #include "config.h" #include "pervasive.h" -#define _HIGHEST_DEBUG_LVL 100 -#define _DEBUG_LVL 0 /*_HIGHEST_DEBUG_LVL*/ -#define _ENABLE_WARNINGS_OUTPUT 1 -#define _ENABLE_RUNTIME_ERRORS_OUTPUT 1 -#define _ENABLE_PROGRAMMING_ERRORS_OUTPUT 1 -#define _ENABLE_FATAL_ERROR_OUTPUT 1 -#define _ENABLE_ERROR_LOCATION 0 +#ifndef RELABSD_HIGHEST_DEBUG_LVL + #define RELABSD_HIGHEST_DEBUG_LVL 100 +#endif + +#ifndef RELABSD_DEBUG_LEVEL + #define RELABSD_DEBUG_LVL 0 +#endif + +#define RELABSD_ENABLE_WARNINGS_OUTPUT 1 +#define RELABSD_ENABLE_RUNTIME_ERRORS_OUTPUT 1 +#define RELABSD_ENABLE_PROGRAMMING_ERRORS_OUTPUT 1 +#define RELABSD_ENABLE_FATAL_ERROR_OUTPUT 1 -#if _ENABLE_ERROR_LOCATION - #define _LOCATION "[" __FILE__ "][" _TO_STRING(__LINE__) "]" +#ifdef RELABSD_ENABLE_ERROR_LOCATION + #define RELABSD_LOCATION "[" __FILE__ "][" RELABSD_TO_STRING(__LINE__) "]" #else - #define _LOCATION "" + #define RELABSD_LOCATION "" #endif -#define _PRINT_STDERR(symbol, str, ...)\ - fprintf(stderr, "[" symbol "]" _LOCATION " " str "\n", __VA_ARGS__); +#define RELABSD_PRINT_STDERR(symbol, str, ...)\ + fprintf(stderr, "[" symbol "]" RELABSD_LOCATION " " str "\n", __VA_ARGS__); -#define _DEBUG(level, str, ...)\ - _ISOLATE\ +#define RELABSD_DEBUG(level, str, ...)\ + RELABSD_ISOLATE\ (\ - if (level < _DEBUG_LVL)\ + if (level < RELABSD_DEBUG_LVL)\ {\ - _PRINT_STDERR("D", str, __VA_ARGS__);\ + RELABSD_PRINT_STDERR("D", str, __VA_ARGS__);\ }\ ) -#define _WARNING(str, ...)\ - _ISOLATE\ +#define RELABSD_WARNING(str, ...)\ + RELABSD_ISOLATE\ (\ - if (_ENABLE_WARNINGS_OUTPUT)\ + if (RELABSD_ENABLE_WARNINGS_OUTPUT)\ {\ - _PRINT_STDERR("W", str, __VA_ARGS__);\ + RELABSD_PRINT_STDERR("W", str, __VA_ARGS__);\ }\ ) -#define _ERROR(str, ...)\ - _ISOLATE\ +#define RELABSD_ERROR(str, ...)\ + RELABSD_ISOLATE\ (\ - if (_ENABLE_RUNTIME_ERRORS_OUTPUT)\ + if (RELABSD_ENABLE_RUNTIME_ERRORS_OUTPUT)\ {\ - _PRINT_STDERR("E", str, __VA_ARGS__);\ + RELABSD_PRINT_STDERR("E", str, __VA_ARGS__);\ }\ ) -#define _PROG_ERROR(str, ...)\ - _ISOLATE\ +#define RELABSD_PROG_ERROR(str, ...)\ + RELABSD_ISOLATE\ (\ - if (_ENABLE_PROGRAMMING_ERRORS_OUTPUT)\ + if (RELABSD_ENABLE_PROGRAMMING_ERRORS_OUTPUT)\ {\ - _PRINT_STDERR("P", str, __VA_ARGS__);\ + RELABSD_PRINT_STDERR("P", str, __VA_ARGS__);\ }\ ) -#define _FATAL(str, ...)\ - _ISOLATE\ +#define RELABSD_FATAL(str, ...)\ + RELABSD_ISOLATE\ (\ - if (_ENABLE_FATAL_ERROR_OUTPUT)\ + if (RELABSD_ENABLE_FATAL_ERROR_OUTPUT)\ {\ - _PRINT_STDERR("F", str, __VA_ARGS__);\ + RELABSD_PRINT_STDERR("F", str, __VA_ARGS__);\ }\ ) /* For outputs without dynamic content (static). ******************************/ -#define _PRINT_S_STDERR(symbol, str)\ - fprintf(stderr, "[" symbol "]" _LOCATION " " str "\n"); +#define RELABSD_PRINT_S_STDERR(symbol, str)\ + fprintf(stderr, "[" symbol "]" RELABSD_LOCATION " " str "\n"); -#define _S_DEBUG(level, str)\ - _ISOLATE\ +#define RELABSD_S_DEBUG(level, str)\ + RELABSD_ISOLATE\ (\ - if (level < _DEBUG_LVL)\ + if (level < RELABSD_DEBUG_LVL)\ {\ - _PRINT_S_STDERR("D", str);\ + RELABSD_PRINT_S_STDERR("D", str);\ }\ ) -#define _S_WARNING(str)\ - _ISOLATE\ +#define RELABSD_S_WARNING(str)\ + RELABSD_ISOLATE\ (\ - if (_ENABLE_WARNINGS_OUTPUT)\ + if (RELABSD_ENABLE_WARNINGS_OUTPUT)\ {\ - _PRINT_S_STDERR("W", str);\ + RELABSD_PRINT_S_STDERR("W", str);\ }\ ) -#define _S_ERROR(str)\ - _ISOLATE\ +#define RELABSD_S_ERROR(str)\ + RELABSD_ISOLATE\ (\ - if (_ENABLE_RUNTIME_ERRORS_OUTPUT)\ + if (RELABSD_ENABLE_RUNTIME_ERRORS_OUTPUT)\ {\ - _PRINT_S_STDERR("E", str);\ + RELABSD_PRINT_S_STDERR("E", str);\ }\ ) -#define _S_PROG_ERROR(str)\ - _ISOLATE\ +#define RELABSD_S_PROG_ERROR(str)\ + RELABSD_ISOLATE\ (\ - if (_ENABLE_PROGRAMMING_ERRORS_OUTPUT)\ + if (RELABSD_ENABLE_PROGRAMMING_ERRORS_OUTPUT)\ {\ - _PRINT_S_STDERR("P", str);\ + RELABSD_PRINT_S_STDERR("P", str);\ }\ ) -#define _S_FATAL(str)\ - _ISOLATE\ +#define RELABSD_S_FATAL(str)\ + RELABSD_ISOLATE\ (\ - if (_ENABLE_FATAL_ERROR_OUTPUT)\ + if (RELABSD_ENABLE_FATAL_ERROR_OUTPUT)\ {\ - _PRINT_S_STDERR("F", str);\ + RELABSD_PRINT_S_STDERR("F", str);\ }\ ) diff --git a/src/input.c b/src/input.c index c91e405..a3b9e15 100644 --- a/src/input.c +++ b/src/input.c @@ -37,7 +37,7 @@ static int check_for_axes if (!libevdev_has_event_code(dev, EV_REL, rel_code)) { - _FATAL + RELABSD_FATAL ( "Input device has no relative %s axis, yet the configuration " "file asks to convert it.", @@ -66,7 +66,7 @@ static int device_is_compatible { if (!libevdev_has_event_type(dev, EV_REL)) { - _S_FATAL("Input device has no relative axis."); + RELABSD_S_FATAL("Input device has no relative axis."); return -1; } @@ -89,7 +89,7 @@ int relabsd_input_open if (input->fd < 0) { - _FATAL + RELABSD_FATAL ( "Could not open device '%s' in read only mode: %s.", conf->input_file, @@ -104,7 +104,7 @@ int relabsd_input_open libevdev_new_from_fd(input->fd, &(input->dev)) < 0 ) { - _FATAL + RELABSD_FATAL ( "libevdev could not open '%s': %s.", conf->input_file, @@ -159,12 +159,12 @@ int relabsd_input_read */ if (rc != LIBEVDEV_READ_STATUS_SUCCESS) { - _WARNING("[INPUT] Could not get next event: %s.", strerror(-rc)); + RELABSD_WARNING("[INPUT] Could not get next event: %s.", strerror(-rc)); return -1; } - _DEBUG + RELABSD_DEBUG ( 90, "[INPUT] Valid event received: {type = %s; code = %s; value = %d}.", @@ -16,7 +16,7 @@ static void interrupt (int unused_mandatory_parameter) { RELABSD_RUN = 0; - _S_WARNING("Interrupted, will exit at the next input device event."); + RELABSD_S_WARNING("Interrupted, will exit at the next input device event."); } static void handle_relative_axis_event @@ -90,7 +90,7 @@ static int set_signal_handlers () { if (signal(SIGINT, interrupt) == SIG_ERR) { - _S_FATAL("Unable to set the SIGINT signal handler."); + RELABSD_S_FATAL("Unable to set the SIGINT signal handler."); return -1; } @@ -124,11 +124,11 @@ int main (int argc, char ** argv) return -4; } - _S_DEBUG(10, "Converting inputs..."); + RELABSD_S_DEBUG(10, "Converting inputs..."); convert_input(&conf, &input, &dev); - _S_DEBUG(10, "Terminating..."); + RELABSD_S_DEBUG(10, "Terminating..."); relabsd_device_destroy(&dev); relabsd_input_close(&input); diff --git a/src/pervasive.h b/src/pervasive.h index ee04b08..0dd67fe 100644 --- a/src/pervasive.h +++ b/src/pervasive.h @@ -3,12 +3,12 @@ #include <string.h> -#define __TO_STRING(x) #x -#define _TO_STRING(x) __TO_STRING(x) +#define RELABSD__TO_STRING(x) #x +#define RELABSD_TO_STRING(x) RELABSD__TO_STRING(x) -#define _ISOLATE(a) do {a} while (0) +#define RELABSD_ISOLATE(a) do {a} while (0) /* strncmp stops at '\0' and strlen does not count '\0'. */ -#define _IS_PREFIX(a, b) (strncmp(a, b, strlen(a)) == 0) +#define RELABSD_IS_PREFIX(a, b) (strncmp(a, b, strlen(a)) == 0) #endif diff --git a/src/relabsd_device.c b/src/relabsd_device.c index 174f1eb..0ca6993 100644 --- a/src/relabsd_device.c +++ b/src/relabsd_device.c @@ -61,7 +61,7 @@ int relabsd_device_create if (fd < 0) { - _FATAL + RELABSD_FATAL ( "Could not open device '%s' in read only mode: %s.", config->input_file, @@ -73,7 +73,7 @@ int relabsd_device_create if (libevdev_new_from_fd(fd, &(dev->dev)) < 0) { - _FATAL + RELABSD_FATAL ( "libevdev could not open '%s': '%s'.", config->input_file, @@ -103,7 +103,7 @@ int relabsd_device_create < 0 ) { - _FATAL("Could not create relabsd device: %s.", strerror(errno)); + RELABSD_FATAL("Could not create relabsd device: %s.", strerror(errno)); libevdev_free(dev->dev); |


