From c284885cb9343ac57d3a17ecc9feccda77145f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sun, 6 Sep 2015 12:36:33 +0000 Subject: [PATCH] [GB.EVAL] * BUG: Now lines of any length can be highlighted. git-svn-id: svn://localhost/gambas/trunk@7278 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/lib/eval/eval.c | 2 ++ main/lib/eval/eval_analyze.c | 58 +++++++++++++++++++++++++++++------- main/lib/eval/eval_analyze.h | 5 ++-- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/main/lib/eval/eval.c b/main/lib/eval/eval.c index c52b4dc20..55778f300 100644 --- a/main/lib/eval/eval.c +++ b/main/lib/eval/eval.c @@ -28,6 +28,7 @@ #include "gb_error.h" #include "gb_array.h" +#include "eval_analyze.h" #include "eval_trans.h" #include "gb_code.h" #include "eval.h" @@ -51,6 +52,7 @@ void EVAL_exit(void) { EVAL_clear(&EVAL_read_expr, FALSE); RESERVED_exit(); + EVAL_analyze_exit(); } GB_VALUE *EVAL_expression(EXPRESSION *expr, EVAL_FUNCTION get_value) diff --git a/main/lib/eval/eval_analyze.c b/main/lib/eval/eval_analyze.c index d633358bb..8f9cceb60 100644 --- a/main/lib/eval/eval_analyze.c +++ b/main/lib/eval/eval_analyze.c @@ -25,6 +25,7 @@ #include "gambas.h" #include "gb_common.h" +#include "gb_array.h" #include "eval_analyze.h" #include "CSystem.h" @@ -33,8 +34,10 @@ static char _analyze_buffer[256]; static int _analyze_buffer_pos; -static EVAL_COLOR colors[EVAL_MAX_COLOR]; -static int colors_len; +#define COLOR_BUFFER_SIZE 256 +static EVAL_COLOR _colors[COLOR_BUFFER_SIZE]; +static int _colors_len = 0; +static EVAL_COLOR *_color_buffer = NULL; static int get_type(PATTERN *pattern) { @@ -139,18 +142,49 @@ static void add_data(int state, int len) { EVAL_COLOR *color; - if (colors_len >= EVAL_MAX_COLOR || len == 0) + if (len == 0) return; + + if (_colors_len >= COLOR_BUFFER_SIZE) + { + if (!_color_buffer) + ARRAY_create_inc(&_color_buffer, COLOR_BUFFER_SIZE); + + color = ARRAY_add_many(&_color_buffer, COLOR_BUFFER_SIZE); + memcpy(color, _colors, sizeof(EVAL_COLOR) * COLOR_BUFFER_SIZE); + _colors_len = 0; + } //printf("[%d] %d %d\n", colors_len, state, len); - color = &colors[colors_len]; + color = &_colors[_colors_len]; color->state = state; color->len = len; color->alternate = FALSE; - colors_len++; + _colors_len++; } +static void flush_colors(EVAL_ANALYZE *result) +{ + EVAL_COLOR *color; + + if (_color_buffer) + { + if (_colors_len) + { + color = ARRAY_add_many(&_color_buffer, _colors_len); + memcpy(color, _colors, sizeof(EVAL_COLOR) * _colors_len); + } + + result->color = _color_buffer; + result->len = ARRAY_count(_color_buffer); + } + else + { + result->color = _colors; + result->len = _colors_len; + } +} static int is_proc(void) { @@ -274,8 +308,10 @@ static void analyze(EVAL_ANALYZE *result) int len, i; bool preprocessor; + _colors_len = 0; + EVAL_analyze_exit(); + pattern = EVAL->pattern; - colors_len = 0; nspace = 0; preprocessor = FALSE; @@ -519,9 +555,7 @@ static void analyze(EVAL_ANALYZE *result) } flush_result(result); - - result->color = colors; - result->len = colors_len; + flush_colors(result); //fprintf(stderr, "analyze: %d %s\n", strlen(result->str), result->str); } @@ -614,4 +648,8 @@ PUBLIC void EVAL_analyze(const char *src, int len, int state, EVAL_ANALYZE *resu } - +void EVAL_analyze_exit(void) +{ + if (_color_buffer) + ARRAY_delete(&_color_buffer); +} \ No newline at end of file diff --git a/main/lib/eval/eval_analyze.h b/main/lib/eval/eval_analyze.h index 268292e24..78d6464ae 100644 --- a/main/lib/eval/eval_analyze.h +++ b/main/lib/eval/eval_analyze.h @@ -26,8 +26,7 @@ #include "eval.h" -#define EVAL_MAX_COLOR 256 - -PUBLIC void EVAL_analyze(const char *src, int len, int state, EVAL_ANALYZE *result, bool rewrite); +void EVAL_analyze(const char *src, int len, int state, EVAL_ANALYZE *result, bool rewrite); +void EVAL_analyze_exit(void); #endif