summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouie <lshprung@yahoo.com>2020-07-30 10:15:20 -0700
committerlouie <lshprung@yahoo.com>2020-07-30 10:15:20 -0700
commit2ee23565a15bd969828db7442f2f8b4902d5e261 (patch)
treedb9e8e51d3eddedc05a4f5c108b2f2b055a8deeb
parent5efd6914fbc8101127bed8feda8b02ccb554b79a (diff)
Added standard location(s) for config files
-rw-r--r--draw.c3
-rw-r--r--read_cfg.c26
-rw-r--r--read_cfg.h2
-rw-r--r--read_cfg.obin11464 -> 12448 bytes
4 files changed, 29 insertions, 2 deletions
diff --git a/draw.c b/draw.c
index d588b98..a7acdf1 100644
--- a/draw.c
+++ b/draw.c
@@ -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
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;
diff --git a/read_cfg.h b/read_cfg.h
index 36ed056..4c32bb2 100644
--- a/read_cfg.h
+++ b/read_cfg.h
@@ -1,6 +1,8 @@
#ifndef READ_CFG_H
#define READ_CFG_H
+char *find_config();
+
void cfg_interp();
int get_compmode();
diff --git a/read_cfg.o b/read_cfg.o
index 34660e3..55e23a5 100644
--- a/read_cfg.o
+++ b/read_cfg.o
Binary files differ