History

player/misc: add str_in_list() and use it

Kacper Michajłow committed 2 years ago

Commit 73b58721 parent b73445d4 files · +27 −36Browse files

Unified · Split

4 files
  1. demux/demux_playlist.c +10 −20
  2. player/core.h +1 −0
  3. player/external_files.c +5 −16
  4. player/misc.c +11 −0
demux/demux_playlist.c+10−20
@@ -28,6 +28,7 @@ · 27 unmodified lines
2828 #include "misc/charset_conv.h"
2929 #include "misc/thread_tools.h"
3030 #include "options/path.h"
31+#include "player/core.h"
3132 #include "stream/stream.h"
3233 #include "osdep/io.h"
3334 #include "misc/natural_sort.h"
@@ -410,28 +411,17 @@ static int cmp_dir_entry(const void *a, const void *b) · 376 unmodified lines
410411 }
411412 }
412413
413−static bool has_str(bstr ext, char **list)
414−{
415− if (!list)
416− return false;
417− while (*list) {
418− if (!bstrcasecmp0(ext, *list++))
419− return true;
420− }
421− return false;
422−}
423−
424414 static bool test_path(struct pl_parser *p, char *path, int autocreate)
425415 {
426416 if (autocreate & AUTO_ANY)
427417 return true;
428418
429419 bstr ext = bstr_get_ext(bstr0(path));
430− if (autocreate & AUTO_VIDEO && has_str(ext, p->mp_opts->video_exts))
420+ if (autocreate & AUTO_VIDEO && str_in_list(ext, p->mp_opts->video_exts))
431421 return true;
432− if (autocreate & AUTO_AUDIO && has_str(ext, p->mp_opts->audio_exts))
422+ if (autocreate & AUTO_AUDIO && str_in_list(ext, p->mp_opts->audio_exts))
433423 return true;
434− if (autocreate & AUTO_IMAGE && has_str(ext, p->mp_opts->image_exts))
424+ if (autocreate & AUTO_IMAGE && str_in_list(ext, p->mp_opts->image_exts))
435425 return true;
436426
437427 return false;
@@ -521,11 +511,11 @@ static int parse_dir(struct pl_parser *p) · 83 unmodified lines
521511 autocreate = AUTO_VIDEO | AUTO_AUDIO | AUTO_IMAGE;
522512 break;
523513 case 3: // same
524− if (has_str(ext, p->mp_opts->video_exts)) {
514+ if (str_in_list(ext, p->mp_opts->video_exts)) {
525515 autocreate = AUTO_VIDEO;
526− } else if (has_str(ext, p->mp_opts->audio_exts)) {
516+ } else if (str_in_list(ext, p->mp_opts->audio_exts)) {
527517 autocreate = AUTO_AUDIO;
528− } else if (has_str(ext, p->mp_opts->image_exts)) {
518+ } else if (str_in_list(ext, p->mp_opts->image_exts)) {
529519 autocreate = AUTO_IMAGE;
530520 }
531521 break;
@@ -543,11 +533,11 @@ static int parse_dir(struct pl_parser *p) · 11 unmodified lines
543533 autocreate = AUTO_NONE;
544534 if (!p->opts->directory_filter || !p->opts->directory_filter[0])
545535 autocreate = AUTO_ANY;
546− if (has_str(bstr0("video"), p->opts->directory_filter))
536+ if (str_in_list(bstr0("video"), p->opts->directory_filter))
547537 autocreate |= AUTO_VIDEO;
548− if (has_str(bstr0("audio"), p->opts->directory_filter))
538+ if (str_in_list(bstr0("audio"), p->opts->directory_filter))
549539 autocreate |= AUTO_AUDIO;
550− if (has_str(bstr0("image"), p->opts->directory_filter))
540+ if (str_in_list(bstr0("image"), p->opts->directory_filter))
551541 autocreate |= AUTO_IMAGE;
552542 }
553543 if (!stream->is_directory)
player/core.h+1−0
@@ -565,6 +565,7 @@ void update_window_title(struct MPContext *mpctx, bool force); · 564 unmodified lines
565565 void error_on_track(struct MPContext *mpctx, struct track *track);
566566 int stream_dump(struct MPContext *mpctx, const char *source_filename);
567567 double get_track_seek_offset(struct MPContext *mpctx, struct track *track);
568+bool str_in_list(bstr str, char **list);
568569
569570 // osd.c
570571 void set_osd_bar(struct MPContext *mpctx, int type,
player/external_files.c+5−16
@@ -28,30 +28,19 @@ · 27 unmodified lines
2828 #include "misc/language.h"
2929 #include "options/options.h"
3030 #include "options/path.h"
31+#include "player/core.h"
3132 #include "external_files.h"
3233
3334 // Needed for mp_might_be_subtitle_file
3435 char **sub_exts;
3536
36−static bool test_ext_list(bstr ext, char **list)
37−{
38− if (!list)
39− goto done;
40− for (int n = 0; list[n]; n++) {
41− if (bstrcasecmp(bstr0(list[n]), ext) == 0)
42− return true;
43− }
44−done:
45− return false;
46−}
47−
4837 static int test_ext(MPOpts *opts, bstr ext)
4938 {
50− if (test_ext_list(ext, opts->sub_auto_exts))
39+ if (str_in_list(ext, opts->sub_auto_exts))
5140 return STREAM_SUB;
52− if (test_ext_list(ext, opts->audio_exts))
41+ if (str_in_list(ext, opts->audio_exts))
5342 return STREAM_AUDIO;
54− if (test_ext_list(ext, opts->image_exts))
43+ if (str_in_list(ext, opts->image_exts))
5544 return STREAM_VIDEO;
5645 return -1;
5746 }
@@ -70,7 +59,7 @@ static int test_cover_filename(bstr fname, char **cover_files) · 12 unmodified lines
7059
7160 bool mp_might_be_subtitle_file(const char *filename)
7261 {
73− return test_ext_list(bstr_get_ext(bstr0(filename)), sub_exts);
62+ return str_in_list(bstr_get_ext(bstr0(filename)), sub_exts);
7463 }
7564
7665 void mp_update_subtitle_exts(struct MPOpts *opts)
player/misc.c+11−0
@@ -343,3 +343,14 @@ const char *mp_status_str(enum playback_status st) · 342 unmodified lines
343343 default: return "bug";
344344 }
345345 }
346+
347+bool str_in_list(bstr str, char **list)
348+{
349+ if (!list)
350+ return false;
351+ while (*list) {
352+ if (!bstrcasecmp0(str, *list++))
353+ return true;
354+ }
355+ return false;
356+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t