diff --git a/configure.in b/configure.in index c0931fa7e..cabba3dfd 100644 --- a/configure.in +++ b/configure.in @@ -1066,7 +1066,7 @@ EL_ARG_DEPEND(CONFIG_SYSMOUSE, sysmouse, [ --disable-sysmouse disable BSD sysmouse support]) EL_ARG_ENABLE(CONFIG_88_COLORS, 88-colors, [88 colors], - [ --enable-88-colors enable 88 color support]) + [ --enable-88-colors enable 88 color support]) EL_ARG_ENABLE(CONFIG_256_COLORS, 256-colors, [256 colors], [ --enable-256-colors enable 256 color support]) diff --git a/src/document/html/renderer.c b/src/document/html/renderer.c index cc8a066f0..2bab69b37 100644 --- a/src/document/html/renderer.c +++ b/src/document/html/renderer.c @@ -90,11 +90,11 @@ struct table_cache_entry { #define MAX_TABLE_CACHE_ENTRIES 16384 /* Global variables */ +static int table_cache_entries; +static struct hash *table_cache; + struct renderer_context { - int table_cache_entries; - struct hash *table_cache; - int last_link_to_move; struct tag *last_tag_to_move; /* All tags between document->tags and this tag (inclusive) should @@ -137,11 +137,21 @@ void put_chars(struct html_context *, unsigned char *, int); #define ALIGN_SPACES(x, o, n) mem_align_alloc(x, o, n, unsigned char, SPACES_GRANULARITY) +static inline void +set_screen_char_color(struct screen_char *schar, + color_T bgcolor, color_T fgcolor, + enum color_flags color_flags, + enum color_mode color_mode) +{ + struct color_pair colors = INIT_COLOR_PAIR(bgcolor, fgcolor); + + set_term_color(schar, &colors, color_flags, color_mode); +} + static int realloc_line(struct html_context *html_context, struct document *document, int y, int length) { - struct color_pair colors = INIT_COLOR_PAIR(par_format.bgcolor, 0x0); struct screen_char *pos, *end; struct line *line; @@ -162,7 +172,8 @@ realloc_line(struct html_context *html_context, struct document *document, end = &line->chars[length]; end->data = ' '; end->attr = 0; - set_term_color(end, &colors, 0, document->options.color_mode); + set_screen_char_color(end, par_format.bgcolor, 0x0, + 0, document->options.color_mode); for (pos = &line->chars[line->length]; pos < end; pos++) { copy_screen_chars(pos, end, 1); @@ -219,7 +230,6 @@ static inline void clear_hchars(struct html_context *html_context, int x, int y, int width) { struct part *part; - struct color_pair colors = INIT_COLOR_PAIR(par_format.bgcolor, 0x0); struct screen_char *pos, *end; assert(html_context); @@ -240,7 +250,8 @@ clear_hchars(struct html_context *html_context, int x, int y, int width) end = pos + width - 1; end->data = ' '; end->attr = 0; - set_term_color(end, &colors, 0, part->document->options.color_mode); + set_screen_char_color(end, par_format.bgcolor, 0x0, + 0, part->document->options.color_mode); while (pos < end) copy_screen_chars(pos++, end, 1); @@ -254,10 +265,7 @@ get_frame_char(struct html_context *html_context, struct part *part, int x, int y, unsigned char data, color_T bgcolor, color_T fgcolor) { - struct color_pair colors = INIT_COLOR_PAIR(bgcolor, fgcolor); struct screen_char *template; - static enum color_flags color_flags; - static enum color_mode color_mode; assert(html_context); if_assert_failed return NULL; @@ -274,11 +282,9 @@ get_frame_char(struct html_context *html_context, struct part *part, template = &POS(x, y); template->data = data; template->attr = SCREEN_ATTR_FRAME; - - color_mode = part->document->options.color_mode; - color_flags = part->document->options.color_flags; - - set_term_color(template, &colors, color_flags, color_mode); + set_screen_char_color(template, bgcolor, fgcolor, + part->document->options.color_flags, + part->document->options.color_mode); return template; } @@ -356,15 +362,10 @@ get_format_screen_char(struct html_context *html_context, schar_cache.attr |= SCREEN_ATTR_UNDERLINE; } - { - struct color_pair colors = INIT_COLOR_PAIR(format.style.bg, - format.style.fg); - - set_term_color(&schar_cache, &colors, - html_context->options->color_flags, - html_context->options->color_mode); - } - + set_screen_char_color(&schar_cache, format.style.bg, format.style.fg, + html_context->options->color_flags, + html_context->options->color_mode); + if (html_context->options->display_subs) { if (format.style.attr & AT_SUBSCRIPT) { if (format.style.attr & AT_UPDATE_SUB) { @@ -614,14 +615,14 @@ shift_chars(struct html_context *html_context, int y, int shift) len = LEN(y); - a = mem_alloc(len * sizeof(*a)); + a = fmem_alloc(len * sizeof(*a)); if (!a) return; copy_screen_chars(a, &POS(0, y), len); clear_hchars(html_context, 0, y, shift); copy_chars(html_context, shift, y, len, a); - mem_free(a); + fmem_free(a); move_links(html_context, 0, y, shift, y); } @@ -915,6 +916,38 @@ align_line(struct html_context *html_context, int y, int last) shift_chars(html_context, y, shift); } +static inline void +init_link_event_hooks(struct html_context *html_context, struct link *link) +{ + link->event_hooks = mem_calloc(1, sizeof(*link->event_hooks)); + if (!link->event_hooks) return; + +#define add_evhook(list_, type_, src_) \ + do { \ + struct script_event_hook *evhook; \ + \ + if (!src_) break; \ + \ + evhook = mem_calloc(1, sizeof(*evhook)); \ + if (!evhook) break; \ + \ + evhook->type = type_; \ + evhook->src = stracpy(src_); \ + add_to_list(*(list_), evhook); \ + } while (0) + + init_list(*link->event_hooks); + add_evhook(link->event_hooks, SEVHOOK_ONCLICK, format.onclick); + add_evhook(link->event_hooks, SEVHOOK_ONDBLCLICK, format.ondblclick); + add_evhook(link->event_hooks, SEVHOOK_ONMOUSEOVER, format.onmouseover); + add_evhook(link->event_hooks, SEVHOOK_ONHOVER, format.onhover); + add_evhook(link->event_hooks, SEVHOOK_ONFOCUS, format.onfocus); + add_evhook(link->event_hooks, SEVHOOK_ONMOUSEOUT, format.onmouseout); + add_evhook(link->event_hooks, SEVHOOK_ONBLUR, format.onblur); + +#undef add_evhook +} + static struct link * new_link(struct html_context *html_context, unsigned char *name, int namelen) { @@ -1008,28 +1041,7 @@ new_link(struct html_context *html_context, unsigned char *name, int namelen) link->color.foreground = link_is_textinput(link) ? format.style.fg : format.clink; - link->event_hooks = mem_calloc(1, sizeof(*link->event_hooks)); - if (link->event_hooks) { - init_list(*link->event_hooks); -#define add_evhook(list_, type_, src_) \ -do { \ - struct script_event_hook *evhook = mem_calloc(1, sizeof(*evhook)); \ - \ - if (evhook) { \ - evhook->type = type_; \ - evhook->src = stracpy(src_); \ - add_to_list(*list_, evhook); \ - } \ -} while (0) - if (format.onclick) add_evhook(link->event_hooks, SEVHOOK_ONCLICK, format.onclick); - if (format.ondblclick) add_evhook(link->event_hooks, SEVHOOK_ONDBLCLICK, format.ondblclick); - if (format.onmouseover) add_evhook(link->event_hooks, SEVHOOK_ONMOUSEOVER, format.onmouseover); - if (format.onhover) add_evhook(link->event_hooks, SEVHOOK_ONHOVER, format.onhover); - if (format.onfocus) add_evhook(link->event_hooks, SEVHOOK_ONFOCUS, format.onfocus); - if (format.onmouseout) add_evhook(link->event_hooks, SEVHOOK_ONMOUSEOUT, format.onmouseout); - if (format.onblur) add_evhook(link->event_hooks, SEVHOOK_ONBLUR, format.onblur); -#undef add_evhook - } + init_link_event_hooks(html_context, link); return link; } @@ -1046,14 +1058,14 @@ html_special_tag(struct document *document, unsigned char *t, int x, int y) tag_len = strlen(t); /* One byte is reserved for name in struct tag. */ tag = mem_alloc(sizeof(*tag) + tag_len); - if (tag) { - tag->x = x; - tag->y = y; - memcpy(tag->name, t, tag_len + 1); - add_to_list(document->tags, tag); - if ((void *) renderer_context.last_tag_for_newline == &document->tags) - renderer_context.last_tag_for_newline = tag; - } + if (!tag) return; + + tag->x = x; + tag->y = y; + memcpy(tag->name, t, tag_len + 1); + add_to_list(document->tags, tag); + if (renderer_context.last_tag_for_newline == (struct tag *) &document->tags) + renderer_context.last_tag_for_newline = tag; } @@ -1309,7 +1321,7 @@ put_chars(struct html_context *html_context, unsigned char *chars, int charslen) * non-whitespace content. */ if (html_is_preformatted() || html_has_non_space_chars(chars, charslen)) { - renderer_context.last_tag_for_newline = (void *) &part->document->tags; + renderer_context.last_tag_for_newline = (struct tag *) &part->document->tags; } int_lower_bound(&part->box.height, part->cy + 1); @@ -1417,7 +1429,7 @@ line_break(struct html_context *html_context) if (part->cx > 0) align_line(html_context, part->cy, 1); for (tag = renderer_context.last_tag_for_newline; - tag && (void *) tag != &part->document->tags; + tag && tag != (struct tag *) &part->document->tags; tag = tag->prev) { tag->x = X(0); tag->y = Y(part->cy + 1); @@ -1738,20 +1750,20 @@ html_special(struct html_context *html_context, enum html_special_type c, ...) void free_table_cache(void) { - if (renderer_context.table_cache) { + if (table_cache) { struct hash_item *item; int i; /* We do not free key here. */ - foreach_hash_item (item, *renderer_context.table_cache, i) { + foreach_hash_item (item, *table_cache, i) { mem_free_if(item->value); } - free_hash(renderer_context.table_cache); + free_hash(table_cache); } - renderer_context.table_cache = NULL; - renderer_context.table_cache_entries = 0; + table_cache = NULL; + table_cache_entries = 0; } struct part * @@ -1765,14 +1777,12 @@ format_html_part(struct html_context *html_context, struct html_element *html_state; int llm = renderer_context.last_link_to_move; struct tag *ltm = renderer_context.last_tag_to_move; - /*struct tag *ltn = last_tag_for_newline;*/ - int lm = html_context->margin; int ef = renderer_context.empty_format; - struct table_cache_entry *tce; + int lm = html_context->margin; /* Hash creation if needed. */ - if (!renderer_context.table_cache) { - renderer_context.table_cache = init_hash(8, &strhash); + if (!table_cache) { + table_cache = init_hash(8, &strhash); } else if (!document) { /* Search for cached entry. */ struct table_cache_entry_key key; @@ -1790,7 +1800,7 @@ format_html_part(struct html_context *html_context, key.x = x; key.link_num = link_num; - item = get_hash_item(renderer_context.table_cache, + item = get_hash_item(table_cache, (unsigned char *) &key, sizeof(key)); if (item) { /* We found it in cache, so just copy and return. */ @@ -1817,12 +1827,12 @@ format_html_part(struct html_context *html_context, } renderer_context.last_link_to_move = document->nlinks; - renderer_context.last_tag_to_move = (void *) &document->tags; - renderer_context.last_tag_for_newline = (void *) &document->tags; + renderer_context.last_tag_to_move = (struct tag *) &document->tags; + renderer_context.last_tag_for_newline = (struct tag *) &document->tags; } else { renderer_context.last_link_to_move = 0; - renderer_context.last_tag_to_move = NULL; - renderer_context.last_tag_for_newline = NULL; + renderer_context.last_tag_to_move = (struct tag *) NULL; + renderer_context.last_tag_for_newline = (struct tag *) NULL; } html_context->margin = margin; @@ -1863,17 +1873,17 @@ format_html_part(struct html_context *html_context, ret: renderer_context.last_link_to_move = llm; renderer_context.last_tag_to_move = ltm; - /* renderer_context.last_tag_for_newline = ltn; */ - html_context->margin = lm; renderer_context.empty_format = ef; + html_context->margin = lm; + if (html_context->table_level > 1 && !document - && renderer_context.table_cache - && renderer_context.table_cache_entries < MAX_TABLE_CACHE_ENTRIES) { + && table_cache + && table_cache_entries < MAX_TABLE_CACHE_ENTRIES) { /* Create a new entry. */ /* Clear memory to prevent bad key comparaison due to alignment * of key fields. */ - tce = mem_calloc(1, sizeof(*tce)); + struct table_cache_entry *tce = mem_calloc(1, sizeof(*tce)); /* A goto is used here to prevent a test or code * redundancy. */ if (!tce) goto end; @@ -1887,12 +1897,12 @@ ret: tce->key.link_num = link_num; copy_struct(&tce->part, part); - if (!add_hash_item(renderer_context.table_cache, + if (!add_hash_item(table_cache, (unsigned char *) &tce->key, sizeof(tce->key), tce)) { mem_free(tce); } else { - renderer_context.table_cache_entries++; + table_cache_entries++; } } @@ -1907,8 +1917,8 @@ render_html_document(struct cache_entry *cached, struct document *document, { struct html_context *html_context; struct part *part; - unsigned char *start = NULL; - unsigned char *end = NULL; + unsigned char *start; + unsigned char *end; struct string title; struct string head; int i; @@ -1918,20 +1928,19 @@ render_html_document(struct cache_entry *cached, struct document *document, if (!init_string(&head)) return; - renderer_context.g_ctrl_num = 0; - renderer_context.cached = cached; + if (cached->head) add_to_string(&head, cached->head); start = buffer->source; end = buffer->source + buffer->length; - if (cached->head) add_to_string(&head, cached->head); - html_context = init_html_parser(cached->uri, &document->options, start, end, &head, &title, put_chars_conv, line_break, html_special); if (!html_context) return; + renderer_context.g_ctrl_num = 0; + renderer_context.cached = cached; renderer_context.convert_table = get_convert_table(head.source, document->options.cp, document->options.assume_cp, diff --git a/src/terminal/tab.c b/src/terminal/tab.c index 8d6c1466f..60382097a 100644 --- a/src/terminal/tab.c +++ b/src/terminal/tab.c @@ -166,7 +166,7 @@ really_close_tab(struct session *ses) switch_to_tab(term, term->current_tab - 1, num_tabs - 1); } - + delete_window(ses->tab); }