diff options
author | Thomas E. Dickey <dickey@invisible-island.net> | 2009-06-07 19:32:16 -0400 |
---|---|---|
committer | Thomas E. Dickey <dickey@invisible-island.net> | 2009-06-07 19:32:16 -0400 |
commit | 5101937aad7336c927af766909a0c794f198c59d (patch) | |
tree | e2c924b6a21dffcdfdb38d74287c2783bfc5ce88 /src/HTML.c | |
parent | 96214a47b6745616055c91df4353709bea8e22bb (diff) | |
download | lynx-snapshots-5101937aad7336c927af766909a0c794f198c59d.tar.gz |
snapshot of project "lynx", label v2-8-7pre_5b
Diffstat (limited to 'src/HTML.c')
-rw-r--r-- | src/HTML.c | 263 |
1 files changed, 196 insertions, 67 deletions
diff --git a/src/HTML.c b/src/HTML.c index eaca6ad7..f34670ef 100644 --- a/src/HTML.c +++ b/src/HTML.c @@ -1,5 +1,5 @@ /* - * $LynxId: HTML.c,v 1.126 2009/05/29 00:24:15 tom Exp $ + * $LynxId: HTML.c,v 1.128 2009/06/07 19:05:55 tom Exp $ * * Structured stream to Rich hypertext converter * ============================================ @@ -46,6 +46,7 @@ #include <LYMap.h> #include <LYList.h> #include <LYBookmark.h> +#include <LYHistory.h> #ifdef VMS #include <LYCurses.h> @@ -214,14 +215,56 @@ static void change_paragraph_style(HTStructured * me, HTStyle *style) me->in_word = NO; } +/* + * Return true if we should write a message (to LYNXMESSAGES, or the trace + * file) telling about some bad HTML that we've found. + */ BOOL LYBadHTML(HTStructured * me) { - if (!TRACE && !me->inBadHTML) { - HTUserMsg(BAD_HTML_USE_TRACE); - me->inBadHTML = TRUE; - return FALSE; + BOOL code = FALSE; + + switch ((enumBadHtml) cfg_bad_html) { + case BAD_HTML_IGNORE: + break; + case BAD_HTML_TRACE: + code = TRUE; + break; + case BAD_HTML_MESSAGE: + code = TRUE; + break; + case BAD_HTML_WARN: + /* + * If we're already tracing, do not add a warning. + */ + if (!TRACE && !me->inBadHTML) { + HTUserMsg(BAD_HTML_USE_TRACE); + me->inBadHTML = TRUE; + } + code = TRACE; + break; + } + return code; +} + +/* + * Handle the formatted message. + */ +void LYShowBadHTML(const char *message) +{ + switch ((enumBadHtml) cfg_bad_html) { + case BAD_HTML_IGNORE: + break; + case BAD_HTML_TRACE: + CTRACE((tfp, "%s", message)); + break; + case BAD_HTML_MESSAGE: + CTRACE((tfp, "%s", message)); + LYstore_message(message); + break; + case BAD_HTML_WARN: + CTRACE((tfp, "%s", message)); + break; } - return TRUE; } /*_________________________________________________________________________ @@ -4572,8 +4615,13 @@ static int HTML_start_element(HTStructured * me, int element_number, * Check for an unclosed TEXTAREA. */ if (me->inTEXTAREA) { - if (LYBadHTML(me)) - CTRACE((tfp, "Bad HTML: Missing TEXTAREA end tag.\n")); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, "Bad HTML: Missing TEXTAREA end tag.\n"); + LYShowBadHTML(msg); + FREE(msg); + } } /* @@ -5028,9 +5076,14 @@ static int HTML_start_element(HTStructured * me, int element_number, * Check for an already open SELECT block. - FM */ if (me->inSELECT) { - if (LYBadHTML(me)) - CTRACE((tfp, - "Bad HTML: SELECT start tag in SELECT element. Faking SELECT end tag. *****\n")); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, + "Bad HTML: SELECT start tag in SELECT element. Faking SELECT end tag. *****\n"); + LYShowBadHTML(msg); + FREE(msg); + } if (me->sp->tag_number != HTML_SELECT) { SET_SKIP_STACK(HTML_SELECT); } @@ -5057,9 +5110,14 @@ static int HTML_start_element(HTStructured * me, int element_number, * Make sure we're in a select tag. */ if (!me->inSELECT) { - if (LYBadHTML(me)) - CTRACE((tfp, - "Bad HTML: OPTION tag not within SELECT tag\n")); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, + "Bad HTML: OPTION tag not within SELECT tag\n"); + LYShowBadHTML(msg); + FREE(msg); + } /* * Too likely to cause a crash, so we'll ignore it. - FM @@ -5811,8 +5869,13 @@ static int HTML_end_element(HTStructured * me, int element_number, * Check for unclosed TEXTAREA. - FM */ if (me->inTEXTAREA && element_number != HTML_TEXTAREA) { - if (LYBadHTML(me)) - CTRACE((tfp, "Bad HTML: Missing TEXTAREA end tag\n")); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, "Bad HTML: Missing TEXTAREA end tag\n"); + LYShowBadHTML(msg); + FREE(msg); + } } if (!me->text && !LYMapsOnly) { @@ -5826,16 +5889,21 @@ static int HTML_end_element(HTStructured * me, int element_number, case HTML_HTML: if (me->inA || me->inSELECT || me->inTEXTAREA) { - if (LYBadHTML(me)) - CTRACE((tfp, - "Bad HTML: %s%s%s%s%s not closed before HTML end tag *****\n", - me->inSELECT ? "SELECT" : "", - (me->inSELECT && me->inTEXTAREA) ? ", " : "", - me->inTEXTAREA ? "TEXTAREA" : "", - (((me->inSELECT || me->inTEXTAREA) && me->inA) - ? ", " - : ""), - me->inA ? "A" : "")); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, + "Bad HTML: %s%s%s%s%s not closed before HTML end tag *****\n", + me->inSELECT ? "SELECT" : "", + (me->inSELECT && me->inTEXTAREA) ? ", " : "", + me->inTEXTAREA ? "TEXTAREA" : "", + (((me->inSELECT || me->inTEXTAREA) && me->inA) + ? ", " + : ""), + me->inA ? "A" : ""); + LYShowBadHTML(msg); + FREE(msg); + } } break; @@ -5931,16 +5999,21 @@ static int HTML_end_element(HTStructured * me, int element_number, case HTML_BODY: if (me->inA || me->inSELECT || me->inTEXTAREA) { - if (LYBadHTML(me)) - CTRACE((tfp, - "Bad HTML: %s%s%s%s%s not closed before BODY end tag *****\n", - me->inSELECT ? "SELECT" : "", - (me->inSELECT && me->inTEXTAREA) ? ", " : "", - me->inTEXTAREA ? "TEXTAREA" : "", - (((me->inSELECT || me->inTEXTAREA) && me->inA) - ? ", " - : ""), - me->inA ? "A" : "")); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, + "Bad HTML: %s%s%s%s%s not closed before BODY end tag *****\n", + me->inSELECT ? "SELECT" : "", + (me->inSELECT && me->inTEXTAREA) ? ", " : "", + me->inTEXTAREA ? "TEXTAREA" : "", + (((me->inSELECT || me->inTEXTAREA) && me->inA) + ? ", " + : ""), + me->inA ? "A" : ""); + LYShowBadHTML(msg); + FREE(msg); + } } break; @@ -6306,10 +6379,15 @@ static int HTML_end_element(HTStructured * me, int element_number, * We had more end tags than start tags, so we have bad HTML or * otherwise misparsed. - FM */ - if (LYBadHTML(me)) - CTRACE((tfp, - "Bad HTML: Unmatched OBJECT start and end tags. Discarding content:\n%s\n", - me->object.data)); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, + "Bad HTML: Unmatched OBJECT start and end tags. Discarding content:\n%s\n", + me->object.data); + LYShowBadHTML(msg); + FREE(msg); + } goto End_Object; } if (s > e) { @@ -6441,9 +6519,14 @@ static int HTML_end_element(HTStructured * me, int element_number, goto End_Object; } } else { - if (LYBadHTML(me)) - CTRACE((tfp, - "Bad HTML: Unmatched OBJECT start and end tags. Discarding content.\n")); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, + "Bad HTML: Unmatched OBJECT start and end tags. Discarding content.\n"); + LYShowBadHTML(msg); + FREE(msg); + } goto End_Object; } } @@ -6680,8 +6763,13 @@ static int HTML_end_element(HTStructured * me, int element_number, * FORM-related globals in GridText.c are initialized. - FM */ if (!me->inFORM) { - if (LYBadHTML(me)) - CTRACE((tfp, "Bad HTML: Unmatched FORM end tag\n")); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, "Bad HTML: Unmatched FORM end tag\n"); + LYShowBadHTML(msg); + FREE(msg); + } } EMIT_IFDEF_EXP_JUSTIFY_ELTS(form_in_htext = FALSE); @@ -6695,9 +6783,14 @@ static int HTML_end_element(HTStructured * me, int element_number, * SELECT. - kw */ if (me->inSELECT) { - if (LYBadHTML(me)) - CTRACE((tfp, - "Bad HTML: Open SELECT at FORM end. Faking SELECT end tag. *****\n")); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, + "Bad HTML: Open SELECT at FORM end. Faking SELECT end tag. *****\n"); + LYShowBadHTML(msg); + FREE(msg); + } if (me->sp->tag_number != HTML_SELECT) { SET_SKIP_STACK(HTML_SELECT); } @@ -6748,8 +6841,13 @@ static int HTML_end_element(HTStructured * me, int element_number, * Make sure we had a textarea start tag. */ if (!me->inTEXTAREA) { - if (LYBadHTML(me)) - CTRACE((tfp, "Bad HTML: Unmatched TEXTAREA end tag\n")); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, "Bad HTML: Unmatched TEXTAREA end tag\n"); + LYShowBadHTML(msg); + FREE(msg); + } break; } @@ -6944,8 +7042,14 @@ static int HTML_end_element(HTStructured * me, int element_number, * Make sure we had a select start tag. */ if (!me->inSELECT) { - if (LYBadHTML(me)) - CTRACE((tfp, "Bad HTML: Unmatched SELECT end tag *****\n")); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, + "Bad HTML: Unmatched SELECT end tag *****\n"); + LYShowBadHTML(msg); + FREE(msg); + } break; } @@ -6963,9 +7067,14 @@ static int HTML_end_element(HTStructured * me, int element_number, * Make sure we're in a form. */ if (!me->inFORM) { - if (LYBadHTML(me)) - CTRACE((tfp, - "Bad HTML: SELECT end tag not within FORM element *****\n")); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, + "Bad HTML: SELECT end tag not within FORM element *****\n"); + LYShowBadHTML(msg); + FREE(msg); + } /* * Hopefully won't crash, so we'll ignore it. - kw */ @@ -7276,9 +7385,14 @@ static void HTML_free(HTStructured * me) * close of a still-open form, something must have gone very wrong. * - kw */ - if (LYBadHTML(me)) - CTRACE((tfp, - "Bad HTML: SELECT or OPTION not ended properly *****\n")); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, + "Bad HTML: SELECT or OPTION not ended properly *****\n"); + LYShowBadHTML(msg); + FREE(msg); + } HTChunkTerminate(&me->option); /* * Output the left-over data as text, maybe it was invalid markup @@ -7295,9 +7409,14 @@ static void HTML_free(HTStructured * me) * close of a still-open form, something must have gone very wrong. * - kw */ - if (LYBadHTML(me)) - CTRACE((tfp, - "Bad HTML: TEXTAREA not used properly *****\n")); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, + "Bad HTML: TEXTAREA not used properly *****\n"); + LYShowBadHTML(msg); + FREE(msg); + } HTChunkTerminate(&me->textarea); /* * Output the left-over data as text, maybe it was invalid markup @@ -7341,9 +7460,14 @@ static void HTML_free(HTStructured * me) * If we still have data in the me->option chunk after forcing a close * of a still-open form, something must have gone very wrong. - kw */ - if (LYBadHTML(me)) - CTRACE((tfp, - "Bad HTML: SELECT or OPTION not ended properly *****\n")); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, + "Bad HTML: SELECT or OPTION not ended properly *****\n"); + LYShowBadHTML(msg); + FREE(msg); + } if (TRACE) { HTChunkTerminate(&me->option); CTRACE((tfp, "HTML_free: ***** leftover option data: %s\n", @@ -7357,9 +7481,14 @@ static void HTML_free(HTStructured * me) * close of a still-open form, something must have gone very wrong. - * kw */ - if (LYBadHTML(me)) - CTRACE((tfp, - "Bad HTML: TEXTAREA not used properly *****\n")); + if (LYBadHTML(me)) { + char *msg = NULL; + + HTSprintf0(&msg, + "Bad HTML: TEXTAREA not used properly *****\n"); + LYShowBadHTML(msg); + FREE(msg); + } if (TRACE) { HTChunkTerminate(&me->textarea); CTRACE((tfp, "HTML_free: ***** leftover textarea data: %s\n", |