From d49e86faff6b836e46ce8d8387c1b54fc7234cf4 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Mon, 10 Jan 2022 09:41:37 +0000 Subject: [PATCH] Small tweaks to files --- src/config.c | 4 ++-- src/config.h | 4 ++-- src/main.c | 25 +++++++++++++++---------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/config.c b/src/config.c index 866544a..a1a8c79 100644 --- a/src/config.c +++ b/src/config.c @@ -4,7 +4,7 @@ * Checks if the given path exists by calling stat(). * */ -static bool path_exists(const char *path) { +bool path_exists(const char *path) { struct stat buf; return (stat(path, &buf) == 0); } @@ -12,7 +12,7 @@ static bool path_exists(const char *path) { /* * This function resolves ~ in pathnames. */ -static char* resolveTilde(const char *path) { +char* resolveTilde(const char *path) { static glob_t globbuf; static char *ret = NULL; diff --git a/src/config.h b/src/config.h index 0983340..738f617 100644 --- a/src/config.h +++ b/src/config.h @@ -15,8 +15,8 @@ typedef struct { unsigned int port; } Config; -static bool path_exists(const char *path); -static char* resolveTilde(const char *path); +bool path_exists(const char *path); +char* resolveTilde(const char *path); Config* configDefaults(); char* getConfigDir(); char* getDefaultUserConfigLoc(); diff --git a/src/main.c b/src/main.c index 7740c57..5ec5751 100644 --- a/src/main.c +++ b/src/main.c @@ -29,22 +29,19 @@ void printHelp(){ } int main(int argc, char**argv){ - char *database = DEFAULT_DATABASE; - char *config = DEFAULT_CONFIG; - unsigned int port = DEFAULT_PORT; - - Config *defaultconfig = configDefaults(); + Config *config = configDefaults(); for ( unsigned int i = 1; i < argc; i++ ){ if ( strcmp( argv[i], "--config" ) == 0 ){ if ( i + 2 < argc ){ - setConfig( defaultconfig, argv[i + 1], argv[i + 2] ); + setConfig( config, argv[i + 1], argv[i + 2] ); + i += 2; } else { printf("--config requires 2 positional arguments\n"); } } else if ( strcmp( argv[i], "--print-config" ) == 0 ){ - printConfig(defaultconfig); + printConfig(config); return 0; } else if ( strcmp( argv[i], "--help" ) == 0 ){ printHelp(); @@ -54,12 +51,20 @@ int main(int argc, char**argv){ } } - if ( !db_file_exists(database) ){ + if (path_exists( config->userConfig ) ){ + printf("User config file exists but still needs to be parsed\n"); + } + + if (path_exists( config->localConfig ) ){ + printf("Local config file exists but still needs to be parsed\n"); + } + + if ( !db_file_exists(config->database) ){ printf("Creating DB"); - db_create(database); + db_create(config->database); } - proxy_startListener(port); + proxy_startListener(config->port); return 0; }