2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of quvi <http://quvi.sourceforge.net/>.
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>.
25 #include <glib/gi18n.h>
31 const gchar
* const *data_dirs
;
35 data_dirs
= g_get_system_data_dirs();
36 /* 3=user data, user config, trailing NULL. */
37 r
= g_new(gchar
*, g_strv_length((gchar
**) data_dirs
)+3);
41 while (data_dirs
[j
] != NULL
)
42 r
[i
++] = g_strdup(data_dirs
[j
++]);
44 r
[i
++] = g_strdup(g_get_user_data_dir());
45 r
[i
++] = g_strdup(g_get_user_config_dir());
51 extern gboolean show_config
;
53 static void _keyfile_printerr(const gchar
*fpath
, GError
*e
)
55 if (e
->domain
== G_KEY_FILE_ERROR
)
57 g_printerr(_("error: %s: while reading config: %s (code=%d)\n"),
58 fpath
, e
->message
, e
->code
);
62 if (show_config
== TRUE
)
64 g_message(_("rejected: %s: %s (code=%d)"),
65 fpath
, e
->message
, e
->code
);
71 static void _keyfile_parse(lopts_t lopts
, const gchar
*fpath
)
79 g_key_file_set_list_separator(f
, ',');
81 if (g_key_file_load_from_file(f
, fpath
, G_KEY_FILE_NONE
, &e
) == TRUE
)
83 if (show_config
== TRUE
)
84 g_message(_("parse: %s"), fpath
);
86 if (lopts
->cb
.parse_keyfile_values
!= NULL
)
87 lopts
->cb
.parse_keyfile_values(f
, fpath
);
90 _keyfile_printerr(fpath
, e
);
95 void keyfile_read(lopts_t lopts
)
97 gchar
*rcpath
, **dirs
, *p
;
101 v
= g_getenv("QUVI_SHOW_CONFIG");
102 show_config
= (v
!= NULL
&& strlen(v
) >0) ? TRUE
:FALSE
;
104 if (lopts
->cb
.get_config_fpath
!= NULL
)
106 p
= lopts
->cb
.get_config_fpath();
107 if (p
!= NULL
) /* QUVI_CONFIG was defined. */
109 _keyfile_parse(lopts
, p
);
115 rcpath
= g_build_path(G_DIR_SEPARATOR_S
, "quvi", "quvirc", NULL
);
116 dirs
= search_dirs();
119 while (dirs
[i
] != NULL
)
121 p
= g_build_path(G_DIR_SEPARATOR_S
, dirs
[i
++], rcpath
, NULL
);
122 _keyfile_parse(lopts
, p
);
127 /* vim: set ts=2 sw=2 tw=72 expandtab: */