From 2ee23565a15bd969828db7442f2f8b4902d5e261 Mon Sep 17 00:00:00 2001 From: louie Date: Thu, 30 Jul 2020 10:15:20 -0700 Subject: Added standard location(s) for config files --- read_cfg.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'read_cfg.c') diff --git a/read_cfg.c b/read_cfg.c index 9029d0b..bfe118a 100644 --- a/read_cfg.c +++ b/read_cfg.c @@ -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; -- cgit