Small tweaks to files
This commit is contained in:
parent
0e53f180ad
commit
d49e86faff
3 changed files with 20 additions and 15 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
27
src/main.c
27
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) ){
|
||||
printf("Creating DB");
|
||||
db_create(database);
|
||||
if (path_exists( config->userConfig ) ){
|
||||
printf("User config file exists but still needs to be parsed\n");
|
||||
}
|
||||
|
||||
proxy_startListener(port);
|
||||
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(config->database);
|
||||
}
|
||||
|
||||
proxy_startListener(config->port);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue