summaryrefslogtreecommitdiffstats
path: root/wgt-config-xml.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2015-12-08 14:44:38 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2015-12-08 14:44:38 +0100
commit381842f4c264e5946ad964f43608f7e543fbcb19 (patch)
tree8da99034ead205ca52c0ade46da51e25d6f9a657 /wgt-config-xml.c
parent7fc1ab01c2309d3078e3d66cfff05bf27fdad26f (diff)
work relatively to a root directory
Change-Id: I7cbb96bd3f699092ddfded8cc8893ec780a97d8c
Diffstat (limited to 'wgt-config-xml.c')
-rw-r--r--wgt-config-xml.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/wgt-config-xml.c b/wgt-config-xml.c
index 41c2085..f92ae3a 100644
--- a/wgt-config-xml.c
+++ b/wgt-config-xml.c
@@ -14,6 +14,7 @@
limitations under the License.
*/
+#include <unistd.h>
#include <string.h>
#include <syslog.h>
#include <assert.h>
@@ -46,18 +47,31 @@ static xmlNodePtr first(const char *type)
return NULL;
}
+static int scorelang(xmlNodePtr node)
+{
+ char *lang = xmlNodeGetLang(node);
+ int score = locales_score(lang);
+ xmlFree(lang);
+ return score;
+}
+
static xmlNodePtr element_based_localisation(const char *type)
{
- xmlNodePtr resu;
- char *lang;
+ xmlNodePtr resu, elem;
+ int sr, s;
resu = first(type);
- while (resu) {
- lang = xmlNodeGetLang(resu);
- if (lang) {
- xmlFree(lang);
+ if (resu) {
+ sr = scorelang(resu);
+ elem = next(resu->next, type);
+ while (resu) {
+ s = scorelang(elem);
+ if (s < sr) {
+ resu = elem;
+ sr = s;
+ }
+ elem = next(elem->next, type);
}
- resu = next(resu->next, type);
}
return resu;
}
@@ -72,8 +86,15 @@ void confixml_close()
int confixml_open()
{
+ int fd;
assert(!configxml);
- configxml = xmlReadFile(_config_xml_, NULL, 0);
+ fd = widget_open_read(_config_xml_);
+ if (fd < 0) {
+ syslog(LOG_ERR, "can't open config file %s", _config_xml_);
+ return fd;
+ }
+ configxml = xmlReadFd(fd, "_config_xml_", NULL, 0);
+ close(fd);
if (configxml == NULL) {
syslog(LOG_ERR, "xml parse of config file %s failed", _config_xml_);
return -1;