From 9a95c4c48dfbd2e084d92afe00f86daf1eeda9bb Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Wed, 17 Jul 2019 10:34:07 +0200 Subject: [PATCH] implement suggestions by dwfreed --- src/fe-text/textbuffer-formats.c | 19 +++++-------------- src/fe-text/textbuffer.c | 10 ++-------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/fe-text/textbuffer-formats.c b/src/fe-text/textbuffer-formats.c index 89308652..c9672029 100644 --- a/src/fe-text/textbuffer-formats.c +++ b/src/fe-text/textbuffer-formats.c @@ -10,7 +10,6 @@ #include #include -static int skip_next_printtext; TEXT_BUFFER_FORMAT_REC *format_rec; #define g_ref_string_release_opt(str) ((str) == NULL ? (void)0 : g_ref_string_release(str)) @@ -18,8 +17,12 @@ TEXT_BUFFER_FORMAT_REC *format_rec; void textbuffer_format_rec_free(TEXT_BUFFER_FORMAT_REC *rec) { int n; + if (rec == NULL) return; + if (rec == LINE_INFO_FORMAT_SET) + return; + g_ref_string_release_opt(rec->module); g_ref_string_release_opt(rec->format); g_ref_string_release_opt(rec->server_tag); @@ -64,7 +67,6 @@ static void sig_print_format(THEME_REC *theme, const char *module, TEXT_DEST_REC int formatnum; FORMAT_REC *formats; - skip_next_printtext = TRUE; dest->flags |= PRINT_FLAG_FORMAT; formatnum = GPOINTER_TO_INT(formatnump); @@ -85,14 +87,6 @@ static void sig_print_noformat(TEXT_DEST_REC *dest, const char *text) format_rec->flags = dest->flags; } -static void sig_print_text(TEXT_DEST_REC *dest, const char *text) -{ - if (skip_next_printtext) { - skip_next_printtext = FALSE; - return; - } -} - static void sig_gui_print_text_finished(WINDOW_REC *window) { GUI_WINDOW_REC *gui; @@ -142,7 +136,7 @@ LINE_REC *textbuffer_reformat_line(WINDOW_REC *window, LINE_REC *line) curr = line; line = line->prev; - while (line != NULL && line->info.format != NULL && line->info.format == LINE_INFO_FORMAT_SET) { + while (line != NULL && line->info.format == LINE_INFO_FORMAT_SET) { LINE_REC *prev = line->prev; textbuffer_view_remove_line(gui->view, line); line = prev; @@ -196,13 +190,11 @@ LINE_REC *textbuffer_reformat_line(WINDOW_REC *window, LINE_REC *line) void textbuffer_formats_init(void) { - skip_next_printtext = FALSE; format_rec = NULL; signal_add("print format", (SIGNAL_FUNC) sig_print_format); signal_add("print noformat", (SIGNAL_FUNC) sig_print_noformat); signal_add("gui print text finished", (SIGNAL_FUNC) sig_gui_print_text_finished); - signal_add_first("print text", (SIGNAL_FUNC) sig_print_text); } void textbuffer_formats_deinit(void) @@ -210,7 +202,6 @@ void textbuffer_formats_deinit(void) signal_remove("print format", (SIGNAL_FUNC) sig_print_format); signal_remove("print noformat", (SIGNAL_FUNC) sig_print_noformat); signal_remove("gui print text finished", (SIGNAL_FUNC) sig_gui_print_text_finished); - signal_remove("print text", (SIGNAL_FUNC) sig_print_text); textbuffer_format_rec_free(format_rec); } diff --git a/src/fe-text/textbuffer.c b/src/fe-text/textbuffer.c index 24878441..14bf29be 100644 --- a/src/fe-text/textbuffer.c +++ b/src/fe-text/textbuffer.c @@ -397,10 +397,7 @@ void textbuffer_remove(TEXT_BUFFER_REC *buffer, LINE_REC *line) buffer->lines_count--; text_chunk_line_free(buffer, line); - if (line->info.format != NULL && - line->info.format != LINE_INFO_FORMAT_SET) { - textbuffer_format_rec_free(line->info.format); - } + textbuffer_format_rec_free(line->info.format); g_slice_free(LINE_REC, line); } @@ -419,10 +416,7 @@ void textbuffer_remove_all_lines(TEXT_BUFFER_REC *buffer) while (buffer->first_line != NULL) { line = buffer->first_line->next; - if (buffer->first_line->info.format != NULL && - buffer->first_line->info.format != LINE_INFO_FORMAT_SET) { - textbuffer_format_rec_free(buffer->first_line->info.format); - } + textbuffer_format_rec_free(buffer->first_line->info.format); g_slice_free(LINE_REC, buffer->first_line); buffer->first_line = line; }