From 9e2c360ffbb8db360d44f9997a8d2858b8c1ad30 Mon Sep 17 00:00:00 2001 From: "jordi.saludes" Date: Fri, 18 Jun 2010 15:34:08 +0000 Subject: [PATCH] Added 'languageCode' to py-bindings. --- contrib/py-bindings/gfmodule.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/contrib/py-bindings/gfmodule.c b/contrib/py-bindings/gfmodule.c index 34375a85d..5e0406182 100644 --- a/contrib/py-bindings/gfmodule.c +++ b/contrib/py-bindings/gfmodule.c @@ -145,6 +145,23 @@ languages(PGFModule* self) return langs; } +static PyObject* +languageCode(PGFModule *self, PyObject *args) +{ + Lang *lang; + if (!PyArg_ParseTuple(args, "O", &lang)) + return NULL; + char* scode = gf_languageCode(self->obj, lang->obj); + if (scode) { + PyObject* result = PyString_FromString(scode); + free(scode); + return result; + } else { + Py_INCREF(Py_None); + return Py_None; + } +} + static PyObject* linearize(PGFModule *self, PyObject *args) { @@ -226,6 +243,7 @@ readPGF(PyObject *self, PyObject *args) static PyMethodDef pgf_methods[] = { {"parse", (PyCFunction)parse, METH_VARARGS|METH_KEYWORDS,"Parse a string."}, {"lin", (PyCFunction)linearize, METH_VARARGS,"Linearize tree."}, + {"lang_code", (PyCFunction)languageCode, METH_VARARGS,"Get the language code."}, {"startcat", (PyCFunction)startCategory, METH_NOARGS,"Get the start category."}, {"categories", (PyCFunction)categories, METH_NOARGS,"Get all categories."}, {"abstract", (PyCFunction)abstractName, METH_NOARGS,"Get the module abstract name."},