diff options
| author | Cyrille Bagard <nocbos@gmail.com> | 2025-03-28 04:42:25 (GMT) | 
|---|---|---|
| committer | Cyrille Bagard <nocbos@gmail.com> | 2025-03-28 04:42:25 (GMT) | 
| commit | ec6706fe5e9b71ece7f2a6770f57f6757c375b33 (patch) | |
| tree | 1176027c3c760723f488e94437acbe01e7f63b7b /plugins/pychrysalide/glibext | |
| parent | fe1d32e4b7de540afe393cdcdba793d44fc14048 (diff) | |
Create a basic Python binding to the TokenGenerator interface.
Diffstat (limited to 'plugins/pychrysalide/glibext')
| -rw-r--r-- | plugins/pychrysalide/glibext/Makefile.am | 19 | ||||
| -rw-r--r-- | plugins/pychrysalide/glibext/bufferline.c | 109 | ||||
| -rw-r--r-- | plugins/pychrysalide/glibext/constants-ui.c | 131 | ||||
| -rw-r--r-- | plugins/pychrysalide/glibext/constants-ui.h | 41 | ||||
| -rw-r--r-- | plugins/pychrysalide/glibext/constants.c | 100 | ||||
| -rw-r--r-- | plugins/pychrysalide/glibext/constants.h | 6 | ||||
| -rw-r--r-- | plugins/pychrysalide/glibext/generator.c | 584 | ||||
| -rw-r--r-- | plugins/pychrysalide/glibext/generator.h | 18 | ||||
| -rw-r--r-- | plugins/pychrysalide/glibext/module-ui.c | 62 | ||||
| -rw-r--r-- | plugins/pychrysalide/glibext/module-ui.h | 38 | 
10 files changed, 662 insertions, 446 deletions
| diff --git a/plugins/pychrysalide/glibext/Makefile.am b/plugins/pychrysalide/glibext/Makefile.am index 3a5fab2..6d3d746 100644 --- a/plugins/pychrysalide/glibext/Makefile.am +++ b/plugins/pychrysalide/glibext/Makefile.am @@ -1,14 +1,11 @@ -noinst_LTLIBRARIES = libpychrysaglibext.la +noinst_LTLIBRARIES = libpychrysaglibext.la libpychrysaglibextui.la  # libpychrysaglibext_la_SOURCES =				\  # 	binarycursor.h binarycursor.c			\  # 	buffercache.h buffercache.c				\ -# 	bufferline.h bufferline.c				\  # 	configuration.h configuration.c			\ -# 	linecursor.h linecursor.c				\ -# 	linegen.h linegen.c						\ -# 	module.h module.c +# 	linecursor.h linecursor.c  # if BUILD_GTK_SUPPORT @@ -38,6 +35,16 @@ libpychrysaglibext_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBPYTHON_INTERPRETER_CFLAGS)  	-I$(top_srcdir)/src -DNO_IMPORT_PYGOBJECT +libpychrysaglibextui_la_SOURCES =			\ +	bufferline.h bufferline.c				\ +	constants-ui.h constants-ui.c			\ +	generator.h generator.c					\ +	module-ui.h module-ui.c + +libpychrysaglibextui_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ +	-I$(top_srcdir)/src -DNO_IMPORT_PYGOBJECT + +  devdir = $(includedir)/chrysalide/$(subdir) -dev_HEADERS = $(libpychrysaglibext_la_SOURCES:%c=) +dev_HEADERS = $(libpychrysaglibext_la_SOURCES:%c=) $(libpychrysaglibextui_la_SOURCES:%c=) diff --git a/plugins/pychrysalide/glibext/bufferline.c b/plugins/pychrysalide/glibext/bufferline.c index 09404bc..c5b3664 100644 --- a/plugins/pychrysalide/glibext/bufferline.c +++ b/plugins/pychrysalide/glibext/bufferline.c @@ -2,7 +2,7 @@  /* Chrysalide - Outil d'analyse de fichiers binaires   * bufferline.c - équivalent Python du fichier "glibext/bufferline.h"   * - * Copyright (C) 2018-2019 Cyrille Bagard + * Copyright (C) 2018-2025 Cyrille Bagard   *   *  This file is part of Chrysalide.   * @@ -26,25 +26,38 @@  #include <assert.h> -#include <malloc.h> +//#include <malloc.h>  #include <pygobject.h> -#include <i18n.h> -#include <glibext/bufferline.h> -#include <plugins/dt.h> +#include <glibext/bufferline-int.h> -#include "constants.h" +//#include "constants.h"  #include "../access.h"  #include "../helpers.h" -#include "../arch/vmpa.h" +//#include "../arch/vmpa.h" +/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */ + + +CREATE_DYN_CONSTRUCTOR(buffer_line, G_TYPE_BUFFER_LINE); + +/* Initialise une instance sur la base du dérivé de GObject. */ +static int py_buffer_line_init(PyObject *, PyObject *, PyObject *); + + + +/* ------------------ LIAISON DE FONCTIONNALITES AVEC L'API PYTHON ------------------ */ + +  /* Accompagne la création d'une instance dérivée en Python. */  static PyObject *py_buffer_line_new(PyTypeObject *, PyObject *, PyObject *); +#if 0 +  /* Ajoute du texte à formater dans une ligne donnée. */  static PyObject *py_buffer_line_append_text(PyObject *, PyObject *); @@ -54,29 +67,34 @@ static PyObject *py_buffer_line_get_text(PyObject *, PyObject *);  /* Renseigne sur les propriétés particulières liées à une ligne. */  static PyObject *py_buffer_line_get_flags(PyObject *, void *); +#endif + + + +/* ---------------------------------------------------------------------------------- */ +/*                          GLUE POUR CREATION DEPUIS PYTHON                          */ +/* ---------------------------------------------------------------------------------- */  /******************************************************************************  *                                                                             * -*  Paramètres  : type = type du nouvel objet à mettre en place.               * -*                args = éventuelle liste d'arguments.                         * -*                kwds = éventuel dictionnaire de valeurs mises à disposition. * +*  Paramètres  : self = objet à initialiser (théoriquement).                  * +*                args = arguments fournis à l'appel.                          * +*                kwds = arguments de type key=val fournis.                    *  *                                                                             * -*  Description : Accompagne la création d'une instance dérivée en Python.     * +*  Description : Initialise une instance sur la base du dérivé de GObject.    *  *                                                                             * -*  Retour      : Nouvel objet Python mis en place ou NULL en cas d'échec.     * +*  Retour      : 0.                                                           *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -static PyObject *py_buffer_line_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +static int py_buffer_line_init(PyObject *self, 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   */ +    unsigned char col_count;                /* Qté de colonnes attendues   */ +    int ret;                                /* Bilan de lecture des args.  */ +    GBufferLine *line;                      /* Ligne en version native     */  #define BUFFER_LINE_DOC                                                     \      "The BufferLine object is used to display processed data: disassembled" \ @@ -84,51 +102,40 @@ static PyObject *py_buffer_line_new(PyTypeObject *type, PyObject *args, PyObject      "\n"                                                                    \      "Instances can be created using the following constructor:\n"           \      "\n"                                                                    \ -    "    BufferLine()"                                                      \ +    "    BufferLine(col_count)"                                             \ +    "\n"                                                                    \ +    " Where *col_count* is a integer value providing the expected number of"\ +    " rendering columns."                                                   \      "\n"                                                                    \      "Such objets aim to be created from the Chrysalide core only, and"      \      " then get populated on demand. Thus, these lines can be viewed as"     \      " cached lines and their properties have to be set through the"         \      " pychrysalide.glibext.BufferCache instance which contains them." -    /* Validations diverses */ - -    base = get_python_buffer_line_type(); +    /* Récupération des paramètres */ -    if (type == base) -        goto simple_way; +    ret = PyArg_ParseTuple(args, "B", &col_count); +    if (!ret) return -1; -    /* Mise en place d'un type dédié */ +    /* Initialisation d'un objet GLib */ -    first_time = (g_type_from_name(type->tp_name) == 0); +    ret = forward_pygobjet_init(self); +    if (ret == -1) return -1; -    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); +    /* Eléments de 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); +    line = G_BUFFER_LINE(pygobject_get(self)); - exit: +    if (!g_buffer_line_create(line, col_count)) +        return -1; -    return result; +    return 0;  } +#if 0 +  /******************************************************************************  *                                                                             *  *  Paramètres  : self = classe représentant une ligne de tampon.              * @@ -256,6 +263,7 @@ static PyObject *py_buffer_line_get_flags(PyObject *self, void *closure)      return result;  } +#endif  /****************************************************************************** @@ -273,20 +281,24 @@ static PyObject *py_buffer_line_get_flags(PyObject *self, void *closure)  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,              "get_text($self, first_col, last_col, markup, /)\n--\n\nProvide the text of a buffer line."          }, +        */          { NULL }      };      static PyGetSetDef py_buffer_line_getseters[] = { +        /*          {              "flags", py_buffer_line_get_flags, NULL,              "Current flags of the buffer line.", NULL          }, +        */          { NULL }      }; @@ -304,7 +316,8 @@ PyTypeObject *get_python_buffer_line_type(void)          .tp_methods     = py_buffer_line_methods,          .tp_getset      = py_buffer_line_getseters, -        .tp_new         = py_buffer_line_new +        .tp_init        = py_buffer_line_init, +        .tp_new         = py_buffer_line_new,      }; @@ -342,11 +355,13 @@ bool ensure_python_buffer_line_is_registered(void)          if (!register_class_for_pygobject(dict, G_TYPE_BUFFER_LINE, type))              return false; +        /*          if (!define_line_segment_constants(type))              return false;          if (!define_buffer_line_constants(type))              return false; +        */      } diff --git a/plugins/pychrysalide/glibext/constants-ui.c b/plugins/pychrysalide/glibext/constants-ui.c new file mode 100644 index 0000000..4101600 --- /dev/null +++ b/plugins/pychrysalide/glibext/constants-ui.c @@ -0,0 +1,131 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * constants-ui.c - ajout des constantes pour les extensions graphique à la GLib + * + * Copyright (C) 2025 Cyrille Bagard + * + *  This file is part of Chrysalide. + * + *  Chrysalide is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 3 of the License, or + *  (at your option) any later version. + * + *  Chrysalide is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with this program; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + */ + + +#include "constants-ui.h" + + +#include <glibext/bufferline.h> + + +#include "../helpers.h" + + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : type = type dont le dictionnaire est à compléter.            * +*                                                                             * +*  Description : Définit les constantes relatives aux lignes de tampon.       * +*                                                                             * +*  Retour      : true en cas de succès de l'opération, false sinon.           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool define_buffer_line_constants(PyTypeObject *type) +{ +    bool result;                            /* Bilan à retourner           */ +    PyObject *values;                       /* Groupe de valeurs à établir */ + +    values = PyDict_New(); + +    result = add_const_to_group(values, "NONE", BLF_NONE); +    if (result) result = add_const_to_group(values, "HAS_CODE", BLF_HAS_CODE); +    if (result) result = add_const_to_group(values, "IS_LABEL", BLF_IS_LABEL); +    if (result) result = add_const_to_group(values, "ENTRYPOINT", BLF_ENTRYPOINT); +    if (result) result = add_const_to_group(values, "BOOKMARK", BLF_BOOKMARK); +    if (result) result = add_const_to_group(values, "WIDTH_MANAGER", BLF_WIDTH_MANAGER); +    if (result) result = add_const_to_group(values, "ALL", BLF_ALL); + +    if (!result) +    { +        Py_DECREF(values); +        goto exit; +    } + +    result = attach_constants_group_to_type(type, true, "BufferLineFlags", values, +                                            "Optional flags linked to a rendering line."); + + exit: + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : arg = argument quelconque à tenter de convertir.             * +*                dst = destination des valeurs récupérées en cas de succès.   * +*                                                                             * +*  Description : Tente de convertir en constante BufferLineFlags.             * +*                                                                             * +*  Retour      : Bilan de l'opération, voire indications supplémentaires.     * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +int convert_to_buffer_line_flags(PyObject *arg, void *dst) +{ +    int result;                             /* Bilan à retourner           */ +    unsigned long value;                    /* Valeur transcrite           */ + +    result = PyObject_IsInstance(arg, (PyObject *)&PyLong_Type); + +    switch (result) +    { +        case -1: +            /* L'exception est déjà fixée par Python */ +            result = 0; +            break; + +        case 0: +            PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to BufferLineFlags"); +            break; + +        case 1: +            value = PyLong_AsUnsignedLong(arg); + +            if ((value & BLF_ALL) != value) +            { +                PyErr_SetString(PyExc_TypeError, "invalid value for BufferLineFlags"); +                result = 0; +            } + +            else +                *((BufferLineFlags *)dst) = value; + +            break; + +        default: +            assert(false); +            break; + +    } + +    return result; + +} diff --git a/plugins/pychrysalide/glibext/constants-ui.h b/plugins/pychrysalide/glibext/constants-ui.h new file mode 100644 index 0000000..6c7bc6e --- /dev/null +++ b/plugins/pychrysalide/glibext/constants-ui.h @@ -0,0 +1,41 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * constants-ui.h - prototypes pour l'ajout des constantes pour les extensions graphique à la GLib + * + * Copyright (C) 2025 Cyrille Bagard + * + *  This file is part of Chrysalide. + * + *  Chrysalide is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 3 of the License, or + *  (at your option) any later version. + * + *  Chrysalide is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with this program; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_GLIBEXT_CONSTANTS_UI_H +#define _PLUGINS_PYCHRYSALIDE_GLIBEXT_CONSTANTS_UI_H + + +#include <Python.h> +#include <stdbool.h> + + +/* Définit les constantes relatives aux lignes de tampon. */ +bool define_buffer_line_constants(PyTypeObject *); + +/* Tente de convertir en constante BufferLineFlags. */ +int convert_to_buffer_line_flags(PyObject *, void *); + + + +#endif  /* _PLUGINS_PYCHRYSALIDE_GLIBEXT_CONSTANTS_UI_H */ diff --git a/plugins/pychrysalide/glibext/constants.c b/plugins/pychrysalide/glibext/constants.c index 90ce8cd..f733cf6 100644 --- a/plugins/pychrysalide/glibext/constants.c +++ b/plugins/pychrysalide/glibext/constants.c @@ -29,7 +29,6 @@  /*  #include <i18n.h> -#include <glibext/bufferline.h>  #include <glibext/comparison.h>  #include <glibext/configuration.h>  #include <glibext/linesegment.h> @@ -159,105 +158,6 @@ int convert_to_portion_access_rights(PyObject *arg, void *dst)  *                                                                             *  *  Paramètres  : type = type dont le dictionnaire est à compléter.            *  *                                                                             * -*  Description : Définit les constantes relatives aux lignes de tampon.       * -*                                                                             * -*  Retour      : true en cas de succès de l'opération, false sinon.           * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool define_buffer_line_constants(PyTypeObject *type) -{ -    bool result;                            /* Bilan à retourner           */ -    PyObject *values;                       /* Groupe de valeurs à établir */ - -    values = PyDict_New(); - -    result = add_const_to_group(values, "NONE", BLF_NONE); -    if (result) result = add_const_to_group(values, "HAS_CODE", BLF_HAS_CODE); -    if (result) result = add_const_to_group(values, "IS_LABEL", BLF_IS_LABEL); -    if (result) result = add_const_to_group(values, "ENTRYPOINT", BLF_ENTRYPOINT); -    if (result) result = add_const_to_group(values, "BOOKMARK", BLF_BOOKMARK); -    if (result) result = add_const_to_group(values, "WIDTH_MANAGER", BLF_WIDTH_MANAGER); -    if (result) result = add_const_to_group(values, "ALL", BLF_ALL); - -    if (!result) -    { -        Py_DECREF(values); -        goto exit; -    } - -    result = attach_constants_group_to_type(type, true, "BufferLineFlags", values, -                                            "Optional flags linked to a rendering line."); - - exit: - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : arg = argument quelconque à tenter de convertir.             * -*                dst = destination des valeurs récupérées en cas de succès.   * -*                                                                             * -*  Description : Tente de convertir en constante BufferLineFlags.             * -*                                                                             * -*  Retour      : Bilan de l'opération, voire indications supplémentaires.     * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -int convert_to_buffer_line_flags(PyObject *arg, void *dst) -{ -    int result;                             /* Bilan à retourner           */ -    unsigned long value;                    /* Valeur transcrite           */ - -    result = PyObject_IsInstance(arg, (PyObject *)&PyLong_Type); - -    switch (result) -    { -        case -1: -            /* L'exception est déjà fixée par Python */ -            result = 0; -            break; - -        case 0: -            PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to BufferLineFlags"); -            break; - -        case 1: -            value = PyLong_AsUnsignedLong(arg); - -            if ((value & BLF_ALL) != value) -            { -                PyErr_SetString(PyExc_TypeError, "invalid value for BufferLineFlags"); -                result = 0; -            } - -            else -                *((BufferLineFlags *)dst) = value; - -            break; - -        default: -            assert(false); -            break; - -    } - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : type = type dont le dictionnaire est à compléter.            * -*                                                                             *  *  Description : Définit les constantes relatives aux modes de comparaison.   *  *                                                                             *  *  Retour      : true en cas de succès de l'opération, false sinon.           * diff --git a/plugins/pychrysalide/glibext/constants.h b/plugins/pychrysalide/glibext/constants.h index a950125..c695aa9 100644 --- a/plugins/pychrysalide/glibext/constants.h +++ b/plugins/pychrysalide/glibext/constants.h @@ -39,12 +39,6 @@ int convert_to_portion_access_rights(PyObject *, void *);  #if 0 -/* Définit les constantes relatives aux lignes de tampon. */ -bool define_buffer_line_constants(PyTypeObject *); - -/* Tente de convertir en constante BufferLineFlags. */ -int convert_to_buffer_line_flags(PyObject *, void *); -  /* Définit les constantes relatives aux modes de comparaison. */  bool define_comparable_item_constants(PyTypeObject *); diff --git a/plugins/pychrysalide/glibext/generator.c b/plugins/pychrysalide/glibext/generator.c index d7e96fd..3a9a8ab 100644 --- a/plugins/pychrysalide/glibext/generator.c +++ b/plugins/pychrysalide/glibext/generator.c @@ -1,8 +1,8 @@  /* Chrysalide - Outil d'analyse de fichiers binaires - * linegen.c - équivalent Python du fichier "glibext/linegen.h" + * generator.c - équivalent Python du fichier "glibext/generator.h"   * - * Copyright (C) 2018-2019 Cyrille Bagard + * Copyright (C) 2018-2025 Cyrille Bagard   *   *  This file is part of Chrysalide.   * @@ -22,21 +22,21 @@   */ -#include "linegen.h" +#include "generator.h"  #include <pygobject.h> -#include <glibext/linegen-int.h> +#include <glibext/generator-int.h>  #include "bufferline.h" -#include "constants.h" -#include "linecursor.h" +#include "constants-ui.h" +//#include "linecursor.h"  #include "../access.h"  #include "../helpers.h" -#include "../analysis/content.h" +//#include "../analysis/content.h" @@ -44,42 +44,55 @@  /* Procède à l'initialisation de l'interface de génération. */ -static void py_line_generator_interface_init(GLineGeneratorIface *, gpointer *); +static void py_token_generator_interface_init(GTokenGeneratorInterface *, gpointer *);  /* Indique le nombre de ligne prêtes à être générées. */ -static size_t py_line_generator_count_lines_wrapper(const GLineGenerator *); +static size_t py_token_generator_count_lines_wrapper(const GTokenGenerator *); + +/* Renseigne sur les propriétés liées à un générateur. */ +static BufferLineFlags py_token_generator_get_flags_wrapper(const GTokenGenerator *, size_t, size_t); + +/*Description : Etablit dans une ligne de rendu le contenu représenté. */ +static void py_token_generator_populate_line_wrappper(const GTokenGenerator *, size_t, size_t, GBufferLine *, void *); + + +#if 0 +  /* Retrouve l'emplacement correspondant à une position donnée. */ -static void py_line_generator_compute_cursor_wrapper(const GLineGenerator *, gint, size_t, size_t, GLineCursor **); +static void py_token_generator_compute_cursor_wrapper(const GTokenGenerator *, gint, size_t, size_t, GLineCursor **);  /* Détermine si le conteneur s'inscrit dans une plage donnée. */ -static int py_line_generator_contain_cursor_wrapper(const GLineGenerator *, size_t, size_t, const GLineCursor *); +static int py_token_generator_contain_cursor_wrapper(const GTokenGenerator *, size_t, size_t, const GLineCursor *); + + +#endif -/* Renseigne sur les propriétés liées à un générateur. */ -static BufferLineFlags py_line_generator_get_flags_wrapper(const GLineGenerator *, size_t, size_t); -/* Imprime dans une ligne de rendu le contenu représenté. */ -static void py_line_generator_print_wrapper(GLineGenerator *, GBufferLine *, size_t, size_t, const GBinContent *); +/* ------------------ LIAISON DE FONCTIONNALITES AVEC L'API PYTHON ------------------ */ -/* ------------------------- CONNEXION AVEC L'API DE PYTHON ------------------------- */ +/* Renseigne sur les propriétés liées à un générateur. */ +static PyObject *py_token_generator_get_flags(PyObject *, PyObject *); + +/* Etablit dans une ligne de rendu le contenu représenté. */ +static PyObject *py_token_generator_populate_line(PyObject *self, PyObject *args); + +#if 0  /* Retrouve l'emplacement correspondant à une position donnée. */ -static PyObject *py_line_generator_compute_cursor(PyObject *, PyObject *); +static PyObject *py_token_generator_compute_cursor(PyObject *, PyObject *);  /* Détermine si le conteneur s'inscrit dans une plage donnée. */ -static PyObject *py_line_generator_contain_cursor(PyObject *, PyObject *); +static PyObject *py_token_generator_contain_cursor(PyObject *, PyObject *); -/* Renseigne sur les propriétés liées à un générateur. */ -static PyObject *py_line_generator_get_flags(PyObject *, PyObject *); +#endif -/* Imprime dans une ligne de rendu le contenu représenté. */ -static PyObject *py_line_generator_print(PyObject *, PyObject *);  /* Indique le nombre de ligne prêtes à être générées. */ -static PyObject *py_line_generator_get_lines_count(PyObject *, void *); +static PyObject *py_token_generator_get_lines_count(PyObject *, void *); @@ -101,31 +114,33 @@ static PyObject *py_line_generator_get_lines_count(PyObject *, void *);  *                                                                             *  ******************************************************************************/ -static void py_line_generator_interface_init(GLineGeneratorIface *iface, gpointer *unused) +static void py_token_generator_interface_init(GTokenGeneratorInterface *iface, gpointer *unused)  { -#define LINE_GENERATOR_DOC                                                  \ -    "LineGenerator gives an interface to all objects which aim to produce"  \ +#define TOKEN_GENERATOR_DOC                                                 \ +    "TokenGenerator gives an interface to all objects which aim to produce" \      " content for rendering lines. Such lines can be exported to graphical" \      " interfaces or text files.\n"                                          \      "\n"                                                                    \      "A typical class declaration for a new implementation looks like:\n"    \      "\n"                                                                    \ -    "    class NewImplem(GObject.Object, LineGenerator):\n"                 \ +    "    class NewImplem(GObject.Object, TokenGenerator):\n"                \      "        ...\n"                                                         \      "\n"                                                                    \      "The following methods have to be defined for new implementations:\n"   \ -    "* pychrysalide.glibext.LineGenerator._count_lines();\n"                \ -    "* pychrysalide.glibext.LineGenerator._compute_cursor();\n"             \ -    "* pychrysalide.glibext.LineGenerator._contain_cursor();\n"             \ -    "* pychrysalide.glibext.LineGenerator._get_flags();\n"                  \ -    "* pychrysalide.glibext.LineGenerator._print();\n"                      \ - -    iface->count = py_line_generator_count_lines_wrapper; -    iface->compute = py_line_generator_compute_cursor_wrapper; -    iface->contain = py_line_generator_contain_cursor_wrapper; -    iface->get_flags = py_line_generator_get_flags_wrapper; -    iface->print = py_line_generator_print_wrapper; +    "* pychrysalide.glibext.TokenGenerator._count_lines();\n"               \ +    "* pychrysalide.glibext.TokenGenerator._get_flags();\n"                 \ +    "* pychrysalide.glibext.TokenGenerator._populate_line();\n"             \ +    "* pychrysalide.glibext.TokenGenerator._compute_cursor();\n"            \ +    "* pychrysalide.glibext.TokenGenerator._contain_cursor().\n" + +    iface->count = py_token_generator_count_lines_wrapper; +    iface->get_flags = py_token_generator_get_flags_wrapper; +    iface->populate = py_token_generator_populate_line_wrappper; +#if 0 +    iface->compute = py_token_generator_compute_cursor_wrapper; +    iface->contain = py_token_generator_contain_cursor_wrapper; +#endif  } @@ -142,7 +157,7 @@ static void py_line_generator_interface_init(GLineGeneratorIface *iface, gpointe  *                                                                             *  ******************************************************************************/ -static size_t py_line_generator_count_lines_wrapper(const GLineGenerator *generator) +static size_t py_token_generator_count_lines_wrapper(const GTokenGenerator *generator)  {      size_t result;                          /* Décompte à retourner        */      PyGILState_STATE gstate;                /* Sauvegarde d'environnement  */ @@ -150,7 +165,7 @@ static size_t py_line_generator_count_lines_wrapper(const GLineGenerator *genera      PyObject *pyret;                        /* Bilan de consultation       */      int ret;                                /* Bilan d'une conversion      */ -#define LINE_GENERATOR_COUNT_LINES_WRAPPER PYTHON_WRAPPER_DEF       \ +#define TOKEN_GENERATOR_COUNT_LINES_WRAPPER PYTHON_WRAPPER_DEF       \  (                                                                   \      _count_lines, "$self, /",                                       \      METH_NOARGS,                                                    \ @@ -193,61 +208,61 @@ static size_t py_line_generator_count_lines_wrapper(const GLineGenerator *genera  /******************************************************************************  *                                                                             *  *  Paramètres  : generator = générateur à consulter.                          * -*                x         = position géographique sur la ligne concernée.    *  *                index     = indice de cette même ligne dans le tampon global.*  *                repeat    = indice d'utilisations successives du générateur. *  *                                                                             * -*  Description : Retrouve l'emplacement correspondant à une position donnée.  * +*  Description : Renseigne sur les propriétés liées à un générateur.          *  *                                                                             * -*  Retour      : Emplacement constitué.                                       * +*  Retour      : Propriétés particulières associées.                          *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -static void py_line_generator_compute_cursor_wrapper(const GLineGenerator *generator, gint x, size_t index, size_t repeat, GLineCursor **cursor) +static BufferLineFlags py_token_generator_get_flags_wrapper(const GTokenGenerator *generator, size_t index, size_t repeat)  { +    BufferLineFlags result;                 /* Fanions à retourner         */      PyGILState_STATE gstate;                /* Sauvegarde d'environnement  */      PyObject *pyobj;                        /* Objet Python concerné       */      PyObject *args;                         /* Arguments pour l'appel      */      PyObject *pyret;                        /* Bilan de consultation       */      int ret;                                /* Bilan d'une conversion      */ -#define LINE_GENERATOR_COMPUTE_CURSOR_WRAPPER PYTHON_WRAPPER_DEF    \ +#define TOKEN_GENERATOR_GET_FLAGS_WRAPPER PYTHON_WRAPPER_DEF         \  (                                                                   \ -    _compute_cursor, "$self, x, index, repeat, /",                  \ +    _get_flags, "$self, index, repeat, /",                          \      METH_VARARGS,                                                   \ -    "Abstract method used to create a new cursor for a given"       \ -    " location inside displayed lines.\n"                           \ +    "Abstract method used to provide flags for a given rendering"   \ +    " line.\n"                                                      \      "\n"                                                            \ -    "The position on the horizontal axis, the line index and the"   \ -    " number of repetitions (only relevant if the generator"        \ -    " produces several lines) give indications about the active"    \ -    " position.\n"                                                  \ +    "The line index and the number of repetitions (only relevant"   \ +    " if the generator produces several lines) give indications"    \ +    " about the active position.\n"                                 \      "\n"                                                            \ -    "The result has to be a pychrysalide.glibext.LineCursor"        \ -    " instance."                                                    \ +    "The result has to be a"                                        \ +    " pychrysalide.glibext.BufferLine.BufferLineFlags value.\n"     \  ) +    result = BLF_NONE; +      gstate = PyGILState_Ensure();      pyobj = pygobject_new(G_OBJECT(generator)); -    if (has_python_method(pyobj, "_compute_cursor")) +    if (has_python_method(pyobj, "_get_flags"))      { -        args = PyTuple_New(3); -        PyTuple_SetItem(args, 0, PyLong_FromSize_t(x)); -        PyTuple_SetItem(args, 1, PyLong_FromSize_t(index)); -        PyTuple_SetItem(args, 2, PyLong_FromSize_t(repeat)); +        args = PyTuple_New(2); +        PyTuple_SetItem(args, 0, PyLong_FromSize_t(index)); +        PyTuple_SetItem(args, 1, PyLong_FromSize_t(repeat)); -        pyret = run_python_method(pyobj, "_compute_cursor", args); +        pyret = run_python_method(pyobj, "_get_flags", args);          if (pyret != NULL)          { -            ret = convert_to_line_cursor(pyret, cursor); +            ret = convert_to_buffer_line_flags(pyret, &result);              if (ret != 1) -                *cursor = NULL; +                result = BLF_NONE;              Py_DECREF(pyret); @@ -261,75 +276,66 @@ static void py_line_generator_compute_cursor_wrapper(const GLineGenerator *gener      PyGILState_Release(gstate); +    return result; +  }  /******************************************************************************  *                                                                             * -*  Paramètres  : generator = générateur à consulter.                          * +*  Paramètres  : generator = générateur à utiliser pour l'impression.         *  *                index     = indice de cette même ligne dans le tampon global.*  *                repeat    = indice d'utilisations successives du générateur. * -*                cursor    = emplacement à analyser.                          * +*                line      = ligne de rendu à compléter.                      * +*                data      = éventuelle donnée complémentaire fournie.        *  *                                                                             * -*  Description : Détermine si le conteneur s'inscrit dans une plage donnée.   * +*  Description : Etablit dans une ligne de rendu le contenu représenté.       *  *                                                                             * -*  Retour      : Bilan de la détermination, utilisable en comparaisons.       * +*  Retour      : -                                                            *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -static int py_line_generator_contain_cursor_wrapper(const GLineGenerator *generator, size_t index, size_t repeat, const GLineCursor *cursor) +static void py_token_generator_populate_line_wrappper(const GTokenGenerator *generator, size_t index, size_t repeat, GBufferLine *line, void *data)  { -    int result;                             /* Bilan d'analyse à retourner */      PyGILState_STATE gstate;                /* Sauvegarde d'environnement  */      PyObject *pyobj;                        /* Objet Python concerné       */      PyObject *args;                         /* Arguments pour l'appel      */      PyObject *pyret;                        /* Bilan de consultation       */ -    int ret;                                /* Bilan d'une conversion      */ -#define LINE_GENERATOR_CONTAIN_CURSOR_WRAPPER PYTHON_WRAPPER_DEF    \ +#define TOKEN_GENERATOR_POPULATE_LINE_WRAPPER PYTHON_WRAPPER_DEF    \  (                                                                   \ -    _contain_cursor, "$self, index, repeat, cursor, /",             \ +    _populate_line, "$self, index, repeat, line, /",                \      METH_VARARGS,                                                   \ -    "Abstract method used to check the position of a cursor in"     \ -    " relation to rendering lines.\n"                               \ +    "Abstract method used to generate content into a rendering"     \ +    " line.\n"                                                      \      "\n"                                                            \ -    "The line index and the number of repetitions (only relevant"   \ +    "This rendering output is pointed by the *line* argument, which"\ +    " is a provided pychrysalide.glibext.BufferLine instance. The"  \ +    " line *index* and the number of repetitions (only relevant"    \      " if the generator produces several lines) give indications"    \ -    " about the active position. The cursor is a"                   \ -    " pychrysalide.glibext.LineCursor instance.\n"                  \ +    " about the current rendering position.\n"                      \      "\n"                                                            \ -    "The result has to be an integer less than, equal to, or"       \ -    " greater than zero if the cursor is, respectively, before,"    \ -    " inside or after the area covered by the generator."           \ +    "If set, the content is a pychrysalide.analysis.BinContent"     \ +    " instance providing access to the processed binary data."      \  ) -    result = 0; -      gstate = PyGILState_Ensure();      pyobj = pygobject_new(G_OBJECT(generator)); -    if (has_python_method(pyobj, "_contain_cursor")) +    if (has_python_method(pyobj, "_populate_line"))      {          args = PyTuple_New(3);          PyTuple_SetItem(args, 0, PyLong_FromSize_t(index));          PyTuple_SetItem(args, 1, PyLong_FromSize_t(repeat)); -        PyTuple_SetItem(args, 2, pygobject_new(G_OBJECT(cursor))); +        PyTuple_SetItem(args, 2, pygobject_new(G_OBJECT(line))); +        //PyTuple_SetItem(args, 3, pygobject_new(G_OBJECT(content))); -        pyret = run_python_method(pyobj, "_contain_cursor", args); - -        if (pyret != NULL) -        { -            ret = PyLong_Check(pyret); +        pyret = run_python_method(pyobj, "_populate_line", args); -            if (ret) -                result = PyLong_AsLong(pyret); - -            Py_DECREF(pyret); - -        } +        Py_XDECREF(pyret);          Py_DECREF(args); @@ -339,69 +345,70 @@ static int py_line_generator_contain_cursor_wrapper(const GLineGenerator *genera      PyGILState_Release(gstate); -    return result; -  } +#if 0 + +  /******************************************************************************  *                                                                             *  *  Paramètres  : generator = générateur à consulter.                          * +*                x         = position géographique sur la ligne concernée.    *  *                index     = indice de cette même ligne dans le tampon global.*  *                repeat    = indice d'utilisations successives du générateur. *  *                                                                             * -*  Description : Renseigne sur les propriétés liées à un générateur.          * +*  Description : Retrouve l'emplacement correspondant à une position donnée.  *  *                                                                             * -*  Retour      : Propriétés particulières associées.                          * +*  Retour      : Emplacement constitué.                                       *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -static BufferLineFlags py_line_generator_get_flags_wrapper(const GLineGenerator *generator, size_t index, size_t repeat) +static void py_token_generator_compute_cursor_wrapper(const GTokenGenerator *generator, gint x, size_t index, size_t repeat, GLineCursor **cursor)  { -    BufferLineFlags result;                 /* Fanions à retourner         */      PyGILState_STATE gstate;                /* Sauvegarde d'environnement  */      PyObject *pyobj;                        /* Objet Python concerné       */      PyObject *args;                         /* Arguments pour l'appel      */      PyObject *pyret;                        /* Bilan de consultation       */      int ret;                                /* Bilan d'une conversion      */ -#define LINE_GENERATOR_GET_FLAGS_WRAPPER PYTHON_WRAPPER_DEF         \ +#define TOKEN_GENERATOR_COMPUTE_CURSOR_WRAPPER PYTHON_WRAPPER_DEF    \  (                                                                   \ -    _get_flags, "$self, index, repeat, /",                          \ +    _compute_cursor, "$self, x, index, repeat, /",                  \      METH_VARARGS,                                                   \ -    "Abstract method used to provide flags for a given rendering"   \ -    " line.\n"                                                      \ +    "Abstract method used to create a new cursor for a given"       \ +    " location inside displayed lines.\n"                           \      "\n"                                                            \ -    "The line index and the number of repetitions (only relevant"   \ -    " if the generator produces several lines) give indications"    \ -    " about the active position.\n"                                 \ +    "The position on the horizontal axis, the line index and the"   \ +    " number of repetitions (only relevant if the generator"        \ +    " produces several lines) give indications about the active"    \ +    " position.\n"                                                  \      "\n"                                                            \ -    "The result has to be a"                                        \ -    " pychrysalide.glibext.BufferLine.BufferLineFlags value.\n"     \ +    "The result has to be a pychrysalide.glibext.LineCursor"        \ +    " instance."                                                    \  ) -    result = BLF_NONE; -      gstate = PyGILState_Ensure();      pyobj = pygobject_new(G_OBJECT(generator)); -    if (has_python_method(pyobj, "_get_flags")) +    if (has_python_method(pyobj, "_compute_cursor"))      { -        args = PyTuple_New(2); -        PyTuple_SetItem(args, 0, PyLong_FromSize_t(index)); -        PyTuple_SetItem(args, 1, PyLong_FromSize_t(repeat)); +        args = PyTuple_New(3); +        PyTuple_SetItem(args, 0, PyLong_FromSize_t(x)); +        PyTuple_SetItem(args, 1, PyLong_FromSize_t(index)); +        PyTuple_SetItem(args, 2, PyLong_FromSize_t(repeat)); -        pyret = run_python_method(pyobj, "_get_flags", args); +        pyret = run_python_method(pyobj, "_compute_cursor", args);          if (pyret != NULL)          { -            ret = convert_to_buffer_line_flags(pyret, &result); +            ret = convert_to_line_cursor(pyret, cursor);              if (ret != 1) -                result = BLF_NONE; +                *cursor = NULL;              Py_DECREF(pyret); @@ -415,65 +422,75 @@ static BufferLineFlags py_line_generator_get_flags_wrapper(const GLineGenerator      PyGILState_Release(gstate); -    return result; -  }  /******************************************************************************  *                                                                             * -*  Paramètres  : generator = générateur à utiliser pour l'impression.         * -*                line      = ligne de rendu à compléter.                      * +*  Paramètres  : generator = générateur à consulter.                          *  *                index     = indice de cette même ligne dans le tampon global.*  *                repeat    = indice d'utilisations successives du générateur. * -*                content   = éventuel contenu binaire brut à imprimer.        * +*                cursor    = emplacement à analyser.                          *  *                                                                             * -*  Description : Imprime dans une ligne de rendu le contenu représenté.       * +*  Description : Détermine si le conteneur s'inscrit dans une plage donnée.   *  *                                                                             * -*  Retour      : -                                                            * +*  Retour      : Bilan de la détermination, utilisable en comparaisons.       *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -static void py_line_generator_print_wrapper(GLineGenerator *generator, GBufferLine *line, size_t index, size_t repeat, const GBinContent *content) +static int py_token_generator_contain_cursor_wrapper(const GTokenGenerator *generator, size_t index, size_t repeat, const GLineCursor *cursor)  { +    int result;                             /* Bilan d'analyse à retourner */      PyGILState_STATE gstate;                /* Sauvegarde d'environnement  */      PyObject *pyobj;                        /* Objet Python concerné       */      PyObject *args;                         /* Arguments pour l'appel      */      PyObject *pyret;                        /* Bilan de consultation       */ +    int ret;                                /* Bilan d'une conversion      */ -#define LINE_GENERATOR_PRINT_WRAPPER PYTHON_WRAPPER_DEF             \ +#define TOKEN_GENERATOR_CONTAIN_CURSOR_WRAPPER PYTHON_WRAPPER_DEF    \  (                                                                   \ -    _print, "$self, line, index, repeat, content, /",               \ +    _contain_cursor, "$self, index, repeat, cursor, /",             \      METH_VARARGS,                                                   \ -    "Abstract method used to generate content into a rendering"     \ -    " line, which is a provided pychrysalide.glibext.BufferLine"    \ -    " instance.\n"                                                  \ +    "Abstract method used to check the position of a cursor in"     \ +    " relation to rendering lines.\n"                               \      "\n"                                                            \      "The line index and the number of repetitions (only relevant"   \      " if the generator produces several lines) give indications"    \ -    " about the current rendering position.\n"                      \ +    " about the active position. The cursor is a"                   \ +    " pychrysalide.glibext.LineCursor instance.\n"                  \      "\n"                                                            \ -    "If set, the content is a pychrysalide.analysis.BinContent"     \ -    " instance providing access to the processed binary data."      \ +    "The result has to be an integer less than, equal to, or"       \ +    " greater than zero if the cursor is, respectively, before,"    \ +    " inside or after the area covered by the generator."           \  ) +    result = 0; +      gstate = PyGILState_Ensure();      pyobj = pygobject_new(G_OBJECT(generator)); -    if (has_python_method(pyobj, "_print")) +    if (has_python_method(pyobj, "_contain_cursor"))      { -        args = PyTuple_New(4); -        PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(line))); -        PyTuple_SetItem(args, 1, PyLong_FromSize_t(index)); -        PyTuple_SetItem(args, 2, PyLong_FromSize_t(repeat)); -        PyTuple_SetItem(args, 3, pygobject_new(G_OBJECT(content))); +        args = PyTuple_New(3); +        PyTuple_SetItem(args, 0, PyLong_FromSize_t(index)); +        PyTuple_SetItem(args, 1, PyLong_FromSize_t(repeat)); +        PyTuple_SetItem(args, 2, pygobject_new(G_OBJECT(cursor))); -        pyret = run_python_method(pyobj, "_print", args); +        pyret = run_python_method(pyobj, "_contain_cursor", args); -        Py_XDECREF(pyret); +        if (pyret != NULL) +        { +            ret = PyLong_Check(pyret); + +            if (ret) +                result = PyLong_AsLong(pyret); + +            Py_DECREF(pyret); + +        }          Py_DECREF(args); @@ -483,12 +500,16 @@ static void py_line_generator_print_wrapper(GLineGenerator *generator, GBufferLi      PyGILState_Release(gstate); +    return result; +  } +#endif +  /* ---------------------------------------------------------------------------------- */ -/*                           CONNEXION AVEC L'API DE PYTHON                           */ +/*                    LIAISON DE FONCTIONNALITES AVEC L'API PYTHON                    */  /* ---------------------------------------------------------------------------------- */ @@ -497,57 +518,45 @@ static void py_line_generator_print_wrapper(GLineGenerator *generator, GBufferLi  *  Paramètres  : self = classe représentant un générateur à manipuler.        *  *                args = arguments fournis à l'appel.                          *  *                                                                             * -*  Description : Retrouve l'emplacement correspondant à une position donnée.  * +*  Description : Renseigne sur les propriétés liées à un générateur.          *  *                                                                             * -*  Retour      : Emplacement constitué.                                       * +*  Retour      : Propriétés particulières associées.                          *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -static PyObject *py_line_generator_compute_cursor(PyObject *self, PyObject *args) +static PyObject *py_token_generator_get_flags(PyObject *self, PyObject *args)  {      PyObject *result;                       /* Propriétés à retourner      */ -    int x;                                  /* Position horizontale        */      size_t index;                           /* Indice dans le tampon       */      size_t repeat;                          /* Utilisations successives    */      int ret;                                /* Bilan de lecture des args.  */ -    GLineGenerator *generator;              /* Version native              */ -    GLineCursor *cursor;                    /* Curseur nouveau obtenu      */ +    GTokenGenerator *generator;             /* Version native              */ +    BufferLineFlags flags;                  /* Propriétés courantes        */ -#define LINE_GENERATOR_COMPUTE_CURSOR_METHOD PYTHON_METHOD_DEF      \ -(                                                                   \ -    compute_cursor, "$self, x, index, repeat, /",                   \ -    METH_VARARGS, py_line_generator,                                \ -    "Create a a new cursor for a given location inside displayed"   \ -    " lines.\n"                                                     \ -    "\n"                                                            \ -    "The position on the horizontal axis, the line index and the"   \ -    " number of repetitions (only relevant if the generator"        \ -    " produces several lines) give indications about the active"    \ -    " position.\n"                                                  \ -    "\n"                                                            \ -    "The result has to be a pychrysalide.glibext.LineCursor"        \ -    " instance."                                                    \ +#define TOKEN_GENERATOR_GET_FLAGS_METHOD PYTHON_METHOD_DEF              \ +(                                                                       \ +    get_flags, "$self, index, repeat, /",                               \ +    METH_VARARGS, py_token_generator,                                   \ +    "Get the flags of a given position from the generator.\n"           \ +    "\n"                                                                \ +    "The line index and the number of repetitions (only relevant"       \ +    " if the generator produces several lines) give indications"        \ +    " about the active position.\n"                                     \ +    "\n"                                                                \ +    "The result is a pychrysalide.glibext.BufferLine.BufferLineFlags"   \ +    " value."                                                           \  ) -    ret = PyArg_ParseTuple(args, "inn", &x, &index, &repeat); +    ret = PyArg_ParseTuple(args, "nn", &index, &repeat);      if (!ret) return NULL; -    generator = G_LINE_GENERATOR(pygobject_get(self)); +    generator = G_TOKEN_GENERATOR(pygobject_get(self)); -    cursor = g_line_generator_compute_cursor(generator, x, index, repeat); +    flags = g_token_generator_get_flags(generator, index, repeat); -    if (cursor != NULL) -    { -        result = pygobject_new(G_OBJECT(cursor)); -        g_object_unref(G_OBJECT(cursor)); -    } -    else -    { -        result = Py_None; -        Py_INCREF(result); -    } +    result = cast_with_constants_group_from_type(get_python_buffer_line_type(), "BufferLineFlags", flags);      return result; @@ -559,99 +568,108 @@ static PyObject *py_line_generator_compute_cursor(PyObject *self, PyObject *args  *  Paramètres  : self = classe représentant un générateur à manipuler.        *  *                args = arguments fournis à l'appel.                          *  *                                                                             * -*  Description : Détermine si le conteneur s'inscrit dans une plage donnée.   * +*  Description : Etablit dans une ligne de rendu le contenu représenté.       *  *                                                                             * -*  Retour      : Bilan de la détermination, utilisable en comparaisons.       * +*  Retour      : -                                                            *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -static PyObject *py_line_generator_contain_cursor(PyObject *self, PyObject *args) +static PyObject *py_token_generator_populate_line(PyObject *self, PyObject *args)  { -    PyObject *result;                       /* Propriétés à retourner      */ +    GBufferLine *line;                      /* Ligne de rendu à compléter  */      size_t index;                           /* Indice dans le tampon       */      size_t repeat;                          /* Utilisations successives    */ -    GLineCursor *cursor;                    /* Curseur à venir situer      */ +    GTokenGenerator *generator;             /* Version native              */      int ret;                                /* Bilan de lecture des args.  */ -    GLineGenerator *generator;              /* Version native              */ -    int status;                             /* Bilan d'une analyse         */ -#define LINE_GENERATOR_CONTAIN_CURSOR_METHOD PYTHON_METHOD_DEF      \ +#define TOKEN_GENERATOR_POPULATE_LINE_METHOD PYTHON_METHOD_DEF      \  (                                                                   \ -    contain_cursor, "$self, index, repeat, cursor, /",              \ -    METH_VARARGS, py_line_generator,                                \ -    "Check the position of a cursor in relation to rendering"       \ -    " lines.\n"                                                     \ +    populate_line, "$self, index, repeat, line, /",                 \ +    METH_VARARGS, py_token_generator,                               \ +    "Produce output into a rendering line with optional content.\n" \      "\n"                                                            \ -    "The line index and the number of repetitions (only relevant"   \ -    " if the generator produces several lines) give indications"    \ -    " about the active position. The cursor is a"                   \ -    " pychrysalide.glibext.LineCursor instance.\n"                  \ +    "The provided *line* is a pychrysalide.glibext.BufferLine"      \ +    " instance. The *index* and the number of repetitions (only"    \ +    " relevant if the generator produces several lines) give"       \ +    " indications about the current rendering position.\n"          \      "\n"                                                            \ -    "The result has to be an integer less than, equal to, or"       \ -    " greater than zero if the cursor is, respectively, before,"    \ -    " inside or after the area covered by the generator."           \ +    "If set, the content is a pychrysalide.analysis.BinContent"     \ +    " instance providing access to the processed binary data."      \  ) -    ret = PyArg_ParseTuple(args, "nnO&", &index, &repeat, convert_to_line_cursor, &cursor); +    ret = PyArg_ParseTuple(args, "nnO&", &index, &repeat, convert_to_buffer_line, &line);      if (!ret) return NULL; -    generator = G_LINE_GENERATOR(pygobject_get(self)); +    generator = G_TOKEN_GENERATOR(pygobject_get(self)); -    status = g_line_generator_contain_cursor(generator, index, repeat, cursor); +    g_token_generator_populate_line(generator, index, repeat, line, NULL); -    result = PyLong_FromLong(status); - -    return result; +    Py_RETURN_NONE;  } + +#if 0 +  /******************************************************************************  *                                                                             *  *  Paramètres  : self = classe représentant un générateur à manipuler.        *  *                args = arguments fournis à l'appel.                          *  *                                                                             * -*  Description : Renseigne sur les propriétés liées à un générateur.          * +*  Description : Retrouve l'emplacement correspondant à une position donnée.  *  *                                                                             * -*  Retour      : Propriétés particulières associées.                          * +*  Retour      : Emplacement constitué.                                       *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -static PyObject *py_line_generator_get_flags(PyObject *self, PyObject *args) +static PyObject *py_token_generator_compute_cursor(PyObject *self, PyObject *args)  {      PyObject *result;                       /* Propriétés à retourner      */ +    int x;                                  /* Position horizontale        */      size_t index;                           /* Indice dans le tampon       */      size_t repeat;                          /* Utilisations successives    */      int ret;                                /* Bilan de lecture des args.  */ -    GLineGenerator *generator;              /* Version native              */ -    BufferLineFlags flags;                  /* Propriétés courantes        */ +    GTokenGenerator *generator;              /* Version native              */ +    GLineCursor *cursor;                    /* Curseur nouveau obtenu      */ -#define LINE_GENERATOR_GET_FLAGS_METHOD PYTHON_METHOD_DEF               \ -(                                                                       \ -    get_flags, "$self, index, repeat, /",                               \ -    METH_VARARGS, py_line_generator,                                    \ -    "Get the flags of a given position from the generator.\n"           \ -    "\n"                                                                \ -    "The line index and the number of repetitions (only relevant"       \ -    " if the generator produces several lines) give indications"        \ -    " about the active position.\n"                                     \ -    "\n"                                                                \ -    "The result is a pychrysalide.glibext.BufferLine.BufferLineFlags"   \ -    " value."                                                           \ +#define TOKEN_GENERATOR_COMPUTE_CURSOR_METHOD PYTHON_METHOD_DEF      \ +(                                                                   \ +    compute_cursor, "$self, x, index, repeat, /",                   \ +    METH_VARARGS, py_token_generator,                                \ +    "Create a a new cursor for a given location inside displayed"   \ +    " lines.\n"                                                     \ +    "\n"                                                            \ +    "The position on the horizontal axis, the line index and the"   \ +    " number of repetitions (only relevant if the generator"        \ +    " produces several lines) give indications about the active"    \ +    " position.\n"                                                  \ +    "\n"                                                            \ +    "The result has to be a pychrysalide.glibext.LineCursor"        \ +    " instance."                                                    \  ) -    ret = PyArg_ParseTuple(args, "nn", &index, &repeat); +    ret = PyArg_ParseTuple(args, "inn", &x, &index, &repeat);      if (!ret) return NULL; -    generator = G_LINE_GENERATOR(pygobject_get(self)); +    generator = G_TOKEN_GENERATOR(pygobject_get(self)); -    flags = g_line_generator_get_flags(generator, index, repeat); +    cursor = g_token_generator_compute_cursor(generator, x, index, repeat); -    result = cast_with_constants_group_from_type(get_python_buffer_line_type(), "BufferLineFlags", flags); +    if (cursor != NULL) +    { +        result = pygobject_new(G_OBJECT(cursor)); +        g_object_unref(G_OBJECT(cursor)); +    } +    else +    { +        result = Py_None; +        Py_INCREF(result); +    }      return result; @@ -663,50 +681,56 @@ static PyObject *py_line_generator_get_flags(PyObject *self, PyObject *args)  *  Paramètres  : self = classe représentant un générateur à manipuler.        *  *                args = arguments fournis à l'appel.                          *  *                                                                             * -*  Description : Imprime dans une ligne de rendu le contenu représenté.       * +*  Description : Détermine si le conteneur s'inscrit dans une plage donnée.   *  *                                                                             * -*  Retour      : -                                                            * +*  Retour      : Bilan de la détermination, utilisable en comparaisons.       *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -static PyObject *py_line_generator_print(PyObject *self, PyObject *args) +static PyObject *py_token_generator_contain_cursor(PyObject *self, PyObject *args)  { -    GBufferLine *line;                      /* Ligne de rendu à compléter  */ +    PyObject *result;                       /* Propriétés à retourner      */      size_t index;                           /* Indice dans le tampon       */      size_t repeat;                          /* Utilisations successives    */ -    GBinContent *content;                   /* Contenu binaire associé     */ -    GLineGenerator *generator;              /* Version native              */ +    GLineCursor *cursor;                    /* Curseur à venir situer      */      int ret;                                /* Bilan de lecture des args.  */ +    GTokenGenerator *generator;              /* Version native              */ +    int status;                             /* Bilan d'une analyse         */ -#define LINE_GENERATOR_PRINT_METHOD PYTHON_METHOD_DEF               \ +#define TOKEN_GENERATOR_CONTAIN_CURSOR_METHOD PYTHON_METHOD_DEF      \  (                                                                   \ -    print, "$self, line, index, repeat, content, /",                \ -    METH_VARARGS, py_line_generator,                                \ -    "Produce output into a rendering line with optional content.\n" \ +    contain_cursor, "$self, index, repeat, cursor, /",              \ +    METH_VARARGS, py_token_generator,                                \ +    "Check the position of a cursor in relation to rendering"       \ +    " lines.\n"                                                     \      "\n"                                                            \ -    "The provided line is a pychrysalide.glibext.BufferLine"        \ -    " instance. The index and the number of repetitions (only"      \ -    " relevant if the generator produces several lines) give"       \ -    " indications about the current rendering position.\n"          \ +    "The line index and the number of repetitions (only relevant"   \ +    " if the generator produces several lines) give indications"    \ +    " about the active position. The cursor is a"                   \ +    " pychrysalide.glibext.LineCursor instance.\n"                  \      "\n"                                                            \ -    "If set, the content is a pychrysalide.analysis.BinContent"     \ -    " instance providing access to the processed binary data."      \ +    "The result has to be an integer less than, equal to, or"       \ +    " greater than zero if the cursor is, respectively, before,"    \ +    " inside or after the area covered by the generator."           \  ) -    ret = PyArg_ParseTuple(args, "O&nnO&", convert_to_buffer_line, &line, &index, -                           &repeat, convert_to_binary_content, &content); +    ret = PyArg_ParseTuple(args, "nnO&", &index, &repeat, convert_to_line_cursor, &cursor);      if (!ret) return NULL; -    generator = G_LINE_GENERATOR(pygobject_get(self)); +    generator = G_TOKEN_GENERATOR(pygobject_get(self)); -    g_line_generator_print(generator, line, index, repeat, content); +    status = g_token_generator_contain_cursor(generator, index, repeat, cursor); -    Py_RETURN_NONE; +    result = PyLong_FromLong(status); + +    return result;  } +#endif +  /******************************************************************************  *                                                                             * @@ -721,24 +745,24 @@ static PyObject *py_line_generator_print(PyObject *self, PyObject *args)  *                                                                             *  ******************************************************************************/ -static PyObject *py_line_generator_get_lines_count(PyObject *self, void *closure) +static PyObject *py_token_generator_get_lines_count(PyObject *self, void *closure)  {      PyObject *result;                       /* Décompte à retourner        */ -    GLineGenerator *generator;              /* Version native              */ +    GTokenGenerator *generator;              /* Version native              */      size_t count;                           /* Nombre de lignes présentes  */ -#define LINE_GENERATOR_LINES_COUNT_ATTRIB PYTHON_GET_DEF_FULL       \ +#define TOKEN_GENERATOR_LINES_COUNT_ATTRIB PYTHON_GET_DEF_FULL      \  (                                                                   \ -    lines_count, py_line_generator,                                 \ +    lines_count, py_token_generator,                                \      "Quantity of lines produced by the generator.\n"                \      "\n"                                                            \      "This number may vary between calls, if a width has changed"    \      " for instance."                                                \  ) -    generator = G_LINE_GENERATOR(pygobject_get(self)); +    generator = G_TOKEN_GENERATOR(pygobject_get(self)); -    count = g_line_generator_count_lines(generator); +    count = g_token_generator_count_lines(generator);      result = PyLong_FromSize_t(count); @@ -759,43 +783,47 @@ static PyObject *py_line_generator_get_lines_count(PyObject *self, void *closure  *                                                                             *  ******************************************************************************/ -PyTypeObject *get_python_line_generator_type(void) +PyTypeObject *get_python_token_generator_type(void)  { -    static PyMethodDef py_line_generator_methods[] = { -        LINE_GENERATOR_COUNT_LINES_WRAPPER, -        LINE_GENERATOR_COMPUTE_CURSOR_WRAPPER, -        LINE_GENERATOR_CONTAIN_CURSOR_WRAPPER, -        LINE_GENERATOR_GET_FLAGS_WRAPPER, -        LINE_GENERATOR_PRINT_WRAPPER, -        LINE_GENERATOR_COMPUTE_CURSOR_METHOD, -        LINE_GENERATOR_CONTAIN_CURSOR_METHOD, -        LINE_GENERATOR_GET_FLAGS_METHOD, -        LINE_GENERATOR_PRINT_METHOD, +    static PyMethodDef py_token_generator_methods[] = { +        TOKEN_GENERATOR_COUNT_LINES_WRAPPER, +        TOKEN_GENERATOR_GET_FLAGS_WRAPPER, +        TOKEN_GENERATOR_POPULATE_LINE_WRAPPER, +        /* +        TOKEN_GENERATOR_COMPUTE_CURSOR_WRAPPER, +        TOKEN_GENERATOR_CONTAIN_CURSOR_WRAPPER, +        */ +        TOKEN_GENERATOR_GET_FLAGS_METHOD, +        TOKEN_GENERATOR_POPULATE_LINE_METHOD, +        /* +        TOKEN_GENERATOR_COMPUTE_CURSOR_METHOD, +        TOKEN_GENERATOR_CONTAIN_CURSOR_METHOD, +        */          { NULL }      }; -    static PyGetSetDef py_line_generator_getseters[] = { -        LINE_GENERATOR_LINES_COUNT_ATTRIB, +    static PyGetSetDef py_token_generator_getseters[] = { +        TOKEN_GENERATOR_LINES_COUNT_ATTRIB,          { NULL }      }; -    static PyTypeObject py_line_generator_type = { +    static PyTypeObject py_token_generator_type = {          PyVarObject_HEAD_INIT(NULL, 0) -        .tp_name        = "pychrysalide.glibext.LineGenerator", +        .tp_name        = "pychrysalide.glibext.TokenGenerator",          .tp_basicsize   = sizeof(PyObject),          .tp_flags       = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, -        .tp_doc         = LINE_GENERATOR_DOC, +        .tp_doc         = TOKEN_GENERATOR_DOC, -        .tp_methods     = py_line_generator_methods, -        .tp_getset      = py_line_generator_getseters, +        .tp_methods     = py_token_generator_methods, +        .tp_getset      = py_token_generator_getseters,      }; -    return &py_line_generator_type; +    return &py_token_generator_type;  } @@ -804,7 +832,7 @@ PyTypeObject *get_python_line_generator_type(void)  *                                                                             *  *  Paramètres  : module = module dont la définition est à compléter.          *  *                                                                             * -*  Description : Prend en charge l'objet 'pychrysalide.glibext.LineGenerator'.* +*  Description : Prend en charge l'objet 'pychrysalide.....TokenGenerator'.   *  *                                                                             *  *  Retour      : Bilan de l'opération.                                        *  *                                                                             * @@ -812,21 +840,21 @@ PyTypeObject *get_python_line_generator_type(void)  *                                                                             *  ******************************************************************************/ -bool ensure_python_line_generator_is_registered(void) +bool ensure_python_token_generator_is_registered(void)  { -    PyTypeObject *type;                     /* Type Python 'LineGenerator' */ +    PyTypeObject *type;                     /* Type Python 'TokenGenerator'*/      PyObject *module;                       /* Module à recompléter        */      PyObject *dict;                         /* Dictionnaire du module      */      static GInterfaceInfo info = {          /* Paramètres d'inscription    */ -        .interface_init = (GInterfaceInitFunc)py_line_generator_interface_init, +        .interface_init = (GInterfaceInitFunc)py_token_generator_interface_init,          .interface_finalize = NULL,          .interface_data = NULL,      }; -    type = get_python_line_generator_type(); +    type = get_python_token_generator_type();      if (!PyType_HasFeature(type, Py_TPFLAGS_READY))      { @@ -834,7 +862,7 @@ bool ensure_python_line_generator_is_registered(void)          dict = PyModule_GetDict(module); -        if (!register_interface_for_pygobject(dict, G_TYPE_LINE_GENERATOR, type, &info)) +        if (!register_interface_for_pygobject(dict, G_TYPE_TOKEN_GENERATOR, type, &info))              return false;      } @@ -857,11 +885,11 @@ bool ensure_python_line_generator_is_registered(void)  *                                                                             *  ******************************************************************************/ -int convert_to_line_generator(PyObject *arg, void *dst) +int convert_to_token_generator(PyObject *arg, void *dst)  {      int result;                             /* Bilan à retourner           */ -    result = PyObject_IsInstance(arg, (PyObject *)get_python_line_generator_type()); +    result = PyObject_IsInstance(arg, (PyObject *)get_python_token_generator_type());      switch (result)      { @@ -871,11 +899,11 @@ int convert_to_line_generator(PyObject *arg, void *dst)              break;          case 0: -            PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to line generator"); +            PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to token generator");              break;          case 1: -            *((GLineGenerator **)dst) = G_LINE_GENERATOR(pygobject_get(arg)); +            *((GTokenGenerator **)dst) = G_TOKEN_GENERATOR(pygobject_get(arg));              break;          default: diff --git a/plugins/pychrysalide/glibext/generator.h b/plugins/pychrysalide/glibext/generator.h index bfad885..b2672a8 100644 --- a/plugins/pychrysalide/glibext/generator.h +++ b/plugins/pychrysalide/glibext/generator.h @@ -1,8 +1,8 @@  /* Chrysalide - Outil d'analyse de fichiers binaires - * linegen.h - prototypes pour l'équivalent Python du fichier "glibext/linegen.h" + * generator.h - prototypes pour l'équivalent Python du fichier "glibext/generator.h"   * - * Copyright (C) 2018 Cyrille Bagard + * Copyright (C) 2018-2025 Cyrille Bagard   *   *  This file is part of Chrysalide.   * @@ -22,8 +22,8 @@   */ -#ifndef _PLUGINS_PYCHRYSALIDE_GLIBEXT_LINEGEN_H -#define _PLUGINS_PYCHRYSALIDE_GLIBEXT_LINEGEN_H +#ifndef _PLUGINS_PYCHRYSALIDE_GLIBEXT_GENERATOR_H +#define _PLUGINS_PYCHRYSALIDE_GLIBEXT_GENERATOR_H  #include <Python.h> @@ -32,14 +32,14 @@  /* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_line_generator_type(void); +PyTypeObject *get_python_token_generator_type(void); -/* Prend en charge l'objet 'pychrysalide.glibext.LineGenerator'. */ -bool ensure_python_line_generator_is_registered(void); +/* Prend en charge l'objet 'pychrysalide.glibext.TokenGenerator'. */ +bool ensure_python_token_generator_is_registered(void);  /* Tente de convertir en générateur de lignes. */ -int convert_to_line_generator(PyObject *, void *); +int convert_to_token_generator(PyObject *, void *); -#endif  /* _PLUGINS_PYCHRYSALIDE_GLIBEXT_LINEGEN_H */ +#endif  /* _PLUGINS_PYCHRYSALIDE_GLIBEXT_GENERATOR_H */ diff --git a/plugins/pychrysalide/glibext/module-ui.c b/plugins/pychrysalide/glibext/module-ui.c new file mode 100644 index 0000000..8fa6d0e --- /dev/null +++ b/plugins/pychrysalide/glibext/module-ui.c @@ -0,0 +1,62 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire glibext (forme graphique) en tant que module + * + * Copyright (C) 2025 Cyrille Bagard + * + *  This file is part of Chrysalide. + * + *  Chrysalide is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 3 of the License, or + *  (at your option) any later version. + * + *  Chrysalide is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with this program; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + */ + + +#include "module-ui.h" + + +#include <assert.h> + + +#include "bufferline.h" +#include "generator.h" + + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : -                                                            * +*                                                                             * +*  Description : Intègre les objets du module 'glibext' (mode UI).            * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool populate_glibext_module_ui(void) +{ +    bool result;                            /* Bilan à retourner           */ + +    result = true; + +    if (result) result = ensure_python_token_generator_is_registered(); + +    if (result) result = ensure_python_buffer_line_is_registered(); + +    assert(result); + +    return result; + +} diff --git a/plugins/pychrysalide/glibext/module-ui.h b/plugins/pychrysalide/glibext/module-ui.h new file mode 100644 index 0000000..d91a2fa --- /dev/null +++ b/plugins/pychrysalide/glibext/module-ui.h @@ -0,0 +1,38 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire glibext (forme graphique) en tant que module + * + * Copyright (C) 2025 Cyrille Bagard + * + *  This file is part of Chrysalide. + * + *  Chrysalide is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 3 of the License, or + *  (at your option) any later version. + * + *  Chrysalide is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with this program; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_GLIBEXT_MODULE_UI_H +#define _PLUGINS_PYCHRYSALIDE_GLIBEXT_MODULE_UI_H + + +#include <Python.h> +#include <stdbool.h> + + +/* Intègre les objets du module 'glibext' (mode UI). */ +bool populate_glibext_module_ui(void); + + + +#endif  /* _PLUGINS_PYCHRYSALIDE_GLIBEXT_MODULE_UI_H */ | 
