diff options
author | Don Anderson <dda@mongodb.com> | 2016-05-19 16:53:57 -0400 |
---|---|---|
committer | sueloverso <sue@mongodb.com> | 2016-05-19 16:53:57 -0400 |
commit | 40b21968b834b255f63aeaa548759c643243e606 (patch) | |
tree | 23b1b12ce61e8ed5be27d00bc8d81903d90d0150 | |
parent | df54fd30bd12cd5a8bf6ab817ed3fac877f4833a (diff) | |
download | mongo-40b21968b834b255f63aeaa548759c643243e606.tar.gz |
WT-2611 Modify wtperf to handle escaped quotes. (#2714)
* Modify wtperf to handle escaped quotes.
* Made local function static.
Added backslash in quote (normally redundant) needed to keep spell check sane.
Fixed C++ style comment.
-rw-r--r-- | bench/wtperf/config.c | 61 | ||||
-rw-r--r-- | dist/s_string.ok | 1 |
2 files changed, 57 insertions, 5 deletions
diff --git a/bench/wtperf/config.c b/bench/wtperf/config.c index e83d6fcceed..e2f541b2819 100644 --- a/bench/wtperf/config.c +++ b/bench/wtperf/config.c @@ -47,6 +47,53 @@ static void config_opt_usage(void); (strncmp(str, bytes, len) == 0 && (str)[(len)] == '\0') /* + * config_unescape -- + * Modify a string in place, replacing any backslash escape sequences. + * The modified string is always shorter. + */ +static int +config_unescape(char *orig) +{ + char ch, *dst, *s; + + for (dst = s = orig; *s != '\0';) { + if ((ch = *s++) == '\\') { + ch = *s++; + switch (ch) { + case 'b': + *dst++ = '\b'; + break; + case 'f': + *dst++ = '\f'; + break; + case 'n': + *dst++ = '\n'; + break; + case 'r': + *dst++ = '\r'; + break; + case 't': + *dst++ = '\t'; + break; + case '\\': + case '/': + case '\"': /* Backslash needed for spell check. */ + *dst++ = ch; + break; + default: + /* Note: Unicode (\u) not implemented. */ + fprintf(stderr, + "invalid escape in string: %s\n", orig); + return (EINVAL); + } + } else + *dst++ = ch; + } + *dst = '\0'; + return (0); +} + +/* * config_assign -- * Assign the src config to the dest, any storage allocated in dest is * freed as a result. @@ -363,7 +410,8 @@ static int config_opt(CONFIG *cfg, WT_CONFIG_ITEM *k, WT_CONFIG_ITEM *v) { CONFIG_OPT *popt; - char *newstr, **strp; + char *begin, *newstr, **strp; + int ret; size_t i, newlen, nopt; void *valueloc; @@ -438,16 +486,19 @@ config_opt(CONFIG *cfg, WT_CONFIG_ITEM *k, WT_CONFIG_ITEM *v) } strp = (char **)valueloc; newlen = v->len + 1; - if (*strp == NULL) { - newstr = dstrdup(v->str); - } else { + if (*strp == NULL) + begin = newstr = dstrdup(v->str); + else { newlen += (strlen(*strp) + 1); newstr = dcalloc(newlen, sizeof(char)); snprintf(newstr, newlen, "%s,%*s", *strp, (int)v->len, v->str); /* Free the old value now we've copied it. */ free(*strp); + begin = &newstr[newlen - 1 - v->len]; } + if ((ret = config_unescape(begin)) != 0) + return (ret); *strp = newstr; break; case STRING_TYPE: @@ -531,7 +582,7 @@ config_opt_file(CONFIG *cfg, const char *filename) * WiredTiger configuration string compatible string, and using * the WiredTiger configuration parser to parse it at once. */ -#define WTPERF_CONFIG_DELIMS "\n\\" +#define WTPERF_CONFIG_DELIMS "\n" for (line = strtok(file_buf, WTPERF_CONFIG_DELIMS); line != NULL; line = strtok(NULL, WTPERF_CONFIG_DELIMS)) { diff --git a/dist/s_string.ok b/dist/s_string.ok index 81d09a55225..8debd9c3360 100644 --- a/dist/s_string.ok +++ b/dist/s_string.ok @@ -1079,6 +1079,7 @@ uncompresssed undef unencrypted unesc +unescape unescaped unicode uninstantiated |