Git init
[pkgs/e/elektra.git] / examples / cascading.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <kdb.h>
4
5 void BailOut (char * msg)
6 {
7         perror (msg);
8 }
9
10 int main()
11 {
12         KDB * h;
13         KeySet * myConfig = ksNew(0);
14         Key    * myKey;
15         char   * myValue;
16
17         /* Open the Key Database */
18         if ((h = kdbOpen()) != 0)
19                 BailOut ("Could not open Key Database");
20         
21         /* Get myapps keyset */
22         if (kdbGetByName(h, myConfig, "/examples", 0 ) == -1)
23                 BailOut ("Could not get Keys");
24
25         /* Find the key in the keyset */
26         if ((myKey = ksLookupByName (myConfig, "/examples/key", 0)) == NULL)
27                 BailOut ("Could not Lookup Key");
28
29         /* Get the value of the key */
30         if ((myValue = (char*) keyValue (myKey)) == NULL)
31                 BailOut ("Could not get Keyvalue");
32                 
33         /* Actually print the key */
34         printf ("%s\n", myValue);
35         /* Close the Key database */
36         kdbClose(h);
37         ksDel(myConfig);
38         return 0;
39 }
40