diff options
Diffstat (limited to 'src/glibext')
| -rw-r--r-- | src/glibext/Makefile.am | 2 | ||||
| -rw-r--r-- | src/glibext/comparison-int.h | 55 | ||||
| -rw-r--r-- | src/glibext/comparison.c | 143 | ||||
| -rw-r--r-- | src/glibext/comparison.h | 69 | 
4 files changed, 269 insertions, 0 deletions
| diff --git a/src/glibext/Makefile.am b/src/glibext/Makefile.am index 67fe0d8..ad98809 100644 --- a/src/glibext/Makefile.am +++ b/src/glibext/Makefile.am @@ -8,6 +8,8 @@ libglibext_la_SOURCES =						\  	buffercache.h buffercache.c				\  	bufferline.h bufferline.c				\  	chrysamarshal.h chrysamarshal.c			\ +	comparison-int.h						\ +	comparison.h comparison.c				\  	configuration-int.h						\  	configuration.h configuration.c			\  	delayed-int.h							\ diff --git a/src/glibext/comparison-int.h b/src/glibext/comparison-int.h new file mode 100644 index 0000000..efb289a --- /dev/null +++ b/src/glibext/comparison-int.h @@ -0,0 +1,55 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * comparison-int.h - définitions internes propres aux opérations de comparaison d'objets + * + * Copyright (C) 2022 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 Chrysalide.  If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _GLIBEXT_COMPARISON_INT_H +#define _GLIBEXT_COMPARISON_INT_H + + +#include "comparison.h" + + + +/* Réalise une comparaison entre objets selon un critère précis. */ +typedef bool (* compare_rich_fc) (const GComparableItem *, const GComparableItem *, RichCmpOperation, bool *); + + +/* Instance d'élément comparable (interface) */ +struct _GComparableItemIface +{ +    GTypeInterface base_iface;              /* A laisser en premier        */ + +    compare_rich_fc cmp_rich;               /* Comparaison de façon précise*/ + +}; + + +/* Redéfinition */ +typedef GComparableItemIface GComparableItemInterface; + + +/* Réalise une comparaison riche entre valeurs entière. */ +bool compare_rich_integer_values(unsigned long long, unsigned long long, RichCmpOperation); + + + +#endif  /* _GLIBEXT_COMPARISON_INT_H */ diff --git a/src/glibext/comparison.c b/src/glibext/comparison.c new file mode 100644 index 0000000..463f354 --- /dev/null +++ b/src/glibext/comparison.c @@ -0,0 +1,143 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * comparison.c - opérations de comparaison d'objets + * + * Copyright (C) 2022 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 Foobar.  If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "comparison.h" + + +#include <assert.h> + + +#include "comparison-int.h" + + + +/* Procède à l'initialisation de l'interface de comparaison. */ +static void g_comparable_item_default_init(GComparableItemInterface *); + + + +/* Détermine le type d'une interface pour un objet comparable. */ +G_DEFINE_INTERFACE(GComparableItem, g_comparable_item, G_TYPE_OBJECT) + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : iface = interface GLib à initialiser.                        * +*                                                                             * +*  Description : Procède à l'initialisation de l'interface de comparaison.    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_comparable_item_default_init(GComparableItemInterface *iface) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : item   = premier objet à consulter pour une comparaison.     * +*                other  = second objet à consulter pour une comparaison.      * +*                op     = opération de comparaison à réaliser.                * +*                status = bilan des opérations de comparaison. [OUT]          * +*                                                                             * +*  Description : Réalise une comparaison entre objets selon un critère précis.* +*                                                                             * +*  Retour      : true si la comparaison a pu être effectuée, false sinon.     * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool g_comparable_item_compare_rich(const GComparableItem *item, const GComparableItem *other, RichCmpOperation op, bool *status) +{ +    bool result;                            /* Etat à retourner            */ +    GComparableItemIface *iface;            /* Interface utilisée          */ + +    iface = G_COMPARABLE_ITEM_GET_IFACE(item); + +    result = iface->cmp_rich(item, other, op, status); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : a  = premier élément à consulter pour une comparaison.       * +*                b  = second objet à consulter pour une comparaison.          * +*                op = opération de comparaison à réaliser.                    * +*                                                                             * +*  Description : Réalise une comparaison riche entre valeurs entière.         * +*                                                                             * +*  Retour      : Bilan des opérations de comparaison.                         * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool compare_rich_integer_values(unsigned long long a, unsigned long long b, RichCmpOperation op) +{ +    bool result;                            /* Bilan  à retourner          */ + +    switch (op) +    { +        case RCO_LT: +            result = (a < b); +            break; + +        case RCO_LE: +            result = (a <= b); +            break; + +        case RCO_EQ: +            result = (a == b); +            break; + +        case RCO_NE: +            result = (a != b); +            break; + +        case RCO_GT: +            result = (a > b); +            break; + +        case RCO_GE: +            result = (a >= b); +            break; + +        default: +            assert(false); +            result = false; +            break; + +    } + +    return result; + +} diff --git a/src/glibext/comparison.h b/src/glibext/comparison.h new file mode 100644 index 0000000..26e501c --- /dev/null +++ b/src/glibext/comparison.h @@ -0,0 +1,69 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * comparison.h - prototypes pour les opérations de comparaison d'objets + * + * Copyright (C) 2022 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 Foobar.  If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _GLIBEXT_COMPARISON_H +#define _GLIBEXT_COMPARISON_H + + +#include <glib-object.h> +#include <stdbool.h> + + + +#define G_TYPE_COMPARABLE_ITEM             (g_comparable_item_get_type()) +#define G_COMPARABLE_ITEM(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_COMPARABLE_ITEM, GComparableItem)) +#define G_COMPARABLE_ITEM_CLASS(vtable)    (G_TYPE_CHECK_CLASS_CAST((vtable), G_TYPE_COMPARABLE_ITEM, GComparableItemIface)) +#define G_IS_COMPARABLE_ITEM(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_COMPARABLE_ITEM)) +#define G_IS_COMPARABLE_ITEM_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE((vtable), G_TYPE_COMPARABLE_ITEM)) +#define G_COMPARABLE_ITEM_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE((inst), G_TYPE_COMPARABLE_ITEM, GComparableItemIface)) + + +/* Instance d'élément comparable (coquille vide) */ +typedef struct _GComparableItem GComparableItem; + +/* Instance d'élément comparable (interface) */ +typedef struct _GComparableItemIface GComparableItemIface; + + +/* Modes de comparaison */ +typedef enum _RichCmpOperation +{ +    RCO_LT,                                 /* Equivalent de '<'           */ +    RCO_LE,                                 /* Equivalent de '<='          */ +    RCO_EQ,                                 /* Equivalent de '=='          */ +    RCO_NE,                                 /* Equivalent de '!='          */ +    RCO_GT,                                 /* Equivalent de '>'           */ +    RCO_GE,                                 /* Equivalent de '>°'          */ + +} RichCmpOperation; + + +/* Détermine le type d'une interface pour un objet comparable. */ +GType g_comparable_item_get_type(void) G_GNUC_CONST; + +/* Réalise une comparaison entre objets selon un critère précis. */ +bool g_comparable_item_compare_rich(const GComparableItem *, const GComparableItem *, RichCmpOperation, bool *); + + + +#endif  /* _GLIBEXT_COMPARISON_H */ | 
