aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 191a159..b3e7af4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3,10 +3,12 @@
#include "font.h"
#include "media.h"
#include "render.h"
+#include "util.h"
#include <GLFW/glfw3.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#define WINDOW_WIDTH 1000
@@ -24,6 +26,9 @@ static void print_usage(const char *argv0) {
fprintf(stderr, "env:\n");
fprintf(stderr, " ECEX_FONT=/path/to/font.ttf\n");
fprintf(stderr, " ECEX_INCLUDE=/path/to/ecex/include\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "default config:\n");
+ fprintf(stderr, " ~/.config/ecex/ecexrc.c\n");
}
static int parse_args(int argc,
@@ -66,6 +71,24 @@ static const char *select_font_path(ecex_t *ed, const char *font_path_arg) {
return font_choose_path(NULL);
}
+static const char *find_default_config_path(void) {
+ static char path[4096];
+
+ const char *xdg_config = getenv("XDG_CONFIG_HOME");
+ if (xdg_config && xdg_config[0]) {
+ snprintf(path, sizeof(path), "%s/ecex/ecexrc.c", xdg_config);
+ if (ecex_file_exists(path)) return path;
+ }
+
+ const char *home = getenv("HOME");
+ if (home && home[0]) {
+ snprintf(path, sizeof(path), "%s/.config/ecex/ecexrc.c", home);
+ if (ecex_file_exists(path)) return path;
+ }
+
+ return NULL;
+}
+
int main(int argc, char **argv) {
const char *config_path = NULL;
const char *font_path_arg = NULL;
@@ -81,6 +104,10 @@ int main(int argc, char **argv) {
return 1;
}
+ if (!config_path) {
+ config_path = find_default_config_path();
+ }
+
if (config_path) {
if (ecex_load_c_config(ed, config_path) != 0) {
fprintf(stderr, "ecex: continuing without config\n");