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

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

Webmaster