aboutsummaryrefslogtreecommitdiffstats
path: root/samples/c/sample3.c
diff options
context:
space:
mode:
authorJonathan McCrohan <jmccrohan@gmail.com>2011-12-01 23:47:41 +0000
committerJonathan McCrohan <jmccrohan@gmail.com>2011-12-01 23:47:41 +0000
commit1eaceca55c7e62892fd28bfbb5fc03240a48cee3 (patch)
tree7243fcd09c57e06e72b15f0044fd2c77babd7843 /samples/c/sample3.c
parentd4b5ddf4bcacd692011f5a597025c38a1262d6ca (diff)
parent429e46051dba814e7d6c74368eb1bba550222cbe (diff)
downloadlibconfig-1eaceca55c7e62892fd28bfbb5fc03240a48cee3.tar.gz
Merge commit 'upstream/1.4.8'
Conflicts: debian/changelog debian/control debian/libconfig++9-dev.install debian/libconfig8.install debian/libconfig9-dev.install debian/rules
Diffstat (limited to 'samples/c/sample3.c')
-rw-r--r--samples/c/sample3.c104
1 files changed, 0 insertions, 104 deletions
diff --git a/samples/c/sample3.c b/samples/c/sample3.c
deleted file mode 100644
index 22f5f36..0000000
--- a/samples/c/sample3.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/*************************************************************************
- ** Sample3
- ** Load sample.cfg and try to add a setting "foo"..
- ** on success save to testfoo.cfg
- *************************************************************************/
-
-#include <stdio.h>
-#include <libconfig.h>
-
-/***************************************************************************/
-
-/*
- */
-
-int print_path(config_setting_t *setting)
-{
- if(setting)
- {
- const char *name = config_setting_name(setting);
-
- if(print_path(config_setting_parent(setting)))
- putchar('.');
-
- if(! config_setting_is_root(setting))
- {
- if(! name)
- printf("[%d]", config_setting_index(setting));
- else
- printf(name);
-
- return(1);
- }
- }
-
- return(0);
-}
-
-/*
- */
-
-int main()
-{
- struct config_t cfg;
- config_setting_t *setting = NULL;
- int i;
-
- do
- {
- /* Initialize the configuration */
- config_init(&cfg);
-
- /* Load the file */
- printf("loading [sample.cfg]...");
- if (!config_read_file(&cfg, "sample.cfg"))
- {
- puts("failed");
- break;
- }
-
- puts("ok");
-
- /* Add setting "foo" */
- printf("add setting \"foo\"...");
- setting = config_setting_add(cfg.root, "foo", CONFIG_TYPE_INT);
- if (!setting)
- {
- puts("failed");
- break;
- }
-
- config_setting_set_int(setting, 1234);
- puts("ok");
-
- /** Look up an array element */
- printf("looking up array element...");
- setting = config_lookup(&cfg, "arrays.values.[0]");
- if(! setting)
- {
- puts("failed");
- break;
- }
-
- printf("value is: %d\n", config_setting_get_int(setting));
- printf("path is: ");
- print_path(setting);
- putchar('\n');
-
- /* Save to "samplefoo.cfg" */
- printf("saving [samplefoo.cfg]...");
- config_write_file(&cfg, "samplefoo.cfg");
- puts("ok");
-
- puts("Done!");
- }
- while(0);
-
- /* Free the configuration */
- config_destroy(&cfg);
-
- return 0;
-}
-
-
-/***************************************************************************/