diff options
author | louie <lshprung@yahoo.com> | 2020-07-08 16:11:59 -0700 |
---|---|---|
committer | louie <lshprung@yahoo.com> | 2020-07-08 16:11:59 -0700 |
commit | e95d1c2aa7447cd99700120716820f89ec88dbe4 (patch) | |
tree | 4e016a401f3d3707ed3c5712958d3596e16d64bc | |
parent | 697ba798ab9ac09ba84dbf2285bcb0fb44ea0b36 (diff) |
Added ability to specify config location; polished read_cfg error output
-rw-r--r-- | draw.c | 8 | ||||
-rw-r--r-- | read_cfg.c | 29 | ||||
-rw-r--r-- | read_cfg.o | bin | 8408 -> 8624 bytes |
3 files changed, 23 insertions, 14 deletions
@@ -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 @@ -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]); } } |