summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--draw.c2
-rw-r--r--entry.c37
-rw-r--r--entry.h2
-rw-r--r--entry.obin4256 -> 4976 bytes
-rw-r--r--group.c27
-rw-r--r--group.obin7792 -> 8248 bytes
-rw-r--r--read_cfg.c20
-rw-r--r--read_cfg.h2
-rw-r--r--read_cfg.obin12448 -> 12896 bytes
9 files changed, 84 insertions, 6 deletions
diff --git a/draw.c b/draw.c
index a7acdf1..9907276 100644
--- a/draw.c
+++ b/draw.c
@@ -272,6 +272,7 @@ void update_col(int mode, int hl_where){
name_len = 9;
break;
+
default:
return;
}
@@ -294,6 +295,7 @@ void update_col(int mode, int hl_where){
case 1:
e_count = get_ecount(g[g_hover]);
e = get_entries(get_ghead(g[g_hover]), e_count);
+ system("touch log");
fill_entries(e, e_count);
mvwchgat(entry_win, y_hl, 1, entry_win->_maxx-1, A_DIM, 1, NULL);
break;
diff --git a/entry.c b/entry.c
index d455f6b..4fd3d1e 100644
--- a/entry.c
+++ b/entry.c
@@ -20,6 +20,7 @@ ENTRY *create_entry(char *new_name, char *new_path, bool force);
void entry_rm(ENTRY *e, ENTRY *prev);
void clear_entries(ENTRY *head);
ENTRY *entry_add_last(ENTRY *tail, ENTRY *add);
+int entry_add_sorted(ENTRY *head, ENTRY *tail, ENTRY *add);
ENTRY **get_entries(ENTRY *head, int count);
char *get_ename(ENTRY *e);
char *get_epath(ENTRY *e);
@@ -57,6 +58,7 @@ void clear_entries(ENTRY *head){
return;
}
+//TODO consider joining entry_add_last and entry_add_sorted
ENTRY *entry_add_last(ENTRY *tail, ENTRY *add){
assert(add != NULL);
@@ -69,6 +71,41 @@ ENTRY *entry_add_last(ENTRY *tail, ENTRY *add){
return tail;
}
+//returns 0 if in the middle, 1 if new head, 2 if new tail, or 3 if both new head and tail
+//TODO this is kind of a stupid way of handling things
+int entry_add_sorted(ENTRY *head, ENTRY *tail, ENTRY *add){
+ assert(add != NULL);
+ ENTRY *ahead;
+
+ //Empty group (no need to sort)
+ if(head == NULL) return 3;
+
+ //add is the new tail
+ if(strcmp(tail->name, add->name) <= 0){
+ tail->next = add;
+ return 2;
+ }
+
+ //add is the new head
+ if(strcmp(add->name, head->name) <= 0){
+ add->next = head;
+ return 1;
+ }
+
+ ahead = head->next;
+
+ while(ahead != NULL){
+ if(strcmp(head->name, add->name) <= 0 && strcmp(add->name, ahead->name) <= 0) break;
+ head = head->next;
+ ahead = ahead->next;
+ }
+
+ head->next = add;
+ add->next = ahead;
+
+ return 0;
+}
+
ENTRY **get_entries(ENTRY *head, int count){
ENTRY **arr = malloc(sizeof(ENTRY *) * count);
ENTRY *trav = head;
diff --git a/entry.h b/entry.h
index bcefc04..d0027cb 100644
--- a/entry.h
+++ b/entry.h
@@ -11,6 +11,8 @@ void clear_entries(ENTRY *head);
ENTRY *entry_add_last(ENTRY *tail, ENTRY *add);
+int entry_add_sorted(ENTRY *head, ENTRY *tail, ENTRY *add);
+
ENTRY **get_entries(ENTRY *head, int count);
char *get_ename(ENTRY *e);
diff --git a/entry.o b/entry.o
index e9344db..155f850 100644
--- a/entry.o
+++ b/entry.o
Binary files differ
diff --git a/group.c b/group.c
index 7697e96..a9253c0 100644
--- a/group.c
+++ b/group.c
@@ -6,6 +6,7 @@
#include <unistd.h>
#include "entry.h"
#include "group.h"
+#include "read_cfg.h"
#define BUF_LEN 1024
typedef struct group{
@@ -103,8 +104,30 @@ void group_add(char *gname, ENTRY *addme){
//add the entry to the list of entries in the group
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
+ if(get_sort()){
+ i = entry_add_sorted(gp->head, gp->tail, addme);
+ switch(i){
+ case 1:
+ gp->head = addme;
+ break;
+
+ case 2:
+ gp->tail = addme;
+ break;
+
+ case 3:
+ gp->head = addme;
+ gp->tail = addme;
+ break;
+
+ }
+ }
+
+ else{
+ 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++;
}
diff --git a/group.o b/group.o
index 469076d..b6318a6 100644
--- a/group.o
+++ b/group.o
Binary files differ
diff --git a/read_cfg.c b/read_cfg.c
index bfe118a..9bf64ee 100644
--- a/read_cfg.c
+++ b/read_cfg.c
@@ -10,12 +10,13 @@
#include "group.h"
#define BUF_LEN 1024 //maybe move this line to the header file
#define MAX_ARGS 5
-#define OPTION_CNT 10
+#define OPTION_CNT 11
//public
char *find_config();
void cfg_interp(char *path);
int get_compmode();
+bool get_sort();
//private
void check_line(char *buffer, char **options);
@@ -33,6 +34,9 @@ int compmode = 0;
//1 -> WSL
//maybe more later?
+//turn on or off sorting (A-Z)
+bool sort = 0;
+
//set to true to automatically try to create a human readable name for an entry
bool hr = false;
@@ -76,7 +80,6 @@ void cfg_interp(char *path){
int i;
int j;
- //TODO have this check in certain locations for a config file, give error message if "config" does not exist
fp = fopen(path, "r");
assert(fp != NULL);
@@ -92,6 +95,7 @@ void cfg_interp(char *path){
options[7] = "compMode";
options[8] = "setFlags";
options[9] = "setLauncher";
+ options[10] = "sort";
//Read each line of "config"
while(fgets(buffer, BUF_LEN, fp)){
@@ -124,7 +128,11 @@ int get_compmode(){
return compmode;
}
-//TODO add support for "addR" recursive adding
+bool get_sort(){
+ return sort;
+}
+
+//TODO add support for "addR" recursive adding (still needs work...)
//TODO add support for "alias" option
//TODO add support for "hide" option
void check_line(char *buffer, char **options){
@@ -195,7 +203,6 @@ void check_line(char *buffer, char **options){
case 0: //add
//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 add sorting functionality
handle_fname(args[1], args[2], 0, 0, NULL);
break;
@@ -268,6 +275,11 @@ void check_line(char *buffer, char **options){
else printf("Error: Group \"%s\" does not exist\n", args[1]);
break;
+ case 10: //sort
+ if(!(strcmp(args[1], "on"))) sort = true;
+ else if(!(strcmp(args[1], "off"))) sort = false;
+ break;
+
default:
printf("Error: Unknown config option \"%s\"\n", args[0]);
diff --git a/read_cfg.h b/read_cfg.h
index 4c32bb2..a88dfa6 100644
--- a/read_cfg.h
+++ b/read_cfg.h
@@ -7,4 +7,6 @@ void cfg_interp();
int get_compmode();
+bool get_sort();
+
#endif
diff --git a/read_cfg.o b/read_cfg.o
index 55e23a5..ed4daa4 100644
--- a/read_cfg.o
+++ b/read_cfg.o
Binary files differ