From 51dff92af8ca82ac1cce3f74be70c3705ca88683 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sat, 30 Jun 2012 10:58:19 +0000 Subject: Improved the function providing line indexes from addresses. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@246 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 5 +++++ src/glibext/gcodebuffer.c | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 07eb283..6968d8a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +12-06-30 Cyrille Bagard + + * src/glibext/gcodebuffer.c: + Improve the function providing line indexes from addresses. + 12-06-24 Cyrille Bagard * src/glibext/gcodebuffer.c: diff --git a/src/glibext/gcodebuffer.c b/src/glibext/gcodebuffer.c index de92b71..d5dbc8c 100644 --- a/src/glibext/gcodebuffer.c +++ b/src/glibext/gcodebuffer.c @@ -26,7 +26,6 @@ #include #include -#include #include "../glibext/delayed-int.h" @@ -380,8 +379,7 @@ GCodeBuffer *g_code_buffer_new(void) * * * Description : Convertit une adresse en indice de ligne. * * * -* Retour : Indice de l'adresse trouvée, ou buffer->used en cas d'échec, * -* pour assurer la prise en compte de VMPA_MAX. * +* Retour : Indice de l'adresse trouvée, ou 0 en cas d'échec. * * * * Remarques : - * * * @@ -391,10 +389,16 @@ static size_t g_code_buffer_get_index_from_address(GCodeBuffer *buffer, vmpa_t a { size_t result; /* Indice à retourner */ + if (addr == VMPA_MAX) + return (buffer->used > 0 ? buffer->used - 1 : 0); + for (result = 0; result < buffer->used; result++) if (g_buffer_line_get_address(buffer->lines[result]) == addr) break; + if (result == buffer->used) + result = 0; + return result; } @@ -650,8 +654,6 @@ static void g_buffer_view_compute_required_widths(GBufferView *view) first = g_code_buffer_get_index_from_address(view->buffer, view->start); last = g_code_buffer_get_index_from_address(view->buffer, view->end); - last = MIN(last, view->buffer->used > 0 ? view->buffer->used - 1 : 0); - view->line_height = 17; view->left_margin = 2 * view->line_height; -- cgit v0.11.2-87-g4458