Compare commits
3 Commits
d979621621
...
119f681fc2
Author | SHA1 | Date |
---|---|---|
nekobit | 119f681fc2 | |
nekobit | 53461b6fc3 | |
nekobit | 7606545a27 |
|
@ -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}
|
||||
)
|
||||
|
||||
|
|
|
@ -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}
|
||||
)
|
||||
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue