Code Review
/
src
/
app-framework-main.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
work relatively to a root directory
[src/app-framework-main.git]
/
wgt-config-xml.c
diff --git
a/wgt-config-xml.c
b/wgt-config-xml.c
index
41c2085
..
f92ae3a
100644
(file)
--- a/
wgt-config-xml.c
+++ b/
wgt-config-xml.c
@@
-14,6
+14,7
@@
limitations under the License.
*/
limitations under the License.
*/
+#include <unistd.h>
#include <string.h>
#include <syslog.h>
#include <assert.h>
#include <string.h>
#include <syslog.h>
#include <assert.h>
@@
-46,18
+47,31
@@
static xmlNodePtr first(const char *type)
return NULL;
}
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)
{
static xmlNodePtr element_based_localisation(const char *type)
{
- xmlNodePtr resu;
-
char *lang
;
+ xmlNodePtr resu
, elem
;
+
int sr, s
;
resu = first(type);
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;
}
}
return resu;
}
@@
-72,8
+86,15
@@
void confixml_close()
int confixml_open()
{
int confixml_open()
{
+ int fd;
assert(!configxml);
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;
if (configxml == NULL) {
syslog(LOG_ERR, "xml parse of config file %s failed", _config_xml_);
return -1;