From 160c3fddd57f54ae77c159ebc77fd41063d49cd6 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 23 Jul 2020 15:59:41 +0200 Subject: [PATCH] Change build outputs and paths, use cmake's defaults, change some build definitions, remove unistd dep listing (it isn't used), add option summary, instruct for out of tree builds, fix a assembler bug and add ircv3 test for the msg assembler --- .gitignore | 7 ------- CMakeLists.txt | 7 ++----- README.md | 10 +++++++--- src/assemblers.c | 2 ++ tests/msgassm.c | 15 ++++++++++----- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 8cd5b87..378eac2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1 @@ build -CMakeCache.txt -CMakeFiles -cmake_install.cmake -install_manifest.txt -Makefile -Testing -CTestTestfile.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 158c6c3..58e624e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,11 +7,8 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -Werror -Wformat-ove if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) endif() -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/bin) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/lib) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/archive) -if ( UIRC_IRCV3 ) +if ( IRCV3 ) add_definitions(-DUIRC_IRCV3) endif() if ( BUILD_TESTS ) @@ -24,7 +21,7 @@ set(build_FILES src/tokenizers.c src/validators.c ) -if ( USE_HELPERS ) +if ( BUILD_HELPERS ) message("Helper functions are going to be built.") set(build_FILES ${build_FILES} src/helpers.c) endif() diff --git a/README.md b/README.md index a5f4c22..bb97677 100644 --- a/README.md +++ b/README.md @@ -3,21 +3,25 @@ ## Requirements - CMake (tested on 3.17) -- Standard UNIX library - C99+ compiler ## Building First, create the required build files (usually the Makefile) ```sh -cmake . -DUSE_HELPERS=1 -DCMAKE_BUILD_TYPE=Release -DUIRC_IRCV3=1 +cmake -H. -Bbuild/ -DBUILD_HELPERS=1 -DCMAKE_BUILD_TYPE=Release -DIRCV3=1 ``` -Note: You can omit USE_HELPERS or/and UIRC_IRCV3 if you do not plan to use those features. +| Option | Description | Type | Supported since | +|:-------------:|:---------------------------------------------------------------------:|:--------:|:---------------:| +| BUILD_HELPERS | Build simple assemblers and tokenizers that handle the heavy lifting | boolean | - | +| BUILD_TESTS | Build tests that check if the build results behave as they should | boolean | - | +| IRCV3 | Build IRCv3 support (WIP) | boolean | - | Following that, just use your build system and compile it Example for **make**: ```sh +cd build/ make ``` diff --git a/src/assemblers.c b/src/assemblers.c index 54540c9..ca9fa7a 100644 --- a/src/assemblers.c +++ b/src/assemblers.c @@ -29,6 +29,8 @@ signed int Assm_mesg(char* buf, IRC_Message* in, size_t len) pos += ret; else return ret; + if (!safe_charcpy(&pos, ' ', len - (pos - buf))) + return ERR_UIRC_BUFFER_ERR; #endif if (in->name.nick != NULL || in->name.host != NULL) { if (!safe_charcpy(&pos, ':', len - (pos - buf))) diff --git a/tests/msgassm.c b/tests/msgassm.c index 52627e5..920a1e2 100644 --- a/tests/msgassm.c +++ b/tests/msgassm.c @@ -7,10 +7,11 @@ int main(void) { char mesg[513] = {0}; IRC_Message input = { - .name = { - .nick = "dad", - .user = "dad-door", - .host = "home.localhost"}, +#ifdef UIRC_IRCV3 + .tags = { + .msgid = {.value = "10"}}, +#endif + .name = {.nick = "dad", .user = "dad-door", .host = "home.localhost"}, .cmd = PRIVMSG, .args = {"(You)"}, .trailing = "are ya winning son?", @@ -20,7 +21,11 @@ int main(void) printf("Failed to assemble message. (%i)\n", res); return EXIT_FAILURE; } - char* expect = ":dad!dad-door@home.localhost PRIVMSG (You) :are ya winning son?\r\n"; + char* expect = +#ifdef UIRC_IRCV3 + "@msgid=10 " +#endif + ":dad!dad-door@home.localhost PRIVMSG (You) :are ya winning son?\r\n"; if (strcmp(expect, mesg)) { printf("Assembled message mismatch.\nGot:\n%s\nbut expected:\n%s\n", mesg, expect); return EXIT_FAILURE;