diff --git a/CMakeLists.txt b/CMakeLists.txt index 28cffa6..4655617 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,9 @@ find_package(CURL REQUIRED) # Find the real cJSON pkg_check_modules(CJSON libcjson) +# Includes test programs... unit tests +add_subdirectory(tests) + if (NOT (CJSON_FOUND AND CJSON_VERSION VERSION_GREATER_EQUAL 1.7.14)) # This was a workaround to some distributions providing an older cJSON message("CJSON not found or CJSON_VERSION < 1.7.14, falling back to header-only.") @@ -96,9 +99,11 @@ target_compile_options(mastodont PUBLIC -Wall -Wextra -std=c99 -Wshadow -Wcast-align -Wstrict-prototypes ) + target_link_options(mastodont PUBLIC ${CURL_LDFLAGS_OTHER} ) + target_include_directories(mastodont PUBLIC include/ ${CURL_INCLUDE_DIRS} diff --git a/README.md b/README.md new file mode 100644 index 0000000..d7b86b3 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Mastodont-c + +Mastodont-c is a C library to access the Mastodon API and it's variants +(Pleroma, Akkoma, Soapbox). + +It was written in C due to it's portability. It's designed to be used in +Treebird, but it can be used in other programs as well. + +# Documentation + +Documentation is essentially non-existant, but this will improve over time. \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..5b1215d --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(get_feed get_feed.c) +target_compile_options(get_feed PUBLIC -std=c99 -Wall) +target_include_directories(get_feed PUBLIC + ../include + ${CURL_INCLUDE_DIRS} + ../libs) \ No newline at end of file diff --git a/tests/Makefile b/tests/Makefile deleted file mode 100644 index e69de29..0000000 diff --git a/tests/get_feed.c b/tests/get_feed.c new file mode 100644 index 0000000..bf24df0 --- /dev/null +++ b/tests/get_feed.c @@ -0,0 +1,50 @@ +#include +#include + +char* get_line(char const* prompt, size_t* res_size) +{ + char* result = NULL; +#define GL_BUF_SIZE 25 + size_t _res_size; + char buffer[GL_BUF_SIZE]; + + if (prompt) + { + fputs(prompt, stdout); + fputs(": ", stdout); + } + + while (fgets(buffer, GL_BUF_SIZE, stdin) != NULL) + { + _res_size += GL_BUF_SIZE; + result = realloc(result, _res_size); + memcpy(result, buffer, GL_BUF_SIZE); + } + + if (res_size) + *res_size = _res_size; + + return result; +} + +int +main() +{ + mstdnt_global_curl_init(); + + mastodont_t data; + + if (mstdnt_init(&data) != 0) + { + fputs("Couldn't initialize Mastodont-c!", stderr); + } + + char* instance = get_line("Instance: ", NULL); + + puts(instance); + + free(instance); + + mstdnt_cleanup(&data); + mstdnt_global_curl_cleanup(); +} \ No newline at end of file