diff options
-rw-r--r-- | draw.c | 3 | ||||
-rw-r--r-- | read_cfg.c | 26 | ||||
-rw-r--r-- | read_cfg.h | 2 | ||||
-rw-r--r-- | read_cfg.o | bin | 11464 -> 12448 bytes |
4 files changed, 29 insertions, 2 deletions
@@ -48,7 +48,7 @@ int e_offset = 0; //TODO consider figuring out where some refreshes are unecessary int main(int argc, char **argv){ - char *cfg_path = "config"; + char *cfg_path; bool tall = true; //is the window a certain height (tbd what the threshold should be TODO) bool wide = true; //is the window a certain width (tbd what the threshold should be TODO) int input; @@ -56,6 +56,7 @@ int main(int argc, char **argv){ //if a config path was given as an argument, set it accordingly if(argc > 2 && (!strcmp(argv[1], "-c") || !strcmp(argv[1], "--cfg_path"))) cfg_path = argv[2]; + else cfg_path = find_config(); //Fill Groups cfg_interp(cfg_path); //read the contents of the cfg file @@ -13,6 +13,7 @@ #define OPTION_CNT 10 //public +char *find_config(); void cfg_interp(char *path); int get_compmode(); @@ -42,6 +43,29 @@ char sep = '\\'; char sep = '/'; #endif +char *find_config(){ + char *home = getenv("HOME"); + char *path = malloc(sizeof(char) * BUF_LEN); + char choices[2][BUF_LEN]; + int check_count = 2; + int i; + + sprintf(choices[0], "%s%c.config%ctml%cconfig", home, sep, sep, sep); + sprintf(choices[1], "%s%c.tml%cconfig", home, sep, sep); + + //TODO where do we want the Windows config to be? + + for(i = 0; i < check_count; i++){ + path = choices[i]; + if(access(path, R_OK) == 0){ + printf("Using config \"%s\"\n", path); + return path; + } + } + + return "config"; +} + void cfg_interp(char *path){ FILE *fp; char buffer[BUF_LEN]; @@ -146,7 +170,7 @@ void check_line(char *buffer, char **options){ break; case '\\': - if(*(tok_p+1) == '"') tok_p++; + tok_p++; default: *arg_p = *tok_p; @@ -1,6 +1,8 @@ #ifndef READ_CFG_H #define READ_CFG_H +char *find_config(); + void cfg_interp(); int get_compmode(); Binary files differ |