From b4bcfa1da5c1be9f7999d4d4df4e8d1b73c3061a Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Sun, 10 Nov 2024 15:40:44 -0500 Subject: Make list entry name a wide string Signed-off-by: Andrew Opalach --- src/liana/list.c | 8 ++++---- src/liana/list.h | 6 +++--- src/liana/list_cmp.h | 51 ++++++++++++++++++++++++++++++--------------------- 3 files changed, 37 insertions(+), 28 deletions(-) (limited to 'src/liana') diff --git a/src/liana/list.c b/src/liana/list.c index fc34aca..df91140 100644 --- a/src/liana/list.c +++ b/src/liana/list.c @@ -435,7 +435,7 @@ static void handle_clear(struct lia_list *list) { struct lia_list_entry *entry; al_array_foreach(list->entries, i, entry) { - al_str_free(&entry->name); + al_wstr_free(&entry->name); al_free(entry); } list->entries.size = 0; @@ -532,7 +532,7 @@ void lia_list_remove_sink(struct lia_list *list, void *userdata) pump_queue(list); } -void lia_list_add(struct lia_list *list, void *opaque, u64 duration, str *name) +void lia_list_add(struct lia_list *list, void *opaque, u64 duration, wstr *name) { struct lia_list_entry *entry = al_alloc_object(struct lia_list_entry); entry->opaque = opaque; @@ -541,7 +541,7 @@ void lia_list_add(struct lia_list *list, void *opaque, u64 duration, str *name) entry->offset = 0; entry->ended = false; entry->duration = duration; - al_str_clone(&entry->name, name); + al_wstr_clone(&entry->name, name); entry->list = list; struct lia_list_cmd *cmd = al_alloc_object(struct lia_list_cmd); cmd->op = ADD; @@ -643,7 +643,7 @@ void lia_list_free(struct lia_list *list) { struct lia_list_entry *entry; al_array_foreach(list->entries, i, entry) { - al_str_free(&entry->name); + al_wstr_free(&entry->name); al_free(entry); } al_array_free(list->entries); diff --git a/src/liana/list.h b/src/liana/list.h index 270ef98..4f56641 100644 --- a/src/liana/list.h +++ b/src/liana/list.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #define LIANA_SEQUENCE_ANY -1 @@ -56,7 +56,7 @@ struct lia_list_entry { u64 offset; bool ended; u64 duration; - str name; + wstr name; struct lia_list *list; }; @@ -98,7 +98,7 @@ void lia_list_pump(struct lia_list *list); void lia_list_add_sink(struct lia_list *list, void (*callback)(void *, u8, struct lia_list_entry *, s32, struct lia_timing *), void *userdata); void lia_list_remove_sink(struct lia_list *list, void *userdata); -void lia_list_add(struct lia_list *list, void *opaque, u64 duration, str *name); +void lia_list_add(struct lia_list *list, void *opaque, u64 duration, wstr *name); void lia_list_unset(struct lia_list *list); void lia_list_skipto(struct lia_list *list, s32 sequence, s32 i); void lia_list_skip(struct lia_list *list, s32 sequence, s32 n); diff --git a/src/liana/list_cmp.h b/src/liana/list_cmp.h index 1f77b46..ef923fb 100644 --- a/src/liana/list_cmp.h +++ b/src/liana/list_cmp.h @@ -4,32 +4,39 @@ #include "list.h" -static void camu_db_num_from_path(str *path, s64 *id, s64 *index) +AL_UNUSED_FUNCTION_PUSH + +static void camu_db_num_from_path(wstr *path, s64 *id, s64 *index) { - s32 index0 = al_str_rfind(path, '/'); + s32 index0 = al_wstr_rfind(path, L'/'); if (index0 < 0) return; - str s = *al_str_substr(path, index0 + 1, path->len); - index0 = al_str_find(&s, '_'); + wstr w = *al_wstr_substr(path, index0 + 1, path->len); + index0 = al_wstr_find(&w, L'_'); if (index0 < 0) return; - s = *al_str_substr(&s, index0 + 1, s.len); - index0 = al_str_find(&s, '_'); + w = *al_wstr_substr(&w, index0 + 1, w.len); + index0 = al_wstr_find(&w, L'_'); if (index0 < 0) return; - s = *al_str_substr(&s, index0 + 1, s.len); - index0 = al_str_find(&s, '_'); + w = *al_wstr_substr(&w, index0 + 1, w.len); + index0 = al_wstr_find(&w, L'_'); if (index0 < 0) return; - s = *al_str_substr(&s, 0, index0); + w = *al_wstr_substr(&w, 0, index0); + str s; + al_wstr_to_str(&w, &s); s64 num = al_str_to_long(&s, 10); + al_str_free(&s); if (num == INT64_MIN || num == INT64_MAX) return; *id = num; - index0 = al_str_rfind(path, '.'); - s32 index1 = al_str_rfind(path, 'a'); + index0 = al_wstr_rfind(path, L'.'); + s32 index1 = al_wstr_rfind(path, 'a'); if (index0 < 0 || index1 < 0) return; - s = *al_str_substr(path, index1 + 1, index0); + w = *al_wstr_substr(path, index1 + 1, index0); + al_wstr_to_str(&w, &s); num = al_str_to_long(&s, 10); + al_str_free(&s); if (num == INT64_MIN || num == INT64_MAX) return; *index = num; } @@ -38,16 +45,18 @@ static s32 camu_db_compare(const void *a, const void *b) { struct lia_list_entry *aa = *((struct lia_list_entry **)a); struct lia_list_entry *bb = *((struct lia_list_entry **)b); - s64 anum = -1, aindex = -1; - s64 bnum = -1, bindex = -1; - camu_db_num_from_path(&aa->name, &anum, &aindex); - camu_db_num_from_path(&bb->name, &bnum, &bindex); - if (anum == bnum) { - if (aindex > bindex) return 1; - else if (aindex < bindex) return -1; + s64 a_id = -1, a_index = -1; + s64 b_id = -1, b_index = -1; + camu_db_num_from_path(&aa->name, &a_id, &a_index); + camu_db_num_from_path(&bb->name, &b_id, &b_index); + if (a_id == b_id) { + if (a_index > b_index) return 1; + else if (a_index < b_index) return -1; } else { - if (anum > bnum) return -1; - else if (anum < bnum) return 1; + if (a_id > b_id) return -1; + else if (a_id < b_id) return 1; } return 0; } + +AL_UNUSED_FUNCTION_PUSH -- cgit v1.2.3-101-g0448