diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 31 |
1 files changed, 30 insertions, 1 deletions
@@ -1,10 +1,12 @@ #include <GL/glew.h> #include <GLFW/glfw3.h> #include <curl/curl.h> +#include <limits.h> #include <locale.h> #include <stdio.h> #include <stdlib.h> +#include "toml.h" #define MAX_VERTEX_BUFFER 512 * 1024 #define MAX_ELEMENT_BUFFER 128 * 1024 #define NK_INCLUDE_FIXED_TYPES @@ -29,6 +31,7 @@ #include "unifont.h" extern int win_width, win_height; +static char *cookie; extern void load_ui(struct ui_struct *); static void error_callback(int e, const char *d) { printf("Error %d: %s\n", e, d); @@ -40,8 +43,34 @@ int main(void) { /* Set locale*/ setlocale(LC_ALL, ".UTF-8"); + /* Parse config */ + // NOTICE: string parsed from toml should always be freed afterwards!!! + { + FILE *fp; + const char *config_file = "config.toml"; + char errbuf[UCHAR_MAX]; + + fp = fopen(config_file, "r"); + if (!fp) { + fprintf(stderr, "[tomlc99] Cannot open %s, applying default config...\n", + config_file); + } else { + toml_table_t *conf = toml_parse_file(fp, errbuf, sizeof(errbuf)); + fclose(fp); + + if (!conf) { + fprintf(stderr, "[tomlc99] Cannot parse %s\n", config_file); + } + toml_datum_t cookie_datum = toml_string_in(conf, "cookie"); + if (cookie_datum.ok) { + printf("[tomlc99] Found cookie string in config.toml, applying...\n"); + cookie = cookie_datum.u.s; + } + } + } + /* Curl */ - curl_init(); + curl_init(cookie); /* GLFW */ struct nk_glfw glfw = {0}; |