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
28#include "misc/charset_conv.h"28#include "misc/charset_conv.h"
29#include "misc/thread_tools.h"29#include "misc/thread_tools.h"
30#include "options/path.h"30#include "options/path.h"
31#include "player/core.h"
31#include "stream/stream.h"32#include "stream/stream.h"
32#include "osdep/io.h"33#include "osdep/io.h"
33#include "misc/natural_sort.h"34#include "misc/natural_sort.h"
@@ -410,28 +411,17 @@ static int cmp_dir_entry(const void *a, const void *b) · 376 unmodified lines
410 }411 }
411}412}
412 413
413static 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
424static bool test_path(struct pl_parser *p, char *path, int autocreate)414static bool test_path(struct pl_parser *p, char *path, int autocreate)
425{415{
426 if (autocreate & AUTO_ANY)416 if (autocreate & AUTO_ANY)
427 return true;417 return true;
428 418
429 bstr ext = bstr_get_ext(bstr0(path));419 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))
431 return true;421 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))
433 return true;423 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))
435 return true;425 return true;
436 426
437 return false;427 return false;
@@ -521,11 +511,11 @@ static int parse_dir(struct pl_parser *p) · 83 unmodified lines
521 autocreate = AUTO_VIDEO | AUTO_AUDIO | AUTO_IMAGE;511 autocreate = AUTO_VIDEO | AUTO_AUDIO | AUTO_IMAGE;
522 break;512 break;
523 case 3: // same513 case 3: // same
524 if (has_str(ext, p->mp_opts->video_exts)) {514 if (str_in_list(ext, p->mp_opts->video_exts)) {
525 autocreate = AUTO_VIDEO;515 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)) {
527 autocreate = AUTO_AUDIO;517 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)) {
529 autocreate = AUTO_IMAGE;519 autocreate = AUTO_IMAGE;
530 }520 }
531 break;521 break;
@@ -543,11 +533,11 @@ static int parse_dir(struct pl_parser *p) · 11 unmodified lines
543 autocreate = AUTO_NONE;533 autocreate = AUTO_NONE;
544 if (!p->opts->directory_filter || !p->opts->directory_filter[0])534 if (!p->opts->directory_filter || !p->opts->directory_filter[0])
545 autocreate = AUTO_ANY;535 autocreate = AUTO_ANY;
546 if (has_str(bstr0("video"), p->opts->directory_filter))536 if (str_in_list(bstr0("video"), p->opts->directory_filter))
547 autocreate |= AUTO_VIDEO;537 autocreate |= AUTO_VIDEO;
548 if (has_str(bstr0("audio"), p->opts->directory_filter))538 if (str_in_list(bstr0("audio"), p->opts->directory_filter))
549 autocreate |= AUTO_AUDIO;539 autocreate |= AUTO_AUDIO;
550 if (has_str(bstr0("image"), p->opts->directory_filter))540 if (str_in_list(bstr0("image"), p->opts->directory_filter))
551 autocreate |= AUTO_IMAGE;541 autocreate |= AUTO_IMAGE;
552 }542 }
553 if (!stream->is_directory)543 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
565void error_on_track(struct MPContext *mpctx, struct track *track);565void error_on_track(struct MPContext *mpctx, struct track *track);
566int stream_dump(struct MPContext *mpctx, const char *source_filename);566int stream_dump(struct MPContext *mpctx, const char *source_filename);
567double get_track_seek_offset(struct MPContext *mpctx, struct track *track);567double get_track_seek_offset(struct MPContext *mpctx, struct track *track);
568bool str_in_list(bstr str, char **list);
568 569
569// osd.c570// osd.c
570void set_osd_bar(struct MPContext *mpctx, int type,571void set_osd_bar(struct MPContext *mpctx, int type,
player/external_files.c+5−16
@@ -28,30 +28,19 @@ · 27 unmodified lines
28#include "misc/language.h"28#include "misc/language.h"
29#include "options/options.h"29#include "options/options.h"
30#include "options/path.h"30#include "options/path.h"
31#include "player/core.h"
31#include "external_files.h"32#include "external_files.h"
32 33
33// Needed for mp_might_be_subtitle_file34// Needed for mp_might_be_subtitle_file
34char **sub_exts;35char **sub_exts;
35 36
36static 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 }
44done:
45 return false;
46}
47
48static int test_ext(MPOpts *opts, bstr ext)37static int test_ext(MPOpts *opts, bstr ext)
49{38{
50 if (test_ext_list(ext, opts->sub_auto_exts))39 if (str_in_list(ext, opts->sub_auto_exts))
51 return STREAM_SUB;40 return STREAM_SUB;
52 if (test_ext_list(ext, opts->audio_exts))41 if (str_in_list(ext, opts->audio_exts))
53 return STREAM_AUDIO;42 return STREAM_AUDIO;
54 if (test_ext_list(ext, opts->image_exts))43 if (str_in_list(ext, opts->image_exts))
55 return STREAM_VIDEO;44 return STREAM_VIDEO;
56 return -1;45 return -1;
57}46}
@@ -70,7 +59,7 @@ static int test_cover_filename(bstr fname, char **cover_files) · 12 unmodified lines
70 59
71bool mp_might_be_subtitle_file(const char *filename)60bool mp_might_be_subtitle_file(const char *filename)
72{61{
73 return test_ext_list(bstr_get_ext(bstr0(filename)), sub_exts);62 return str_in_list(bstr_get_ext(bstr0(filename)), sub_exts);
74}63}
75 64
76void mp_update_subtitle_exts(struct MPOpts *opts)65void 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
343 default: return "bug";343 default: return "bug";
344 }344 }
345}345}
346
347bool 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