From 773549180db2e07cdd1051a6b26441b32d935c48 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Fri, 19 Jun 2009 16:55:15 +0300 Subject: [PATCH] dump: Use dump functions in add_document_to_string Now that struct dump_output supports appending to a string, add_document_to_string() can just use that feature, instead of duplicating the code. --- src/viewer/dump/dump.c | 87 ++++---------------------------------------------- 1 file changed, 7 insertions(+), 80 deletions(-) diff --git a/src/viewer/dump/dump.c b/src/viewer/dump/dump.c index 83f9b152..7bd454ef 100644 --- a/src/viewer/dump/dump.c +++ b/src/viewer/dump/dump.c @@ -599,93 +599,20 @@ dump_next(LIST_OF(struct string_list_item) *url_list) } } -/* Using this function in dump_to_file() is unfortunately slightly slower than - * the current code. However having this here instead of in the scripting - * backends is better. */ struct string * add_document_to_string(struct string *string, struct document *document) { - int y; + struct dump_output *out; + int error; assert(string && document); if_assert_failed return NULL; -#ifdef CONFIG_UTF8 - if (is_cp_utf8(document->options.cp)) - goto utf8; -#endif /* CONFIG_UTF8 */ - - for (y = 0; y < document->height; y++) { - int white = 0; - int x; - - for (x = 0; x < document->data[y].length; x++) { - struct screen_char *pos = &document->data[y].chars[x]; - unsigned char data = pos->data; - unsigned int frame = (pos->attr & SCREEN_ATTR_FRAME); + out = dump_output_alloc(-1, string); + if (!out) return NULL; - if (!isscreensafe(data)) { - white++; - continue; - } else { - if (frame && data >= 176 && data < 224) - data = frame_dumb[data - 176]; - - if (data <= ' ') { - /* Count spaces. */ - white++; - } else { - /* Print spaces if any. */ - if (white) { - add_xchar_to_string(string, ' ', white); - white = 0; - } - add_char_to_string(string, data); - } - } - } - - add_char_to_string(string, '\n'); - } -#ifdef CONFIG_UTF8 - goto end; -utf8: - for (y = 0; y < document->height; y++) { - int white = 0; - int x; - - for (x = 0; x < document->data[y].length; x++) { - struct screen_char *pos = &document->data[y].chars[x]; - unicode_val_T data = pos->data; - unsigned int frame = (pos->attr & SCREEN_ATTR_FRAME); - - if (!isscreensafe_ucs(data)) { - white++; - continue; - } else { - if (frame && data >= 176 && data < 224) - data = frame_dumb[data - 176]; - - if (data <= ' ') { - /* Count spaces. */ - white++; - } else if (data == UCS_NO_CHAR) { - /* This is the second cell of - * a double-cell character. */ - } else { - /* Print spaces if any. */ - if (white) { - add_xchar_to_string(string, ' ', white); - white = 0; - } - add_to_string(string, encode_utf8(data)); - } - } - } + error = dump_nocolor(document, out); - add_char_to_string(string, '\n'); - } -end: -#endif /* CONFIG_UTF8 */ - return string; + mem_free(out); + return error ? NULL : string; } -- 2.11.4.GIT