• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2007-2008 The Android Open Source Project
2 **
3 ** This software is licensed under the terms of the GNU General Public
4 ** License version 2, as published by the Free Software Foundation, and
5 ** may be copied, distributed, and modified under those terms.
6 **
7 ** This program is distributed in the hope that it will be useful,
8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 ** GNU General Public License for more details.
11 */
12 #ifndef ANDROID_CONFIG_H
13 #define ANDROID_CONFIG_H
14 
15 /** ANDROID CONFIGURATION FILE SUPPORT
16  **
17  ** A configuration file is loaded as a simplre tree of (key,value)
18  ** pairs. keys and values are simple strings
19  **/
20 typedef struct AConfig  AConfig;
21 
22 struct AConfig
23 {
24     AConfig*     next;
25     AConfig*     first_child;
26     AConfig*     last_child;
27     const char*  name;
28     const char*  value;
29 };
30 
31 /* parse a text string into a config node tree */
32 extern void   aconfig_load(AConfig*  root, char*  data);
33 
34 /* parse a file into a config node tree, return 0 in case of success, -1 otherwise */
35 extern int    aconfig_load_file(AConfig*  root, const char*  path);
36 
37 /* save a config node tree into a file, return 0 in case of success, -1 otherwise */
38 extern int    aconfig_save_file(AConfig*  root, const char* path);
39 
40 /* create a single config node */
41 extern AConfig*  aconfig_node(const char *name, const char *value);
42 
43 /* locate a named child of a config node */
44 extern AConfig*  aconfig_find(AConfig *root, const char *name);
45 
46 /* add a named child to a config node (or modify it if it already exists) */
47 extern void      aconfig_set(AConfig *root, const char *name, const char *value);
48 
49 
50 /* look up a child by name and return its value, eventually converted
51  * into a boolean or integer */
52 extern int          aconfig_bool    (AConfig *root, const char *name, int _default);
53 extern unsigned     aconfig_unsigned(AConfig *root, const char *name, unsigned _default);
54 extern int          aconfig_int     (AConfig *root, const char *name, int _default);
55 extern const char*  aconfig_str     (AConfig *root, const char *name, const char *_default);
56 
57 #endif /* ANDROID_CONFIG_H */
58