From 73b58722e7db333d8b22bc77e6401cf0b6bb331d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Mon, 29 Jul 2024 20:54:06 +0200 Subject: [PATCH] player/misc: add str_in_list() and use it --- demux/demux_playlist.c | 30 ++++++++++-------------------- player/core.h | 1 + player/external_files.c | 21 +++++---------------- player/misc.c | 11 +++++++++++ 4 files changed, 27 insertions(+), 36 deletions(-) diff --git a/demux/demux_playlist.c b/demux/demux_playlist.c index 17e2cd165b..a157c05deb 100644 --- a/demux/demux_playlist.c +++ b/demux/demux_playlist.c @@ -28,6 +28,7 @@ #include "misc/charset_conv.h" #include "misc/thread_tools.h" #include "options/path.h" +#include "player/core.h" #include "stream/stream.h" #include "osdep/io.h" #include "misc/natural_sort.h" @@ -410,28 +411,17 @@ static int cmp_dir_entry(const void *a, const void *b) } } -static bool has_str(bstr ext, char **list) -{ - if (!list) - return false; - while (*list) { - if (!bstrcasecmp0(ext, *list++)) - return true; - } - return false; -} - static bool test_path(struct pl_parser *p, char *path, int autocreate) { if (autocreate & AUTO_ANY) return true; bstr ext = bstr_get_ext(bstr0(path)); - if (autocreate & AUTO_VIDEO && has_str(ext, p->mp_opts->video_exts)) + if (autocreate & AUTO_VIDEO && str_in_list(ext, p->mp_opts->video_exts)) return true; - if (autocreate & AUTO_AUDIO && has_str(ext, p->mp_opts->audio_exts)) + if (autocreate & AUTO_AUDIO && str_in_list(ext, p->mp_opts->audio_exts)) return true; - if (autocreate & AUTO_IMAGE && has_str(ext, p->mp_opts->image_exts)) + if (autocreate & AUTO_IMAGE && str_in_list(ext, p->mp_opts->image_exts)) return true; return false; @@ -521,11 +511,11 @@ static int parse_dir(struct pl_parser *p) autocreate = AUTO_VIDEO | AUTO_AUDIO | AUTO_IMAGE; break; case 3: // same - if (has_str(ext, p->mp_opts->video_exts)) { + if (str_in_list(ext, p->mp_opts->video_exts)) { autocreate = AUTO_VIDEO; - } else if (has_str(ext, p->mp_opts->audio_exts)) { + } else if (str_in_list(ext, p->mp_opts->audio_exts)) { autocreate = AUTO_AUDIO; - } else if (has_str(ext, p->mp_opts->image_exts)) { + } else if (str_in_list(ext, p->mp_opts->image_exts)) { autocreate = AUTO_IMAGE; } break; @@ -543,11 +533,11 @@ static int parse_dir(struct pl_parser *p) autocreate = AUTO_NONE; if (!p->opts->directory_filter || !p->opts->directory_filter[0]) autocreate = AUTO_ANY; - if (has_str(bstr0("video"), p->opts->directory_filter)) + if (str_in_list(bstr0("video"), p->opts->directory_filter)) autocreate |= AUTO_VIDEO; - if (has_str(bstr0("audio"), p->opts->directory_filter)) + if (str_in_list(bstr0("audio"), p->opts->directory_filter)) autocreate |= AUTO_AUDIO; - if (has_str(bstr0("image"), p->opts->directory_filter)) + if (str_in_list(bstr0("image"), p->opts->directory_filter)) autocreate |= AUTO_IMAGE; } if (!stream->is_directory) diff --git a/player/core.h b/player/core.h index e37851e100..4ed7872a4f 100644 --- a/player/core.h +++ b/player/core.h @@ -565,6 +565,7 @@ void update_window_title(struct MPContext *mpctx, bool force); void error_on_track(struct MPContext *mpctx, struct track *track); int stream_dump(struct MPContext *mpctx, const char *source_filename); double get_track_seek_offset(struct MPContext *mpctx, struct track *track); +bool str_in_list(bstr str, char **list); // osd.c void set_osd_bar(struct MPContext *mpctx, int type, diff --git a/player/external_files.c b/player/external_files.c index e1577a8607..996344405f 100644 --- a/player/external_files.c +++ b/player/external_files.c @@ -28,30 +28,19 @@ #include "misc/language.h" #include "options/options.h" #include "options/path.h" +#include "player/core.h" #include "external_files.h" // Needed for mp_might_be_subtitle_file char **sub_exts; -static bool test_ext_list(bstr ext, char **list) -{ - if (!list) - goto done; - for (int n = 0; list[n]; n++) { - if (bstrcasecmp(bstr0(list[n]), ext) == 0) - return true; - } -done: - return false; -} - static int test_ext(MPOpts *opts, bstr ext) { - if (test_ext_list(ext, opts->sub_auto_exts)) + if (str_in_list(ext, opts->sub_auto_exts)) return STREAM_SUB; - if (test_ext_list(ext, opts->audio_exts)) + if (str_in_list(ext, opts->audio_exts)) return STREAM_AUDIO; - if (test_ext_list(ext, opts->image_exts)) + if (str_in_list(ext, opts->image_exts)) return STREAM_VIDEO; return -1; } @@ -70,7 +59,7 @@ static int test_cover_filename(bstr fname, char **cover_files) bool mp_might_be_subtitle_file(const char *filename) { - return test_ext_list(bstr_get_ext(bstr0(filename)), sub_exts); + return str_in_list(bstr_get_ext(bstr0(filename)), sub_exts); } void mp_update_subtitle_exts(struct MPOpts *opts) diff --git a/player/misc.c b/player/misc.c index 3f5da68dc8..036da5cf0b 100644 --- a/player/misc.c +++ b/player/misc.c @@ -343,3 +343,14 @@ const char *mp_status_str(enum playback_status st) default: return "bug"; } } + +bool str_in_list(bstr str, char **list) +{ + if (!list) + return false; + while (*list) { + if (!bstrcasecmp0(str, *list++)) + return true; + } + return false; +}