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 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'entry.c') 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; } -- cgit