blob: f18d2c0b12529760fce6e7118e60e5145e0a82f9 [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
Jussi Kukkonen649bbce2016-07-19 14:16:27 +030033#include <stdint.h>
34
Pekka Paalanen6c71aae2015-03-24 15:56:19 +020035#define WESTON_CONFIG_FILE_ENV_VAR "WESTON_CONFIG_FILE"
36
Pekka Paalanen28a20702011-12-08 09:24:24 +020037enum config_key_type {
Scott Moreaufa1de692012-01-27 13:25:49 -070038 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 */
Pekka Paalanenc1765c62011-12-05 15:58:11 +020042};
43
44struct config_key {
45 const char *name;
Pekka Paalanen28a20702011-12-08 09:24:24 +020046 enum config_key_type type;
Pekka Paalanenc1765c62011-12-05 15:58:11 +020047 void *data;
48};
49
50struct config_section {
51 const char *name;
52 const struct config_key *keys;
53 int num_keys;
54 void (*done)(void *data);
55};
56
Kristian Høgsbergbcacef12012-03-11 21:05:57 -040057enum weston_option_type {
58 WESTON_OPTION_INTEGER,
59 WESTON_OPTION_UNSIGNED_INTEGER,
60 WESTON_OPTION_STRING,
Kristian Høgsbergb71302e2012-05-10 12:28:35 -040061 WESTON_OPTION_BOOLEAN
Kristian Høgsbergbcacef12012-03-11 21:05:57 -040062};
63
64struct weston_option {
65 enum weston_option_type type;
66 const char *name;
67 int short_name;
68 void *data;
69};
70
71int
72parse_options(const struct weston_option *options,
Kristian Høgsberg4172f662013-02-20 15:27:49 -050073 int count, int *argc, char *argv[]);
Kristian Høgsbergbcacef12012-03-11 21:05:57 -040074
Kristian Høgsberg73274712013-04-01 12:41:23 -040075struct weston_config_section;
76struct weston_config;
77
78struct weston_config_section *
79weston_config_get_section(struct weston_config *config, const char *section,
80 const char *key, const char *value);
81int
82weston_config_section_get_int(struct weston_config_section *section,
83 const char *key,
84 int32_t *value, int32_t default_value);
85int
86weston_config_section_get_uint(struct weston_config_section *section,
87 const char *key,
88 uint32_t *value, uint32_t default_value);
89int
Bryce Harringtone776f2a2016-07-14 18:28:03 -070090weston_config_section_get_color(struct weston_config_section *section,
91 const char *key,
92 uint32_t *color, uint32_t default_color);
93int
Armin Kb502f902013-07-31 01:41:03 +020094weston_config_section_get_double(struct weston_config_section *section,
95 const char *key,
96 double *value, double default_value);
97int
Kristian Høgsberg73274712013-04-01 12:41:23 -040098weston_config_section_get_string(struct weston_config_section *section,
99 const char *key,
100 char **value,
101 const char *default_value);
102int
103weston_config_section_get_bool(struct weston_config_section *section,
104 const char *key,
105 int *value, int default_value);
Derek Foremanc7210432014-08-21 11:32:38 -0500106const char *
107weston_config_get_libexec_dir(void);
108
Pekka Paalanen6c71aae2015-03-24 15:56:19 +0200109const char *
110weston_config_get_name_from_env(void);
111
Kristian Høgsberg73274712013-04-01 12:41:23 -0400112struct weston_config *
Kristian Høgsberg1abe0482013-09-21 23:02:31 -0700113weston_config_parse(const char *name);
Kristian Høgsberg73274712013-04-01 12:41:23 -0400114
Kristian Høgsbergeeefc9e2013-09-21 23:17:35 -0700115const char *
116weston_config_get_full_path(struct weston_config *config);
117
Kristian Høgsberg73274712013-04-01 12:41:23 -0400118void
119weston_config_destroy(struct weston_config *config);
120
Kristian Høgsbergf73f3162013-05-26 20:50:53 -0400121int weston_config_next_section(struct weston_config *config,
122 struct weston_config_section **section,
123 const char **name);
124
125
Giulio Camuffo7fe01b12013-03-28 18:02:42 +0100126#ifdef __cplusplus
127}
128#endif
129
Pekka Paalanenc1765c62011-12-05 15:58:11 +0200130#endif /* CONFIGPARSER_H */
131