summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis/db
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-12-28 17:28:26 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-12-28 17:28:26 (GMT)
commit63d012bfab75840b789e144177ca73847ea989e7 (patch)
treee833613b772f76d4389efa950b9adbcd0ce6f6fb /plugins/pychrysalide/analysis/db
parentdf8dba24f7b01a507acd03659c8d4d4868dea143 (diff)
Enabled the comment creation from Python.
Diffstat (limited to 'plugins/pychrysalide/analysis/db')
-rw-r--r--plugins/pychrysalide/analysis/db/Makefile.am4
-rw-r--r--plugins/pychrysalide/analysis/db/items/comment.c116
2 files changed, 74 insertions, 46 deletions
diff --git a/plugins/pychrysalide/analysis/db/Makefile.am b/plugins/pychrysalide/analysis/db/Makefile.am
index 940deca..709f153 100644
--- a/plugins/pychrysalide/analysis/db/Makefile.am
+++ b/plugins/pychrysalide/analysis/db/Makefile.am
@@ -7,9 +7,11 @@ libpychrysaanalysisdb_la_SOURCES = \
item.h item.c \
module.h module.c
-libpychrysaanalysisdb_la_LDFLAGS = \
+libpychrysaanalysisdb_la_LIBADD = \
items/libpychrysaanalysisdbitems.la
+libpychrysaanalysisdb_la_LDFLAGS =
+
devdir = $(includedir)/chrysalide-$(subdir)
diff --git a/plugins/pychrysalide/analysis/db/items/comment.c b/plugins/pychrysalide/analysis/db/items/comment.c
index 3a12019..6d05403 100644
--- a/plugins/pychrysalide/analysis/db/items/comment.c
+++ b/plugins/pychrysalide/analysis/db/items/comment.c
@@ -43,12 +43,12 @@
/* Crée un nouvel objet Python de type 'DbComment'. */
static PyObject *py_db_comment_new(PyTypeObject *, PyObject *, PyObject *);
+/* Associe un contenu statique supplémentaire à un commentaire. */
+static PyObject *py_db_comment_add_text(PyObject *, PyObject *);
+
/* Fournit le commentaire associé à un commentaire. */
static PyObject *py_db_comment_get_text(PyObject *, void *);
-/* Définit le commentaire associé à un commentaire. */
-static int py_db_comment_set_text(PyObject *, PyObject *, void *);
-
/******************************************************************************
@@ -68,24 +68,46 @@ static int py_db_comment_set_text(PyObject *, PyObject *, void *);
static PyObject *py_db_comment_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *result; /* Instance à retourner */
- PyObject *py_vmpa; /* Localisation version Python */
- const char *text; /* Texte à associer */
- int is_volatile; /* Conservation en mémoire */
+ int repeatable; /* Note une répétition demandée*/
+ const char *text; /* Eventuel premier commentaire*/
+ int before; /* Indication sur l'emplacement*/
+ vmpa2t addr; /* Emplacement ciblé */
+ unsigned long flags; /* Identifiants de ligne visée */
int ret; /* Bilan de lecture des args. */
- vmpa2t *addr; /* Localisation version C */
GDbComment *comment; /* Version GLib du commentaire */
- ret = PyArg_ParseTuple(args, "Osp", &py_vmpa, &text, &is_volatile);
- if (!ret) Py_RETURN_NONE;
+ static char *kwlist[] = { "addr", "flags", "repeatable", "text", "before", NULL };
+
+ /* Récupération des paramètres */
+
+ repeatable = -1;
+ text = NULL;
+ before = -1;
- ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type());
+ ret = PyArg_ParseTupleAndKeywords(args, kwds, "O&k|$psp", kwlist,
+ convert_any_to_vmpa, &addr, &flags, &repeatable, &text, &before);
if (!ret) return NULL;
- addr = get_internal_vmpa(py_vmpa);
- if (py_vmpa == NULL) Py_RETURN_NONE;
+ /* Vérifications diverses */
+
+ if (flags > BLF_ALL)
+ {
+ PyErr_SetString(PyExc_ValueError, _("Invalid flag combination"));
+ return NULL;
+ }
+
+ if ((repeatable == -1 && before == -1) || (repeatable != -1 && before != -1))
+ {
+ PyErr_SetString(PyExc_ValueError, _("repeatable or before has to be defined"));
+ return NULL;
+ }
- return NULL;/* FIXME */
- //comment = g_db_comment_new(addr, text, is_volatile);
+ /* Construction */
+
+ if (repeatable)
+ comment = g_db_comment_new_inlined(&addr, flags, repeatable);
+ else
+ comment = g_db_comment_new_area(&addr, flags, text, before);
result = pygobject_new(G_OBJECT(comment));
g_object_unref(comment);
@@ -97,38 +119,31 @@ static PyObject *py_db_comment_new(PyTypeObject *type, PyObject *args, PyObject
/******************************************************************************
* *
-* Paramètres : self = objet Python concerné par l'appel. *
-* closure = non utilisé ici. *
+* Paramètres : self = classe représentant un commentaire. *
+* args = arguments fournis à l'appel. *
* *
-* Description : Fournit le commentaire associé à un commentaire. *
+* Description : Associe un contenu statique supplémentaire à un commentaire. *
* *
-* Retour : Texte manipulable en Python. *
+* Retour : None. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_db_comment_get_text(PyObject *self, void *closure)
+static PyObject *py_db_comment_add_text(PyObject *self, PyObject *args)
{
- PyObject *result; /* Résultat à retourner */
+ const char *text; /* Commentaire complémentaire */
+ int ret; /* Bilan de lecture des args. */
GDbComment *comment; /* Commentaire à consulter */
- char *text; /* Contenu textuel associé */
+
+ ret = PyArg_ParseTuple(args, "s", &text);
+ if (!ret) return NULL;
comment = G_DB_COMMENT(pygobject_get(self));
- text = g_db_comment_get_text(comment);
- if (text == NULL)
- {
- result = Py_None;
- Py_INCREF(result);
- }
- else
- {
- result = PyUnicode_FromString(text);
- free(text);
- }
+ g_db_comment_add_static_text(comment, text);
- return result;
+ Py_RETURN_NONE;
}
@@ -136,31 +151,37 @@ static PyObject *py_db_comment_get_text(PyObject *self, void *closure)
/******************************************************************************
* *
* Paramètres : self = objet Python concerné par l'appel. *
-* value = valeur fournie à intégrer ou prendre en compte. *
* closure = non utilisé ici. *
* *
-* Description : Définit le commentaire associé à un commentaire. *
+* Description : Fournit le commentaire associé à un commentaire. *
* *
-* Retour : Bilan de l'opération pour Python. *
+* Retour : Texte manipulable en Python. *
* *
* Remarques : - *
* *
******************************************************************************/
-static int py_db_comment_set_text(PyObject *self, PyObject *value, void *closure)
+static PyObject *py_db_comment_get_text(PyObject *self, void *closure)
{
+ PyObject *result; /* Résultat à retourner */
GDbComment *comment; /* Commentaire à consulter */
+ char *text; /* Contenu textuel associé */
+
+ comment = G_DB_COMMENT(pygobject_get(self));
+ text = g_db_comment_get_text(comment);
- if (!PyUnicode_Check(value))
+ if (text == NULL)
{
- PyErr_SetString(PyExc_TypeError, _("The attribute value must be a string."));
- return -1;
+ result = Py_None;
+ Py_INCREF(result);
+ }
+ else
+ {
+ result = PyUnicode_FromString(text);
+ free(text);
}
- comment = G_DB_COMMENT(pygobject_get(self));
- //g_db_comment_set_text(comment, PyUnicode_DATA(value));
-
- return 0;
+ return result;
}
@@ -180,12 +201,17 @@ static int py_db_comment_set_text(PyObject *self, PyObject *value, void *closure
PyTypeObject *get_python_db_comment_type(void)
{
static PyMethodDef py_db_comment_methods[] = {
+ {
+ "add_text", py_db_comment_add_text,
+ METH_VARARGS,
+ "add_text($self, text, /)\n--\n\nAppend extra text to a given comment."
+ },
{ NULL }
};
static PyGetSetDef py_db_comment_getseters[] = {
{
- "text", py_db_comment_get_text, py_db_comment_set_text,
+ "text", py_db_comment_get_text, NULL,
"Give access to the content of a given comment.", NULL
},
{ NULL }