Annotation of Amaya/amaya/XHTMLbuilder.c, revision 1.29

1.1       cvs         1: /*
                      2:  *
                      3:  *  (c) COPYRIGHT MIT and INRIA, 1996.
                      4:  *  Please first read the full copyright statement in file COPYRIGHT.
                      5:  *
                      6:  */
                      7: 
                      8: /*
                      9:  *
1.23      cvs        10:  * Builds the corresponding abstract tree for a Thot document of type HTML.
1.1       cvs        11:  *
1.20      cvs        12:  * Authors: L. Carcone
                     13:  *          V. Quint 
1.1       cvs        14:  */
                     15: 
                     16: #define THOT_EXPORT extern
                     17: #include "amaya.h"
                     18: #include "css.h"
1.2       cvs        19: #include "parser.h"
                     20: #include "HTML.h"
                     21: 
1.13      cvs        22: #include "css_f.h"
                     23: #include "fetchXMLname_f.h"
1.22      cvs        24: #include "html2thot_f.h"
1.1       cvs        25: #include "HTMLactions_f.h"
                     26: #include "HTMLedit_f.h"
1.22      cvs        27: #include "HTMLform_f.h"
1.1       cvs        28: #include "HTMLimage_f.h"
                     29: #include "HTMLtable_f.h"
                     30: #include "HTMLimage_f.h"
                     31: #include "UIcss_f.h"
1.13      cvs        32: #include "styleparser_f.h"
1.2       cvs        33: #include "XHTMLbuilder_f.h"
1.13      cvs        34: #include "Xml2thot_f.h"
1.1       cvs        35: 
                     36: /* maximum length of a Thot structure schema name */
                     37: #define MAX_SS_NAME_LENGTH 32
                     38: 
1.14      cvs        39: /* Mapping table of HTML attribute values */
                     40: AttrValueMapping XhtmlAttrValueMappingTable[] =
1.1       cvs        41: {
                     42:    {HTML_ATTR_dir, TEXT("ltr"), HTML_ATTR_dir_VAL_ltr},
                     43:    {HTML_ATTR_dir, TEXT("rtl"), HTML_ATTR_dir_VAL_rtl},
                     44: 
                     45:    {HTML_ATTR_TextAlign, TEXT("left"), HTML_ATTR_TextAlign_VAL_left_},
                     46:    {HTML_ATTR_TextAlign, TEXT("center"), HTML_ATTR_TextAlign_VAL_center_},
                     47:    {HTML_ATTR_TextAlign, TEXT("right"), HTML_ATTR_TextAlign_VAL_right_},
                     48:    {HTML_ATTR_TextAlign, TEXT("justify"), HTML_ATTR_TextAlign_VAL_justify_},
                     49: 
                     50:    {HTML_ATTR_Align, TEXT("left"), HTML_ATTR_Align_VAL_left_},
                     51:    {HTML_ATTR_Align, TEXT("center"), HTML_ATTR_Align_VAL_center_},
                     52:    {HTML_ATTR_Align, TEXT("right"), HTML_ATTR_Align_VAL_right_},
                     53: 
                     54:    {HTML_ATTR_LAlign, TEXT("top"), HTML_ATTR_LAlign_VAL_Top_},
                     55:    {HTML_ATTR_LAlign, TEXT("bottom"), HTML_ATTR_LAlign_VAL_Bottom_},
                     56:    {HTML_ATTR_LAlign, TEXT("left"), HTML_ATTR_LAlign_VAL_Left_},
                     57:    {HTML_ATTR_LAlign, TEXT("right"), HTML_ATTR_LAlign_VAL_Right_},
                     58: 
                     59:    {HTML_ATTR_Clear, TEXT("left"), HTML_ATTR_Clear_VAL_Left_},
                     60:    {HTML_ATTR_Clear, TEXT("right"), HTML_ATTR_Clear_VAL_Right_},
                     61:    {HTML_ATTR_Clear, TEXT("all"), HTML_ATTR_Clear_VAL_All_},
                     62:    {HTML_ATTR_Clear, TEXT("none"), HTML_ATTR_Clear_VAL_None_},
                     63: 
                     64:    {HTML_ATTR_NumberStyle, TEXT("1"), HTML_ATTR_NumberStyle_VAL_Arabic_},
                     65:    {HTML_ATTR_NumberStyle, TEXT("a"), HTML_ATTR_NumberStyle_VAL_LowerAlpha},
                     66:    {HTML_ATTR_NumberStyle, TEXT("A"), HTML_ATTR_NumberStyle_VAL_UpperAlpha},
                     67:    {HTML_ATTR_NumberStyle, TEXT("i"), HTML_ATTR_NumberStyle_VAL_LowerRoman},
                     68:    {HTML_ATTR_NumberStyle, TEXT("I"), HTML_ATTR_NumberStyle_VAL_UpperRoman},
                     69: 
                     70:    {HTML_ATTR_BulletStyle, TEXT("disc"), HTML_ATTR_BulletStyle_VAL_disc},
                     71:    {HTML_ATTR_BulletStyle, TEXT("square"), HTML_ATTR_BulletStyle_VAL_square},
                     72:    {HTML_ATTR_BulletStyle, TEXT("circle"), HTML_ATTR_BulletStyle_VAL_circle},
                     73: 
                     74:    {HTML_ATTR_ItemStyle, TEXT("1"), HTML_ATTR_ItemStyle_VAL_Arabic_},
                     75:    {HTML_ATTR_ItemStyle, TEXT("a"), HTML_ATTR_ItemStyle_VAL_LowerAlpha},
                     76:    {HTML_ATTR_ItemStyle, TEXT("A"), HTML_ATTR_ItemStyle_VAL_UpperAlpha},
                     77:    {HTML_ATTR_ItemStyle, TEXT("i"), HTML_ATTR_ItemStyle_VAL_LowerRoman},
                     78:    {HTML_ATTR_ItemStyle, TEXT("I"), HTML_ATTR_ItemStyle_VAL_UpperRoman},
                     79:    {HTML_ATTR_ItemStyle, TEXT("disc"), HTML_ATTR_ItemStyle_VAL_disc},
                     80:    {HTML_ATTR_ItemStyle, TEXT("square"), HTML_ATTR_ItemStyle_VAL_square},
                     81:    {HTML_ATTR_ItemStyle, TEXT("circle"), HTML_ATTR_ItemStyle_VAL_circle},
                     82: 
                     83:    {HTML_ATTR_Button_type, TEXT("button"), HTML_ATTR_Button_type_VAL_button},
                     84:    {HTML_ATTR_Button_type, TEXT("submit"), HTML_ATTR_Button_type_VAL_submit},
                     85:    {HTML_ATTR_Button_type, TEXT("reset"), HTML_ATTR_Button_type_VAL_reset},
                     86: 
                     87:    {HTML_ATTR_frame, TEXT("void"), HTML_ATTR_frame_VAL_void},
                     88:    {HTML_ATTR_frame, TEXT("above"), HTML_ATTR_frame_VAL_above},
                     89:    {HTML_ATTR_frame, TEXT("below"), HTML_ATTR_frame_VAL_below},
                     90:    {HTML_ATTR_frame, TEXT("hsides"), HTML_ATTR_frame_VAL_hsides},
                     91:    {HTML_ATTR_frame, TEXT("lhs"), HTML_ATTR_frame_VAL_lhs},
                     92:    {HTML_ATTR_frame, TEXT("rhs"), HTML_ATTR_frame_VAL_rhs},
                     93:    {HTML_ATTR_frame, TEXT("vsides"), HTML_ATTR_frame_VAL_vsides},
                     94:    {HTML_ATTR_frame, TEXT("box"), HTML_ATTR_frame_VAL_box},
                     95:    {HTML_ATTR_frame, TEXT("border"), HTML_ATTR_frame_VAL_border},
                     96: 
                     97:    {HTML_ATTR_frameborder, TEXT("0"), HTML_ATTR_frameborder_VAL_Border0},
                     98:    {HTML_ATTR_frameborder, TEXT("1"), HTML_ATTR_frameborder_VAL_Border1},
                     99: 
                    100:    {HTML_ATTR_scrolling, TEXT("yes"), HTML_ATTR_scrolling_VAL_Yes_},
                    101:    {HTML_ATTR_scrolling, TEXT("no"), HTML_ATTR_scrolling_VAL_No_},
                    102:    {HTML_ATTR_scrolling, TEXT("auto"), HTML_ATTR_scrolling_VAL_auto_},
                    103: 
                    104:    {HTML_ATTR_rules_, TEXT("none"), HTML_ATTR_rules__VAL_none_},
                    105:    {HTML_ATTR_rules_, TEXT("groups"), HTML_ATTR_rules__VAL_groups},
                    106:    {HTML_ATTR_rules_, TEXT("rows"), HTML_ATTR_rules__VAL_rows},
                    107:    {HTML_ATTR_rules_, TEXT("cols"), HTML_ATTR_rules__VAL_cols},
                    108:    {HTML_ATTR_rules_, TEXT("all"), HTML_ATTR_rules__VAL_all},
                    109: 
                    110:    {HTML_ATTR_Cell_align, TEXT("left"), HTML_ATTR_Cell_align_VAL_Cell_left},
                    111:    {HTML_ATTR_Cell_align, TEXT("center"), HTML_ATTR_Cell_align_VAL_Cell_center},
                    112:    {HTML_ATTR_Cell_align, TEXT("right"), HTML_ATTR_Cell_align_VAL_Cell_right},
                    113:    {HTML_ATTR_Cell_align, TEXT("justify"), HTML_ATTR_Cell_align_VAL_Cell_justify},
                    114:    {HTML_ATTR_Cell_align, TEXT("char"), HTML_ATTR_Cell_align_VAL_Cell_char},
                    115: 
                    116:    {HTML_ATTR_Alignment, TEXT("top"), HTML_ATTR_Alignment_VAL_Top_},
                    117:    {HTML_ATTR_Alignment, TEXT("middle"), HTML_ATTR_Alignment_VAL_Middle_},
                    118:    {HTML_ATTR_Alignment, TEXT("bottom"), HTML_ATTR_Alignment_VAL_Bottom_},
                    119:    {HTML_ATTR_Alignment, TEXT("left"), HTML_ATTR_Alignment_VAL_Left_},
                    120:    {HTML_ATTR_Alignment, TEXT("right"), HTML_ATTR_Alignment_VAL_Right_},
                    121: 
                    122:    {HTML_ATTR_METHOD, TEXT("get"), HTML_ATTR_METHOD_VAL_Get_},
                    123:    {HTML_ATTR_METHOD, TEXT("post"), HTML_ATTR_METHOD_VAL_Post_},
                    124: 
                    125:    {HTML_ATTR_Position, TEXT("top"), HTML_ATTR_Position_VAL_Position_top},
                    126:    {HTML_ATTR_Position, TEXT("bottom"), HTML_ATTR_Position_VAL_Position_bottom},
                    127:    {HTML_ATTR_Position, TEXT("left"), HTML_ATTR_Position_VAL_Position_left},
                    128:    {HTML_ATTR_Position, TEXT("right"), HTML_ATTR_Position_VAL_Position_right},
                    129: 
                    130:    {HTML_ATTR_Row_valign, TEXT("top"), HTML_ATTR_Row_valign_VAL_Row_top},
                    131:    {HTML_ATTR_Row_valign, TEXT("middle"), HTML_ATTR_Row_valign_VAL_Row_middle},
                    132:    {HTML_ATTR_Row_valign, TEXT("bottom"), HTML_ATTR_Row_valign_VAL_Row_bottom},
                    133:    {HTML_ATTR_Row_valign, TEXT("baseline"), HTML_ATTR_Row_valign_VAL_Row_baseline},
                    134: 
                    135:    {HTML_ATTR_Cell_valign, TEXT("top"), HTML_ATTR_Cell_valign_VAL_Cell_top},
                    136:    {HTML_ATTR_Cell_valign, TEXT("middle"), HTML_ATTR_Cell_valign_VAL_Cell_middle},
                    137:    {HTML_ATTR_Cell_valign, TEXT("bottom"), HTML_ATTR_Cell_valign_VAL_Cell_bottom},
                    138:    {HTML_ATTR_Cell_valign, TEXT("baseline"), HTML_ATTR_Cell_valign_VAL_Cell_baseline},
                    139: 
                    140:    {HTML_ATTR_shape, TEXT("rect"), HTML_ATTR_shape_VAL_rectangle},
                    141:    {HTML_ATTR_shape, TEXT("circle"), HTML_ATTR_shape_VAL_circle},
                    142:    {HTML_ATTR_shape, TEXT("poly"), HTML_ATTR_shape_VAL_polygon},
                    143: 
                    144:    {HTML_ATTR_valuetype, TEXT("data"), HTML_ATTR_valuetype_VAL_data_},
                    145:    {HTML_ATTR_valuetype, TEXT("ref"), HTML_ATTR_valuetype_VAL_ref},
                    146:    {HTML_ATTR_valuetype, TEXT("object"), HTML_ATTR_valuetype_VAL_object_},
                    147: 
                    148: /* HTML attribute TYPE generates a Thot element */
                    149:    {DummyAttribute, TEXT("button"), HTML_EL_Button_Input},
                    150:    {DummyAttribute, TEXT("checkbox"), HTML_EL_Checkbox_Input},
                    151:    {DummyAttribute, TEXT("file"), HTML_EL_File_Input},
                    152:    {DummyAttribute, TEXT("hidden"), HTML_EL_Hidden_Input},
                    153:    {DummyAttribute, TEXT("image"), HTML_EL_PICTURE_UNIT},
                    154:    {DummyAttribute, TEXT("password"), HTML_EL_Password_Input},
                    155:    {DummyAttribute, TEXT("radio"), HTML_EL_Radio_Input},
                    156:    {DummyAttribute, TEXT("reset"), HTML_EL_Reset_Input},
                    157:    {DummyAttribute, TEXT("submit"), HTML_EL_Submit_Input},
                    158:    {DummyAttribute, TEXT("text"), HTML_EL_Text_Input},
                    159: 
                    160: /* The following declarations allow the parser to accept boolean attributes */
                    161: /* written "checked=CHECKED"), for instance */
                    162:    {HTML_ATTR_ISMAP, TEXT("ismap"), HTML_ATTR_ISMAP_VAL_Yes_},
                    163:    {HTML_ATTR_nohref, TEXT("nohref"), HTML_ATTR_nohref_VAL_Yes_},
                    164:    {HTML_ATTR_COMPACT, TEXT("compact"), HTML_ATTR_COMPACT_VAL_Yes_},
                    165:    {HTML_ATTR_Multiple, TEXT("multiple"), HTML_ATTR_Multiple_VAL_Yes_},
                    166:    {HTML_ATTR_Selected, TEXT("selected"), HTML_ATTR_Selected_VAL_Yes_},
                    167:    {HTML_ATTR_Checked, TEXT("checked"), HTML_ATTR_Checked_VAL_Yes_},
                    168:    {HTML_ATTR_No_wrap, TEXT("nowrap"), HTML_ATTR_No_wrap_VAL_no_wrap},
                    169:    {HTML_ATTR_NoShade, TEXT("noshade"), HTML_ATTR_NoShade_VAL_NoShade_},
                    170:    {HTML_ATTR_declare, TEXT("declare"), HTML_ATTR_declare_VAL_Yes_},
                    171:    {HTML_ATTR_defer, TEXT("defer"), HTML_ATTR_defer_VAL_Yes_},
                    172:    {HTML_ATTR_disabled, TEXT("disabled"), HTML_ATTR_disabled_VAL_Yes_},
                    173:    {HTML_ATTR_readonly, TEXT("readonly"), HTML_ATTR_readonly_VAL_Yes_},
                    174:    {HTML_ATTR_no_resize, TEXT("noresize"), HTML_ATTR_no_resize_VAL_Yes_},
1.21      cvs       175: 
                    176:    /* XML attribute xml:space */
                    177:    {HTML_ATTR_xml_space, TEXT("default"), HTML_ATTR_xml_space_VAL_xml_space_default},
                    178:    {HTML_ATTR_xml_space, TEXT("preserve"), HTML_ATTR_xml_space_VAL_xml_space_preserve},
                    179: 
1.1       cvs       180:    {0, TEXT(""), 0}                    /* Last entry. Mandatory */
                    181: };
1.6       cvs       182: 
1.28      cvs       183: /* Define a pointer to let parser functions access the HTML entity table */
                    184: extern XmlEntity *pXhtmlEntityTable;
1.6       cvs       185: 
                    186: /*----------------------------------------------------------------------
1.15      cvs       187:   ParseCharset:
1.6       cvs       188:   Parses the element HTTP-EQUIV and looks for the charset value.
                    189:   ----------------------------------------------------------------------*/
                    190: #ifdef __STDC__
1.15      cvs       191: void     ParseCharset (Element el, Document doc) 
1.6       cvs       192: #else  /* !__STDC__ */
1.15      cvs       193: void     ParseCharset (el, doc) 
1.6       cvs       194: Element  el;
                    195: Document doc;
                    196: #endif /* !__STDC__ */
                    197: {
1.15      cvs       198:    AttributeType attrType;
                    199:    Attribute     attr;
                    200:    SSchema       docSSchema;
                    201:    CHARSET       charset;
1.6       cvs       202:    CHAR_T       *text, *text2, *ptrText, *str;
                    203:    CHAR_T        charsetname[MAX_LENGTH];
1.15      cvs       204:    int           length;
1.6       cvs       205:    int           pos, index = 0;
                    206: 
1.15      cvs       207:    charset = TtaGetDocumentCharset (doc);
                    208:    if (charset != UNDEFINED_CHARSET)
                    209:      /* the charset was already defined by the http header */
                    210:      return;
1.6       cvs       211: 
                    212:    docSSchema = TtaGetDocumentSSchema (doc);
                    213:    attrType.AttrSSchema = docSSchema;
                    214:    attrType.AttrTypeNum = HTML_ATTR_http_equiv;
                    215:    attr = TtaGetAttribute (el, attrType);
                    216:    if (attr != NULL)
                    217:      {
                    218:        /* There is a HTTP-EQUIV attribute */
                    219:        length = TtaGetTextAttributeLength (attr);
                    220:        if (length > 0)
                    221:         {
                    222:           text = TtaAllocString (length + 1);
                    223:           TtaGiveTextAttributeValue (attr, text, &length);
                    224:           if (!ustrcasecmp (text, TEXT("content-type")))
                    225:             {
                    226:               attrType.AttrTypeNum = HTML_ATTR_meta_content;
                    227:               attr = TtaGetAttribute (el, attrType);
                    228:               if (attr != NULL)
                    229:                 {
                    230:                   length = TtaGetTextAttributeLength (attr);
                    231:                   if (length > 0)
                    232:                     {
                    233:                       text2 = TtaAllocString (length + 1);
                    234:                       TtaGiveTextAttributeValue (attr, text2, &length);
                    235:                       ptrText = text2;
                    236:                       while (*ptrText)
                    237:                         {
                    238:                           *ptrText = utolower (*ptrText);
                    239:                           ptrText++;
                    240:                         }
                    241:                       
                    242:                       str = ustrstr (text2, TEXT("charset="));
                    243:                       if (str)
                    244:                         {
                    245:                           pos = str - text2 + 8;
                    246:                           while (text2[pos] != WC_SPACE &&
                    247:                                  text2[pos] != WC_TAB && text2[pos] != WC_EOS)
                    248:                             charsetname[index++] = text2[pos++];
                    249:                           charsetname[index] = WC_EOS;
1.15      cvs       250:                           charset = TtaGetCharset (charsetname);
                    251:                           if (charset != UNDEFINED_CHARSET)
                    252:                             TtaSetDocumentCharset (doc, charset);
1.6       cvs       253:                         }
                    254:                       TtaFreeMemory (text2);
                    255:                     }       
                    256:                 } 
                    257:             }
                    258:           TtaFreeMemory (text);
                    259:         }
                    260:      }
                    261: }
                    262: 
1.23      cvs       263: /*----------------------------------------------------------------------
                    264:    XhtmlEntityCreated
                    265:    A XTHML entity has been created by the XML parser.
                    266:   ----------------------------------------------------------------------*/
                    267: #ifdef __STDC__
1.29    ! cvs       268: void        XhtmlEntityCreated (int entityValue,
        !           269:                                STRING entityName,
        !           270:                                ParserData *context)
1.23      cvs       271: #else
1.29    ! cvs       272: void        XhtmlEntityCreated (entityValue, entityName, context)
1.23      cvs       273: int         entityValue;
                    274: Language    lang;
                    275: STRING      entityName;
                    276: ParserData *context;
                    277: #endif
                    278: { 
1.29    ! cvs       279:   ElementType   elType;
        !           280:   Element       elText;
        !           281:   AttributeType  attrType;
        !           282:   Attribute     attr;
        !           283:   Language      lang;
        !           284:   int           len;
        !           285:   CHAR_T        buffer[MaxEntityLength+10];
        !           286: #define MAX_ENTITY_LENGTH 80
        !           287:   
        !           288:   if (entityValue < 255)
1.23      cvs       289:     {
1.29    ! cvs       290:       buffer[0] = ((UCHAR_T) entityValue);
        !           291:       buffer[1] = WC_EOS;
        !           292:       lang = TtaGetLanguageIdFromAlphabet('L');
1.23      cvs       293:     }
1.29    ! cvs       294:   else
        !           295:     /* try to find a fallback character */
        !           296:     GetFallbackCharacter (entityValue, buffer, &lang);
        !           297: 
        !           298:   /* create a new text leaf */
        !           299:   elType.ElSSchema = TtaGetDocumentSSchema (context->doc);
        !           300:   elType.ElTypeNum = HTML_EL_TEXT_UNIT;
        !           301:   elText = TtaNewElement (context->doc, elType);
        !           302:   XmlSetElemLineNumber (elText);
        !           303:   InsertXmlElement (&elText);
        !           304:   TtaSetTextContent (elText, buffer, lang, context->doc);
        !           305:   context->lastElement = elText;
        !           306:   context->lastElementClosed = TRUE;
        !           307:   context->mergeText = FALSE;
        !           308:   
        !           309:   /* Make that text leaf read-only */
        !           310:   TtaSetAccessRight (elText, ReadOnly, context->doc);
        !           311:   
        !           312:   /* Associate an attribute EntityName with the new text leaf */
        !           313:   attrType.AttrSSchema = TtaGetDocumentSSchema (context->doc);
        !           314:   attrType.AttrTypeNum = HTML_ATTR_EntityName;
        !           315:   attr = TtaNewAttribute (attrType);
        !           316:   TtaAttachAttribute (elText, attr, context->doc);
        !           317: 
        !           318:   len = ustrlen (entityName);
        !           319:   if (len > MAX_ENTITY_LENGTH -3)
        !           320:     len = MAX_ENTITY_LENGTH -3;
        !           321:   buffer[0] = '&';
        !           322:   ustrncpy (&buffer[1], entityName, len);
        !           323:   buffer[len+1] = ';';
        !           324:   buffer[len+2] = WC_EOS;
        !           325:   TtaSetAttributeText (attr, buffer, elText, context->doc);
1.23      cvs       326: }
                    327: 
1.6       cvs       328: /*----------------------------------------------------------------------
                    329:   XhtmlElementComplete
1.20      cvs       330:   Complete Xhtml elements.
1.6       cvs       331:   Check its attributes and its contents.
                    332:   ----------------------------------------------------------------------*/
                    333: #ifdef __STDC__
1.15      cvs       334: void       XhtmlElementComplete (Element el, Document doc, int *error)
1.6       cvs       335: #else
1.15      cvs       336: void       XhtmlElementComplete (el, doc, error)
                    337: Element    el;
                    338: Document   doc;
                    339: int       *error;
1.6       cvs       340: #endif
                    341: {
1.23      cvs       342:    ElementType       elType, newElType, childType;
                    343:    Element           constElem, child, desc, leaf, prev, next, last,
                    344:                     elFrames, lastFrame, lastChild;
                    345:    Attribute         attr;
                    346:    AttributeType     attrType;
                    347:    Language          lang;
                    348:    STRING            text;
                    349:    CHAR_T            lastChar[2];
                    350:    STRING            name1;
                    351:    int               length;
                    352:    SSchema           docSSchema;
1.6       cvs       353: 
                    354:    *error = 0;
                    355:    docSSchema = TtaGetDocumentSSchema (doc);
                    356: 
                    357:    elType = TtaGetElementType (el);
                    358:    /* is this a block-level element in a character-level element? */
1.27      cvs       359:    if (!IsXMLElementInline (elType) &&
1.24      cvs       360:        elType.ElTypeNum != HTML_EL_Comment_ &&
                    361:        elType.ElTypeNum != HTML_EL_XMLPI)
1.6       cvs       362:        BlockInCharLevelElem (el);
                    363: 
                    364:    newElType.ElSSchema = elType.ElSSchema;
                    365:    switch (elType.ElTypeNum)
                    366:      {
                    367:      case HTML_EL_Object:      /*  it's an object */
                    368:        /* create Object_Content */
                    369:        child = TtaGetFirstChild (el);
                    370:        if (child != NULL)
                    371:           elType = TtaGetElementType (child);
                    372:         
                    373:        /* is it the PICTURE element ? */
                    374:        if (child == NULL || elType.ElTypeNum != HTML_EL_PICTURE_UNIT)
                    375:         {
                    376:           desc = child;
                    377:           /* create the PICTURE element */
                    378:           elType.ElTypeNum = HTML_EL_PICTURE_UNIT;
                    379:           child = TtaNewTree (doc, elType, "");
                    380:           if (desc == NULL)
                    381:               TtaInsertFirstChild (&child, el, doc);
                    382:           else
                    383:               TtaInsertSibling (child, desc, TRUE, doc);
                    384:         }
                    385: 
                    386:        /* copy attribute data into SRC attribute of Object_Image */
                    387:        attrType.AttrSSchema = docSSchema;
                    388:        attrType.AttrTypeNum = HTML_ATTR_data;
                    389:        attr = TtaGetAttribute (el, attrType);
                    390:        if (attr != NULL)
                    391:         {
                    392:           length = TtaGetTextAttributeLength (attr);
                    393:           if (length > 0)
                    394:             {
                    395:               name1 = TtaAllocString (length + 1);
                    396:               TtaGiveTextAttributeValue (attr, name1, &length);
                    397:               attrType.AttrTypeNum = HTML_ATTR_SRC;
                    398:               attr = TtaGetAttribute (child, attrType);
                    399:               if (attr == NULL)
                    400:                 {
                    401:                   attr = TtaNewAttribute (attrType);
                    402:                   TtaAttachAttribute (child, attr, doc);
                    403:                 }
                    404:               TtaSetAttributeText (attr, name1, child, doc);
                    405:               TtaFreeMemory (name1);
                    406:             }
                    407:         }
                    408: 
                    409:        /* is the Object_Content element already created ? */
                    410:        desc = child;
                    411:        TtaNextSibling(&desc);
                    412:        if (desc != NULL)
                    413:           elType = TtaGetElementType (desc);
                    414:         
                    415:        /* is it the Object_Content element ? */
                    416:        if (desc == NULL || elType.ElTypeNum != HTML_EL_Object_Content)
                    417:         {
                    418:           /* create Object_Content */
                    419:           elType.ElTypeNum = HTML_EL_Object_Content;
                    420:           desc = TtaNewTree (doc, elType, "");
                    421:           TtaInsertSibling (desc, child, FALSE, doc);
                    422:           /* move previous existing children into Object_Content */
                    423:           child = TtaGetLastChild(el);
                    424:           while (child != desc)
                    425:             {
                    426:               TtaRemoveTree (child, doc);
                    427:               TtaInsertFirstChild (&child, desc, doc);
                    428:               child = TtaGetLastChild(el);
                    429:             }
                    430:         }
                    431:        break;
                    432:        
                    433:      case HTML_EL_Unnumbered_List:
                    434:      case HTML_EL_Numbered_List:
                    435:      case HTML_EL_Menu:
                    436:      case HTML_EL_Directory:
                    437:        /* It's a List element. It should only have List_Item children.
                    438:          If it has List element chidren, move these List elements
                    439:          within their previous List_Item sibling.  This is to fix
                    440:          a bug in document generated by Mozilla. */
                    441:        prev = NULL;
                    442:        next = NULL;
                    443:        child = TtaGetFirstChild (el);
                    444:        while (child != NULL)
                    445:         {
                    446:           next = child;
                    447:           TtaNextSibling (&next);
                    448:           elType = TtaGetElementType (child);
                    449:           if (elType.ElTypeNum == HTML_EL_Unnumbered_List ||
                    450:               elType.ElTypeNum == HTML_EL_Numbered_List ||
                    451:               elType.ElTypeNum == HTML_EL_Menu ||
                    452:               elType.ElTypeNum == HTML_EL_Directory)
                    453:             /* this list element is a child of another list element */
                    454:             if (prev)
                    455:               {
                    456:                 elType = TtaGetElementType (prev);
                    457:                 if (elType.ElTypeNum == HTML_EL_List_Item)
                    458:                   {
                    459:                     /* get the last child of the previous List_Item */
                    460:                     desc = TtaGetFirstChild (prev);
                    461:                     last = NULL;
                    462:                     while (desc)
                    463:                       {
                    464:                         last = desc;
                    465:                         TtaNextSibling (&desc);
                    466:                       }
                    467:                     /* move the list element after the last child of the
                    468:                        previous List_Item */
                    469:                     TtaRemoveTree (child, doc);
                    470:                     if (last)
                    471:                       TtaInsertSibling (child, last, FALSE, doc);
                    472:                     else
                    473:                       TtaInsertFirstChild (&child, prev, doc);
                    474:                     child = prev;
                    475:                   }
                    476:               }
                    477:           prev = child;
                    478:           child = next;
                    479:         }
                    480:        break;
                    481:        
                    482:      case HTML_EL_FRAMESET:
                    483:        /* The FRAMESET element is now complete.  Gather all its FRAMESET
                    484:          and FRAME children and wrap them up in a Frames element */
                    485:        elFrames = NULL; lastFrame = NULL;
                    486:        lastChild = NULL;
                    487:        child = TtaGetFirstChild (el);
                    488:        while (child != NULL)
                    489:         {
                    490:           next = child;
                    491:           TtaNextSibling (&next);
                    492:           elType = TtaGetElementType (child);
                    493:           if (elType.ElTypeNum == HTML_EL_FRAMESET ||
                    494:               elType.ElTypeNum == HTML_EL_FRAME ||
                    495:               elType.ElTypeNum == HTML_EL_Comment_)
                    496:             {
                    497:               /* create the Frames element if it does not exist */
                    498:               if (elFrames == NULL)
                    499:                 {
                    500:                   newElType.ElSSchema = docSSchema;
                    501:                   newElType.ElTypeNum = HTML_EL_Frames;
                    502:                   elFrames = TtaNewElement (doc, newElType);
                    503:                   XmlSetElemLineNumber (elFrames);
                    504:                   TtaInsertSibling (elFrames, child, TRUE, doc);
                    505:                 }
                    506:               /* move the element as the last child of the Frames element */
                    507:               TtaRemoveTree (child, doc);
                    508:               if (lastFrame == NULL)
                    509:                 TtaInsertFirstChild (&child, elFrames, doc);
                    510:               else
                    511:                 TtaInsertSibling (child, lastFrame, FALSE, doc);
                    512:               lastFrame = child;
                    513:             }
                    514:           child = next;
                    515:         }
                    516:        break;
                    517:        
                    518:      case HTML_EL_Input:       /* it's an INPUT without any TYPE attribute */
                    519:        /* Create a child of type Text_Input */
                    520:        elType.ElTypeNum = HTML_EL_Text_Input;
                    521:        child = TtaNewTree (doc, elType, "");
                    522:        XmlSetElemLineNumber (child);
                    523:        TtaInsertFirstChild (&child, el, doc);
                    524:        /* now, process it like a Text_Input element */
                    525: 
                    526:      case HTML_EL_Text_Input:
                    527:      case HTML_EL_Password_Input:
                    528:      case HTML_EL_File_Input:
                    529:        /* get element Inserted_Text */
                    530:        child = TtaGetFirstChild (el);
                    531:        if (child != NULL)
                    532:         {
                    533:           attrType.AttrSSchema = docSSchema;
                    534:           attrType.AttrTypeNum = HTML_ATTR_Value_;
                    535:           attr = TtaGetAttribute (el, attrType);
                    536:           if (attr != NULL)
                    537:             {
                    538:               /* copy the value of attribute "value" into the first text
                    539:                  leaf of element */
                    540:               length = TtaGetTextAttributeLength (attr);
                    541:               if (length > 0)
                    542:                 {
                    543:                   /* get the text leaf */
                    544:                   leaf = TtaGetFirstChild (child);
                    545:                   if (leaf != NULL)
                    546:                     {
                    547:                       childType = TtaGetElementType (leaf);
                    548:                       if (childType.ElTypeNum == HTML_EL_TEXT_UNIT)
                    549:                         {
                    550:                           /* copy attribute value into the text leaf */
                    551:                           text = TtaAllocString (length + 1);
                    552:                           TtaGiveTextAttributeValue (attr, text, &length);
                    553:                           TtaSetTextContent (leaf, text, 
                    554:                                              TtaGetDefaultLanguage (), doc);
                    555:                           TtaFreeMemory (text);
                    556:                         }
                    557:                     }
                    558:                 }
                    559:             }
                    560:         }
                    561:        break;
                    562:        
                    563:      case HTML_EL_META:
1.15      cvs       564:        ParseCharset (el, doc);
1.6       cvs       565:        break;
                    566: 
                    567:      case HTML_EL_STYLE_:      /* it's a STYLE element */
1.8       cvs       568:      case HTML_EL_SCRIPT:      /* it's a SCRIPT element */
1.6       cvs       569:      case HTML_EL_Preformatted:        /* it's a PRE */
                    570:        /* if the last line of the Preformatted is empty, remove it */
                    571:        leaf = XmlLastLeafInElement (el);
                    572:        if (leaf != NULL)
                    573:         {
                    574:           elType = TtaGetElementType (leaf);
                    575:           if (elType.ElTypeNum == HTML_EL_TEXT_UNIT)
                    576:             /* the last leaf is a TEXT element */
                    577:             {
                    578:               length = TtaGetTextLength (leaf);
                    579:               if (length > 0)
                    580:                 {
                    581:                   TtaGiveSubString (leaf, lastChar, length, 1);
                    582:                   if (lastChar[0] == EOL)
                    583:                     /* last character is new line, delete it */
                    584:                     {
                    585:                       if (length == 1)
                    586:                         /* empty TEXT element */
                    587:                         TtaDeleteTree (leaf, doc);
                    588:                       else
                    589:                         /* remove the last character */
                    590:                         TtaDeleteTextContent (leaf, length, 1, doc);
                    591:                     }
                    592:                 }
                    593:             }
                    594:         }
                    595:        if (IsParsingCSS ())
                    596:         {
                    597:           text = GetStyleContents (el);
                    598:           if (text)
                    599:             {
                    600:               ReadCSSRules (doc, NULL, text, FALSE);
                    601:               TtaFreeMemory (text);
                    602:             }
                    603:           SetParsingCSS (FALSE);
                    604:         }
                    605:        /* and continue as if it were a Preformatted or a Script */
                    606:        break;
                    607:        
                    608:      case HTML_EL_Text_Area:   /* it's a Text_Area */
                    609:        SetParsingTextArea (FALSE);
                    610:        child = TtaGetFirstChild (el);
                    611:        if (child == NULL)
                    612:         /* it's an empty Text_Area */
                    613:         /* insert a Inserted_Text element in the element */
                    614:         {
                    615:           newElType.ElTypeNum = HTML_EL_Inserted_Text;
                    616:           child = TtaNewTree (doc, newElType, "");
                    617:           TtaInsertFirstChild (&child, el, doc);
                    618:         }
                    619:        else
                    620:         {
                    621:           /* save the text into Default_Value attribute */
                    622:           attrType.AttrSSchema = docSSchema;
                    623:           attrType.AttrTypeNum = HTML_ATTR_Default_Value;
                    624:           if (TtaGetAttribute (el, attrType) == NULL)
                    625:             /* attribute Default_Value is missing */
                    626:             {
                    627:               attr = TtaNewAttribute (attrType);
                    628:               TtaAttachAttribute (el, attr, doc);
                    629:               desc = TtaGetFirstChild (child);
                    630:               length = TtaGetTextLength (desc) + 1;
                    631:               text = TtaAllocString (length);
                    632:               TtaGiveTextContent (desc, text, &length, &lang);
                    633:               TtaSetAttributeText (attr, text, el, doc);
                    634:               TtaFreeMemory (text);
                    635:             }
                    636:         }
                    637:        /* insert a Frame element */
                    638:        newElType.ElTypeNum = HTML_EL_Frame;
                    639:        constElem = TtaNewTree (doc, newElType, "");
                    640:        TtaInsertSibling (constElem, child, FALSE, doc);
                    641:        break;
                    642:        
                    643:      case HTML_EL_Radio_Input:
                    644:      case HTML_EL_Checkbox_Input:
                    645:        /* put an attribute Checked if it is missing */
                    646:        attrType.AttrSSchema = docSSchema;
                    647:        attrType.AttrTypeNum = HTML_ATTR_Checked;
                    648:        if (TtaGetAttribute (el, attrType) == NULL)
                    649:         /* attribute Checked is missing */
                    650:         {
                    651:           attr = TtaNewAttribute (attrType);
                    652:           TtaAttachAttribute (el, attr, doc);
                    653:           TtaSetAttributeValue (attr, HTML_ATTR_Checked_VAL_No_, el, doc);
                    654:         }
                    655:        break;
                    656:        
                    657:      case HTML_EL_Option_Menu:
                    658:        /* Check that at least one option has a SELECTED attribute */
                    659:        OnlyOneOptionSelected (el, doc, TRUE);
                    660:        break;
                    661: 
                    662:      case HTML_EL_PICTURE_UNIT:
                    663:        break;
                    664:        
                    665:      case HTML_EL_LINK:
                    666:        CheckCSSLink (el, doc, docSSchema);
                    667:        break;
                    668:        
                    669:      case HTML_EL_Data_cell:
                    670:      case HTML_EL_Heading_cell:
                    671:        /* insert a pseudo paragraph into empty cells */
                    672:        child = TtaGetFirstChild (el);
                    673:        if (child == NULL)
                    674:         {
                    675:           elType.ElTypeNum = HTML_EL_Pseudo_paragraph;
                    676:           child = TtaNewTree (doc, elType, "");
                    677:           if (child != NULL)
                    678:               TtaInsertFirstChild (&child, el, doc);
                    679:         }
                    680:        
                    681:        /* detect whether we're parsing a whole table or just a cell */
                    682:        if (IsWithinTable ())
                    683:           NewCell (el, doc, FALSE);
                    684:        break;
                    685:        
                    686:      case HTML_EL_Table:
                    687:        CheckTable (el, doc);
                    688:        SubWithinTable ();
                    689:        break;
                    690:        
                    691:      case HTML_EL_TITLE:
                    692:        /* show the TITLE in the main window */
                    693:        UpdateTitle (el, doc);
                    694:        break;
                    695:        
                    696:      default:
                    697:        break;
                    698:      }
                    699: }
1.1       cvs       700: 
                    701: /*----------------------------------------------------------------------
1.16      cvs       702:    MapHTMLAttributeValue
1.2       cvs       703:    Search in the Attribute Value Mapping Table the entry for the attribute
                    704:    ThotAtt and its value AttrVal. Returns the corresponding Thot value.
1.1       cvs       705:   ----------------------------------------------------------------------*/
                    706: #ifdef __STDC__
1.16      cvs       707: void            MapHTMLAttributeValue (CHAR_T* AttrVal,
1.20      cvs       708:                                       AttributeType attrType,
                    709:                                       int* value)
1.1       cvs       710: #else
1.23      cvs       711: void            MapHTMLAttributeValue (AttrVal, attrType, value)
1.11      cvs       712: CHAR_T*         AttrVal;
                    713: AttributeType   attrType;
                    714: int*            value;
1.1       cvs       715: #endif
                    716: {
1.2       cvs       717:    int       i;
1.1       cvs       718: 
1.2       cvs       719:    *value = 0;
1.1       cvs       720:    i = 0;
                    721: 
1.2       cvs       722:    while (XhtmlAttrValueMappingTable[i].ThotAttr != attrType.AttrTypeNum &&
                    723:          XhtmlAttrValueMappingTable[i].ThotAttr != 0)
                    724:        i++;
                    725: 
                    726:    if (XhtmlAttrValueMappingTable[i].ThotAttr == attrType.AttrTypeNum)
                    727:      {
                    728:        do
1.18      cvs       729:            if (!ustrcmp (XhtmlAttrValueMappingTable[i].XMLattrValue, AttrVal))
1.2       cvs       730:               *value = XhtmlAttrValueMappingTable[i].ThotAttrValue;
1.1       cvs       731:           else 
1.2       cvs       732:               i++;
                    733:        while (*value <= 0 &&
                    734:              XhtmlAttrValueMappingTable[i].ThotAttr != 0);
1.1       cvs       735:      }
                    736: }

Webmaster