From ae45bbeb76120c71e034459e550a52123cea9f0a Mon Sep 17 00:00:00 2001 From: louie Date: Sun, 2 Aug 2020 19:26:52 -0700 Subject: Set sort on by default, simplified entry_add --- entry.c | 21 ++++----------------- entry.h | 4 +--- entry.o | Bin 4976 -> 4672 bytes group.c | 36 ++++++++++++++---------------------- group.o | Bin 8248 -> 7864 bytes read_cfg.c | 4 ++-- read_cfg.o | Bin 12896 -> 12896 bytes 7 files changed, 21 insertions(+), 44 deletions(-) diff --git a/entry.c b/entry.c index 4fd3d1e..af3a5c8 100644 --- a/entry.c +++ b/entry.c @@ -7,6 +7,7 @@ #include #include "entry.h" #include "group.h" +#include "read_cfg.h" #define BUF_LEN 1024 typedef struct entry{ @@ -19,8 +20,7 @@ typedef struct entry{ 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); +int entry_add(ENTRY *head, ENTRY *tail, ENTRY *add); ENTRY **get_entries(ENTRY *head, int count); char *get_ename(ENTRY *e); char *get_epath(ENTRY *e); @@ -58,22 +58,9 @@ 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); - - if(tail == NULL) tail = add; - else{ - tail->next = add; - tail = 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){ +int entry_add(ENTRY *head, ENTRY *tail, ENTRY *add){ assert(add != NULL); ENTRY *ahead; @@ -81,7 +68,7 @@ int entry_add_sorted(ENTRY *head, ENTRY *tail, ENTRY *add){ if(head == NULL) return 3; //add is the new tail - if(strcmp(tail->name, add->name) <= 0){ + if(!get_sort() || strcmp(tail->name, add->name) <= 0){ tail->next = add; return 2; } diff --git a/entry.h b/entry.h index d0027cb..caa724e 100644 --- a/entry.h +++ b/entry.h @@ -9,9 +9,7 @@ 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); +int entry_add(ENTRY *head, ENTRY *tail, ENTRY *add); ENTRY **get_entries(ENTRY *head, int count); diff --git a/entry.o b/entry.o index 155f850..c80c26c 100644 Binary files a/entry.o and b/entry.o differ diff --git a/group.c b/group.c index a9253c0..6b293a6 100644 --- a/group.c +++ b/group.c @@ -6,7 +6,6 @@ #include #include "entry.h" #include "group.h" -#include "read_cfg.h" #define BUF_LEN 1024 typedef struct group{ @@ -104,29 +103,22 @@ void group_add(char *gname, ENTRY *addme){ //add the entry to the list of entries in the group if(addme != NULL){ - 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; + i = entry_add(gp->head, gp->tail, addme); + switch(i){ + case 1: + gp->head = addme; + break; - } - } + case 2: + 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 - } + case 3: + gp->head = addme; + gp->tail = addme; + break; + + } gp->entry_count++; total_count++; diff --git a/group.o b/group.o index b6318a6..32cd6fb 100644 Binary files a/group.o and b/group.o differ diff --git a/read_cfg.c b/read_cfg.c index 9bf64ee..0950887 100644 --- a/read_cfg.c +++ b/read_cfg.c @@ -34,8 +34,8 @@ int compmode = 0; //1 -> WSL //maybe more later? -//turn on or off sorting (A-Z) -bool sort = 0; +//turn on or off sorting (A-Z); On by default +bool sort = 1; //set to true to automatically try to create a human readable name for an entry bool hr = false; diff --git a/read_cfg.o b/read_cfg.o index ed4daa4..83867ba 100644 Binary files a/read_cfg.o and b/read_cfg.o differ -- cgit