summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/glibext/bufferline.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/glibext/bufferline.c')
-rw-r--r--plugins/pychrysalide/glibext/bufferline.c145
1 files changed, 141 insertions, 4 deletions
diff --git a/plugins/pychrysalide/glibext/bufferline.c b/plugins/pychrysalide/glibext/bufferline.c
index d6b391a..47b2bc4 100644
--- a/plugins/pychrysalide/glibext/bufferline.c
+++ b/plugins/pychrysalide/glibext/bufferline.c
@@ -31,17 +31,23 @@
#include <i18n.h>
-
-
#include <glibext/gbufferline.h>
+#include <plugins/dt.h>
+#include "constants.h"
#include "../access.h"
#include "../helpers.h"
#include "../arch/vmpa.h"
+/* Accompagne la création d'une instance dérivée en Python. */
+static PyObject *py_buffer_line_new(PyTypeObject *, PyObject *, PyObject *);
+
+/* Ajoute du texte à formater dans une ligne donnée. */
+static PyObject *py_buffer_line_append_text(PyObject *, PyObject *);
+
/* Reconstruit et fournit le texte présent sur une ligne tampon. */
static PyObject *py_buffer_line_get_text(PyObject *, PyObject *);
@@ -64,6 +70,131 @@ static bool py_buffer_line_define_constants(PyTypeObject *);
/******************************************************************************
* *
+* Paramètres : type = type du nouvel objet à mettre en place. *
+* args = éventuelle liste d'arguments. *
+* kwds = éventuel dictionnaire de valeurs mises à disposition. *
+* *
+* Description : Accompagne la création d'une instance dérivée en Python. *
+* *
+* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_buffer_line_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyObject *result; /* Objet à retourner */
+ PyTypeObject *base; /* Type de base à dériver */
+ bool first_time; /* Evite les multiples passages*/
+ GType gtype; /* Nouveau type de processeur */
+ bool status; /* Bilan d'un enregistrement */
+
+#define BUFFER_LINE_DOC \
+ "The BufferLine object is used to display processed data: disassembled" \
+ " instruction, binary content in hexadecimal form, aso.\n" \
+ "\n" \
+ "Instances can be created using the following constructor:\n" \
+ "\n" \
+ " BufferLine()" \
+ "\n" \
+ "Such objets aim to be created from the Chrysalide core only, and" \
+ " then get populated by plugins on demand."
+
+ /* Validations diverses */
+
+ base = get_python_buffer_line_type();
+
+ if (type == base)
+ goto simple_way;
+
+ /* Mise en place d'un type dédié */
+
+ first_time = (g_type_from_name(type->tp_name) == 0);
+
+ gtype = build_dynamic_type(G_TYPE_BUFFER_LINE, type->tp_name, NULL, NULL, NULL);
+
+ if (first_time)
+ {
+ status = register_class_for_dynamic_pygobject(gtype, type, base);
+
+ if (!status)
+ {
+ result = NULL;
+ goto exit;
+ }
+
+ }
+
+ /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */
+
+ simple_way:
+
+ result = PyType_GenericNew(type, args, kwds);
+
+ exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant une ligne de tampon. *
+* args = arguments fournis à l'appel. *
+* *
+* Description : Ajoute du texte à formater dans une ligne donnée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_buffer_line_append_text(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Trouvailles à retourner */
+ unsigned long column; /* Indice de colonne */
+ const char *text; /* Texte à ajouter */
+ RenderingTagType type; /* Type de rendu attendu */
+ GObject *creator; /* Eventuel créateur à associer*/
+ int ret; /* Bilan de lecture des args. */
+ GBufferLine *line; /* Version native */
+
+#define BUFFER_LINE_APPEND_TEXT_METHOD PYTHON_METHOD_DEF \
+( \
+ append_text, "$self, column, text, tag, /, creator=None", \
+ METH_VARARGS, py_buffer_line, \
+ "Append some text to a line at a given column index. The" \
+ " expected rendering for this text is defined by the tag, which"\
+ " must be a pychrysalide.glibext.BufferLine.RenderingTagType" \
+ " value." \
+ "\n" \
+ "An optional GObject instance may be provided as origin of the" \
+ " creation." \
+)
+
+ creator = NULL;
+
+ ret = PyArg_ParseTuple(args, "ksO&|O&", &column, &text,
+ convert_to_rendering_tag_type, &type, convert_to_gobject, &creator);
+ if (!ret) return NULL;
+
+ line = G_BUFFER_LINE(pygobject_get(self));
+
+ g_buffer_line_append_text(line, column, text, strlen(text), type, creator);
+
+ result = Py_None;
+ Py_INCREF(result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : self = classe représentant une ligne de tampon. *
* args = arguments fournis à l'appel. *
* *
@@ -292,6 +423,7 @@ static bool py_buffer_line_define_constants(PyTypeObject *obj_type)
PyTypeObject *get_python_buffer_line_type(void)
{
static PyMethodDef py_buffer_line_methods[] = {
+ BUFFER_LINE_APPEND_TEXT_METHOD,
{
"get_text", py_buffer_line_get_text,
METH_VARARGS,
@@ -329,13 +461,15 @@ PyTypeObject *get_python_buffer_line_type(void)
.tp_name = "pychrysalide.glibext.BufferLine",
.tp_basicsize = sizeof(PyGObject),
- .tp_flags = Py_TPFLAGS_DEFAULT,
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- .tp_doc = "PyChrysalide buffer line",
+ .tp_doc = BUFFER_LINE_DOC,
.tp_methods = py_buffer_line_methods,
.tp_getset = py_buffer_line_getseters,
+ .tp_new = py_buffer_line_new
+
};
return &py_buffer_line_type;
@@ -372,6 +506,9 @@ bool ensure_python_buffer_line_is_registered(void)
if (!register_class_for_pygobject(dict, G_TYPE_BUFFER_LINE, type, &PyGObject_Type))
return false;
+ if (!define_line_segment_constants(type))
+ return false;
+
if (!py_buffer_line_define_constants(type))
return false;