[BACK] Return to HTML.c CVS log [TXT] [DIR] Up to [Public] / libwww / Library / src

Annotation of libwww/Library/src/HTML.c, revision 1.67

1.39 frystyk 1: /*                                   HTML.c
 2: **   STRUCTURED STREAM TO RICH HYPERTEXT CONVERTER
 3: **
1.43 frystyk 4: **   (c) COPYRIGHT MIT 1995.
1.39 frystyk 5: **   Please first read the full copyright statement in the file COPYRIGH.
1.67 ! frystyk 6: **   @(#) $Id: HTML.c,v 1.66 1997年02月16日 17:49:21 frystyk Exp $
1.1 timbl 7: **
1.2 timbl 8: **   This generates of a hypertext object. It converts from the
 9: **   structured stream interface fro HTMl events into the style-
1.47 frystyk 10: **   oriented iunterface of the HText interface. This module is
1.2 timbl 11: **   only used in clients and shouldnot be linked into servers.
1.1 timbl 12: **
1.6 timbl 13: **   Override this module if making a new GUI browser.
1.1 timbl 14: **
1.35 duns 15: ** HISTORY:
 16: **   8 Jul 94 FM  Insulate free() from _free structure element.
 17: **
1.1 timbl 18: */
1.16 timbl 19: 
1.41 frystyk 20: /* Library include files */
1.60 frystyk 21: #include "sysdep.h"
1.63 frystyk 22: #include "WWWUtil.h"
 23: #include "WWWCore.h"
 24: #include "WWWHTML.h"
1.1 timbl 25: #include "HText.h"
 26: #include "HTStyle.h"
1.41 frystyk 27: #include "HTML.h"
1.1 timbl 28: 
 29: extern HTStyleSheet * styleSheet;   /* Application-wide */
 30: 
 31: /*   Module-wide style cache
 32: */
 33: PRIVATE int      got_styles = 0;
1.16 timbl 34: PRIVATE HTStyle *styles[HTMLP_ELEMENTS];
1.2 timbl 35: PRIVATE HTStyle *default_style;
1.1 timbl 36: 
1.62 frystyk 37: #define TAB  '0円'
1.1 timbl 38: 
 39: /*       HTML Object
 40: **       -----------
 41: */
1.2 timbl 42: #define MAX_NESTING 20     /* Should be checked by parser */
 43: 
 44: typedef struct _stack_element {
 45:     HTStyle *   style;
 46:    int       tag_number;
 47: } stack_element;
 48: 
 49: struct _HTStructured {
1.60 frystyk 50:   const HTStructuredClass * isa;
1.54 frystyk 51:   HTRequest *            request;
1.2 timbl 52:   HTParentAnchor *      node_anchor;
 53:   HText *          text;
 54: 
 55:   HTStream*         target;         /* Output stream */
 56:   HTStreamClass       targetClass;      /* Output routines */
 57: 
1.56 frystyk 58:   HTChunk *         title;     /* Grow by 128 */
1.2 timbl 59:   
 60:   char *           comment_start; /* for literate programming */
 61:   char *           comment_end;
1.16 timbl 62:   
1.60 frystyk 63:   const SGML_dtd*      dtd;
1.16 timbl 64:   
1.2 timbl 65:   HTTag *          current_tag;
 66:   BOOL            style_change;
 67:   HTStyle *         new_style;
 68:   HTStyle *         old_style;
 69:   BOOL            in_word; /* Have just had a non-white char */
1.44 frystyk 70: 
 71:   stack_element       stack[MAX_NESTING];
 72:   stack_element       *sp;         /* Style stack pointer */
 73:   int                overflow; /* Keep track of overflow nesting */
1.1 timbl 74: };
 75: 
1.2 timbl 76: struct _HTStream {
1.60 frystyk 77:   const HTStreamClass *   isa;
1.2 timbl 78:   /* .... */
 79: };
1.1 timbl 80: 
 81: /*       Forward declarations of routines
 82: */
1.52 frystyk 83: PRIVATE void get_styles (void);
1.1 timbl 84: 
 85: 
1.52 frystyk 86: PRIVATE void actually_set_style (HTStructured * me);
 87: PRIVATE void change_paragraph_style (HTStructured * me, HTStyle * style);
1.1 timbl 88: 
 89: /*   Style buffering avoids dummy paragraph begin/ends.
 90: */
1.4 timbl 91: #define UPDATE_STYLE if (me->style_change) { actually_set_style(me); }
1.1 timbl 92: 
1.2 timbl 93: /*   Entity values -- for ISO Latin 1 local representation
 94: **
 95: **   This MUST match exactly the table referred to in the DTD!
 96: */
 97: static char * ISO_Latin1[] = {
 98:    "306円", /* capital AE diphthong (ligature) */ 
 99:    "301円", /* capital A, acute accent */ 
 100:    "302円", /* capital A, circumflex accent */ 
 101:    "300円", /* capital A, grave accent */ 
 102:    "305円", /* capital A, ring */ 
 103:    "303円", /* capital A, tilde */ 
 104:    "304円", /* capital A, dieresis or umlaut mark */ 
 105:    "307円", /* capital C, cedilla */ 
 106:    "320円", /* capital Eth, Icelandic */ 
 107:    "311円", /* capital E, acute accent */ 
 108:    "312円", /* capital E, circumflex accent */ 
 109:    "310円", /* capital E, grave accent */ 
 110:    "313円", /* capital E, dieresis or umlaut mark */ 
 111:    "315円", /* capital I, acute accent */ 
 112:    "316円", /* capital I, circumflex accent */ 
 113:    "314円", /* capital I, grave accent */ 
 114:    "317円", /* capital I, dieresis or umlaut mark */ 
 115:    "321円", /* capital N, tilde */ 
 116:    "323円", /* capital O, acute accent */ 
 117:    "324円", /* capital O, circumflex accent */ 
 118:    "322円", /* capital O, grave accent */ 
 119:    "330円", /* capital O, slash */ 
 120:    "325円", /* capital O, tilde */ 
 121:    "326円", /* capital O, dieresis or umlaut mark */ 
 122:    "336円", /* capital THORN, Icelandic */ 
 123:    "332円", /* capital U, acute accent */ 
 124:    "333円", /* capital U, circumflex accent */ 
 125:    "331円", /* capital U, grave accent */ 
 126:    "334円", /* capital U, dieresis or umlaut mark */ 
 127:    "335円", /* capital Y, acute accent */ 
 128:    "341円", /* small a, acute accent */ 
 129:    "342円", /* small a, circumflex accent */ 
 130:    "346円", /* small ae diphthong (ligature) */ 
 131:    "340円", /* small a, grave accent */ 
 132:    "046円", /* ampersand */ 
 133:    "345円", /* small a, ring */ 
 134:    "343円", /* small a, tilde */ 
 135:    "344円", /* small a, dieresis or umlaut mark */ 
 136:    "347円", /* small c, cedilla */ 
 137:    "351円", /* small e, acute accent */ 
 138:    "352円", /* small e, circumflex accent */ 
 139:    "350円", /* small e, grave accent */ 
 140:    "360円", /* small eth, Icelandic */ 
 141:    "353円", /* small e, dieresis or umlaut mark */ 
 142:    "076円", /* greater than */ 
 143:    "355円", /* small i, acute accent */ 
 144:    "356円", /* small i, circumflex accent */ 
 145:    "354円", /* small i, grave accent */ 
 146:    "357円", /* small i, dieresis or umlaut mark */ 
 147:    "074円", /* less than */ 
1.62 frystyk 148:    "040円", /* non-breaking space */
1.2 timbl 149:    "361円", /* small n, tilde */ 
 150:    "363円", /* small o, acute accent */ 
 151:    "364円", /* small o, circumflex accent */ 
 152:    "362円", /* small o, grave accent */ 
 153:    "370円", /* small o, slash */ 
 154:    "365円", /* small o, tilde */ 
 155:    "366円", /* small o, dieresis or umlaut mark */ 
1.36 frystyk 156:     "042円", /* double quote sign - June 94 */
1.2 timbl 157:    "337円", /* small sharp s, German (sz ligature) */ 
 158:    "376円", /* small thorn, Icelandic */ 
 159:    "372円", /* small u, acute accent */ 
 160:    "373円", /* small u, circumflex accent */ 
 161:    "371円", /* small u, grave accent */ 
 162:    "374円", /* small u, dieresis or umlaut mark */ 
 163:    "375円", /* small y, acute accent */ 
 164:    "377円", /* small y, dieresis or umlaut mark */ 
1.1 timbl 165: };
 166: 
1.2 timbl 167: 
 168: /*   Entity values -- for NeXT local representation
 169: **
 170: **   This MUST match exactly the table referred to in the DTD!
 171: **
 172: */
 173: static char * NeXTCharacters[] = {
 174:    "341円", /* capital AE diphthong (ligature)   */ 
 175:    "202円", /* capital A, acute accent       */ 
 176:    "203円", /* capital A, circumflex accent     */ 
 177:    "201円", /* capital A, grave accent       */ 
 178:    "206円", /* capital A, ring           */ 
 179:    "204円", /* capital A, tilde           */ 
 180:    "205円", /* capital A, dieresis or umlaut mark  */ 
 181:    "207円", /* capital C, cedilla          */ 
 182:    "220円", /* capital Eth, Icelandic        */ 
 183:    "211円", /* capital E, acute accent               */ 
 184:    "212円", /* capital E, circumflex accent             */ 
 185:    "210円", /* capital E, grave accent               */ 
 186:    "213円", /* capital E, dieresis or umlaut mark          */ 
 187:    "215円", /* capital I, acute accent               */ 
 188:    "216円", /* capital I, circumflex accent     these are    */ 
 189:    "214円", /* capital I, grave accent       ISO -100 hex  */ 
 190:    "217円", /* capital I, dieresis or umlaut mark          */ 
 191:    "221円", /* capital N, tilde                   */ 
 192:    "223円", /* capital O, acute accent               */ 
 193:    "224円", /* capital O, circumflex accent             */ 
 194:    "222円", /* capital O, grave accent               */ 
 195:    "351円", /* capital O, slash       'cept this */ 
 196:    "225円", /* capital O, tilde                   */ 
 197:    "226円", /* capital O, dieresis or umlaut mark          */ 
 198:    "234円", /* capital THORN, Icelandic */ 
 199:    "230円", /* capital U, acute accent */ 
 200:    "231円", /* capital U, circumflex accent */ 
 201:    "227円", /* capital U, grave accent */ 
 202:    "232円", /* capital U, dieresis or umlaut mark */ 
 203:    "233円", /* capital Y, acute accent */ 
 204:    "326円", /* small a, acute accent */ 
 205:    "327円", /* small a, circumflex accent */ 
 206:    "361円", /* small ae diphthong (ligature) */ 
 207:    "325円", /* small a, grave accent */ 
 208:    "046円", /* ampersand */ 
 209:    "332円", /* small a, ring */ 
 210:    "330円", /* small a, tilde */ 
 211:    "331円", /* small a, dieresis or umlaut mark */ 
 212:    "333円", /* small c, cedilla */ 
 213:    "335円", /* small e, acute accent */ 
 214:    "336円", /* small e, circumflex accent */ 
 215:    "334円", /* small e, grave accent */ 
 216:    "346円", /* small eth, Icelandic     */ 
 217:    "337円", /* small e, dieresis or umlaut mark */ 
 218:    "076円", /* greater than */ 
 219:    "342円", /* small i, acute accent */ 
 220:    "344円", /* small i, circumflex accent */ 
 221:    "340円", /* small i, grave accent */ 
 222:    "345円", /* small i, dieresis or umlaut mark */ 
 223:    "074円", /* less than */ 
1.62 frystyk 224:    "040円", /* non-breaking space */
1.2 timbl 225:    "347円", /* small n, tilde */ 
 226:    "355円", /* small o, acute accent */ 
 227:    "356円", /* small o, circumflex accent */ 
 228:    "354円", /* small o, grave accent */ 
 229:    "371円", /* small o, slash */ 
 230:    "357円", /* small o, tilde */ 
 231:    "360円", /* small o, dieresis or umlaut mark */ 
1.36 frystyk 232:     "042円", /* double quote sign - June 94 */
1.2 timbl 233:    "373円", /* small sharp s, German (sz ligature) */ 
 234:    "374円", /* small thorn, Icelandic */ 
 235:    "363円", /* small u, acute accent */ 
 236:    "364円", /* small u, circumflex accent */ 
 237:    "362円", /* small u, grave accent */ 
 238:    "366円", /* small u, dieresis or umlaut mark */ 
 239:    "367円", /* small y, acute accent */ 
 240:    "375円", /* small y, dieresis or umlaut mark */ 
1.1 timbl 241: };
 242: 
1.2 timbl 243: /*   Entity values -- for IBM/PC Code Page 850 (International)
 244: **
 245: **   This MUST match exactly the table referred to in the DTD!
 246: **
 247: */
 248: /* @@@@@@@@@@@@@@@@@ TBD */
 249: 
 250: 
 251: 
 252: /*       Set character set
 253: **       ----------------
 254: */
 255: 
 256: PRIVATE char** p_entity_values = ISO_Latin1;  /* Pointer to translation */
1.1 timbl 257: 
1.53 frystyk 258: PUBLIC void HTMLUseCharacterSet (HTMLCharacterSet i)
1.2 timbl 259: {
 260:   p_entity_values = (i == HTML_NEXT_CHARS) ? NeXTCharacters
 261:                       : ISO_Latin1;
 262: }
1.1 timbl 263: 
 264: 
 265: /*       Flattening the style structure
 266: **       ------------------------------
 267: **
 268: On the NeXT, and on any read-only browser, it is simpler for the text to have
 269: a sequence of styles, rather than a nested tree of styles. In this
 270: case we have to flatten the structure as it arrives from SGML tags into
 271: a sequence of styles.
 272: */
 273: 
 274: /*       If style really needs to be set, call this
 275: */
1.53 frystyk 276: PRIVATE void actually_set_style (HTStructured * me)
1.1 timbl 277: {
1.4 timbl 278:   if (!me->text) {          /* First time through */
1.54 frystyk 279:      me->text = HText_new2(me->request, me->node_anchor, me->target);
1.4 timbl 280:      HText_beginAppend(me->text);
 281:      HText_setStyle(me->text, me->new_style);
 282:      me->in_word = NO;
1.1 timbl 283:   } else {
1.4 timbl 284:      HText_setStyle(me->text, me->new_style);
1.1 timbl 285:   }
1.4 timbl 286:   me->old_style = me->new_style;
 287:   me->style_change = NO;
1.1 timbl 288: }
 289: 
 290: /*   If you THINK you need to change style, call this
 291: */
 292: 
1.53 frystyk 293: PRIVATE void change_paragraph_style (HTStructured * me, HTStyle *style)
1.1 timbl 294: {
1.4 timbl 295:   if (me->new_style!=style) {
 296:    me->style_change = YES;
 297:    me->new_style = style;
1.1 timbl 298:   }
1.11 timbl 299:   me->in_word = NO;
1.1 timbl 300: }
 301: 
1.2 timbl 302: /*_________________________________________________________________________
 303: **
 304: **           A C T I O N   R O U T I N E S
 305: */
 306: 
1.64 frystyk 307: PRIVATE int HTML_put_character (HTStructured * me, char c)
1.1 timbl 308: {
1.4 timbl 309:   switch (me->sp[0].tag_number) {
1.2 timbl 310:   case HTML_COMMENT:
 311:    break;                 /* Do Nothing */
 312:    
 313:   case HTML_TITLE:  
1.56 frystyk 314:    HTChunk_putb(me->title, &c, 1);
1.2 timbl 315:    break;
 316: 
 317:    
 318:   case HTML_LISTING:             /* Litteral text */
 319:   case HTML_XMP:
 320:   case HTML_PLAINTEXT:
 321:   case HTML_PRE:
 322: /*   We guarrantee that the style is up-to-date in begin_litteral
 323: */
1.4 timbl 324:    HText_appendCharacter(me->text, c);
1.2 timbl 325:    break;
 326:    
 327:   default:                  /* Free format text */
1.4 timbl 328:    if (me->style_change) {
1.42 frystyk 329:      if ((c=='\n') || (c==' ')) return HT_OK;  /* Ignore it */
1.2 timbl 330:      UPDATE_STYLE;
 331:    }
1.62 frystyk 332:    if (c == TAB)
 333:      HText_appendCharacter(me->text, '\t');
 334:    else if (WHITE(c)) {
1.4 timbl 335:      if (me->in_word) {
 336:        HText_appendCharacter(me->text, ' ');
 337:        me->in_word = NO;
1.2 timbl 338:      }
 339:    } else {
1.4 timbl 340:      HText_appendCharacter(me->text, c);
 341:      me->in_word = YES;
1.2 timbl 342:    }
 343:   } /* end switch */
1.42 frystyk 344:   return HT_OK;
1.1 timbl 345: }
 346: 
1.64 frystyk 347: 
 348: PRIVATE int HTML_write (HTStructured * me, const char * b, int l)
1.1 timbl 349: {
1.64 frystyk 350:   while (l-- > 0) HTML_put_character(me, *b++);
 351:   return HT_OK;
1.1 timbl 352: }
 353: 
1.64 frystyk 354: PRIVATE int HTML_put_string (HTStructured * me, const char* s)
1.1 timbl 355: {
1.64 frystyk 356:   while (*s) HTML_put_character(me, *s++);
 357:   return HT_OK;
1.1 timbl 358: }
1.2 timbl 359: 
 360: /*   Start Element
 361: **   -------------
 362: */
1.53 frystyk 363: PRIVATE void HTML_start_element (
 364:    HTStructured * me,
 365:    int           element_number,
1.60 frystyk 366:    const BOOL*       present,
 367:    const char **      value)
1.2 timbl 368: {
 369:   switch (element_number) {
 370:   case HTML_A:
 371:    {
1.8 timbl 372:      HTChildAnchor * source;
1.9 timbl 373:      char * href = NULL;
1.42 frystyk 374:      if (present[HTML_A_HREF])
1.9 timbl 375:        StrAllocCopy(href, value[HTML_A_HREF]);
1.8 timbl 376:      source = HTAnchor_findChildAndLink(
1.4 timbl 377:        me->node_anchor,                /* parent */
1.2 timbl 378:        present[HTML_A_NAME] ? value[HTML_A_NAME] : 0, /* Tag */
1.9 timbl 379:        present[HTML_A_HREF] ? href : 0,        /* Addresss */
1.16 timbl 380:        present[HTML_A_REL] && value[HTML_A_REL] ? 
1.54 frystyk 381:            (HTLinkType) HTAtom_for(value[HTML_A_REL])
 382:                        : 0);
1.2 timbl 383:      
1.63 frystyk 384:      if (present[HTML_A_TITLE] && value[HTML_A_TITLE]) {     
 385:        HTLink * link = HTAnchor_mainLink((HTAnchor *) source);
 386:        HTParentAnchor *dest=HTAnchor_parent(HTLink_destination(link));
1.2 timbl 387:        if (!HTAnchor_title(dest))
 388:            HTAnchor_setTitle(dest, value[HTML_A_TITLE]);
 389:      }
 390:      UPDATE_STYLE;
1.4 timbl 391:      HText_beginAnchor(me->text, source);
1.58 frystyk 392:      HT_FREE(href);           /* Leak fix Henrik 17/02-94 */
1.2 timbl 393:    }
 394:    break;
 395:    
1.63 frystyk 396:   case HTML_LINK:
 397: 
 398:    /* MORE */
 399: 
 400:    break;
 401: 
1.2 timbl 402:   case HTML_TITLE:
1.56 frystyk 403:     HTChunk_clear(me->title);
1.2 timbl 404:    break;
 405:    
 406:   case HTML_NEXTID:
 407:    /* if (present[NEXTID_N] && value[NEXTID_N])
1.4 timbl 408:        HText_setNextId(me->text, atoi(value[NEXTID_N])); */
1.2 timbl 409:    break;
 410:    
 411:   case HTML_ISINDEX:
1.4 timbl 412:    HTAnchor_setIndex(me->node_anchor);
1.2 timbl 413:    break;
 414:    
1.15 timbl 415:   case HTML_BR: 
 416:    UPDATE_STYLE;
 417:    HText_appendCharacter(me->text, '\n');
 418:    me->in_word = NO;
 419:    break;
 420:    
 421:   case HTML_HR: 
 422:    UPDATE_STYLE;
 423:    HText_appendCharacter(me->text, '\n');
1.16 timbl 424:    HText_appendText(me->text, "___________________________________");
1.15 timbl 425:    HText_appendCharacter(me->text, '\n');
 426:    me->in_word = NO;
 427:    break;
 428:    
1.2 timbl 429:   case HTML_P:
 430:    UPDATE_STYLE;
1.4 timbl 431:    HText_appendParagraph(me->text);
 432:    me->in_word = NO;
1.2 timbl 433:    break;
 434: 
 435:   case HTML_DL:
1.11 timbl 436:     change_paragraph_style(me, present && present[DL_COMPACT]
1.16 timbl 437:        ? styles[HTML_DL]
1.2 timbl 438:        : styles[HTML_DL]);
 439:    break;
 440:    
 441:   case HTML_DT:
1.4 timbl 442:     if (!me->style_change) {
 443:      HText_appendParagraph(me->text);
 444:      me->in_word = NO;
1.2 timbl 445:    }
 446:    break;
 447:    
 448:   case HTML_DD:
 449:     UPDATE_STYLE;
1.62 frystyk 450:    HTML_put_character(me, TAB);  /* Just tab out one stop */
1.4 timbl 451:    me->in_word = NO;
 452:    break;
1.2 timbl 453: 
 454:   case HTML_UL:
 455:   case HTML_OL:
 456:   case HTML_MENU:
 457:   case HTML_DIR:
1.11 timbl 458:    change_paragraph_style(me, styles[element_number]);
1.2 timbl 459:    break;
 460:    
 461:   case HTML_LI:
 462:     UPDATE_STYLE;
1.7 timbl 463:    if (me->sp[0].tag_number != HTML_DIR)
1.4 timbl 464:      HText_appendParagraph(me->text);
1.2 timbl 465:    else
1.62 frystyk 466:      HText_appendCharacter(me->text, TAB);
1.4 timbl 467:    me->in_word = NO;
1.2 timbl 468:    break;
 469:    
 470:   case HTML_LISTING:             /* Litteral text */
 471:   case HTML_XMP:
 472:   case HTML_PLAINTEXT:
 473:   case HTML_PRE:
1.11 timbl 474:    change_paragraph_style(me, styles[element_number]);
1.2 timbl 475:    UPDATE_STYLE;
1.4 timbl 476:    if (me->comment_end)
 477:      HText_appendText(me->text, me->comment_end);
1.2 timbl 478:    break;
1.11 timbl 479: 
1.23 frystyk 480:   case HTML_IMG:           /* Images */
 481:    {
 482:      HTChildAnchor *source;
 483:      char *src = NULL;
1.49 frystyk 484:      if (present[HTML_IMG_SRC])
1.23 frystyk 485:        StrAllocCopy(src, value[HTML_IMG_SRC]);
 486:      source = HTAnchor_findChildAndLink(
 487:                        me->node_anchor,  /* parent */
 488:                        0,           /* Tag */
 489:                        src ? src : 0,  /* Addresss */
 490:                        0);
 491:      UPDATE_STYLE;
 492:      HText_appendImage(me->text, source,
1.24 frystyk 493:           present[HTML_IMG_ALT] ? value[HTML_IMG_ALT] : NULL,
 494:           present[HTML_IMG_ALIGN] ? value[HTML_IMG_ALIGN] : NULL,
 495:           present[HTML_IMG_ISMAP] ? YES : NO);
1.58 frystyk 496:      HT_FREE(src);
1.24 frystyk 497:    }    
 498:    break;
 499: 
1.63 frystyk 500:   case HTML_BASE:          /* Base header */
 501:    if (present[HTML_BASE_HREF]) {
 502:     char * base = (char *) value[HTML_BASE_HREF];
 503:     if (base) {
 504:       HTAnchor_setBase(me->node_anchor, base);
 505:       if (SGML_TRACE) HTTrace("HTML Parser. New base `%s\'\n", base);
 506:     } else {
 507:       if (SGML_TRACE) HTTrace("HTML Parser. No base found\n");
 508:     }
 509:    }
 510:    break;
 511: 
1.24 frystyk 512:   case HTML_HTML:          /* Ignore these altogether */
 513:   case HTML_HEAD:
 514:   case HTML_BODY:
1.62 frystyk 515:    break;
1.24 frystyk 516:   
1.10 timbl 517:   case HTML_TT:           /* Physical character highlighting */
 518:   case HTML_B:            /* Currently ignored */
 519:   case HTML_I:
 520:   case HTML_U:
1.62 frystyk 521:    UPDATE_STYLE;
1.65 frystyk 522: #if 0
1.62 frystyk 523:    HText_appendCharacter(me->text, '_');
1.65 frystyk 524: #endif
1.62 frystyk 525:    me->in_word = NO;
 526:    break;
1.10 timbl 527:   
 528:   case HTML_EM:           /* Logical character highlighting */
 529:   case HTML_STRONG:         /* Currently ignored */
 530:   case HTML_CODE:
 531:   case HTML_SAMP:
 532:   case HTML_KBD:
 533:   case HTML_VAR:
 534:   case HTML_DFN:
 535:   case HTML_CITE:
 536:    break;
 537:    
1.11 timbl 538:   case HTML_H1:           /* paragraph styles */
 539:   case HTML_H2:
 540:   case HTML_H3:
 541:   case HTML_H4:
 542:   case HTML_H5:
 543:   case HTML_H6:
 544:   case HTML_H7:
 545:   case HTML_ADDRESS:
 546:   case HTML_BLOCKQUOTE:
 547:    change_paragraph_style(me, styles[element_number]);   /* May be postponed */
1.2 timbl 548:    break;
 549: 
 550:   } /* end switch */
 551: 
1.16 timbl 552:   if (me->dtd->tags[element_number].contents!= SGML_EMPTY) {
1.13 timbl 553:     if (me->sp == me->stack) {
1.44 frystyk 554:      if (SGML_TRACE)
1.63 frystyk 555:        HTTrace("HTML Parser. Maximum nesting of %d exceded!\n",
1.44 frystyk 556:            MAX_NESTING); 
 557:      me->overflow++;
1.12 timbl 558:      return;
 559:    }
1.4 timbl 560:    --(me->sp);
 561:    me->sp[0].style = me->new_style;    /* Stack new style */
 562:    me->sp[0].tag_number = element_number;
1.10 timbl 563:   } 
1.1 timbl 564: }
1.10 timbl 565: 
1.2 timbl 566: 
1.1 timbl 567: /*       End Element
1.2 timbl 568: **       -----------
1.1 timbl 569: **
1.2 timbl 570: */
 571: /*   When we end an element, the style must be returned to that
1.1 timbl 572: **   in effect before that element. Note that anchors (etc?)
 573: **   don't have an associated style, so that we must scan down the
 574: **   stack for an element with a defined style. (In fact, the styles
 575: **   should be linked to the whole stack not just the top one.)
 576: **   TBL 921119
1.6 timbl 577: **
 578: **   We don't turn on "CAREFUL" check because the parser produces
 579: **   (internal code errors apart) good nesting. The parser checks
 580: **   incoming code errors, not this module.
1.1 timbl 581: */
1.53 frystyk 582: PRIVATE void HTML_end_element (HTStructured * me, int element_number)
1.1 timbl 583: {
1.2 timbl 584: #ifdef CAREFUL         /* parser assumed to produce good nesting */
1.4 timbl 585:   if (element_number != me->sp[0].tag_number) {
1.59 eric 586:     HTTrace("HTMLText: end of element %s when expecting end of %s\n",
1.16 timbl 587:        me->dtd->tags[element_number].name,
 588:        me->dtd->tags[me->sp->tag_number].name);
1.6 timbl 589:        /* panic */
1.1 timbl 590:   }
1.2 timbl 591: #endif
1.44 frystyk 592: 
 593:   /* HFN, If overflow of nestings, we need to get back to reality */
 594:   if (me->overflow > 0) {
 595:    me->overflow--;
 596:    return;
 597:   }
 598: 
1.4 timbl 599:   me->sp++;             /* Pop state off stack */
1.67 ! frystyk 600:   if (me->sp > me->stack + MAX_NESTING - 1) {
 ! 601:    if (SGML_TRACE) HTTrace("HTML Parser. Bottom of style stack reached\n");
 ! 602:    me->sp = me->stack + MAX_NESTING - 1;
 ! 603:   }
1.44 frystyk 604: 
1.2 timbl 605:   switch(element_number) {
 606: 
 607:   case HTML_A:
 608:    UPDATE_STYLE;
1.4 timbl 609:    HText_endAnchor(me->text);
1.2 timbl 610:    break;
 611: 
 612:   case HTML_TITLE:
1.56 frystyk 613:    HTAnchor_setTitle(me->node_anchor, HTChunk_data(me->title));
1.2 timbl 614:    break;
 615:    
1.62 frystyk 616:   case HTML_TT:           /* Physical character highlighting */
 617:   case HTML_B:            /* Currently ignored */
 618:   case HTML_I:
 619:   case HTML_U:
 620:    UPDATE_STYLE;
1.66 frystyk 621: #if 0
1.62 frystyk 622:    HText_appendCharacter(me->text, '_');
1.66 frystyk 623: #endif
1.62 frystyk 624:    break;
1.66 frystyk 625: 
 626:   case HTML_EM:           /* Logical character highlighting */
 627:   case HTML_STRONG:         /* Currently ignored */
 628:   case HTML_CODE:
 629:   case HTML_SAMP:
 630:   case HTML_KBD:
 631:   case HTML_VAR:
 632:   case HTML_DFN:
 633:   case HTML_CITE:
 634:    break;
1.62 frystyk 635:   
1.2 timbl 636:   case HTML_LISTING:             /* Litteral text */
 637:   case HTML_XMP:
 638:   case HTML_PLAINTEXT:
 639:   case HTML_PRE:
1.4 timbl 640:    if (me->comment_start)
 641:      HText_appendText(me->text, me->comment_start);
1.2 timbl 642:    /* Fall through */
 643:    
 644:   default:
1.44 frystyk 645: 
 646:    /* Often won't really change */
 647:    change_paragraph_style(me, me->sp->style);
1.2 timbl 648:    break;
 649:    
 650:   } /* switch */
1.1 timbl 651: }
 652: 
1.2 timbl 653: 
 654: /*       Expanding entities
 655: **       ------------------
 656: */
 657: /*   (In fact, they all shrink!)
1.1 timbl 658: */
1.2 timbl 659: 
1.53 frystyk 660: PRIVATE void HTML_put_entity (HTStructured * me, int entity_number)
1.1 timbl 661: {
1.4 timbl 662:   HTML_put_string(me, ISO_Latin1[entity_number]);  /* @@ Other representations */
1.1 timbl 663: }
1.2 timbl 664: 
1.42 frystyk 665: /*   Flush an HTML object
 666: **   --------------------
 667: */
1.53 frystyk 668: PUBLIC int HTML_flush (HTStructured * me)
1.42 frystyk 669: {
 670:   UPDATE_STYLE;              /* Creates empty document here! */
1.57 frystyk 671:   if (me->comment_end) HTML_put_string(me,me->comment_end);
 672:   return me->target ? (*me->targetClass.flush)(me->target) : HT_OK;
1.42 frystyk 673: }
1.2 timbl 674: 
 675: /*   Free an HTML object
 676: **   -------------------
 677: **
1.4 timbl 678: ** If the document is empty, the text object will not yet exist.
 679:  So we could in fact abandon creating the document and return
 680:  an error code. In fact an empty document is an important type
 681:  of document, so we don't.
 682: **
 683: **   If non-interactive, everything is freed off.  No: crashes -listrefs
1.2 timbl 684: **   Otherwise, the interactive object is left.   
 685: */
1.53 frystyk 686: PUBLIC int HTML_free (HTStructured * me)
1.1 timbl 687: {
1.4 timbl 688:   UPDATE_STYLE;       /* Creates empty document here! */
 689:   if (me->comment_end)
 690:        HTML_put_string(me,me->comment_end);
 691:   HText_endAppend(me->text);
 692: 
 693:   if (me->target) {
1.35 duns 694:     (*me->targetClass._free)(me->target);
1.2 timbl 695:   }
1.56 frystyk 696:   HTChunk_delete(me->title);
1.58 frystyk 697:   HT_FREE(me);
1.42 frystyk 698:   return HT_OK;
1.1 timbl 699: }
 700: 
 701: 
1.53 frystyk 702: PRIVATE int HTML_abort (HTStructured * me, HTList * e)
1.1 timbl 703: 
1.14 timbl 704: {
 705:   if (me->target) {
 706:     (*me->targetClass.abort)(me->target, e);
 707:   }
1.56 frystyk 708:   HTChunk_delete(me->title);
1.58 frystyk 709:   HT_FREE(me);
1.42 frystyk 710:   return HT_ERROR;
1.1 timbl 711: }
 712: 
1.2 timbl 713: 
 714: /*   Get Styles from style sheet
 715: **   ---------------------------
 716: */
1.53 frystyk 717: PRIVATE void get_styles (void)
1.1 timbl 718: {
1.2 timbl 719:   got_styles = YES;
 720:   
 721:   default_style =      HTStyleNamed(styleSheet, "Normal");
1.1 timbl 722: 
1.2 timbl 723:   styles[HTML_H1] =     HTStyleNamed(styleSheet, "Heading1");
 724:   styles[HTML_H2] =     HTStyleNamed(styleSheet, "Heading2");
 725:   styles[HTML_H3] =     HTStyleNamed(styleSheet, "Heading3");
 726:   styles[HTML_H4] =     HTStyleNamed(styleSheet, "Heading4");
 727:   styles[HTML_H5] =     HTStyleNamed(styleSheet, "Heading5");
 728:   styles[HTML_H6] =     HTStyleNamed(styleSheet, "Heading6");
 729:   styles[HTML_H7] =     HTStyleNamed(styleSheet, "Heading7");
 730: 
 731:   styles[HTML_DL] =     HTStyleNamed(styleSheet, "Glossary");
 732:   styles[HTML_UL] =
 733:   styles[HTML_OL] =     HTStyleNamed(styleSheet, "List");
 734:   styles[HTML_MENU] =        HTStyleNamed(styleSheet, "Menu");
 735:   styles[HTML_DIR] =     HTStyleNamed(styleSheet, "Dir");  
1.16 timbl 736: /* styles[HTML_DLC] =     HTStyleNamed(styleSheet, "GlossaryCompact"); */
1.2 timbl 737:   styles[HTML_ADDRESS]=   HTStyleNamed(styleSheet, "Address");
 738:   styles[HTML_BLOCKQUOTE]=  HTStyleNamed(styleSheet, "BlockQuote");
 739:   styles[HTML_PLAINTEXT] =
 740:   styles[HTML_XMP] =     HTStyleNamed(styleSheet, "Example");
 741:   styles[HTML_PRE] =     HTStyleNamed(styleSheet, "Preformatted");
 742:   styles[HTML_LISTING] =   HTStyleNamed(styleSheet, "Listing");
 743: }
 744: /*               P U B L I C
 745: */
 746: 
 747: /*   Structured Object Class
 748: **   -----------------------
 749: */
1.60 frystyk 750: PRIVATE const HTStructuredClass HTMLPresentation = /* As opposed to print etc */
1.2 timbl 751: {       
 752:    "text/html",
1.42 frystyk 753:    HTML_flush,
1.2 timbl 754:    HTML_free,
1.14 timbl 755:    HTML_abort,
1.2 timbl 756:    HTML_put_character,   HTML_put_string, HTML_write,
 757:    HTML_start_element,   HTML_end_element,
 758:    HTML_put_entity
 759: }; 
1.1 timbl 760: 
1.4 timbl 761: 
1.2 timbl 762: /*       New Structured Text object
 763: **       --------------------------
 764: **
1.16 timbl 765: **   The structured stream can generate either presentation,
1.4 timbl 766: **   or plain text, or HTML.
1.1 timbl 767: */
1.53 frystyk 768: PRIVATE HTStructured* HTML_new (HTRequest *  request,
 769:                   void *       param,
 770:                   HTFormat      input_format,
 771:                   HTFormat      output_format,
 772:                   HTStream * output_stream)
1.1 timbl 773: {
 774: 
1.4 timbl 775:   HTStructured * me;
 776:   
1.47 frystyk 777: #if 0
1.16 timbl 778:   if (output_format != WWW_PLAINTEXT
 779:    && output_format != WWW_PRESENT
 780:    && output_format != HTAtom_for("text/x-c")) {
1.37 frystyk 781:     HTStream * intermediate = HTStreamStack(WWW_HTML, output_format,
 782:                        output_stream, request, NO);
1.6 timbl 783:    if (intermediate) return HTMLGenerator(intermediate);
1.44 frystyk 784:    if (SGML_TRACE)
1.63 frystyk 785:      HTTrace("HTML Parser. Can't parse HTML to %s\n",
1.44 frystyk 786:          HTAtom_name(output_format));
1.4 timbl 787:    exit (-99);
 788:   }
1.47 frystyk 789: #endif
1.4 timbl 790: 
1.58 frystyk 791:   if ((me = (HTStructured *) HT_CALLOC(1, sizeof(*me))) == NULL)
 792:     HT_OUTOFMEM("HTML_new");
1.1 timbl 793: 
 794:   if (!got_styles) get_styles();
 795: 
1.4 timbl 796:   me->isa = &HTMLPresentation;
1.47 frystyk 797:   me->dtd = &HTMLP_dtd;
1.54 frystyk 798:   me->request = request;
1.48 frystyk 799:   me->node_anchor = HTRequest_anchor(request);
1.56 frystyk 800:   me->title = HTChunk_new(128);
1.4 timbl 801:   me->text = 0;
 802:   me->style_change = YES; /* Force check leading to text creation */
 803:   me->new_style = default_style;
 804:   me->old_style = 0;
 805:   me->sp = me->stack + MAX_NESTING - 1;
 806:   me->sp->tag_number = -1;              /* INVALID */
 807:   me->sp->style = default_style;           /* INVALID */
1.1 timbl 808:   
1.4 timbl 809:   me->comment_start = NULL;
 810:   me->comment_end = NULL;
1.16 timbl 811:   me->target = output_stream;
 812:   if (output_stream) me->targetClass = *output_stream->isa; /* Copy pointers */
1.1 timbl 813:   
1.4 timbl 814:   return (HTStructured*) me;
1.1 timbl 815: }
 816: 
 817: 
1.2 timbl 818: /*   HTConverter for HTML to plain text
 819: **   ----------------------------------
1.1 timbl 820: **
1.2 timbl 821: **   This will convert from HTML to presentation or plain text.
1.1 timbl 822: */
1.53 frystyk 823: PUBLIC HTStream* HTMLToPlain (
 824:    HTRequest *       request,
 825:    void *         param,
 826:    HTFormat        input_format,
 827:    HTFormat        output_format,
 828:    HTStream *       output_stream)
1.1 timbl 829: {
1.47 frystyk 830:   return SGML_new(&HTMLP_dtd, HTML_new(
1.16 timbl 831:    request, NULL, input_format, output_format, output_stream));
1.1 timbl 832: }
 833: 
 834: 
1.2 timbl 835: /*   HTConverter for HTML to C code
 836: **   ------------------------------
 837: **
1.36 frystyk 838: **   C code is like plain text but all non-preformatted code
1.2 timbl 839: **   is commented out.
 840: **   This will convert from HTML to presentation or plain text.
 841: */
1.53 frystyk 842: PUBLIC HTStream* HTMLToC (
 843:    HTRequest *       request,
 844:    void *         param,
 845:    HTFormat        input_format,
 846:    HTFormat        output_format,
 847:    HTStream *       output_stream)
1.1 timbl 848: {
1.4 timbl 849:   
 850:   HTStructured * html;
 851:   
1.36 frystyk 852:   (*output_stream->isa->put_string)(output_stream, "/* "); /* Before title */
1.16 timbl 853:   html = HTML_new(request, NULL, input_format, output_format, output_stream);
1.45 frystyk 854:   html->comment_start = "\n/* ";
1.47 frystyk 855:   html->dtd = &HTMLP_dtd;
1.2 timbl 856:   html->comment_end = " */\n";    /* Must start in col 1 for cpp */
1.47 frystyk 857:   return SGML_new(&HTMLP_dtd, html);
1.1 timbl 858: }
 859: 
 860: 
1.2 timbl 861: /*   Presenter for HTML
 862: **   ------------------
 863: **
 864: **   This will convert from HTML to presentation or plain text.
 865: **
 866: **   Override this if you have a windows version
1.1 timbl 867: */
1.2 timbl 868: #ifndef GUI
1.53 frystyk 869: PUBLIC HTStream* HTMLPresent (
 870:    HTRequest *       request,
 871:    void *         param,
 872:    HTFormat        input_format,
 873:    HTFormat        output_format,
 874:    HTStream *       output_stream)
1.1 timbl 875: {
1.47 frystyk 876:   return SGML_new(&HTMLP_dtd, HTML_new(
1.16 timbl 877:    request, NULL, input_format, output_format, output_stream));
1.1 timbl 878: }
1.2 timbl 879: #endif
1.29 frystyk 880: 

Webmaster

AltStyle によって変換されたページ (->オリジナル) /