• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdbool.h>
34 #include <stdint.h>
35 
36 #define WESTON_CONFIG_FILE_ENV_VAR "WESTON_CONFIG_FILE"
37 
38 enum config_key_type {
39 	CONFIG_KEY_INTEGER,		/* typeof data = int */
40 	CONFIG_KEY_UNSIGNED_INTEGER,	/* typeof data = unsigned int */
41 	CONFIG_KEY_STRING,		/* typeof data = char* */
42 	CONFIG_KEY_BOOLEAN		/* typeof data = int */
43 };
44 
45 struct config_key {
46 	const char *name;
47 	enum config_key_type type;
48 	void *data;
49 };
50 
51 struct config_section {
52 	const char *name;
53 	const struct config_key *keys;
54 	int num_keys;
55 	void (*done)(void *data);
56 };
57 
58 enum weston_option_type {
59 	WESTON_OPTION_INTEGER,
60 	WESTON_OPTION_UNSIGNED_INTEGER,
61 	WESTON_OPTION_STRING,
62 	WESTON_OPTION_BOOLEAN
63 };
64 
65 struct weston_option {
66 	enum weston_option_type type;
67 	const char *name;
68 	char short_name;
69 	void *data;
70 };
71 
72 int
73 parse_options(const struct weston_option *options,
74 	      int count, int *argc, char *argv[]);
75 
76 struct weston_config_section;
77 struct weston_config;
78 
79 struct weston_config_section *
80 weston_config_get_section(struct weston_config *config, const char *section,
81 			  const char *key, const char *value);
82 int
83 weston_config_section_get_int(struct weston_config_section *section,
84 			      const char *key,
85 			      int32_t *value, int32_t default_value);
86 int
87 weston_config_section_get_uint(struct weston_config_section *section,
88 			       const char *key,
89 			       uint32_t *value, uint32_t default_value);
90 int
91 weston_config_section_get_color(struct weston_config_section *section,
92 				const char *key,
93 				uint32_t *color, uint32_t default_color);
94 int
95 weston_config_section_get_double(struct weston_config_section *section,
96 				 const char *key,
97 				 double *value, double default_value);
98 int
99 weston_config_section_get_string(struct weston_config_section *section,
100 				 const char *key,
101 				 char **value,
102 				 const char *default_value);
103 int
104 weston_config_section_get_bool(struct weston_config_section *section,
105 			       const char *key,
106 			       bool *value, bool default_value);
107 
108 const char *
109 weston_config_get_name_from_env(void);
110 
111 struct weston_config *
112 weston_config_parse(const char *name);
113 
114 const char *
115 weston_config_get_full_path(struct weston_config *config);
116 
117 void
118 weston_config_destroy(struct weston_config *config);
119 
120 int weston_config_next_section(struct weston_config *config,
121 			       struct weston_config_section **section,
122 			       const char **name);
123 
124 
125 #ifdef  __cplusplus
126 }
127 #endif
128 
129 #endif /* CONFIGPARSER_H */
130 
131