Git init
[pkgs/e/elektra.git] / examples / keyset.c
1 #include <kdb.h>
2 #include <stdio.h>
3
4 void f (const Key * source)
5 {
6         Key * dup = keyDup (source);
7         printf ("\tin f\n");
8
9         keyDel (dup);
10 }
11
12 void g (const Key * source, KeySet * ks)
13 {
14         Key * dup = keyDup (source);
15         printf ("\tin g\n");
16
17         ksAppendKey (ks, dup);
18 }
19
20 void h (Key *k)
21 {
22         Key * c = keyNew("user/from/h", KEY_END);
23         printf ("\tin h\n");
24
25         keyCopy (k, c);
26         keyDel (c);
27         /* the caller will see the changed key k */
28 }
29
30 int main()
31 {
32         Key * origKey;
33         KeySet * ks = ksNew(0);
34
35         Key * key = keyNew ("user/test/name",
36                         KEY_VALUE, "myvalue",
37                         KEY_END);
38         printf ("Created key %s with value %s\n",
39                         keyName(key), keyValue(key));
40
41         f(key);
42         printf ("Key is unchanged with value %s\n",
43                         keyValue(key));
44
45         g(key, ks);
46         printf ("A duplication was appended in keyset with name %s\n",
47                         keyName(ksHead(ks)));
48
49         h(key);
50         printf ("Key has changed to name %s with value %s\n",
51                         keyName(key), keyValue(key));
52
53         /* key is yet independent */
54         keyDel (key);
55
56         ksRewind (ks);
57         origKey = ksNext (ks);
58         key = keyDup (origKey);
59         printf ("A duplication of the key %s with value %s\n",
60                         keyName(key), keyValue(key));
61
62         keyDel (key);
63         ksDel (ks);
64         return 0;
65 }