summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlex Gorrod <alexg@wiredtiger.com>2014-02-24 15:38:48 +1100
committerAlex Gorrod <alexg@wiredtiger.com>2014-02-24 15:38:48 +1100
commit54b39fc72f084b1eecdb91e9c8250c9f601f6b8d (patch)
tree48416a92ba77055f824d60f71828df4bc664c2ab /examples
parentf507e9450947683ca55bf23b48779ee804d7163f (diff)
downloadmongo-54b39fc72f084b1eecdb91e9c8250c9f601f6b8d.tar.gz
Update the configuration parsing API. Not finalized, but a step closer.
Diffstat (limited to 'examples')
-rw-r--r--examples/c/Makefile.am1
-rw-r--r--examples/c/ex_config_parse.c99
-rw-r--r--examples/c/ex_data_source.c49
3 files changed, 100 insertions, 49 deletions
diff --git a/examples/c/Makefile.am b/examples/c/Makefile.am
index bd281df7130..5b43dcc2285 100644
--- a/examples/c/Makefile.am
+++ b/examples/c/Makefile.am
@@ -6,6 +6,7 @@ noinst_PROGRAMS = \
ex_all \
ex_call_center \
ex_config \
+ ex_config_parse \
ex_cursor \
ex_data_source \
ex_extending \
diff --git a/examples/c/ex_config_parse.c b/examples/c/ex_config_parse.c
new file mode 100644
index 00000000000..6456d7aeb61
--- /dev/null
+++ b/examples/c/ex_config_parse.c
@@ -0,0 +1,99 @@
+/*-
+ * Public Domain 2008-2014 WiredTiger, Inc.
+ *
+ * This is free and unencumbered software released into the public domain.
+ *
+ * Anyone is free to copy, modify, publish, use, compile, sell, or
+ * distribute this software, either in source code form or as a compiled
+ * binary, for any purpose, commercial or non-commercial, and by any
+ * means.
+ *
+ * In jurisdictions that recognize copyright laws, the author or authors
+ * of this software dedicate any and all copyright interest in the
+ * software to the public domain. We make this dedication for the benefit
+ * of the public at large and to the detriment of our heirs and
+ * successors. We intend this dedication to be an overt act of
+ * relinquishment in perpetuity of all present and future rights to this
+ * software under copyright law.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ex_config_parse.c
+ * This is an example demonstrating how to parse WiredTiger compatible
+ * configuration strings.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <wiredtiger.h>
+
+const char *home = NULL;
+
+int main(void)
+{
+ int ret;
+ {
+ /*! [WT_CONFIG_PARSER search] */
+ WT_CONFIG_ITEM v;
+ WT_CONFIG_PARSER *parser;
+ int64_t my_page_size;
+
+ const char *config_string = "path=/dev/loop,page_size=1024";
+
+ if ((ret = wiredtiger_config_parser_open(
+ NULL, config_string, strlen(config_string), &parser)) != 0) {
+ fprintf(stderr, "Error creating configuration parser: %s\n",
+ wiredtiger_strerror(ret));
+ return (ret);
+ }
+
+ /*
+ * Retrieve the value of the integer configuration string "page_size".
+ */
+ if ((ret = parser->search(parser, "page_size", &v)) != 0) {
+ fprintf(stderr,
+ "page_size configuration: %s", wiredtiger_strerror(ret));
+ return (ret);
+ }
+ my_page_size = v.val;
+ /*! [WT_CONFIG_PARSER search] */
+
+ (void)my_page_size;
+ }
+
+ {
+ /*! [WT_CONFIG_PARSER scan] */
+ WT_CONFIG_ITEM k, v;
+ WT_CONFIG_PARSER *parser;
+
+ const char *config_string = "path=/dev/loop,page_size=1024";
+
+ if ((ret = wiredtiger_config_parser_open(
+ NULL, config_string, strlen(config_string), &parser)) != 0) {
+ fprintf(stderr, "Error creating configuration parser: %s\n",
+ wiredtiger_strerror(ret));
+ return (ret);
+ }
+ /*
+ * Retrieve the values of the configuration strings.
+ */
+ while ((ret = parser->next(parser, &k, &v)) == 0) {
+ printf("%.*s:", (int)k.len, k.str);
+ if (v.type == WT_CONFIG_ITEM_STRING)
+ printf("%.*s\n", (int)v.len, v.str);
+ else if (v.type == WT_CONFIG_ITEM_NUM)
+ printf("%d\n", (int)v.val);
+ }
+ ret = parser->close(parser);
+ /*! [WT_CONFIG_PARSER scan] */
+ }
+
+ return (ret);
+}
diff --git a/examples/c/ex_data_source.c b/examples/c/ex_data_source.c
index daedce04075..953bb799340 100644
--- a/examples/c/ex_data_source.c
+++ b/examples/c/ex_data_source.c
@@ -339,30 +339,6 @@ my_open_cursor(WT_DATA_SOURCE *dsrc, WT_SESSION *session,
}
{
- /*! [WT_EXTENSION config_strget] */
- WT_CONFIG_ITEM v;
- int64_t my_data_source_page_size;
-
- /*
- * Retrieve the value of the integer type configuration string
- * "page_size" from a local string (as opposed to the provided
- * WT_CONFIG_ARG reference).
- */
- const char *config_string = "path=/dev/loop,page_size=1024";
-
- if ((ret = wt_api->config_strget(
- wt_api, session, config_string, "page_size", &v)) != 0) {
- (void)wt_api->err_printf(wt_api, session,
- "page_size configuration: %s", wiredtiger_strerror(ret));
- return (ret);
- }
- my_data_source_page_size = v.val;
- /*! [WT_EXTENSION config_strget] */
-
- (void)my_data_source_page_size;
- }
-
- {
/*! [WT_EXTENSION config_get] */
WT_CONFIG_ITEM v;
const char *my_data_source_key;
@@ -392,31 +368,6 @@ my_open_cursor(WT_DATA_SOURCE *dsrc, WT_SESSION *session,
}
{
- /*! [WT_EXTENSION config scan] */
- WT_CONFIG_ITEM k, v;
- WT_CONFIG_SCAN *scan;
-
- /*
- * Retrieve the value of the list type configuration string "paths".
- */
- if ((ret = wt_api->config_get(
- wt_api, session, config, "paths", &v)) != 0) {
- (void)wt_api->err_printf(wt_api, session,
- "paths configuration: %s", wiredtiger_strerror(ret));
- return (ret);
- }
-
- /*
- * Step through the list of entries.
- */
- ret = wt_api->config_scan_begin(wt_api, session, v.str, v.len, &scan);
- while ((ret = wt_api->config_scan_next(wt_api, scan, &k, &v)) == 0)
- printf("%.*s\n", (int)k.len, k.str);
- ret = wt_api->config_scan_end(wt_api, scan);
- /*! [WT_EXTENSION config scan] */
- }
-
- {
/*! [WT_EXTENSION collator config] */
/*
* Configure the appropriate collator.