diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..4a008c4 --- /dev/null +++ b/.clang-format @@ -0,0 +1,10 @@ +BasedOnStyle: LLVM +UseTab: Always +TabWidth: 4 +IndentWidth: 4 +IndentCaseLabels: true +ColumnLimit: 120 +PointerAlignment: Right +AllowShortFunctionsOnASingleLine: None +InsertBraces: true +AllowShortBlocksOnASingleLine: Empty diff --git a/include/discord.h b/include/discord.h new file mode 100644 index 0000000..36154d8 --- /dev/null +++ b/include/discord.h @@ -0,0 +1,9 @@ +#ifndef DISCORD_DISCORD_H +#define DISCORD_DISCORD_H + +#define DISCORD_BASE_URL "https://discord.com/api" +#define DISCORD_API_VERSION "10" + +typedef struct discord_client discord_client; + +#endif diff --git a/include/error.h b/include/error.h new file mode 100644 index 0000000..f4d50c6 --- /dev/null +++ b/include/error.h @@ -0,0 +1,18 @@ +#ifndef DISCORD_ERROR_H +#define DISCORD_ERROR_H + +typedef enum discord_error { + DISCORD_OK, + DISCORD_ERR, + DISCORD_AUTH_ERR, +} discord_error; + +/** + * @brief Retrieves error string. + * + * @param err Discord error. + * @return String of the error. + */ +const char *discord_err_str(discord_error err); + +#endif diff --git a/include/meson.build b/include/meson.build new file mode 100644 index 0000000..e69de29 diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..a7bcdea --- /dev/null +++ b/meson.build @@ -0,0 +1,43 @@ +project( + 'discord-c', + 'c', + version: '0.1', + default_options: ['warning_level=3', 'c_std=c17'], +) + +sources = [] +headers = [] +include_directories('src') +include_directories('include') +incdir = include_directories('include') + +libcurl = dependency('libcurl', required: true) +libyyjson = dependency('yyjson', required: true) + +deps = [libcurl, libyyjson] + +libdiscord = static_library( + 'discord', + sources, + dependencies: deps, + install: true, + include_directories: incdir, +) +install_headers(headers, install_dir: 'discord-c') + +# Test executable +exesrc = files('test/test1.c') +executable( + 'dstest', + exesrc, + build_by_default: false, + link_with: libdiscord, + include_directories: incdir, +) + +# Commands +clangformat = find_program('clang-format', required: false) +if clangformat.found() + all_files = sources + headers + exesrc + run_target('format', command: [clangformat, '-i'] + all_files) +endif diff --git a/src/discord.c b/src/discord.c new file mode 100644 index 0000000..d2bef58 --- /dev/null +++ b/src/discord.c @@ -0,0 +1,6 @@ +#include "discord.h" + +typedef struct discord_client { + char *token_type; + char *token_value; +} discord_client; diff --git a/src/error.c b/src/error.c new file mode 100644 index 0000000..6b81fbd --- /dev/null +++ b/src/error.c @@ -0,0 +1,26 @@ +#include "error.h" + +#include + +#define ARR_SIZE(X) (sizeof(X) / sizeof(*X)) + +typedef struct discord_err { + discord_error error; + const char *text; +} discord_err; + +static discord_err errors[] = { + {DISCORD_OK, "OK"}, + {DISCORD_ERR, "ERR"}, + {DISCORD_AUTH_ERR, "Authentication error, maybe wrong token"}, +}; + +const char *discord_err_str(discord_error err) { + for (size_t i = 0; i < ARR_SIZE(errors); ++i) { + if (errors[i].error == err) { + return errors[i].text; + } + } + + return NULL; +} diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..b298885 --- /dev/null +++ b/src/meson.build @@ -0,0 +1 @@ +sources += files('main.c') diff --git a/test/test1.c b/test/test1.c new file mode 100644 index 0000000..304799a --- /dev/null +++ b/test/test1.c @@ -0,0 +1,7 @@ +#include + +int main(void) { + puts("discord.c"); + + return 0; +}