diff options
author | wm4 <wm4@nowhere> | 2013-01-13 16:13:13 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-01-13 17:32:39 +0100 |
commit | 20c9dfa61692d9ed741a91177d3fa185d73c02dd (patch) | |
tree | 8931b8f4036bbcc4941c8d372546b08dbd75e53b /core | |
parent | cbdee50f29e2d1c44453f7b5ed5d67296f7a16dc (diff) | |
download | mpv-20c9dfa61692d9ed741a91177d3fa185d73c02dd.tar.bz2 mpv-20c9dfa61692d9ed741a91177d3fa185d73c02dd.tar.xz |
Replace strsep() uses
This function sucks and apparently is not very portable (at least on
mingw, the configure check fails). Also remove the emulation of that
function from osdep/strsep*, and remove the configure check.
Diffstat (limited to 'core')
-rw-r--r-- | core/bstr.c | 13 | ||||
-rw-r--r-- | core/bstr.h | 1 | ||||
-rw-r--r-- | core/command.c | 14 |
3 files changed, 22 insertions, 6 deletions
diff --git a/core/bstr.c b/core/bstr.c index 5d8a47e9ac..a472fbfb02 100644 --- a/core/bstr.c +++ b/core/bstr.c @@ -121,6 +121,19 @@ struct bstr bstr_split(struct bstr str, const char *sep, struct bstr *rest) return bstr_splice(str, 0, end); } +// Unlike with bstr_split(), tok is a string, and not a set of char. +// If tok is in str, return true, and: concat(out_left, tok, out_right) == str +// Otherwise, return false, and set out_left==str, out_right=="" +bool bstr_split_tok(bstr str, const char *tok, bstr *out_left, bstr *out_right) +{ + bstr bsep = bstr0(tok); + int pos = bstr_find(str, bsep); + if (pos < 0) + pos = str.len; + *out_left = bstr_splice(str, 0, pos); + *out_right = bstr_cut(str, pos + bsep.len); + return pos != str.len; +} struct bstr bstr_splice(struct bstr str, int start, int end) { diff --git a/core/bstr.h b/core/bstr.h index dfe6f3a556..bcac6cdba3 100644 --- a/core/bstr.h +++ b/core/bstr.h @@ -65,6 +65,7 @@ struct bstr *bstr_splitlines(void *talloc_ctx, struct bstr str); struct bstr bstr_lstrip(struct bstr str); struct bstr bstr_strip(struct bstr str); struct bstr bstr_split(struct bstr str, const char *sep, struct bstr *rest); +bool bstr_split_tok(bstr str, const char *tok, bstr *out_left, bstr *out_right); struct bstr bstr_splice(struct bstr str, int start, int end); long long bstrtoll(struct bstr str, struct bstr *rest, int base); double bstrtod(struct bstr str, struct bstr *rest); diff --git a/core/command.c b/core/command.c index 1e4ccd88bc..bad1543224 100644 --- a/core/command.c +++ b/core/command.c @@ -51,7 +51,6 @@ #include "audio/filter/af.h" #include "video/decode/dec_video.h" #include "audio/decode/dec_audio.h" -#include "osdep/strsep.h" #include "sub/spudec.h" #include "core/path.h" #include "sub/ass_mp.h" @@ -2266,16 +2265,19 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) if (!sh_audio) break; char *af_args = strdup(cmd->args[0].v.s); - char *af_commands = af_args; - char *af_command; + bstr af_commands = bstr0(af_args); struct af_instance *af; - while ((af_command = strsep(&af_commands, ",")) != NULL) { + while (af_commands.len) { + bstr af_command; + bstr_split_tok(af_commands, ",", &af_command, &af_commands); + char *af_command0 = bstrdup0(NULL, af_command); if (cmd->id == MP_CMD_AF_DEL) { - af = af_get(mpctx->mixer.afilter, af_command); + af = af_get(mpctx->mixer.afilter, af_command0); if (af != NULL) af_remove(mpctx->mixer.afilter, af); } else - af_add(mpctx->mixer.afilter, af_command); + af_add(mpctx->mixer.afilter, af_command0); + talloc_free(af_command0); } reinit_audio_chain(mpctx); free(af_args); |