fix weston launch error
[platform/upstream/weston.git] / shared / config-parser.h
1 /*
2  * Copyright © 2008 Kristian Høgsberg
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial
14  * portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25
26 #ifndef CONFIGPARSER_H
27 #define CONFIGPARSER_H
28
29 #ifdef  __cplusplus
30 extern "C" {
31 #endif
32
33 #include <stdint.h>
34
35 #define WESTON_CONFIG_FILE_ENV_VAR "WESTON_CONFIG_FILE"
36
37 enum config_key_type {
38         CONFIG_KEY_INTEGER,             /* typeof data = int */
39         CONFIG_KEY_UNSIGNED_INTEGER,    /* typeof data = unsigned int */
40         CONFIG_KEY_STRING,              /* typeof data = char* */
41         CONFIG_KEY_BOOLEAN              /* typeof data = int */
42 };
43
44 struct config_key {
45         const char *name;
46         enum config_key_type type;
47         void *data;
48 };
49
50 struct config_section {
51         const char *name;
52         const struct config_key *keys;
53         int num_keys;
54         void (*done)(void *data);
55 };
56
57 enum weston_option_type {
58         WESTON_OPTION_INTEGER,
59         WESTON_OPTION_UNSIGNED_INTEGER,
60         WESTON_OPTION_STRING,
61         WESTON_OPTION_BOOLEAN
62 };
63
64 struct weston_option {
65         enum weston_option_type type;
66         const char *name;
67         char short_name;
68         void *data;
69 };
70
71 int
72 parse_options(const struct weston_option *options,
73               int count, int *argc, char *argv[]);
74
75 struct weston_config_section;
76 struct weston_config;
77
78 struct weston_config_section *
79 weston_config_get_section(struct weston_config *config, const char *section,
80                           const char *key, const char *value);
81 int
82 weston_config_section_get_int(struct weston_config_section *section,
83                               const char *key,
84                               int32_t *value, int32_t default_value);
85 int
86 weston_config_section_get_uint(struct weston_config_section *section,
87                                const char *key,
88                                uint32_t *value, uint32_t default_value);
89 int
90 weston_config_section_get_color(struct weston_config_section *section,
91                                 const char *key,
92                                 uint32_t *color, uint32_t default_color);
93 int
94 weston_config_section_get_double(struct weston_config_section *section,
95                                  const char *key,
96                                  double *value, double default_value);
97 int
98 weston_config_section_get_string(struct weston_config_section *section,
99                                  const char *key,
100                                  char **value,
101                                  const char *default_value);
102 int
103 weston_config_section_get_bool(struct weston_config_section *section,
104                                const char *key,
105                                int *value, int default_value);
106
107 const char *
108 weston_config_get_name_from_env(void);
109
110 struct weston_config *
111 weston_config_parse(const char *name);
112
113 const char *
114 weston_config_get_full_path(struct weston_config *config);
115
116 void
117 weston_config_destroy(struct weston_config *config);
118
119 int weston_config_next_section(struct weston_config *config,
120                                struct weston_config_section **section,
121                                const char **name);
122
123
124 #ifdef  __cplusplus
125 }
126 #endif
127
128 #endif /* CONFIGPARSER_H */
129