summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouie <lshprung@yahoo.com>2020-08-04 10:07:20 -0700
committerlouie <lshprung@yahoo.com>2020-08-04 10:07:20 -0700
commit1c85b0c98c3a8a55665abfdd8517baf7791531da (patch)
treebdcf94ee22bcbfc155822d96145dd9c2ef23f6b4
parenta98dd21113d8e8a6893e6813f9411a8d0b6ef10e (diff)
Added hide option for read_cfg
-rw-r--r--docs/README.md2
-rw-r--r--docs/tml-config.md8
-rw-r--r--entry.c18
-rw-r--r--entry.h4
-rw-r--r--entry.obin4672 -> 5016 bytes
-rw-r--r--group.c6
-rw-r--r--group.h2
-rw-r--r--group.obin7864 -> 8184 bytes
-rw-r--r--read_cfg.c55
-rw-r--r--read_cfg.obin12896 -> 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.
diff --git a/entry.c b/entry.c
index af3a5c8..188a2de 100644
--- a/entry.c
+++ b/entry.c
@@ -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){
diff --git a/entry.h b/entry.h
index caa724e..51e43ca 100644
--- a/entry.h
+++ b/entry.h
@@ -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
diff --git a/entry.o b/entry.o
index c80c26c..b03cbc0 100644
--- a/entry.o
+++ b/entry.o
Binary files differ
diff --git a/group.c b/group.c
index 6b293a6..ca47edd 100644
--- a/group.c
+++ b/group.c
@@ -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;
}
diff --git a/group.h b/group.h
index 38a33f8..e29107c 100644
--- a/group.h
+++ b/group.h
@@ -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();
diff --git a/group.o b/group.o
index 32cd6fb..8d1460d 100644
--- a/group.o
+++ b/group.o
Binary files differ
diff --git a/read_cfg.c b/read_cfg.c
index 0950887..3d3a6a6 100644
--- a/read_cfg.c
+++ b/read_cfg.c
@@ -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;
diff --git a/read_cfg.o b/read_cfg.o
index 83867ba..1d6de0e 100644
--- a/read_cfg.o
+++ b/read_cfg.o
Binary files differ