diff options
author | louie <lshprung@yahoo.com> | 2020-08-02 18:09:03 -0700 |
---|---|---|
committer | louie <lshprung@yahoo.com> | 2020-08-02 18:09:03 -0700 |
commit | 7cab81c193a01775d804fb037f7d26c6a6806e74 (patch) | |
tree | ba6049ca4c3243496bcd46c1f5639d8f69591e7a | |
parent | 2ee23565a15bd969828db7442f2f8b4902d5e261 (diff) |
Added option to sort entries
-rw-r--r-- | draw.c | 2 | ||||
-rw-r--r-- | entry.c | 37 | ||||
-rw-r--r-- | entry.h | 2 | ||||
-rw-r--r-- | entry.o | bin | 4256 -> 4976 bytes | |||
-rw-r--r-- | group.c | 27 | ||||
-rw-r--r-- | group.o | bin | 7792 -> 8248 bytes | |||
-rw-r--r-- | read_cfg.c | 20 | ||||
-rw-r--r-- | read_cfg.h | 2 | ||||
-rw-r--r-- | read_cfg.o | bin | 12448 -> 12896 bytes |
9 files changed, 84 insertions, 6 deletions
@@ -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; @@ -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; @@ -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); Binary files differ@@ -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++; } Binary files differ@@ -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]); @@ -7,4 +7,6 @@ void cfg_interp(); int get_compmode(); +bool get_sort(); + #endif Binary files differ |