File: html.h

package info (click to toggle)
html2text 1.3.2a-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 736 kB
  • ctags: 1,694
  • sloc: cpp: 9,311; yacc: 828; sh: 209; makefile: 144
file content (629 lines) | stat: -rw-r--r-- 19,943 bytes parent folder | download | duplicates (8)
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629

 /***************************************************************************/

/*
 * 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 <arno@unkrig.de>
 *
 * All advertising materials mentioning features or use of this software
 * must display the following acknowledgement:
 * "This product includes software developed by GMRS Software GmbH."
 * The name of GMRS Software GmbH may not be used to endorse or promote
 * products derived from this software without specific prior written
 * permission.
 */
 
/* 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.
 */

 /***************************************************************************/

/*
 * Changes to version 1.2.2 were made by Martin Bayer <mbayer@zedat.fu-berlin.de>
 * Dates and reasons of modifications:
 * Fre Jun  8 17:46:31 CEST 2001: new method
 * Thu Oct  4 21:38:47 CEST 2001: ported to g++ 3.0
 */
  
 /***************************************************************************/


#ifndef __html_h_INCLUDED__ /* { */
#define __html_h_INCLUDED__

/* ------------------------------------------------------------------------- */


#include <string>
#include <list>
#ifdef AUTO_PTR_BROKEN /* { */
#  define auto_ptr broken_auto_ptr
#  include <memory>
#  undef auto_ptr
#  include "libstd/include/auto_ptr.h"
#else /* } { */
#  include <memory>
#endif /* } */
#include <utility>

#include "Area.h"

/* ------------------------------------------------------------------------- */

#define LATIN1_nbsp   160
#define LATIN1_iexcl  161
#define LATIN1_cent   162
#define LATIN1_pound  163
#define LATIN1_curren 164
#define LATIN1_yen    165
#define LATIN1_brvbar 166
#define LATIN1_sect   167
#define LATIN1_uml    168
#define LATIN1_copy   169
#define LATIN1_ordf   170
#define LATIN1_laquo  171
#define LATIN1_not    172
#define LATIN1_shy    173
#define LATIN1_reg    174
#define LATIN1_macr   175
#define LATIN1_deg    176
#define LATIN1_plusmn 177
#define LATIN1_sup2   178
#define LATIN1_sup3   179
#define LATIN1_acute  180
#define LATIN1_micro  181
#define LATIN1_para   182
#define LATIN1_middot 183
#define LATIN1_cedil  184
#define LATIN1_sup1   185
#define LATIN1_ordm   186
#define LATIN1_raquo  187
#define LATIN1_frac14 188
#define LATIN1_frac12 189
#define LATIN1_frac34 190
#define LATIN1_iquest 191
#define LATIN1_Agrave 192
#define LATIN1_Aacute 193
#define LATIN1_Acirc  194
#define LATIN1_Atilde 195
#define LATIN1_Auml   196
#define LATIN1_Aring  197
#define LATIN1_AElig  198
#define LATIN1_Ccedil 199
#define LATIN1_Egrave 200
#define LATIN1_Eacute 201
#define LATIN1_Ecirc  202
#define LATIN1_Euml   203
#define LATIN1_Igrave 204
#define LATIN1_Iacute 205
#define LATIN1_Icirc  206
#define LATIN1_Iuml   207
#define LATIN1_ETH    208
#define LATIN1_Ntilde 209
#define LATIN1_Ograve 210
#define LATIN1_Oacute 211
#define LATIN1_Ocirc  212
#define LATIN1_Otilde 213
#define LATIN1_Ouml   214
#define LATIN1_times  215
#define LATIN1_Oslash 216
#define LATIN1_Ugrave 217
#define LATIN1_Uacute 218
#define LATIN1_Ucirc  219
#define LATIN1_Uuml   220
#define LATIN1_Yacute 221
#define LATIN1_THORN  222
#define LATIN1_szlig  223
#define LATIN1_agrave 224
#define LATIN1_aacute 225
#define LATIN1_acirc  226
#define LATIN1_atilde 227
#define LATIN1_auml   228
#define LATIN1_aring  229
#define LATIN1_aelig  230
#define LATIN1_ccedil 231
#define LATIN1_egrave 232
#define LATIN1_eacute 233
#define LATIN1_ecirc  234
#define LATIN1_euml   235
#define LATIN1_igrave 236
#define LATIN1_iacute 237
#define LATIN1_icirc  238
#define LATIN1_iuml   239
#define LATIN1_eth    240
#define LATIN1_ntilde 241
#define LATIN1_ograve 242
#define LATIN1_oacute 243
#define LATIN1_ocirc  244
#define LATIN1_otilde 245
#define LATIN1_ouml   246
#define LATIN1_divide 247
#define LATIN1_oslash 248
#define LATIN1_ugrave 249
#define LATIN1_uacute 250
#define LATIN1_ucirc  251
#define LATIN1_uuml   252
#define LATIN1_yacute 253
#define LATIN1_thorn  254
#define LATIN1_yuml   255

/* ------------------------------------------------------------------------- */

using std::string;
using std::pair;
using std::list;

typedef pair<string, string> TagAttribute;

string get_attribute(
  const list<TagAttribute> *, const char *name, const char *dflt
);
// neue Methode fuer leere Attribute - Johannes Geiger
string 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 */
);

/* ------------------------------------------------------------------------- */

typedef ostream &(*ostream_manipulator)(ostream &);

struct Element {
  virtual ~Element();
  virtual void unparse(ostream &, ostream_manipulator separator) const = 0;

  /*
   * 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 {
  string text;

  /*virtual*/ PCData *to_PCData() { return this; }

  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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;

  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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

  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
};

struct LineBreak : public Element {
  auto_ptr<list<TagAttribute> > attributes; // CLEAR

  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*virtual*/ Line *line_format() const;
};

struct Map : public Element {
  auto_ptr<list<TagAttribute> >                   attributes; // NAME
  auto_ptr<list<auto_ptr<list<TagAttribute> > > > areas;

  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
};

struct Paragraph : public Element {
  auto_ptr<list<TagAttribute> >       attributes; // ALIGN
  auto_ptr<list<auto_ptr<Element> > > texts;

  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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

  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
};

struct Division : public Element {
  auto_ptr<list<TagAttribute> >       attributes; // ALIGN
  auto_ptr<list<auto_ptr<Element> > > body_content;

  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*virtual*/ Line *line_format() const;
};

struct Option {
  auto_ptr<list<TagAttribute> > attributes; // SELECTED VALUE
  auto_ptr<PCData>              pcdata;

  void unparse(ostream &, ostream_manipulator separator) const;
};

struct Select : public Element {
  auto_ptr<list<TagAttribute> >      attributes; // NAME SIZE MULTIPLE
  auto_ptr<list<auto_ptr<Option> > > content;

  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*virtual*/ Line *line_format() const;
};

struct TextArea : public Element {
  auto_ptr<list<TagAttribute> > attributes; // NAME ROWS COLS
  auto_ptr<PCData>              pcdata;

  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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 void unparse(ostream &, ostream_manipulator separator) const;
  virtual Area *format(Area::size_type w, int halign) const;
  void format(
    Area::size_type indent_left,
    Area::size_type w,
    int             halign,
    ostream         &os
  ) const;
};

struct Script {
  auto_ptr<list<TagAttribute> > attributes; // LANGUAGE, ???
  string                        text;

  void unparse(ostream &, ostream_manipulator separator) const;
};

struct Style {
  auto_ptr<list<TagAttribute> > attributes; // ???
  string                        text;

  void unparse(ostream &, ostream_manipulator separator) const;
};

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;
  auto_ptr<list<TagAttribute> > meta_attributes;    // HTTP-EQUIV NAME CONTENT
  auto_ptr<list<TagAttribute> > link_attributes;    // HREF REL REV TITLE

  void unparse(ostream &, ostream_manipulator separator) const;
};

struct Document {
  auto_ptr<list<TagAttribute> > attributes; // VERSION
  Head                          head;
  Body                          body;

  void unparse(ostream &, ostream_manipulator separator) const;
  Area *format(Area::size_type w, int halign) const;
  void format(
    Area::size_type indent_left,
    Area::size_type w,
    int             halign,
    ostream         &os
  ) const;
};

struct Heading : public Element {
  int                                 level;
  auto_ptr<list<TagAttribute> >       attributes; // ALIGN
  auto_ptr<list<auto_ptr<Element> > > content;

  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*virtual*/ Area *format(Area::size_type w, int halign) const;
};

struct TableCell : public Body {
  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
};

struct TableHeadingCell : public TableCell {
  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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;

  void unparse(ostream &, ostream_manipulator separator) const;
};

struct Caption {
  auto_ptr<list<TagAttribute> >       attributes; // ALIGN
  auto_ptr<list<auto_ptr<Element> > > texts;

  void unparse(ostream &, ostream_manipulator separator) const;
  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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*virtual*/ Area *format(Area::size_type w, int halign) const;
};

struct NoBreak : public Element {
  auto_ptr<list<auto_ptr<Element> > > content;

  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*virtual*/ Line *line_format() const;
};

struct HorizontalRule : public Element {
  auto_ptr<list<TagAttribute> > attributes; // ALIGN NOSHADE SIZE WIDTH

  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*virtual*/ Area *format(Area::size_type w, int halign) const;
};

/* ------------------------------------------------------------------------- */

struct ListItem {
  virtual ~ListItem() {}
  virtual void unparse(ostream &, ostream_manipulator separator) const = 0;
  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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*virtual*/ Area *format(Area::size_type w, int halign) const;
};

/* ------------------------------------------------------------------------- */

struct DefinitionListItem {
  virtual ~DefinitionListItem() {}
  virtual void unparse(ostream &, ostream_manipulator separator) const = 0;
  virtual Area *format(Area::size_type w, int halign) const = 0;
};

struct TermName : public DefinitionListItem {
  auto_ptr<list<auto_ptr<Element> > > flow;

  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*virtual*/ Area *format(Area::size_type w, int halign) const;
};

struct TermDefinition : public DefinitionListItem {
  auto_ptr<list<auto_ptr<Element> > > flow;

  /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*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*/ void unparse(ostream &, ostream_manipulator separator) const;
  /*virtual*/ Area *format(Area::size_type w, int halign) const;
};

/* ------------------------------------------------------------------------- */

#endif /* } */

/* ------------------------------------------------------------------------- */