summaryrefslogtreecommitdiffstats
path: root/m_option.c
diff options
context:
space:
mode:
authorreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2005-10-12 16:35:37 +0000
committerreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2005-10-12 16:35:37 +0000
commit9474719abec111631f58c738b4ec2ef76ac1c6f8 (patch)
treec653e6d931c1103944c7e87742c123c8bcbc111a /m_option.c
parent1e85a471ab41ae7cdbd7251fbe5d0acae266bf0d (diff)
downloadmpv-9474719abec111631f58c738b4ec2ef76ac1c6f8.tar.bz2
mpv-9474719abec111631f58c738b4ec2ef76ac1c6f8.tar.xz
Add support for suboption escaping via both "" and %n%str syntax
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@16742 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'm_option.c')
-rw-r--r--m_option.c54
1 files changed, 41 insertions, 13 deletions
diff --git a/m_option.c b/m_option.c
index 67a445ebe1..135f2cee71 100644
--- a/m_option.c
+++ b/m_option.c
@@ -872,7 +872,6 @@ static int parse_subconf(m_option_t* opt,char *name, char *param, void* dst, int
char *subopt;
int nr = 0,i,r;
m_option_t *subopts;
- char *token;
char *p;
char** lst = NULL;
@@ -881,20 +880,54 @@ static int parse_subconf(m_option_t* opt,char *name, char *param, void* dst, int
subparam = malloc(strlen(param)+1);
subopt = malloc(strlen(param)+1);
- p = strdup(param); // In case that param is a static string (cf man strtok)
+ p = param;
subopts = opt->p;
- token = strtok(p, (char *)&(":"));
- while(token)
+ while(p[0])
{
- int sscanf_ret;
+ int sscanf_ret = 1;
+ int optlen = strcspn(p, ":=");
/* clear out */
subopt[0] = subparam[0] = 0;
+ strlcpy(subopt, p, optlen);
+ p = &p[optlen];
+ if (p[0] == '=') {
+ sscanf_ret = 2;
+ p = &p[1];
+ if (p[0] == '"') {
+ p = &p[1];
+ optlen = strcspn(p, "\"");
+ strlcpy(subparam, p, optlen);
+ p = &p[optlen];
+ if (p[0] != '"') {
+ mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Terminating '\"' missing for '%s'\n", subopt);
+ return M_OPT_INVALID;
+ }
+ p = &p[1];
+ } else if (p[0] == '%') {
+ p = &p[1];
+ optlen = (int)strtol(p, &p, 0);
+ if (!p || p[0] != '%' || (optlen > strlen(p) - 1)) {
+ mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid length %i for '%s'\n", optlen, subopt);
+ return M_OPT_INVALID;
+ }
+ p = &p[1];
+ strlcpy(subparam, p, optlen);
+ p = &p[optlen];
+ } else {
+ optlen = strcspn(p, ":");
+ strlcpy(subparam, p, optlen);
+ p = &p[optlen];
+ }
+ }
+ if (p[0] == ':')
+ p = &p[1];
+ else if (p[0]) {
+ mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Incorrect termination for '%s'\n", subopt);
+ return M_OPT_INVALID;
+ }
- sscanf_ret = sscanf(token, "%[^=]=%[^:]", subopt, subparam);
-
- mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "token: '%s', subopt='%s', subparam='%s' (ret: %d)\n", token, subopt, subparam, sscanf_ret);
switch(sscanf_ret)
{
case 1:
@@ -918,16 +951,11 @@ static int parse_subconf(m_option_t* opt,char *name, char *param, void* dst, int
nr++;
}
break;
- default:
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid subconfig argument! ('%s')\n", token);
- return M_OPT_INVALID;
}
- token = strtok(NULL, (char *)&(":"));
}
free(subparam);
free(subopt);
- free(p);
if(dst)
VAL(dst) = lst;