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

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

Webmaster