Pekka Paalanen | c1765c6 | 2011-12-05 15:58:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2008 Kristian Høgsberg |
| 3 | * |
Bryce Harrington | 6c6164c | 2015-06-11 14:20:17 -0700 | [diff] [blame] | 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: |
Pekka Paalanen | c1765c6 | 2011-12-05 15:58:11 +0200 | [diff] [blame] | 11 | * |
Bryce Harrington | 6c6164c | 2015-06-11 14:20:17 -0700 | [diff] [blame] | 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. |
Pekka Paalanen | c1765c6 | 2011-12-05 15:58:11 +0200 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #ifndef CONFIGPARSER_H |
| 27 | #define CONFIGPARSER_H |
| 28 | |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 29 | #ifdef __cplusplus |
| 30 | extern "C" { |
| 31 | #endif |
| 32 | |
Jussi Kukkonen | 649bbce | 2016-07-19 14:16:27 +0300 | [diff] [blame] | 33 | #include <stdint.h> |
| 34 | |
Pekka Paalanen | 6c71aae | 2015-03-24 15:56:19 +0200 | [diff] [blame] | 35 | #define WESTON_CONFIG_FILE_ENV_VAR "WESTON_CONFIG_FILE" |
| 36 | |
Pekka Paalanen | 28a2070 | 2011-12-08 09:24:24 +0200 | [diff] [blame] | 37 | enum config_key_type { |
Scott Moreau | fa1de69 | 2012-01-27 13:25:49 -0700 | [diff] [blame] | 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 */ |
Pekka Paalanen | c1765c6 | 2011-12-05 15:58:11 +0200 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | struct config_key { |
| 45 | const char *name; |
Pekka Paalanen | 28a2070 | 2011-12-08 09:24:24 +0200 | [diff] [blame] | 46 | enum config_key_type type; |
Pekka Paalanen | c1765c6 | 2011-12-05 15:58:11 +0200 | [diff] [blame] | 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 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 57 | enum weston_option_type { |
| 58 | WESTON_OPTION_INTEGER, |
| 59 | WESTON_OPTION_UNSIGNED_INTEGER, |
| 60 | WESTON_OPTION_STRING, |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 61 | WESTON_OPTION_BOOLEAN |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | struct weston_option { |
| 65 | enum weston_option_type type; |
| 66 | const char *name; |
| 67 | int short_name; |
| 68 | void *data; |
| 69 | }; |
| 70 | |
| 71 | int |
| 72 | parse_options(const struct weston_option *options, |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 73 | int count, int *argc, char *argv[]); |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 74 | |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 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 |
Bryce Harrington | e776f2a | 2016-07-14 18:28:03 -0700 | [diff] [blame] | 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 |
Armin K | b502f90 | 2013-07-31 01:41:03 +0200 | [diff] [blame] | 94 | weston_config_section_get_double(struct weston_config_section *section, |
| 95 | const char *key, |
| 96 | double *value, double default_value); |
| 97 | int |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 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); |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 106 | const char * |
| 107 | weston_config_get_libexec_dir(void); |
| 108 | |
Pekka Paalanen | 6c71aae | 2015-03-24 15:56:19 +0200 | [diff] [blame] | 109 | const char * |
| 110 | weston_config_get_name_from_env(void); |
| 111 | |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 112 | struct weston_config * |
Kristian Høgsberg | 1abe048 | 2013-09-21 23:02:31 -0700 | [diff] [blame] | 113 | weston_config_parse(const char *name); |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 114 | |
Kristian Høgsberg | eeefc9e | 2013-09-21 23:17:35 -0700 | [diff] [blame] | 115 | const char * |
| 116 | weston_config_get_full_path(struct weston_config *config); |
| 117 | |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 118 | void |
| 119 | weston_config_destroy(struct weston_config *config); |
| 120 | |
Kristian Høgsberg | f73f316 | 2013-05-26 20:50:53 -0400 | [diff] [blame] | 121 | int weston_config_next_section(struct weston_config *config, |
| 122 | struct weston_config_section **section, |
| 123 | const char **name); |
| 124 | |
| 125 | |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 126 | #ifdef __cplusplus |
| 127 | } |
| 128 | #endif |
| 129 | |
Pekka Paalanen | c1765c6 | 2011-12-05 15:58:11 +0200 | [diff] [blame] | 130 | #endif /* CONFIGPARSER_H */ |
| 131 | |