summaryrefslogtreecommitdiff
path: root/entry.c
diff options
context:
space:
mode:
authorlouie <lshprung@yahoo.com>2020-08-02 19:26:52 -0700
committerlouie <lshprung@yahoo.com>2020-08-02 19:26:52 -0700
commitae45bbeb76120c71e034459e550a52123cea9f0a (patch)
treef76160266ecb8fb3251245ab696d9e9d626ddc3f /entry.c
parentb8881cc837238c238b78436d9b156e206feea71e (diff)
Set sort on by default, simplified entry_add
Diffstat (limited to 'entry.c')
-rw-r--r--entry.c21
1 files changed, 4 insertions, 17 deletions
diff --git a/entry.c b/entry.c
index 4fd3d1e..af3a5c8 100644
--- a/entry.c
+++ b/entry.c
@@ -7,6 +7,7 @@
#include <unistd.h>
#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;
}