summaryrefslogtreecommitdiff
path: root/src/glibext
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-02-22 11:35:09 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-02-22 11:35:09 (GMT)
commitb639c1f4abca32152bf88f8fd47a9cd114da701b (patch)
tree3c10f78c94e2747f4c22d692d276ae24c1f6a44d /src/glibext
parentd450f573d94f795d83d09526546d63c81fde2e1d (diff)
Created a dialog box to select an entry point to display.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@476 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/glibext')
-rw-r--r--src/glibext/gbinportion.c15
-rw-r--r--src/glibext/gbufferline.c56
-rw-r--r--src/glibext/gbufferline.h10
-rw-r--r--src/glibext/gbuffersegment.c76
-rw-r--r--src/glibext/gbuffersegment.h2
-rw-r--r--src/glibext/gcodebuffer.c90
-rw-r--r--src/glibext/gcodebuffer.h2
7 files changed, 223 insertions, 28 deletions
diff --git a/src/glibext/gbinportion.c b/src/glibext/gbinportion.c
index 1fbb460..16f4814 100644
--- a/src/glibext/gbinportion.c
+++ b/src/glibext/gbinportion.c
@@ -699,18 +699,21 @@ bool g_binary_portion_get_pos_from_addr(GBinPortion *portion, const vmpa2t *addr
void g_binary_portion_print(const GBinPortion *portion, GCodeBuffer *buffer, MemoryDataSize msize)
{
+ mrange_t range; /* Couverture à fournir */
GBufferLine *line; /* Nouvelle ligne à éditer */
char rights[64]; /* Traduction en texte */
/* On ne traite pas les portions anonymes ! */
if (portion->desc == NULL) return;
- line = g_code_buffer_append_new_line(buffer, &portion->range);
+ init_mrange(&range, get_mrange_addr(&portion->range), 0);
+
+ line = g_code_buffer_append_new_line(buffer, &range);
g_buffer_line_fill_mrange(line, msize, msize);
/* Séparation */
- line = g_code_buffer_append_new_line(buffer, &portion->range);
+ line = g_code_buffer_append_new_line(buffer, &range);
g_buffer_line_fill_mrange(line, msize, msize);
g_buffer_line_start_merge_at(line, BLC_ASSEMBLY_HEAD);
@@ -719,7 +722,7 @@ void g_binary_portion_print(const GBinPortion *portion, GCodeBuffer *buffer, Mem
/* Retour à la ligne */
- line = g_code_buffer_append_new_line(buffer, &portion->range);
+ line = g_code_buffer_append_new_line(buffer, &range);
g_buffer_line_fill_mrange(line, msize, msize);
g_buffer_line_start_merge_at(line, BLC_ASSEMBLY_HEAD);
@@ -727,7 +730,7 @@ void g_binary_portion_print(const GBinPortion *portion, GCodeBuffer *buffer, Mem
/* Description */
- line = g_code_buffer_append_new_line(buffer, &portion->range);
+ line = g_code_buffer_append_new_line(buffer, &range);
g_buffer_line_fill_mrange(line, msize, msize);
g_buffer_line_start_merge_at(line, BLC_ASSEMBLY_HEAD);
@@ -746,13 +749,13 @@ void g_binary_portion_print(const GBinPortion *portion, GCodeBuffer *buffer, Mem
/* Retour à la ligne */
- line = g_code_buffer_append_new_line(buffer, &portion->range);
+ line = g_code_buffer_append_new_line(buffer, &range);
g_buffer_line_fill_mrange(line, msize, msize);
g_buffer_line_start_merge_at(line, BLC_ASSEMBLY_HEAD);
g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, "; ", 2, RTT_COMMENT);
- line = g_code_buffer_append_new_line(buffer, &portion->range);
+ line = g_code_buffer_append_new_line(buffer, &range);
g_buffer_line_fill_mrange(line, msize, msize);
}
diff --git a/src/glibext/gbufferline.c b/src/glibext/gbufferline.c
index 824578d..ff64604 100644
--- a/src/glibext/gbufferline.c
+++ b/src/glibext/gbufferline.c
@@ -24,6 +24,7 @@
#include "gbufferline.h"
+#include <assert.h>
#include <string.h>
#include <gtk/gtk.h> /* Récupération du langage par défaut ; FIXME ? */
@@ -834,7 +835,7 @@ GBufferSegment *g_buffer_line_get_segment_at(const GBufferLine *line, const gint
if (result == NULL)
printf(" -- get segment at -- found nothing...\n");
else
- printf(" -- get segment at -- found %p '%s'...\n", result, g_buffer_segment_get_text(result));
+ printf(" -- get segment at -- found %p '%s'...\n", result, g_buffer_segment_get_text(result, false));
@@ -1025,7 +1026,10 @@ void g_buffer_line_insert_text(GBufferLine *line, BufferLineColumn column, const
/******************************************************************************
* *
-* Paramètres : line = ligne à venir consulter. *
+* Paramètres : line = ligne à venir consulter. *
+* first = première colonne à parcourir. *
+* end = colonne de fin de parcours. *
+* markup = indique si le texte doit être décoré ou non. *
* *
* Description : Donne le texte représenté par une ligne de tampon. *
* *
@@ -1035,23 +1039,38 @@ void g_buffer_line_insert_text(GBufferLine *line, BufferLineColumn column, const
* *
******************************************************************************/
-char *g_buffer_line_get_text(const GBufferLine *line)
+char *g_buffer_line_get_text(const GBufferLine *line, BufferLineColumn first, BufferLineColumn end, bool markup)
{
char *result; /* Construction à retourner */
BufferLineColumn i; /* Boucle de parcours #1 */
size_t j; /* Boucle de parcours #2 */
+ char *extra; /* Contenu à intégrer au texte */
result = NULL;
- for (i = BLC_ASSEMBLY_HEAD; i < BLC_COUNT; i++)
+ assert(first < end);
+
+ for (i = first; i < end; i++)
+ {
+ if (i > first && result != NULL)
+ result = stradd(result, " ");
+
for (j = 0; j < line->columns[i].count; j++)
+ {
+ extra = g_buffer_segment_get_text(line->columns[i].segments[j], markup);
+
if (result == NULL)
+ result = extra;
+
+ else
{
- result = strdup(g_buffer_segment_get_text(line->columns[i].segments[j]));
- result = stradd(result, " ");
+ result = stradd(result, extra);
+ free(extra);
}
- else
- result = stradd(result, g_buffer_segment_get_text(line->columns[i].segments[j]));
+
+ }
+
+ }
return result;
@@ -1160,6 +1179,25 @@ void g_buffer_line_add_flag(GBufferLine *line, BufferLineFlags flag)
/******************************************************************************
* *
+* Paramètres : line = ligne à venir consulter. *
+* *
+* Description : Renseigne sur les propriétés particulières liées à une ligne.*
+* *
+* Retour : Propriétés intégrées. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+BufferLineFlags g_buffer_line_get_flags(const GBufferLine *line)
+{
+ return line->flags;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : line = ligne à venir compléter. *
* flag = propriété à supprimer. *
* *
@@ -1201,7 +1239,7 @@ void g_buffer_line_draw(GBufferLine *line, cairo_t *cairo, const gint max_widths
gint x; /* Point de départ d'impression*/
BufferLineColumn i; /* Boucle de parcours */
- if (line->flags != BLF_NONE)
+ if (line->flags != BLF_NONE && line->flags != BLF_HAS_CODE)
{
class = G_BUFFER_LINE_GET_CLASS(line);
diff --git a/src/glibext/gbufferline.h b/src/glibext/gbufferline.h
index 6984c37..bf703ab 100644
--- a/src/glibext/gbufferline.h
+++ b/src/glibext/gbufferline.h
@@ -87,8 +87,9 @@ typedef enum _BufferLineColumn
typedef enum _BufferLineFlags
{
BLF_NONE = 0 << 0, /* Aucune */
- BLF_ENTRYPOINT = 1 << 0, /* Représentation d'une entrée */
- BLF_BOOKMARK = 1 << 1 /* Signet associé */
+ BLF_HAS_CODE = 1 << 0, /* La ligne contient du code */
+ BLF_ENTRYPOINT = 1 << 1, /* Représentation d'une entrée */
+ BLF_BOOKMARK = 1 << 2 /* Signet associé */
} BufferLineFlags;
@@ -124,7 +125,7 @@ GSList *g_buffer_line_highlight_all_same_segments(const GBufferLine *, GSList *,
void g_buffer_line_insert_text(GBufferLine *, BufferLineColumn, const char *, size_t, RenderingTagType);
/* Donne le texte représenté par une ligne de tampon. */
-char *g_buffer_line_get_text(const GBufferLine *);
+char *g_buffer_line_get_text(const GBufferLine *, BufferLineColumn, BufferLineColumn, bool);
/* Fournit la largeur requise pour une colonne de ligne donnée. */
gint g_buffer_line_get_column_width(GBufferLine *, BufferLineColumn);
@@ -138,6 +139,9 @@ void g_buffer_line_start_merge_at(GBufferLine *, BufferLineColumn);
/* Ajoute une propriété particulière à une ligne donnée. */
void g_buffer_line_add_flag(GBufferLine *, BufferLineFlags);
+/* Renseigne sur les propriétés particulières liées à une ligne. */
+BufferLineFlags g_buffer_line_get_flags(const GBufferLine *);
+
/* Retire une propriété particulière à une ligne donnée. */
void g_buffer_line_remove_flag(GBufferLine *, BufferLineFlags);
diff --git a/src/glibext/gbuffersegment.c b/src/glibext/gbuffersegment.c
index 1ebb543..27891a8 100644
--- a/src/glibext/gbuffersegment.c
+++ b/src/glibext/gbuffersegment.c
@@ -29,6 +29,7 @@
#include <string.h>
+#include "../common/extstr.h"
#include "../common/fnv1a.h"
#include "../gtkext/gtkblockview.h"
#include "../gtkext/support.h"
@@ -385,6 +386,7 @@ bool g_buffer_segment_compare(const GBufferSegment *segment, const GBufferSegmen
/******************************************************************************
* *
* Paramètres : segment = fragment de texte à consulter. *
+* markup = indique si le texte doit être décoré ou non. *
* *
* Description : Fournit le texte brut conservé dans le segment. *
* *
@@ -394,9 +396,79 @@ bool g_buffer_segment_compare(const GBufferSegment *segment, const GBufferSegmen
* *
******************************************************************************/
-const char *g_buffer_segment_get_text(const GBufferSegment *segment)
+char *g_buffer_segment_get_text(const GBufferSegment *segment, bool markup)
{
- return segment->text;
+ char *result; /* Description à renvoyer */
+ char color[7]; /* Couleur hexadécimale */
+
+ /* Résolution du cas simple */
+ if (!markup)
+ return strdup(segment->text);
+
+ result = strdup("<span ");
+
+ /* Couleur */
+
+ result = stradd(result, "foreground=\"#");
+
+ snprintf(color, sizeof(color), "%02hhx%02hhx%02hhx",
+ (unsigned char)(segment->pattern->foreground.color.red * 255),
+ (unsigned char)(segment->pattern->foreground.color.green * 255),
+ (unsigned char)(segment->pattern->foreground.color.blue * 255));
+
+ result = stradd(result, color);
+
+ result = stradd(result, "\"");
+
+ /* Style */
+
+ result = stradd(result, "style=\"");
+
+ switch (segment->pattern->slant)
+ {
+ case CAIRO_FONT_SLANT_NORMAL:
+ result = stradd(result, "normal");
+ break;
+
+ case CAIRO_FONT_SLANT_ITALIC:
+ result = stradd(result, "italic");
+ break;
+
+ case CAIRO_FONT_SLANT_OBLIQUE:
+ result = stradd(result, "oblique");
+ break;
+
+ }
+
+ result = stradd(result, "\"");
+
+ /* Epaisseur */
+
+ result = stradd(result, "weight=\"");
+
+ switch (segment->pattern->weight)
+ {
+ case CAIRO_FONT_WEIGHT_NORMAL:
+ result = stradd(result, "normal");
+ break;
+
+ case CAIRO_FONT_WEIGHT_BOLD:
+ result = stradd(result, "bold");
+ break;
+
+ }
+
+ result = stradd(result, "\"");
+
+ /* Conclusion */
+
+ result = stradd(result, ">");
+
+ result = stradd(result, segment->text);
+
+ result = stradd(result, "</span>");
+
+ return result;
}
diff --git a/src/glibext/gbuffersegment.h b/src/glibext/gbuffersegment.h
index 10ae374..ace4e42 100644
--- a/src/glibext/gbuffersegment.h
+++ b/src/glibext/gbuffersegment.h
@@ -110,7 +110,7 @@ GBufferSegment *g_buffer_segment_new(RenderingTagType, const char *, size_t);
bool g_buffer_segment_compare(const GBufferSegment *, const GBufferSegment *);
/* Fournit le texte brut conservé dans le segment. */
-const char *g_buffer_segment_get_text(const GBufferSegment *);
+char *g_buffer_segment_get_text(const GBufferSegment *, bool);
/* Fournit la quantité de pixels requise pour l'impression. */
gint g_buffer_segment_get_width(const GBufferSegment *);
diff --git a/src/glibext/gcodebuffer.c b/src/glibext/gcodebuffer.c
index d13c9d6..afad0f4 100644
--- a/src/glibext/gcodebuffer.c
+++ b/src/glibext/gcodebuffer.c
@@ -127,6 +127,9 @@ static void g_code_buffer_init(GCodeBuffer *);
static size_t _g_code_buffer_get_index_from_address(const GCodeBuffer *, const vmpa2t *, bool);
/* Convertit une adresse en indice de ligne. */
+static size_t _g_code_buffer_get_index_from_address_new(const GCodeBuffer *, const vmpa2t *, bool);
+
+/* Convertit une adresse en indice de ligne. */
static size_t g_code_buffer_get_index_from_address(GCodeBuffer *, const vmpa2t *, bool);
@@ -419,6 +422,66 @@ static size_t _g_code_buffer_get_index_from_address(const GCodeBuffer *buffer, c
return (first ? 0 : buffer->used - 1);
+#if 0
+
+ for (result = 0; result < buffer->used; result++)
+ if (g_buffer_line_get_address(buffer->lines[result]) == addr)
+ break;
+
+ if (!first)
+ for (; result < (buffer->used - 1); result++)
+ if (g_buffer_line_get_address(buffer->lines[result + 1]) != addr)
+ break;
+
+#endif
+
+ return result;
+
+}
+
+/******************************************************************************
+* *
+* Paramètres : buffer = composant GTK à mettre à jour. *
+* addr = adresse où va se situer la ligne. *
+* first = indique si on l'arrête à la première ou la dernière.*
+* *
+* Description : Convertit une adresse en indice de ligne. *
+* *
+* Retour : Indice de l'adresse trouvée, ou 0 en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static size_t _g_code_buffer_get_index_from_address_new(const GCodeBuffer *buffer, const vmpa2t *addr, bool first)
+{
+ size_t result; /* Indice à retourner */
+ const mrange_t *range; /* Couverture d'une ligne */
+
+
+ for (result = 0; result < buffer->used; result++)
+ {
+ range = g_buffer_line_get_range(buffer->lines[result]);
+
+ if (mrange_contains_addr(range, addr))
+ {
+ printf(":: STOP :: %x + %u // %x\n",
+ range->addr.virtual, range->length, addr->virtual);
+ break;
+ }
+
+ }
+
+#if 0
+
+ size_t result; /* Indice à retourner */
+
+ if (addr == VMPA_MAX)
+ return (buffer->used > 0 ? buffer->used - 1 : 0);
+
+ /* TODO : coder un parcours plus optimal ! */
+
+ return (first ? 0 : buffer->used - 1);
#if 0
@@ -433,6 +496,8 @@ static size_t _g_code_buffer_get_index_from_address(const GCodeBuffer *buffer, c
#endif
+#endif
+
return result;
}
@@ -596,18 +661,31 @@ GBufferLine *g_code_buffer_insert_after(GCodeBuffer *buffer, GBufferLine *line)
* *
******************************************************************************/
-GBufferLine *g_code_buffer_find_line_by_addr(const GCodeBuffer *buffer, vmpa_t addr)
+GBufferLine *g_code_buffer_find_line_by_addr(const GCodeBuffer *buffer, const vmpa2t *addr)
{
GBufferLine *result; /* Instance à retourner */
size_t index; /* Indice de la ligne visée */
- index = _g_code_buffer_get_index_from_address(buffer, addr, true);
+ index = _g_code_buffer_get_index_from_address_new(buffer, addr, true);
if (index == buffer->used)
result = NULL;
else
+ {
result = buffer->lines[index];
+ while ((g_buffer_line_get_flags(result) & BLF_HAS_CODE) == 0)
+ {
+ if ((index + 1) == buffer->used) break;
+
+ result = buffer->lines[++index];
+
+ }
+
+ g_object_ref(G_OBJECT(result));
+
+ }
+
return result;
}
@@ -1109,7 +1187,7 @@ const vmpa2t *g_buffer_view_compute_caret(GBufferView *view, GBufferLine *line,
x - tmp_x, tmp_x, g_buffer_segment_get_caret_position(segment, tmp_x),
g_buffer_segment_get_width(segment));
- printf(" '%s'\n", g_buffer_segment_get_text(segment));
+ printf(" '%s'\n", g_buffer_segment_get_text(segment, false));
caret->x = (x - tmp_x) + g_buffer_segment_get_caret_position(segment, tmp_x);
@@ -1167,7 +1245,7 @@ static bool _g_buffer_view_move_caret(GBufferView *view, const GBufferLine *line
if (segment == NULL) return false;
- printf(" ====== FIRST SEG :: %p ('%s')\n", segment, g_buffer_segment_get_text(segment));
+ printf(" ====== FIRST SEG :: %p ('%s')\n", segment, g_buffer_segment_get_text(segment, false));
@@ -1190,7 +1268,7 @@ static bool _g_buffer_view_move_caret(GBufferView *view, const GBufferLine *line
segment = g_buffer_line_find_near_segment(line, segment, view->max_widths, display, dir, &offset);
- printf(" ====== NEAR SEG :: %p ('%s')\n", segment, segment ? g_buffer_segment_get_text(segment) : NULL);
+ printf(" ====== NEAR SEG :: %p ('%s')\n", segment, segment ? g_buffer_segment_get_text(segment, false) : NULL);
if (segment != NULL)
{
@@ -1484,7 +1562,7 @@ void g_buffer_view_highlight_segments(GBufferView *view, gint x, gint y)
if (segment == NULL) return;
- printf("text :: '%s'\n", g_buffer_segment_get_text(segment));
+ printf("text :: '%s'\n", g_buffer_segment_get_text(segment, false));
if (view->highlighted != NULL)
diff --git a/src/glibext/gcodebuffer.h b/src/glibext/gcodebuffer.h
index 62b725c..ddd45db 100644
--- a/src/glibext/gcodebuffer.h
+++ b/src/glibext/gcodebuffer.h
@@ -70,7 +70,7 @@ GBufferLine *g_code_buffer_insert_at(GCodeBuffer *, vmpa_t, bool);
GBufferLine *g_code_buffer_insert_after(GCodeBuffer *, GBufferLine *);
/* Retrouve une ligne au sein d'un tampon avec une adresse. */
-GBufferLine *g_code_buffer_find_line_by_addr(const GCodeBuffer *, vmpa_t);
+GBufferLine *g_code_buffer_find_line_by_addr(const GCodeBuffer *, const vmpa2t *);
/* Augmente l'indentation des prochaines lignes. */
void g_code_buffer_inc_indentation(GCodeBuffer *);