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

1.1       cvs         1: /*
                      2:  *
1.101     vatton      3:  *  (c) COPYRIGHT INRIA and W3C, 1996-2004
1.1       cvs         4:  *  Please first read the full copyright statement in file COPYRIGHT.
                      5:  *
                      6:  */
                      7: 
                      8: /*
1.30      cvs         9:  * XHTMLbuilder.c
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"
1.30      cvs        21: #include "fetchHTMLname.h"
1.2       cvs        22: 
1.13      cvs        23: #include "css_f.h"
1.76      vatton     24: #include "EDITstyle_f.h"
1.13      cvs        25: #include "fetchXMLname_f.h"
1.30      cvs        26: #include "fetchHTMLname_f.h"
1.22      cvs        27: #include "html2thot_f.h"
1.1       cvs        28: #include "HTMLactions_f.h"
                     29: #include "HTMLedit_f.h"
1.22      cvs        30: #include "HTMLform_f.h"
1.1       cvs        31: #include "HTMLimage_f.h"
                     32: #include "HTMLtable_f.h"
                     33: #include "HTMLimage_f.h"
1.104     vatton     34: #include "init_f.h"
1.1       cvs        35: #include "UIcss_f.h"
1.13      cvs        36: #include "styleparser_f.h"
1.2       cvs        37: #include "XHTMLbuilder_f.h"
1.13      cvs        38: #include "Xml2thot_f.h"
1.1       cvs        39: 
1.47      cvs        40: /* Elements that cannot contain text as immediate children.
                     41:    When some text is present in the HTML file it must be 
                     42:    surrounded by a Pseudo_paragraph element */
                     43: static int          NoTextChild[] =
                     44: {
                     45:    HTML_EL_Document, HTML_EL_HTML, HTML_EL_HEAD, HTML_EL_BODY,
                     46:    HTML_EL_Definition_List, HTML_EL_Block_Quote, HTML_EL_Directory,
                     47:    HTML_EL_Form, HTML_EL_Menu, HTML_EL_FIELDSET,
                     48:    HTML_EL_Numbered_List, HTML_EL_Option_Menu,
                     49:    HTML_EL_Unnumbered_List, HTML_EL_Definition, HTML_EL_List_Item,
                     50:    HTML_EL_MAP, HTML_EL_map, HTML_EL_Applet,
                     51:    HTML_EL_Object, HTML_EL_IFRAME, HTML_EL_NOFRAMES,
                     52:    HTML_EL_Division, HTML_EL_Center, HTML_EL_NOSCRIPT,
                     53:    HTML_EL_Data_cell, HTML_EL_Heading_cell,
                     54:    0};
                     55: 
1.28      cvs        56: /* Define a pointer to let parser functions access the HTML entity table */
                     57: extern XmlEntity *pXhtmlEntityTable;
1.6       cvs        58: 
1.30      cvs        59: /* maximum size of error messages */
                     60: #define MaxMsgLength 200
                     61: 
1.6       cvs        62: /*----------------------------------------------------------------------
1.104     vatton     63:   ParseCharsetAndContentType:
1.6       cvs        64:   Parses the element HTTP-EQUIV and looks for the charset value.
                     65:   ----------------------------------------------------------------------*/
1.104     vatton     66: void ParseCharsetAndContentType (Element el, Document doc) 
1.30      cvs        67: 
1.6       cvs        68: {
1.15      cvs        69:    AttributeType attrType;
                     70:    Attribute     attr;
1.109     vatton     71:    ElementType   elType;
1.15      cvs        72:    CHARSET       charset;
1.39      cvs        73:    char         *text, *text2, *ptrText, *str;
                     74:    char          charsetname[MAX_LENGTH];
1.15      cvs        75:    int           length;
1.6       cvs        76:    int           pos, index = 0;
                     77: 
1.15      cvs        78:    charset = TtaGetDocumentCharset (doc);
1.104     vatton     79:    if (charset != UNDEFINED_CHARSET &&
                     80:        DocumentMeta[doc] && DocumentMeta[doc]->content_type)
1.15      cvs        81:      return;
1.6       cvs        82: 
1.109     vatton     83:    elType = TtaGetElementType (el);
                     84:    attrType.AttrSSchema = elType.ElSSchema;
1.6       cvs        85:    attrType.AttrTypeNum = HTML_ATTR_http_equiv;
                     86:    attr = TtaGetAttribute (el, attrType);
                     87:    if (attr != NULL)
                     88:      {
                     89:        /* There is a HTTP-EQUIV attribute */
                     90:        length = TtaGetTextAttributeLength (attr);
                     91:        if (length > 0)
                     92:         {
1.100     gully      93:           text = (char *)TtaGetMemory (length + 1);
1.6       cvs        94:           TtaGiveTextAttributeValue (attr, text, &length);
1.37      cvs        95:           if (!strcasecmp (text, "content-type"))
1.6       cvs        96:             {
                     97:               attrType.AttrTypeNum = HTML_ATTR_meta_content;
                     98:               attr = TtaGetAttribute (el, attrType);
                     99:               if (attr != NULL)
                    100:                 {
                    101:                   length = TtaGetTextAttributeLength (attr);
                    102:                   if (length > 0)
                    103:                     {
1.100     gully     104:                       text2 = (char *)TtaGetMemory (length + 1);
1.6       cvs       105:                       TtaGiveTextAttributeValue (attr, text2, &length);
                    106:                       ptrText = text2;
                    107:                       while (*ptrText)
                    108:                         {
1.53      vatton    109:                           *ptrText = tolower (*ptrText);
1.6       cvs       110:                           ptrText++;
                    111:                         }
1.104     vatton    112: 
                    113:                       if (!DocumentMeta[doc])
                    114:                         DocumentMeta[doc] = DocumentMetaDataAlloc ();
                    115:                       if (DocumentMeta[doc]->content_type == NULL)
1.6       cvs       116:                         {
1.104     vatton    117:                           
                    118:                           if (!strncmp (text2, "text/html", 9))
                    119:                             DocumentMeta[doc]->content_type = TtaStrdup ("text/html");
                    120:                           else
                    121:                             DocumentMeta[doc]->content_type = TtaStrdup (AM_XHTML_MIME_TYPE);
                    122:                         }
                    123: 
                    124:                       if (charset == UNDEFINED_CHARSET)
                    125:                         {
                    126:                         /* the charset is not already defined by the http header */
                    127:                           str = strstr (text2, "charset=");
                    128:                           if (str)
                    129:                             {
                    130:                               pos = str - text2 + 8;
                    131:                               while (text2[pos] != SPACE &&
                    132:                                      text2[pos] != TAB && text2[pos] != EOS)
                    133:                                 charsetname[index++] = text2[pos++];
                    134:                               charsetname[index] = EOS;
                    135:                               charset = TtaGetCharset (charsetname);
                    136:                               if (charset != UNDEFINED_CHARSET)
                    137:                                 TtaSetDocumentCharset (doc, charset, FALSE);
                    138:                             }
1.6       cvs       139:                         }
                    140:                       TtaFreeMemory (text2);
                    141:                     }       
                    142:                 } 
                    143:             }
                    144:           TtaFreeMemory (text);
                    145:         }
                    146:      }
                    147: }
                    148: 
1.23      cvs       149: /*----------------------------------------------------------------------
1.47      cvs       150:    XhtmlCannotContainText 
                    151:    Return TRUE if element el is a block element.
                    152:   ----------------------------------------------------------------------*/
1.109     vatton    153: ThotBool XhtmlCannotContainText (ElementType elType)
1.47      cvs       154: 
                    155: {
                    156:    int        i;
                    157:    ThotBool   ret;
                    158: 
                    159:    if (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML"))
                    160:       /* not an HTML element */
                    161:       ret = TRUE;
                    162:    else
                    163:      {
                    164:        ret = FALSE;
                    165:        i = 0;
                    166:        while (NoTextChild[i] > 0 && NoTextChild[i] != elType.ElTypeNum)
                    167:            i++;
                    168:        if (NoTextChild[i] == elType.ElTypeNum)
                    169:            ret = TRUE;
                    170:      }
                    171:    return ret;
1.23      cvs       172: }
                    173: 
1.6       cvs       174: /*----------------------------------------------------------------------
1.117     quint     175:   CheckMandatoryAttribute
                    176:   If attribute attrNum is not present on element el, generate a
                    177:   parsing error message.
1.111     vatton    178:   ----------------------------------------------------------------------*/
1.114     vatton    179: static void CheckMandatoryAttribute (Element el, Document doc, int attrNum)
1.111     vatton    180: {
                    181:   ElementType    elType;
                    182:   Attribute      attr;
                    183:   AttributeType  attrType;
1.117     quint     184:   int            lineNum;
1.114     vatton    185:   char          *name;
                    186:   char           msgBuffer[MaxMsgLength];
1.111     vatton    187: 
                    188:    elType = TtaGetElementType (el);
                    189:    attrType.AttrSSchema = elType.ElSSchema;
1.114     vatton    190:    attrType.AttrTypeNum = attrNum;
1.111     vatton    191:    attr = TtaGetAttribute (el, attrType);
                    192:    if (attr == NULL)
                    193:      {
1.114     vatton    194:        name = GetXMLAttributeName (attrType, elType, doc);
                    195:        if (name)
                    196:         {
1.117     quint     197:           sprintf (msgBuffer, "Missing mandatory attribute %s for element %s",
                    198:                    name, TtaGetElementTypeName(TtaGetElementType(el)));
                    199:           lineNum = TtaGetElementLineNumber(el);
1.114     vatton    200:           if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
1.117     quint     201:             XmlParseError (errorParsing, (unsigned char *)msgBuffer, lineNum);
1.114     vatton    202:           else
1.117     quint     203:             HTMLParseError (doc, msgBuffer, lineNum);
1.114     vatton    204:         }
1.111     vatton    205:      }
                    206: }
                    207: 
1.118     vatton    208: 
                    209: /*----------------------------------------------------------------------
                    210:   AddRowsColumns
                    211:   Add default rows and columns attributes to a TEXTAREA element.
                    212:   ----------------------------------------------------------------------*/
                    213: void AddRowsColumns (Element el, Document doc)
                    214: {
                    215:   ElementType    elType;
                    216:   Attribute      attr;
                    217:   AttributeType  attrType;
                    218: 
                    219:   /* Add defaults rows and columns to display the textarea */
                    220:   elType = TtaGetElementType (el);
                    221:   attrType.AttrSSchema = elType.ElSSchema;
                    222:   attrType.AttrTypeNum = HTML_ATTR_Rows;
                    223:   attr = TtaGetAttribute (el, attrType);
                    224:   if (attr == NULL)
                    225:     {
                    226:       attr = TtaNewAttribute (attrType);
                    227:       TtaAttachAttribute (el, attr, doc);
                    228:       TtaSetAttributeValue (attr, 4, el, doc);
                    229:     }
                    230:   attrType.AttrTypeNum = HTML_ATTR_Columns;
                    231:   attr = TtaGetAttribute (el, attrType);
                    232:   if (attr == NULL)
                    233:     {
                    234:       attr = TtaNewAttribute (attrType);
                    235:       TtaAttachAttribute (el, attr, doc);
                    236:       TtaSetAttributeValue (attr, 20, el, doc);
                    237:     }
                    238: }
                    239: 
1.111     vatton    240: /*----------------------------------------------------------------------
1.6       cvs       241:   XhtmlElementComplete
1.20      cvs       242:   Complete Xhtml elements.
1.6       cvs       243:   Check its attributes and its contents.
                    244:   ----------------------------------------------------------------------*/
1.99      cvs       245: void XhtmlElementComplete (ParserData *context, Element el, int *error)
1.30      cvs       246: {
1.72      cvs       247:    Document       doc;   
1.30      cvs       248:    ElementType    elType, newElType, childType;
1.104     vatton    249:    Element        child, desc, leaf, prev, next, last,
1.62      quint     250:                  elFrames, lastFrame, lastChild, parent, picture, content;
1.30      cvs       251:    Attribute      attr;
                    252:    AttributeType  attrType;
                    253:    Language       lang;
1.41      cvs       254:    char           *text;
1.39      cvs       255:    char           lastChar[2];
1.79      quint     256:    char           *name1, *data;
1.30      cvs       257:    int            length;
1.109     vatton    258:    SSchema        htmlSchema;
1.106     quint     259:    ThotBool       isImage, isInline;
1.6       cvs       260: 
                    261:    *error = 0;
1.72      cvs       262:    doc = context->doc;
1.6       cvs       263: 
                    264:    elType = TtaGetElementType (el);
1.109     vatton    265:    htmlSchema = elType.ElSSchema;
1.106     quint     266:    isInline = IsXMLElementInline (elType, doc);
1.96      quint     267:    newElType.ElSSchema = elType.ElSSchema;
                    268: 
1.106     quint     269:    if (elType.ElTypeNum == HTML_EL_Paragraph ||
                    270:        elType.ElTypeNum == HTML_EL_Address ||
                    271:        elType.ElTypeNum == HTML_EL_H1 ||
                    272:        elType.ElTypeNum == HTML_EL_H2 ||
                    273:        elType.ElTypeNum == HTML_EL_H3 ||
                    274:        elType.ElTypeNum == HTML_EL_H4 ||
                    275:        elType.ElTypeNum == HTML_EL_H5 ||
                    276:        elType.ElTypeNum == HTML_EL_H6 ||
                    277:        elType.ElTypeNum == HTML_EL_Preformatted ||
                    278:        elType.ElTypeNum == HTML_EL_Term ||
                    279:        elType.ElTypeNum == HTML_EL_LEGEND ||
                    280:        elType.ElTypeNum == HTML_EL_CAPTION ||
                    281:        elType.ElTypeNum == HTML_EL_rb ||
                    282:        elType.ElTypeNum == HTML_EL_rt ||
1.121   ! vatton    283:        (isInline &&  !TtaIsLeaf (elType) &&
        !           284:        elType.ElTypeNum != HTML_EL_Text_Area))
1.106     quint     285:      /* It's an element that is supposed to contain at least a Basic_Elem.
                    286:        If it is empty, insert a Basic_Elem to allow the user to put the
                    287:        selection within this element */
                    288:      /* Don't do it for a Text_Area, as an Inserted_Text element has to be
1.97      quint     289:        created (see below) */
1.96      quint     290:      {
                    291:        child = TtaGetFirstChild (el);
                    292:        if (child == NULL)
                    293:         /* it's an empty inline element */
                    294:         /* insert a Basic_Elem element in the element */
                    295:         {
                    296:           newElType.ElTypeNum = HTML_EL_Basic_Elem;
                    297:           child = TtaNewTree (doc, newElType, "");
                    298:           TtaInsertFirstChild (&child, el, doc);
                    299:         }
                    300:      }
1.106     quint     301:    if (!isInline)
1.96      quint     302:      /* It's a block-level element. Is it within a character-level element? */
                    303:      if (elType.ElTypeNum != HTML_EL_Comment_ &&
                    304:         elType.ElTypeNum != HTML_EL_XMLPI)
1.6       cvs       305:        BlockInCharLevelElem (el);
                    306: 
                    307:    switch (elType.ElTypeNum)
                    308:      {
1.62      quint     309:      case HTML_EL_Object:      /* it's an object */
1.79      quint     310:        data = NULL;
1.62      quint     311:        isImage = FALSE;
                    312:        /* is there a type attribute on the object element? */
                    313:        attrType.AttrSSchema = elType.ElSSchema;
                    314:        attrType.AttrTypeNum = HTML_ATTR_Object_type;
1.6       cvs       315:        attr = TtaGetAttribute (el, attrType);
1.62      quint     316:        if (attr)
                    317:         /* there is a type attribute. Get its value to see if the object
                    318:            represents an image */
1.6       cvs       319:         {
                    320:           length = TtaGetTextAttributeLength (attr);
                    321:           if (length > 0)
                    322:             {
1.100     gully     323:               name1 = (char *)TtaGetMemory (length + 1);
1.6       cvs       324:               TtaGiveTextAttributeValue (attr, name1, &length);
1.68      kahan     325:               if (!strcmp (name1, AM_MATHML_MIME_TYPE) ||
1.62      quint     326:                   !strcmp (name1, "application/postscript") ||
                    327:                   !strcmp (name1, "image/x-bitmap") ||
                    328:                   !strcmp (name1, "image/x-xpixmap") ||
                    329:                   !strcmp (name1, "image/gif") ||
                    330:                   !strcmp (name1, "image/jpeg") ||
                    331:                   !strcmp (name1, "image/png") ||
1.67      kahan     332:                   !strcmp (name1, "image/svg") ||
1.83      cvs       333:                   !strcmp (name1, AM_SVG_MIME_TYPE) ||
                    334:                   !strcmp (name1, AM_XHTML_MIME_TYPE) ||
                    335:                   !strcmp (name1, "text/html") ||
                    336:                   !strcmp (name1, "text/htm") ||
                    337:                   !strcmp (name1, AM_GENERIC_XML_MIME_TYPE))
1.62      quint     338:                 isImage = TRUE;
                    339:               TtaFreeMemory (name1);
                    340:             }
                    341:         }
1.79      quint     342: 
                    343:        attrType.AttrTypeNum = HTML_ATTR_data;
                    344:        attr = TtaGetAttribute (el, attrType);
                    345:        if (attr)
                    346:         /* the object has a data attribute */
                    347:         {
                    348:           length = TtaGetTextAttributeLength (attr);
                    349:           if (length > 0)
                    350:             {
1.100     gully     351:               data = (char *)TtaGetMemory (length + 1);
1.79      quint     352:               TtaGiveTextAttributeValue (attr, data, &length);
                    353:               if (!isImage)
                    354:                 if (!strcmp (&data[length-3], "mml") ||
                    355:                     !strcmp (&data[length-3], "gif") ||
                    356:                     !strcmp (&data[length-3], "jpg") ||
                    357:                     !strcmp (&data[length-4], "jpeg") ||
                    358:                     !strcmp (&data[length-3], "png") ||
                    359:                     !strcmp (&data[length-3], "svg") ||
1.80      cvs       360:                     !strcmp (&data[length-4], "svgz") ||
1.83      cvs       361:                     !strcmp (&data[length-3], "htm") ||
                    362:                     !strcmp (&data[length-4], "html") ||
                    363:                     !strcmp (&data[length-3], "xml"))
1.79      quint     364:                   isImage = TRUE;
                    365:             }
                    366:         }
1.62      quint     367:        picture = NULL;     /* no PICTURE element yet */
                    368:        child = TtaGetFirstChild (el);
                    369:        if (isImage)
                    370:         /* the object represents an image. We need a PICTURE element as
                    371:            child of the object to hold the image */
                    372:         {
1.113     vatton    373:           elType.ElTypeNum = HTML_EL_PICTURE_UNIT;
                    374:           picture = TtaNewTree (doc, elType, "");
1.62      quint     375:           if (child)
1.113     vatton    376:             TtaInsertSibling (picture, child, TRUE, doc);
                    377:           else
                    378:             TtaInsertFirstChild (&picture, el, doc);
1.62      quint     379:           /* copy attribute data of the object into the SRC attribute of
                    380:              the PICTURE element */
1.79      quint     381:           if (data)
                    382:             /* the object has a data attribute */
                    383:             {
                    384:               attrType.AttrTypeNum = HTML_ATTR_SRC;
                    385:               attr = TtaGetAttribute (picture, attrType);
                    386:               if (attr == NULL)
                    387:                 {
                    388:                   attr = TtaNewAttribute (attrType);
                    389:                   TtaAttachAttribute (picture, attr, doc);
                    390:                 }
                    391:               TtaSetAttributeText (attr, data, picture, doc);
                    392:             }
                    393:           attrType.AttrTypeNum = HTML_ATTR_Height_;
1.62      quint     394:           attr = TtaGetAttribute (el, attrType);
                    395:           if (attr)
1.79      quint     396:             /* the Object has a height attribute. Applies it to the
                    397:                picture element */
                    398:             {
                    399:               length = TtaGetTextAttributeLength (attr);
                    400:               if (length > 0)
                    401:                 {
1.100     gully     402:                   text = (char *)TtaGetMemory (length + 1);
1.79      quint     403:                   TtaGiveTextAttributeValue (attr, text, &length);
                    404:                   /* create the corresponding attribute IntHeightPercent or */
                    405:                   /* IntHeightPxl */
                    406:                   CreateAttrHeightPercentPxl (text, el, doc, -1);
                    407:                   TtaFreeMemory (text);
                    408:                 }
                    409:             }
                    410:           attrType.AttrTypeNum = HTML_ATTR_Width__;
                    411:           attr = TtaGetAttribute (el, attrType);
                    412:           if (attr)
                    413:             /* the Object has a width attribute. Applies it to the
                    414:                picture element */
1.62      quint     415:             {
                    416:               length = TtaGetTextAttributeLength (attr);
                    417:               if (length > 0)
1.6       cvs       418:                 {
1.100     gully     419:                   text = (char *)TtaGetMemory (length + 1);
1.79      quint     420:                   TtaGiveTextAttributeValue (attr, text, &length);
                    421:                   /* create the corresponding attribute IntWidthPercent or */
                    422:                   /* IntWidthPxl */
                    423:                   CreateAttrWidthPercentPxl (text, el, doc, -1);
                    424:                   TtaFreeMemory (text);
1.6       cvs       425:                 }
                    426:             }
                    427:         }
                    428:        /* is the Object_Content element already created ? */
1.62      quint     429:        if (child)
                    430:         /* the object element has at least 1 child element */
                    431:         {
                    432:           content = NULL;
                    433:           desc = child;
1.6       cvs       434:           elType = TtaGetElementType (desc);
1.62      quint     435:           if (elType.ElTypeNum != HTML_EL_Object_Content)
                    436:             {
                    437:               TtaNextSibling(&desc);
                    438:               if (desc)
                    439:                 elType = TtaGetElementType (desc);
                    440:             }
                    441:           /* is it the Object_Content element ? */
                    442:           if (elType.ElTypeNum == HTML_EL_Object_Content)
                    443:             content = desc;
                    444:           else
1.6       cvs       445:             {
1.62      quint     446:               /* create an Object_Content element */
                    447:               elType.ElTypeNum = HTML_EL_Object_Content;
                    448:               content = TtaNewElement (doc, elType);
                    449:               if (picture)
                    450:                 TtaInsertSibling (content, picture, FALSE, doc);
                    451:               else
                    452:                 TtaInsertSibling (content, child, TRUE, doc);
                    453:               /* move previous existing children into Object_Content */
1.6       cvs       454:               child = TtaGetLastChild(el);
1.62      quint     455:               while (child != content)
                    456:                 {
                    457:                   TtaRemoveTree (child, doc);
                    458:                   TtaInsertFirstChild (&child, content, doc);
                    459:                   child = TtaGetLastChild(el);
                    460:                 }
                    461:             }
1.6       cvs       462:         }
1.79      quint     463:        if (data)
                    464:         TtaFreeMemory (data);
1.6       cvs       465:        break;
1.62      quint     466: 
1.114     vatton    467:      case HTML_EL_Parameter:
                    468:        /* Check the mandatory name attribute */
                    469:        CheckMandatoryAttribute (el, doc, HTML_ATTR_Param_name);
                    470:        break;
                    471: 
1.105     cvs       472:      case HTML_EL_IFRAME:        /* it's an iframe */
                    473:        child = TtaGetFirstChild (el);
                    474:        /* is the Iframe_Content element already created ? */
                    475:        if (child)
                    476:         /* the iframe element has at least 1 child element */
                    477:         {
                    478:           content = NULL;
                    479:           desc = child;
                    480:           elType = TtaGetElementType (desc);
                    481:           if (elType.ElTypeNum != HTML_EL_Iframe_Content)
                    482:             {
                    483:               TtaNextSibling(&desc);
                    484:               if (desc)
                    485:                 elType = TtaGetElementType (desc);
                    486:             }
                    487:           /* is it the Iframe_Content element ? */
                    488:           if (elType.ElTypeNum == HTML_EL_Iframe_Content)
                    489:             content = desc;
                    490:           else
                    491:             {
                    492:               /* create an Iframe_Content element */
                    493:               elType.ElTypeNum = HTML_EL_Iframe_Content;
                    494:               content = TtaNewElement (doc, elType);
                    495:               TtaInsertSibling (content, child, TRUE, doc);
                    496:               /* move previous existing children into Iframe_Content */
                    497:               child = TtaGetLastChild(el);
                    498:               while (child != content)
                    499:                 {
                    500:                   TtaRemoveTree (child, doc);
                    501:                   TtaInsertFirstChild (&child, content, doc);
                    502:                   child = TtaGetLastChild(el);
                    503:                 }
                    504:             }
                    505:         }
                    506:        break;
                    507: 
1.6       cvs       508:      case HTML_EL_Unnumbered_List:
                    509:      case HTML_EL_Numbered_List:
                    510:      case HTML_EL_Menu:
                    511:      case HTML_EL_Directory:
                    512:        /* It's a List element. It should only have List_Item children.
                    513:          If it has List element chidren, move these List elements
                    514:          within their previous List_Item sibling.  This is to fix
                    515:          a bug in document generated by Mozilla. */
                    516:        prev = NULL;
                    517:        next = NULL;
                    518:        child = TtaGetFirstChild (el);
                    519:        while (child != NULL)
                    520:         {
                    521:           next = child;
                    522:           TtaNextSibling (&next);
                    523:           elType = TtaGetElementType (child);
                    524:           if (elType.ElTypeNum == HTML_EL_Unnumbered_List ||
                    525:               elType.ElTypeNum == HTML_EL_Numbered_List ||
                    526:               elType.ElTypeNum == HTML_EL_Menu ||
                    527:               elType.ElTypeNum == HTML_EL_Directory)
                    528:             /* this list element is a child of another list element */
                    529:             if (prev)
                    530:               {
                    531:                 elType = TtaGetElementType (prev);
                    532:                 if (elType.ElTypeNum == HTML_EL_List_Item)
                    533:                   {
                    534:                     /* get the last child of the previous List_Item */
                    535:                     desc = TtaGetFirstChild (prev);
                    536:                     last = NULL;
                    537:                     while (desc)
                    538:                       {
                    539:                         last = desc;
                    540:                         TtaNextSibling (&desc);
                    541:                       }
                    542:                     /* move the list element after the last child of the
                    543:                        previous List_Item */
                    544:                     TtaRemoveTree (child, doc);
                    545:                     if (last)
                    546:                       TtaInsertSibling (child, last, FALSE, doc);
                    547:                     else
                    548:                       TtaInsertFirstChild (&child, prev, doc);
                    549:                     child = prev;
                    550:                   }
                    551:               }
                    552:           prev = child;
                    553:           child = next;
                    554:         }
                    555:        break;
                    556:        
                    557:      case HTML_EL_FRAMESET:
                    558:        /* The FRAMESET element is now complete.  Gather all its FRAMESET
                    559:          and FRAME children and wrap them up in a Frames element */
                    560:        elFrames = NULL; lastFrame = NULL;
                    561:        lastChild = NULL;
                    562:        child = TtaGetFirstChild (el);
                    563:        while (child != NULL)
                    564:         {
                    565:           next = child;
                    566:           TtaNextSibling (&next);
                    567:           elType = TtaGetElementType (child);
                    568:           if (elType.ElTypeNum == HTML_EL_FRAMESET ||
                    569:               elType.ElTypeNum == HTML_EL_FRAME ||
                    570:               elType.ElTypeNum == HTML_EL_Comment_)
                    571:             {
                    572:               /* create the Frames element if it does not exist */
                    573:               if (elFrames == NULL)
                    574:                 {
1.109     vatton    575:                   newElType.ElSSchema = htmlSchema;
1.6       cvs       576:                   newElType.ElTypeNum = HTML_EL_Frames;
                    577:                   elFrames = TtaNewElement (doc, newElType);
1.63      cvs       578:                   if (DocumentMeta[doc]->xmlformat)
                    579:                     XmlSetElemLineNumber (elFrames);
                    580:                   else
                    581:                     SetHtmlElemLineNumber (elFrames);
1.6       cvs       582:                   TtaInsertSibling (elFrames, child, TRUE, doc);
                    583:                 }
                    584:               /* move the element as the last child of the Frames element */
                    585:               TtaRemoveTree (child, doc);
                    586:               if (lastFrame == NULL)
                    587:                 TtaInsertFirstChild (&child, elFrames, doc);
                    588:               else
                    589:                 TtaInsertSibling (child, lastFrame, FALSE, doc);
                    590:               lastFrame = child;
                    591:             }
                    592:           child = next;
                    593:         }
                    594:        break;
                    595:        
1.116     quint     596:      case HTML_EL_Form:
                    597:        /* Check the mandatory action attribute */
                    598:        CheckMandatoryAttribute (el, doc, HTML_ATTR_Script_URL);
                    599:        break;
                    600: 
1.6       cvs       601:      case HTML_EL_Input:       /* it's an INPUT without any TYPE attribute */
                    602:        /* Create a child of type Text_Input */
                    603:        elType.ElTypeNum = HTML_EL_Text_Input;
                    604:        child = TtaNewTree (doc, elType, "");
1.63      cvs       605:        if (DocumentMeta[doc]->xmlformat)
                    606:         XmlSetElemLineNumber (child);
                    607:        else
                    608:         SetHtmlElemLineNumber (child);
1.6       cvs       609:        TtaInsertFirstChild (&child, el, doc);
                    610:        /* now, process it like a Text_Input element */
                    611: 
                    612:      case HTML_EL_Text_Input:
                    613:      case HTML_EL_Password_Input:
                    614:      case HTML_EL_File_Input:
1.91      quint     615:        /* set default size */
                    616:        attrType.AttrSSchema = elType.ElSSchema;
                    617:        attrType.AttrTypeNum = HTML_ATTR_IntAreaSize;
                    618:        attr = TtaGetAttribute (el, attrType);
                    619:        if (!attr)
                    620:         CreateAttrIntAreaSize (20, el, doc);
1.6       cvs       621:        /* get element Inserted_Text */
                    622:        child = TtaGetFirstChild (el);
                    623:        if (child != NULL)
                    624:         {
                    625:           attrType.AttrTypeNum = HTML_ATTR_Value_;
                    626:           attr = TtaGetAttribute (el, attrType);
                    627:           if (attr != NULL)
                    628:             {
                    629:               /* copy the value of attribute "value" into the first text
                    630:                  leaf of element */
                    631:               length = TtaGetTextAttributeLength (attr);
                    632:               if (length > 0)
                    633:                 {
                    634:                   /* get the text leaf */
                    635:                   leaf = TtaGetFirstChild (child);
                    636:                   if (leaf != NULL)
                    637:                     {
                    638:                       childType = TtaGetElementType (leaf);
                    639:                       if (childType.ElTypeNum == HTML_EL_TEXT_UNIT)
                    640:                         {
                    641:                           /* copy attribute value into the text leaf */
1.100     gully     642:                           text = (char *)TtaGetMemory (length + 1);
1.6       cvs       643:                           TtaGiveTextAttributeValue (attr, text, &length);
1.100     gully     644:                           TtaSetTextContent (leaf, (unsigned char *)text, 
1.6       cvs       645:                                              TtaGetDefaultLanguage (), doc);
                    646:                           TtaFreeMemory (text);
                    647:                         }
                    648:                     }
                    649:                 }
                    650:             }
                    651:         }
                    652:        break;
                    653:        
                    654:      case HTML_EL_META:
1.104     vatton    655:        ParseCharsetAndContentType (el, doc);
1.114     vatton    656:        /* Check the mandatory CONTENT attribute */
                    657:        CheckMandatoryAttribute (el, doc, HTML_ATTR_meta_content);
                    658:        break;
                    659: 
                    660:      case HTML_EL_BASE:
                    661:        /* Check the mandatory HREF attribute */
                    662:        CheckMandatoryAttribute (el, doc, HTML_ATTR_HREF_);
                    663:        break;
                    664: 
                    665:      case HTML_EL_BaseFont:
                    666:        /* Check the mandatory size attribute */
                    667:        CheckMandatoryAttribute (el, doc, HTML_ATTR_BaseFontSize);
                    668:        break;
                    669: 
                    670:      case HTML_EL_BDO:
                    671:        /* Check the mandatory DIR attribute */
                    672:        CheckMandatoryAttribute (el, doc, HTML_ATTR_dir);
1.6       cvs       673:        break;
                    674: 
                    675:      case HTML_EL_STYLE_:      /* it's a STYLE element */
1.60      vatton    676:      case HTML_EL_SCRIPT_:     /* it's a SCRIPT element */
1.6       cvs       677:      case HTML_EL_Preformatted:        /* it's a PRE */
                    678:        /* if the last line of the Preformatted is empty, remove it */
                    679:        leaf = XmlLastLeafInElement (el);
                    680:        if (leaf != NULL)
                    681:         {
                    682:           elType = TtaGetElementType (leaf);
                    683:           if (elType.ElTypeNum == HTML_EL_TEXT_UNIT)
                    684:             /* the last leaf is a TEXT element */
                    685:             {
                    686:               length = TtaGetTextLength (leaf);
                    687:               if (length > 0)
                    688:                 {
1.100     gully     689:                   TtaGiveSubString (leaf, (unsigned char *)lastChar, length, 1);
1.6       cvs       690:                   if (lastChar[0] == EOL)
                    691:                     /* last character is new line, delete it */
                    692:                     {
                    693:                       if (length == 1)
                    694:                         /* empty TEXT element */
                    695:                         TtaDeleteTree (leaf, doc);
                    696:                       else
                    697:                         /* remove the last character */
                    698:                         TtaDeleteTextContent (leaf, length, 1, doc);
                    699:                     }
                    700:                 }
                    701:             }
                    702:         }
1.114     vatton    703: 
                    704:        if (elType.ElTypeNum == HTML_EL_STYLE_)
                    705:         /* Check the mandatory TYPE attribute */
                    706:         CheckMandatoryAttribute (el, doc, HTML_ATTR_Notation);
                    707:        else if (elType.ElTypeNum == HTML_EL_SCRIPT_)
                    708:         /* Check the mandatory TYPE attribute */
                    709:         CheckMandatoryAttribute (el, doc, HTML_ATTR_content_type);
                    710: 
1.75      kahan     711:        if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
1.63      cvs       712:         {
                    713:           if (IsXmlParsingCSS ())
                    714:             {
                    715:               text = GetStyleContents (el);
                    716:               if (text)
                    717:                 {
1.71      vatton    718:                   ReadCSSRules (doc, NULL, text, NULL,
1.82      quint     719:                                 TtaGetElementLineNumber (el), FALSE, el);
1.63      cvs       720:                   TtaFreeMemory (text);
                    721:                 }
                    722:               SetXmlParsingCSS (FALSE);
                    723:             }
                    724:         }
                    725:        else
1.6       cvs       726:         {
1.63      cvs       727:           if (IsHtmlParsingCSS ())
1.6       cvs       728:             {
1.63      cvs       729:               text = GetStyleContents (el);
                    730:               if (text)
                    731:                 {
1.71      vatton    732:                   ReadCSSRules (doc, NULL, text, NULL,
1.82      quint     733:                                 TtaGetElementLineNumber (el), FALSE, el);
1.63      cvs       734:                   TtaFreeMemory (text);
                    735:                 }
                    736:               SetHtmlParsingCSS (FALSE);
1.6       cvs       737:             }
                    738:         }
                    739:        /* and continue as if it were a Preformatted or a Script */
                    740:        break;
                    741:        
                    742:      case HTML_EL_Text_Area:   /* it's a Text_Area */
1.69      cvs       743:        if (DocumentMeta[doc]->xmlformat)
                    744:         SetParsingTextArea (FALSE);
                    745:        else
                    746:         SetHtmlParsingTextArea (FALSE);
1.6       cvs       747:        child = TtaGetFirstChild (el);
                    748:        if (child == NULL)
                    749:         /* it's an empty Text_Area */
1.97      quint     750:         /* insert a Inserted_Text element and a child Basic_Elem in the
                    751:             Text_Area element */
1.6       cvs       752:         {
                    753:           newElType.ElTypeNum = HTML_EL_Inserted_Text;
                    754:           child = TtaNewTree (doc, newElType, "");
                    755:           TtaInsertFirstChild (&child, el, doc);
                    756:         }
                    757:        else
                    758:         {
                    759:           /* save the text into Default_Value attribute */
1.109     vatton    760:           attrType.AttrSSchema = htmlSchema;
1.6       cvs       761:           attrType.AttrTypeNum = HTML_ATTR_Default_Value;
                    762:           if (TtaGetAttribute (el, attrType) == NULL)
                    763:             /* attribute Default_Value is missing */
                    764:             {
                    765:               desc = TtaGetFirstChild (child);
1.97      quint     766:               if (desc)
                    767:                 {
                    768:                   length = TtaGetTextLength (desc);
                    769:                   if (length > 0)
                    770:                     {
                    771:                       length++;
                    772:                       attr = TtaNewAttribute (attrType);
                    773:                       TtaAttachAttribute (el, attr, doc);
1.100     gully     774:                       text = (char *)TtaGetMemory (length);
                    775:                       TtaGiveTextContent (desc, (unsigned char *)text, &length, &lang);
1.97      quint     776:                       TtaSetAttributeText (attr, text, el, doc);
                    777:                       TtaFreeMemory (text);
                    778:                     }
                    779:                 }
1.6       cvs       780:             }
                    781:         }
1.114     vatton    782:        /* Check the mandatory rows attribute */
                    783:        CheckMandatoryAttribute (el, doc, HTML_ATTR_Rows);
                    784:        /* Check the mandatory columns attribute */
                    785:        CheckMandatoryAttribute (el, doc, HTML_ATTR_Columns);
1.118     vatton    786:        /* Add default rows and columns attributes */
                    787:        AddRowsColumns (el, doc);
1.6       cvs       788:        break;
1.103     quint     789: 
1.6       cvs       790:      case HTML_EL_Radio_Input:
                    791:      case HTML_EL_Checkbox_Input:
                    792:        /* put an attribute Checked if it is missing */
1.109     vatton    793:        attrType.AttrSSchema = htmlSchema;
1.6       cvs       794:        attrType.AttrTypeNum = HTML_ATTR_Checked;
                    795:        if (TtaGetAttribute (el, attrType) == NULL)
                    796:         /* attribute Checked is missing */
                    797:         {
                    798:           attr = TtaNewAttribute (attrType);
                    799:           TtaAttachAttribute (el, attr, doc);
                    800:           TtaSetAttributeValue (attr, HTML_ATTR_Checked_VAL_No_, el, doc);
                    801:         }
                    802:        break;
                    803:        
                    804:      case HTML_EL_Option_Menu:
                    805:        /* Check that at least one option has a SELECTED attribute */
                    806:        OnlyOneOptionSelected (el, doc, TRUE);
1.114     vatton    807:        break;
                    808: 
                    809:      case HTML_EL_OptGroup:
                    810:        /* Check the mandatory label attribute */
                    811:        CheckMandatoryAttribute (el, doc, HTML_ATTR_label);
1.6       cvs       812:        break;
                    813: 
1.116     quint     814:      case HTML_EL_MAP:
                    815:      case HTML_EL_map:
1.117     quint     816:        /* Check the mandatory attributes */
                    817:        if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
                    818:         /* it's XHTML. Check attribute id */
                    819:         CheckMandatoryAttribute (el, doc, HTML_ATTR_ID);
                    820:        else
                    821:         /* it's a HTML document. Check attribute name */
                    822:         CheckMandatoryAttribute (el, doc, HTML_ATTR_NAME);
1.116     quint     823:        break;
                    824: 
                    825:      case HTML_EL_AREA:
                    826:        /* Check the mandatory alt attribute */
                    827:        CheckMandatoryAttribute (el, doc, HTML_ATTR_ALT);
                    828:        break;
                    829: 
1.6       cvs       830:      case HTML_EL_PICTURE_UNIT:
1.111     vatton    831:        /* Check the mandatory ALT attribute */
1.114     vatton    832:        attrType.AttrSSchema = htmlSchema;
                    833:        attrType.AttrTypeNum = HTML_ATTR_IsInput;
                    834:        if (TtaGetAttribute (el, attrType) == NULL)
                    835:         CheckMandatoryAttribute (el, doc, HTML_ATTR_ALT);
                    836:        /* Check the mandatory SRC attribute */
                    837:        CheckMandatoryAttribute (el, doc, HTML_ATTR_SRC);
1.6       cvs       838:        break;
                    839:        
                    840:      case HTML_EL_LINK:
1.109     vatton    841:        CheckCSSLink (el, doc, htmlSchema);
1.6       cvs       842:        break;
                    843:        
                    844:      case HTML_EL_Data_cell:
                    845:      case HTML_EL_Heading_cell:
1.107     quint     846:      case HTML_EL_List_Item:
                    847:      case HTML_EL_Definition:
                    848:        /* insert a pseudo paragraph into empty cells or list items */
1.6       cvs       849:        child = TtaGetFirstChild (el);
                    850:        if (child == NULL)
                    851:         {
                    852:           elType.ElTypeNum = HTML_EL_Pseudo_paragraph;
                    853:           child = TtaNewTree (doc, elType, "");
                    854:           if (child != NULL)
                    855:               TtaInsertFirstChild (&child, el, doc);
                    856:         }
1.107     quint     857:        if (elType.ElTypeNum == HTML_EL_Data_cell ||
                    858:           elType.ElTypeNum == HTML_EL_Heading_cell)
                    859:         /* detect whether we are parsing a whole table or just a cell */
1.63      cvs       860:         {
1.107     quint     861:           if (DocumentMeta[doc]->xmlformat)
                    862:             {
                    863:               if (IsWithinXmlTable ())
                    864:                 NewCell (el, doc, FALSE, FALSE, FALSE);
                    865:             }
                    866:           else
                    867:             {
                    868:               if (IsWithinHtmlTable ())
                    869:                 NewCell (el, doc, FALSE, FALSE, FALSE);
                    870:             }
1.63      cvs       871:         }
1.6       cvs       872:        break;
                    873:        
1.110     quint     874:      case HTML_EL_Table_:
1.6       cvs       875:        CheckTable (el, doc);
                    876:        SubWithinTable ();
                    877:        break;
                    878:        
                    879:      case HTML_EL_TITLE:
                    880:        /* show the TITLE in the main window */
                    881:        UpdateTitle (el, doc);
                    882:        break;
1.41      cvs       883: 
                    884:      case HTML_EL_rbc:
                    885:        /* an rbc element has been read. Its parent should be a complex_ruby.
                    886:          Change the type of the parent, as simple_ruby are created by
                    887:          default */
                    888:        parent = TtaGetParent (el);
                    889:        if (parent)
                    890:         {
                    891:           newElType = TtaGetElementType (parent);
                    892:           if (newElType.ElSSchema == elType.ElSSchema &&
                    893:               newElType.ElTypeNum == HTML_EL_simple_ruby)
1.95      vatton    894:              TtaChangeElementType (parent, HTML_EL_complex_ruby);
1.41      cvs       895:         }
                    896:        break;
                    897: 
                    898:      case HTML_EL_rtc1:
                    899:        /* an rtc element has been parsed. If it has already a rtc1 sibling,
                    900:          change its type to rtc2 */
                    901:        prev = el;
                    902:        do
                    903:         {
                    904:           TtaPreviousSibling(&prev);
                    905:           if (prev)
                    906:             {
                    907:               newElType = TtaGetElementType (prev);
                    908:               if (newElType.ElSSchema == elType.ElSSchema &&
                    909:                   newElType.ElTypeNum == HTML_EL_rtc1)
                    910:                 {
1.95      vatton    911:                   TtaChangeElementType (el, HTML_EL_rtc2);
1.41      cvs       912:                   prev = NULL;
                    913:                 }
                    914:             }
                    915:         }
                    916:        while (prev);
                    917:        break;
                    918: 
1.6       cvs       919:      default:
                    920:        break;
                    921:      }
                    922: }
1.1       cvs       923: 
                    924: /*----------------------------------------------------------------------
1.30      cvs       925:    PutInContent    
                    926:    Put the string ChrString in the leaf of current element.
                    927:   ----------------------------------------------------------------------*/
1.39      cvs       928: Element         PutInContent (char *ChrString, ParserData *context)
1.30      cvs       929: 
                    930: {
                    931:    Element      el, child;
                    932:    ElementType  elType;
                    933:    int          length;
                    934: 
                    935:    el = NULL;
                    936:    if (context->lastElement != NULL)
                    937:      {
                    938:        /* search first leaf of current element */
                    939:        el = context->lastElement;
                    940:        do
                    941:          {
                    942:             child = TtaGetFirstChild (el);
                    943:             if (child != NULL)
                    944:                el = child;
                    945:          }
                    946:        while (child != NULL);
                    947:        elType = TtaGetElementType (el);
                    948:        length = 0;
                    949:        if (elType.ElTypeNum == 1)
                    950:           length = TtaGetTextLength (el);
                    951:        if (length == 0)
1.114     vatton    952:           TtaSetTextContent (el, (unsigned char *)ChrString,
                    953:                              context->language, context->doc);
1.30      cvs       954:        else
1.100     gully     955:           TtaAppendTextContent (el, (unsigned char *)ChrString, context->doc);
1.30      cvs       956:      }
                    957:    return el;
                    958: }
                    959: 
                    960: /*----------------------------------------------------------------------
1.93      vatton    961:   UnknownXhtmlNameSpace
                    962:   The element doesn't belong to a supported namespace
1.51      cvs       963:   ----------------------------------------------------------------------*/
1.93      vatton    964: void UnknownXhtmlNameSpace (ParserData *context, Element *unknownEl,
                    965:                            char* content)
1.51      cvs       966: {
                    967:    ElementType     elType;
1.65      cvs       968:    Element         elText;
1.51      cvs       969: 
                    970:    /* Create a new Invalid_element */
                    971:    elType.ElSSchema = GetXMLSSchema (XHTML_TYPE, context->doc);
1.94      cvs       972:    elType.ElTypeNum = HTML_EL_XHTML_Unknown_namespace;
1.65      cvs       973:    *unknownEl = TtaNewElement (context->doc, elType);
                    974:    if (*unknownEl != NULL)
1.51      cvs       975:      {
1.65      cvs       976:        XmlSetElemLineNumber (*unknownEl);
                    977:        InsertXmlElement (unknownEl);
1.51      cvs       978:        context->lastElementClosed = TRUE;
                    979:        elType.ElTypeNum = HTML_EL_TEXT_UNIT;
                    980:        elText = TtaNewElement (context->doc, elType);
                    981:        XmlSetElemLineNumber (elText);
1.65      cvs       982:        TtaInsertFirstChild (&elText, *unknownEl, context->doc);
1.100     gully     983:        TtaSetTextContent (elText, (unsigned char *)content, context->language, context->doc);
1.51      cvs       984:        TtaSetAccessRight (elText, ReadOnly, context->doc);
                    985:      }
                    986: }
                    987: 
                    988: /*----------------------------------------------------------------------
1.30      cvs       989:    CreateHTMLAttribute
                    990:    create an attribute of type attrType for the element el.
                    991:   ----------------------------------------------------------------------*/
1.93      vatton    992: void CreateHTMLAttribute (Element       el,
                    993:                          AttributeType attrType,
                    994:                          char*         text,
                    995:                          ThotBool      isInvalid,
                    996:                          Document      doc,
                    997:                          Attribute    *lastAttribute,
                    998:                          Element      *lastAttrElement)
1.30      cvs       999: {
                   1000:    int         attrKind;
                   1001:    int         length;
1.39      cvs      1002:    char       *buffer;
1.30      cvs      1003:    Attribute   attr, oldAttr;
                   1004: 
                   1005:    if (attrType.AttrTypeNum != 0)
                   1006:      {
                   1007:        oldAttr = TtaGetAttribute (el, attrType);
                   1008:        if (oldAttr != NULL)
                   1009:         /* this attribute already exists */
                   1010:         attr = oldAttr;
                   1011:        else
                   1012:         /* create a new attribute and attach it to the element */
                   1013:         {
                   1014:           attr = TtaNewAttribute (attrType);
                   1015:           TtaAttachAttribute (el, attr, doc);
                   1016:         }
                   1017:        *lastAttribute = attr;
                   1018:        *lastAttrElement = el;
                   1019: 
                   1020:        TtaGiveAttributeType (attr, &attrType, &attrKind);
                   1021:        if (attrKind == 0)      /* enumerate */
                   1022:         TtaSetAttributeValue (attr, 1, el, doc);
                   1023: 
                   1024:        /* attribute BORDER without any value (ThotBool attribute) is */
                   1025:        /* considered as BORDER=1 */
                   1026:        if (attrType.AttrTypeNum == HTML_ATTR_Border)
                   1027:         TtaSetAttributeValue (attr, 1, el, doc);
                   1028: 
                   1029:        if (isInvalid)
                   1030:         /* Copy the name of the invalid attribute as the content */
                   1031:         /* of the Invalid_attribute attribute. */
                   1032:         {
1.37      cvs      1033:           length = strlen (text) + 2;
1.30      cvs      1034:           length += TtaGetTextAttributeLength (attr);
1.100     gully    1035:           buffer = (char *)TtaGetMemory (length + 1);
1.30      cvs      1036:           TtaGiveTextAttributeValue (attr, buffer, &length);
1.37      cvs      1037:           strcat (buffer, " ");
                   1038:           strcat (buffer, text);
1.30      cvs      1039:           TtaSetAttributeText (attr, buffer, el, doc);
                   1040:           TtaFreeMemory (buffer);
                   1041:         }
                   1042:      }
                   1043: }
                   1044: 
                   1045: /*----------------------------------------------------------------------
                   1046:    HTMLTypeAttrValue
                   1047:    Value val has been read for the HTML attribute TYPE.
                   1048:    Create a child for the current Thot element INPUT accordingly.
                   1049:   ----------------------------------------------------------------------*/
1.109     vatton   1050: void HTMLTypeAttrValue (char *val, Attribute lastAttribute,
                   1051:                        Element lastAttrElement, ParserData *context)
1.30      cvs      1052: {
                   1053:   ElementType      elType;
                   1054:   Element          newChild;
                   1055:   AttributeType    attrType;
                   1056:   Attribute        attr;
1.39      cvs      1057:   char             msgBuffer[MaxMsgLength];
1.30      cvs      1058:   int              value;
                   1059:   int              numberOfLinesRead;
                   1060: 
                   1061:   value = MapAttrValue (DummyAttribute, val);
1.109     vatton   1062:   elType = TtaGetElementType (context->lastElement);
1.91      quint    1063:   if (value <= 0)
1.30      cvs      1064:     {
1.37      cvs      1065:       if (strlen (val) > MaxMsgLength - 40)
                   1066:          val[MaxMsgLength - 40] = EOS;
                   1067:       sprintf (msgBuffer, "Unknown attribute value \"type = %s\"", val);
1.117     quint    1068:       HTMLParseError (context->doc, msgBuffer, 0);
1.109     vatton   1069:       attrType.AttrSSchema = elType.ElSSchema;
1.30      cvs      1070:       attrType.AttrTypeNum = pHTMLAttributeMapping[0].ThotAttribute;
1.37      cvs      1071:       sprintf (msgBuffer, "type=%s", val);
1.30      cvs      1072:       CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
                   1073:                           context->doc, &lastAttribute, &lastAttrElement);
                   1074:     }
                   1075:   else
                   1076:     {
                   1077:       if (elType.ElTypeNum != HTML_EL_Input)
                   1078:        {
1.37      cvs      1079:          if (strlen (val) > MaxMsgLength - 40)
                   1080:            val[MaxMsgLength - 40] = EOS;
                   1081:          sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.30      cvs      1082:        }
                   1083:       else
                   1084:        {
                   1085:          elType.ElTypeNum = value;
                   1086:          newChild = TtaNewTree (context->doc, elType, "");
                   1087:          numberOfLinesRead = 0;
                   1088:          TtaSetElementLineNumber (newChild, numberOfLinesRead);
                   1089:          TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
                   1090:          if (value == HTML_EL_PICTURE_UNIT)
                   1091:            {
                   1092:              /* add the attribute IsInput to input pictures */
                   1093:              attrType.AttrSSchema = elType.ElSSchema;
                   1094:              attrType.AttrTypeNum = HTML_ATTR_IsInput;
                   1095:              attr = TtaNewAttribute (attrType);
                   1096:              TtaAttachAttribute (newChild, attr, context->doc);
                   1097:            }
                   1098:        }
                   1099:     }
                   1100: }
                   1101: 
                   1102: /*----------------------------------------------------------------------
                   1103:    XhtmlTypeAttrValue 
                   1104:    Value val has been read for the HTML attribute TYPE.
                   1105:    Create a child for the current Thot element INPUT accordingly.
                   1106:   ----------------------------------------------------------------------*/
1.111     vatton   1107: void XhtmlTypeAttrValue (char       *val,
                   1108:                         Attribute   currentAttribute,
                   1109:                         Element     lastAttrElement,
                   1110:                         ParserData *context)
1.30      cvs      1111: {
                   1112:   ElementType     elType;
                   1113:   Element         newChild;
                   1114:   AttributeType   attrType;
                   1115:   Attribute       attr;
1.39      cvs      1116:   char            msgBuffer[MaxMsgLength];
1.30      cvs      1117:   int             value;
                   1118:   ThotBool        level;
                   1119: 
1.91      quint    1120:   /* Look in the dummy section of the attribute value table */
1.30      cvs      1121:   attrType.AttrTypeNum = DummyAttribute;
1.100     gully    1122:   MapHTMLAttributeValue (val, &attrType, &value);
1.91      quint    1123:   if (value <= 0)
                   1124:     /* invalid value for the type attribute of an input element */
1.30      cvs      1125:     {
1.37      cvs      1126:       sprintf (msgBuffer, "Unknown attribute value \"type=%s\"", val);
1.100     gully    1127:       XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
1.36      cvs      1128:       MapHTMLAttribute ("unknown_attr", &attrType, NULL,
1.30      cvs      1129:                        &level, context->doc);
1.37      cvs      1130:       sprintf (msgBuffer, "type=%s", val);
1.30      cvs      1131:       CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
                   1132:                           context->doc, &currentAttribute, &lastAttrElement);
                   1133:     }
                   1134:   else
1.91      quint    1135:     /* value is the Thot type of the element to be created for this value of
                   1136:        the TYPE attribute */
1.30      cvs      1137:     {
                   1138:       elType = TtaGetElementType (context->lastElement);
                   1139:       if (elType.ElTypeNum != HTML_EL_Input)
                   1140:        {
1.37      cvs      1141:          sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.100     gully    1142:          XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
1.30      cvs      1143:        }
                   1144:       else
                   1145:        {
                   1146:          elType.ElTypeNum = value;
                   1147:          newChild = TtaNewTree (context->doc, elType, "");
                   1148:          XmlSetElemLineNumber (newChild);
                   1149:          TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
                   1150:          if (value == HTML_EL_PICTURE_UNIT)
                   1151:            {
                   1152:              /* add the attribute IsInput to input pictures */
                   1153:              attrType.AttrSSchema = elType.ElSSchema;
                   1154:              attrType.AttrTypeNum = HTML_ATTR_IsInput;
                   1155:              attr = TtaNewAttribute (attrType);
                   1156:              TtaAttachAttribute (newChild, attr, context->doc);
                   1157:            }
                   1158:        }
                   1159:     }
                   1160: }
                   1161: 
                   1162: /*----------------------------------------------------------------------
                   1163:    CreateAttrWidthPercentPxl
1.79      quint    1164:    an HTML attribute "width" has been created for a Table, an image,
                   1165:    an Object of a HR.
1.30      cvs      1166:    Create the corresponding attribute IntWidthPercent or IntWidthPxl.
                   1167:    oldWidth is -1 or the old image width.
                   1168:   ----------------------------------------------------------------------*/
1.58      vatton   1169: void CreateAttrWidthPercentPxl (char *buffer, Element el,
                   1170:                                Document doc, int oldWidth)
1.30      cvs      1171: {
                   1172:   AttributeType   attrTypePxl, attrTypePercent;
                   1173:   Attribute       attrOld, attrNew;
                   1174:   int             length, val;
1.39      cvs      1175:   char            msgBuffer[MaxMsgLength];
1.79      quint    1176:   ElementType    elType, childType;
                   1177:   Element         origEl, child;
1.30      cvs      1178:   int             w, h;
                   1179:   ThotBool        isImage;
                   1180: 
1.79      quint    1181:   origEl = el;
1.30      cvs      1182:   elType = TtaGetElementType (el);
                   1183:   isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
                   1184:             elType.ElTypeNum == HTML_EL_Data_cell ||
1.79      quint    1185:             elType.ElTypeNum == HTML_EL_Heading_cell ||
                   1186:             elType.ElTypeNum == HTML_EL_Object);
                   1187:   if (elType.ElTypeNum == HTML_EL_Object)
                   1188:     /* the width attribute is attached to an Object element */
                   1189:     {
                   1190:       child = TtaGetFirstChild (el);
                   1191:       if (child)
                   1192:        {
                   1193:          childType = TtaGetElementType (child);
                   1194:          if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
                   1195:            /* the Object element is of type image. apply the width
                   1196:               attribute to the actual image element */
                   1197:            el = child;
                   1198:        }
                   1199:     }
1.30      cvs      1200:   /* remove trailing spaces */
1.37      cvs      1201:   length = strlen (buffer) - 1;
1.30      cvs      1202:   while (length > 0 && buffer[length] <= SPACE)
                   1203:     length--;
1.109     vatton   1204:   attrTypePxl.AttrSSchema = elType.ElSSchema;
                   1205:   attrTypePercent.AttrSSchema = elType.ElSSchema;
1.30      cvs      1206:   attrTypePxl.AttrTypeNum = HTML_ATTR_IntWidthPxl;
                   1207:   attrTypePercent.AttrTypeNum = HTML_ATTR_IntWidthPercent;
                   1208:   /* is the last character a '%' ? */
                   1209:   if (buffer[length] == '%')
                   1210:     {
                   1211:       /* remove IntWidthPxl */
                   1212:       attrOld = TtaGetAttribute (el, attrTypePxl);
                   1213:       /* update IntWidthPercent */
                   1214:       attrNew = TtaGetAttribute (el, attrTypePercent);
                   1215:       if (attrNew == NULL)
                   1216:        {
                   1217:          attrNew = TtaNewAttribute (attrTypePercent);
                   1218:          TtaAttachAttribute (el, attrNew, doc);
                   1219:        }
                   1220:       else if (isImage && oldWidth == -1)
                   1221:        {
                   1222:          if (attrOld == NULL)
                   1223:            oldWidth = TtaGetAttributeValue (attrNew);
                   1224:          else
                   1225:            oldWidth = TtaGetAttributeValue (attrOld);
                   1226:        }
                   1227:     }
                   1228:   else
                   1229:     {
                   1230:       /* remove IntWidthPercent */
                   1231:       attrOld = TtaGetAttribute (el, attrTypePercent);
                   1232:       /* update IntWidthPxl */
                   1233:       attrNew = TtaGetAttribute (el, attrTypePxl);
                   1234:       if (attrNew == NULL)
                   1235:        {
                   1236:          attrNew = TtaNewAttribute (attrTypePxl);
                   1237:          TtaAttachAttribute (el, attrNew, doc);
                   1238:        }
                   1239:       else if (isImage && oldWidth == -1)
                   1240:        {
                   1241:          TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
                   1242:          if (attrOld == NULL)
                   1243:            oldWidth = w * TtaGetAttributeValue (attrNew) / 100;
                   1244:          else
                   1245:            oldWidth = w * TtaGetAttributeValue (attrOld) / 100;          
                   1246:        }
                   1247:     }
                   1248: 
                   1249:   if (attrOld != NULL)
                   1250:     TtaRemoveAttribute (el, attrOld, doc);
1.43      cvs      1251:   if (sscanf (buffer, "%d", &val))
1.30      cvs      1252:     TtaSetAttributeValue (attrNew, val, el, doc);
                   1253:   else
                   1254:     /* its not a number. Delete attribute and send an error message */
                   1255:     {
                   1256:     TtaRemoveAttribute (el, attrNew, doc);
1.37      cvs      1257:     if (strlen (buffer) > MaxMsgLength - 30)
1.30      cvs      1258:         buffer[MaxMsgLength - 30] = EOS;
1.37      cvs      1259:     sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.117     quint    1260:     HTMLParseError (doc, msgBuffer, 0);
1.30      cvs      1261:     }
                   1262:   if (isImage)
1.79      quint    1263:     UpdateImageMap (origEl, doc, oldWidth, -1);
1.30      cvs      1264: }
                   1265: 
                   1266: /*----------------------------------------------------------------------
1.58      vatton   1267:    CreateAttrHeightPercentPxl
1.79      quint    1268:    an HTML attribute "width" has been created for a Table, an image,
                   1269:    an Object or a HR.
1.58      vatton   1270:    Create the corresponding attribute IntHeightPercent or IntHeightPxl.
                   1271:    oldHeight is -1 or the old image width.
                   1272:   ----------------------------------------------------------------------*/
                   1273: void CreateAttrHeightPercentPxl (char *buffer, Element el,
                   1274:                                Document doc, int oldHeight)
                   1275: {
                   1276:   AttributeType   attrTypePxl, attrTypePercent;
                   1277:   Attribute       attrOld, attrNew;
                   1278:   int             length, val;
                   1279:   char            msgBuffer[MaxMsgLength];
1.79      quint    1280:   ElementType    elType, childType;
                   1281:   Element         origEl, child;
1.58      vatton   1282:   int             w, h;
                   1283:   ThotBool        isImage;
                   1284: 
1.79      quint    1285:   origEl = el;
1.58      vatton   1286:   elType = TtaGetElementType (el);
                   1287:   isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
                   1288:             elType.ElTypeNum == HTML_EL_Data_cell ||
1.79      quint    1289:             elType.ElTypeNum == HTML_EL_Heading_cell ||
                   1290:             elType.ElTypeNum == HTML_EL_Object);
                   1291:   if (elType.ElTypeNum == HTML_EL_Object)
                   1292:     /* the height attribute is attached to an Object element */
                   1293:     {
                   1294:       child = TtaGetFirstChild (el);
1.81      cvs      1295:       if (!child)
                   1296:        return;
                   1297:       else
1.79      quint    1298:        {
                   1299:          childType = TtaGetElementType (child);
                   1300:          if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
                   1301:            /* the Object element is of type image. apply the width
                   1302:               attribute to the actual image element */
                   1303:            el = child;
1.81      cvs      1304:          else
                   1305:            return;
1.79      quint    1306:        }
                   1307:     }
1.58      vatton   1308:   /* remove trailing spaces */
                   1309:   length = strlen (buffer) - 1;
                   1310:   while (length > 0 && buffer[length] <= SPACE)
                   1311:     length--;
1.109     vatton   1312:   attrTypePxl.AttrSSchema = elType.ElSSchema;
                   1313:   attrTypePercent.AttrSSchema = elType.ElSSchema;
1.58      vatton   1314:   attrTypePxl.AttrTypeNum = HTML_ATTR_IntHeightPxl;
                   1315:   attrTypePercent.AttrTypeNum = HTML_ATTR_IntHeightPercent;
                   1316:   /* is the last character a '%' ? */
                   1317:   if (buffer[length] == '%')
                   1318:     {
                   1319:       /* remove IntHeightPxl */
                   1320:       attrOld = TtaGetAttribute (el, attrTypePxl);
                   1321:       /* update IntHeightPercent */
                   1322:       attrNew = TtaGetAttribute (el, attrTypePercent);
                   1323:       if (attrNew == NULL)
                   1324:        {
                   1325:          attrNew = TtaNewAttribute (attrTypePercent);
                   1326:          TtaAttachAttribute (el, attrNew, doc);
                   1327:        }
                   1328:       else if (isImage && oldHeight == -1)
                   1329:        {
                   1330:          if (attrOld == NULL)
                   1331:            oldHeight = TtaGetAttributeValue (attrNew);
                   1332:          else
                   1333:            oldHeight = TtaGetAttributeValue (attrOld);
                   1334:        }
                   1335:     }
                   1336:   else
                   1337:     {
                   1338:       /* remove IntHeightPercent */
                   1339:       attrOld = TtaGetAttribute (el, attrTypePercent);
                   1340:       /* update IntHeightPxl */
                   1341:       attrNew = TtaGetAttribute (el, attrTypePxl);
                   1342:       if (attrNew == NULL)
                   1343:        {
                   1344:          attrNew = TtaNewAttribute (attrTypePxl);
                   1345:          TtaAttachAttribute (el, attrNew, doc);
                   1346:        }
                   1347:       else if (isImage && oldHeight == -1)
                   1348:        {
                   1349:          TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
                   1350:          if (attrOld == NULL)
                   1351:            oldHeight = w * TtaGetAttributeValue (attrNew) / 100;
                   1352:          else
                   1353:            oldHeight = w * TtaGetAttributeValue (attrOld) / 100;         
                   1354:        }
                   1355:     }
                   1356: 
                   1357:   if (attrOld != NULL)
                   1358:     TtaRemoveAttribute (el, attrOld, doc);
                   1359:   if (sscanf (buffer, "%d", &val))
                   1360:     TtaSetAttributeValue (attrNew, val, el, doc);
                   1361:   else
                   1362:     /* its not a number. Delete attribute and send an error message */
                   1363:     {
                   1364:     TtaRemoveAttribute (el, attrNew, doc);
                   1365:     if (strlen (buffer) > MaxMsgLength - 30)
                   1366:         buffer[MaxMsgLength - 30] = EOS;
                   1367:     sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.117     quint    1368:     HTMLParseError (doc, msgBuffer, 0);
1.58      vatton   1369:     }
                   1370:   if (isImage)
1.79      quint    1371:     UpdateImageMap (origEl, doc, oldHeight, -1);
1.58      vatton   1372: }
                   1373: 
                   1374: /*----------------------------------------------------------------------
1.91      quint    1375:    CreateAttrIntAreaSize
                   1376:    an HTML attribute "size" has been created or modified for a input element.
                   1377:    Create or update the corresponding attribute IntAreaSize.
                   1378:   ----------------------------------------------------------------------*/
                   1379: void CreateAttrIntAreaSize (int value, Element el, Document doc)
                   1380: {
                   1381:   AttributeType   attrType;
                   1382:   Attribute       attr;
                   1383:   ElementType    elType;
                   1384: 
                   1385:   elType = TtaGetElementType (el);
                   1386:   attrType.AttrSSchema = elType.ElSSchema;
                   1387:   attrType.AttrTypeNum = HTML_ATTR_IntAreaSize;
                   1388:   attr = TtaGetAttribute (el, attrType);
                   1389:   if (!attr)
                   1390:     {
                   1391:       attr = TtaNewAttribute (attrType);
                   1392:       TtaAttachAttribute (el, attr, doc);
                   1393:     }
                   1394:   /* the presentation rule associated with attribute IntAreaSize expresses
                   1395:      the element width in "em". Convert the value into em */
                   1396:   TtaSetAttributeValue (attr, (int) (value * 0.55), el, doc);
                   1397: }
                   1398: 
                   1399: /*----------------------------------------------------------------------
1.30      cvs      1400:    CreateAttrIntSize
                   1401:    an HTML attribute "size" has been created for a Font element.
                   1402:    Create the corresponding internal attribute.
                   1403:   ----------------------------------------------------------------------*/
1.109     vatton   1404: void CreateAttrIntSize (char *buffer, Element el, Document doc)
1.30      cvs      1405: 
                   1406: {
1.109     vatton   1407:    ElementType    elType;
1.30      cvs      1408:    AttributeType  attrType;
                   1409:    int            val, ind, factor, delta;
                   1410:    Attribute      attr;
1.37      cvs      1411:    char         msgBuffer[MaxMsgLength];
1.30      cvs      1412: 
                   1413:    /* is the first character a '+' or a '-' ? */
1.109     vatton   1414:    elType = TtaGetElementType (el);
1.30      cvs      1415:    ind = 0;
                   1416:    factor = 1;
                   1417:    delta = 0;
                   1418:    if (buffer[0] == '+')
                   1419:      {
                   1420:        attrType.AttrTypeNum = HTML_ATTR_IntSizeIncr;
                   1421:        ind++;
1.90      vatton   1422:        factor = 1;
1.30      cvs      1423:      }
                   1424:    else if (buffer[0] == '-')
                   1425:      {
                   1426:        attrType.AttrTypeNum = HTML_ATTR_IntSizeDecr;
                   1427:        ind++;
1.90      vatton   1428:        factor = 1;
1.30      cvs      1429:      }
                   1430:    else
                   1431:      {
                   1432:        attrType.AttrTypeNum = HTML_ATTR_IntSizeRel;
                   1433:        delta = 1;
                   1434:      }
1.109     vatton   1435:    attrType.AttrSSchema = elType.ElSSchema;
1.30      cvs      1436:    attr = TtaGetAttribute (el, attrType);
1.43      cvs      1437:    if (sscanf (&buffer[ind], "%d", &val))
1.30      cvs      1438:      {
                   1439:        val = val * factor + delta;
                   1440:        if (attr == NULL)
                   1441:         {
                   1442:           /* this attribute doesn't exist, create it */
                   1443:           attr = TtaNewAttribute (attrType);
                   1444:           TtaAttachAttribute (el, attr, doc);
                   1445:         }
                   1446:        TtaSetAttributeValue (attr, val, el, doc);
                   1447:      }
                   1448:    else
                   1449:      /* its not a number. Delete attribute and send an error message */
                   1450:      {
                   1451:        if (attr)
                   1452:          TtaRemoveAttribute (el, attr, doc);
1.37      cvs      1453:        if (strlen (buffer) > MaxMsgLength - 30)
1.30      cvs      1454:          buffer[MaxMsgLength - 30] = EOS;
1.37      cvs      1455:        sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.117     quint    1456:        HTMLParseError (doc, msgBuffer, 0);
1.30      cvs      1457:      }
                   1458: }
                   1459: /*----------------------------------------------------------------------
                   1460:    EndOfHTMLAttributeValue
                   1461:    Filling of an HTML attribute value
                   1462:   ----------------------------------------------------------------------*/
1.109     vatton   1463: void EndOfHTMLAttributeValue (char *attrValue, AttributeMapping *lastMappedAttr,
                   1464:                              Attribute currentAttribute, Element lastAttrElement,
                   1465:                              ThotBool UnknownAttr, ParserData *context,
1.48      vatton   1466:                              ThotBool isXML)
1.30      cvs      1467: {
1.48      vatton   1468:   AttributeType   attrType, attrType1;
                   1469:   Attribute       attr;
1.79      quint    1470:   ElementType    elType;
1.48      vatton   1471:   Element         child, root;
                   1472:   Language        lang;
                   1473:   char            translation;
                   1474:   char            shape;
                   1475:   char           *buffer;
                   1476:   char           *attrName;
                   1477:   char            msgBuffer[MaxMsgLength];
                   1478:   int             val;
                   1479:   int             length;
                   1480:   int             attrKind;
                   1481:   ThotBool        done = FALSE;
1.88      vatton   1482:   ThotBool            loadcss;
1.30      cvs      1483: 
1.48      vatton   1484:   /* treatments of some particular HTML attributes */
                   1485:   if (!strcmp (lastMappedAttr->XMLattribute, "style"))
                   1486:     {
                   1487:       TtaSetAttributeText (currentAttribute, attrValue,
                   1488:                           lastAttrElement, context->doc);
1.88      vatton   1489:       /* check if we have to load CSS */
                   1490:       TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
                   1491:       if (loadcss)
                   1492:        ParseHTMLSpecificStyle (context->lastElement, attrValue,
1.115     quint    1493:                                context->doc, 200, FALSE);
1.48      vatton   1494:       done = TRUE;
                   1495:     }
                   1496:   else
                   1497:     {
                   1498:       if (!strcmp (lastMappedAttr->XMLattribute, "link"))
1.89      vatton   1499:        HTMLSetAlinkColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1500:       else if (!strcmp (lastMappedAttr->XMLattribute, "alink"))
1.89      vatton   1501:        HTMLSetAactiveColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1502:       else if (!strcmp (lastMappedAttr->XMLattribute, "vlink"))
1.89      vatton   1503:        HTMLSetAvisitedColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1504:     }
1.30      cvs      1505: 
1.48      vatton   1506:   if (!done)
                   1507:     {
1.109     vatton   1508:       elType = TtaGetElementType (lastAttrElement);
1.48      vatton   1509:       val = 0;
                   1510:       translation = lastMappedAttr->AttrOrContent;
                   1511:       switch (translation)
                   1512:        {
                   1513:        case 'C':       /* Content */
                   1514:          child = PutInContent (attrValue, context);
                   1515:          if (child != NULL)
1.100     gully    1516:            TtaAppendTextContent (child, (unsigned char *)"\" ", context->doc);
1.48      vatton   1517:          break;
                   1518:        case 'A':
                   1519:          if (currentAttribute != NULL)
                   1520:            {
                   1521:              TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
                   1522:              switch (attrKind)
                   1523:                {
                   1524:                case 0: /* enumerate */
                   1525:                  if (isXML)
1.100     gully    1526:                    MapHTMLAttributeValue (attrValue, &attrType, &val);
1.48      vatton   1527:                  else
                   1528:                    val = MapAttrValue (lastMappedAttr->ThotAttribute,
1.40      cvs      1529:                                        attrValue);
1.48      vatton   1530:                  if (val < 0)
                   1531:                    {
                   1532:                      TtaGiveAttributeType (currentAttribute,
                   1533:                                            &attrType, &attrKind);
                   1534:                      attrName = TtaGetAttributeName (attrType);
                   1535:                      sprintf (msgBuffer,
1.51      cvs      1536:                               "Invalid attribute value \"%s = %s\"",
1.48      vatton   1537:                               attrName, attrValue);
                   1538:                      if (isXML)
1.100     gully    1539:                        XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
1.48      vatton   1540:                      else
1.84      quint    1541:                        /* we are parsing an HTML file, not an XHTML file */
1.51      cvs      1542:                        {
1.84      quint    1543:                          /* generate an error message in the log */
1.117     quint    1544:                          HTMLParseError (context->doc, msgBuffer, 0);
1.84      quint    1545:                          /* special case for value POLYGON of attribute 
                   1546:                             shape (AREA element) */
                   1547:                          if (attrType.AttrTypeNum == HTML_ATTR_shape &&
                   1548:                              strcasecmp (attrValue, "POLYGON") == 0)
                   1549:                            {
                   1550:                              val = HTML_ATTR_shape_VAL_polygon;
                   1551:                              /* interpret it as if it were "poly" */
                   1552:                              TtaSetAttributeValue (currentAttribute, val,
                   1553:                                          lastAttrElement, context->doc);
                   1554:                            }
                   1555:                          else
                   1556:                            /* remove the attribute and replace it by an */
                   1557:                            /* Invalid_attribute (not for XHTML) */
                   1558:                            {
                   1559:                              TtaRemoveAttribute (lastAttrElement,
1.51      cvs      1560:                                              currentAttribute, context->doc);
1.109     vatton   1561:                              attrType.AttrSSchema = elType.ElSSchema;
1.84      quint    1562:                              attrType.AttrTypeNum =
                   1563:                                       pHTMLAttributeMapping[0].ThotAttribute;
                   1564:                              sprintf (msgBuffer, "%s=%s", attrName,attrValue);
                   1565:                              CreateHTMLAttribute (lastAttrElement, attrType,
                   1566:                                         msgBuffer, TRUE, context->doc,
                   1567:                                         &currentAttribute, &lastAttrElement);
                   1568:                            }
1.48      vatton   1569:                        }
                   1570:                    }
                   1571:                  else
                   1572:                    TtaSetAttributeValue (currentAttribute, val,
                   1573:                                          lastAttrElement, context->doc);
                   1574:                  break;
                   1575:                case 1: /* integer */
                   1576:                  if (attrType.AttrTypeNum == HTML_ATTR_Border &&
                   1577:                      !strcasecmp (attrValue, "border"))
                   1578:                    {
                   1579:                      /* border="border" for a table */
                   1580:                      val = 1;
                   1581:                      TtaSetAttributeValue (currentAttribute, val,
1.30      cvs      1582:                                            lastAttrElement, context->doc);
1.48      vatton   1583:                    }
                   1584:                  else if (sscanf (attrValue, "%d", &val))
                   1585:                    TtaSetAttributeValue (currentAttribute, val,
                   1586:                                          lastAttrElement, context->doc);
                   1587:                  else
                   1588:                    {
                   1589:                      TtaRemoveAttribute (lastAttrElement, currentAttribute,
                   1590:                                          context->doc);
                   1591:                      sprintf (msgBuffer,
                   1592:                               "Unknown attribute value \"%s\"",
                   1593:                               attrValue);
                   1594:                      if (isXML)
1.100     gully    1595:                        XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
1.48      vatton   1596:                      else
1.117     quint    1597:                        HTMLParseError (context->doc, msgBuffer, 0);
1.48      vatton   1598:                    }
                   1599:                  break;
                   1600:                case 2: /* text */
                   1601:                  if (!UnknownAttr)
                   1602:                    {
                   1603:                      TtaSetAttributeText (currentAttribute, attrValue,
                   1604:                                           lastAttrElement, context->doc);
1.55      cvs      1605:                      if (attrType.AttrTypeNum == HTML_ATTR_Language)
1.48      vatton   1606:                        {
                   1607:                          /* it's a LANG attribute value */
                   1608:                          lang = TtaGetLanguageIdFromName (attrValue);
1.70      vatton   1609:                          if (lang < 0)
1.48      vatton   1610:                            {
                   1611:                              sprintf (msgBuffer,
                   1612:                                       "warning - unsupported language: %s",
                   1613:                                       attrValue);
                   1614:                              if (isXML)
1.100     gully    1615:                                XmlParseError (warningMessage, (unsigned char *)msgBuffer, 0);
1.48      vatton   1616:                              else
1.117     quint    1617:                                HTMLParseError (context->doc, msgBuffer, 0);
1.48      vatton   1618:                            }
                   1619:                          else
                   1620:                            {
                   1621:                              /* change current language */
                   1622:                              context->language = lang;
                   1623:                              if (isXML)
                   1624:                                SetLanguagInXmlStack (lang);
                   1625:                              else
                   1626:                                SetLanguagInHTMLStack (lang);
                   1627:                            }
                   1628:                          root = TtaGetRootElement (context->doc);
                   1629:                          if (lastAttrElement == root)
                   1630:                            /* it's a LANG attribute on the root element */
                   1631:                            /* set the RealLang attribute */
                   1632:                            {
1.109     vatton   1633:                              attrType1.AttrSSchema = elType.ElSSchema;
1.48      vatton   1634:                              attrType1.AttrTypeNum = HTML_ATTR_RealLang;
                   1635:                              /* this attribute could be already present,
                   1636:                                 (lang and xml:lang attributes) */
                   1637:                              if (!TtaGetAttribute (lastAttrElement,
                   1638:                                                    attrType1))
                   1639:                                /* it's not present. Add it */
                   1640:                                {
                   1641:                                  attr = TtaNewAttribute (attrType1);
                   1642:                                  TtaAttachAttribute (lastAttrElement,
                   1643:                                                      attr, context->doc);
                   1644:                                  TtaSetAttributeValue (attr,
                   1645:                                                        HTML_ATTR_RealLang_VAL_Yes_,
                   1646:                                                        lastAttrElement,
                   1647:                                                        context->doc);
                   1648:                                }
                   1649:                            }
                   1650:                        }
1.120     vatton   1651:                      else if (attrType.AttrTypeNum == HTML_ATTR_ID ||
                   1652:                               attrType.AttrTypeNum == HTML_ATTR_NAME)
                   1653:                        CheckUniqueName (lastAttrElement, context->doc,
                   1654:                                         currentAttribute, attrType);
1.48      vatton   1655:                      else if (attrType.AttrTypeNum == HTML_ATTR_accesskey)
                   1656:                        TtaAddAccessKey (context->doc, (unsigned int)attrValue[0],
                   1657:                                         lastAttrElement);
                   1658:                    }
                   1659:                  else
                   1660:                    {
1.51      cvs      1661:                      /* this is the content of an invalid attribute */
                   1662:                      /* append it to the current Invalid_attribute */
                   1663:                      if (!isXML)
                   1664:                        {
                   1665:                          length = strlen (attrValue) + 2;
                   1666:                          length += TtaGetTextAttributeLength (currentAttribute);
1.100     gully    1667:                          buffer = (char *)TtaGetMemory (length + 1);
1.51      cvs      1668:                          TtaGiveTextAttributeValue (currentAttribute,
                   1669:                                                     buffer, &length);
                   1670:                          strcat (buffer, "=");
                   1671:                          strcat (buffer, attrValue);
                   1672:                          TtaSetAttributeText (currentAttribute, buffer,
                   1673:                                               lastAttrElement, context->doc);
                   1674:                          TtaFreeMemory (buffer);
                   1675:                        }
1.48      vatton   1676:                    }
                   1677:                  break;
                   1678:                case 3: /* reference */
                   1679:                  break;
                   1680:                }
                   1681:            }
                   1682:          break;
                   1683:        case SPACE:
                   1684:          if (isXML)
                   1685:            XhtmlTypeAttrValue (attrValue, currentAttribute,
1.30      cvs      1686:                                lastAttrElement, context);
1.48      vatton   1687:          else
                   1688:            HTMLTypeAttrValue (attrValue, currentAttribute,
                   1689:                               lastAttrElement, context);
1.109     vatton   1690:          break;  
1.30      cvs      1691:         default:
                   1692:           break;
1.48      vatton   1693:        }
1.30      cvs      1694: 
                   1695:       if (lastMappedAttr->ThotAttribute == HTML_ATTR_Width__)
1.79      quint    1696:        /* HTML attribute "width" */
                   1697:        {
                   1698:          /* if it's an Object element, wait until all attributes are handled,
                   1699:             especially the data attribute that may generate the image to
                   1700:             which the width has to be applied */
                   1701:          if (elType.ElTypeNum != HTML_EL_Object)
                   1702:            /* create the corresponding attribute IntWidthPercent or */
                   1703:            /* IntWidthPxl */
                   1704:            CreateAttrWidthPercentPxl (attrValue, lastAttrElement,
                   1705:                                       context->doc, -1);
                   1706:        }
1.58      vatton   1707:       else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Height_)
1.79      quint    1708:        /* HTML attribute "height" */
                   1709:        {
                   1710:          /* if it's an Object element, wait until all attributes are handled,
                   1711:             especially the data attribute that may generate the image to
                   1712:             which the height has to be applied */
                   1713:          if (elType.ElTypeNum != HTML_EL_Object)
                   1714:            /* create the corresponding attribute IntHeightPercent or */
                   1715:            /* IntHeightPxl */
                   1716:            CreateAttrHeightPercentPxl (attrValue, lastAttrElement,
                   1717:                                        context->doc, -1);
                   1718:        }
1.91      quint    1719:       else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Area_Size)
                   1720:        /* HTML attribute "size" for an element "input" */
                   1721:        CreateAttrIntAreaSize (val, lastAttrElement, context->doc);
1.48      vatton   1722:       else if (!strcmp (lastMappedAttr->XMLattribute, "size"))
                   1723:        {
                   1724:          TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
                   1725:          if (attrType.AttrTypeNum == HTML_ATTR_Font_size)
                   1726:            CreateAttrIntSize (attrValue, lastAttrElement, context->doc);
                   1727:        }
                   1728:       else if (!strcmp (lastMappedAttr->XMLattribute, "shape"))
                   1729:        {
                   1730:          child = TtaGetFirstChild (lastAttrElement);
                   1731:          if (child != NULL)
                   1732:            {
                   1733:              switch (val)
                   1734:                {
                   1735:                case HTML_ATTR_shape_VAL_rectangle:
                   1736:                  shape = 'R';
                   1737:                  break;
                   1738:                case HTML_ATTR_shape_VAL_circle:
                   1739:                  shape = 'a';
                   1740:                  break;
                   1741:                case HTML_ATTR_shape_VAL_polygon:
                   1742:                  shape = 'p';
                   1743:                  break;
                   1744:                default:
                   1745:                  shape = SPACE;
                   1746:                  break;
                   1747:                }
                   1748:              TtaSetGraphicsShape (child, shape, context->doc);
                   1749:            }
                   1750:        }
                   1751:       else if (!strcmp (lastMappedAttr->XMLattribute, "value"))
                   1752:        {
                   1753:          if (elType.ElTypeNum == HTML_EL_Text_Input ||
                   1754:              elType.ElTypeNum == HTML_EL_Password_Input ||
                   1755:              elType.ElTypeNum == HTML_EL_File_Input ||
                   1756:              elType.ElTypeNum == HTML_EL_Input)
                   1757:            /* create a Default_Value attribute with the same content */
                   1758:            {
                   1759:              attrType1.AttrSSchema = attrType.AttrSSchema;
                   1760:              attrType1.AttrTypeNum = HTML_ATTR_Default_Value;
                   1761:              attr = TtaNewAttribute (attrType1);
                   1762:              TtaAttachAttribute (lastAttrElement, attr, context->doc);
                   1763:              TtaSetAttributeText (attr, attrValue,
                   1764:                                   lastAttrElement, context->doc);
                   1765:            }
                   1766:        }
1.30      cvs      1767:       else
1.48      vatton   1768:        {
                   1769:          /* Some HTML attributes are equivalent to a CSS property:      */
                   1770:          /*      background     ->                   background         */
                   1771:          /*      bgcolor        ->                   background         */
                   1772:          /*      text           ->                   color              */
                   1773:          /*      color          ->                   color              */
                   1774:          if (!strcmp (lastMappedAttr->XMLattribute, "background"))
                   1775:            {
                   1776:              if (strlen (attrValue) > MaxMsgLength - 30)
                   1777:                attrValue[MaxMsgLength - 30] = EOS;
1.76      vatton   1778:              HTMLSetBackgroundImage (context->doc, context->lastElement,
1.108     vatton   1779:                                      REPEAT, 0, attrValue, FALSE);
1.48      vatton   1780:            }
                   1781:          else if (!strcmp (lastMappedAttr->XMLattribute, "bgcolor"))
1.76      vatton   1782:            HTMLSetBackgroundColor (context->doc, context->lastElement,
1.108     vatton   1783:                                    0, attrValue);
1.48      vatton   1784:          else if (!strcmp (lastMappedAttr->XMLattribute, "text") ||
                   1785:                   !strcmp (lastMappedAttr->XMLattribute, "color"))
1.108     vatton   1786:            HTMLSetForegroundColor (context->doc, context->lastElement,
                   1787:                                    0, attrValue);
1.48      vatton   1788:        }
                   1789:     }
1.30      cvs      1790: }
                   1791: 
                   1792: /*----------------------------------------------------------------------
1.16      cvs      1793:    MapHTMLAttributeValue
1.2       cvs      1794:    Search in the Attribute Value Mapping Table the entry for the attribute
1.66      vatton   1795:    ThotAtt and its value attVal. Returns the corresponding Thot value.
1.1       cvs      1796:   ----------------------------------------------------------------------*/
1.118     vatton   1797: void MapHTMLAttributeValue (char *attVal, const AttributeType *attrType,
                   1798:                            int *value)
1.1       cvs      1799: {
1.66      vatton   1800:   MapXMLAttributeValue (XHTML_TYPE, attVal, attrType, value);
1.1       cvs      1801: }

Webmaster