summaryrefslogtreecommitdiff
path: root/src/glibext
diff options
context:
space:
mode:
Diffstat (limited to 'src/glibext')
-rw-r--r--src/glibext/gcodebuffer.c133
-rw-r--r--src/glibext/gcodebuffer.h4
2 files changed, 120 insertions, 17 deletions
diff --git a/src/glibext/gcodebuffer.c b/src/glibext/gcodebuffer.c
index ac6e807..b504473 100644
--- a/src/glibext/gcodebuffer.c
+++ b/src/glibext/gcodebuffer.c
@@ -24,8 +24,8 @@
#include "gcodebuffer.h"
-#include <limits.h>
#include <malloc.h>
+#include <stdlib.h>
#include <string.h>
@@ -143,8 +143,8 @@ struct _GBufferView
GObject parent; /* A laisser en premier */
GCodeBuffer *buffer; /* Tampon de code visualisé */
- vmpa_t start; /* Première ligne intégrée */
- vmpa_t end; /* Dernière ligne intégrée */
+ vmpa2t *start; /* Première ligne intégrée */
+ vmpa2t *end; /* Dernière ligne intégrée */
size_t first_index; /* Indice de la première ligne */
gint line_height; /* Hauteur maximale des lignes */
@@ -512,7 +512,7 @@ static size_t _g_code_buffer_get_index_from_address_new(const GCodeBuffer *buffe
* *
* Description : Convertit une adresse en indice de ligne. *
* *
-* Retour : Indice de l'adresse trouvée, ou 0 en cas d'échec. *
+* Retour : Indice de l'adresse trouvée, ou le nombre de lignes sinon. *
* *
* Remarques : - *
* *
@@ -521,6 +521,108 @@ static size_t _g_code_buffer_get_index_from_address_new(const GCodeBuffer *buffe
static size_t g_code_buffer_get_index_from_address(GCodeBuffer *buffer, const vmpa2t *addr, bool first)
{
size_t result; /* Indice à retourner */
+ GBufferLine **found; /* Renvoi vers une trouvaille */
+ const mrange_t *range; /* Couverture d'une ligne */
+
+ /**
+ * Si aucune adresse (ie. aucune limite ?) n'est précisée, on se base sur
+ * la direction pour trouver le bon indice.
+ */
+
+ if (addr == NULL)
+ result = (first ? 0 : buffer->used - 1);
+
+ /**
+ * Sinon on parcourt méthodiquement toutes les lignes !
+ */
+
+ else
+ {
+
+#if 0
+ int cmp_addr_and_line(const vmpa2t *addr, const GBufferLine **line)
+ {
+ int status; /* Bilan d'une comparaison */
+ const mrange_t *lrange; /* Couverture d'une ligne */
+
+ lrange = g_buffer_line_get_range(*line);
+
+ if (mrange_contains_addr(lrange, addr))
+ status = 0;
+
+ else
+ {
+ if (cmp_vmpa(addr, get_mrange_addr(lrange)) < 0)
+ status = -1;
+ else
+ status = 1;
+ }
+
+ return status;
+
+ }
+
+ found = bsearch(addr, buffer->lines, buffer->used, sizeof(GBufferLine *),
+ (__compar_fn_t)cmp_addr_and_line);
+#endif
+
+
+
+
+ found = NULL;
+
+
+
+ for (result = 0; result < buffer->used; result++)
+ {
+ range = g_buffer_line_get_range(buffer->lines[result]);
+
+ if (mrange_contains_addr(range, addr))
+ {
+ found = &buffer->lines[result];
+ break;
+ }
+
+ }
+
+
+ if (found == NULL)
+ result = buffer->used;
+
+ else
+ {
+ result = found - buffer->lines;
+
+ //printf(" [index] [B] 0x%08x -> %zu\n", (unsigned int)addr->virtual, result);
+
+ if (first)
+ for (; result > 0; result--)
+ {
+ range = g_buffer_line_get_range(buffer->lines[result - 1]);
+ if (!mrange_contains_addr(range, addr)) break;
+ }
+
+ else
+ for (; (result + 1) < buffer->used; result++)
+ {
+ range = g_buffer_line_get_range(buffer->lines[result + 1]);
+ if (!mrange_contains_addr(range, addr)) break;
+ }
+
+ //printf(" [A] 0x%08x -> %zu\n", (unsigned int)addr->virtual, result);
+
+ }
+
+ }
+
+ return result;
+
+
+
+
+
+#if 0
+ size_t result; /* Indice à retourner */
result = _g_code_buffer_get_index_from_address(buffer, addr, first);
@@ -533,7 +635,7 @@ static size_t g_code_buffer_get_index_from_address(GCodeBuffer *buffer, const vm
result = 0;
return result;
-
+#endif
}
@@ -671,6 +773,7 @@ GBufferLine *g_code_buffer_find_line_by_addr(const GCodeBuffer *buffer, const vm
if (index == buffer->used)
result = NULL;
+
else
{
result = buffer->lines[index];
@@ -844,8 +947,8 @@ GBufferView *g_buffer_view_new(GCodeBuffer *buffer)
g_object_ref(G_OBJECT(buffer));
result->buffer = buffer;
- result->start = 0;
- result->end = VMPA_MAX;
+ result->start = NULL;
+ result->end = NULL;
return result;
@@ -866,10 +969,10 @@ GBufferView *g_buffer_view_new(GCodeBuffer *buffer)
* *
******************************************************************************/
-void g_buffer_view_restrict(GBufferView *view, vmpa_t start, vmpa_t end)
+void g_buffer_view_restrict(GBufferView *view, const vmpa2t *start, const vmpa2t *end)
{
- view->start = start;
- view->end = end;
+ view->start = dup_vmpa(start);
+ view->end = dup_vmpa(end);
}
@@ -888,10 +991,10 @@ void g_buffer_view_restrict(GBufferView *view, vmpa_t start, vmpa_t end)
* *
******************************************************************************/
-void g_buffer_view_get_restrictions(GBufferView *view, vmpa_t *start, vmpa_t *end)
+void g_buffer_view_get_restrictions(GBufferView *view, vmpa2t *start, vmpa2t *end)
{
- if (start != NULL) *start = view->start;
- if (end != NULL) *end = view->end;
+ if (start != NULL) copy_vmpa(start, view->start);
+ if (end != NULL) copy_vmpa(end, view->end);
}
@@ -1081,7 +1184,7 @@ gint g_buffer_view_get_width(GBufferView *view, const bool *display)
gint full_width; /* Calcul selon les fusions */
BufferLineColumn i; /* Boucle de parcours */
- if (!WIDTHS_CACHED(view))
+ //if (!WIDTHS_CACHED(view))
g_buffer_view_compute_required_widths(view, display);
result = view->left_text;
@@ -1685,7 +1788,7 @@ void g_buffer_view_highlight_segments(GBufferView *view, gint x, gint y)
first = g_code_buffer_get_index_from_address(view->buffer, view->start, true);
last = g_code_buffer_get_index_from_address(view->buffer, view->end, false);
- for (i = first; i < last; i++)
+ for (i = first; i <= last; i++)
view->highlighted = g_buffer_line_highlight_all_same_segments(view->buffer->lines[i],
view->highlighted, segment);
diff --git a/src/glibext/gcodebuffer.h b/src/glibext/gcodebuffer.h
index e607b9c..cb17821 100644
--- a/src/glibext/gcodebuffer.h
+++ b/src/glibext/gcodebuffer.h
@@ -111,10 +111,10 @@ GType g_buffer_view_get_type(void);
GBufferView *g_buffer_view_new(GCodeBuffer *);
/* Restreint le champ d'application de l'affichage. */
-void g_buffer_view_restrict(GBufferView *, vmpa_t, vmpa_t);
+void g_buffer_view_restrict(GBufferView *, const vmpa2t *, const vmpa2t *);
/* Indique le champ d'application de l'affichage. */
-void g_buffer_view_get_restrictions(GBufferView *, vmpa_t *, vmpa_t *);
+void g_buffer_view_get_restrictions(GBufferView *, vmpa2t *, vmpa2t *);
/* Fournit le tampon de code lié à un visualisateur donné. */
GCodeBuffer *g_buffer_view_get_buffer(const GBufferView *);