-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhtml.h
453 lines (355 loc) · 11.4 KB
/
html.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
/*
* Portions Copyright (c) 1999 GMRS Software GmbH
* Carl-von-Linde-Str. 38, D-85716 Unterschleissheim, http://www.gmrs.de
* All rights reserved.
*
* Author: Arno Unkrig <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License in the file COPYING for more details.
*/
#ifndef __html_h_INCLUDED__ /* { */
#define __html_h_INCLUDED__
#include <string>
#include <list>
#define auto_ptr broken_auto_ptr
#include <memory>
#undef auto_ptr
#include "auto_ptr.h"
#include <utility>
#include "Area.h"
#include "iconvstream.h"
#include "istr.h"
using std::string;
using std::pair;
using std::list;
typedef pair<string, istr> TagAttribute;
istr get_attribute(
const list<TagAttribute> *, const char *name, const char *dflt
);
istr get_attribute(
const list<TagAttribute> *, const char *name, bool *exists
);
int get_attribute(
const list<TagAttribute> *, const char *name, int dflt
);
int get_attribute(
const list<TagAttribute> *, const char *name, int dflt,
const char *s1, int v1, ... /* ... NULL */
);
int get_attribute(
const list<TagAttribute> *, const char *name, const char *dflt1, int dflt2,
const char *s1, int v1, ... /* ... NULL */
);
istr get_style_attr(istr *style, const char *name, const char *dflt);
typedef char ostream_manipulator;
struct Element {
virtual ~Element();
/*
* Attempt to line-format the element. If the element contains "Block"s,
* then it cannot be line-formatted, and 0 will be returned. However, it
* is still possible to try "format()" (see below).
*/
virtual Line *line_format() const
{
return 0;
}
/*
* Format the element into a rectangular area. Attempt to not exceed
* "width".
*/
virtual Area *format(
Area::size_type /*width*/,
int /*halign*/
) const
{
return 0;
}
virtual struct PCData *to_PCData()
{
return 0;
}
};
struct PCData : public Element {
istr text;
/*virtual*/ PCData *to_PCData()
{
return this;
}
/*virtual*/ Line *line_format() const;
};
struct Font : public Element {
int attribute; // TT I B U STRIKE BIG SMALL
// SUB SUP
auto_ptr<list<auto_ptr<Element> > > texts;
Font(int a, list<auto_ptr<Element> > *t = 0) : attribute(a), texts(t)
{}
/*virtual*/ Line *line_format() const;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct Phrase : public Element {
int attribute; // EM STRONG DFN CODE SAMP
// KBD VAR CITE
auto_ptr<list<auto_ptr<Element> > > texts;
Phrase(int a, list<auto_ptr<Element> > *t = 0) : attribute(a), texts(t)
{}
/*virtual*/ Line *line_format() const;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct Font2 : public Element {
auto_ptr<list<TagAttribute> > attributes;// SIZE COLOR
auto_ptr<list<auto_ptr<Element> > > elements;
/*virtual*/ Line *line_format() const;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct Anchor : public Element {
auto_ptr<list<TagAttribute> > attributes;// NAME HREF REL REV TITLE
auto_ptr<list<auto_ptr<Element> > > texts;
mutable int refnum;
/*virtual*/ Line *line_format() const;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct BaseFont : public Element {
auto_ptr<list<TagAttribute> > attributes; // SIZE
};
struct LineBreak : public Element {
auto_ptr<list<TagAttribute> > attributes; // CLEAR
/*virtual*/ Line *line_format() const;
};
struct Map : public Element {
auto_ptr<list<TagAttribute> > attributes;// NAME
auto_ptr<list<auto_ptr<list<TagAttribute> > > > areas;
};
struct Paragraph : public Element {
auto_ptr<list<TagAttribute> > attributes;// ALIGN
auto_ptr<list<auto_ptr<Element> > > texts;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct Image : public Element {
auto_ptr<list<TagAttribute> > attributes; // SRC ALT ALIGN WIDTH HEIGHT
// BORDER HSPACE VSPACE USEMAP
// ISMAP
/*virtual*/ Line *line_format() const;
};
struct Applet : public Element {
auto_ptr<list<TagAttribute> > attributes;// CODEBASE CODE ALT NAME
// WIDTH HEIGHT ALIGN HSPACE
// VSPACE
auto_ptr<list<auto_ptr<Element> > > content;
/*virtual*/ Line *line_format() const;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct Param : public Element {
auto_ptr<list<TagAttribute> > attributes; // NAME VALUE
};
struct Division : public Element {
auto_ptr<list<TagAttribute> > attributes;// ALIGN
auto_ptr<list<auto_ptr<Element> > > body_content;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct Center : public Element {
// No attributes specified for <CENTER>!
auto_ptr<list<auto_ptr<Element> > > body_content;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct BlockQuote : public Element {
// No attributes specified for <BLOCKQUOTE>!
auto_ptr<list<auto_ptr<Element> > > content;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct Address : public Element {
// No attributes specified for <ADDRESS>!
auto_ptr<list<auto_ptr<Element> > > content;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct Form : public Element {
auto_ptr<list<TagAttribute> > attributes;// ACTION METHOD ENCTYPE
auto_ptr<list<auto_ptr<Element> > > content;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct Input : public Element {
auto_ptr<list<TagAttribute> > attributes; // TYPE NAME VALUE CHECKED SIZE
// MAXLENGTH SRC ALIGN
/*virtual*/ Line *line_format() const;
};
struct Option {
auto_ptr<list<TagAttribute> > attributes; // SELECTED VALUE
auto_ptr<PCData> pcdata;
};
struct Select : public Element {
auto_ptr<list<TagAttribute> > attributes;// NAME SIZE MULTIPLE
auto_ptr<list<auto_ptr<Option> > > content;
/*virtual*/ Line *line_format() const;
};
struct TextArea : public Element {
auto_ptr<list<TagAttribute> > attributes; // NAME ROWS COLS
auto_ptr<PCData> pcdata;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct Preformatted : public Element {
auto_ptr<list<TagAttribute> > attributes;// WIDTH
auto_ptr<list<auto_ptr<Element> > > texts;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct Body {
auto_ptr<list<TagAttribute> > attributes;// BACKGROUND BGCOLOR TEXT
// LINK VLINK ALINK
auto_ptr<list<auto_ptr<Element> > > content;
virtual ~Body()
{}
virtual Area *format(Area::size_type w, int halign) const;
void format(
Area::size_type indent_left,
Area::size_type w,
int halign,
iconvstream& os
) const;
};
struct Script {
auto_ptr<list<TagAttribute> > attributes; // LANGUAGE, ???
string text;
};
struct Style {
auto_ptr<list<TagAttribute> > attributes; // ???
string text;
};
struct Meta {
auto_ptr<list<TagAttribute> > attributes; // HTTP-EQUIV NAME CONTENT
};
struct Head {
auto_ptr<PCData> title;
auto_ptr<list<TagAttribute> > isindex_attributes; // PROMPT
auto_ptr<list<TagAttribute> > base_attributes; // HREF
list<auto_ptr<Script> > scripts;
list<auto_ptr<Style> > styles;
list<auto_ptr<Meta> > metas;
auto_ptr<list<TagAttribute> > link_attributes; // HREF REL REV TITLE
};
struct Document {
auto_ptr<list<TagAttribute> > attributes; // VERSION
Head head;
Body body;
Area *format(Area::size_type w, int halign) const;
void format(
Area::size_type indent_left,
Area::size_type w,
int halign,
iconvstream& os
) const;
};
struct Heading : public Element {
int level;
auto_ptr<list<TagAttribute> > attributes;// ALIGN
auto_ptr<list<auto_ptr<Element> > > content;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct TableCell : public Body {
};
struct TableHeadingCell : public TableCell {
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct TableRow {
auto_ptr<list<TagAttribute> > attributes;// ALIGN VALIGN
auto_ptr<list<auto_ptr<TableCell> > > cells;
};
struct Caption {
auto_ptr<list<TagAttribute> > attributes;// ALIGN
auto_ptr<list<auto_ptr<Element> > > texts;
Area *format(Area::size_type w, int halign) const;
};
struct Table : public Element {
auto_ptr<list<TagAttribute> > attributes;// ALIGN WIDTH BORDER
// CELLSPACING CELLPADDING
auto_ptr<Caption> caption;
auto_ptr<list<auto_ptr<TableRow> > > rows;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct NoBreak : public Element {
auto_ptr<list<auto_ptr<Element> > > content;
/*virtual*/ Line *line_format() const;
};
struct HorizontalRule : public Element {
auto_ptr<list<TagAttribute> > attributes; // ALIGN NOSHADE SIZE WIDTH
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct ListItem {
virtual ~ListItem()
{}
virtual Area *format(
Area::size_type w,
int style,
Area::size_type indent,
int *number_in_out = 0
) const = 0;
};
struct ListNormalItem : public ListItem {
auto_ptr<list<TagAttribute> > attributes;// TYPE VALUE
auto_ptr<list<auto_ptr<Element> > > flow;
/*virtual*/ Area *format(
Area::size_type w,
int style,
Area::size_type indent,
int *number_in_out
) const;
};
struct ListBlockItem : public ListItem {
auto_ptr<Element> block;
/*virtual*/ Area *format(
Area::size_type w,
int style,
Area::size_type indent,
int *
) const;
};
struct OrderedList : public Element {
auto_ptr<list<TagAttribute> > attributes;// TYPE START COMPACT
auto_ptr<list<auto_ptr<ListItem> > > items;
int nesting;
// Item indentation depends on on the list nesting level.
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct UnorderedList : public Element {
auto_ptr<list<TagAttribute> > attributes;// TYPE COMPACT
auto_ptr<list<auto_ptr<ListItem> > > items;
int nesting;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct Dir : public Element {
auto_ptr<list<TagAttribute> > attributes;// COMPACT
auto_ptr<list<auto_ptr<ListItem> > > items;
int nesting;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct Menu : public Element {
auto_ptr<list<TagAttribute> > attributes;// COMPACT
auto_ptr<list<auto_ptr<ListItem> > > items;
int nesting;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct DefinitionListItem {
virtual ~DefinitionListItem()
{}
virtual Area *format(Area::size_type w, int halign) const = 0;
};
struct TermName : public DefinitionListItem {
auto_ptr<list<auto_ptr<Element> > > flow;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct TermDefinition : public DefinitionListItem {
auto_ptr<list<auto_ptr<Element> > > flow;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
struct DefinitionList : public Element {
auto_ptr<list<TagAttribute> > attributes;// COMPACT
auto_ptr<list<auto_ptr<Element> > > preamble;
auto_ptr<list<auto_ptr<DefinitionListItem> > > items;
/*virtual*/ Area *format(Area::size_type w, int halign) const;
};
#endif /* } */