diff options
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | bstr.c | 51 | ||||
-rw-r--r-- | bstr.h | 39 | ||||
-rw-r--r-- | libmpdemux/demux_mkv.c | 4 | ||||
-rw-r--r-- | libmpdemux/ebml.c | 4 | ||||
-rw-r--r-- | libmpdemux/ebml.h | 6 |
6 files changed, 96 insertions, 9 deletions
@@ -331,6 +331,7 @@ SRCS_COMMON-$(ZR) += libmpcodecs/vd_zrmjpeg.c \ libmpcodecs/vf_zrmjpeg.c SRCS_COMMON = asxparser.c \ av_log.c \ + bstr.c \ codec-cfg.c \ cpudetect.c \ defaultopts.c \ diff --git a/bstr.c b/bstr.c new file mode 100644 index 0000000000..3cc3928086 --- /dev/null +++ b/bstr.c @@ -0,0 +1,51 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <string.h> +#include <libavutil/avutil.h> +#include "bstr.h" + +int bstrcmp(struct bstr str1, struct bstr str2) +{ + int ret = memcmp(str1.start, str2.start, FFMIN(str1.len, str2.len)); + + if (!ret) { + if (str1.len == str2.len) + return 0; + else if (str1.len > str2.len) + return 1; + else + return -1; + } + return ret; +} + +int bstrcasecmp(struct bstr str1, struct bstr str2) +{ + int ret = strncasecmp(str1.start, str2.start, FFMIN(str1.len, str2.len)); + + if (!ret) { + if (str1.len == str2.len) + return 0; + else if (str1.len > str2.len) + return 1; + else + return -1; + } + return ret; +} diff --git a/bstr.h b/bstr.h new file mode 100644 index 0000000000..459bf70bef --- /dev/null +++ b/bstr.h @@ -0,0 +1,39 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPLAYER_BSTR_H +#define MPLAYER_BSTR_H + +#include <stdint.h> +#include <stddef.h> +#include <string.h> + +struct bstr { + const uint8_t *start; + size_t len; +}; + +int bstrcmp(struct bstr str1, struct bstr str2); +int bstrcasecmp(struct bstr str1, struct bstr str2); + +// Create bstr compound literal from null-terminated string +#define BSTR(s) (struct bstr){(s), (s) ? strlen(s) : 0} +// create a pair (not single value!) for "%.*s" printf syntax +#define BSTR_P(bstr) (int)((bstr).len), (bstr).start + +#endif /* MPLAYER_BSTR_H */ diff --git a/libmpdemux/demux_mkv.c b/libmpdemux/demux_mkv.c index 17b4691183..0a63df400e 100644 --- a/libmpdemux/demux_mkv.c +++ b/libmpdemux/demux_mkv.c @@ -862,7 +862,7 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer) (int) ((chapter.end / 60 / 1000) % 60), (int) ((chapter.end / 1000) % 60), (int) (chapter.end % 1000), - name.len, name.start); + BSTR_P(name)); if (idx == selected_edition){ demuxer_add_chapter(demuxer, name.start, name.len, @@ -920,7 +920,7 @@ static int demux_mkv_read_attachments(demuxer_t *demuxer) demuxer_add_attachment(demuxer, name.start, name.len, mime.start, mime.len, data, data_size); mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Attachment: %.*s, %.*s, %u bytes\n", - name.len, name.start, mime.len, mime.start, data_size); + BSTR_P(name), BSTR_P(mime), data_size); } out: diff --git a/libmpdemux/ebml.c b/libmpdemux/ebml.c index 166c5df5cd..28b4a4643a 100644 --- a/libmpdemux/ebml.c +++ b/libmpdemux/ebml.c @@ -612,9 +612,9 @@ static void ebml_parse_element(struct ebml_parse_ctx *ctx, void *target, strptr->len = length; if (ed->type == EBML_TYPE_STR) mp_msg(MSGT_DEMUX, MSGL_DBG2, "string \"%.*s\"\n", - strptr->len, strptr->start); + BSTR_P(*strptr)); else - mp_msg(MSGT_DEMUX, MSGL_DBG2, "binary %d bytes\n", + mp_msg(MSGT_DEMUX, MSGL_DBG2, "binary %zd bytes\n", strptr->len); break; diff --git a/libmpdemux/ebml.h b/libmpdemux/ebml.h index b2fed46fb9..395ffc4df5 100644 --- a/libmpdemux/ebml.h +++ b/libmpdemux/ebml.h @@ -24,6 +24,7 @@ #include <stdbool.h> #include "stream/stream.h" +#include "bstr.h" /* EBML version supported */ @@ -62,11 +63,6 @@ struct ebml_parse_ctx { bool no_error_messages; }; -struct bstr { - uint8_t *start; - int len; -}; - #include "ebml_types.h" #define EBML_ID_INVALID 0xffffffff |