diff options
| -rw-r--r-- | ChangeLog | 25 | ||||
| -rw-r--r-- | src/analysis/line.c | 148 | ||||
| -rw-r--r-- | src/analysis/line.h | 23 | ||||
| -rwxr-xr-x | src/common/Makefile.am | 3 | ||||
| -rw-r--r-- | src/common/dllist.c | 87 | ||||
| -rw-r--r-- | src/common/dllist.h | 182 | ||||
| -rw-r--r-- | src/editor.c | 1 | ||||
| -rw-r--r-- | src/gtksnippet.c | 70 | ||||
| -rw-r--r-- | src/gtksnippet.h | 5 | 
9 files changed, 260 insertions, 284 deletions
| @@ -1,3 +1,28 @@ +009-04-05  Cyrille Bagard <nocbos@gmail.com> + +	* src/analysis/line.c: +	* src/analysis/line.h: +	Use the new double linked lists macros. Create more clever functions +	for the GtkSnippet widget. + +	* src/common/dllist.c: +	* src/common/dllist.h: +	Manage double linked lists in a more powerful way. + +	* src/common/macros.h: +	New entry: properly define container_of(). + +	* src/common/Makefile.am: +	Add macros.h to libcommon_a_SOURCES. + +	* src/editor.c: +	Remove a call to gtk_snippet_set_sel(). + +	* src/gtksnippet.c: +	* src/gtksnippet.h: +	Clean the code ; delete gtk_snippet_set_sel() and fix some GCC warnings. +	Use the new functions provided by src/analysis/line.[ch]. +  2009-03-15  Cyrille Bagard <nocbos@gmail.com>  	* src/analysis/line.c: diff --git a/src/analysis/line.c b/src/analysis/line.c index 62acb8e..21f0fd5 100644 --- a/src/analysis/line.c +++ b/src/analysis/line.c @@ -53,7 +53,7 @@ typedef void (* refresh_markup_fc) (rendering_line *);  /* Ligne de représentation générique */  struct _rendering_line  { -    DL_LIST_ITEM; +    DL_LIST_ITEM(link);                     /* Maillon de liste chaînée    */      uint64_t offset;                        /* Position en mémoire/physique*/ @@ -73,6 +73,12 @@ struct _rendering_line  #define RENDERING_LINE(l) ((rendering_line *)l) +#define lines_list_next_iter(iter, head) dl_list_next_iter(iter, head, rendering_line, link) +#define lines_list_add_tail(new, head) dl_list_add_tail(new, head, rendering_line, link) +#define lines_list_splice_before(pos, head1, head2) dl_list_splice_before(pos, head1, head2, rendering_line, link) +#define lines_list_for_each(pos, head) dl_list_for_each(pos, head, rendering_line, link) + +  /* Procède à l'initialisation des bases d'une représentation. */  void init_rendering_line(rendering_line *); @@ -158,7 +164,7 @@ void refresh_code_markup(code_line *);  void init_rendering_line(rendering_line *line)  { -    DL_LIST_ITEM_INIT(DLL_CAST(line)); +    DL_LIST_ITEM_INIT(&line->link);      line->layout = gtk_widget_create_pango_layout(mywid, NULL); @@ -246,7 +252,7 @@ RenderingLineFlag get_rendering_line_flags(const rendering_line *line)  void add_line_to_rendering_lines(rendering_line **lines, rendering_line *line)  { -    dl_list_add_tail(DLL_CAST(line), (dl_list_item **)lines); +    lines_list_add_tail(line, lines);  } @@ -268,9 +274,8 @@ void add_line_to_rendering_lines(rendering_line **lines, rendering_line *line)  void insert_line_into_rendering_lines(rendering_line **lines, rendering_line *line, bool first)  {      rendering_line *iter;                   /* Boucle de parcours          */ -    rendering_line *next;                   /* Prochaine ligne parcourue   */ -    dl_list_for_each_safe(iter, DLL_HCAST(lines), next, rendering_line *) +    lines_list_for_each(iter, *lines)      {          if (first && iter->offset >= line->offset) break;          else if (!first) @@ -281,12 +286,12 @@ void insert_line_into_rendering_lines(rendering_line **lines, rendering_line *li      }      if (iter == NULL) -        dl_list_add_tail(line, DLL_HCAST(lines)); +        lines_list_add_tail(line, lines);      else      {          if (first) -            dl_list_insert_before(line, iter, DLL_HCAST(lines)); +            lines_list_splice_before(iter, lines, line);          else              /* TODO */;      } @@ -307,11 +312,11 @@ void insert_line_into_rendering_lines(rendering_line **lines, rendering_line *li  *                                                                             *  ******************************************************************************/ -rendering_line *find_offset_in_rendering_lines(const rendering_line **lines, uint64_t offset) +rendering_line *find_offset_in_rendering_lines(rendering_line *lines, uint64_t offset)  {      rendering_line *result; -    dl_list_for_each(result, DLL_HCAST(lines), rendering_line *) +    lines_list_for_each(result, lines)          if (result->offset == offset) break;      return result; @@ -319,13 +324,17 @@ rendering_line *find_offset_in_rendering_lines(const rendering_line **lines, uin  } -  /******************************************************************************  *                                                                             * -*  Paramètres  : line = ligne de représentation à actualiser.                 * -*                blen = longueur maximale à mettre à jour. [OUT]              * +*  Paramètres  : line     = adresse de la structure à représenter.            * +*                drawable = support de rendu pour le dessin.                  * +*                gc       = contexte graphique à utiliser.                    * +*                x0       = abscisse de la zone de rendu (marge).             * +*                x1       = abscisse de la zone de rendu (texte).             * +*                y        = ordonnée de la zone de rendu.                     * +*                h        = hauteur réservée pour la ligne.                   *  *                                                                             * -*  Description : Met à jour le nombre d'octets maximal par instruction.       * +*  Description : Procède à l'initialisation des bases d'une représentation.   *  *                                                                             *  *  Retour      : -                                                            *  *                                                                             * @@ -333,43 +342,67 @@ rendering_line *find_offset_in_rendering_lines(const rendering_line **lines, uin  *                                                                             *  ******************************************************************************/ -void get_rendering_line_binary_len(rendering_line *line, off_t *blen) +void draw_rendering_line(rendering_line *line, GdkDrawable *drawable, GdkGC *gc, gint x0, gint x1, gint y, gint h)  { -    if (line->get_bin_len != NULL) -        line->get_bin_len(line, blen); +    GdkPixbuf *pixbuf;                      /* Données utiles au dessin    */ + +    gdk_draw_layout(drawable, gc, x1, y, line->layout); + +    if (line->flags & RLF_ENTRY_POINT) +        pixbuf = gtk_widget_render_icon(mywid, "gtk-go-forward", GTK_ICON_SIZE_MENU, NULL); + +    else pixbuf = NULL; + +    if (pixbuf != NULL) +    { +        gdk_draw_pixbuf(drawable, gc, pixbuf, 0, 0, x0, y, +                        gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), +                        GDK_RGB_DITHER_NORMAL, 0, 0); + +        g_object_unref(pixbuf); + +    }  } + +/* ---------------------------------------------------------------------------------- */ +/*                          TRAITEMENT DES LIGNES PAR GROUPE                          */ +/* ---------------------------------------------------------------------------------- */ + +  /******************************************************************************  *                                                                             * -*  Paramètres  : line = ligne de représentation à actualiser.                 * -*                blen = longueur maximale à prendre en compte.                * +*  Paramètres  : line = liste de lignes de représentation à actualiser.       * +*              : iter = position actuelle dans la liste.                      *  *                                                                             * -*  Description : Prend en compte le nombre d'octets maximal par instruction.  * +*  Description : Fournit l'élement suivant un autre pour un parcours.         *  *                                                                             * -*  Retour      : -                                                            * +*  Retour      : Elément suivant ou NULL si aucun.                            *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -void set_rendering_line_max_binary_len(rendering_line *line, off_t blen) +rendering_line *g_rendering_line_get_next_iter(rendering_line *lines, const rendering_line *iter)  { -    line->max_bin_len = blen * 2 + (blen - 1); +    rendering_line *result;                 /* Elément suivant à renvoyer  */ + +    if (iter == NULL) iter = lines; -    line->refresh_markup(line); +    result = lines_list_next_iter(iter, lines); + +    return result;  }  /******************************************************************************  *                                                                             * -*  Paramètres  : line   = adresse de la structure à représenter.              * -*                width  = largeur maximale des lignes à compléter.            * -*                height = hauteur maximale des lignes à compléter.            * +*  Paramètres  : line = liste de lignes de représentation à actualiser.       *  *                                                                             * -*  Description : Fournit les dimensions d'une ligne par rapport à d'autres.   * +*  Description : Met à jour le nombre d'octets maximal par instruction.       *  *                                                                             *  *  Retour      : -                                                            *  *                                                                             * @@ -377,30 +410,34 @@ void set_rendering_line_max_binary_len(rendering_line *line, off_t blen)  *                                                                             *  ******************************************************************************/ -void get_rendering_line_size(rendering_line *line, int *width, int *height) +void g_rendering_lines_update_bin_len(rendering_line *lines)  { -    int w;                                  /* Largeur de l'objet actuelle */ -    int h;                                  /* Hauteur de l'objet actuelle */ +    rendering_line *iter;                   /* Boucle de parcours          */ +    off_t bin_len;                          /* Taille d'instruction        */ -    pango_layout_get_pixel_size(line->layout, &w, &h); +    bin_len = 0; -    *width = MAX(*width, w); -    *height += h; +    lines_list_for_each(iter, lines) +        if (iter->get_bin_len != NULL) +            iter->get_bin_len(iter, &bin_len); + +    lines_list_for_each(iter, lines) +    { +        iter->max_bin_len = bin_len * 2 + (bin_len - 1); +        iter->refresh_markup(iter); +    }  }  /******************************************************************************  *                                                                             * -*  Paramètres  : line     = adresse de la structure à représenter.            * -*                drawable = support de rendu pour le dessin.                  * -*                gc       = contexte graphique à utiliser.                    * -*                x0       = abscisse de la zone de rendu (marge).             * -*                x1       = abscisse de la zone de rendu (texte).             * -*                y        = ordonnée de la zone de rendu.                     * -*                h        = hauteur réservée pour la ligne.                   * +*  Paramètres  : lines  = liste de lignes de représentation à actualiser.     * +*                width  = largeur maximale des lignes. [OUT]                  * +*                height = hauteur maximale des lignes. [OUT]                  * +*                alone  = hauteur d'une seule ligne. [OUT]                    *  *                                                                             * -*  Description : Procède à l'initialisation des bases d'une représentation.   * +*  Description : Fournit les dimensions de lignes de représentation.          *  *                                                                             *  *  Retour      : -                                                            *  *                                                                             * @@ -408,24 +445,25 @@ void get_rendering_line_size(rendering_line *line, int *width, int *height)  *                                                                             *  ******************************************************************************/ -void draw_rendering_line(rendering_line *line, GdkDrawable *drawable, GdkGC *gc, gint x0, gint x1, gint y, gint h) +void g_rendering_lines_get_size(rendering_line *lines, int *width, int *height, int *alone)  { -    GdkPixbuf *pixbuf;                      /* Données utiles au dessin    */ - -    gdk_draw_layout(drawable, gc, x1, y, line->layout); - -    if (line->flags & RLF_ENTRY_POINT) -        pixbuf = gtk_widget_render_icon(mywid, "gtk-go-forward", GTK_ICON_SIZE_MENU, NULL); +    rendering_line *iter;                   /* Boucle de parcours          */ +    int w;                                  /* Largeur de l'objet actuelle */ +    int h;                                  /* Hauteur de l'objet actuelle */ -    else pixbuf = NULL; +    *width = 0; +    *height = 0; +    *alone = 0; -    if (pixbuf != NULL) +    lines_list_for_each(iter, lines)      { -        gdk_draw_pixbuf(drawable, gc, pixbuf, 0, 0, x0, y, -                        gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), -                        GDK_RGB_DITHER_NORMAL, 0, 0); +        pango_layout_get_pixel_size(iter->layout, &w, &h); -        g_object_unref(pixbuf); +        *width = MAX(*width, w); +        *height += h; + +        if (iter == lines) +            *alone = h;      } @@ -528,7 +566,7 @@ rendering_line *create_comment_line(uint64_t offset, RenderingLineType type, con  {      comment_line *result;                   /* Structure à retourner       */ -    result = (prologue_line *)calloc(1, sizeof(prologue_line)); +    result = (comment_line *)calloc(1, sizeof(comment_line));      init_rendering_line(RENDERING_LINE(result)); diff --git a/src/analysis/line.h b/src/analysis/line.h index bb628b6..abb2757 100644 --- a/src/analysis/line.h +++ b/src/analysis/line.h @@ -88,21 +88,26 @@ void add_line_to_rendering_lines(rendering_line **, rendering_line *);  void insert_line_into_rendering_lines(rendering_line **, rendering_line *, bool);  /* Recherche une ligne d'après sa position en mémoire/physique. */ -rendering_line *find_offset_in_rendering_lines(const rendering_line **, uint64_t); +rendering_line *find_offset_in_rendering_lines(rendering_line *, uint64_t); -/* Met à jour la nombre d'octets maximale par instruction. */ -void get_rendering_line_binary_len(rendering_line *, off_t *); +/* Procède à l'initialisation des bases d'une représentation. */ +void draw_rendering_line(rendering_line *, GdkDrawable *, GdkGC *, gint, gint, gint, gint); -/* Prend en compte le nombre d'octets maximal par instruction. */ -void set_rendering_line_max_binary_len(rendering_line *, off_t); -/* Fournit les dimensions d'une ligne par rapport à d'autres. */ -void get_rendering_line_size(rendering_line *, int *, int *); -/* Procède à l'initialisation des bases d'une représentation. */ -void draw_rendering_line(rendering_line *, GdkDrawable *, GdkGC *, gint, gint, gint, gint); +/* ------------------------ TRAITEMENT DES LIGNES PAR GROUPE ------------------------ */ + + +/* Fournit l'élement suivant un autre pour un parcours. */ +rendering_line *g_rendering_line_get_next_iter(rendering_line *, const rendering_line *); + +/* Met à jour le nombre d'octets maximal par instruction. */ +void g_rendering_lines_update_bin_len(rendering_line *); + +/* Fournit les dimensions de lignes de représentation. */ +void g_rendering_lines_get_size(rendering_line *, int *, int *, int *); diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 5b21da3..f23941b 100755 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -4,7 +4,8 @@ lib_LIBRARIES = libcommon.a  libcommon_a_SOURCES =					\  	dllist.h dllist.c					\  	endianness.h endianness.c			\ -	extstr.h extstr.c +	extstr.h extstr.c					\ +	macros.h  libcommon_a_CFLAGS = $(AM_CFLAGS) diff --git a/src/common/dllist.c b/src/common/dllist.c index 7e56bf4..5de3cd9 100644 --- a/src/common/dllist.c +++ b/src/common/dllist.c @@ -24,9 +24,6 @@  #include "dllist.h" -#include <stdbool.h> - -  /******************************************************************************  *                                                                             * @@ -59,8 +56,8 @@ void __dl_list_add(dl_list_item *new, dl_list_head *head, dl_list_item *prev, dl  /******************************************************************************  *                                                                             * -*  Paramètres  : prev = élément précédent dans la liste.                      * -*                next = élément suivant dans la liste.                        * +*  Paramètres  : item = élément à supprimer.                                  * +*                head = adresse d'enregistrement de la tête de la liste.      *  *                                                                             *  *  Description : Supprime un élément d'une liste doublement chaînée.          *  *                                                                             * @@ -70,85 +67,39 @@ void __dl_list_add(dl_list_item *new, dl_list_head *head, dl_list_item *prev, dl  *                                                                             *  ******************************************************************************/ -void __dl_list_del(dl_list_item *prev, dl_list_item *next) +void __dl_list_del(dl_list_item *item, dl_list_head *head)  { -    next->prev = prev; -    prev->next = next; +    item->next->prev = item->prev; +    item->prev->next = item->next; -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : head = début de la liste, à mettre éventuellement à jour.    * -*                a    = premier élément à traiter.                            * -*                b    = second élément à traiter.                             * -*                                                                             * -*  Description : Intervertit deux éléments dans une liste doublement chaînée. * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void swap_dl_list_items(dl_list_head *head, dl_list_item *a, dl_list_item *b) -{ -    bool a_is_head;                         /* Indique si a est le début   */ -    bool b_is_head;                         /* Indique si b est le début   */ -    dl_list_item tmp;                       /* Stockage temporaire         */ - -    a_is_head = (*head == a); -    b_is_head = (*head == b); - -    /* Liens vers l'extérieur et l'intérieur */ - -    if (a->prev != b) a->prev->next = b; -    if (a->next != b) a->next->prev = b; - -    if (b->prev != a) b->prev->next = a; -    if (b->next != a) b->next->prev = a; - -    /* Liens propres aux éléments */ - -    tmp = *a; - -    a->prev = (b->prev == a ? b : b->prev); -    a->next = (b->next == a ? b : b->next); - -    b->prev = (tmp.prev == b ? a : tmp.prev); -    b->next = (tmp.next == b ? a : tmp.next); - -    /* Mise à jour éventuelle de la tête */ - -    if (a_is_head) *head = b; -    else if (b_is_head) *head = a; +    if (*head == item) +    { +        *head = item->next; +        if (*head == item) *head = NULL; +    }  }  /******************************************************************************  *                                                                             * -*  Paramètres  : list = liste à parcourir.                                    * +*  Paramètres  : item = point d'insertion.                                    * +*                head = seconde liste à intégrer.                             *  *                                                                             * -*  Description : Compte le nombre d'éléments présents dans une liste.         * +*  Description : Insère une liste au sein d'une autre.                        *  *                                                                             * -*  Retour      : Nombre d'éléments comptabilisés.                             * +*  Retour      : -                                                            *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -unsigned int count_dl_list_items(dl_list_head list) +void __dl_list_splice(dl_list_item *pos, dl_list_head head)  { -    unsigned int result;                    /* Résultat à renvoyer         */ -    dl_list_item *iter;                     /* Boucle de parcours          */ - -    result = 0; - -    dl_list_for_each(iter, list, dl_list_item *) -        result++; +    pos->next->prev = head; +    head->prev->next = pos->next; -    return result; +    pos->next = head; +    head->prev = pos;  } diff --git a/src/common/dllist.h b/src/common/dllist.h index 670d3b9..1bd1ead 100644 --- a/src/common/dllist.h +++ b/src/common/dllist.h @@ -21,11 +21,11 @@   */ -#ifndef _DLLIST_H -#define _DLLIST_H +#ifndef _COMMON_DLLIST_H +#define _COMMON_DLLIST_H -#define NULL ((void *)0) +#include "macros.h" @@ -37,106 +37,110 @@ typedef struct _dl_list_item  } dl_list_item; -  typedef dl_list_item *dl_list_head; -#define DL_LIST_ITEM dl_list_item dummy - -#define DLL_CAST(item) ((dl_list_item *)item) -#define DLL_HCAST(item) ((dl_list_item **)item) +#define DL_LIST_ITEM(name) dl_list_item name -#define DL_LIST_HEAD_INIT(head)                                         \ -    *(head) = NULL -#define DL_LIST_ITEM_INIT(item)                                         \ -    do                                                                  \ -    {                                                                   \ -        DLL_CAST(item)->prev = NULL;                                    \ -        DLL_CAST(item)->next = NULL;                                    \ -                                                                        \ +#define DL_LIST_ITEM_INIT(item)                                                     \ +    do                                                                              \ +    {                                                                               \ +        (item)->prev = (item);                                                      \ +        (item)->next = (item);                                                      \ +                                                                                    \      } while(0) -#define DL_LIST_NEXT(item, type) (type)DLL_CAST(item)->next -#define DL_LIST_PREV(item, type) (type)DLL_CAST(item)->prev -#define DL_LIST_IS_ALONE(head) (DLL_CAST(head)->next == DLL_CAST(head)) - -   /* Ajoute un élément dans une liste doublement chaînée. */  void __dl_list_add(dl_list_item *, dl_list_head *, dl_list_item *, dl_list_item *);  /* Supprime un élément d'une liste doublement chaînée. */ -void __dl_list_del(dl_list_item *, dl_list_item *); - -/* Intervertit deux éléments dans une liste doublement chaînée. */ -void swap_dl_list_items(dl_list_head *, dl_list_item *, dl_list_item *); +void __dl_list_del(dl_list_item *, dl_list_head *); -/* Compte le nombre d'éléments présents dans une liste. */ -unsigned int count_dl_list_items(dl_list_head); +/* Insère une liste au sein d'une autre. */ +void __dl_list_splice(dl_list_item *, dl_list_head); -#define dl_list_empty(head)                                             \ +#define dl_list_empty(head)                                                         \      ((head) == NULL) -#define dl_list_last(head, type)                                        \ -    (dl_list_empty(head) ? NULL : (type)((head)->prev == NULL ? (head) : (head)->prev)) - -#define dl_list_add(new, head)                                          \ -    __dl_list_add(DLL_CAST(new), (head), (dl_list_empty(*(head)) ? DLL_CAST(new) : dl_list_last(*head, dl_list_item *)), (dl_list_empty(*(head)) ? DLL_CAST(new) : *(head))) - -#define dl_list_add_tail(new, head)                                     \ -    __dl_list_add(DLL_CAST(new), (head), (dl_list_empty(*(head)) ? DLL_CAST(new) : (*(head))->prev), (dl_list_empty(*(head)) ? DLL_CAST(new) : *(head))) - -#define dl_list_insert_before(new, target, head)                        \ -    do                                                                  \ -    {                                                                   \ -        DLL_CAST(new)->prev = DLL_CAST(target)->prev;                   \ -        DLL_CAST(target)->prev->next = DLL_CAST(new);                   \ -        DLL_CAST(new)->next = DLL_CAST(target);                         \ -        DLL_CAST(target)->prev = DLL_CAST(new);                         \ -        if (DLL_CAST(target) == *head) *head = DLL_CAST(target);        \ -                                                                        \ -    } while (0) - -#define dl_list_del(item, head)                                         \ -    do                                                                  \ -    {                                                                   \ -        __dl_list_del(DLL_CAST(item)->prev, DLL_CAST(item)->next);      \ -        if (*head == DLL_CAST(item)) *head = DLL_CAST(item)->next;      \ -        if (*head == DLL_CAST(item)) *head = NULL;                      \ -        DLL_CAST(item)->next = NULL;                                    \ -        DLL_CAST(item)->prev = NULL;                                    \ -                                                                        \ -    } while(0) - -#define dl_list_move_tail(item, head)                                   \ -    do                                                                  \ -    {                                                                   \ -        dl_list_del(item, head);                                        \ -        dl_list_add_tail(item, head);                                   \ -                                                                        \ -    } while(0) - -#define dl_list_for_each(pos, head, type)                               \ -	for (pos = (type)(head);                                            \ -         pos != NULL;                                                   \ -         pos = (type)(DLL_CAST(pos)->next == (head) ? NULL : DLL_CAST(pos)->next)) - -#define dl_list_for_each_safe(pos, head, tmp, type)                     \ -	for (pos = (type)*(head),                                           \ -             tmp = (type)(pos != NULL && DLL_CAST(pos)->next != *(head) ?\ -                 DLL_CAST(pos)->next : NULL);                           \ -         pos != NULL;                                                   \ -         pos = tmp,                                                     \ -             tmp = (type)(pos != NULL && DLL_CAST(pos)->next != *(head) ?\ -                 DLL_CAST(pos)->next : NULL)) - -#define dl_list_for_each_prev(pos, head, type)                          \ -	for (pos = dl_list_last(head, type);                                \ -         pos != NULL;                                                   \ -         pos = (type)(DLL_CAST(pos) == (head) ? NULL : DLL_CAST(pos)->prev)) - - - -#endif  /* _DLLIST_H */ +#define dl_list_last(head, type, member)                                            \ +    (dl_list_empty(head) ? NULL : (type *)container_of(head->member.prev, type, member)) + +#define dl_list_add(new, head, type, member)                                        \ +    do                                                                              \ +    {                                                                               \ +        dl_list_item *hmbr = (dl_list_empty(*(head)) ? NULL : &(*head)->member);    \ +        __dl_list_add(&new->member, &hmbr,                                          \ +                      dl_list_empty(*(head)) ? &new->member : hmbr->prev,           \ +                      dl_list_empty(*(head)) ? &new->member : hmbr);                \ +        *(head) = new;                                                              \ +    }                                                                               \ +    while (0) + +#define dl_list_add_tail(new, head, type, member)                                   \ +    do                                                                              \ +    {                                                                               \ +        dl_list_item *hmbr = (dl_list_empty(*(head)) ? NULL : &(*head)->member);    \ +        __dl_list_add(&new->member, &hmbr,                                          \ +                      dl_list_empty(*(head)) ? &new->member : hmbr->prev,           \ +                      dl_list_empty(*(head)) ? &new->member : hmbr);                \ +        *(head) = container_of(hmbr, type, member);                                 \ +    }                                                                               \ +    while (0) + +#define dl_list_del(item, head, type, member)                                       \ +    do                                                                              \ +    {                                                                               \ +        dl_list_item *hmbr = &(*head)->member;                                      \ +        __dl_list_del(&item->member, &hmbr);                                        \ +        *(head) = container_of(hmbr, type, member);                                 \ +        DL_LIST_ITEM_INIT(&item->member);                                           \ +    }                                                                               \ +    while(0) + +#define dl_list_splice_before(pos, head1, head2, type, member)                      \ +    do                                                                              \ +    {                                                                               \ +        if (pos == *head1)                                                          \ +        {                                                                           \ +            __dl_list_splice(head2->member.prev, &(*head1)->member);                \ +            *head1 = head2;                                                         \ +        }                                                                           \ +        else __dl_list_splice(pos->member.prev, &head2->member);                    \ +    }                                                                               \ +    while(0) + +#define dl_list_splice_after(pos, head2, type, member)                              \ +        __dl_list_splice(&pos->member, &head2->member); + +#define dl_list_next_iter(iter, head, type, member)                                 \ +    (iter->member.next == &head->member ?                                           \ +     NULL : container_of(iter->member.next, type, member)) + +#define dl_list_for_each(pos, head, type, member)                                   \ +	for (pos = head;                                                                \ +         pos != NULL;                                                               \ +         pos = dl_list_next_iter(pos, (head), type, member)) + +#define dl_list_next_iter_safe(iter, head, type, member)                            \ +    (iter == NULL || iter->member.next == &(*head)->member ?                        \ +     NULL : container_of(iter->member.next, type, member)) + +#define dl_list_for_each_safe(pos, head, next, type, member)                        \ +	for (pos = *head,                                                               \ +             next = dl_list_next_iter_safe(pos, (head), type, member);              \ +         pos != NULL;                                                               \ +         pos = next,                                                                \ +             next = dl_list_next_iter_safe(pos, (head), type, member)) + +#define dl_list_for_each_rev(pos, head, type, member)                               \ +	for (pos = dl_list_last(head, type, member);                                    \ +         pos != NULL;                                                               \ +         pos = (pos == head ?                                                       \ +                NULL : container_of(pos->member.prev, type, member))) + + + +#endif  /* _COMMON_DLLIST_H */ diff --git a/src/editor.c b/src/editor.c index c1041c6..e8ff222 100644 --- a/src/editor.c +++ b/src/editor.c @@ -625,7 +625,6 @@ GtkWidget *create_editor(void)    snippet = gtk_snippet_new();    gtk_widget_show(binview); -  gtk_snippet_set_sel(GTK_SNIPPET(snippet), 44);    /*    snippet = gtk_text_view_new ();    */ diff --git a/src/gtksnippet.c b/src/gtksnippet.c index bd5b3df..f56ccd0 100644 --- a/src/gtksnippet.c +++ b/src/gtksnippet.c @@ -143,7 +143,7 @@ static void gtk_snippet_size_allocate(GtkWidget *widget,  static void gtk_snippet_realize(GtkWidget *widget); -static gboolean gtk_snippet_button_press(GtkSnippet *snippet, GdkEventButton *event, gpointer *data); +static gboolean gtk_snippet_button_press(GtkWidget *widget, GdkEventButton *event);  static gboolean gtk_snippet_expose(GtkWidget *widget,      GdkEventExpose *event); @@ -175,15 +175,8 @@ gtk_snippet_get_type(void)    return gtk_snippet_type;  } -void -gtk_snippet_set_state(GtkSnippet *cpu, gint num) -{ -   cpu->sel = num; -   gtk_snippet_paint(GTK_WIDGET(cpu)); -} - -GtkWidget * gtk_snippet_new() +GtkWidget *gtk_snippet_new(void)  {      GtkSnippet *result; @@ -300,13 +293,16 @@ gtk_snippet_realize(GtkWidget *widget)  } -static gboolean gtk_snippet_button_press(GtkSnippet *snippet, GdkEventButton *event, gpointer *data) +static gboolean gtk_snippet_button_press(GtkWidget *widget, GdkEventButton *event)  { +    GtkSnippet *snippet;                    /* COmposant GTK réel          */      unsigned int index;                     /* Indice de la ligne visée    */      PangoLayoutIter *iter;                  /* Boucle de parcours          */      int y0;                                 /* Ordonnée du haut d'une ligne*/      int y1;                                 /* Ordonnée du bas d'une ligne */ +    snippet = GTK_SNIPPET(widget); +      index = 0;      iter = pango_layout_get_iter(snippet->layout); @@ -342,7 +338,7 @@ gtk_snippet_expose(GtkWidget *widget,    g_return_val_if_fail(GTK_IS_SNIPPET(widget), FALSE);    g_return_val_if_fail(event != NULL, FALSE); -  gtk_snippet_paint(widget); +  gtk_snippet_paint(GTK_SNIPPET(widget));    return FALSE;  } @@ -410,7 +406,7 @@ gtk_snippet_paint(GtkSnippet *snippet)      y0 = 0; -    dl_list_for_each(/**/liter, snippet->lines, rendering_line *) +    for (/* l! */liter = snippet->lines; liter != NULL; liter = g_rendering_line_get_next_iter(snippet->lines, liter))      {          draw_rendering_line(liter, GDK_DRAWABLE(widget->window), snippet->gc,                              MARGIN_SPACE, 2 * MARGIN_SPACE + snippet->line_height, @@ -421,7 +417,6 @@ gtk_snippet_paint(GtkSnippet *snippet)      } -  } @@ -446,27 +441,6 @@ gtk_snippet_destroy(GtkObject *object) -void gtk_snippet_set_sel(GtkSnippet *cpu, gint sel) -{ -    cpu->sel = sel; - -} - - - -void gtk_snippet_test(GtkSnippet *snippet) -{ - - - -    pango_layout_set_markup(snippet->layout, "<tt>int\t<span foreground='#ff0000'>80</span></tt>", -1); - - - - -} - -  /****************************************************************************** @@ -571,18 +545,9 @@ void gtk_snippet_set_processor(GtkSnippet *snippet, const asm_processor *proc)  void gtk_snippet_set_rendering_lines(GtkSnippet *snippet, rendering_line *lines)  { -    rendering_line *iter;                   /* Boucle de parcours          */ -    off_t bin_len;                          /* Taille d'instruction        */ -      snippet->lines = lines; -    bin_len = 0; - -    dl_list_for_each(iter, lines, rendering_line *) -        get_rendering_line_binary_len(iter, &bin_len); - -    dl_list_for_each(iter, lines, rendering_line *) -        set_rendering_line_max_binary_len(iter, bin_len); +    g_rendering_lines_update_bin_len(lines);      gtk_snippet_recompute_size_request(snippet); @@ -608,21 +573,12 @@ void gtk_snippet_recompute_size_request(GtkSnippet *snippet)  {      int width;                              /* Largeur de l'objet actuelle */      int height;                             /* Hauteur de l'objet actuelle */ -    rendering_line *iter;                   /* Boucle de parcours          */ -    width = 0; -    height = 0; - -    dl_list_for_each(iter, snippet->lines, rendering_line *) -    { -        get_rendering_line_size(iter, &width, &height); - -        if (iter == snippet->lines) -            snippet->line_height = height; - -    } +    g_rendering_lines_get_size(snippet->lines, &width, &height, &snippet->line_height); -    gtk_widget_set_size_request(GTK_WIDGET(snippet), width + 2 * MARGIN_SPACE + snippet->line_height, height); +    gtk_widget_set_size_request(GTK_WIDGET(snippet), +                                width + 2 * MARGIN_SPACE + snippet->line_height, +                                height);  } diff --git a/src/gtksnippet.h b/src/gtksnippet.h index 7488122..ab7ad4f 100644 --- a/src/gtksnippet.h +++ b/src/gtksnippet.h @@ -110,14 +110,11 @@ struct _GtkSnippetClass {  GtkType gtk_snippet_get_type(void);  void gtk_snippet_set_sel(GtkSnippet *cpu, gint sel); -GtkWidget * gtk_snippet_new(); +GtkWidget *gtk_snippet_new(void); -void gtk_snippet_test(GtkSnippet *cpu); - -  /* Choisit d'afficher les adresses virtuelles ou non. */  void gtk_snippet_show_vaddress(GtkSnippet *, gboolean); | 
