blob: b8462a72b41b32c24dda8ed82668b622699c371e [file] [log] [blame]
Pekka Paalanenc1765c62011-12-05 15:58:11 +02001/*
2 * Copyright © 2008 Kristian Høgsberg
3 *
Bryce Harrington6c6164c2015-06-11 14:20:17 -07004 * 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:
Pekka Paalanenc1765c62011-12-05 15:58:11 +020011 *
Bryce Harrington6c6164c2015-06-11 14:20:17 -070012 * 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.
Pekka Paalanenc1765c62011-12-05 15:58:11 +020024 */
25
26#ifndef CONFIGPARSER_H
27#define CONFIGPARSER_H
28
Giulio Camuffo7fe01b12013-03-28 18:02:42 +010029#ifdef __cplusplus
30extern "C" {
31#endif
32
Pekka Paalanen6c71aae2015-03-24 15:56:19 +020033#define WESTON_CONFIG_FILE_ENV_VAR "WESTON_CONFIG_FILE"
34
Pekka Paalanen28a20702011-12-08 09:24:24 +020035enum config_key_type {
Scott Moreaufa1de692012-01-27 13:25:49 -070036 CONFIG_KEY_INTEGER, /* typeof data = int */
37 CONFIG_KEY_UNSIGNED_INTEGER, /* typeof data = unsigned int */
38 CONFIG_KEY_STRING, /* typeof data = char* */
39 CONFIG_KEY_BOOLEAN /* typeof data = int */
Pekka Paalanenc1765c62011-12-05 15:58:11 +020040};
41
42struct config_key {
43 const char *name;
Pekka Paalanen28a20702011-12-08 09:24:24 +020044 enum config_key_type type;
Pekka Paalanenc1765c62011-12-05 15:58:11 +020045 void *data;
46};
47
48struct config_section {
49 const char *name;
50 const struct config_key *keys;
51 int num_keys;
52 void (*done)(void *data);
53};
54
Kristian Høgsbergbcacef12012-03-11 21:05:57 -040055enum weston_option_type {
56 WESTON_OPTION_INTEGER,
57 WESTON_OPTION_UNSIGNED_INTEGER,
58 WESTON_OPTION_STRING,
Kristian Høgsbergb71302e2012-05-10 12:28:35 -040059 WESTON_OPTION_BOOLEAN
Kristian Høgsbergbcacef12012-03-11 21:05:57 -040060};
61
62struct weston_option {
63 enum weston_option_type type;
64 const char *name;
65 int short_name;
66 void *data;
67};
68
69int
70parse_options(const struct weston_option *options,
Kristian Høgsberg4172f662013-02-20 15:27:49 -050071 int count, int *argc, char *argv[]);
Kristian Høgsbergbcacef12012-03-11 21:05:57 -040072
Kristian Høgsberg73274712013-04-01 12:41:23 -040073struct weston_config_section;
74struct weston_config;
75
76struct weston_config_section *
77weston_config_get_section(struct weston_config *config, const char *section,
78 const char *key, const char *value);
79int
80weston_config_section_get_int(struct weston_config_section *section,
81 const char *key,
82 int32_t *value, int32_t default_value);
83int
84weston_config_section_get_uint(struct weston_config_section *section,
85 const char *key,
86 uint32_t *value, uint32_t default_value);
87int
Armin Kb502f902013-07-31 01:41:03 +020088weston_config_section_get_double(struct weston_config_section *section,
89 const char *key,
90 double *value, double default_value);
91int
Kristian Høgsberg73274712013-04-01 12:41:23 -040092weston_config_section_get_string(struct weston_config_section *section,
93 const char *key,
94 char **value,
95 const char *default_value);
96int
97weston_config_section_get_bool(struct weston_config_section *section,
98 const char *key,
99 int *value, int default_value);
Derek Foremanc7210432014-08-21 11:32:38 -0500100const char *
101weston_config_get_libexec_dir(void);
102
Pekka Paalanen6c71aae2015-03-24 15:56:19 +0200103const char *
104weston_config_get_name_from_env(void);
105
Kristian Høgsberg73274712013-04-01 12:41:23 -0400106struct weston_config *
Kristian Høgsberg1abe0482013-09-21 23:02:31 -0700107weston_config_parse(const char *name);
Kristian Høgsberg73274712013-04-01 12:41:23 -0400108
Kristian Høgsbergeeefc9e2013-09-21 23:17:35 -0700109const char *
110weston_config_get_full_path(struct weston_config *config);
111
Kristian Høgsberg73274712013-04-01 12:41:23 -0400112void
113weston_config_destroy(struct weston_config *config);
114
Kristian Høgsbergf73f3162013-05-26 20:50:53 -0400115int weston_config_next_section(struct weston_config *config,
116 struct weston_config_section **section,
117 const char **name);
118
119
Giulio Camuffo7fe01b12013-03-28 18:02:42 +0100120#ifdef __cplusplus
121}
122#endif
123
Pekka Paalanenc1765c62011-12-05 15:58:11 +0200124#endif /* CONFIGPARSER_H */
125