From 9d6c0b13e88c775010b91646aefd974b624fa83e Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 22 Apr 2007 22:37:12 +0300 Subject: [PATCH 001/133] Bug 879, u2cp_: Use UCS_NO_BREAK_SPACE instead of 0xa0. --- src/intl/charsets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/intl/charsets.c b/src/intl/charsets.c index 719aff33..26da9d15 100644 --- a/src/intl/charsets.c +++ b/src/intl/charsets.c @@ -185,7 +185,7 @@ u2cp_(unicode_val_T u, int to, enum nbsp_mode nbsp_mode) /* To mark non breaking spaces in non-UTF-8 strings, we use a * special char NBSP_CHAR. */ - if (u == 0xa0) { + if (u == UCS_NO_BREAK_SPACE) { if (nbsp_mode == NBSP_MODE_HACK) return NBSP_CHAR_STRING; else /* NBSP_MODE_ASCII */ return " "; } From 70dc594d93795fd519b9b53d856256c970a063aa Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 22 Apr 2007 22:38:40 +0300 Subject: [PATCH 002/133] Bug 879: New constant UCS_SOFT_HYPHEN; use where applicable. --- src/intl/charsets.c | 2 +- src/intl/charsets.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/intl/charsets.c b/src/intl/charsets.c index 26da9d15..f65711a7 100644 --- a/src/intl/charsets.c +++ b/src/intl/charsets.c @@ -189,7 +189,7 @@ u2cp_(unicode_val_T u, int to, enum nbsp_mode nbsp_mode) if (nbsp_mode == NBSP_MODE_HACK) return NBSP_CHAR_STRING; else /* NBSP_MODE_ASCII */ return " "; } - if (u == 0xad) return ""; + if (u == UCS_SOFT_HYPHEN) return ""; if (u < 0xa0) { unicode_val_T strange = strange_chars[u - 0x80]; diff --git a/src/intl/charsets.h b/src/intl/charsets.h index 02524547..75e6f843 100644 --- a/src/intl/charsets.h +++ b/src/intl/charsets.h @@ -10,6 +10,9 @@ typedef uint32_t unicode_val_T; /* U+00A0 NO-BREAK SPACE. */ #define UCS_NO_BREAK_SPACE ((unicode_val_T) 0x00A0) +/* U+00AD SOFT HYPHEN. */ +#define UCS_SOFT_HYPHEN ((unicode_val_T) 0x00AD) + /* U+FFFD REPLACEMENT CHARACTER. Used when no Unicode mapping is * known for a byte in a codepage, or when invalid UTF-8 is received * from a terminal. After generating the character, ELinks then From 0c3a871a4b1fe342cd933036755b3d872ed62bf8 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Thu, 26 Apr 2007 07:12:28 +0300 Subject: [PATCH 003/133] Bug 879, set_hline: Discard U+00AD SOFT HYPHEN characters if UTF-8. If not UTF-8, then charsets.c has already discarded them. --- src/document/html/renderer.c | 38 +++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/document/html/renderer.c b/src/document/html/renderer.c index dfd7f625..44020319 100644 --- a/src/document/html/renderer.c +++ b/src/document/html/renderer.c @@ -406,6 +406,21 @@ set_hline(struct html_context *html_context, unsigned char *chars, int charslen, if (realloc_spaces(part, x + charslen)) return 0; + /* U+00AD SOFT HYPHEN characters in HTML documents are + * supposed to be displayed only if the word is broken at that + * point. ELinks currently does not use them, so it should + * not display them. If the input @chars is in UTF-8, then + * set_hline() discards the characters. If the input is in + * some other charset, then set_hline() does not know which + * byte that charset uses for U+00AD, so it cannot discard + * the characters; instead, the translation table used by + * convert_string() has already discarded the characters. + * + * Likewise, if the input @chars is in UTF-8, then it may + * contain U+00A0 NO-BREAK SPACE characters; but if the input + * is in some other charset, then the translation table + * has mapped those characters to NBSP_CHAR. */ + if (part->document) { /* Reallocate LINE(y).chars[] to large enough. The * last parameter of realloc_line is the index of the @@ -424,7 +439,7 @@ set_hline(struct html_context *html_context, unsigned char *chars, int charslen, if (orig_length < 0) /* error */ return 0; if (utf8) { - unsigned char *end = chars + charslen; + unsigned char *const end = chars + charslen; unicode_val_T data; if (part->document->buf_length) { @@ -459,7 +474,7 @@ set_hline(struct html_context *html_context, unsigned char *chars, int charslen, } } - for (; chars < end; x++) { + while (chars < end) { /* ELinks does not use NBSP_CHAR in UTF-8. */ data = utf8_to_unicode(&chars, end); @@ -473,7 +488,7 @@ set_hline(struct html_context *html_context, unsigned char *chars, int charslen, schar->attr = SCREEN_ATTR_FRAME; copy_screen_chars(&POS(x, y), schar, 1); schar->attr = attr; - part->char_width[x] = 0; + part->char_width[x++] = 0; continue; } else { unsigned char i; @@ -486,6 +501,8 @@ set_hline(struct html_context *html_context, unsigned char *chars, int charslen, } } else { good_char: + if (data == UCS_SOFT_HYPHEN) + continue; if (data == UCS_NO_BREAK_SPACE && html_context->options->wrap_nbsp) data = UCS_SPACE; @@ -502,8 +519,8 @@ good_char: schar->data = (unicode_val_T)data; } } - copy_screen_chars(&POS(x, y), schar, 1); - } + copy_screen_chars(&POS(x++, y), schar, 1); + } /* while chars < end */ } else { /* not UTF-8 */ for (; charslen > 0; charslen--, x++, chars++) { part->char_width[x] = 1; @@ -535,13 +552,15 @@ good_char: len = x - x2; } else { /* part->document == NULL */ if (utf8) { - unsigned char *end; + unsigned char *const end = chars + charslen; - for (end = chars + charslen; chars < end; x++) { + while (chars < end) { unicode_val_T data; - part->spaces[x] = (*chars == ' '); data = utf8_to_unicode(&chars, end); + if (data == UCS_SOFT_HYPHEN) + continue; + part->spaces[x] = (data == UCS_SPACE); part->char_width[x] = unicode_to_cell(data); if (part->char_width[x] == 2) { x++; @@ -552,7 +571,8 @@ good_char: /* this is at the end only */ return x - x2; } - } + x++; + } /* while chars < end */ len = x - x2; } else { /* not UTF-8 */ for (; charslen > 0; charslen--, x++, chars++) { From fa9567653d3453fe1b75c3bbf59fba7da099e687 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Thu, 26 Apr 2007 07:38:37 +0300 Subject: [PATCH 004/133] set_hline: Outdent some code. --- src/document/html/renderer.c | 39 +++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/document/html/renderer.c b/src/document/html/renderer.c index 44020319..b992bed5 100644 --- a/src/document/html/renderer.c +++ b/src/document/html/renderer.c @@ -499,25 +499,28 @@ set_hline(struct html_context *html_context, unsigned char *chars, int charslen, part->document->buf_length = i; break; } - } else { + /* not reached */ + } + good_char: - if (data == UCS_SOFT_HYPHEN) - continue; - if (data == UCS_NO_BREAK_SPACE - && html_context->options->wrap_nbsp) - data = UCS_SPACE; - part->spaces[x] = (data == UCS_SPACE); - if (unicode_to_cell(data) == 2) { - schar->data = (unicode_val_T)data; - part->char_width[x] = 2; - copy_screen_chars(&POS(x++, y), schar, 1); - schar->data = UCS_NO_CHAR; - part->spaces[x] = 0; - part->char_width[x] = 0; - } else { - part->char_width[x] = unicode_to_cell(data); - schar->data = (unicode_val_T)data; - } + if (data == UCS_SOFT_HYPHEN) + continue; + + if (data == UCS_NO_BREAK_SPACE + && html_context->options->wrap_nbsp) + data = UCS_SPACE; + part->spaces[x] = (data == UCS_SPACE); + + if (unicode_to_cell(data) == 2) { + schar->data = (unicode_val_T)data; + part->char_width[x] = 2; + copy_screen_chars(&POS(x++, y), schar, 1); + schar->data = UCS_NO_CHAR; + part->spaces[x] = 0; + part->char_width[x] = 0; + } else { + part->char_width[x] = unicode_to_cell(data); + schar->data = (unicode_val_T)data; } copy_screen_chars(&POS(x++, y), schar, 1); } /* while chars < end */ From 0b7a56f89af491466821a6831e2bb4484eb817b0 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Thu, 26 Apr 2007 07:48:11 +0300 Subject: [PATCH 005/133] Bug 947, set_hline: Respect wrap_nbsp also if !part->document. This does not yet fix bug 947 for the case where the document is UTF-8 and the terminal is ISO-8859-1. That will require changing charsets.c too, it seems. --- src/document/html/renderer.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/document/html/renderer.c b/src/document/html/renderer.c index b992bed5..a723b78e 100644 --- a/src/document/html/renderer.c +++ b/src/document/html/renderer.c @@ -563,7 +563,12 @@ good_char: data = utf8_to_unicode(&chars, end); if (data == UCS_SOFT_HYPHEN) continue; + + if (data == UCS_NO_BREAK_SPACE + && html_context->options->wrap_nbsp) + data = UCS_SPACE; part->spaces[x] = (data == UCS_SPACE); + part->char_width[x] = unicode_to_cell(data); if (part->char_width[x] == 2) { x++; @@ -579,7 +584,12 @@ good_char: len = x - x2; } else { /* not UTF-8 */ for (; charslen > 0; charslen--, x++, chars++) { - part->spaces[x] = (*chars == ' '); + unsigned char c = *chars; + + if (c == NBSP_CHAR + && html_context->options->wrap_nbsp) + c = ' '; + part->spaces[x] = (c == ' '); part->char_width[x] = 1; } } From da3c8c5ce24e365996087f8206b375548193422c Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Thu, 26 Apr 2007 21:39:46 +0300 Subject: [PATCH 006/133] Bugs 879, 928, 947: Specially map U+00A0 and U+00AD in translation tables. --- src/intl/charsets.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/intl/charsets.c b/src/intl/charsets.c index f65711a7..48d13f55 100644 --- a/src/intl/charsets.c +++ b/src/intl/charsets.c @@ -909,6 +909,10 @@ get_translation_table(int from, int to) if (is_cp_ptr_utf8(&codepages[from])) { int i; + /* Map U+00A0 and U+00AD the same way as u2cp() would. */ + add_utf8(table, UCS_NO_BREAK_SPACE, strings[NBSP_CHAR]); + add_utf8(table, UCS_SOFT_HYPHEN, ""); + for (i = 0x80; i <= 0xFF; i++) if (codepages[to].highhalf[i - 0x80] != 0xFFFF) add_utf8(table, From ce05aa1f374bb07d3b55487263ea9f21dcdc422e Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Thu, 26 Apr 2007 23:46:03 +0300 Subject: [PATCH 007/133] Bug 947, set_hline: Also recognize NBSP_CHAR #ifndef CONFIG_UTF8. --- src/document/html/renderer.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/document/html/renderer.c b/src/document/html/renderer.c index a723b78e..bafacf29 100644 --- a/src/document/html/renderer.c +++ b/src/document/html/renderer.c @@ -584,13 +584,12 @@ good_char: len = x - x2; } else { /* not UTF-8 */ for (; charslen > 0; charslen--, x++, chars++) { - unsigned char c = *chars; - - if (c == NBSP_CHAR - && html_context->options->wrap_nbsp) - c = ' '; - part->spaces[x] = (c == ' '); part->char_width[x] = 1; + if (*chars == NBSP_CHAR) { + part->spaces[x] = html_context->options->wrap_nbsp; + } else { + part->spaces[x] = (*chars == ' '); + } } } } /* end of part->document check */ @@ -633,7 +632,11 @@ set_hline(struct html_context *html_context, unsigned char *chars, int charslen, } } else { for (; charslen > 0; charslen--, x++, chars++) { - part->spaces[x] = (*chars == ' '); + if (*chars == NBSP_CHAR) { + part->spaces[x] = html_context->options->wrap_nbsp; + } else { + part->spaces[x] = (*chars == ' '); + } } } } From 65fbb904133c3738fc481f89a91661176297008c Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Thu, 26 Apr 2007 23:53:39 +0300 Subject: [PATCH 008/133] NEWS: mention bugs 928, 947 --- NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS b/NEWS index 8ecca51e..44e20dee 100644 --- a/NEWS +++ b/NEWS @@ -110,6 +110,9 @@ roughly in decreasing order of importance. - (enhancement) Add support for parsing space separated CSS class attribute values - (bugfix 387) Treat inside
...
as a newline. + - (bugfix 928) Properly display no-break spaces in a UTF-8 document + if the terminal uses some other charset. + - (bugfix 947) document.html.wrap_html also affects text in tables. * Changes in parsing and rendering of non-HTML content-types - (new feature 121) If a mailcap entry indicates copiousoutput, ELinks itself acts as a pager. From 69c185c34e2e0da279925276e3ca1b92dd01ca3d Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 29 Apr 2007 21:21:25 +0300 Subject: [PATCH 009/133] Document the charset of form_state.value for FC_TEXTAREA. --- src/viewer/text/form.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/viewer/text/form.h b/src/viewer/text/form.h index bd1d36e1..7d1eff6e 100644 --- a/src/viewer/text/form.h +++ b/src/viewer/text/form.h @@ -37,18 +37,19 @@ struct form_state { int position; enum form_type type; - /* For FC_TEXT, FC_PASSWORD, and FC_FILE, @value is the text - * string that the user can edit. The string is null-terminated; - * its length is not stored separately. The size of the buffer - * is not stored anywhere; extending the string always requires - * calling realloc(). The string is not normally allowed to grow - * past @form_control.maxlength bytes (not counting the null), - * but there may be ways to get longer strings. If CONFIG_UTF8 - * is defined and UTF-8 I/O is enabled for the terminal, then - * @value is in UTF-8; otherwise, @value is in the charset of the - * terminal, and the charset is assumed to be unibyte. (Thus, if - * you choose UTF-8 as the charset but disable UTF-8 I/O, you - * lose.) The charset of the document has no effect here. */ + /* For FC_TEXT, FC_PASSWORD, FC_FILE, and FC_TEXTAREA, @value + * is the text string that the user can edit. The string is + * null-terminated; its length is not stored separately. The + * size of the buffer is not stored anywhere; extending the + * string always requires calling realloc(). The string is + * not normally allowed to grow past @form_control.maxlength + * bytes (not counting the null), but there may be ways to get + * longer strings. If CONFIG_UTF8 is defined and UTF-8 I/O is + * enabled for the terminal, then @value is in UTF-8; + * otherwise, @value is in the charset of the terminal, and + * the charset is assumed to be unibyte. (Thus, if you choose + * UTF-8 as the charset but disable UTF-8 I/O, you lose.) + * The charset of the document has no effect here. */ unsigned char *value; /* For FC_TEXT, FC_PASSWORD, and FC_FILE, @state is the byte * position of the insertion point in @value. From 084d402c516c82c6e7edc79f975d381f37d83393 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Thu, 12 Oct 2006 09:56:00 +0200 Subject: [PATCH 010/133] Bug 816, html_special_form_control: Don't parse character entity references. --- src/document/html/renderer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/document/html/renderer.c b/src/document/html/renderer.c index bafacf29..844b4080 100644 --- a/src/document/html/renderer.c +++ b/src/document/html/renderer.c @@ -1816,7 +1816,7 @@ html_special_form_control(struct part *part, struct form_control *fc) fc->default_value, strlen(fc->default_value), part->document->options.cp, - CSM_QUERY, NULL, NULL, NULL); + CSM_FORM, NULL, NULL, NULL); if (dv) mem_free_set(&fc->default_value, dv); } From 487a0472640d99842c20b6d6df825a4b40d82327 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 29 Apr 2007 21:28:40 +0300 Subject: [PATCH 011/133] Document the meaning of document_options.cp. Miciah provided part of the text. --- src/document/options.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/document/options.h b/src/document/options.h index 11894d7d..d48a579b 100644 --- a/src/document/options.h +++ b/src/document/options.h @@ -22,6 +22,9 @@ struct active_link_options { * whether they satisfy the current state of the document options. */ struct document_options { enum color_mode color_mode; + /* cp is the codepage for which the document is being formatted; + * typically it is the codepage of a terminal. It is set in + * render_document_frames. */ int cp, assume_cp, hard_assume; int margin; int num_links_key; From 0df5b7fdf5f819f03f33b5eb972c4880b35904d1 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 29 Apr 2007 21:39:28 +0300 Subject: [PATCH 012/133] Apply form history to fs->value, not fc->default_value. I am going make fc->default_value use the charset of the document, and recoding the string from the form history to that might lose characters. This change also affects what ECMAScript sees in the defaultValue property. says it should represent the HTML "value" attribute, so changing it based on form history is not appropriate. --- src/viewer/text/form.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/viewer/text/form.c b/src/viewer/text/form.c index 01d517c7..13e737c3 100644 --- a/src/viewer/text/form.c +++ b/src/viewer/text/form.c @@ -160,9 +160,16 @@ init_form_state(struct form_control *fc, struct form_state *fs) switch (fc->type) { case FC_TEXT: case FC_PASSWORD: +#ifdef CONFIG_FORMHIST + fs->value = null_or_stracpy( + get_form_history_value( + fc->form->action, fc->name)); +#endif /* CONFIG_FORMHIST */ + /* fall through */ case FC_TEXTAREA: - fs->value = stracpy(fc->default_value); - fs->state = strlen(fc->default_value); + if (fs->value == NULL) + fs->value = stracpy(fc->default_value); + fs->state = fs->value ? strlen(fs->value) : 0; #ifdef CONFIG_UTF8 if (fc->type == FC_TEXTAREA) fs->state_cell = 0; @@ -577,18 +584,6 @@ draw_forms(struct terminal *term, struct document_view *doc_view) struct form_control *fc = get_link_form_control(l1); if (!fc) continue; -#ifdef CONFIG_FORMHIST - if (fc->type == FC_TEXT || fc->type == FC_PASSWORD) { - unsigned char *value; - - assert(fc->form); - value = get_form_history_value(fc->form->action, fc->name); - - if (value) - mem_free_set(&fc->default_value, - stracpy(value)); - } -#endif /* CONFIG_FORMHIST */ draw_form_entry(term, doc_view, l1); } while (l1++ < l2); From 5e83337d49ff77a59ec5d5904d6631abb027a49e Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 29 Apr 2007 22:01:13 +0300 Subject: [PATCH 013/133] Bug 784: Keep form_control.default_value in the document charset. Previously, html_special_form_control converted form_control.default_value to the terminal charset, and init_form_state then copied the value to form_state.value. However, when CONFIG_UTF8 is defined and UTF-8 I/O is enabled, form_state.value is supposed to be in UTF-8, rather than in the terminal charset. This mismatch could not be conveniently fixed in html_special_form_control because that does not know which terminal is being used and whether UTF-8 I/O is enabled there. Also, constructing a conversion table from the document charset to form_state.value could have ruined renderer_context.convert_table, because src/intl/charsets.c does not support multiple concurrent conversion tables. So instead, we now keep form_control.default_value in the document charset, and convert it in the viewer each time it is needed. Because the result of the conversion is kept in form_state.value between incremental renderings, this shouldn't even slow things down too much. I am not implementing the proper charset conversions for the DOM defaultValue property yet, because the current code doesn't have them for other string properties either, and bug 805 is already open for that. --- src/document/forms.h | 4 ++++ src/document/html/renderer.c | 12 ---------- src/ecmascript/see/form.c | 1 + src/ecmascript/spidermonkey/form.c | 1 + src/viewer/text/form.c | 37 +++++++++++++++++++++++++----- 5 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/document/forms.h b/src/document/forms.h index 55934afe..17449892 100644 --- a/src/document/forms.h +++ b/src/document/forms.h @@ -86,6 +86,10 @@ struct form_control { unsigned char *id; /* used by scripts */ unsigned char *name; unsigned char *alt; + /* For FC_TEXT, FC_PASSWORD, and FC_TEXTAREA: @default_value + * is in the charset of the document. + * + * For FC_FILE: The parser does not set @default_value. */ unsigned char *default_value; int default_state; int size; diff --git a/src/document/html/renderer.c b/src/document/html/renderer.c index 844b4080..cabf9aa3 100644 --- a/src/document/html/renderer.c +++ b/src/document/html/renderer.c @@ -1809,18 +1809,6 @@ html_special_form_control(struct part *part, struct form_control *fc) fc->g_ctrl_num = renderer_context.g_ctrl_num++; - /* We don't want to recode hidden fields. */ - if (fc->type == FC_TEXT || fc->type == FC_PASSWORD || - fc->type == FC_TEXTAREA) { - unsigned char *dv = convert_string(renderer_context.convert_table, - fc->default_value, - strlen(fc->default_value), - part->document->options.cp, - CSM_FORM, NULL, NULL, NULL); - - if (dv) mem_free_set(&fc->default_value, dv); - } - if (list_empty(part->document->forms)) { /* No forms encountered yet, that means a homeless form * control. Generate a dummy form for those Flying diff --git a/src/ecmascript/see/form.c b/src/ecmascript/see/form.c index 9b2f5b9f..abdb6317 100644 --- a/src/ecmascript/see/form.c +++ b/src/ecmascript/see/form.c @@ -200,6 +200,7 @@ input_get(struct SEE_interpreter *interp, struct SEE_object *o, } else if (p == s_defaultChecked) { SEE_SET_BOOLEAN(res, fc->default_state); } else if (p == s_defaultValue) { + /* FIXME (bug 805): convert from the charset of the document */ str = string_to_SEE_string(interp, fc->default_value); SEE_SET_STRING(res, str); } else if (p == s_disabled) { diff --git a/src/ecmascript/spidermonkey/form.c b/src/ecmascript/spidermonkey/form.c index 9436e1b9..2701f147 100644 --- a/src/ecmascript/spidermonkey/form.c +++ b/src/ecmascript/spidermonkey/form.c @@ -206,6 +206,7 @@ input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) boolean_to_jsval(ctx, vp, fc->default_state); break; case JSP_INPUT_DEFAULT_VALUE: + /* FIXME (bug 805): convert from the charset of the document */ string_to_jsval(ctx, vp, fc->default_value); break; case JSP_INPUT_DISABLED: diff --git a/src/viewer/text/form.c b/src/viewer/text/form.c index 13e737c3..3b35391a 100644 --- a/src/viewer/text/form.c +++ b/src/viewer/text/form.c @@ -150,11 +150,24 @@ selected_item(struct terminal *term, void *item_, void *ses_) } static void -init_form_state(struct form_control *fc, struct form_state *fs) +init_form_state(struct document_view *doc_view, + struct form_control *fc, struct form_state *fs) { + struct terminal *term; + int doc_cp, viewer_cp; + assert(fc && fs); if_assert_failed return; + doc_cp = doc_view->document->cp; + term = doc_view->session->tab->term; +#ifdef CONFIG_UTF8 + if (term->utf8) + viewer_cp = get_cp_index("UTF-8"); + else +#endif + viewer_cp = get_opt_codepage_tree(term->spec, "charset"); + mem_free_set(&fs->value, NULL); switch (fc->type) { @@ -167,8 +180,14 @@ init_form_state(struct form_control *fc, struct form_state *fs) #endif /* CONFIG_FORMHIST */ /* fall through */ case FC_TEXTAREA: - if (fs->value == NULL) - fs->value = stracpy(fc->default_value); + if (fs->value == NULL) { + fs->value = convert_string( + get_translation_table(doc_cp, viewer_cp), + fc->default_value, + strlen(fc->default_value), + viewer_cp, CSM_FORM, + &fs->state, NULL, NULL); + } fs->state = fs->value ? strlen(fs->value) : 0; #ifdef CONFIG_UTF8 if (fc->type == FC_TEXTAREA) @@ -182,7 +201,12 @@ init_form_state(struct form_control *fc, struct form_state *fs) fs->vpos = 0; break; case FC_SELECT: - fs->value = stracpy(fc->default_value); + fs->value = convert_string( + get_translation_table(doc_cp, viewer_cp), + fc->default_value, + strlen(fc->default_value), + viewer_cp, CSM_FORM, + &fs->state, NULL, NULL); fs->state = fc->default_state; fixup_select_state(fc, fs); break; @@ -195,6 +219,7 @@ init_form_state(struct form_control *fc, struct form_state *fs) case FC_RESET: case FC_BUTTON: case FC_HIDDEN: + /* We don't want to recode hidden fields. */ fs->value = stracpy(fc->default_value); break; } @@ -236,7 +261,7 @@ find_form_state(struct document_view *doc_view, struct form_control *fc) fs->g_ctrl_num = fc->g_ctrl_num; fs->position = fc->position; fs->type = fc->type; - init_form_state(fc, fs); + init_form_state(doc_view, fc, fs); return fs; } @@ -1096,7 +1121,7 @@ do_reset_form(struct document_view *doc_view, struct form *form) foreach (fc, form->items) { struct form_state *fs = find_form_state(doc_view, fc); - if (fs) init_form_state(fc, fs); + if (fs) init_form_state(doc_view, fc, fs); } } From 8b010bb27d9a2695e644bbd2353933993f26de31 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 29 Apr 2007 23:33:23 +0300 Subject: [PATCH 014/133] NEWS: mention bug 816 --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index 44e20dee..07dc6ece 100644 --- a/NEWS +++ b/NEWS @@ -113,6 +113,7 @@ roughly in decreasing order of importance. - (bugfix 928) Properly display no-break spaces in a UTF-8 document if the terminal uses some other charset. - (bugfix 947) document.html.wrap_html also affects text in tables. + - (bugfix 816) Convert entity references in input/@value only once. * Changes in parsing and rendering of non-HTML content-types - (new feature 121) If a mailcap entry indicates copiousoutput, ELinks itself acts as a pager. From bafe47508d37cb841f9ff4e1abb97d1e155cbd24 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Mon, 30 Apr 2007 00:56:39 +0300 Subject: [PATCH 015/133] Bug 784: Add html_context->doc_cp and parse attributes with it. options->cp is still used for this in seven places where html_context is not easily available. Those should eventually be corrected too, but I'm checking this change in already because it's better than what we had before. --- src/document/css/apply.c | 6 +-- src/document/html/internal.h | 4 ++ src/document/html/parser.c | 19 +++++++-- src/document/html/parser/forms.c | 68 +++++++++++++++--------------- src/document/html/parser/general.c | 34 +++++++-------- src/document/html/parser/link.c | 56 ++++++++++++------------ src/document/html/parser/parse.c | 12 ++++-- src/document/html/parser/stack.c | 2 +- src/document/html/parser/table.c | 42 +++++++++--------- src/document/html/renderer.c | 1 + 10 files changed, 131 insertions(+), 113 deletions(-) diff --git a/src/document/css/apply.c b/src/document/css/apply.c index b4400edd..f39e84a0 100644 --- a/src/document/css/apply.c +++ b/src/document/css/apply.c @@ -186,7 +186,7 @@ examine_element(struct html_context *html_context, struct css_selector *base, process_found_selector(selector, CST_PSEUDO, base); } - code = get_attr_val(element->options, "class", html_context->options->cp); + code = get_attr_val(element->options, "class", html_context->doc_cp); if (code && seltype <= CST_CLASS) { unsigned char *class = code; @@ -203,7 +203,7 @@ examine_element(struct html_context *html_context, struct css_selector *base, } mem_free_if(code); - code = get_attr_val(element->options, "id", html_context->options->cp); + code = get_attr_val(element->options, "id", html_context->doc_cp); if (code && seltype <= CST_ID) { selector = find_css_selector(selectors, CST_ID, rel, code, -1); process_found_selector(selector, CST_ID, base); @@ -240,7 +240,7 @@ get_css_selector_for_element(struct html_context *html_context, DBG("Element %.*s applied.", element->namelen, element->name); #endif - code = get_attr_val(element->options, "style", html_context->options->cp); + code = get_attr_val(element->options, "style", html_context->doc_cp); if (code) { struct css_selector *stylesel; struct scanner scanner; diff --git a/src/document/html/internal.h b/src/document/html/internal.h index 89a56df1..419da38f 100644 --- a/src/document/html/internal.h +++ b/src/document/html/internal.h @@ -51,6 +51,10 @@ struct html_context { struct document_options *options; + /* doc_cp is the charset of the document, i.e. part->document->cp. + * It is copied here because part->document is NULL sometimes. */ + int doc_cp; + /* For: * html/parser/parse.c * html/parser/stack.c diff --git a/src/document/html/parser.c b/src/document/html/parser.c index ca25f8ed..8732de7e 100644 --- a/src/document/html/parser.c +++ b/src/document/html/parser.c @@ -57,7 +57,7 @@ get_color(struct html_context *html_context, unsigned char *a, if (!use_document_fg_colors(html_context->options)) return -1; - at = get_attr_val(a, c, html_context->options->cp); + at = get_attr_val(a, c, html_context->doc_cp); if (!at) return -1; r = decode_color(at, strlen(at), rgb); @@ -78,6 +78,8 @@ get_bgcolor(struct html_context *html_context, unsigned char *a, color_T *rgb) unsigned char * get_target(struct document_options *options, unsigned char *a) { + /* FIXME (bug 784): options->cp is the terminal charset; + * should use the document charset instead. */ unsigned char *v = get_attr_val(a, "target", options->cp); if (!v) return NULL; @@ -154,7 +156,7 @@ set_fragment_identifier(struct html_context *html_context, { unsigned char *id_attr; - id_attr = get_attr_val(attr_name, attr, html_context->options->cp); + id_attr = get_attr_val(attr_name, attr, html_context->doc_cp); if (id_attr) { html_context->special_f(html_context, SP_TAG, id_attr); @@ -235,7 +237,7 @@ html_focusable(struct html_context *html_context, unsigned char *a) if (!a) return; options = html_context->options; - cp = options->cp; + cp = html_context->doc_cp; accesskey = get_attr_val(a, "accesskey", cp); if (accesskey) { @@ -243,7 +245,7 @@ html_focusable(struct html_context *html_context, unsigned char *a) mem_free(accesskey); } - tabindex = get_num(a, "tabindex", options->cp); + tabindex = get_num(a, "tabindex", html_context->doc_cp); if (0 < tabindex && tabindex < 32767) { format.tabindex = (tabindex & 0x7fff) << 16; } @@ -450,6 +452,8 @@ look_for_map(unsigned char **pos, unsigned char *eof, struct uri *uri, if (strlcasecmp(name, namelen, "MAP", 3)) return 1; if (uri && uri->fragment) { + /* FIXME (bug 784): options->cp is the terminal charset; + * should use the document charset instead. */ al = get_attr_val(attr, "name", options->cp); if (!al) return 1; @@ -548,6 +552,8 @@ look_for_link(unsigned char **pos, unsigned char *eof, struct menu_item **menu, if (*pos >= eof) return 0; } else if (!strlcasecmp(name, namelen, "AREA", 4)) { + /* FIXME (bug 784): options->cp is the terminal charset; + * should use the document charset instead. */ unsigned char *alt = get_attr_val(attr, "alt", options->cp); if (alt) { @@ -582,6 +588,8 @@ look_for_link(unsigned char **pos, unsigned char *eof, struct menu_item **menu, return 1; } + /* FIXME (bug 784): options->cp is the terminal charset; + * should use the document charset instead. */ href = get_url_val(attr, "href", options->cp); if (!href) { mem_free_if(label); @@ -741,6 +749,9 @@ done_html_parser_state(struct html_context *html_context, } +/* This function does not set html_context.doc_cp = document.cp, + * because it does not know the document, and because the codepage has + * not even been decided when it is called. */ struct html_context * init_html_parser(struct uri *uri, struct document_options *options, unsigned char *start, unsigned char *end, diff --git a/src/document/html/parser/forms.c b/src/document/html/parser/forms.c index 51f975d1..7bfff63f 100644 --- a/src/document/html/parser/forms.c +++ b/src/document/html/parser/forms.c @@ -50,13 +50,13 @@ html_form(struct html_context *html_context, unsigned char *a, form->method = FORM_METHOD_GET; form->form_num = a - html_context->startf; - al = get_attr_val(a, "method", html_context->options->cp); + al = get_attr_val(a, "method", html_context->doc_cp); if (al) { if (!strcasecmp(al, "post")) { unsigned char *enctype; enctype = get_attr_val(a, "enctype", - html_context->options->cp); + html_context->doc_cp); form->method = FORM_METHOD_POST; if (enctype) { @@ -69,11 +69,11 @@ html_form(struct html_context *html_context, unsigned char *a, } mem_free(al); } - form->onsubmit = get_attr_val(a, "onsubmit", html_context->options->cp); - al = get_attr_val(a, "name", html_context->options->cp); + form->onsubmit = get_attr_val(a, "onsubmit", html_context->doc_cp); + al = get_attr_val(a, "name", html_context->doc_cp); if (al) form->name = al; - al = get_attr_val(a, "action", html_context->options->cp); + al = get_attr_val(a, "action", html_context->doc_cp); /* The HTML specification at * http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.3 states * that the behavior of an empty action attribute should be undefined. @@ -114,10 +114,10 @@ html_form(struct html_context *html_context, unsigned char *a, static int get_form_mode(struct html_context *html_context, unsigned char *attr) { - if (has_attr(attr, "disabled", html_context->options->cp)) + if (has_attr(attr, "disabled", html_context->doc_cp)) return FORM_MODE_DISABLED; - if (has_attr(attr, "readonly", html_context->options->cp)) + if (has_attr(attr, "readonly", html_context->doc_cp)) return FORM_MODE_READONLY; return FORM_MODE_NORMAL; @@ -146,8 +146,7 @@ html_button(struct html_context *html_context, unsigned char *a, unsigned char *al; struct form_control *fc; enum form_type type = FC_SUBMIT; - int cp = (html_context->part && html_context->part->document) ? - html_context->part->document->cp : html_context->options->cp; + int cp = html_context->doc_cp; html_focusable(html_context, a); @@ -197,7 +196,7 @@ html_input_format(struct html_context *html_context, unsigned char *a, html_focusable(html_context, a); format.form = fc; if (format.title) mem_free(format.title); - format.title = get_attr_val(a, "title", html_context->options->cp); + format.title = get_attr_val(a, "title", html_context->doc_cp); switch (fc->type) { case FC_TEXT: case FC_PASSWORD: @@ -223,10 +222,10 @@ html_input_format(struct html_context *html_context, unsigned char *a, unsigned char *al; mem_free_set(&format.image, NULL); - al = get_url_val(a, "src", html_context->options->cp); + al = get_url_val(a, "src", html_context->doc_cp); if (!al) al = get_url_val(a, "dynsrc", - html_context->options->cp); + html_context->doc_cp); if (al) { format.image = join_urls(html_context->base_href, al); mem_free(al); @@ -267,8 +266,7 @@ html_input(struct html_context *html_context, unsigned char *a, { unsigned char *al; struct form_control *fc; - int cp = (html_context->part && html_context->part->document) ? - html_context->part->document->cp : html_context->options->cp; + int cp = html_context->doc_cp; fc = init_form_control(FC_TEXT, a, html_context); if (!fc) return; @@ -421,18 +419,18 @@ abort: if (!closing_tag) { unsigned char *value, *label; - if (has_attr(t_attr, "disabled", html_context->options->cp)) + if (has_attr(t_attr, "disabled", html_context->doc_cp)) goto see; if (preselect == -1 - && has_attr(t_attr, "selected", html_context->options->cp)) + && has_attr(t_attr, "selected", html_context->doc_cp)) preselect = order; - value = get_attr_val(t_attr, "value", html_context->options->cp); + value = get_attr_val(t_attr, "value", html_context->doc_cp); if (!mem_align_alloc(&values, order, order + 1, 0xFF)) goto abort; values[order++] = value; - label = get_attr_val(t_attr, "label", html_context->options->cp); + label = get_attr_val(t_attr, "label", html_context->doc_cp); if (label) new_menu_item(&lnk_menu, label, order - 1, 0); if (!value || !label) { init_string(&lbl); @@ -452,7 +450,7 @@ abort: if (!closing_tag) { unsigned char *label; - label = get_attr_val(t_attr, "label", html_context->options->cp); + label = get_attr_val(t_attr, "label", html_context->doc_cp); if (!label) { label = stracpy(""); @@ -479,8 +477,8 @@ end_parse: goto abort; } - fc->id = get_attr_val(attr, "id", html_context->options->cp); - fc->name = get_attr_val(attr, "name", html_context->options->cp); + fc->id = get_attr_val(attr, "id", html_context->doc_cp); + fc->name = get_attr_val(attr, "name", html_context->doc_cp); fc->default_state = preselect < 0 ? 0 : preselect; fc->default_value = order ? stracpy(values[fc->default_state]) : stracpy(""); fc->nvalues = order; @@ -520,13 +518,13 @@ do_html_select_multiple(struct html_context *html_context, unsigned char *a, unsigned char *html, unsigned char *eof, unsigned char **end) { - unsigned char *al = get_attr_val(a, "name", html_context->options->cp); + unsigned char *al = get_attr_val(a, "name", html_context->doc_cp); if (!al) return; html_focusable(html_context, a); html_top->type = ELEMENT_DONT_KILL; mem_free_set(&format.select, al); - format.select_disabled = has_attr(a, "disabled", html_context->options->cp) + format.select_disabled = has_attr(a, "disabled", html_context->doc_cp) ? FORM_MODE_DISABLED : FORM_MODE_NORMAL; } @@ -535,7 +533,7 @@ void html_select(struct html_context *html_context, unsigned char *a, unsigned char *html, unsigned char *eof, unsigned char **end) { - if (has_attr(a, "multiple", html_context->options->cp)) + if (has_attr(a, "multiple", html_context->doc_cp)) do_html_select_multiple(html_context, a, html, eof, end); else do_html_select(a, html, eof, end, html_context); @@ -551,7 +549,7 @@ html_option(struct html_context *html_context, unsigned char *a, if (!format.select) return; - val = get_attr_val(a, "value", html_context->options->cp); + val = get_attr_val(a, "value", html_context->doc_cp); if (!val) { struct string str; unsigned char *p, *r; @@ -602,11 +600,11 @@ end_parse: return; } - fc->id = get_attr_val(a, "id", html_context->options->cp); + fc->id = get_attr_val(a, "id", html_context->doc_cp); fc->name = null_or_stracpy(format.select); fc->default_value = val; - fc->default_state = has_attr(a, "selected", html_context->options->cp); - fc->mode = has_attr(a, "disabled", html_context->options->cp) + fc->default_state = has_attr(a, "selected", html_context->doc_cp); + fc->mode = has_attr(a, "disabled", html_context->doc_cp) ? FORM_MODE_DISABLED : format.select_disabled; @@ -648,8 +646,8 @@ pp: fc = init_form_control(FC_TEXTAREA, attr, html_context); if (!fc) return; - fc->id = get_attr_val(attr, "id", html_context->options->cp); - fc->name = get_attr_val(attr, "name", html_context->options->cp); + fc->id = get_attr_val(attr, "id", html_context->doc_cp); + fc->name = get_attr_val(attr, "name", html_context->doc_cp); fc->default_value = memacpy(html, p - html); for (p = fc->default_value; p && p[0]; p++) { /* FIXME: We don't cope well with entities here. Bugzilla uses @@ -666,7 +664,7 @@ pp: } } - cols = get_num(attr, "cols", html_context->options->cp); + cols = get_num(attr, "cols", html_context->doc_cp); if (cols <= 0) cols = html_context->options->default_form_input_size; cols++; /* Add 1 column, other browsers may have different @@ -675,14 +673,14 @@ pp: cols = html_context->options->box.width; fc->cols = cols; - rows = get_num(attr, "rows", html_context->options->cp); + rows = get_num(attr, "rows", html_context->doc_cp); if (rows <= 0) rows = 1; if (rows > html_context->options->box.height) rows = html_context->options->box.height; fc->rows = rows; html_context->options->needs_height = 1; - wrap_attr = get_attr_val(attr, "wrap", html_context->options->cp); + wrap_attr = get_attr_val(attr, "wrap", html_context->doc_cp); if (wrap_attr) { if (!strcasecmp(wrap_attr, "hard") || !strcasecmp(wrap_attr, "physical")) { @@ -696,14 +694,14 @@ pp: } mem_free(wrap_attr); - } else if (has_attr(attr, "nowrap", html_context->options->cp)) { + } else if (has_attr(attr, "nowrap", html_context->doc_cp)) { fc->wrap = FORM_WRAP_NONE; } else { fc->wrap = FORM_WRAP_SOFT; } - fc->maxlength = get_num(attr, "maxlength", html_context->options->cp); + fc->maxlength = get_num(attr, "maxlength", html_context->doc_cp); if (fc->maxlength == -1) fc->maxlength = INT_MAX; if (rows > 1) ln_break(html_context, 1); diff --git a/src/document/html/parser/general.c b/src/document/html/parser/general.c index 33fe08c0..0dbff5e9 100644 --- a/src/document/html/parser/general.c +++ b/src/document/html/parser/general.c @@ -136,7 +136,7 @@ void html_font(struct html_context *html_context, unsigned char *a, unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5) { - unsigned char *al = get_attr_val(a, "size", html_context->options->cp); + unsigned char *al = get_attr_val(a, "size", html_context->doc_cp); if (al) { int p = 0; @@ -223,7 +223,7 @@ html_script(struct html_context *html_context, unsigned char *a, /* Ref: * http://www.ietf.org/internet-drafts/draft-hoehrmann-script-types-03.txt */ - type = get_attr_val(a, "type", html_context->options->cp); + type = get_attr_val(a, "type", html_context->doc_cp); if (type) { unsigned char *pos = type; @@ -265,7 +265,7 @@ not_processed: * language attribute can be JavaScript with optional version digits * postfixed (like: ``JavaScript1.1''). * That attribute is deprecated in favor of type by HTML 4.01 */ - language = get_attr_val(a, "language", html_context->options->cp); + language = get_attr_val(a, "language", html_context->doc_cp); if (language) { int languagelen = strlen(language); @@ -280,7 +280,7 @@ not_processed: } if (html_context->part->document - && (src = get_attr_val(a, "src", html_context->options->cp))) { + && (src = get_attr_val(a, "src", html_context->doc_cp))) { /* External reference. */ unsigned char *import_url; @@ -479,7 +479,7 @@ void html_linebrk(struct html_context *html_context, unsigned char *a, unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5) { - unsigned char *al = get_attr_val(a, "align", html_context->options->cp); + unsigned char *al = get_attr_val(a, "align", html_context->doc_cp); if (al) { if (!strcasecmp(al, "left")) par_format.align = ALIGN_LEFT; @@ -632,7 +632,7 @@ html_hr(struct html_context *html_context, unsigned char *a, { int i/* = par_format.width - 10*/; unsigned char r = (unsigned char) BORDER_DHLINE; - int q = get_num(a, "size", html_context->options->cp); + int q = get_num(a, "size", html_context->doc_cp); if (q >= 0 && q < 2) r = (unsigned char) BORDER_SHLINE; html_stack_dup(html_context, ELEMENT_KILLABLE); @@ -714,7 +714,7 @@ html_base(struct html_context *html_context, unsigned char *a, { unsigned char *al; - al = get_url_val(a, "href", html_context->options->cp); + al = get_url_val(a, "href", html_context->doc_cp); if (al) { unsigned char *base = join_urls(html_context->base_href, al); struct uri *uri = base ? get_uri(base, 0) : NULL; @@ -743,7 +743,7 @@ html_ul(struct html_context *html_context, unsigned char *a, par_format.list_number = 0; par_format.flags = P_STAR; - al = get_attr_val(a, "type", html_context->options->cp); + al = get_attr_val(a, "type", html_context->doc_cp); if (al) { if (!strcasecmp(al, "disc") || !strcasecmp(al, "circle")) par_format.flags = P_O; @@ -767,12 +767,12 @@ html_ol(struct html_context *html_context, unsigned char *a, int st; par_format.list_level++; - st = get_num(a, "start", html_context->options->cp); + st = get_num(a, "start", html_context->doc_cp); if (st == -1) st = 1; par_format.list_number = st; par_format.flags = P_NUMBER; - al = get_attr_val(a, "type", html_context->options->cp); + al = get_attr_val(a, "type", html_context->doc_cp); if (al) { if (*al && !al[1]) { if (*al == '1') par_format.flags = P_NUMBER; @@ -875,7 +875,7 @@ html_li(struct html_context *html_context, unsigned char *a, unsigned char n[32]; int nlen; int t = par_format.flags & P_LISTMASK; - int s = get_num(a, "value", html_context->options->cp); + int s = get_num(a, "value", html_context->doc_cp); if (s != -1) par_format.list_number = s; @@ -932,7 +932,7 @@ html_dl(struct html_context *html_context, unsigned char *a, unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5) { par_format.flags &= ~P_COMPACT; - if (has_attr(a, "compact", html_context->options->cp)) + if (has_attr(a, "compact", html_context->doc_cp)) par_format.flags |= P_COMPACT; if (par_format.list_level) par_format.leftmargin += 5; par_format.list_level++; @@ -954,7 +954,7 @@ html_dt(struct html_context *html_context, unsigned char *a, par_format.align = ALIGN_LEFT; par_format.leftmargin = par_format.dd_margin; if (!(par_format.flags & P_COMPACT) - && !has_attr(a, "compact", html_context->options->cp)) + && !has_attr(a, "compact", html_context->doc_cp)) ln_break(html_context, 2); } @@ -995,7 +995,7 @@ html_frame(struct html_context *html_context, unsigned char *a, { unsigned char *name, *src, *url; - src = get_url_val(a, "src", html_context->options->cp); + src = get_url_val(a, "src", html_context->doc_cp); if (!src) { url = stracpy("about:blank"); } else { @@ -1004,7 +1004,7 @@ html_frame(struct html_context *html_context, unsigned char *a, } if (!url) return; - name = get_attr_val(a, "name", html_context->options->cp); + name = get_attr_val(a, "name", html_context->doc_cp); if (!name) { name = stracpy(url); } else if (!name[0]) { @@ -1048,13 +1048,13 @@ html_frameset(struct html_context *html_context, unsigned char *a, || !html_context->special_f(html_context, SP_USED, NULL)) return; - cols = get_attr_val(a, "cols", html_context->options->cp); + cols = get_attr_val(a, "cols", html_context->doc_cp); if (!cols) { cols = stracpy("100%"); if (!cols) return; } - rows = get_attr_val(a, "rows", html_context->options->cp); + rows = get_attr_val(a, "rows", html_context->doc_cp); if (!rows) { rows = stracpy("100%"); if (!rows) { diff --git a/src/document/html/parser/link.c b/src/document/html/parser/link.c index 1c7911ff..1b774c2a 100644 --- a/src/document/html/parser/link.c +++ b/src/document/html/parser/link.c @@ -45,7 +45,7 @@ html_a(struct html_context *html_context, unsigned char *a, { unsigned char *href; - href = get_url_val(a, "href", html_context->options->cp); + href = get_url_val(a, "href", html_context->doc_cp); if (href) { unsigned char *target; @@ -84,7 +84,7 @@ html_a(struct html_context *html_context, unsigned char *a, } mem_free_set(&format.title, - get_attr_val(a, "title", html_context->options->cp)); + get_attr_val(a, "title", html_context->doc_cp)); html_focusable(html_context, a); @@ -215,8 +215,6 @@ html_img_do(unsigned char *a, unsigned char *object_src, unsigned char *usemap_attr; struct document_options *options = html_context->options; int display_style = options->image_link.display_style; - int cp = (html_context->part && html_context->part->document) ? - html_context->part->document->cp : html_context->options->cp; /* Note about display_style: * 0 means always display IMG @@ -224,7 +222,7 @@ html_img_do(unsigned char *a, unsigned char *object_src, * 2 means display alt/title attribute if possible, IMG if not * 3 means display alt/title attribute if possible, filename if not */ - usemap_attr = get_attr_val(a, "usemap", options->cp); + usemap_attr = get_attr_val(a, "usemap", html_context->doc_cp); if (usemap_attr) { unsigned char *joined_urls = join_urls(html_context->base_href, usemap_attr); @@ -245,13 +243,13 @@ html_img_do(unsigned char *a, unsigned char *object_src, } ismap = format.link - && has_attr(a, "ismap", options->cp) + && has_attr(a, "ismap", html_context->doc_cp) && !usemap; if (display_style == 2 || display_style == 3) { - label = get_attr_val(a, "alt", cp); + label = get_attr_val(a, "alt", html_context->doc_cp); if (!label) - label = get_attr_val(a, "title", options->cp); + label = get_attr_val(a, "title", html_context->doc_cp); /* Little hack to preserve rendering of [ ], in directories listing, * but we still want to drop extra spaces in alt or title attribute @@ -260,8 +258,8 @@ html_img_do(unsigned char *a, unsigned char *object_src, } src = null_or_stracpy(object_src); - if (!src) src = get_url_val(a, "src", options->cp); - if (!src) src = get_url_val(a, "dynsrc", options->cp); + if (!src) src = get_url_val(a, "src", html_context->doc_cp); + if (!src) src = get_url_val(a, "dynsrc", html_context->doc_cp); /* If we have no label yet (no title or alt), so * just use default ones, or image filename. */ @@ -322,7 +320,7 @@ html_img_do(unsigned char *a, unsigned char *object_src, format.image = join_urls(html_context->base_href, src); } - format.title = get_attr_val(a, "title", options->cp); + format.title = get_attr_val(a, "title", html_context->doc_cp); if (ismap) { unsigned char *new_link; @@ -382,10 +380,10 @@ html_applet(struct html_context *html_context, unsigned char *a, { unsigned char *code, *alt; - code = get_url_val(a, "code", html_context->options->cp); + code = get_url_val(a, "code", html_context->doc_cp); if (!code) return; - alt = get_attr_val(a, "alt", html_context->options->cp); + alt = get_attr_val(a, "alt", html_context->doc_cp); html_focusable(html_context, a); @@ -408,11 +406,11 @@ html_iframe_do(unsigned char *a, unsigned char *object_src, unsigned char *name, *url = NULL; url = null_or_stracpy(object_src); - if (!url) url = get_url_val(a, "src", html_context->options->cp); + if (!url) url = get_url_val(a, "src", html_context->doc_cp); if (!url) return; - name = get_attr_val(a, "name", html_context->options->cp); - if (!name) name = get_attr_val(a, "id", html_context->options->cp); + name = get_attr_val(a, "name", html_context->doc_cp); + if (!name) name = get_attr_val(a, "id", html_context->doc_cp); if (!name) name = stracpy(""); if (!name) { mem_free(url); @@ -450,11 +448,11 @@ html_object(struct html_context *html_context, unsigned char *a, * this, which is anyway in the spirit of element, unifying * and