iconv: Bail out of the loop when an illegal sequence of bytes occurs.
[elinks/elinks-j605.git] / src / document / html / internal.h
blobc1924755637b406876502352b3a95e90de097dc3
2 #ifndef EL__DOCUMENT_HTML_INTERNAL_H
3 #define EL__DOCUMENT_HTML_INTERNAL_H
5 #include "document/css/stylesheet.h"
6 #include "document/html/parser.h"
7 #include "util/lists.h"
9 struct document_options;
10 struct uri;
12 /* For parser/parse.c: */
14 void process_head(struct html_context *html_context, unsigned char *head);
15 void put_chrs(struct html_context *html_context, unsigned char *start, int len);
17 enum html_whitespace_state {
18 /* Either we are starting a new "block" or the last segment of the
19 * current "block" is ending with whitespace and we should eat any
20 * leading whitespace of the next segment passed to put_chrs().
21 * This prevents HTML whitespace from indenting new blocks by one
22 * or creating two consecutive segments of whitespace in the middle
23 * of a block. */
24 HTML_SPACE_SUPPRESS,
26 /* Do not do anything special. */
27 HTML_SPACE_NORMAL,
29 /* We should add a space when we start the next segment if it doesn't
30 * already start with whitespace. This is used in an "x </y> z"
31 * scenario when the parser hits </y>: it renders "x" and sets this,
32 * so that it will then render " z". XXX: Then we could of course
33 * render "x " and set -1. But we test for this value in parse_html()
34 * if we hit an opening tag of an element and potentially
35 * put_chrs(" "). That needs more investigation yet. --pasky */
36 HTML_SPACE_ADD,
39 struct html_context {
40 #ifdef CONFIG_CSS
41 /* The default stylesheet is initially merged into it. When parsing CSS
42 * from <style>-tags and external stylesheets if enabled is merged
43 * added to it. */
44 struct css_stylesheet css_styles;
45 struct html_element html;
46 #endif
48 /* These are global per-document base values, alterable by the <base>
49 * element. */
50 struct uri *base_href;
51 unsigned char *base_target;
53 struct document_options *options;
55 /* doc_cp is the charset of the document, i.e. part->document->cp.
56 * It is copied here because part->document is NULL sometimes. */
57 int doc_cp;
59 /* For:
60 * html/parser/parse.c
61 * html/parser/stack.c
62 * html/parser.c */
63 LIST_OF(struct html_element) stack;
65 /* For parser/parse.c: */
66 unsigned char *eoff; /* For parser/forms.c too */
67 int line_breax; /* This is for ln_break. */
68 int position; /* This is the position on the document canvas relative
69 * to the current line and is maintained by put_chrs. */
70 enum html_whitespace_state putsp; /* This is for the put_chrs
71 * state-machine. */
72 int was_li;
74 unsigned int quote_level; /* Nesting level of <q> tags. See @html_quote
75 * for why this is unsigned. */
77 unsigned int was_br:1;
78 unsigned int was_xmp:1;
79 unsigned int was_style:1;
80 unsigned int has_link_lines:1;
81 unsigned int was_body:1; /* For META refresh inside <body>. */
82 unsigned int was_body_background:1; /* For <HTML> with style. */
83 unsigned int was_html:1; /* was <HTML> */
85 /* For html/parser.c, html/renderer.c */
86 int margin;
88 /* For parser/forms.c: */
89 unsigned char *startf;
91 /* For:
92 * html/parser/parse.c
93 * html/parser.c
94 * html/renderer.c
95 * html/tables.c */
96 int table_level;
98 /* For:
99 * html/parser/forms.c
100 * html/parser/link.c
101 * html/parser/parse.c
102 * html/parser/stack.c
103 * html/parser.c */
104 struct part *part;
106 /* For:
107 * html/parser/forms.c
108 * html/parser/link.c
109 * html/parser/parse.c
110 * html/parser.c */
111 /* Note that this is for usage by put_chrs only; anywhere else in
112 * the parser, one should use put_chrs. */
113 void (*put_chars_f)(struct html_context *, unsigned char *, int);
115 /* For:
116 * html/parser/forms.c
117 * html/parser/link.c
118 * html/parser/parse.c
119 * html/parser/stack.c
120 * html/parser.c */
121 void (*line_break_f)(struct html_context *);
123 /* For:
124 * html/parser/forms.c
125 * html/parser/parse.c
126 * html/parser.c */
127 void *(*special_f)(struct html_context *, enum html_special_type, ...);
130 #define html_top ((struct html_element *) html_context->stack.next)
131 #define html_bottom ((struct html_element *) html_context->stack.prev)
132 #define format (html_top->attr)
133 #define par_format (html_top->parattr)
135 #define html_is_preformatted() (format.style.attr & AT_PREFORMATTED)
137 #define get_html_max_width() \
138 int_max(par_format.width - (par_format.leftmargin + par_format.rightmargin), 0)
140 /* For parser/link.c: */
142 void html_focusable(struct html_context *html_context, unsigned char *a);
143 void html_skip(struct html_context *html_context, unsigned char *a);
144 unsigned char *get_target(struct document_options *options, unsigned char *a);
146 void
147 import_css_stylesheet(struct css_stylesheet *css, struct uri *base_uri,
148 const unsigned char *unterminated_url, int len);
150 #endif