commit 049d23ab28f2708506dbde362539e9b5f36a10c4
parent f868887d311cbb330732587c89ab9d886dfa4693
Author: Louis Burda <quent.burda@gmail.com>
Date: Sun, 12 Nov 2023 19:45:08 +0100
Update liblist api and remote
Diffstat:
11 files changed, 199 insertions(+), 192 deletions(-)
diff --git a/.gitmodules b/.gitmodules
@@ -1,3 +1,3 @@
[submodule "lib/liblist"]
path = lib/liblist
- url = git@sinitax.com:sinitax/liblist
+ url = git@sinitax.com:sinitax/liblist-c
diff --git a/src/cmd.c b/src/cmd.c
@@ -51,11 +51,11 @@ cmd_status_from_errno(int err)
bool
cmd_save(const char *args)
{
- struct link *link;
+ struct list_link *link;
struct tag *tag;
for (LIST_ITER(&tags, link)) {
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
if (tag->index_dirty || tag->reordered)
tag_save_tracks(tag);
}
@@ -66,7 +66,7 @@ cmd_save(const char *args)
bool
cmd_move(const char *name)
{
- struct link *link;
+ struct list_link *link;
struct track *track;
struct tag *tag;
@@ -99,7 +99,7 @@ cmd_move(const char *name)
bool
cmd_copy(const char *name)
{
- struct link *link;
+ struct list_link *link;
struct track *track, *new;
struct tag *tag;
char *newpath;
@@ -150,7 +150,7 @@ bool
cmd_reindex(const char *name)
{
struct track *track;
- struct link *link;
+ struct list_link *link;
struct tag *tag;
struct ref *ref;
struct list matches;
@@ -166,21 +166,21 @@ cmd_reindex(const char *name)
if (!*name) {
link = list_at(&tags, tag_nav.sel);
if (!link) return false;
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
ref = ref_alloc(tag);
- list_push_back(&matches, &ref->link);
+ list_insert_back(&matches, &ref->link);
} else if (!strcmp(name, "*")) {
for (LIST_ITER(&tags, link)) {
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
ref = ref_alloc(tag);
- list_push_back(&matches, &ref->link);
+ list_insert_back(&matches, &ref->link);
}
} else {
for (LIST_ITER(&tags, link)) {
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
if (!strcmp(tag->name, name)) {
ref = ref_alloc(tag);
- list_push_back(&matches, &ref->link);
+ list_insert_back(&matches, &ref->link);
break;
}
}
@@ -198,7 +198,7 @@ cmd_reindex(const char *name)
/* update each tag specified */
for (LIST_ITER(&matches, link)) {
- ref = UPCAST(link, struct ref, link);
+ ref = LIST_UPCAST(link, struct ref, link);
if (!tag_reindex_tracks(ref->data))
goto cleanup;
}
@@ -206,7 +206,7 @@ cmd_reindex(const char *name)
/* try to find old playing track among reindexed tracks */
if (playing_tag) {
for (LIST_ITER(&playing_tag->tracks, link)) {
- track = UPCAST(link, struct track, link_tt);
+ track = LIST_UPCAST(link, struct track, link_tt);
if (!strcmp(track->name, playing_name)) {
player.track = track;
break;
@@ -246,13 +246,13 @@ cmd_add_tag(const char *name)
bool
cmd_rm_tag(const char *name)
{
- struct link *link;
+ struct list_link *link;
struct tag *tag;
if (!*name) {
link = list_at(&tags, tag_nav.sel);
if (!link) return false;
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
} else {
tag = tag_find(name);
if (!tag) {
@@ -272,7 +272,7 @@ cmd_rm_tag(const char *name)
bool
cmd_rename(const char *name)
{
- struct link *link;
+ struct list_link *link;
struct track *track;
struct tag *tag;
@@ -292,7 +292,7 @@ cmd_rename(const char *name)
} else if (pane_after_cmd == tag_pane) {
link = list_at(&tags, tag_nav.sel);
if (!link) return false;
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
if (!tag_rename(tag, name))
return false;
}
diff --git a/src/data.c b/src/data.c
@@ -13,6 +13,7 @@
#include <unistd.h>
#include <stdbool.h>
#include <string.h>
+#include <stdlib.h>
const char *datadir;
@@ -30,7 +31,7 @@ static void tag_free(struct tag *tag);
static struct track *track_alloc(const char *path, const char *fname);
static void track_free(struct track *t);
-static bool tag_name_cmp(struct link *l1, struct link *l2);
+static bool tag_name_cmp(const void *p1, const void *p2, void *user);
struct tag *
tag_alloc(const char *path, const char *fname)
@@ -44,8 +45,8 @@ tag_alloc(const char *path, const char *fname)
tag->name = astrdup(fname);
tag->index_dirty = false;
tag->reordered = false;
- tag->link = LINK_EMPTY;
- tag->link_sel = LINK_EMPTY;
+ tag->link = LIST_LINK_INIT;
+ tag->link_sel = LIST_LINK_INIT;
list_init(&tag->tracks);
return tag;
@@ -71,11 +72,11 @@ track_alloc(const char *dir, const char *fname)
track->fpath = aprintf("%s/%s", dir, fname);
track->name = astrdup(fname);
track->tag = NULL;
- track->link = LINK_EMPTY;
- track->link_pl = LINK_EMPTY;
- track->link_tt = LINK_EMPTY;
- track->link_pq = LINK_EMPTY;
- track->link_hs = LINK_EMPTY;
+ track->link = LIST_LINK_INIT;
+ track->link_pl = LIST_LINK_INIT;
+ track->link_tt = LIST_LINK_INIT;
+ track->link_pq = LIST_LINK_INIT;
+ track->link_hs = LIST_LINK_INIT;
return track;
}
@@ -89,12 +90,9 @@ track_free(struct track *t)
}
bool
-tag_name_cmp(struct link *l1, struct link *l2)
+tag_name_cmp(const void *p1, const void *p2, void *user)
{
- struct tag *t1, *t2;
-
- t1 = LINK_UPCAST(l1, struct tag, link);
- t2 = LINK_UPCAST(l2, struct tag, link);
+ const struct tag *t1 = p1, *t2 = p2;
return strcmp(t1->name, t2->name) <= 0;
}
@@ -214,12 +212,12 @@ move_file(const char *src, const char *dst)
void
tag_clear_tracks(struct tag *tag)
{
- struct link *link;
+ struct list_link *link;
struct track *track;
while (!list_empty(&tag->tracks)) {
link = list_pop_front(&tag->tracks);
- track = UPCAST(link, struct track, link_tt);
+ track = LIST_UPCAST(link, struct track, link_tt);
track_rm(track, false);
}
}
@@ -255,7 +253,7 @@ void
tag_save_tracks(struct tag *tag)
{
struct track *track;
- struct link *link;
+ struct list_link *link;
char *index_path;
FILE *file;
@@ -271,7 +269,7 @@ tag_save_tracks(struct tag *tag)
}
for (LIST_ITER(&tag->tracks, link)) {
- track = UPCAST(link, struct track, link_tt);
+ track = LIST_UPCAST(link, struct track, link_tt);
fprintf(file, "%s\n", track->name);
}
@@ -313,12 +311,12 @@ tag_reindex_tracks(struct tag *tag)
}
struct track *
-tracks_vis_track(struct link *link)
+tracks_vis_track(struct list_link *link)
{
if (tracks_vis == &player.playlist) {
- return UPCAST(link, struct track, link_pl);
+ return LIST_UPCAST(link, struct track, link_pl);
} else {
- return UPCAST(link, struct track, link_tt);
+ return LIST_UPCAST(link, struct track, link_tt);
}
}
@@ -332,7 +330,7 @@ playlist_clear(void)
void
playlist_update(void)
{
- struct link *link, *link2;
+ struct list_link *link, *link2;
struct track *track;
struct tag *tag;
@@ -342,11 +340,11 @@ playlist_update(void)
playlist_clear();
for (LIST_ITER(&tags_sel, link)) {
- tag = UPCAST(link, struct tag, link_sel);
+ tag = LIST_UPCAST(link, struct tag, link_sel);
for (LIST_ITER(&tag->tracks, link2)) {
- track = UPCAST(link2, struct track, link_tt);
- link_pop(&track->link_pl);
- list_push_back(&player.playlist, &track->link_pl);
+ track = LIST_UPCAST(link2, struct track, link_tt);
+ list_link_pop(&track->link_pl);
+ list_insert_back(&player.playlist, &track->link_pl);
}
}
@@ -382,7 +380,7 @@ tag_add(const char *fname)
tag = tag_alloc(datadir, fname);
if (!tag) return NULL;
- list_push_back(&tags, &tag->link);
+ list_insert_back(&tags, &tag->link);
return tag;
}
@@ -390,11 +388,11 @@ tag_add(const char *fname)
struct tag *
tag_find(const char *name)
{
- struct link *link;
+ struct list_link *link;
struct tag *tag;
for (LIST_ITER(&tags, link)) {
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
if (!strcmp(tag->name, name))
return tag;
}
@@ -405,13 +403,13 @@ tag_find(const char *name)
bool
tag_rm(struct tag *tag, bool sync_fs)
{
- struct link *link;
+ struct list_link *link;
struct track *track;
/* remove contained tracks */
while (!list_empty(&tag->tracks)) {
link = list_pop_front(&tag->tracks);
- track = UPCAST(link, struct track, link_tt);
+ track = LIST_UPCAST(link, struct track, link_tt);
if (!track_rm(track, sync_fs))
return false;
}
@@ -421,10 +419,10 @@ tag_rm(struct tag *tag, bool sync_fs)
return false;
/* remove from selected */
- link_pop(&tag->link_sel);
+ list_link_pop(&tag->link_sel);
/* remove from tags list */
- link_pop(&tag->link);
+ list_link_pop(&tag->link);
tag_free(tag);
@@ -434,7 +432,7 @@ tag_rm(struct tag *tag, bool sync_fs)
bool
tag_rename(struct tag *tag, const char *name)
{
- struct link *link;
+ struct list_link *link;
struct track *track;
char *newpath;
@@ -452,7 +450,7 @@ tag_rename(struct tag *tag, const char *name)
tag->name = astrdup(name);
for (LIST_ITER(&tag->tracks, link)) {
- track = UPCAST(link, struct track, link_tt);
+ track = LIST_UPCAST(link, struct track, link_tt);
free(track->fpath);
track->fpath = aprintf("%s/%s", newpath, track->name);
}
@@ -469,13 +467,13 @@ track_add(struct tag *tag, const char *fname)
track->tag = tag;
/* insert track into sorted tracks list */
- list_push_back(&tracks, &track->link);
+ list_insert_back(&tracks, &track->link);
/* add to tag's tracks list */
- list_push_back(&tag->tracks, &track->link_tt);
+ list_insert_back(&tag->tracks, &track->link_tt);
/* if track's tag is selected, update playlist */
- if (link_inuse(&tag->link_sel))
+ if (list_link_inuse(&tag->link_sel))
playlist_outdated = true;
tag->index_dirty = true;
@@ -492,19 +490,19 @@ track_rm(struct track *track, bool sync_fs)
track->tag->index_dirty = true;
/* remove from tracks list */
- link_pop(&track->link);
+ list_link_pop(&track->link);
/* remove from tag's track list */
- link_pop(&track->link_tt);
+ list_link_pop(&track->link_tt);
/* remove from playlist */
- link_pop(&track->link_pl);
+ list_link_pop(&track->link_pl);
/* remove from player queue */
- link_pop(&track->link_pq);
+ list_link_pop(&track->link_pq);
/* remove from player history */
- link_pop(&track->link_hs);
+ list_link_pop(&track->link_hs);
/* remove the reference as last used track */
if (player.track == track)
@@ -678,7 +676,8 @@ data_load(void)
free(path);
}
- list_sort(&tags, false, tag_name_cmp);
+ list_insertion_sort(&tags, false, tag_name_cmp,
+ LIST_OFFSET(struct tag, link), NULL);
playlist_outdated = true;
@@ -688,11 +687,11 @@ data_load(void)
void
data_save(void)
{
- struct link *link;
+ struct list_link *link;
struct tag *tag;
for (LIST_ITER(&tags, link)) {
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
if (tag->index_dirty)
tag_save_tracks(tag);
}
@@ -703,7 +702,7 @@ data_save(void)
void
data_free(void)
{
- struct link *link;
+ struct list_link *link;
struct tag *tag;
list_clear(&player.playlist);
@@ -712,7 +711,7 @@ data_free(void)
while (!list_empty(&tags)) {
link = list_pop_front(&tags);
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
tag_rm(tag, false);
}
}
diff --git a/src/data.h b/src/data.h
@@ -10,19 +10,19 @@ struct tag {
bool index_dirty;
bool reordered;
- struct link link; /* tags list */
- struct link link_sel; /* selected tags list */
+ struct list_link link; /* tags list */
+ struct list_link link_sel; /* selected tags list */
};
struct track {
char *name, *fpath;
struct tag *tag;
- struct link link; /* tracks list */
- struct link link_pl; /* player playlist */
- struct link link_tt; /* tag tracks list */
- struct link link_pq; /* player queue */
- struct link link_hs; /* player history */
+ struct list_link link; /* tracks list */
+ struct list_link link_pl; /* player playlist */
+ struct list_link link_tt; /* tag tracks list */
+ struct list_link link_pq; /* player queue */
+ struct list_link link_hs; /* player history */
};
bool path_exists(const char *path);
@@ -34,7 +34,7 @@ bool copy_file(const char *dst, const char *src);
bool dup_file(const char *dst, const char *src);
bool move_file(const char *dst, const char *src);
-struct track *tracks_vis_track(struct link *link);
+struct track *tracks_vis_track(struct list_link *link);
void playlist_clear(void);
void playlist_update(void);
diff --git 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);
}
diff --git a/src/history.h b/src/history.h
@@ -9,7 +9,7 @@ struct inputln {
int len, cap;
int cur;
- struct link link;
+ struct list_link link;
};
struct history {
diff --git a/src/player.c b/src/player.c
@@ -3,19 +3,21 @@
#include "list.h"
#include "data.h"
+#include <stdlib.h>
+
static bool player_history_contains(struct track *cmp, int depth);
-static struct track *playlist_track_next_unused(struct link *start);
+static struct track *playlist_track_next_unused(struct list_link *start);
static struct track *player_next_from_playlist(void);
bool
player_history_contains(struct track *cmp, int depth)
{
- struct link *link;
+ struct list_link *link;
struct track *track;
link = list_back(&player.history);
while (LIST_INNER(link) && depth-- > 0) {
- track = UPCAST(link, struct track, link_hs);
+ track = LIST_UPCAST(link, struct track, link_hs);
if (track == cmp)
return true;
link = link->prev;
@@ -25,10 +27,10 @@ player_history_contains(struct track *cmp, int depth)
}
struct track *
-playlist_track_next_unused(struct link *start)
+playlist_track_next_unused(struct list_link *start)
{
struct track *track;
- struct link *link;
+ struct list_link *link;
bool in_history;
int len;
@@ -39,7 +41,7 @@ playlist_track_next_unused(struct link *start)
link = start;
while (LIST_INNER(link)) {
- track = UPCAST(link, struct track, link_pl);
+ track = LIST_UPCAST(link, struct track, link_pl);
in_history = player_history_contains(track, len - 2);
if (track != player.track && !in_history)
@@ -59,7 +61,7 @@ playlist_track_next_unused(struct link *start)
struct track *
player_next_from_playlist(void)
{
- struct link *link;
+ struct list_link *link;
int index;
if (list_empty(&player.playlist))
@@ -70,7 +72,7 @@ player_next_from_playlist(void)
link = list_at(&player.playlist, index);
return playlist_track_next_unused(link);
} else {
- if (player.track && link_inuse(&player.track->link_pl)) {
+ if (player.track && list_link_inuse(&player.track->link_pl)) {
index = list_index(&player.playlist,
&player.track->link_pl);
ASSERT(index >= 0);
@@ -80,7 +82,7 @@ player_next_from_playlist(void)
index = 0;
}
link = list_at(&player.playlist, index);
- return UPCAST(link, struct track, link_pl);
+ return LIST_UPCAST(link, struct track, link_pl);
}
return NULL;
@@ -100,9 +102,9 @@ player_next_from_playlist(void)
void
player_add_history(struct track *new)
{
- if (!link_inuse(&new->link_hs)) {
- link_pop(&new->link_hs);
- list_push_back(&player.history, &new->link_hs);
+ if (!list_link_inuse(&new->link_hs)) {
+ list_link_pop(&new->link_hs);
+ list_insert_back(&player.history, &new->link_hs);
}
}
@@ -116,13 +118,13 @@ player_add_history(struct track *new)
int
player_prev(void)
{
- struct link *next;
+ struct list_link *next;
struct track *track;
if (list_empty(&player.history))
return PLAYER_ERR;
- if (!player.track || !link_inuse(&player.track->link_hs)) {
+ if (!player.track || !list_link_inuse(&player.track->link_hs)) {
next = list_back(&player.history);
} else if (LIST_INNER(player.track->link_hs.prev)) {
next = player.track->link_hs.prev;
@@ -130,7 +132,7 @@ player_prev(void)
return PLAYER_ERR;
}
- track = UPCAST(next, struct track, link_hs);
+ track = LIST_UPCAST(next, struct track, link_hs);
player_play_track(track, false);
return PLAYER_OK;
@@ -140,17 +142,17 @@ int
player_next(void)
{
struct track *next_track;
- struct link *link;
+ struct list_link *link;
bool new_entry;
- if (player.track && link_inuse(&player.track->link_hs)
+ if (player.track && list_link_inuse(&player.track->link_hs)
&& LIST_INNER(player.track->link_hs.next)) {
- next_track = UPCAST(player.track->link_hs.next,
+ next_track = LIST_UPCAST(player.track->link_hs.next,
struct track, link_hs);
new_entry = false;
} else if (!list_empty(&player.queue)) {
link = list_pop_front(&player.queue);
- next_track = UPCAST(link, struct track, link_pq);
+ next_track = LIST_UPCAST(link, struct track, link_pq);
new_entry = true;
} else {
next_track = player_next_from_playlist();
diff --git a/src/player_mplay.c b/src/player_mplay.c
@@ -222,7 +222,7 @@ player_play_track(struct track *track, bool new)
return PLAYER_ERR;
/* new invocations are removed from history */
- if (new) link_pop(&track->link_hs);
+ if (new) list_link_pop(&track->link_hs);
player.time_pos = 0;
player.time_end = 0;
diff --git a/src/ref.c b/src/ref.c
@@ -1,6 +1,9 @@
#include "ref.h"
+#include "list.h"
#include "util.h"
+#include <stdlib.h>
+
struct ref *
ref_alloc(void *data)
{
@@ -9,7 +12,7 @@ ref_alloc(void *data)
ref = malloc(sizeof(struct ref));
if (!ref) ERROR(SYSTEM, "malloc");
- ref->link = LINK_EMPTY;
+ ref->link = LIST_LINK_INIT;
ref->data = data;
return ref;
@@ -24,19 +27,19 @@ ref_free(void *ref)
void
refs_free(struct list *list)
{
- list_free(list, ref_free, LINK_OFFSET(struct ref, link));
+ list_free_items(list, ref_free, LIST_OFFSET(struct ref, link));
}
int
refs_index(struct list *list, void *data)
{
- struct link *iter;
+ struct list_link *iter;
struct ref *ref;
int index;
index = 0;
for (LIST_ITER(list, iter)) {
- ref = UPCAST(iter, struct ref, link);
+ ref = LIST_UPCAST(iter, struct ref, link);
if (ref->data == data)
return index;
index++;
@@ -45,14 +48,14 @@ refs_index(struct list *list, void *data)
return -1;
}
-struct link *
+struct list_link *
refs_find(struct list *list, void *data)
{
- struct link *iter;
+ struct list_link *iter;
struct ref *ref;
for (LIST_ITER(list, iter)) {
- ref = UPCAST(iter, struct ref, link);
+ ref = LIST_UPCAST(iter, struct ref, link);
if (ref->data == data)
return iter;
}
@@ -63,7 +66,7 @@ refs_find(struct list *list, void *data)
int
refs_incl(struct list *list, void *data)
{
- struct link *ref;
+ struct list_link *ref;
ref = refs_find(list, data);
@@ -73,14 +76,14 @@ refs_incl(struct list *list, void *data)
void
refs_rm(struct list *list, void *data)
{
- struct link *ref;
+ struct list_link *ref;
struct ref *dataref;
ref = refs_find(list, data);
if (!ref) return;
- dataref = UPCAST(ref, struct ref, link);
- link_pop(ref);
+ dataref = LIST_UPCAST(ref, struct ref, link);
+ list_link_pop(ref);
free(dataref);
}
diff --git a/src/ref.h b/src/ref.h
@@ -5,7 +5,7 @@
struct ref {
void *data;
- struct link link;
+ struct list_link link;
};
struct ref *ref_alloc(void *data);
@@ -14,7 +14,7 @@ void ref_free(void *ref);
void refs_free(struct list *list);
int refs_index(struct list *list, void *data);
-struct link *refs_find(struct list *list, void *data);
+struct list_link *refs_find(struct list *list, void *data);
int refs_incl(struct list *list, void *data);
void refs_rm(struct list *list, void *data);
diff --git a/src/tui.c b/src/tui.c
@@ -54,7 +54,7 @@ static bool toggle_current_tag(void);
static void select_only_current_tag(void);
static void seek_next_selected_tag(void);
static void delete_current_tag(void);
-static bool tag_name_cmp(struct link *l1, struct link *l2);
+static bool tag_name_cmp(const void *p1, const void *p2, void *user);
static void sort_visible_tags(void);
static bool tag_pane_input(wint_t c);
static void tag_pane_vis(struct pane *pane, int sel);
@@ -66,7 +66,7 @@ static bool rename_current_track(void);
static bool delete_current_track(void);
static void queue_current_track(void);
static void unqueue_last_track(void);
-static bool track_vis_name_cmp(struct link *l1, struct link *l2);
+static bool track_vis_name_cmp(const void *p1, const void *p2, void *user);
static void sort_visible_tracks(void);
static bool track_pane_input(wint_t c);
static void track_pane_vis(struct pane *pane, int sel);
@@ -215,8 +215,8 @@ command_name_gen(const char *text, int fwd, int reset)
char *
track_vis_name_gen(const char *text, int fwd, int reset)
{
- static struct link *cur;
- struct link *link;
+ static struct list_link *cur;
+ struct list_link *link;
struct track *track;
const char *prevname;
char *dup;
@@ -256,8 +256,8 @@ next:
char *
track_name_gen(const char *text, int fwd, int reset)
{
- static struct link *cur;
- struct link *link;
+ static struct list_link *cur;
+ struct list_link *link;
struct track *track;
const char *prevname;
char *dup;
@@ -270,13 +270,13 @@ track_name_gen(const char *text, int fwd, int reset)
link = fwd ? cur->next : cur->prev;
prevname = NULL;
if (LIST_INNER(cur)) {
- track = UPCAST(cur, struct track, link);
+ track = LIST_UPCAST(cur, struct track, link);
prevname = track->name;
}
}
while (LIST_INNER(link)) {
- track = UPCAST(link, struct track, link);
+ track = LIST_UPCAST(link, struct track, link);
if (prevname && !strcmp(prevname, track->name))
goto next;
@@ -297,8 +297,8 @@ next:
char *
tag_name_gen(const char *text, int fwd, int reset)
{
- static struct link *cur;
- struct link *link;
+ static struct list_link *cur;
+ struct list_link *link;
struct tag *tag;
char *dup;
@@ -310,7 +310,7 @@ tag_name_gen(const char *text, int fwd, int reset)
}
while (LIST_INNER(link)) {
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
if (strcasestr(tag->name, text)) {
cur = link;
dup = astrdup(tag->name);
@@ -325,13 +325,13 @@ tag_name_gen(const char *text, int fwd, int reset)
bool
rename_current_tag(void)
{
- struct link *link;
+ struct list_link *link;
struct tag *tag;
char *cmd;
link = list_at(&tags, tag_nav.sel);
if (!link) return false;
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
cmd = aprintf("rename %s", tag->name);
select_cmd_pane(IMODE_EXECUTE);
@@ -344,20 +344,20 @@ rename_current_tag(void)
bool
toggle_current_tag(void)
{
- struct link *link;
+ struct list_link *link;
struct tag *tag;
if (list_empty(&tags)) return false;
link = list_at(&tags, tag_nav.sel);
if (!link) return false;
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
/* toggle tag in tags_sel */
- if (link_inuse(&tag->link_sel)) {
- link_pop(&tag->link_sel);
+ if (list_link_inuse(&tag->link_sel)) {
+ list_link_pop(&tag->link_sel);
} else {
- list_push_back(&tags_sel, &tag->link_sel);
+ list_insert_back(&tags_sel, &tag->link_sel);
}
playlist_outdated = true;
@@ -375,7 +375,7 @@ select_only_current_tag(void)
void
seek_next_selected_tag(void)
{
- struct link *link;
+ struct list_link *link;
struct tag *tag;
int index;
@@ -389,7 +389,7 @@ seek_next_selected_tag(void)
if (!link) return;
index = tag_nav.sel;
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
do {
index += 1;
link = tag->link.next;
@@ -397,8 +397,8 @@ seek_next_selected_tag(void)
link = list_at(&tags, 0);
index = 0;
}
- tag = UPCAST(link, struct tag, link);
- } while (!link_inuse(&tag->link_sel));
+ tag = LIST_UPCAST(link, struct tag, link);
+ } while (!list_link_inuse(&tag->link_sel));
listnav_update_sel(&tag_nav, index);
}
@@ -406,7 +406,7 @@ seek_next_selected_tag(void)
void
delete_current_tag(void)
{
- struct link *link;
+ struct list_link *link;
struct tag *tag;
if (!confirm_popup("Delete tag?"))
@@ -414,19 +414,16 @@ delete_current_tag(void)
link = list_at(&tags, tag_nav.sel);
if (!link) return;
- tag = UPCAST(link, struct tag, link);
- if (link_inuse(&tag->link_sel))
+ tag = LIST_UPCAST(link, struct tag, link);
+ if (list_link_inuse(&tag->link_sel))
playlist_outdated = true;
tag_rm(tag, true);
}
bool
-tag_name_cmp(struct link *l1, struct link *l2)
+tag_name_cmp(const void *p1, const void *p2, void *user)
{
- struct tag *t1, *t2;
-
- t1 = LINK_UPCAST(l1, struct tag, link);
- t2 = LINK_UPCAST(l2, struct tag, link);
+ const struct tag *t1 = p1, *t2 = p2;
return strcasecmp(t1->name, t2->name) <= 0;
}
@@ -434,7 +431,8 @@ tag_name_cmp(struct link *l1, struct link *l2)
void
sort_visible_tags(void)
{
- list_sort(&tags, false, tag_name_cmp);
+ list_insertion_sort(&tags, false, tag_name_cmp,
+ LIST_OFFSET(struct tag, link), NULL);
}
bool
@@ -488,7 +486,7 @@ void
tag_pane_vis(struct pane *pane, int sel)
{
struct tag *tag;
- struct link *link;
+ struct list_link *link;
int index, tagsel;
werase(pane->win);
@@ -499,8 +497,8 @@ tag_pane_vis(struct pane *pane, int sel)
index = -1;
for (LIST_ITER(&tags, link)) {
- tag = UPCAST(link, struct tag, link);
- tagsel = link_inuse(&tag->link_sel);
+ tag = LIST_UPCAST(link, struct tag, link);
+ tagsel = list_link_inuse(&tag->link_sel);
index += 1;
if (index < tag_nav.wmin) continue;
@@ -531,7 +529,7 @@ tag_pane_vis(struct pane *pane, int sel)
bool
play_current_track(void)
{
- struct link *link;
+ struct list_link *link;
struct track *track;
link = list_at(tracks_vis, track_nav.sel);
@@ -561,7 +559,7 @@ nav_to_track_tag(struct track *target)
bool
nav_to_track(struct track *target)
{
- struct link *link;
+ struct list_link *link;
struct track *track;
int index;
@@ -583,7 +581,7 @@ nav_to_track(struct track *target)
bool
rename_current_track(void)
{
- struct link *link;
+ struct list_link *link;
struct track *track;
char *cmd;
@@ -602,7 +600,7 @@ rename_current_track(void)
bool
delete_current_track(void)
{
- struct link *link;
+ struct list_link *link;
struct track *track;
link = list_at(tracks_vis, track_nav.sel);
@@ -626,33 +624,30 @@ delete_current_track(void)
void
queue_current_track(void)
{
- struct link *link;
+ struct list_link *link;
struct track *track;
link = list_at(tracks_vis, track_nav.sel);
if (!link) return;
track = tracks_vis_track(link);
- list_push_back(&player.queue, &track->link_pq);
+ list_insert_back(&player.queue, &track->link_pq);
}
void
unqueue_last_track(void)
{
- struct link *link;
+ struct list_link *link;
link = list_back(&player.queue);
if (!link) return;
- link_pop(link);
+ list_link_pop(link);
}
bool
-track_vis_name_cmp(struct link *l1, struct link *l2)
+track_vis_name_cmp(const void *p1, const void *p2, void *user)
{
- struct track *t1, *t2;
-
- t1 = tracks_vis_track(l1);
- t2 = tracks_vis_track(l2);
+ const struct track *t1 = p1, *t2 = p2;
return strcasecmp(t1->name, t2->name) <= 0;
}
@@ -660,15 +655,21 @@ track_vis_name_cmp(struct link *l1, struct link *l2)
void
sort_visible_tracks(void)
{
- struct link *link;
+ struct list_link *link;
struct tag *tag;
- list_sort(tracks_vis, false, track_vis_name_cmp);
+ if (tracks_vis == &player.playlist) {
+ list_insertion_sort(tracks_vis, false, track_vis_name_cmp,
+ LIST_OFFSET(struct track, link_pl), NULL);
+ } else {
+ list_insertion_sort(tracks_vis, false, track_vis_name_cmp,
+ LIST_OFFSET(struct track, link_tt), NULL);
+ }
if (!track_show_playlist) {
link = list_at(&tags, tag_nav.sel);
if (!link) return;
- tag = LINK_UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
tag->reordered = true;
}
}
@@ -729,7 +730,7 @@ void
track_pane_vis(struct pane *pane, int sel)
{
struct track *track;
- struct link *link;
+ struct list_link *link;
struct tag *tag;
int index;
@@ -741,7 +742,7 @@ track_pane_vis(struct pane *pane, int sel)
if (!link) {
pane_title(pane, sel, "Tracks");
} else {
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
pane_title(pane, sel, "Tracks (%s)", tag->name);
}
}
@@ -838,10 +839,10 @@ bool
play_track(const char *query)
{
struct track *track;
- struct link *link;
+ struct list_link *link;
for (LIST_ITER(&tracks, link)) {
- track = UPCAST(link, struct track, link);
+ track = LIST_UPCAST(link, struct track, link);
if (!strcmp(track->name, query)) {
player_play_track(track, true);
return true;
@@ -856,7 +857,7 @@ nav_to_track_by_name(const char *query)
{
struct track *track;
struct tag *tag;
- struct link *link;
+ struct list_link *link;
const char *qtrack;
const char *qtag;
@@ -866,7 +867,7 @@ nav_to_track_by_name(const char *query)
qtrack += 1;
for (LIST_ITER(&tags, link)) {
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
if (!strncmp(tag->name, qtag, qtrack - qtag - 1))
break;
}
@@ -874,7 +875,7 @@ nav_to_track_by_name(const char *query)
return false;
for (LIST_ITER(&tag->tracks, link)) {
- track = UPCAST(link, struct track, link_tt);
+ track = LIST_UPCAST(link, struct track, link_tt);
if (!strcmp(track->name, qtrack)) {
nav_to_track_tag(track);
nav_to_track(track);
@@ -890,7 +891,7 @@ bool
nav_to_track_vis_by_name(const char *query)
{
struct track *track;
- struct link *link;
+ struct list_link *link;
for (LIST_ITER(tracks_vis, link)) {
track = tracks_vis_track(link);
@@ -908,13 +909,13 @@ bool
seek_tag(const char *query)
{
struct tag *tag;
- struct link *link;
+ struct list_link *link;
int index;
index = -1;
for (LIST_ITER(&tags, link)) {
index += 1;
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
if (!strcmp(tag->name, query)) {
listnav_update_sel(&tag_nav, index);
pane_after_cmd = tag_pane;
@@ -1025,7 +1026,7 @@ cmd_pane_vis(struct pane *pane, int sel)
{
static struct strbuf line = { 0 };
struct inputln *cmd;
- struct link *link;
+ struct list_link *link;
int index, offset;
werase(pane->win);
@@ -1100,7 +1101,7 @@ cmd_pane_vis(struct pane *pane, int sel)
if (cmd != history->input) {
index = 0;
for (LIST_ITER(&history->list, link)) {
- if (UPCAST(link, struct inputln, link) == cmd)
+ if (LIST_UPCAST(link, struct inputln, link) == cmd)
break;
index += 1;
}
@@ -1135,7 +1136,7 @@ cmd_pane_vis(struct pane *pane, int sel)
void
update_tracks_vis(void)
{
- struct link *link;
+ struct list_link *link;
struct tag *tag;
if (track_show_playlist) {
@@ -1143,7 +1144,7 @@ update_tracks_vis(void)
} else {
link = list_at(&tags, tag_nav.sel);
if (!link) return;
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
tracks_vis = &tag->tracks;
}
@@ -1153,7 +1154,7 @@ update_tracks_vis(void)
void
reindex_selected_tags(void)
{
- struct link *link;
+ struct list_link *link;
struct tag *tag;
struct track *track;
struct tag *playing_tag;
@@ -1169,19 +1170,19 @@ reindex_selected_tags(void)
if (track_show_playlist) {
for (LIST_ITER(&tags_sel, link)) {
- tag = UPCAST(link, struct tag, link_sel);
+ tag = LIST_UPCAST(link, struct tag, link_sel);
tag_reindex_tracks(tag);
}
} else {
link = list_at(&tags, tag_nav.sel);
if (!link) return;
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
tag_reindex_tracks(tag);
}
if (playing_tag) {
for (LIST_ITER(&playing_tag->tracks, link)) {
- track = UPCAST(link, struct track, link_tt);
+ track = LIST_UPCAST(link, struct track, link_tt);
if (!strcmp(track->name, playing_name)) {
player.track = track;
break;
@@ -1337,7 +1338,7 @@ tui_curses_init(void)
void
tui_resize(void)
{
- struct link *link;
+ struct list_link *link;
struct tag *tag;
int leftw;
@@ -1354,7 +1355,7 @@ tui_resize(void)
/* adjust tag pane width to name lengths */
leftw = 0;
for (LIST_ITER(&tags, link)) {
- tag = UPCAST(link, struct tag, link);
+ tag = LIST_UPCAST(link, struct tag, link);
leftw = MAX(leftw, strlen(tag->name));
}
leftw = MAX(leftw + 1, 0.2f * scrw);