From e95d1c2aa7447cd99700120716820f89ec88dbe4 Mon Sep 17 00:00:00 2001 From: louie Date: Wed, 8 Jul 2020 16:11:59 -0700 Subject: Added ability to specify config location; polished read_cfg error output --- draw.c | 8 ++++++-- read_cfg.c | 29 +++++++++++++++++------------ read_cfg.o | Bin 8408 -> 8624 bytes 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/draw.c b/draw.c index f059c05..92d5bb4 100644 --- a/draw.c +++ b/draw.c @@ -36,13 +36,17 @@ int e_offset = 0; //TODO consider figuring out where some refreshes are unecessary -int main(){ +int main(int argc, char **argv){ + char *cfg_path = "config"; 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; + //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]; + //Fill Groups - cfg_interp(); //read the contents of the cfg file + cfg_interp(cfg_path); //read the contents of the cfg file g = get_groups(); //retrieve results of previous function g_count = get_gcount(g); //retrieve number of groups in g diff --git a/read_cfg.c b/read_cfg.c index ff213ad..5cd63aa 100644 --- a/read_cfg.c +++ b/read_cfg.c @@ -12,7 +12,7 @@ #define MAX_ARGS 5 //public -void cfg_interp(); +void cfg_interp(char *path); void check_line(char *buffer); int get_compmode(); @@ -31,7 +31,7 @@ int compmode = 0; //set to true to automatically try to create a human readable name for an entry bool hr = false; -void cfg_interp(){ +void cfg_interp(char *path){ FILE *fp; char buffer[BUF_LEN]; GROUP **g; @@ -42,7 +42,7 @@ void cfg_interp(){ int j; //TODO have this check in certain locations for a config file, give error message if "config" does not exist - fp = fopen("config", "r"); + fp = fopen(path, "r"); assert(fp != NULL); //Read each line of "config" @@ -114,7 +114,7 @@ void check_line(char *buffer){ //TODO add potential dash functions //TODO add support for "-R" recursive adding //TODO add sorting functionality - if(!(strcmp(args[0], "add"))) handle_fname(args[1], args[2]); + else if(!(strcmp(args[0], "add"))) handle_fname(args[1], args[2]); //create a new group else if(!(strcmp(args[0], "addGroup"))) group_add(args[1], NULL); @@ -136,17 +136,22 @@ void check_line(char *buffer){ if(!(strcmp(get_gname(g[i]), args[1]))) break; } - //assert that a matching group was found - if(i < g_count){ - //set a group's launcher (this requires pulling down the existing groups and finding the one that args[1] mentions) - if(!(strcmp(args[0], "setLauncher"))) set_gprog(g[i], args[2]); + //set a group's launcher (this requires pulling down the existing groups and finding the one that args[1] mentions) + if(!(strcmp(args[0], "setLauncher"))){ + //assert that a matching group was found + if(i < g_count) set_gprog(g[i], args[2]); + else printf("Error: Group \"%s\" does not exist\n", args[1]); + } - //set a group's launcher flags (like ./program -f file for fullscreen) - if(!(strcmp(args[0], "setFlags"))) set_gflags(g[i], args[2]); + //set a group's launcher flags (like ./program -f file for fullscreen) + else if(!(strcmp(args[0], "setFlags"))){ + //assert that a matching group was found + if(i < g_count) set_gflags(g[i], args[2]); + else printf("Error: Group \"%s\" does not exist\n", args[1]); } - //couldn't find a match - else printf("Error: Group \"%s\" does not exist\n", args[1]); + //args[0] is not a valid config option + else printf("Error: Unknown config option \"%s\"\n", args[0]); } } diff --git a/read_cfg.o b/read_cfg.o index 4c6f502..f91c404 100644 Binary files a/read_cfg.o and b/read_cfg.o differ -- cgit