diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-11-12 19:45:08 +0100 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-11-12 20:46:57 +0100 |
| commit | 049d23ab28f2708506dbde362539e9b5f36a10c4 (patch) | |
| tree | a9a64494a0c8662ac2431d9d70ac18b5c89329a5 /src/history.c | |
| parent | f868887d311cbb330732587c89ab9d886dfa4693 (diff) | |
| download | tmus-049d23ab28f2708506dbde362539e9b5f36a10c4.tar.gz tmus-049d23ab28f2708506dbde362539e9b5f36a10c4.zip | |
Update liblist api and remote
Diffstat (limited to 'src/history.c')
| -rw-r--r-- | src/history.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/history.c b/src/history.c index d11e106..ab12019 100644 --- a/src/history.c +++ b/src/history.c @@ -1,9 +1,11 @@ +#include "list.h" #define _GNU_SOURCE #include "history.h" #include "util.h" #include <string.h> +#include <stdlib.h> static struct inputln *history_list_prev( struct inputln *cur, const char *search); @@ -14,11 +16,11 @@ static struct inputln *history_list_next( struct inputln * history_list_prev(struct inputln *cur, const char *search) { - struct link *iter; + struct list_link *iter; struct inputln *ln; for (iter = cur->link.prev; iter && iter->prev; iter = iter->prev) { - ln = UPCAST(iter, struct inputln, link); + ln = LIST_UPCAST(iter, struct inputln, link); if (!search || !*search || strcasestr(ln->buf, search)) return ln; } @@ -29,12 +31,12 @@ history_list_prev(struct inputln *cur, const char *search) struct inputln * history_list_next(struct inputln *cur, const char *search) { - struct link *iter; + struct list_link *iter; struct inputln *ln; iter = cur->link.next; while (LIST_INNER(iter)) { - ln = UPCAST(iter, struct inputln, link); + ln = LIST_UPCAST(iter, struct inputln, link); if (!search || !*search || strcasestr(ln->buf, search)) return ln; iter = iter->next; @@ -54,16 +56,16 @@ history_init(struct history *history) void history_deinit(struct history *history) { - struct link *link; + struct list_link *link; struct inputln *ln; - link = link_pop(&history->input->link); - ln = UPCAST(link, struct inputln, link); + link = list_link_pop(&history->input->link); + ln = LIST_UPCAST(link, struct inputln, link); inputln_free(ln); history->input = NULL; - list_free(&history->list, (link_free_func) inputln_free, - LINK_OFFSET(struct inputln, link)); + list_free_items(&history->list, (list_item_free_fn) inputln_free, + LIST_OFFSET(struct inputln, link)); history->sel = NULL; } @@ -73,12 +75,12 @@ history_submit(struct history *history) { /* if chose from history free input */ if (history->sel != history->input) { - link_pop(&history->input->link); + list_link_pop(&history->input->link); inputln_free(history->input); } /* pop first in case already in history */ - link_pop(&history->sel->link); + list_link_pop(&history->sel->link); history_add(history, history->sel); /* create new input buf and add to hist */ @@ -103,16 +105,16 @@ void history_add(struct history *history, struct inputln *line) { struct inputln *ln; - struct link *back; + struct list_link *back; if (list_len(&history->list) == HISTORY_MAX) { /* pop last item to make space */ back = list_pop_back(&history->list); - ln = UPCAST(back, struct inputln, link); + ln = LIST_UPCAST(back, struct inputln, link); inputln_free(ln); } - list_push_front(&history->list, &line->link); + list_insert_front(&history->list, &line->link); } void @@ -122,7 +124,7 @@ inputln_init(struct inputln *ln) ln->len = 0; ln->cap = 0; ln->cur = 0; - ln->link = LINK_EMPTY; + ln->link = LIST_LINK_INIT; inputln_resize(ln, 128); } |
