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

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

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

Webmaster

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