Commit 357cbb45 authored by Yves Combe's avatar Yves Combe
Browse files

checked get_wordlist utility fonction, and add binding.

parent 15ff868c
2005-09-04 Yves Combe <yves@ycombe.net>
checked get_wordlist utility fonction, and add binding.
* src/boards/Makefile.am:
* src/boards/py-mod-gcompris.c:
(py_gcompris_get_wordlist_from_file):
* src/gcompris/wordlist.c: (gcompris_get_wordlist_from_file),
(gcompris_wordlist_free):
* src/gcompris/wordlist.h:
2005-09-04 Bruno coudoin <bruno.coudoin@free.fr>
* boards/administration.xml.in: added documentation (edited from Yves)
......
......@@ -235,6 +235,7 @@ libpython_la_SOURCES = python.c \
py-gcompris-board.c py-gcompris-board.h \
py-gcompris-properties.c py-gcompris-properties.h \
py-gcompris-profile.c py-gcompris-profile.h \
py-gcompris-wordlist.c py-gcompris-wordlist.h \
py-gcompris-user.c \
py-gcompris-class.c \
py-gcompris-group.c \
......
......@@ -5,6 +5,7 @@
#include "py-gcompris-board.h"
#include "py-gcompris-properties.h"
#include "py-gcompris-profile.h"
#include "py-gcompris-wordlist.h"
/* submodules includes */
#include "py-mod-bonus.h"
......@@ -1588,6 +1589,19 @@ py_gcompris_get_current_board_dirname (PyObject* self, PyObject* args)
}
static PyObject*
py_gcompris_get_wordlist_from_file (PyObject* self, PyObject* args)
{
gchar *filename;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "s:gcompris.get_wordlist", &filename))
return NULL;
/* Call the corresponding C function */
return gcompris_new_pyGcomprisWordlistObject(gcompris_get_wordlist_from_file (filename));
}
/****************************************************/
......@@ -1650,7 +1664,7 @@ static PyMethodDef PythonGcomprisModule[] = {
{ "get_current_user_dirname", py_gcompris_get_current_user_dirname, METH_VARARGS, "gcompris_get_current_user_dirname" },
{ "get_board_dirname", py_gcompris_get_board_dirname, METH_VARARGS, "gcompris_get_board_dirname" },
{ "get_current_board_dirname", py_gcompris_get_current_board_dirname, METH_VARARGS, "gcompris_get_current_board_dirname" },
{ "get_wordlist", py_gcompris_get_wordlist_from_file, METH_VARARGS, "gcompris_get_wordlist_from_file" },
{ NULL, NULL, 0, NULL}
};
......
......@@ -42,16 +42,23 @@ GcomprisWordlist *gcompris_get_wordlist_from_file(gchar *filename)
/* if the file doesn't exist */
if(!g_file_test(xmlfilename, G_FILE_TEST_EXISTS))
{
g_warning(_("Couldn't find file %s !"), xmlfilename);
return;
g_free(xmlfilename);
xmlfilename = g_strdup_printf("%s/wordgame/%s.xml", properties->package_data_dir, filename);
if(!g_file_test(xmlfilename, G_FILE_TEST_EXISTS)){
g_warning(_("Couldn't find file %s !"), xmlfilename);
g_free(xmlfilename);
return NULL;
}
}
g_warning("Wordlist found %s\n", xmlfilename);
xmldoc = xmlParseFile(xmlfilename);
g_free(xmlfilename);
if(!xmldoc){
g_warning(_("Couldn't parse file %s !"), xmlfilename);
return;
return NULL;
}
if(/* if there is no root element */
......@@ -62,7 +69,7 @@ GcomprisWordlist *gcompris_get_wordlist_from_file(gchar *filename)
g_strcasecmp((gchar *)xmldoc->children->name,(gchar *)"GCompris")!=0) {
g_warning("No Gcompris node");
xmlFreeDoc(xmldoc);
return;
return NULL;
}
/* there is only one element child */
......@@ -74,7 +81,7 @@ GcomprisWordlist *gcompris_get_wordlist_from_file(gchar *filename)
g_strcasecmp((gchar *)wlNode->name,"wordlist")!=0) {
g_warning("No wordlist node %s", (wlNode == NULL) ? (gchar *)wlNode->name : "NULL node");
xmlFreeDoc(xmldoc);
return;
return NULL;
}
node = wlNode->children;
......@@ -83,7 +90,7 @@ GcomprisWordlist *gcompris_get_wordlist_from_file(gchar *filename)
if (!node){
g_warning("No wordlist text node %s", wlNode->name);
return;
return NULL;
}
/* ok, we can process the wordlist */
......@@ -103,12 +110,18 @@ GcomprisWordlist *gcompris_get_wordlist_from_file(gchar *filename)
wordlist->locale = g_strdup ((gchar *) text);
xmlFree (text);
}
text = xmlGetProp ( wlNode,
(const xmlChar *) "level");
if (text) {
wordlist->level = g_strdup ((gchar *) text);
xmlFree (text);
}
text = xmlNodeGetContent ( node);
wordsArray = g_strsplit ((const gchar *) text,
(const gchar *) " ",
0);
wordsArray = g_strsplit_set ((const gchar *) text,
(const gchar *) " \n\t",
0);
xmlFree (text);
......@@ -130,7 +143,7 @@ GcomprisWordlist *gcompris_get_wordlist_from_file(gchar *filename)
g_free ( wordlist->filename);
g_free ( wordlist->description);
g_free ( wordlist->locale);
g_free ( wordlist->level);
for ( list = wordlist->words; list !=NULL; list=list->next)
g_free(list->data);
......
......@@ -24,6 +24,7 @@ typedef struct {
gchar *filename;
gchar *description;
gchar *locale;
gchar *level;
GList *words;
} GcomprisWordlist;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment