summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouie <lshprung@yahoo.com>2020-06-22 21:08:10 -0700
committerlouie <lshprung@yahoo.com>2020-06-22 21:08:10 -0700
commit43eeda3d0982160d7863dd2268d989f79c24f03f (patch)
tree8beca0a69f63b520683148f3a265b8b5806c7f6b
parent4ca501cb1ded2bf4466a28fcad28a6b7c60d8aff (diff)
Altered Group Structure and cfg
-rw-r--r--Makefile9
-rw-r--r--draw.c14
-rw-r--r--entry.c16
-rw-r--r--entry.h2
-rw-r--r--entry.obin0 -> 3520 bytes
-rw-r--r--group.c47
-rw-r--r--group.h4
-rw-r--r--group.obin0 -> 5656 bytes
-rw-r--r--read_cfg.c36
-rw-r--r--read_cfg.obin0 -> 2968 bytes
10 files changed, 63 insertions, 65 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..91b5d34
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,9 @@
+CC = gcc
+PROGS = tml
+
+all: $(PROGS)
+
+clean:; $(RM) $(PROGS) *.o core
+
+tml: draw.o read_cfg.o entry.o group.o
+ $(CC) -o tml draw.o read_cfg.o entry.o group.o -lncurses
diff --git a/draw.c b/draw.c
index 888ac26..4fc69a0 100644
--- a/draw.c
+++ b/draw.c
@@ -36,6 +36,11 @@ int main(){
bool wide = true; //is the window a certain width (tbd what the threshold should be TODO)
int input;
+ //Fill Groups
+ cfg_interp(); //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
+
initscr();
cbreak();
keypad(stdscr, true);
@@ -67,11 +72,6 @@ int main(){
draw_win(group_win, "GROUP");
draw_win(entry_win, "ENTRY");
draw_win(info_win, "INFO");
-
- //Fill Groups
- cfg_interp(); //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
fill_groups(g, g_count);
//start with hover on the first group, draw the entries from the selected group, true_hover is over the groups (rather than the entries)
@@ -151,7 +151,7 @@ void fill_groups(GROUP **group_arr, int count){
name = get_gname(group_arr[i]);
//the name is too long, take the group to the trimming function
- if(strlen(name) > max_len) name = trim_name(name, get_gpath(group_arr[i]), max_len);
+ if(strlen(name) > max_len) name = trim_name(name, get_gname(group_arr[i]), max_len);
wmove(group_win, ycoord, 1);
wprintw(group_win, "%s", name);
ycoord++;
@@ -182,7 +182,7 @@ void fill_entries(ENTRY **entry_arr, int count){
return;
}
-//FIXME issue trimming entry
+//FIXME issue trimming entries with path title
char *trim_name(char *name, char *path, int max_len){
char *tok; //for use in finding relative path name
char *tok_ahead;
diff --git a/entry.c b/entry.c
index d5f1425..6b5e9ce 100644
--- a/entry.c
+++ b/entry.c
@@ -14,29 +14,25 @@ typedef struct entry{
struct entry *next;
} ENTRY;
-ENTRY *create_entry(char *new_path, char *new_group);
+ENTRY *create_entry(char *new_name, char *new_path);
ENTRY *entry_add_last(ENTRY *tail, ENTRY *add);
ENTRY **get_entries(ENTRY *head, int count);
char *get_ename(ENTRY *e);
char *get_epath(ENTRY *e);
-ENTRY *create_entry(char *new_path, char *new_group){
+ENTRY *create_entry(char *new_name, char *new_path){
ENTRY *new;
- char full_path[BUF_LEN] = "";
-
- if(new_group != NULL) strcat(full_path, new_group);
- strcat(full_path, new_path);
//check if file exists
- if(access(full_path, F_OK) == -1){
- printf("Error: Invalid File Name \"%s\"\n", full_path);
+ if(access(new_path, F_OK) == -1){
+ printf("Error: Invalid File Name \"%s\"\n", new_path);
return NULL;
}
new = malloc(sizeof(ENTRY));
- strcpy(new->name, new_path);
- strcpy(new->path, full_path);
+ strcpy(new->name, new_name);
+ strcpy(new->path, new_path);
new->next = NULL;
return new;
diff --git a/entry.h b/entry.h
index 3c8a366..b76919c 100644
--- a/entry.h
+++ b/entry.h
@@ -3,7 +3,7 @@
typedef struct entry ENTRY;
-ENTRY *create_entry(char *new_path, char *new_group);
+ENTRY *create_entry(char *new_name, char *new_path);
ENTRY *entry_add_last(ENTRY *tail, ENTRY *add);
diff --git a/entry.o b/entry.o
new file mode 100644
index 0000000..fc225bc
--- /dev/null
+++ b/entry.o
Binary files differ
diff --git a/group.c b/group.c
index b78f054..be2594d 100644
--- a/group.c
+++ b/group.c
@@ -10,7 +10,6 @@
typedef struct group{
char name[BUF_LEN];
- char path[BUF_LEN];
char program[BUF_LEN];
struct entry *head;
struct entry *tail;
@@ -18,11 +17,10 @@ typedef struct group{
int entry_count;
} GROUP;
-GROUP *create_group(char *new_path);
+GROUP *create_group(char *new_name);
void group_add(char *gname, ENTRY *addme);
GROUP **get_groups();
char *get_gname(GROUP *g);
-char *get_gpath(GROUP *g);
char *get_gprog(GROUP *g);
ENTRY *get_ghead(GROUP *g);
int get_ecount(GROUP *g);
@@ -34,12 +32,11 @@ GROUP *gp; //pointer to remember last group that was looked at
int group_count = 0;
int total_count = 0;
-GROUP *create_group(char *new_path){
+GROUP *create_group(char *new_name){
GROUP *new = malloc(sizeof(GROUP));
- strcpy(new->name, new_path); //by default, group name is equivalent to the path
- strcpy(new->path, new_path);
- strcpy(new->program, "./"); //by default, launch an entry by executing it
+ strcpy(new->name, new_name); //by default, group name is equivalent to the path
+ strcpy(new->program, "./"); //by default, launch an entry by executing it
new->head = NULL;
new->tail = NULL;
new->next = NULL;
@@ -49,6 +46,7 @@ GROUP *create_group(char *new_path){
return new;
}
+//add an entry to a group or add a new empty group
//FIXME maybe make this function part of a seperate file to handle a tree (AVL?)
//for now, simple linked list implementation
void group_add(char *gname, ENTRY *addme){
@@ -56,12 +54,26 @@ void group_add(char *gname, ENTRY *addme){
GROUP *new;
GROUP *last = NULL; //last element in an existing group list (NULL to start)
+ //only adding a new group
+ if(addme == NULL){
+ gp = groups_head;
+ while(gp != NULL){
+ if(!(strcmp(gp->name, gname))){
+ printf("config error: %s is already a group!\n", gname);
+ return;
+ }
+
+ last = gp;
+ gp = gp->next;
+ }
+ }
+
//The previous group is not the same as the new group to add to
- if(!(gp != NULL && (!(strcmp(gp->name, gname)) || !(strcmp(gp->path, gname))))){
+ if(!(gp != NULL && (!(strcmp(gp->name, gname))))){
gp = groups_head;
while(gp != NULL){
- //gname matches groups[i]'s name or path, add entry here
- if(!(strcmp(gp->name, gname)) || !(strcmp(gp->path, gname))) break;
+ //gname matches groups[i]'s name, add entry here
+ if(!(strcmp(gp->name, gname))) break;
last = gp;
gp = gp->next;
@@ -83,11 +95,13 @@ void group_add(char *gname, ENTRY *addme){
}
//add the entry to the list of entries in the group
- gp->tail = entry_add_last(gp->tail, addme);
- if(gp->head == NULL) gp->head = gp->tail; //first element of the new list
+ if(addme != NULL){
+ gp->tail = entry_add_last(gp->tail, addme);
+ if(gp->head == NULL) gp->head = gp->tail; //first element of the new list
+ gp->entry_count++;
+ total_count++;
+ }
- gp->entry_count++;
- total_count++;
return;
}
@@ -109,11 +123,6 @@ char *get_gname(GROUP *g){
return g->name;
}
-char *get_gpath(GROUP *g){
- assert(g != NULL);
- return g->path;
-}
-
char *get_gprog(GROUP *g){
assert(g != NULL);
return g->program;
diff --git a/group.h b/group.h
index 1afb63d..01fe54d 100644
--- a/group.h
+++ b/group.h
@@ -3,7 +3,7 @@
typedef struct group GROUP;
-GROUP *create_group(char *new_path);
+GROUP *create_group(char *new_name);
void group_add(char *gname, ENTRY *addme);
@@ -11,8 +11,6 @@ GROUP **get_groups();
char *get_gname(GROUP *g);
-char *get_gpath(GROUP *g);
-
char *get_gprog(GROUP *g);
ENTRY *get_ghead(GROUP *g);
diff --git a/group.o b/group.o
new file mode 100644
index 0000000..ced49ea
--- /dev/null
+++ b/group.o
Binary files differ
diff --git a/read_cfg.c b/read_cfg.c
index 8def4ef..c7dd47f 100644
--- a/read_cfg.c
+++ b/read_cfg.c
@@ -53,40 +53,26 @@ void cfg_interp(){
void check_line(char *buffer){
char *delims = " \t\n";
char *tok = strtok(buffer, delims);
- DIR *dp;
- struct dirent *d_entry;
ENTRY *new;
- //add a path to the entry list
+ //add entry(ies) to a group: first arg is the file(s), second arg is the group to add to
//TODO add potential dash functions
//TODO account for spaces in file name
+ //TODO add regex support for adding patterns
+ //TODO allow adding directories (might fall into regex support)
if(!(strcmp(tok, "add"))){
- tok = strtok(NULL, delims);
- new = create_entry(tok, NULL);
+ //look at first arg
+ tok = strtok(NULL, delims);
+ new = create_entry(tok, tok);
+ //look at second arg
+ tok = strtok(NULL, delims);
if(new != NULL) group_add(tok, new);
}
- //recursively add entries from a directory
- if(!(strcmp(tok, "addDir"))){
+ //create a new group
+ if(!(strcmp(tok, "addGroup"))){
tok = strtok(NULL, delims);
- dp = opendir(tok);
-
- //check if the directory is valid
- if(dp == NULL) printf("Error: Invalid Directory \"%s\"\n", tok);
-
- else{
- while((d_entry = readdir(dp))){
- //only add if its a file (d_type = 8)
- if(d_entry->d_type == 8){
- new = create_entry(d_entry->d_name, tok);
- if(new != NULL) group_add(tok, new);
- }
- }
- }
-
- //TODO add option to also add files from directories inside directory (-r)
-
- closedir(dp);
+ group_add(tok, NULL);
}
return;
diff --git a/read_cfg.o b/read_cfg.o
new file mode 100644
index 0000000..768690e
--- /dev/null
+++ b/read_cfg.o
Binary files differ