Small tweaks to files

master
Jonathan Hodgson 3 years ago
parent 0e53f180ad
commit d49e86faff
  1. 4
      src/config.c
  2. 4
      src/config.h
  3. 25
      src/main.c

@ -4,7 +4,7 @@
* Checks if the given path exists by calling stat(). * 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; struct stat buf;
return (stat(path, &buf) == 0); return (stat(path, &buf) == 0);
} }
@ -12,7 +12,7 @@ static bool path_exists(const char *path) {
/* /*
* This function resolves ~ in pathnames. * This function resolves ~ in pathnames.
*/ */
static char* resolveTilde(const char *path) { char* resolveTilde(const char *path) {
static glob_t globbuf; static glob_t globbuf;
static char *ret = NULL; static char *ret = NULL;

@ -15,8 +15,8 @@ typedef struct {
unsigned int port; unsigned int port;
} Config; } Config;
static bool path_exists(const char *path); bool path_exists(const char *path);
static char* resolveTilde(const char *path); char* resolveTilde(const char *path);
Config* configDefaults(); Config* configDefaults();
char* getConfigDir(); char* getConfigDir();
char* getDefaultUserConfigLoc(); char* getDefaultUserConfigLoc();

@ -29,22 +29,19 @@ void printHelp(){
} }
int main(int argc, char**argv){ int main(int argc, char**argv){
char *database = DEFAULT_DATABASE; Config *config = configDefaults();
char *config = DEFAULT_CONFIG;
unsigned int port = DEFAULT_PORT;
Config *defaultconfig = configDefaults();
for ( unsigned int i = 1; i < argc; i++ ){ for ( unsigned int i = 1; i < argc; i++ ){
if ( strcmp( argv[i], "--config" ) == 0 ){ if ( strcmp( argv[i], "--config" ) == 0 ){
if ( i + 2 < argc ){ if ( i + 2 < argc ){
setConfig( defaultconfig, argv[i + 1], argv[i + 2] ); setConfig( config, argv[i + 1], argv[i + 2] );
i += 2;
} else { } else {
printf("--config requires 2 positional arguments\n"); printf("--config requires 2 positional arguments\n");
} }
} else if ( strcmp( argv[i], "--print-config" ) == 0 ){ } else if ( strcmp( argv[i], "--print-config" ) == 0 ){
printConfig(defaultconfig); printConfig(config);
return 0; return 0;
} else if ( strcmp( argv[i], "--help" ) == 0 ){ } else if ( strcmp( argv[i], "--help" ) == 0 ){
printHelp(); 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"); printf("Creating DB");
db_create(database); db_create(config->database);
} }
proxy_startListener(port); proxy_startListener(config->port);
return 0; return 0;
} }

Loading…
Cancel
Save