1 2 /***************************************************************************/ 3 4 /* 5 * Portions Copyright (c) 1999 GMRS Software GmbH 6 * Carl-von-Linde-Str. 38, D-85716 Unterschleissheim, http://www.gmrs.de 7 * All rights reserved. 8 * 9 * Author: Arno Unkrig <arno@unkrig.de> 10 * 11 * All advertising materials mentioning features or use of this software 12 * must display the following acknowledgement: 13 * "This product includes software developed by GMRS Software GmbH." 14 * The name of GMRS Software GmbH may not be used to endorse or promote 15 * products derived from this software without specific prior written 16 * permission. 17 */ 18 19 /* This program is free software; you can redistribute it and/or modify 20 * it under the terms of the GNU General Public License as published by 21 * the Free Software Foundation; either version 2 of the License, or 22 * (at your option) any later version. 23 * 24 * This program is distributed in the hope that it will be useful, 25 * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 * GNU General Public License in the file COPYING for more details. 28 */ 29 30 /***************************************************************************/ 31 32 /* 33 * Changes to version 1.2.2 were made by Martin Bayer <mbayer@zedat.fu-berlin.de> 34 * Dates and reasons of modifications: 35 * Fre Jun 8 17:46:31 CEST 2001: new method 36 * Thu Oct 4 21:38:47 CEST 2001: ported to g++ 3.0 37 */ 38 39 /***************************************************************************/ 40 41 42 #ifndef __html_h_INCLUDED__ /* { */ 43 #define __html_h_INCLUDED__ 44 45 /* ------------------------------------------------------------------------- */ 46 47 48 #include <string> 49 #include <list> 50 #ifdef AUTO_PTR_BROKEN /* { */ 51 # define auto_ptr broken_auto_ptr 52 # include <memory> 53 # undef auto_ptr 54 # include "libstd/include/auto_ptr.h" 55 #else /* } { */ 56 # include <memory> 57 #endif /* } */ 58 #include <utility> 59 60 #include "Area.h" 61 62 /* ------------------------------------------------------------------------- */ 63 64 #define LATIN1_nbsp 160 65 #define LATIN1_iexcl 161 66 #define LATIN1_cent 162 67 #define LATIN1_pound 163 68 #define LATIN1_curren 164 69 #define LATIN1_yen 165 70 #define LATIN1_brvbar 166 71 #define LATIN1_sect 167 72 #define LATIN1_uml 168 73 #define LATIN1_copy 169 74 #define LATIN1_ordf 170 75 #define LATIN1_laquo 171 76 #define LATIN1_not 172 77 #define LATIN1_shy 173 78 #define LATIN1_reg 174 79 #define LATIN1_macr 175 80 #define LATIN1_deg 176 81 #define LATIN1_plusmn 177 82 #define LATIN1_sup2 178 83 #define LATIN1_sup3 179 84 #define LATIN1_acute 180 85 #define LATIN1_micro 181 86 #define LATIN1_para 182 87 #define LATIN1_middot 183 88 #define LATIN1_cedil 184 89 #define LATIN1_sup1 185 90 #define LATIN1_ordm 186 91 #define LATIN1_raquo 187 92 #define LATIN1_frac14 188 93 #define LATIN1_frac12 189 94 #define LATIN1_frac34 190 95 #define LATIN1_iquest 191 96 #define LATIN1_Agrave 192 97 #define LATIN1_Aacute 193 98 #define LATIN1_Acirc 194 99 #define LATIN1_Atilde 195 100 #define LATIN1_Auml 196 101 #define LATIN1_Aring 197 102 #define LATIN1_AElig 198 103 #define LATIN1_Ccedil 199 104 #define LATIN1_Egrave 200 105 #define LATIN1_Eacute 201 106 #define LATIN1_Ecirc 202 107 #define LATIN1_Euml 203 108 #define LATIN1_Igrave 204 109 #define LATIN1_Iacute 205 110 #define LATIN1_Icirc 206 111 #define LATIN1_Iuml 207 112 #define LATIN1_ETH 208 113 #define LATIN1_Ntilde 209 114 #define LATIN1_Ograve 210 115 #define LATIN1_Oacute 211 116 #define LATIN1_Ocirc 212 117 #define LATIN1_Otilde 213 118 #define LATIN1_Ouml 214 119 #define LATIN1_times 215 120 #define LATIN1_Oslash 216 121 #define LATIN1_Ugrave 217 122 #define LATIN1_Uacute 218 123 #define LATIN1_Ucirc 219 124 #define LATIN1_Uuml 220 125 #define LATIN1_Yacute 221 126 #define LATIN1_THORN 222 127 #define LATIN1_szlig 223 128 #define LATIN1_agrave 224 129 #define LATIN1_aacute 225 130 #define LATIN1_acirc 226 131 #define LATIN1_atilde 227 132 #define LATIN1_auml 228 133 #define LATIN1_aring 229 134 #define LATIN1_aelig 230 135 #define LATIN1_ccedil 231 136 #define LATIN1_egrave 232 137 #define LATIN1_eacute 233 138 #define LATIN1_ecirc 234 139 #define LATIN1_euml 235 140 #define LATIN1_igrave 236 141 #define LATIN1_iacute 237 142 #define LATIN1_icirc 238 143 #define LATIN1_iuml 239 144 #define LATIN1_eth 240 145 #define LATIN1_ntilde 241 146 #define LATIN1_ograve 242 147 #define LATIN1_oacute 243 148 #define LATIN1_ocirc 244 149 #define LATIN1_otilde 245 150 #define LATIN1_ouml 246 151 #define LATIN1_divide 247 152 #define LATIN1_oslash 248 153 #define LATIN1_ugrave 249 154 #define LATIN1_uacute 250 155 #define LATIN1_ucirc 251 156 #define LATIN1_uuml 252 157 #define LATIN1_yacute 253 158 #define LATIN1_thorn 254 159 #define LATIN1_yuml 255 160 161 /* ------------------------------------------------------------------------- */ 162 163 using std::string; 164 using std::pair; 165 using std::list; 166 167 typedef pair<string, string> TagAttribute; 168 169 string get_attribute( 170 const list<TagAttribute> *, const char *name, const char *dflt 171 ); 172 // neue Methode fuer leere Attribute - Johannes Geiger 173 string get_attribute( 174 const list<TagAttribute> *, const char *name, bool *exists 175 ); 176 int get_attribute( 177 const list<TagAttribute> *, const char *name, int dflt 178 ); 179 int get_attribute( 180 const list<TagAttribute> *, const char *name, int dflt, 181 const char *s1, int v1, ... /* ... NULL */ 182 ); 183 int get_attribute( 184 const list<TagAttribute> *, const char *name, const char *dflt1, int dflt2, 185 const char *s1, int v1, ... /* ... NULL */ 186 ); 187 188 /* ------------------------------------------------------------------------- */ 189 190 typedef ostream &(*ostream_manipulator)(ostream &); 191 192 struct Element { 193 virtual ~Element(); 194 virtual void unparse(ostream &, ostream_manipulator separator) const = 0; 195 196 /* 197 * Attempt to line-format the element. If the element contains "Block"s, 198 * then it cannot be line-formatted, and 0 will be returned. However, it 199 * is still possible to try "format()" (see below). 200 */ line_formatElement201 virtual Line *line_format() const 202 { return 0; } 203 204 /* 205 * Format the element into a rectangular area. Attempt to not exceed "width". 206 */ formatElement207 virtual Area *format( 208 Area::size_type /*width*/, 209 int /*halign*/ 210 ) const 211 { return 0; } 212 to_PCDataElement213 virtual struct PCData *to_PCData() { return 0; } 214 }; 215 216 /* ------------------------------------------------------------------------- */ 217 218 struct PCData : public Element { 219 string text; 220 to_PCDataPCData221 /*virtual*/ PCData *to_PCData() { return this; } 222 223 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 224 /*virtual*/ Line *line_format() const; 225 }; 226 227 struct Font : public Element { 228 int attribute; // TT I B U STRIKE BIG SMALL 229 // SUB SUP 230 auto_ptr<list<auto_ptr<Element> > > texts; 231 attributeFont232 Font(int a, list<auto_ptr<Element> > *t = 0) : attribute(a), texts(t) {} 233 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 234 /*virtual*/ Line *line_format() const; 235 /*virtual*/ Area *format(Area::size_type w, int halign) const; 236 }; 237 238 struct Phrase : public Element { 239 int attribute; // EM STRONG DFN CODE SAMP 240 // KBD VAR CITE 241 auto_ptr<list<auto_ptr<Element> > > texts; 242 attributePhrase243 Phrase(int a, list<auto_ptr<Element> > *t = 0) : attribute(a), texts(t) {} 244 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 245 /*virtual*/ Line *line_format() const; 246 /*virtual*/ Area *format(Area::size_type w, int halign) const; 247 }; 248 249 struct Font2 : public Element { 250 auto_ptr<list<TagAttribute> > attributes; // SIZE COLOR 251 auto_ptr<list<auto_ptr<Element> > > elements; 252 253 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 254 /*virtual*/ Line *line_format() const; 255 /*virtual*/ Area *format(Area::size_type w, int halign) const; 256 }; 257 258 struct Anchor : public Element { 259 auto_ptr<list<TagAttribute> > attributes; // NAME HREF REL REV TITLE 260 auto_ptr<list<auto_ptr<Element> > > texts; 261 262 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 263 /*virtual*/ Line *line_format() const; 264 /*virtual*/ Area *format(Area::size_type w, int halign) const; 265 }; 266 267 struct BaseFont : public Element { 268 auto_ptr<list<TagAttribute> > attributes; // SIZE 269 270 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 271 }; 272 273 struct LineBreak : public Element { 274 auto_ptr<list<TagAttribute> > attributes; // CLEAR 275 276 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 277 /*virtual*/ Line *line_format() const; 278 }; 279 280 struct Map : public Element { 281 auto_ptr<list<TagAttribute> > attributes; // NAME 282 auto_ptr<list<auto_ptr<list<TagAttribute> > > > areas; 283 284 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 285 }; 286 287 struct Paragraph : public Element { 288 auto_ptr<list<TagAttribute> > attributes; // ALIGN 289 auto_ptr<list<auto_ptr<Element> > > texts; 290 291 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 292 /*virtual*/ Area *format(Area::size_type w, int halign) const; 293 }; 294 295 struct Image : public Element { 296 auto_ptr<list<TagAttribute> > attributes; // SRC ALT ALIGN WIDTH HEIGHT 297 // BORDER HSPACE VSPACE USEMAP 298 // ISMAP 299 300 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 301 /*virtual*/ Line *line_format() const; 302 }; 303 304 struct Applet : public Element { 305 auto_ptr<list<TagAttribute> > attributes; // CODEBASE CODE ALT NAME 306 // WIDTH HEIGHT ALIGN HSPACE 307 // VSPACE 308 auto_ptr<list<auto_ptr<Element> > > content; 309 310 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 311 /*virtual*/ Line *line_format() const; 312 /*virtual*/ Area *format(Area::size_type w, int halign) const; 313 }; 314 315 struct Param : public Element { 316 auto_ptr<list<TagAttribute> > attributes; // NAME VALUE 317 318 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 319 }; 320 321 struct Division : public Element { 322 auto_ptr<list<TagAttribute> > attributes; // ALIGN 323 auto_ptr<list<auto_ptr<Element> > > body_content; 324 325 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 326 /*virtual*/ Area *format(Area::size_type w, int halign) const; 327 }; 328 329 struct Center : public Element { 330 // No attributes specified for <CENTER>! 331 auto_ptr<list<auto_ptr<Element> > > body_content; 332 333 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 334 /*virtual*/ Area *format(Area::size_type w, int halign) const; 335 }; 336 337 struct BlockQuote : public Element { 338 // No attributes specified for <BLOCKQUOTE>! 339 auto_ptr<list<auto_ptr<Element> > > content; 340 341 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 342 /*virtual*/ Area *format(Area::size_type w, int halign) const; 343 }; 344 345 struct Address : public Element { 346 // No attributes specified for <ADDRESS>! 347 auto_ptr<list<auto_ptr<Element> > > content; 348 349 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 350 /*virtual*/ Area *format(Area::size_type w, int halign) const; 351 }; 352 353 /* ------------------------------------------------------------------------- */ 354 355 struct Form : public Element { 356 auto_ptr<list<TagAttribute> > attributes; // ACTION METHOD ENCTYPE 357 auto_ptr<list<auto_ptr<Element> > > content; 358 359 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 360 /*virtual*/ Area *format(Area::size_type w, int halign) const; 361 }; 362 363 struct Input : public Element { 364 auto_ptr<list<TagAttribute> > attributes; // TYPE NAME VALUE CHECKED SIZE 365 // MAXLENGTH SRC ALIGN 366 367 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 368 /*virtual*/ Line *line_format() const; 369 }; 370 371 struct Option { 372 auto_ptr<list<TagAttribute> > attributes; // SELECTED VALUE 373 auto_ptr<PCData> pcdata; 374 375 void unparse(ostream &, ostream_manipulator separator) const; 376 }; 377 378 struct Select : public Element { 379 auto_ptr<list<TagAttribute> > attributes; // NAME SIZE MULTIPLE 380 auto_ptr<list<auto_ptr<Option> > > content; 381 382 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 383 /*virtual*/ Line *line_format() const; 384 }; 385 386 struct TextArea : public Element { 387 auto_ptr<list<TagAttribute> > attributes; // NAME ROWS COLS 388 auto_ptr<PCData> pcdata; 389 390 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 391 /*virtual*/ Area *format(Area::size_type w, int halign) const; 392 }; 393 394 /* ------------------------------------------------------------------------- */ 395 396 struct Preformatted : public Element { 397 auto_ptr<list<TagAttribute> > attributes; // WIDTH 398 auto_ptr<list<auto_ptr<Element> > > texts; 399 400 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 401 /*virtual*/ Area *format(Area::size_type w, int halign) const; 402 }; 403 404 struct Body { 405 auto_ptr<list<TagAttribute> > attributes; // BACKGROUND BGCOLOR TEXT 406 // LINK VLINK ALINK 407 auto_ptr<list<auto_ptr<Element> > > content; 408 ~BodyBody409 virtual ~Body() {} 410 virtual void unparse(ostream &, ostream_manipulator separator) const; 411 virtual Area *format(Area::size_type w, int halign) const; 412 void format( 413 Area::size_type indent_left, 414 Area::size_type w, 415 int halign, 416 ostream &os 417 ) const; 418 }; 419 420 struct Script { 421 auto_ptr<list<TagAttribute> > attributes; // LANGUAGE, ??? 422 string text; 423 424 void unparse(ostream &, ostream_manipulator separator) const; 425 }; 426 427 struct Style { 428 auto_ptr<list<TagAttribute> > attributes; // ??? 429 string text; 430 431 void unparse(ostream &, ostream_manipulator separator) const; 432 }; 433 434 struct Head { 435 auto_ptr<PCData> title; 436 auto_ptr<list<TagAttribute> > isindex_attributes; // PROMPT 437 auto_ptr<list<TagAttribute> > base_attributes; // HREF 438 list<auto_ptr<Script> > scripts; 439 list<auto_ptr<Style> > styles; 440 auto_ptr<list<TagAttribute> > meta_attributes; // HTTP-EQUIV NAME CONTENT 441 auto_ptr<list<TagAttribute> > link_attributes; // HREF REL REV TITLE 442 443 void unparse(ostream &, ostream_manipulator separator) const; 444 }; 445 446 struct Document { 447 auto_ptr<list<TagAttribute> > attributes; // VERSION 448 Head head; 449 Body body; 450 451 void unparse(ostream &, ostream_manipulator separator) const; 452 Area *format(Area::size_type w, int halign) const; 453 void format( 454 Area::size_type indent_left, 455 Area::size_type w, 456 int halign, 457 ostream &os 458 ) const; 459 }; 460 461 struct Heading : public Element { 462 int level; 463 auto_ptr<list<TagAttribute> > attributes; // ALIGN 464 auto_ptr<list<auto_ptr<Element> > > content; 465 466 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 467 /*virtual*/ Area *format(Area::size_type w, int halign) const; 468 }; 469 470 struct TableCell : public Body { 471 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 472 }; 473 474 struct TableHeadingCell : public TableCell { 475 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 476 /*virtual*/ Area *format(Area::size_type w, int halign) const; 477 }; 478 479 struct TableRow { 480 auto_ptr<list<TagAttribute> > attributes; // ALIGN VALIGN 481 auto_ptr<list<auto_ptr<TableCell> > > cells; 482 483 void unparse(ostream &, ostream_manipulator separator) const; 484 }; 485 486 struct Caption { 487 auto_ptr<list<TagAttribute> > attributes; // ALIGN 488 auto_ptr<list<auto_ptr<Element> > > texts; 489 490 void unparse(ostream &, ostream_manipulator separator) const; 491 Area *format(Area::size_type w, int halign) const; 492 }; 493 494 struct Table : public Element { 495 auto_ptr<list<TagAttribute> > attributes; // ALIGN WIDTH BORDER 496 // CELLSPACING CELLPADDING 497 auto_ptr<Caption> caption; 498 auto_ptr<list<auto_ptr<TableRow> > > rows; 499 500 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 501 /*virtual*/ Area *format(Area::size_type w, int halign) const; 502 }; 503 504 struct NoBreak : public Element { 505 auto_ptr<list<auto_ptr<Element> > > content; 506 507 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 508 /*virtual*/ Line *line_format() const; 509 }; 510 511 struct HorizontalRule : public Element { 512 auto_ptr<list<TagAttribute> > attributes; // ALIGN NOSHADE SIZE WIDTH 513 514 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 515 /*virtual*/ Area *format(Area::size_type w, int halign) const; 516 }; 517 518 /* ------------------------------------------------------------------------- */ 519 520 struct ListItem { ~ListItemListItem521 virtual ~ListItem() {} 522 virtual void unparse(ostream &, ostream_manipulator separator) const = 0; 523 virtual Area *format( 524 Area::size_type w, 525 int style, 526 Area::size_type indent, 527 int *number_in_out = 0 528 ) const = 0; 529 }; 530 531 struct ListNormalItem : public ListItem { 532 auto_ptr<list<TagAttribute> > attributes; // TYPE VALUE 533 auto_ptr<list<auto_ptr<Element> > > flow; 534 535 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 536 /*virtual*/ Area *format( 537 Area::size_type w, 538 int style, 539 Area::size_type indent, 540 int *number_in_out 541 ) const; 542 }; 543 544 struct ListBlockItem : public ListItem { 545 auto_ptr<Element> block; 546 547 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 548 /*virtual*/ Area *format( 549 Area::size_type w, 550 int style, 551 Area::size_type indent, 552 int * 553 ) const; 554 }; 555 556 struct OrderedList : public Element { 557 auto_ptr<list<TagAttribute> > attributes; // TYPE START COMPACT 558 auto_ptr<list<auto_ptr<ListItem> > > items; 559 int nesting; 560 // Item indentation depends on on the list nesting level. 561 562 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 563 /*virtual*/ Area *format(Area::size_type w, int halign) const; 564 }; 565 566 struct UnorderedList : public Element { 567 auto_ptr<list<TagAttribute> > attributes; // TYPE COMPACT 568 auto_ptr<list<auto_ptr<ListItem> > > items; 569 int nesting; 570 571 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 572 /*virtual*/ Area *format(Area::size_type w, int halign) const; 573 }; 574 575 struct Dir : public Element { 576 auto_ptr<list<TagAttribute> > attributes; // COMPACT 577 auto_ptr<list<auto_ptr<ListItem> > > items; 578 int nesting; 579 580 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 581 /*virtual*/ Area *format(Area::size_type w, int halign) const; 582 }; 583 584 struct Menu : public Element { 585 auto_ptr<list<TagAttribute> > attributes; // COMPACT 586 auto_ptr<list<auto_ptr<ListItem> > > items; 587 int nesting; 588 589 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 590 /*virtual*/ Area *format(Area::size_type w, int halign) const; 591 }; 592 593 /* ------------------------------------------------------------------------- */ 594 595 struct DefinitionListItem { ~DefinitionListItemDefinitionListItem596 virtual ~DefinitionListItem() {} 597 virtual void unparse(ostream &, ostream_manipulator separator) const = 0; 598 virtual Area *format(Area::size_type w, int halign) const = 0; 599 }; 600 601 struct TermName : public DefinitionListItem { 602 auto_ptr<list<auto_ptr<Element> > > flow; 603 604 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 605 /*virtual*/ Area *format(Area::size_type w, int halign) const; 606 }; 607 608 struct TermDefinition : public DefinitionListItem { 609 auto_ptr<list<auto_ptr<Element> > > flow; 610 611 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 612 /*virtual*/ Area *format(Area::size_type w, int halign) const; 613 }; 614 615 struct DefinitionList : public Element { 616 auto_ptr<list<TagAttribute> > attributes; // COMPACT 617 auto_ptr<list<auto_ptr<Element> > > preamble; 618 auto_ptr<list<auto_ptr<DefinitionListItem> > > items; 619 620 /*virtual*/ void unparse(ostream &, ostream_manipulator separator) const; 621 /*virtual*/ Area *format(Area::size_type w, int halign) const; 622 }; 623 624 /* ------------------------------------------------------------------------- */ 625 626 #endif /* } */ 627 628 /* ------------------------------------------------------------------------- */ 629 630