1
mirror of https://github.com/mpv-player/mpv synced 2024-12-24 07:33:46 +01:00

bstr: rename bstr() function to bstr0(), and typedef bstr to struct bstr

Replace all uses of bstr() with bstr0().
Also remove the ridiculous C++ workaround.
This commit is contained in:
wm4 2012-07-28 23:47:42 +02:00
parent ca0979a5db
commit 08caadb9c0
25 changed files with 91 additions and 95 deletions

22
bstr.h
View File

@ -29,13 +29,11 @@
/* NOTE: 'len' is size_t, but most string-handling functions below assume /* NOTE: 'len' is size_t, but most string-handling functions below assume
* that input size has been sanity checked and len fits in an int. * that input size has been sanity checked and len fits in an int.
*/ */
struct bstr { typedef struct bstr {
unsigned char *start; unsigned char *start;
size_t len; size_t len;
}; } bstr;
// demux_rtp.cpp (live555) C++ compilation workaround
#ifndef __cplusplus
// If str.start is NULL, return NULL. // If str.start is NULL, return NULL.
static inline char *bstrdup0(void *talloc_ctx, struct bstr str) static inline char *bstrdup0(void *talloc_ctx, struct bstr str)
{ {
@ -51,7 +49,7 @@ static inline struct bstr bstrdup(void *talloc_ctx, struct bstr str)
return r; return r;
} }
static inline struct bstr bstr(const unsigned char *s) static inline struct bstr bstr0(const unsigned char *s)
{ {
return (struct bstr){(unsigned char *)s, s ? strlen(s) : 0}; return (struct bstr){(unsigned char *)s, s ? strlen(s) : 0};
} }
@ -124,7 +122,7 @@ static inline bool bstr_startswith(struct bstr str, struct bstr prefix)
static inline bool bstr_startswith0(struct bstr str, const char *prefix) static inline bool bstr_startswith0(struct bstr str, const char *prefix)
{ {
return bstr_startswith(str, bstr(prefix)); return bstr_startswith(str, bstr0(prefix));
} }
static inline bool bstr_endswith(struct bstr str, struct bstr suffix) static inline bool bstr_endswith(struct bstr str, struct bstr suffix)
@ -136,31 +134,29 @@ static inline bool bstr_endswith(struct bstr str, struct bstr suffix)
static inline bool bstr_endswith0(struct bstr str, const char *suffix) static inline bool bstr_endswith0(struct bstr str, const char *suffix)
{ {
return bstr_endswith(str, bstr(suffix)); return bstr_endswith(str, bstr0(suffix));
} }
static inline int bstrcmp0(struct bstr str1, const char *str2) static inline int bstrcmp0(struct bstr str1, const char *str2)
{ {
return bstrcmp(str1, bstr(str2)); return bstrcmp(str1, bstr0(str2));
} }
static inline int bstrcasecmp0(struct bstr str1, const char *str2) static inline int bstrcasecmp0(struct bstr str1, const char *str2)
{ {
return bstrcasecmp(str1, bstr(str2)); return bstrcasecmp(str1, bstr0(str2));
} }
static inline int bstr_find0(struct bstr haystack, const char *needle) static inline int bstr_find0(struct bstr haystack, const char *needle)
{ {
return bstr_find(haystack, bstr(needle)); return bstr_find(haystack, bstr0(needle));
} }
static inline int bstr_eatstart0(struct bstr *s, char *prefix) static inline int bstr_eatstart0(struct bstr *s, char *prefix)
{ {
return bstr_eatstart(s, bstr(prefix)); return bstr_eatstart(s, bstr0(prefix));
} }
#endif
// create a pair (not single value!) for "%.*s" printf syntax // create a pair (not single value!) for "%.*s" printf syntax
#define BSTR_P(bstr) (int)((bstr).len), (bstr).start #define BSTR_P(bstr) (int)((bstr).len), (bstr).start

View File

@ -226,7 +226,7 @@ static int mp_property_generic_option(struct m_option *prop, int action,
{ {
char *optname = prop->priv; char *optname = prop->priv;
const struct m_option *opt = m_config_get_option(mpctx->mconfig, const struct m_option *opt = m_config_get_option(mpctx->mconfig,
bstr(optname)); bstr0(optname));
void *valptr = m_option_get_ptr(opt, &mpctx->opts); void *valptr = m_option_get_ptr(opt, &mpctx->opts);
switch (action) { switch (action) {
@ -1187,7 +1187,7 @@ static int levels_property_helper(int offset, m_option_t *prop, int action,
{ {
char *optname = prop->priv; char *optname = prop->priv;
const struct m_option *opt = m_config_get_option(mpctx->mconfig, const struct m_option *opt = m_config_get_option(mpctx->mconfig,
bstr(optname)); bstr0(optname));
int *valptr = (int *)m_option_get_ptr(opt, &mpctx->opts); int *valptr = (int *)m_option_get_ptr(opt, &mpctx->opts);
switch (action) { switch (action) {
@ -3220,7 +3220,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
case MP_CMD_LOADLIST: { case MP_CMD_LOADLIST: {
play_tree_t *e = parse_playlist_file(mpctx->mconfig, play_tree_t *e = parse_playlist_file(mpctx->mconfig,
bstr(cmd->args[0].v.s)); bstr0(cmd->args[0].v.s));
if (!e) if (!e)
mp_tmsg(MSGT_CPLAYER, MSGL_ERR, mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
"\nUnable to load playlist %s.\n", cmd->args[0].v.s); "\nUnable to load playlist %s.\n", cmd->args[0].v.s);

View File

@ -1546,7 +1546,7 @@ int mp_input_get_key_from_name(const char *name)
const char *p; const char *p;
while ((p = strchr(name, '+'))) { while ((p = strchr(name, '+'))) {
for (struct key_name *m = modifier_names; m->name; m++) for (struct key_name *m = modifier_names; m->name; m++)
if (!bstrcasecmp(bstr(m->name), if (!bstrcasecmp(bstr0(m->name),
(struct bstr){(char *)name, p - name})) { (struct bstr){(char *)name, p - name})) {
modifiers |= m->key; modifiers |= m->key;
goto found; goto found;
@ -1558,7 +1558,7 @@ found:
name = p + 1; name = p + 1;
} }
struct bstr bname = bstr(name); struct bstr bname = bstr0(name);
struct bstr rest; struct bstr rest;
int code = bstr_decode_utf8(bname, &rest); int code = bstr_decode_utf8(bname, &rest);

View File

@ -495,7 +495,7 @@ struct vf_instance *vf_open_plugin_noerr(struct MPOpts *opts,
void *vf_priv = m_struct_alloc(st); void *vf_priv = m_struct_alloc(st);
int n; int n;
for (n = 0; args && args[2 * n]; n++) for (n = 0; args && args[2 * n]; n++)
m_struct_set(st, vf_priv, args[2 * n], bstr(args[2 * n + 1])); m_struct_set(st, vf_priv, args[2 * n], bstr0(args[2 * n + 1]));
vf->priv = vf_priv; vf->priv = vf_priv;
args = NULL; args = NULL;
} else // Otherwise we should have the '_oldargs_' } else // Otherwise we should have the '_oldargs_'

View File

@ -524,8 +524,8 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
NULL, 0); NULL, 0);
char *filename = ftag ? ftag->value : NULL; char *filename = ftag ? ftag->value : NULL;
if (st->codec->codec_id == CODEC_ID_TTF) if (st->codec->codec_id == CODEC_ID_TTF)
demuxer_add_attachment(demuxer, bstr(filename), demuxer_add_attachment(demuxer, bstr0(filename),
bstr("application/x-truetype-font"), bstr0("application/x-truetype-font"),
(struct bstr){codec->extradata, (struct bstr){codec->extradata,
codec->extradata_size}); codec->extradata_size});
break; break;
@ -644,7 +644,7 @@ static demuxer_t *demux_open_lavf(demuxer_t *demuxer)
uint64_t end = av_rescale_q(c->end, c->time_base, uint64_t end = av_rescale_q(c->end, c->time_base,
(AVRational){1, 1000000000}); (AVRational){1, 1000000000});
t = av_dict_get(c->metadata, "title", NULL, 0); t = av_dict_get(c->metadata, "title", NULL, 0);
demuxer_add_chapter(demuxer, t ? bstr(t->value) : bstr(NULL), demuxer_add_chapter(demuxer, t ? bstr0(t->value) : bstr0(NULL),
start, end); start, end);
} }

View File

@ -1373,7 +1373,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track,
if (t->id == NULL) if (t->id == NULL)
goto error; goto error;
if (t->prefix) { if (t->prefix) {
if (!bstr_startswith0(bstr(track->codec_id), t->id)) if (!bstr_startswith0(bstr0(track->codec_id), t->id))
continue; continue;
} else { } else {
if (strcmp(track->codec_id, t->id)) if (strcmp(track->codec_id, t->id))
@ -1633,8 +1633,8 @@ static int demux_mkv_open(demuxer_t *demuxer)
if (ebml_master.doc_type.start == NULL) { if (ebml_master.doc_type.start == NULL) {
mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] File has EBML header but no doctype." mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] File has EBML header but no doctype."
" Assuming \"matroska\".\n"); " Assuming \"matroska\".\n");
} else if (bstrcmp(ebml_master.doc_type, bstr("matroska")) != 0 } else if (bstrcmp(ebml_master.doc_type, bstr0("matroska")) != 0
&& bstrcmp(ebml_master.doc_type, bstr("webm")) != 0) { && bstrcmp(ebml_master.doc_type, bstr0("webm")) != 0) {
mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] no head found\n"); mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] no head found\n");
talloc_free(parse_ctx.talloc_ctx); talloc_free(parse_ctx.talloc_ctx);
return 0; return 0;

View File

@ -1234,7 +1234,7 @@ int demux_seek(demuxer_t *demuxer, float rel_seek_secs, float audio_delay,
int demux_info_add(demuxer_t *demuxer, const char *opt, const char *param) int demux_info_add(demuxer_t *demuxer, const char *opt, const char *param)
{ {
return demux_info_add_bstr(demuxer, bstr(opt), bstr(param)); return demux_info_add_bstr(demuxer, bstr0(opt), bstr0(param));
} }
int demux_info_add_bstr(demuxer_t *demuxer, struct bstr opt, struct bstr param) int demux_info_add_bstr(demuxer_t *demuxer, struct bstr opt, struct bstr param)
@ -1244,8 +1244,8 @@ int demux_info_add_bstr(demuxer_t *demuxer, struct bstr opt, struct bstr param)
for (n = 0; info && info[2 * n] != NULL; n++) { for (n = 0; info && info[2 * n] != NULL; n++) {
if (!bstrcasecmp(opt, bstr(info[2*n]))) { if (!bstrcasecmp(opt, bstr0(info[2*n]))) {
if (!bstrcmp(param, bstr(info[2*n + 1]))) { if (!bstrcmp(param, bstr0(info[2*n + 1]))) {
mp_msg(MSGT_DEMUX, MSGL_V, "Demuxer info %.*s set to unchanged value %.*s\n", mp_msg(MSGT_DEMUX, MSGL_V, "Demuxer info %.*s set to unchanged value %.*s\n",
BSTR_P(opt), BSTR_P(param)); BSTR_P(opt), BSTR_P(param));
return 0; return 0;

View File

@ -486,7 +486,7 @@ static char *get_section(void *talloc_ctx, struct bstr source,
bool copy = false; bool copy = false;
while (source.len) { while (source.len) {
struct bstr line = bstr_strip_linebreaks(bstr_getline(source, &source)); struct bstr line = bstr_strip_linebreaks(bstr_getline(source, &source));
if (bstr_eatstart(&line, bstr(SECTION_HEADER))) { if (bstr_eatstart(&line, bstr0(SECTION_HEADER))) {
copy = bstrcmp0(line, section) == 0; copy = bstrcmp0(line, section) == 0;
} else if (copy) { } else if (copy) {
res = talloc_asprintf_append_buffer(res, "%.*s\n", BSTR_P(line)); res = talloc_asprintf_append_buffer(res, "%.*s\n", BSTR_P(line));
@ -631,7 +631,7 @@ static void compile_shaders(struct gl_priv *p)
void *tmp = talloc_new(NULL); void *tmp = talloc_new(NULL);
struct bstr src = bstr(vo_gl3_shaders); struct bstr src = bstr0(vo_gl3_shaders);
char *vertex_shader = get_section(tmp, src, "vertex_all"); char *vertex_shader = get_section(tmp, src, "vertex_all");
char *shader_prelude = get_section(tmp, src, "prelude"); char *shader_prelude = get_section(tmp, src, "prelude");
char *s_video = get_section(tmp, src, "frag_video"); char *s_video = get_section(tmp, src, "frag_video");
@ -1970,8 +1970,8 @@ static bool load_icc(struct gl_priv *p, const char *icc_file,
mp_msg(MSGT_VO, MSGL_INFO, "[gl] Opening 3D LUT cache in file '%s'.\n", mp_msg(MSGT_VO, MSGL_INFO, "[gl] Opening 3D LUT cache in file '%s'.\n",
icc_cache); icc_cache);
struct bstr cachedata = load_file(p, tmp, icc_cache); struct bstr cachedata = load_file(p, tmp, icc_cache);
if (bstr_eatstart(&cachedata, bstr(LUT3D_CACHE_HEADER)) if (bstr_eatstart(&cachedata, bstr0(LUT3D_CACHE_HEADER))
&& bstr_eatstart(&cachedata, bstr(cache_info)) && bstr_eatstart(&cachedata, bstr0(cache_info))
&& bstr_eatstart(&cachedata, iccdata) && bstr_eatstart(&cachedata, iccdata)
&& cachedata.len == talloc_get_size(output)) && cachedata.len == talloc_get_size(output))
{ {

View File

@ -412,7 +412,7 @@ static struct m_config_option *m_config_get_co(const struct m_config *config,
struct m_config_option *co; struct m_config_option *co;
for (co = config->opts; co; co = co->next) { for (co = config->opts; co; co = co->next) {
struct bstr coname = bstr(co->name); struct bstr coname = bstr0(co->name);
if ((co->opt->type->flags & M_OPT_TYPE_ALLOW_WILDCARD) if ((co->opt->type->flags & M_OPT_TYPE_ALLOW_WILDCARD)
&& bstr_endswith0(coname, "*")) { && bstr_endswith0(coname, "*")) {
coname.len--; coname.len--;
@ -500,7 +500,7 @@ static int parse_subopts(struct m_config *config, void *optstruct, char *name,
{ {
char **lst = NULL; char **lst = NULL;
// Split the argument into child options // Split the argument into child options
int r = m_option_type_subconfig.parse(NULL, bstr(""), param, false, &lst, int r = m_option_type_subconfig.parse(NULL, bstr0(""), param, false, &lst,
optstruct); optstruct);
if (r < 0) if (r < 0)
return r; return r;
@ -510,11 +510,11 @@ static int parse_subopts(struct m_config *config, void *optstruct, char *name,
char n[110]; char n[110];
if (snprintf(n, 110, "%s%s", prefix, lst[2 * i]) > 100) if (snprintf(n, 110, "%s%s", prefix, lst[2 * i]) > 100)
abort(); abort();
if (!m_config_get_option(config, bstr(n))) { if (!m_config_get_option(config, bstr0(n))) {
if (strncmp(lst[2 * i], "no-", 3)) if (strncmp(lst[2 * i], "no-", 3))
goto nosubopt; goto nosubopt;
snprintf(n, 110, "%s%s", prefix, lst[2 * i] + 3); snprintf(n, 110, "%s%s", prefix, lst[2 * i] + 3);
const struct m_option *o = m_config_get_option(config, bstr(n)); const struct m_option *o = m_config_get_option(config, bstr0(n));
if (!o || o->type != &m_option_type_flag) { if (!o || o->type != &m_option_type_flag) {
nosubopt: nosubopt:
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
@ -532,8 +532,8 @@ static int parse_subopts(struct m_config *config, void *optstruct, char *name,
} }
lst[2 * i + 1] = "no"; lst[2 * i + 1] = "no";
} }
int sr = m_config_parse_option(config, optstruct, bstr(n), int sr = m_config_parse_option(config, optstruct, bstr0(n),
bstr(lst[2 * i + 1]), false, set); bstr0(lst[2 * i + 1]), false, set);
if (sr < 0) { if (sr < 0) {
if (sr == M_OPT_MISSING_PARAM) { if (sr == M_OPT_MISSING_PARAM) {
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
@ -578,7 +578,7 @@ int m_config_parse_suboptions(struct m_config *config, void *optstruct,
{ {
if (!subopts || !*subopts) if (!subopts || !*subopts)
return 0; return 0;
return parse_subopts(config, optstruct, name, "", bstr(subopts), true); return parse_subopts(config, optstruct, name, "", bstr0(subopts), true);
} }

View File

@ -151,7 +151,7 @@ static inline int m_config_set_option0(struct m_config *config,
const char *name, const char *param, const char *name, const char *param,
bool ambiguous) bool ambiguous)
{ {
return m_config_set_option(config, bstr(name), bstr(param), ambiguous); return m_config_set_option(config, bstr0(name), bstr0(param), ambiguous);
} }
/* Check if an option setting is valid. /* Check if an option setting is valid.
@ -164,7 +164,7 @@ static inline int m_config_check_option0(struct m_config *config,
const char *name, const char *param, const char *name, const char *param,
bool ambiguous) bool ambiguous)
{ {
return m_config_check_option(config, bstr(name), bstr(param), ambiguous); return m_config_check_option(config, bstr0(name), bstr0(param), ambiguous);
} }
int m_config_parse_suboptions(struct m_config *config, void *optstruct, int m_config_parse_suboptions(struct m_config *config, void *optstruct,

View File

@ -58,7 +58,7 @@ static const struct m_option *m_option_list_findb(const struct m_option *list,
struct bstr name) struct bstr name)
{ {
for (int i = 0; list[i].name; i++) { for (int i = 0; list[i].name; i++) {
struct bstr lname = bstr(list[i].name); struct bstr lname = bstr0(list[i].name);
if ((list[i].type->flags & M_OPT_TYPE_ALLOW_WILDCARD) if ((list[i].type->flags & M_OPT_TYPE_ALLOW_WILDCARD)
&& bstr_endswith0(lname, "*")) { && bstr_endswith0(lname, "*")) {
lname.len--; lname.len--;
@ -72,7 +72,7 @@ static const struct m_option *m_option_list_findb(const struct m_option *list,
const m_option_t *m_option_list_find(const m_option_t *list, const char *name) const m_option_t *m_option_list_find(const m_option_t *list, const char *name)
{ {
return m_option_list_findb(list, bstr(name)); return m_option_list_findb(list, bstr0(name));
} }
// Default function that just does a memcpy // Default function that just does a memcpy
@ -857,7 +857,7 @@ static int parse_subconf(const m_option_t *opt, struct bstr name,
while (p.len) { while (p.len) {
int optlen = bstrcspn(p, ":="); int optlen = bstrcspn(p, ":=");
struct bstr subopt = bstr_splice(p, 0, optlen); struct bstr subopt = bstr_splice(p, 0, optlen);
struct bstr subparam = bstr(NULL); struct bstr subparam = bstr0(NULL);
p = bstr_cut(p, optlen); p = bstr_cut(p, optlen);
if (bstr_startswith0(p, "=")) { if (bstr_startswith0(p, "=")) {
p = bstr_cut(p, 1); p = bstr_cut(p, 1);
@ -1311,7 +1311,7 @@ static int get_obj_param(struct bstr opt_name, struct bstr obj_name,
return M_OPT_OUT_OF_RANGE; return M_OPT_OUT_OF_RANGE;
} }
opt = &desc->fields[(*nold)]; opt = &desc->fields[(*nold)];
r = m_option_parse(opt, bstr(opt->name), str, false, NULL); r = m_option_parse(opt, bstr0(opt->name), str, false, NULL);
if (r < 0) { if (r < 0) {
if (r > M_OPT_EXIT) if (r > M_OPT_EXIT)
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: " mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: "
@ -1439,7 +1439,7 @@ static int parse_obj_params(const m_option_t *opt, struct bstr name,
return M_OPT_INVALID; return M_OPT_INVALID;
desc = p->desc; desc = p->desc;
r = get_obj_params(name, bstr(desc->name), param, desc, p->separator, r = get_obj_params(name, bstr0(desc->name), param, desc, p->separator,
dst ? &opts : NULL); dst ? &opts : NULL);
if (r < 0) if (r < 0)
return r; return r;
@ -1449,7 +1449,7 @@ static int parse_obj_params(const m_option_t *opt, struct bstr name,
return 1; return 1;
for (r = 0; opts[r]; r += 2) for (r = 0; opts[r]; r += 2)
m_struct_set(desc, dst, opts[r], bstr(opts[r + 1])); m_struct_set(desc, dst, opts[r], bstr0(opts[r + 1]));
return 1; return 1;
} }
@ -1491,7 +1491,7 @@ static int parse_obj_settings(struct bstr opt, struct bstr str,
const m_struct_t *desc; const m_struct_t *desc;
m_obj_settings_t *ret = _ret ? *_ret : NULL; m_obj_settings_t *ret = _ret ? *_ret : NULL;
struct bstr param = bstr(NULL); struct bstr param = bstr0(NULL);
int idx = bstrchr(str, '='); int idx = bstrchr(str, '=');
if (idx >= 0) { if (idx >= 0) {
param = bstr_cut(str, idx + 1); param = bstr_cut(str, idx + 1);
@ -2004,7 +2004,7 @@ static int parse_custom_url(const m_option_t *opt, struct bstr name,
int p = bstrtoll(bstr_cut(portstr, idx + 1), NULL, 0); int p = bstrtoll(bstr_cut(portstr, idx + 1), NULL, 0);
char tmp[100]; char tmp[100];
snprintf(tmp, 99, "%d", p); snprintf(tmp, 99, "%d", p);
r = m_struct_set(desc, dst, "port", bstr(tmp)); r = m_struct_set(desc, dst, "port", bstr0(tmp));
if (r < 0) { if (r < 0) {
mp_msg(MSGT_CFGPARSER, MSGL_ERR, mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"Option %.*s: Error while setting port.\n", "Option %.*s: Error while setting port.\n",
@ -2043,7 +2043,7 @@ static int parse_custom_url(const m_option_t *opt, struct bstr name,
if (dst) { if (dst) {
char *fname = bstrdup0(NULL, bstr_cut(path, 1)); char *fname = bstrdup0(NULL, bstr_cut(path, 1));
url_unescape_string(fname, fname); url_unescape_string(fname, fname);
r = m_struct_set(desc, dst, "filename", bstr(fname)); r = m_struct_set(desc, dst, "filename", bstr0(fname));
talloc_free(fname); talloc_free(fname);
if (r < 0) { if (r < 0) {
mp_msg(MSGT_CFGPARSER, MSGL_ERR, mp_msg(MSGT_CFGPARSER, MSGL_ERR,

View File

@ -108,7 +108,7 @@ int m_property_do(const m_option_t *prop_list, const char *name,
if (!arg) if (!arg)
return M_PROPERTY_ERROR; return M_PROPERTY_ERROR;
val = calloc(1, opt->type->size); val = calloc(1, opt->type->size);
if ((r = m_option_parse(opt, bstr(opt->name), bstr(arg), false, if ((r = m_option_parse(opt, bstr0(opt->name), bstr0(arg), false,
val)) <= 0) { val)) <= 0) {
free(val); free(val);
return r; return r;

View File

@ -71,7 +71,7 @@ int m_struct_set(const m_struct_t *st, void *obj, const char *field,
return 0; return 0;
} }
if(f->type->parse(f, bstr(field), param, false, M_ST_MB_P(obj,f->p), NULL) < 0) { if(f->type->parse(f, bstr0(field), param, false, M_ST_MB_P(obj,f->p), NULL) < 0) {
mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Struct %s, field %s parsing error: %.*s\n", mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Struct %s, field %s parsing error: %.*s\n",
st->name, field, BSTR_P(param)); st->name, field, BSTR_P(param));
return 0; return 0;

View File

@ -1015,7 +1015,7 @@ static int libmpdemux_was_interrupted(struct MPContext *mpctx, int stop_play)
static int playtree_add_playlist(struct MPContext *mpctx, play_tree_t *entry) static int playtree_add_playlist(struct MPContext *mpctx, play_tree_t *entry)
{ {
play_tree_add_bpf(entry, bstr(mpctx->filename)); play_tree_add_bpf(entry, bstr0(mpctx->filename));
{ {
if (!entry) { if (!entry) {
@ -4212,7 +4212,7 @@ play_next_file:
// The entry is added to the main playtree after the switch(). // The entry is added to the main playtree after the switch().
break; break;
case MP_CMD_LOADLIST: case MP_CMD_LOADLIST:
entry = parse_playlist_file(mpctx->mconfig, bstr(cmd->args[0].v.s)); entry = parse_playlist_file(mpctx->mconfig, bstr0(cmd->args[0].v.s));
break; break;
case MP_CMD_QUIT: case MP_CMD_QUIT:
exit_player_with_rc(mpctx, EXIT_QUIT, exit_player_with_rc(mpctx, EXIT_QUIT,

View File

@ -55,7 +55,7 @@ static bool split_opt(struct bstr *opt, struct bstr *param, bool *old_syntax)
if (bstr_startswith0(*opt, "--")) { if (bstr_startswith0(*opt, "--")) {
*old_syntax = false; *old_syntax = false;
*opt = bstr_cut(*opt, 2); *opt = bstr_cut(*opt, 2);
*param = bstr(NULL); *param = bstr0(NULL);
int idx = bstrchr(*opt, '='); int idx = bstrchr(*opt, '=');
if (idx > 0) { if (idx > 0) {
*param = bstr_cut(*opt, idx + 1); *param = bstr_cut(*opt, idx + 1);
@ -88,7 +88,7 @@ static int map_to_option(struct m_config *config, bool old_syntax,
if (old_syntax) if (old_syntax)
return -3; return -3;
*optname = s; *optname = s;
*param = bstr("no"); *param = bstr0("no");
return 0; return 0;
} }
@ -118,7 +118,7 @@ play_tree_t *m_config_parse_mp_command_line(m_config_t *config, int argc,
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
//next: //next:
struct bstr opt = bstr(argv[i]); struct bstr opt = bstr0(argv[i]);
orig_opt = opt; orig_opt = opt;
/* check for -- (no more options id.) except --help! */ /* check for -- (no more options id.) except --help! */
if (!bstrcmp0(opt, "--")) { if (!bstrcmp0(opt, "--")) {
@ -150,7 +150,7 @@ play_tree_t *m_config_parse_mp_command_line(m_config_t *config, int argc,
continue; continue;
} }
struct bstr param = bstr(i+1 < argc ? argv[i+1] : NULL); struct bstr param = bstr0(i+1 < argc ? argv[i+1] : NULL);
bool old_syntax; bool old_syntax;
if (!no_more_opts && split_opt(&opt, &param, &old_syntax)) { if (!no_more_opts && split_opt(&opt, &param, &old_syntax)) {
// Handle some special arguments outside option parser. // Handle some special arguments outside option parser.
@ -220,7 +220,7 @@ play_tree_t *m_config_parse_mp_command_line(m_config_t *config, int argc,
if (r >= 0) { if (r >= 0) {
play_tree_t *pt = last_entry ? last_entry : last_parent; play_tree_t *pt = last_entry ? last_entry : last_parent;
if (r == 0) if (r == 0)
param = bstr(NULL); // for old_syntax case param = bstr0(NULL); // for old_syntax case
play_tree_set_param(pt, opt, param); play_tree_set_param(pt, opt, param);
} }
} }
@ -320,11 +320,11 @@ int m_config_preparse_command_line(m_config_t *config, int argc, char **argv,
config->mode = M_COMMAND_LINE_PRE_PARSE; config->mode = M_COMMAND_LINE_PRE_PARSE;
for (int i = 1 ; i < argc ; i++) { for (int i = 1 ; i < argc ; i++) {
struct bstr opt = bstr(argv[i]); struct bstr opt = bstr0(argv[i]);
// No more options after -- // No more options after --
if (!bstrcmp0(opt, "--")) if (!bstrcmp0(opt, "--"))
break; break;
struct bstr param = bstr(i+1 < argc ? argv[i+1] : NULL); struct bstr param = bstr0(i+1 < argc ? argv[i+1] : NULL);
bool old_syntax; bool old_syntax;
if (!split_opt(&opt, &param, &old_syntax)) if (!split_opt(&opt, &param, &old_syntax))
continue; // Ignore non-option arguments continue; // Ignore non-option arguments

2
path.c
View File

@ -185,7 +185,7 @@ struct bstr mp_dirname(const char *path)
{ {
struct bstr ret = {(uint8_t *)path, mp_basename(path) - path}; struct bstr ret = {(uint8_t *)path, mp_basename(path) - path};
if (ret.len == 0) if (ret.len == 0)
return bstr("."); return bstr0(".");
return ret; return ret;
} }

View File

@ -359,7 +359,7 @@ play_tree_set_params_from(play_tree_t* dest,play_tree_t* src) {
return; return;
for(i = 0; src->params[i].name != NULL ; i++) for(i = 0; src->params[i].name != NULL ; i++)
play_tree_set_param(dest, bstr(src->params[i].name), bstr(src->params[i].value)); play_tree_set_param(dest, bstr0(src->params[i].name), bstr0(src->params[i].value));
if(src->flags & PLAY_TREE_RND) // pass the random flag too if(src->flags & PLAY_TREE_RND) // pass the random flag too
dest->flags |= PLAY_TREE_RND; dest->flags |= PLAY_TREE_RND;

View File

@ -357,7 +357,7 @@ parse_pls(play_tree_parser_t* p) {
entry = play_tree_new(); entry = play_tree_new();
play_tree_add_file(entry,entries[num].file); play_tree_add_file(entry,entries[num].file);
if (entries[num].length) if (entries[num].length)
play_tree_set_param(entry, bstr("endpos"), bstr(entries[num].length)); play_tree_set_param(entry, bstr0("endpos"), bstr0(entries[num].length));
free(entries[num].file); free(entries[num].file);
if(list) if(list)
play_tree_append_entry(last_entry,entry); play_tree_append_entry(last_entry,entry);

View File

@ -355,7 +355,7 @@ static char *create_fname(struct MPContext *mpctx, char *template,
char *end = strchr(template, '}'); char *end = strchr(template, '}');
if (!end) if (!end)
goto error_exit; goto error_exit;
struct bstr prop = bstr_splice(bstr(template), 0, end - template); struct bstr prop = bstr_splice(bstr0(template), 0, end - template);
template = end + 1; template = end + 1;
char *s = do_format_property(mpctx, prop); char *s = do_format_property(mpctx, prop);
if (s) if (s)

View File

@ -164,7 +164,7 @@ static stream_t *open_stream_plugin(const stream_info_t *sinfo,
if(sinfo->opts_url) { if(sinfo->opts_url) {
m_option_t url_opt = m_option_t url_opt =
{ "stream url", arg , CONF_TYPE_CUSTOM_URL, 0, 0 ,0, (void *)sinfo->opts }; { "stream url", arg , CONF_TYPE_CUSTOM_URL, 0, 0 ,0, (void *)sinfo->opts };
if (m_option_parse(&url_opt, bstr("stream url"), bstr(filename), false, arg) < 0) { if (m_option_parse(&url_opt, bstr0("stream url"), bstr0(filename), false, arg) < 0) {
mp_tmsg(MSGT_OPEN,MSGL_ERR, "URL parsing failed on url %s\n",filename); mp_tmsg(MSGT_OPEN,MSGL_ERR, "URL parsing failed on url %s\n",filename);
m_struct_free(desc,arg); m_struct_free(desc,arg);
return NULL; return NULL;

View File

@ -91,7 +91,7 @@ static void append_dir_subtitles(struct MPOpts *opts,
FILE *f; FILE *f;
assert(strlen(fname) < 1e6); assert(strlen(fname) < 1e6);
struct bstr f_fname = bstr(mp_basename(fname)); struct bstr f_fname = bstr0(mp_basename(fname));
struct bstr f_fname_noext = bstrdup(tmpmem, strip_ext(f_fname)); struct bstr f_fname_noext = bstrdup(tmpmem, strip_ext(f_fname));
bstr_lower(f_fname_noext); bstr_lower(f_fname_noext);
struct bstr f_fname_trim = bstr_strip(f_fname_noext); struct bstr f_fname_trim = bstr_strip(f_fname_noext);
@ -107,7 +107,7 @@ static void append_dir_subtitles(struct MPOpts *opts,
mp_msg(MSGT_SUBREADER, MSGL_INFO, "Load subtitles in %.*s\n", BSTR_P(path)); mp_msg(MSGT_SUBREADER, MSGL_INFO, "Load subtitles in %.*s\n", BSTR_P(path));
struct dirent *de; struct dirent *de;
while ((de = readdir(d))) { while ((de = readdir(d))) {
struct bstr dename = bstr(de->d_name); struct bstr dename = bstr0(de->d_name);
void *tmpmem2 = talloc_new(tmpmem); void *tmpmem2 = talloc_new(tmpmem);
// retrieve various parts of the filename // retrieve various parts of the filename
@ -118,11 +118,11 @@ static void append_dir_subtitles(struct MPOpts *opts,
// If it's a .sub, check if there is a .idx with the same name. If // If it's a .sub, check if there is a .idx with the same name. If
// there is one, it's certainly a vobsub so we skip it. // there is one, it's certainly a vobsub so we skip it.
if (bstrcasecmp(tmp_fname_ext, bstr("sub")) == 0) { if (bstrcasecmp(tmp_fname_ext, bstr0("sub")) == 0) {
char *idxname = talloc_asprintf(tmpmem2, "%.*s.idx", char *idxname = talloc_asprintf(tmpmem2, "%.*s.idx",
(int)tmp_fname_noext.len, (int)tmp_fname_noext.len,
de->d_name); de->d_name);
char *idx = mp_path_join(tmpmem2, path, bstr(idxname)); char *idx = mp_path_join(tmpmem2, path, bstr0(idxname));
f = fopen(idx, "rt"); f = fopen(idx, "rt");
if (f) { if (f) {
fclose(f); fclose(f);
@ -143,7 +143,7 @@ static void append_dir_subtitles(struct MPOpts *opts,
while (1) { while (1) {
if (!sub_exts[i]) if (!sub_exts[i])
goto next_sub; goto next_sub;
if (bstrcasecmp(bstr(sub_exts[i]), tmp_fname_ext) == 0) if (bstrcasecmp(bstr0(sub_exts[i]), tmp_fname_ext) == 0)
break; break;
i++; i++;
} }
@ -156,7 +156,7 @@ static void append_dir_subtitles(struct MPOpts *opts,
if (lang.len) { if (lang.len) {
for (int n = 0; opts->sub_lang[n]; n++) { for (int n = 0; opts->sub_lang[n]; n++) {
if (bstr_startswith(lang, if (bstr_startswith(lang,
bstr(opts->sub_lang[n]))) { bstr0(opts->sub_lang[n]))) {
prio = 4; // matches the movie name + lang extension prio = 4; // matches the movie name + lang extension
break; break;
} }
@ -219,15 +219,15 @@ char **find_text_subtitles(struct MPOpts *opts, const char *fname)
if (opts->sub_paths) { if (opts->sub_paths) {
for (int i = 0; opts->sub_paths[i]; i++) { for (int i = 0; opts->sub_paths[i]; i++) {
char *path = mp_path_join(slist, mp_dirname(fname), char *path = mp_path_join(slist, mp_dirname(fname),
bstr(opts->sub_paths[i])); bstr0(opts->sub_paths[i]));
append_dir_subtitles(opts, &slist, &n, bstr(path), fname, 0); append_dir_subtitles(opts, &slist, &n, bstr0(path), fname, 0);
} }
} }
// Load subtitles in ~/.mplayer/sub limiting sub fuzziness // Load subtitles in ~/.mplayer/sub limiting sub fuzziness
char *mp_subdir = get_path("sub/"); char *mp_subdir = get_path("sub/");
if (mp_subdir) if (mp_subdir)
append_dir_subtitles(opts, &slist, &n, bstr(mp_subdir), fname, 1); append_dir_subtitles(opts, &slist, &n, bstr0(mp_subdir), fname, 1);
free(mp_subdir); free(mp_subdir);
// Sort subs by priority and append them // Sort subs by priority and append them
@ -247,7 +247,7 @@ char **find_vob_subtitles(struct MPOpts *opts, const char *fname)
int n = 0; int n = 0;
// Potential vobsub in the media directory // Potential vobsub in the media directory
struct bstr bname = bstr(mp_basename(fname)); struct bstr bname = bstr0(mp_basename(fname));
int pdot = bstrrchr(bname, '.'); int pdot = bstrrchr(bname, '.');
if (pdot >= 0) if (pdot >= 0)
bname.len = pdot; bname.len = pdot;
@ -257,9 +257,9 @@ char **find_vob_subtitles(struct MPOpts *opts, const char *fname)
if (opts->sub_paths) { if (opts->sub_paths) {
for (int i = 0; opts->sub_paths[i]; i++) { for (int i = 0; opts->sub_paths[i]; i++) {
char *path = mp_path_join(NULL, mp_dirname(fname), char *path = mp_path_join(NULL, mp_dirname(fname),
bstr(opts->sub_paths[i])); bstr0(opts->sub_paths[i]));
MP_GROW_ARRAY(vobs, n); MP_GROW_ARRAY(vobs, n);
vobs[n++] = mp_path_join(vobs, bstr(path), bname); vobs[n++] = mp_path_join(vobs, bstr0(path), bname);
talloc_free(path); talloc_free(path);
} }
} }
@ -268,7 +268,7 @@ char **find_vob_subtitles(struct MPOpts *opts, const char *fname)
char *mp_subdir = get_path("sub/"); char *mp_subdir = get_path("sub/");
if (mp_subdir) { if (mp_subdir) {
MP_GROW_ARRAY(vobs, n); MP_GROW_ARRAY(vobs, n);
vobs[n++] = mp_path_join(vobs, bstr(mp_subdir), bname); vobs[n++] = mp_path_join(vobs, bstr0(mp_subdir), bname);
} }
free(mp_subdir); free(mp_subdir);

View File

@ -215,7 +215,7 @@ void subassconvert_subrip(const char *orig, char *dest, int dest_buffer_size)
tag->has_size = true; tag->has_size = true;
has_valid_attr = true; has_valid_attr = true;
} else if (!bstrcmp0(attr, "color")) { } else if (!bstrcmp0(attr, "color")) {
if (bstr_eatstart(&val, bstr("#"))) { if (bstr_eatstart(&val, bstr0("#"))) {
// #RRGGBB format // #RRGGBB format
tag->color = bstrtoll(val, &val, 16) & 0x00ffffff; tag->color = bstrtoll(val, &val, 16) & 0x00ffffff;
if (val.len) if (val.len)
@ -227,7 +227,7 @@ void subassconvert_subrip(const char *orig, char *dest, int dest_buffer_size)
// Standard web colors // Standard web colors
for (int i = 0; i < FF_ARRAY_ELEMS(subrip_web_colors); i++) { for (int i = 0; i < FF_ARRAY_ELEMS(subrip_web_colors); i++) {
char *color = subrip_web_colors[i].s; char *color = subrip_web_colors[i].s;
if (bstrcasecmp(val, bstr(color)) == 0) { if (bstrcasecmp(val, bstr0(color)) == 0) {
tag->color = subrip_web_colors[i].v; tag->color = subrip_web_colors[i].v;
goto foundcolor; goto foundcolor;
} }

View File

@ -83,7 +83,7 @@ static enum cue_command read_cmd(struct bstr *data, struct bstr *out_params)
if (line.len == 0) if (line.len == 0)
return CUE_EMPTY; return CUE_EMPTY;
for (int n = 0; cue_command_strings[n].command != -1; n++) { for (int n = 0; cue_command_strings[n].command != -1; n++) {
struct bstr name = bstr(cue_command_strings[n].text); struct bstr name = bstr0(cue_command_strings[n].text);
if (bstr_startswith(line, name)) { if (bstr_startswith(line, name)) {
struct bstr rest = bstr_cut(line, name.len); struct bstr rest = bstr_cut(line, name.len);
if (rest.len && !strchr(WHITESPACE, rest.start[0])) if (rest.len && !strchr(WHITESPACE, rest.start[0]))
@ -187,12 +187,12 @@ static void add_source(struct MPContext *mpctx, struct stream *s,
static bool try_open(struct MPContext *mpctx, char *filename) static bool try_open(struct MPContext *mpctx, char *filename)
{ {
struct bstr bfilename = bstr(filename); struct bstr bfilename = bstr0(filename);
// Avoid trying to open itself or another .cue file. Best would be // Avoid trying to open itself or another .cue file. Best would be
// to check the result of demuxer auto-detection, but the demuxer // to check the result of demuxer auto-detection, but the demuxer
// API doesn't allow this without opening a full demuxer. // API doesn't allow this without opening a full demuxer.
if (bstr_case_endswith(bfilename, bstr(".cue")) if (bstr_case_endswith(bfilename, bstr0(".cue"))
|| bstrcasecmp(bstr(mpctx->demuxer->filename), bfilename) == 0) || bstrcasecmp(bstr0(mpctx->demuxer->filename), bfilename) == 0)
return false; return false;
int format = 0; int format = 0;
@ -210,7 +210,7 @@ static bool try_open(struct MPContext *mpctx, char *filename)
// fragile, but it's about the only way we have. // fragile, but it's about the only way we have.
// TODO: maybe also could check if the .bin file is a multiple of the Audio // TODO: maybe also could check if the .bin file is a multiple of the Audio
// CD sector size (2352 bytes) // CD sector size (2352 bytes)
if (!d && bstr_case_endswith(bfilename, bstr(".bin"))) { if (!d && bstr_case_endswith(bfilename, bstr0(".bin"))) {
mp_msg(MSGT_CPLAYER, MSGL_WARN, "CUE: Opening as BIN file!\n"); mp_msg(MSGT_CPLAYER, MSGL_WARN, "CUE: Opening as BIN file!\n");
d = demux_open(&mpctx->opts, s, DEMUXER_TYPE_RAWAUDIO, d = demux_open(&mpctx->opts, s, DEMUXER_TYPE_RAWAUDIO,
mpctx->opts.audio_id, mpctx->opts.audio_id,
@ -234,7 +234,7 @@ static bool open_source(struct MPContext *mpctx, struct bstr filename)
struct bstr dirname = mp_dirname(mpctx->demuxer->filename); struct bstr dirname = mp_dirname(mpctx->demuxer->filename);
struct bstr base_filename = bstr(mp_basename(bstrdup0(ctx, filename))); struct bstr base_filename = bstr0(mp_basename(bstrdup0(ctx, filename)));
if (!base_filename.len) { if (!base_filename.len) {
mp_msg(MSGT_CPLAYER, MSGL_WARN, mp_msg(MSGT_CPLAYER, MSGL_WARN,
"CUE: Invalid audio filename in .cue file!\n"); "CUE: Invalid audio filename in .cue file!\n");
@ -252,7 +252,7 @@ static bool open_source(struct MPContext *mpctx, struct bstr filename)
// are renamed. // are renamed.
struct bstr cuefile = struct bstr cuefile =
bstr_strip_ext(bstr(mp_basename(mpctx->demuxer->filename))); bstr_strip_ext(bstr0(mp_basename(mpctx->demuxer->filename)));
DIR *d = opendir(bstrdup0(ctx, dirname)); DIR *d = opendir(bstrdup0(ctx, dirname));
if (!d) if (!d)
@ -260,7 +260,7 @@ static bool open_source(struct MPContext *mpctx, struct bstr filename)
struct dirent *de; struct dirent *de;
while ((de = readdir(d))) { while ((de = readdir(d))) {
char *dename0 = de->d_name; char *dename0 = de->d_name;
struct bstr dename = bstr(dename0); struct bstr dename = bstr0(dename0);
if (bstr_case_startswith(dename, cuefile)) { if (bstr_case_startswith(dename, cuefile)) {
mp_msg(MSGT_CPLAYER, MSGL_WARN, "CUE: No useful audio filename " mp_msg(MSGT_CPLAYER, MSGL_WARN, "CUE: No useful audio filename "
"in .cue file found, trying with '%s' instead!\n", "in .cue file found, trying with '%s' instead!\n",

View File

@ -64,18 +64,18 @@ static int find_edl_source(struct edl_source *sources, int num_sources,
void build_edl_timeline(struct MPContext *mpctx) void build_edl_timeline(struct MPContext *mpctx)
{ {
const struct bstr file_prefix = bstr("<"); const struct bstr file_prefix = bstr0("<");
void *tmpmem = talloc_new(NULL); void *tmpmem = talloc_new(NULL);
struct bstr *lines = bstr_splitlines(tmpmem, mpctx->demuxer->file_contents); struct bstr *lines = bstr_splitlines(tmpmem, mpctx->demuxer->file_contents);
int linec = MP_TALLOC_ELEMS(lines); int linec = MP_TALLOC_ELEMS(lines);
struct bstr header = bstr("mplayer EDL file, version "); struct bstr header = bstr0("mplayer EDL file, version ");
if (!linec || !bstr_startswith(lines[0], header)) { if (!linec || !bstr_startswith(lines[0], header)) {
mp_msg(MSGT_CPLAYER, MSGL_ERR, "EDL: Bad EDL header!\n"); mp_msg(MSGT_CPLAYER, MSGL_ERR, "EDL: Bad EDL header!\n");
goto out; goto out;
} }
struct bstr version = bstr_strip(bstr_cut(lines[0], header.len)); struct bstr version = bstr_strip(bstr_cut(lines[0], header.len));
if (bstrcmp(bstr("2"), version)) { if (bstrcmp(bstr0("2"), version)) {
mp_msg(MSGT_CPLAYER, MSGL_ERR, "EDL: Unsupported EDL file version!\n"); mp_msg(MSGT_CPLAYER, MSGL_ERR, "EDL: Unsupported EDL file version!\n");
goto out; goto out;
} }
@ -125,7 +125,7 @@ void build_edl_timeline(struct MPContext *mpctx)
goto out; goto out;
} }
struct bstr dirname = mp_dirname(mpctx->demuxer->filename); struct bstr dirname = mp_dirname(mpctx->demuxer->filename);
char *fullname = mp_path_join(tmpmem, dirname, bstr(filename)); char *fullname = mp_path_join(tmpmem, dirname, bstr0(filename));
edl_ids[num_sources++] = (struct edl_source){id, fullname, i+1}; edl_ids[num_sources++] = (struct edl_source){id, fullname, i+1};
} }
@ -175,7 +175,7 @@ void build_edl_timeline(struct MPContext *mpctx)
if (!arg.len) if (!arg.len)
goto bad; goto bad;
int64_t val; int64_t val;
if (!bstrcmp(arg, bstr("*"))) if (!bstrcmp(arg, bstr0("*")))
val = -1; val = -1;
else if (isdigit(*arg.start)) { else if (isdigit(*arg.start)) {
val = bstrtoll(arg, &arg, 10) * 1000000000; val = bstrtoll(arg, &arg, 10) * 1000000000;

View File

@ -82,7 +82,7 @@ static char **find_files(const char *original_file, const char *suffix)
if (!strcmp(ep->d_name, basename)) if (!strcmp(ep->d_name, basename))
continue; continue;
char *name = mp_path_join(results, directory, bstr(ep->d_name)); char *name = mp_path_join(results, directory, bstr0(ep->d_name));
char *s1 = ep->d_name; char *s1 = ep->d_name;
char *s2 = basename; char *s2 = basename;
int matchlen = 0; int matchlen = 0;