Compare commits

...

3 Commits

Author SHA1 Message Date
nekobit 119f681fc2 Strip input
FossilOrigin-Name: 5ef214f068ce0ec7a480347850d61d80639689cd8727939713d980108e49a2b1
2023-03-03 19:38:30 +00:00
nekobit 53461b6fc3 Loop
FossilOrigin-Name: 1929800c5a59d2689307cbfa8362cdcb9aeb228eba06da6801fa65ed3d4e71d6
2023-03-03 18:54:08 +00:00
nekobit 7606545a27 Fix function
FossilOrigin-Name: a8910644e6f7612e6793e8be844926f6d87659b2f9b2ac44543b0f5c0851837f
2023-03-03 18:30:07 +00:00
3 changed files with 59 additions and 22 deletions

View File

@ -4,11 +4,18 @@ set(MASTODONT_VERSION 0.1)
# Get parent directory of this config file
find_package(CURL REQUIRED)
find_package(PkgConfig REQUIRED)
# TODO account for built-in cjson lib
pkg_check_modules(MSTDNT_CJSON libcjson)
set(MASTODONT_INCLUDE_DIRS
"${CMAKE_CURRENT_LIST_DIR}/../include"
"${CMAKE_CURRENT_LIST_DIR}/../libs"
../include
../libs
)
set(MASTODONT_LIBRARIES ${CMAKE_CURRENT_LIST_DIR})
set(MASTODONT_LIBRARIES
mastodont
${MSTDNT_CJSON_LIBRARIES}
${CURL_LIBRARIES}
)

View File

@ -1,6 +1,10 @@
include(../cmake/mastodont-config.cmake)
add_executable(get_feed get_feed.c)
target_compile_options(get_feed PUBLIC -std=c99 -Wall)
target_link_libraries(get_feed PUBLIC
${MASTODONT_LIBRARIES}
)
target_include_directories(get_feed PUBLIC
../include
${CURL_INCLUDE_DIRS}
../libs)
${MASTODONT_INCLUDE_DIRS}
)

View File

@ -1,11 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mastodont.h>
char* get_line(char const* prompt, size_t* res_size)
char* get_line(char const* prompt)
{
char* result = NULL;
#define GL_BUF_SIZE 25
size_t _res_size;
#define GL_BUF_SIZE 255
char buffer[GL_BUF_SIZE];
if (prompt)
@ -14,22 +15,36 @@ char* get_line(char const* prompt, size_t* res_size)
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);
}
fgets(buffer, GL_BUF_SIZE, stdin);
int buffer_len = strlen(buffer);
result = realloc(result, buffer_len+1);
memcpy(result, buffer, buffer_len);
result[buffer_len-1] = '\0';
if (res_size)
*res_size = _res_size;
return result;
}
int
main()
tl_callback(mstdnt_request_cb_data* cb_data, void* args)
{
struct mstdnt_statuses* statuses = MSTDNT_CB_DATA(cb_data);
for (int i = 0; i < statuses->len; ++i)
{
struct mstdnt_status* status = statuses->statuses + i;
puts("---------------- BEGIN STATUS ----------------");
printf(" Author: %s", status->account.username);
puts("----------------- END STATUS -----------------");
}
return MSTDNT_REQUEST_DONE;
}
int
main(int argc, char** argv)
{
(void)argc;
(void)argv;
mstdnt_global_curl_init();
mastodont_t data;
@ -37,14 +52,25 @@ main()
if (mstdnt_init(&data) != 0)
{
fputs("Couldn't initialize Mastodont-c!", stderr);
exit(1);
}
char* instance = get_line("Instance: ", NULL);
char* instance = get_line("Instance");
puts(instance);
struct mstdnt_args m_args = {
.url = instance,
.token = NULL,
.flags = 0,
};
mstdnt_timeline_public(&data, &m_args, tl_callback, NULL, (struct mstdnt_timeline_args){});
mstdnt_await(&data, 0, NULL, 0);
// Cleanup
free(instance);
mstdnt_cleanup(&data);
mstdnt_global_curl_cleanup();
return 1;
}