• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __CUTILS_CONFIG_UTILS_H
18 #define __CUTILS_CONFIG_UTILS_H
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 typedef struct cnode cnode;
25 
26 
27 struct cnode
28 {
29     cnode *next;
30     cnode *first_child;
31     cnode *last_child;
32     const char *name;
33     const char *value;
34 };
35 
36 /* parse a text string into a config node tree */
37 void config_load(cnode *root, char *data);
38 
39 /* parse a file into a config node tree */
40 void config_load_file(cnode *root, const char *fn);
41 
42 /* create a single config node */
43 cnode* config_node(const char *name, const char *value);
44 
45 /* locate a named child of a config node */
46 cnode* config_find(cnode *root, const char *name);
47 
48 /* look up a child by name and return the boolean value */
49 int config_bool(cnode *root, const char *name, int _default);
50 
51 /* look up a child by name and return the string value */
52 const char* config_str(cnode *root, const char *name, const char *_default);
53 
54 /* add a named child to a config node (or modify it if it already exists) */
55 void config_set(cnode *root, const char *name, const char *value);
56 
57 /* free a config node tree */
58 void config_free(cnode *root);
59 
60 #ifdef __cplusplus
61 }
62 #endif
63 
64 #endif
65