config-parser: Make weston_config_parse() tkae a file name

Take a basename of the config file to parse instead of an fd.
dev
Kristian Høgsberg 11 years ago
parent 81c2c2eb5e
commit 1abe0486bb
  1. 6
      clients/desktop-shell.c
  2. 6
      clients/tablet-shell.c
  3. 6
      clients/terminal.c
  4. 7
      clients/window.c
  5. 19
      shared/config-parser.c
  6. 5
      shared/config-parser.h
  7. 7
      src/compositor.c
  8. 2
      tests/config-parser-test.c

@ -1280,17 +1280,13 @@ panel_add_launchers(struct panel *panel, struct desktop *desktop)
int main(int argc, char *argv[])
{
struct desktop desktop = { 0 };
int config_fd;
struct output *output;
struct weston_config_section *s;
desktop.unlock_task.run = unlock_dialog_finish;
wl_list_init(&desktop.outputs);
config_fd = open_config_file("weston.ini");
desktop.config = weston_config_parse(config_fd);
close(config_fd);
desktop.config = weston_config_parse("weston.ini");
s = weston_config_get_section(desktop.config, "shell", NULL, NULL);
weston_config_section_get_bool(s, "locking", &desktop.locking, 1);

@ -412,7 +412,6 @@ int main(int argc, char *argv[])
{
struct tablet tablet = { 0 };
struct display *display;
int config_fd;
struct output *output;
struct weston_config *config;
struct weston_config_section *s;
@ -438,10 +437,7 @@ int main(int argc, char *argv[])
wl_list_init(&tablet.homescreen->launcher_list);
config_fd = open_config_file("weston.ini");
config = weston_config_parse(config_fd);
close(config_fd);
config = weston_config_parse("weston.ini");
s = weston_config_get_section(config, "shell", NULL, NULL);
weston_config_section_get_string(s, "lockscreen-icon",
&key_lockscreen_icon, NULL);

@ -2793,7 +2793,6 @@ int main(int argc, char *argv[])
struct terminal *terminal;
struct weston_config *config;
struct weston_config_section *s;
int config_fd;
/* as wcwidth is locale-dependent,
wcwidth needs setlocale call to function properly. */
@ -2803,10 +2802,7 @@ int main(int argc, char *argv[])
if (!option_shell)
option_shell = "/bin/bash";
config_fd = open_config_file("weston.ini");
config = weston_config_parse(config_fd);
close(config_fd);
config = weston_config_parse("weston.ini");
s = weston_config_get_section(config, "terminal", NULL, NULL);
weston_config_section_get_string(s, "font", &option_font, "mono");
weston_config_section_get_int(s, "font-size", &option_font_size, 14);

@ -1309,15 +1309,12 @@ create_cursors(struct display *display)
{
struct weston_config *config;
struct weston_config_section *s;
int config_fd, size;
int size;
char *theme = NULL;
unsigned int i, j;
struct wl_cursor *cursor;
config_fd = open_config_file("weston.ini");
config = weston_config_parse(config_fd);
close(config_fd);
config = weston_config_parse("weston.ini");
s = weston_config_get_section(config, "shell", NULL, NULL);
weston_config_section_get_string(s, "cursor-theme", &theme, NULL);
weston_config_section_get_int(s, "cursor-size", &size, 32);

@ -41,7 +41,7 @@
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
int
static int
open_config_file(const char *name)
{
const char *config_dir = getenv("XDG_CONFIG_HOME");
@ -51,6 +51,9 @@ open_config_file(const char *name)
const char *p, *next;
int fd;
if (name[0] == '/')
return open(name, O_RDONLY | O_CLOEXEC);
/* Precedence is given to config files in the home directory,
* and then to directories listed in XDG_CONFIG_DIRS and
* finally to the current working directory. */
@ -312,13 +315,13 @@ section_add_entry(struct weston_config_section *section,
}
struct weston_config *
weston_config_parse(int fd)
weston_config_parse(const char *name)
{
FILE *fp;
char line[512], *p;
struct weston_config *config;
struct weston_config_section *section = NULL;
int i;
int i, fd;
config = malloc(sizeof *config);
if (config == NULL)
@ -326,13 +329,17 @@ weston_config_parse(int fd)
wl_list_init(&config->section_list);
fp = fdopen(dup(fd), "r");
if (fp == NULL) {
fd = open_config_file(name);
if (fd == -1) {
free(config);
return NULL;
}
rewind(fp);
fp = fdopen(fd, "r");
if (fp == NULL) {
free(config);
return NULL;
}
while (fgets(line, sizeof line, fp)) {
switch (line[0]) {

@ -47,9 +47,6 @@ struct config_section {
void (*done)(void *data);
};
int
open_config_file(const char *name);
enum weston_option_type {
WESTON_OPTION_INTEGER,
WESTON_OPTION_UNSIGNED_INTEGER,
@ -96,7 +93,7 @@ weston_config_section_get_bool(struct weston_config_section *section,
const char *key,
int *value, int default_value);
struct weston_config *
weston_config_parse(int fd);
weston_config_parse(const char *name);
void
weston_config_destroy(struct weston_config *config);

@ -3418,7 +3418,7 @@ int main(int argc, char *argv[])
*(*backend_init)(struct wl_display *display,
int *argc, char *argv[],
struct weston_config *config);
int i, config_fd;
int i;
char *backend = NULL;
char *shell = NULL;
char *modules, *option_modules = NULL;
@ -3486,10 +3486,7 @@ int main(int argc, char *argv[])
backend = WESTON_NATIVE_BACKEND;
}
config_fd = open_config_file("weston.ini");
config = weston_config_parse(config_fd);
close(config_fd);
config = weston_config_parse("weston.ini");
section = weston_config_get_section(config, "core", NULL, NULL);
weston_config_section_get_string(section, "modules", &modules, "");

@ -40,7 +40,7 @@ run_test(const char *text)
len = write(fd, text, strlen(text));
assert(len == (int) strlen(text));
config = weston_config_parse(fd);
config = weston_config_parse(file);
close(fd);
unlink(file);

Loading…
Cancel
Save