diff options
-rw-r--r-- | docs/README.md | 2 | ||||
-rw-r--r-- | docs/tml-config.md | 8 | ||||
-rw-r--r-- | entry.c | 18 | ||||
-rw-r--r-- | entry.h | 4 | ||||
-rw-r--r-- | entry.o | bin | 4672 -> 5016 bytes | |||
-rw-r--r-- | group.c | 6 | ||||
-rw-r--r-- | group.h | 2 | ||||
-rw-r--r-- | group.o | bin | 7864 -> 8184 bytes | |||
-rw-r--r-- | read_cfg.c | 55 | ||||
-rw-r--r-- | read_cfg.o | bin | 12896 -> 14768 bytes |
10 files changed, 82 insertions, 13 deletions
diff --git a/docs/README.md b/docs/README.md index 14ce9d6..7e01ebd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,6 @@ ## Introduction -**Terminal Media Launcher** is a command line utility to help streamline launching applications and other media. The program looks for a config file listing different groups of media and creates an ncurses menu from which to select from. +**Terminal Media Launcher** is a command line utility to help streamline launching applications and other media. The goal of tml is to provide a fast, minimal, command line frontend with a Unix-like approach to setup and configuration. The program looks for a config file listing different groups of media and creates an ncurses menu from which to select from. ## Compiling and Running diff --git a/docs/tml-config.md b/docs/tml-config.md index 451d47f..f4a1faa 100644 --- a/docs/tml-config.md +++ b/docs/tml-config.md @@ -14,6 +14,7 @@ - [addName](#addName) - [addNameF](#addNameF) - [addR](#addR) + - [hide](#hide) - [Settings](#Settings) - [autoAlias](#autoAlias) - [compMode](#compMode) @@ -76,6 +77,12 @@ tml will hide empty groups, so you will need to know how to add entries to a gro `addR` will recursively add entries to a group. `addR` functions like `add`, but will also search sub-directories for matches. +### hide + +- **hide** *entry* *group* + +`hide` will remove a specified entry from a specified group. The entry argument should refer to the entry's name, rather than the entry's path. This option may be useful to hide certain files after adding entries with the '\*' operator. *At the moment, hide can only hide a single entry*. + ## Settings If any of the following settings are specified, they should be at the top of the config file. @@ -89,6 +96,7 @@ If any of the following settings are specified, they should be at the top of the 1. Removing any characters inside parenthesis (including parenthesis) 2. Replacing '-' and '\_' with a space character 3. Replacing cases of multiple spaces in a row with only one space +4. Removing file extensions (if the file has an extension) `autoAlias` is turned off by default. @@ -14,6 +14,7 @@ typedef struct entry{ char name[BUF_LEN]; char path[BUF_LEN]; bool path_force; + bool hidden; struct entry *next; } ENTRY; @@ -25,6 +26,8 @@ ENTRY **get_entries(ENTRY *head, int count); char *get_ename(ENTRY *e); char *get_epath(ENTRY *e); bool get_eforce(ENTRY *e); +void set_hide(ENTRY *e, bool status); +bool get_hide(ENTRY *e); void entry_debug(ENTRY *trav); ENTRY *create_entry(char *new_name, char *new_path, bool force){ @@ -35,6 +38,7 @@ ENTRY *create_entry(char *new_name, char *new_path, bool force){ strcpy(new->name, new_name); strcpy(new->path, new_path); new->path_force = force; + new->hidden = false; new->next = NULL; return new; @@ -96,10 +100,13 @@ int entry_add(ENTRY *head, ENTRY *tail, ENTRY *add){ ENTRY **get_entries(ENTRY *head, int count){ ENTRY **arr = malloc(sizeof(ENTRY *) * count); ENTRY *trav = head; - int i; + int i = 0; - for(i = 0; i < count; i++){ - arr[i] = trav; + while(i < count){ + if(!trav->hidden){ + arr[i] = trav; + i++; + } trav = trav->next; } @@ -120,6 +127,11 @@ bool get_eforce(ENTRY *e){ return e->path_force; } +void set_hide(ENTRY *e, bool status){ + assert(e != NULL); + e->hidden = true; +} + void entry_debug(ENTRY *trav){ while(trav != NULL){ @@ -19,6 +19,10 @@ char *get_epath(ENTRY *e); bool get_eforce(ENTRY *e); +void set_hide(ENTRY *e, bool status); + +bool get_hide(ENTRY *e); + void entry_debug(ENTRY *trav); #endif Binary files differ@@ -30,6 +30,7 @@ char *get_gflags(GROUP *g); void set_gflags(GROUP *g, char *p); ENTRY *get_ghead(GROUP *g); int get_ecount(GROUP *g); +void set_ecount(GROUP *g, int new_count); //for use in hiding entries int get_gcount(); void group_debug(); //debug function to output all groups @@ -220,6 +221,11 @@ int get_ecount(GROUP *g){ return g->entry_count; } +void set_ecount(GROUP *g, int new_count){ + assert(g != NULL); + g->entry_count = new_count; +} + int get_gcount(){ return group_count; } @@ -27,6 +27,8 @@ ENTRY *get_ghead(GROUP *g); int get_ecount(GROUP *g); +void set_ecount(GROUP *g, int new_count); + int get_gcount(); void group_debug(); Binary files differ@@ -10,7 +10,7 @@ #include "group.h" #define BUF_LEN 1024 //maybe move this line to the header file #define MAX_ARGS 5 -#define OPTION_CNT 11 +#define OPTION_CNT 12 //public char *find_config(); @@ -93,9 +93,10 @@ void cfg_interp(char *path){ options[5] = "addR"; options[6] = "autoAlias"; options[7] = "compMode"; - options[8] = "setFlags"; - options[9] = "setLauncher"; - options[10] = "sort"; + options[8] = "hide"; + options[9] = "setFlags"; + options[10] = "setLauncher"; + options[11] = "sort"; //Read each line of "config" while(fgets(buffer, BUF_LEN, fp)){ @@ -140,11 +141,13 @@ void check_line(char *buffer, char **options){ char *tok = strtok(buffer, delims); char args[MAX_ARGS][BUF_LEN]; GROUP **g; + ENTRY **e; char *tok_p; char *arg_p; int g_count; + int e_count; int search_res; - int i; + int i, j; //ensure line is not blank or commented out if(tok != NULL && tok[0] != '#' && tok[0] != '\0'){ @@ -243,7 +246,36 @@ void check_line(char *buffer, char **options){ else printf("Error: Unknown Compatability Mode Argument \"%s\"\n", strip_quotes(args[1])); break; - case 8: //setFlags + //TODO consider having this call handle_fname instead so that '*' can be used + case 8: //hide + //args[2] is referring to a group + g = get_groups(); + g_count = get_gcount(); + + //look for matching existing group + for(i = 0; i < g_count; i++){ + if(!(strcmp(get_gname(g[i]), args[2]))) break; + } + + if(i < g_count){ + e_count = get_ecount(g[i]); + e = get_entries(get_ghead(g[i]), e_count); + + for(j = 0; j < e_count; j++){ + if(!strcmp(get_ename(e[j]), strip_quotes(args[1]))) break; + } + + if(j < e_count){ + set_hide(e[j], true); + set_ecount(g[i], get_ecount(g[i])-1); + } + else printf("Error: Entry \"%s\" does not exist\n", args[1]); + } + + else printf("Error: Group \"%s\" does not exist\n", args[2]); + break; + + case 9: //setFlags //args[1] is referring to a group g = get_groups(); g_count = get_gcount(); @@ -259,7 +291,7 @@ void check_line(char *buffer, char **options){ else printf("Error: Group \"%s\" does not exist\n", args[1]); break; - case 9: //setLauncher + case 10: //setLauncher //args[1] is referring to a group g = get_groups(); g_count = get_gcount(); @@ -275,7 +307,7 @@ void check_line(char *buffer, char **options){ else printf("Error: Group \"%s\" does not exist\n", args[1]); break; - case 10: //sort + case 11: //sort if(!(strcmp(args[1], "on"))) sort = true; else if(!(strcmp(args[1], "off"))) sort = false; break; @@ -425,6 +457,7 @@ char *autoAlias(char *path){ char *hr_name = malloc(sizeof(char) * BUF_LEN); char *p = hr_name; char *rpath; //necessary so as not to touch the actual path + char *last_dot = NULL; //used to trim the file extension (if there is one) bool stop = false; //stop when you don't want to add a series of chars to the output //get to the relative path name @@ -457,6 +490,9 @@ char *autoAlias(char *path){ } break; + case '.': + last_dot = p; + default: if(!stop){ *p = *rpath; @@ -467,7 +503,8 @@ char *autoAlias(char *path){ } //close the name - if(*path == '"') *(p-1) = '\0'; //close early to avoid including closing quote + if(last_dot != NULL) *last_dot = '\0'; + else if(*path == '"') *(p-1) = '\0'; //close early to avoid including closing quote else *p = '\0'; return hr_name; Binary files differ |