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

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 */
                    749:       /* if the last line of the Preformatted is empty, remove it */
                    750:       leaf = XmlLastLeafInElement (el);
                    751:       if (leaf != NULL)
                    752:         {
                    753:           elType = TtaGetElementType (leaf);
                    754:           if (elType.ElTypeNum == HTML_EL_TEXT_UNIT)
                    755:             /* the last leaf is a TEXT element */
                    756:             {
                    757:               length = TtaGetTextLength (leaf);
                    758:               if (length > 0)
                    759:                 {
                    760:                   TtaGiveSubString (leaf, (unsigned char *)lastChar, length, 1);
                    761:                   if (lastChar[0] == EOL)
                    762:                     /* last character is new line, delete it */
                    763:                     {
                    764:                       if (length == 1)
                    765:                         /* empty TEXT element */
                    766:                         TtaDeleteTree (leaf, doc);
                    767:                       else
                    768:                         /* remove the last character */
                    769:                         TtaDeleteTextContent (leaf, length, 1, doc);
                    770:                     }
                    771:                 }
                    772:             }
                    773:         }
                    774: 
                    775:       if (elType.ElTypeNum == HTML_EL_STYLE_)
                    776:         /* Check the mandatory TYPE attribute */
                    777:         CheckMandatoryAttribute (el, doc, HTML_ATTR_Notation);
                    778:       else if (elType.ElTypeNum == HTML_EL_SCRIPT_)
                    779:         /* Check the mandatory TYPE attribute */
                    780:         CheckMandatoryAttribute (el, doc, HTML_ATTR_content_type);
                    781: 
                    782:       if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
                    783:         {
                    784:           if (IsXmlParsingCSS ())
                    785:             {
                    786:               text = GetStyleContents (el);
                    787:               if (text)
                    788:                 {
                    789:                   ReadCSSRules (doc, NULL, text, NULL,
                    790:                                 TtaGetElementLineNumber (el), FALSE, el);
                    791:                   TtaFreeMemory (text);
                    792:                 }
                    793:               SetXmlParsingCSS (FALSE);
                    794:             }
                    795:         }
                    796:       else
                    797:         {
                    798:           if (IsHtmlParsingCSS ())
                    799:             {
                    800:               text = GetStyleContents (el);
                    801:               if (text)
                    802:                 {
                    803:                   ReadCSSRules (doc, NULL, text, NULL,
                    804:                                 TtaGetElementLineNumber (el), FALSE, el);
                    805:                   TtaFreeMemory (text);
                    806:                 }
                    807:               SetHtmlParsingCSS (FALSE);
                    808:             }
                    809:         }
                    810:       /* and continue as if it were a Preformatted or a Script */
                    811:       break;
1.6       cvs       812:        
1.129     vatton    813:     case HTML_EL_Text_Area:    /* it's a Text_Area */
                    814:       if (DocumentMeta[doc]->xmlformat)
                    815:         SetParsingTextArea (FALSE);
                    816:       else
                    817:         SetHtmlParsingTextArea (FALSE);
                    818:       child = TtaGetFirstChild (el);
                    819:       if (child == NULL)
                    820:         /* it's an empty Text_Area */
                    821:         /* insert a Inserted_Text element and a child Basic_Elem in the
                    822:            Text_Area element */
                    823:         {
                    824:           newElType.ElTypeNum = HTML_EL_Inserted_Text;
                    825:           child = TtaNewTree (doc, newElType, "");
                    826:           TtaInsertFirstChild (&child, el, doc);
                    827:         }
                    828:       else
                    829:         {
                    830:           /* save the text into Default_Value attribute */
                    831:           attrType.AttrSSchema = htmlSchema;
                    832:           attrType.AttrTypeNum = HTML_ATTR_Default_Value;
                    833:           if (TtaGetAttribute (el, attrType) == NULL)
                    834:             /* attribute Default_Value is missing */
                    835:             {
                    836:               desc = TtaGetFirstChild (child);
                    837:               if (desc)
                    838:                 {
                    839:                   length = TtaGetTextLength (desc);
                    840:                   if (length > 0)
                    841:                     {
                    842:                       length++;
                    843:                       attr = TtaNewAttribute (attrType);
                    844:                       TtaAttachAttribute (el, attr, doc);
                    845:                       text = (char *)TtaGetMemory (length);
                    846:                       TtaGiveTextContent (desc, (unsigned char *)text, &length, &lang);
                    847:                       TtaSetAttributeText (attr, text, el, doc);
                    848:                       TtaFreeMemory (text);
                    849:                     }
                    850:                 }
                    851:             }
                    852:         }
                    853:       /* Check the mandatory rows attribute */
                    854:       CheckMandatoryAttribute (el, doc, HTML_ATTR_Rows);
                    855:       /* Check the mandatory columns attribute */
                    856:       CheckMandatoryAttribute (el, doc, HTML_ATTR_Columns);
                    857:       /* Add default rows and columns attributes */
                    858:       AddRowsColumns (el, doc);
                    859:       break;
                    860: 
                    861:     case HTML_EL_Radio_Input:
                    862:     case HTML_EL_Checkbox_Input:
                    863:       /* put an attribute Checked if it is missing */
                    864:       attrType.AttrSSchema = htmlSchema;
                    865:       attrType.AttrTypeNum = HTML_ATTR_Checked;
                    866:       if (TtaGetAttribute (el, attrType) == NULL)
                    867:         /* attribute Checked is missing */
                    868:         {
                    869:           attr = TtaNewAttribute (attrType);
                    870:           TtaAttachAttribute (el, attr, doc);
                    871:           TtaSetAttributeValue (attr, HTML_ATTR_Checked_VAL_No_, el, doc);
                    872:         }
                    873:       break;
1.6       cvs       874:        
1.129     vatton    875:     case HTML_EL_Option_Menu:
                    876:       /* Check that at least one option has a SELECTED attribute */
                    877:       OnlyOneOptionSelected (el, doc, TRUE);
                    878:       break;
                    879: 
                    880:     case HTML_EL_OptGroup:
                    881:       /* Check the mandatory label attribute */
                    882:       CheckMandatoryAttribute (el, doc, HTML_ATTR_label);
                    883:       break;
                    884: 
                    885:     case HTML_EL_MAP:
                    886:     case HTML_EL_map:
                    887:       /* Check the mandatory attributes */
                    888:       if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
                    889:         /* it's XHTML. Check attribute id */
                    890:         CheckMandatoryAttribute (el, doc, HTML_ATTR_ID);
                    891:       else
                    892:         /* it's a HTML document. Check attribute name */
                    893:         CheckMandatoryAttribute (el, doc, HTML_ATTR_NAME);
                    894:       break;
                    895: 
                    896:     case HTML_EL_AREA:
                    897:       /* Check the mandatory alt attribute */
                    898:       CheckMandatoryAttribute (el, doc, HTML_ATTR_ALT);
                    899:       break;
                    900: 
                    901:     case HTML_EL_PICTURE_UNIT:
                    902:       /* Check the mandatory ALT attribute */
                    903:       attrType.AttrSSchema = htmlSchema;
                    904:       attrType.AttrTypeNum = HTML_ATTR_IsInput;
                    905:       if (TtaGetAttribute (el, attrType) == NULL)
                    906:         CheckMandatoryAttribute (el, doc, HTML_ATTR_ALT);
                    907:       /* Check the mandatory SRC attribute */
                    908:       CheckMandatoryAttribute (el, doc, HTML_ATTR_SRC);
                    909:       break;
1.6       cvs       910:        
1.129     vatton    911:     case HTML_EL_LINK:
                    912:       CheckCSSLink (el, doc, htmlSchema);
                    913:       break;
1.6       cvs       914:        
1.129     vatton    915:     case HTML_EL_Data_cell:
                    916:     case HTML_EL_Heading_cell:
                    917:     case HTML_EL_List_Item:
                    918:     case HTML_EL_Definition:
                    919:       /* insert a pseudo paragraph into empty cells or list items */
                    920:       child = TtaGetFirstChild (el);
                    921:       if (child == NULL)
                    922:         {
                    923:           elType.ElTypeNum = HTML_EL_Pseudo_paragraph;
                    924:           child = TtaNewTree (doc, elType, "");
                    925:           if (child != NULL)
                    926:             TtaInsertFirstChild (&child, el, doc);
                    927:         }
                    928:       if (elType.ElTypeNum == HTML_EL_Data_cell ||
                    929:           elType.ElTypeNum == HTML_EL_Heading_cell)
                    930:         /* detect whether we are parsing a whole table or just a cell */
                    931:         {
                    932:           if (DocumentMeta[doc]->xmlformat)
                    933:             {
                    934:               if (IsWithinXmlTable ())
                    935:                 NewCell (el, doc, FALSE, FALSE, FALSE);
                    936:             }
                    937:           else
                    938:             {
                    939:               if (IsWithinHtmlTable ())
                    940:                 NewCell (el, doc, FALSE, FALSE, FALSE);
                    941:             }
                    942:         }
                    943:       break;
1.6       cvs       944:        
1.129     vatton    945:     case HTML_EL_Table_:
                    946:       CheckTable (el, doc);
                    947:       SubWithinTable ();
                    948:       break;
1.6       cvs       949:        
1.129     vatton    950:     case HTML_EL_TITLE:
                    951:       /* show the TITLE in the main window */
                    952:       UpdateTitle (el, doc);
                    953:       break;
                    954: 
                    955:     case HTML_EL_rbc:
                    956:       /* an rbc element has been read. Its parent should be a complex_ruby.
                    957:          Change the type of the parent, as simple_ruby are created by
                    958:          default */
                    959:       parent = TtaGetParent (el);
                    960:       if (parent)
                    961:         {
                    962:           newElType = TtaGetElementType (parent);
                    963:           if (newElType.ElSSchema == elType.ElSSchema &&
                    964:               newElType.ElTypeNum == HTML_EL_simple_ruby)
                    965:             TtaChangeElementType (parent, HTML_EL_complex_ruby);
                    966:         }
                    967:       break;
1.41      cvs       968: 
1.129     vatton    969:     case HTML_EL_rtc1:
                    970:       /* an rtc element has been parsed. If it has already a rtc1 sibling,
                    971:          change its type to rtc2 */
                    972:       prev = el;
                    973:       do
                    974:         {
                    975:           TtaPreviousSibling(&prev);
                    976:           if (prev)
                    977:             {
                    978:               newElType = TtaGetElementType (prev);
                    979:               if (newElType.ElSSchema == elType.ElSSchema &&
                    980:                   newElType.ElTypeNum == HTML_EL_rtc1)
                    981:                 {
                    982:                   TtaChangeElementType (el, HTML_EL_rtc2);
                    983:                   prev = NULL;
                    984:                 }
                    985:             }
                    986:         }
                    987:       while (prev);
                    988:       break;
                    989: 
                    990:     case HTML_EL_FIELDSET:
1.124     cvs       991:        
1.129     vatton    992:       childType.ElTypeNum = 0;
                    993:       child = TtaGetFirstChild (el);
                    994:       if (child != NULL)
                    995:         childType = TtaGetElementType (child);
                    996:       if (childType.ElTypeNum != HTML_EL_LEGEND)
                    997:         {
                    998:           sprintf (msgBuffer, "The <fieldset> element requires <legend> as first child element");
                    999:           lineNum = TtaGetElementLineNumber(el);
                   1000:           if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
                   1001:             XmlParseError (errorParsing, (unsigned char *)msgBuffer, lineNum);
                   1002:           else
                   1003:             HTMLParseError (doc, msgBuffer, lineNum);
                   1004: 
                   1005:         }
                   1006:       break;
                   1007: 
                   1008:     default:
                   1009:       break;
                   1010:     }
1.6       cvs      1011: }
1.1       cvs      1012: 
                   1013: /*----------------------------------------------------------------------
1.129     vatton   1014:   PutInContent    
                   1015:   Put the string ChrString in the leaf of current element.
1.30      cvs      1016:   ----------------------------------------------------------------------*/
1.39      cvs      1017: Element         PutInContent (char *ChrString, ParserData *context)
1.30      cvs      1018: 
                   1019: {
1.129     vatton   1020:   Element      el, child;
                   1021:   ElementType  elType;
                   1022:   int          length;
                   1023: 
                   1024:   el = NULL;
                   1025:   if (context->lastElement != NULL)
                   1026:     {
                   1027:       /* search first leaf of current element */
                   1028:       el = context->lastElement;
                   1029:       do
                   1030:         {
                   1031:           child = TtaGetFirstChild (el);
                   1032:           if (child != NULL)
                   1033:             el = child;
                   1034:         }
                   1035:       while (child != NULL);
                   1036:       elType = TtaGetElementType (el);
                   1037:       length = 0;
                   1038:       if (elType.ElTypeNum == 1)
                   1039:         length = TtaGetTextLength (el);
                   1040:       if (length == 0)
                   1041:         TtaSetTextContent (el, (unsigned char *)ChrString,
                   1042:                            context->language, context->doc);
                   1043:       else
                   1044:         TtaAppendTextContent (el, (unsigned char *)ChrString, context->doc);
                   1045:     }
                   1046:   return el;
1.30      cvs      1047: }
                   1048: 
                   1049: /*----------------------------------------------------------------------
1.93      vatton   1050:   UnknownXhtmlNameSpace
                   1051:   The element doesn't belong to a supported namespace
1.51      cvs      1052:   ----------------------------------------------------------------------*/
1.93      vatton   1053: void UnknownXhtmlNameSpace (ParserData *context, Element *unknownEl,
1.129     vatton   1054:                             char* content)
1.51      cvs      1055: {
1.129     vatton   1056:   ElementType     elType;
                   1057:   Element         elText;
1.51      cvs      1058: 
1.129     vatton   1059:   /* Create a new Invalid_element */
                   1060:   elType.ElSSchema = GetXMLSSchema (XHTML_TYPE, context->doc);
                   1061:   elType.ElTypeNum = HTML_EL_XHTML_Unknown_namespace;
                   1062:   *unknownEl = TtaNewElement (context->doc, elType);
                   1063:   if (*unknownEl != NULL)
                   1064:     {
                   1065:       XmlSetElemLineNumber (*unknownEl);
                   1066:       InsertXmlElement (unknownEl);
                   1067:       context->lastElementClosed = TRUE;
                   1068:       elType.ElTypeNum = HTML_EL_TEXT_UNIT;
                   1069:       elText = TtaNewElement (context->doc, elType);
                   1070:       XmlSetElemLineNumber (elText);
                   1071:       TtaInsertFirstChild (&elText, *unknownEl, context->doc);
                   1072:       TtaSetTextContent (elText, (unsigned char *)content, context->language, context->doc);
                   1073:       TtaSetAccessRight (elText, ReadOnly, context->doc);
                   1074:     }
1.51      cvs      1075: }
                   1076: 
                   1077: /*----------------------------------------------------------------------
1.129     vatton   1078:   CreateHTMLAttribute
                   1079:   create an attribute of type attrType for the element el.
1.30      cvs      1080:   ----------------------------------------------------------------------*/
1.93      vatton   1081: void CreateHTMLAttribute (Element       el,
1.129     vatton   1082:                           AttributeType attrType,
                   1083:                           char*         text,
                   1084:                           ThotBool      isInvalid,
                   1085:                           Document      doc,
                   1086:                           Attribute    *lastAttribute,
                   1087:                           Element      *lastAttrElement)
1.30      cvs      1088: {
1.129     vatton   1089:   int         attrKind;
                   1090:   int         length;
                   1091:   char       *buffer;
                   1092:   Attribute   attr, oldAttr;
                   1093: 
                   1094:   if (attrType.AttrTypeNum != 0)
                   1095:     {
                   1096:       oldAttr = TtaGetAttribute (el, attrType);
                   1097:       if (oldAttr != NULL)
                   1098:         /* this attribute already exists */
                   1099:         attr = oldAttr;
                   1100:       else
                   1101:         /* create a new attribute and attach it to the element */
                   1102:         {
                   1103:           attr = TtaNewAttribute (attrType);
                   1104:           TtaAttachAttribute (el, attr, doc);
                   1105:         }
                   1106:       *lastAttribute = attr;
                   1107:       *lastAttrElement = el;
                   1108: 
                   1109:       TtaGiveAttributeType (attr, &attrType, &attrKind);
                   1110:       if (attrKind == 0)       /* enumerate */
                   1111:         TtaSetAttributeValue (attr, 1, el, doc);
                   1112: 
                   1113:       /* attribute BORDER without any value (ThotBool attribute) is */
                   1114:       /* considered as BORDER=1 */
                   1115:       if (attrType.AttrTypeNum == HTML_ATTR_Border)
                   1116:         TtaSetAttributeValue (attr, 1, el, doc);
                   1117: 
                   1118:       if (isInvalid)
                   1119:         /* Copy the name of the invalid attribute as the content */
                   1120:         /* of the Invalid_attribute attribute. */
                   1121:         {
                   1122:           length = strlen (text) + 2;
                   1123:           length += TtaGetTextAttributeLength (attr);
                   1124:           buffer = (char *)TtaGetMemory (length + 1);
                   1125:           TtaGiveTextAttributeValue (attr, buffer, &length);
                   1126:           strcat (buffer, " ");
                   1127:           strcat (buffer, text);
                   1128:           TtaSetAttributeText (attr, buffer, el, doc);
                   1129:           TtaFreeMemory (buffer);
                   1130:         }
                   1131:     }
1.30      cvs      1132: }
                   1133: 
                   1134: /*----------------------------------------------------------------------
1.129     vatton   1135:   HTMLTypeAttrValue
                   1136:   Value val has been read for the HTML attribute TYPE.
                   1137:   Create a child for the current Thot element INPUT accordingly.
1.30      cvs      1138:   ----------------------------------------------------------------------*/
1.109     vatton   1139: void HTMLTypeAttrValue (char *val, Attribute lastAttribute,
1.129     vatton   1140:                         Element lastAttrElement, ParserData *context)
1.30      cvs      1141: {
                   1142:   ElementType      elType;
                   1143:   Element          newChild;
                   1144:   AttributeType    attrType;
                   1145:   Attribute        attr;
1.39      cvs      1146:   char             msgBuffer[MaxMsgLength];
1.30      cvs      1147:   int              value;
                   1148:   int              numberOfLinesRead;
                   1149: 
                   1150:   value = MapAttrValue (DummyAttribute, val);
1.109     vatton   1151:   elType = TtaGetElementType (context->lastElement);
1.91      quint    1152:   if (value <= 0)
1.30      cvs      1153:     {
1.37      cvs      1154:       if (strlen (val) > MaxMsgLength - 40)
1.129     vatton   1155:         val[MaxMsgLength - 40] = EOS;
1.37      cvs      1156:       sprintf (msgBuffer, "Unknown attribute value \"type = %s\"", val);
1.117     quint    1157:       HTMLParseError (context->doc, msgBuffer, 0);
1.109     vatton   1158:       attrType.AttrSSchema = elType.ElSSchema;
1.30      cvs      1159:       attrType.AttrTypeNum = pHTMLAttributeMapping[0].ThotAttribute;
1.37      cvs      1160:       sprintf (msgBuffer, "type=%s", val);
1.30      cvs      1161:       CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
1.129     vatton   1162:                            context->doc, &lastAttribute, &lastAttrElement);
1.30      cvs      1163:     }
                   1164:   else
                   1165:     {
                   1166:       if (elType.ElTypeNum != HTML_EL_Input)
1.129     vatton   1167:         {
                   1168:           if (strlen (val) > MaxMsgLength - 40)
                   1169:             val[MaxMsgLength - 40] = EOS;
                   1170:           sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
                   1171:         }
1.30      cvs      1172:       else
1.129     vatton   1173:         {
                   1174:           elType.ElTypeNum = value;
                   1175:           newChild = TtaNewTree (context->doc, elType, "");
                   1176:           numberOfLinesRead = 0;
                   1177:           TtaSetElementLineNumber (newChild, numberOfLinesRead);
                   1178:           TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
                   1179:           if (value == HTML_EL_PICTURE_UNIT)
                   1180:             {
                   1181:               /* add the attribute IsInput to input pictures */
                   1182:               attrType.AttrSSchema = elType.ElSSchema;
                   1183:               attrType.AttrTypeNum = HTML_ATTR_IsInput;
                   1184:               attr = TtaNewAttribute (attrType);
                   1185:               TtaAttachAttribute (newChild, attr, context->doc);
                   1186:             }
                   1187:         }
1.30      cvs      1188:     }
                   1189: }
                   1190: 
                   1191: /*----------------------------------------------------------------------
1.129     vatton   1192:   XhtmlTypeAttrValue 
                   1193:   Value val has been read for the HTML attribute TYPE.
                   1194:   Create a child for the current Thot element INPUT accordingly.
1.30      cvs      1195:   ----------------------------------------------------------------------*/
1.111     vatton   1196: void XhtmlTypeAttrValue (char       *val,
1.129     vatton   1197:                          Attribute   currentAttribute,
                   1198:                          Element     lastAttrElement,
                   1199:                          ParserData *context)
1.30      cvs      1200: {
                   1201:   ElementType     elType;
                   1202:   Element         newChild;
                   1203:   AttributeType   attrType;
                   1204:   Attribute       attr;
1.39      cvs      1205:   char            msgBuffer[MaxMsgLength];
1.30      cvs      1206:   int             value;
                   1207:   ThotBool        level;
                   1208: 
1.91      quint    1209:   /* Look in the dummy section of the attribute value table */
1.30      cvs      1210:   attrType.AttrTypeNum = DummyAttribute;
1.100     gully    1211:   MapHTMLAttributeValue (val, &attrType, &value);
1.91      quint    1212:   if (value <= 0)
                   1213:     /* invalid value for the type attribute of an input element */
1.30      cvs      1214:     {
1.37      cvs      1215:       sprintf (msgBuffer, "Unknown attribute value \"type=%s\"", val);
1.100     gully    1216:       XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
1.36      cvs      1217:       MapHTMLAttribute ("unknown_attr", &attrType, NULL,
1.129     vatton   1218:                         &level, context->doc);
1.37      cvs      1219:       sprintf (msgBuffer, "type=%s", val);
1.30      cvs      1220:       CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
1.129     vatton   1221:                            context->doc, &currentAttribute, &lastAttrElement);
1.30      cvs      1222:     }
                   1223:   else
1.91      quint    1224:     /* value is the Thot type of the element to be created for this value of
                   1225:        the TYPE attribute */
1.30      cvs      1226:     {
                   1227:       elType = TtaGetElementType (context->lastElement);
                   1228:       if (elType.ElTypeNum != HTML_EL_Input)
1.129     vatton   1229:         {
                   1230:           sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
                   1231:           XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
                   1232:         }
1.30      cvs      1233:       else
1.129     vatton   1234:         {
                   1235:           elType.ElTypeNum = value;
                   1236:           newChild = TtaNewTree (context->doc, elType, "");
                   1237:           XmlSetElemLineNumber (newChild);
                   1238:           TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
                   1239:           if (value == HTML_EL_PICTURE_UNIT)
                   1240:             {
                   1241:               /* add the attribute IsInput to input pictures */
                   1242:               attrType.AttrSSchema = elType.ElSSchema;
                   1243:               attrType.AttrTypeNum = HTML_ATTR_IsInput;
                   1244:               attr = TtaNewAttribute (attrType);
                   1245:               TtaAttachAttribute (newChild, attr, context->doc);
                   1246:             }
                   1247:         }
1.30      cvs      1248:     }
                   1249: }
                   1250: 
                   1251: /*----------------------------------------------------------------------
1.129     vatton   1252:   CreateAttrWidthPercentPxl
                   1253:   an HTML attribute "width" has been created for a Table, an image,
                   1254:   an Object of a HR.
                   1255:   Create the corresponding attribute IntWidthPercent or IntWidthPxl.
                   1256:   oldWidth is -1 or the old image width.
1.30      cvs      1257:   ----------------------------------------------------------------------*/
1.58      vatton   1258: void CreateAttrWidthPercentPxl (char *buffer, Element el,
1.129     vatton   1259:                                 Document doc, int oldWidth)
1.30      cvs      1260: {
                   1261:   AttributeType   attrTypePxl, attrTypePercent;
                   1262:   Attribute       attrOld, attrNew;
                   1263:   int             length, val;
1.39      cvs      1264:   char            msgBuffer[MaxMsgLength];
1.79      quint    1265:   ElementType    elType, childType;
                   1266:   Element         origEl, child;
1.30      cvs      1267:   int             w, h;
                   1268:   ThotBool        isImage;
                   1269: 
1.79      quint    1270:   origEl = el;
1.30      cvs      1271:   elType = TtaGetElementType (el);
                   1272:   isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
1.129     vatton   1273:              elType.ElTypeNum == HTML_EL_Data_cell ||
                   1274:              elType.ElTypeNum == HTML_EL_Heading_cell ||
                   1275:              elType.ElTypeNum == HTML_EL_Object);
1.79      quint    1276:   if (elType.ElTypeNum == HTML_EL_Object)
                   1277:     /* the width attribute is attached to an Object element */
                   1278:     {
                   1279:       child = TtaGetFirstChild (el);
                   1280:       if (child)
1.129     vatton   1281:         {
                   1282:           childType = TtaGetElementType (child);
                   1283:           if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
                   1284:             /* the Object element is of type image. apply the width
                   1285:                attribute to the actual image element */
                   1286:             el = child;
                   1287:         }
1.79      quint    1288:     }
1.30      cvs      1289:   /* remove trailing spaces */
1.37      cvs      1290:   length = strlen (buffer) - 1;
1.30      cvs      1291:   while (length > 0 && buffer[length] <= SPACE)
                   1292:     length--;
1.109     vatton   1293:   attrTypePxl.AttrSSchema = elType.ElSSchema;
                   1294:   attrTypePercent.AttrSSchema = elType.ElSSchema;
1.30      cvs      1295:   attrTypePxl.AttrTypeNum = HTML_ATTR_IntWidthPxl;
                   1296:   attrTypePercent.AttrTypeNum = HTML_ATTR_IntWidthPercent;
                   1297:   /* is the last character a '%' ? */
                   1298:   if (buffer[length] == '%')
                   1299:     {
                   1300:       /* remove IntWidthPxl */
                   1301:       attrOld = TtaGetAttribute (el, attrTypePxl);
                   1302:       /* update IntWidthPercent */
                   1303:       attrNew = TtaGetAttribute (el, attrTypePercent);
                   1304:       if (attrNew == NULL)
1.129     vatton   1305:         {
                   1306:           attrNew = TtaNewAttribute (attrTypePercent);
                   1307:           TtaAttachAttribute (el, attrNew, doc);
                   1308:         }
1.30      cvs      1309:       else if (isImage && oldWidth == -1)
1.129     vatton   1310:         {
                   1311:           if (attrOld == NULL)
                   1312:             oldWidth = TtaGetAttributeValue (attrNew);
                   1313:           else
                   1314:             oldWidth = TtaGetAttributeValue (attrOld);
                   1315:         }
1.30      cvs      1316:     }
                   1317:   else
                   1318:     {
                   1319:       /* remove IntWidthPercent */
                   1320:       attrOld = TtaGetAttribute (el, attrTypePercent);
                   1321:       /* update IntWidthPxl */
                   1322:       attrNew = TtaGetAttribute (el, attrTypePxl);
                   1323:       if (attrNew == NULL)
1.129     vatton   1324:         {
                   1325:           attrNew = TtaNewAttribute (attrTypePxl);
                   1326:           TtaAttachAttribute (el, attrNew, doc);
                   1327:         }
1.30      cvs      1328:       else if (isImage && oldWidth == -1)
1.129     vatton   1329:         {
                   1330:           TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
                   1331:           if (attrOld == NULL)
                   1332:             oldWidth = w * TtaGetAttributeValue (attrNew) / 100;
                   1333:           else
                   1334:             oldWidth = w * TtaGetAttributeValue (attrOld) / 100;         
                   1335:         }
1.30      cvs      1336:     }
                   1337: 
                   1338:   if (attrOld != NULL)
                   1339:     TtaRemoveAttribute (el, attrOld, doc);
1.43      cvs      1340:   if (sscanf (buffer, "%d", &val))
1.30      cvs      1341:     TtaSetAttributeValue (attrNew, val, el, doc);
                   1342:   else
                   1343:     /* its not a number. Delete attribute and send an error message */
                   1344:     {
1.129     vatton   1345:       TtaRemoveAttribute (el, attrNew, doc);
                   1346:       if (strlen (buffer) > MaxMsgLength - 30)
1.30      cvs      1347:         buffer[MaxMsgLength - 30] = EOS;
1.129     vatton   1348:       sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
                   1349:       HTMLParseError (doc, msgBuffer, 0);
1.30      cvs      1350:     }
                   1351:   if (isImage)
1.79      quint    1352:     UpdateImageMap (origEl, doc, oldWidth, -1);
1.30      cvs      1353: }
                   1354: 
                   1355: /*----------------------------------------------------------------------
1.129     vatton   1356:   CreateAttrHeightPercentPxl
                   1357:   an HTML attribute "width" has been created for a Table, an image,
                   1358:   an Object or a HR.
                   1359:   Create the corresponding attribute IntHeightPercent or IntHeightPxl.
                   1360:   oldHeight is -1 or the old image width.
1.58      vatton   1361:   ----------------------------------------------------------------------*/
                   1362: void CreateAttrHeightPercentPxl (char *buffer, Element el,
1.129     vatton   1363:                                  Document doc, int oldHeight)
1.58      vatton   1364: {
                   1365:   AttributeType   attrTypePxl, attrTypePercent;
                   1366:   Attribute       attrOld, attrNew;
                   1367:   int             length, val;
                   1368:   char            msgBuffer[MaxMsgLength];
1.79      quint    1369:   ElementType    elType, childType;
                   1370:   Element         origEl, child;
1.58      vatton   1371:   int             w, h;
                   1372:   ThotBool        isImage;
                   1373: 
1.79      quint    1374:   origEl = el;
1.58      vatton   1375:   elType = TtaGetElementType (el);
                   1376:   isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
1.129     vatton   1377:              elType.ElTypeNum == HTML_EL_Data_cell ||
                   1378:              elType.ElTypeNum == HTML_EL_Heading_cell ||
                   1379:              elType.ElTypeNum == HTML_EL_Object);
1.79      quint    1380:   if (elType.ElTypeNum == HTML_EL_Object)
                   1381:     /* the height attribute is attached to an Object element */
                   1382:     {
                   1383:       child = TtaGetFirstChild (el);
1.81      cvs      1384:       if (!child)
1.129     vatton   1385:         return;
1.81      cvs      1386:       else
1.129     vatton   1387:         {
                   1388:           childType = TtaGetElementType (child);
                   1389:           if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
                   1390:             /* the Object element is of type image. apply the width
                   1391:                attribute to the actual image element */
                   1392:             el = child;
                   1393:           else
                   1394:             return;
                   1395:         }
1.79      quint    1396:     }
1.58      vatton   1397:   /* remove trailing spaces */
                   1398:   length = strlen (buffer) - 1;
                   1399:   while (length > 0 && buffer[length] <= SPACE)
                   1400:     length--;
1.109     vatton   1401:   attrTypePxl.AttrSSchema = elType.ElSSchema;
                   1402:   attrTypePercent.AttrSSchema = elType.ElSSchema;
1.58      vatton   1403:   attrTypePxl.AttrTypeNum = HTML_ATTR_IntHeightPxl;
                   1404:   attrTypePercent.AttrTypeNum = HTML_ATTR_IntHeightPercent;
                   1405:   /* is the last character a '%' ? */
                   1406:   if (buffer[length] == '%')
                   1407:     {
                   1408:       /* remove IntHeightPxl */
                   1409:       attrOld = TtaGetAttribute (el, attrTypePxl);
                   1410:       /* update IntHeightPercent */
                   1411:       attrNew = TtaGetAttribute (el, attrTypePercent);
                   1412:       if (attrNew == NULL)
1.129     vatton   1413:         {
                   1414:           attrNew = TtaNewAttribute (attrTypePercent);
                   1415:           TtaAttachAttribute (el, attrNew, doc);
                   1416:         }
1.58      vatton   1417:       else if (isImage && oldHeight == -1)
1.129     vatton   1418:         {
                   1419:           if (attrOld == NULL)
                   1420:             oldHeight = TtaGetAttributeValue (attrNew);
                   1421:           else
                   1422:             oldHeight = TtaGetAttributeValue (attrOld);
                   1423:         }
1.58      vatton   1424:     }
                   1425:   else
                   1426:     {
                   1427:       /* remove IntHeightPercent */
                   1428:       attrOld = TtaGetAttribute (el, attrTypePercent);
                   1429:       /* update IntHeightPxl */
                   1430:       attrNew = TtaGetAttribute (el, attrTypePxl);
                   1431:       if (attrNew == NULL)
1.129     vatton   1432:         {
                   1433:           attrNew = TtaNewAttribute (attrTypePxl);
                   1434:           TtaAttachAttribute (el, attrNew, doc);
                   1435:         }
1.58      vatton   1436:       else if (isImage && oldHeight == -1)
1.129     vatton   1437:         {
                   1438:           TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
                   1439:           if (attrOld == NULL)
                   1440:             oldHeight = w * TtaGetAttributeValue (attrNew) / 100;
                   1441:           else
                   1442:             oldHeight = w * TtaGetAttributeValue (attrOld) / 100;        
                   1443:         }
1.58      vatton   1444:     }
                   1445: 
                   1446:   if (attrOld != NULL)
                   1447:     TtaRemoveAttribute (el, attrOld, doc);
                   1448:   if (sscanf (buffer, "%d", &val))
                   1449:     TtaSetAttributeValue (attrNew, val, el, doc);
                   1450:   else
                   1451:     /* its not a number. Delete attribute and send an error message */
                   1452:     {
1.129     vatton   1453:       TtaRemoveAttribute (el, attrNew, doc);
                   1454:       if (strlen (buffer) > MaxMsgLength - 30)
1.58      vatton   1455:         buffer[MaxMsgLength - 30] = EOS;
1.129     vatton   1456:       sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
                   1457:       HTMLParseError (doc, msgBuffer, 0);
1.58      vatton   1458:     }
                   1459:   if (isImage)
1.79      quint    1460:     UpdateImageMap (origEl, doc, oldHeight, -1);
1.58      vatton   1461: }
                   1462: 
                   1463: /*----------------------------------------------------------------------
1.129     vatton   1464:   CreateAttrIntAreaSize
                   1465:   an HTML attribute "size" has been created or modified for a input element.
                   1466:   Create or update the corresponding attribute IntAreaSize.
1.91      quint    1467:   ----------------------------------------------------------------------*/
                   1468: void CreateAttrIntAreaSize (int value, Element el, Document doc)
                   1469: {
                   1470:   AttributeType   attrType;
                   1471:   Attribute       attr;
                   1472:   ElementType    elType;
                   1473: 
                   1474:   elType = TtaGetElementType (el);
                   1475:   attrType.AttrSSchema = elType.ElSSchema;
                   1476:   attrType.AttrTypeNum = HTML_ATTR_IntAreaSize;
                   1477:   attr = TtaGetAttribute (el, attrType);
                   1478:   if (!attr)
                   1479:     {
                   1480:       attr = TtaNewAttribute (attrType);
                   1481:       TtaAttachAttribute (el, attr, doc);
                   1482:     }
                   1483:   /* the presentation rule associated with attribute IntAreaSize expresses
                   1484:      the element width in "em". Convert the value into em */
1.122     vatton   1485:   TtaSetAttributeValue (attr, (int) (value * 0.40), el, doc);
1.91      quint    1486: }
                   1487: 
                   1488: /*----------------------------------------------------------------------
1.129     vatton   1489:   CreateAttrIntSize
                   1490:   an HTML attribute "size" has been created for a Font element.
                   1491:   Create the corresponding internal attribute.
1.30      cvs      1492:   ----------------------------------------------------------------------*/
1.109     vatton   1493: void CreateAttrIntSize (char *buffer, Element el, Document doc)
1.30      cvs      1494: 
                   1495: {
1.129     vatton   1496:   ElementType    elType;
                   1497:   AttributeType  attrType;
                   1498:   int            val, ind, factor, delta;
                   1499:   Attribute      attr;
                   1500:   char         msgBuffer[MaxMsgLength];
                   1501: 
                   1502:   /* is the first character a '+' or a '-' ? */
                   1503:   elType = TtaGetElementType (el);
                   1504:   ind = 0;
                   1505:   factor = 1;
                   1506:   delta = 0;
                   1507:   if (buffer[0] == '+')
                   1508:     {
                   1509:       attrType.AttrTypeNum = HTML_ATTR_IntSizeIncr;
                   1510:       ind++;
                   1511:       factor = 1;
                   1512:     }
                   1513:   else if (buffer[0] == '-')
                   1514:     {
                   1515:       attrType.AttrTypeNum = HTML_ATTR_IntSizeDecr;
                   1516:       ind++;
                   1517:       factor = 1;
                   1518:     }
                   1519:   else
                   1520:     {
                   1521:       attrType.AttrTypeNum = HTML_ATTR_IntSizeRel;
                   1522:       delta = 1;
                   1523:     }
                   1524:   attrType.AttrSSchema = elType.ElSSchema;
                   1525:   attr = TtaGetAttribute (el, attrType);
                   1526:   if (sscanf (&buffer[ind], "%d", &val))
                   1527:     {
                   1528:       val = val * factor + delta;
                   1529:       if (attr == NULL)
                   1530:         {
                   1531:           /* this attribute doesn't exist, create it */
                   1532:           attr = TtaNewAttribute (attrType);
                   1533:           TtaAttachAttribute (el, attr, doc);
                   1534:         }
                   1535:       TtaSetAttributeValue (attr, val, el, doc);
                   1536:     }
                   1537:   else
                   1538:     /* its not a number. Delete attribute and send an error message */
                   1539:     {
                   1540:       if (attr)
                   1541:         TtaRemoveAttribute (el, attr, doc);
                   1542:       if (strlen (buffer) > MaxMsgLength - 30)
                   1543:         buffer[MaxMsgLength - 30] = EOS;
                   1544:       sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
                   1545:       HTMLParseError (doc, msgBuffer, 0);
                   1546:     }
1.30      cvs      1547: }
                   1548: /*----------------------------------------------------------------------
1.129     vatton   1549:   EndOfHTMLAttributeValue
                   1550:   Filling of an HTML attribute value
1.30      cvs      1551:   ----------------------------------------------------------------------*/
1.109     vatton   1552: void EndOfHTMLAttributeValue (char *attrValue, AttributeMapping *lastMappedAttr,
1.129     vatton   1553:                               Attribute currentAttribute, Element lastAttrElement,
                   1554:                               ThotBool UnknownAttr, ParserData *context,
                   1555:                               ThotBool isXML)
1.30      cvs      1556: {
1.48      vatton   1557:   AttributeType   attrType, attrType1;
                   1558:   Attribute       attr;
1.79      quint    1559:   ElementType    elType;
1.48      vatton   1560:   Element         child, root;
                   1561:   Language        lang;
                   1562:   char            translation;
                   1563:   char            shape;
                   1564:   char           *buffer;
                   1565:   char           *attrName;
                   1566:   char            msgBuffer[MaxMsgLength];
                   1567:   int             val;
                   1568:   int             length;
                   1569:   int             attrKind;
                   1570:   ThotBool        done = FALSE;
1.88      vatton   1571:   ThotBool            loadcss;
1.30      cvs      1572: 
1.48      vatton   1573:   /* treatments of some particular HTML attributes */
                   1574:   if (!strcmp (lastMappedAttr->XMLattribute, "style"))
                   1575:     {
                   1576:       TtaSetAttributeText (currentAttribute, attrValue,
1.129     vatton   1577:                            lastAttrElement, context->doc);
1.88      vatton   1578:       /* check if we have to load CSS */
                   1579:       TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
                   1580:       if (loadcss)
1.129     vatton   1581:         ParseHTMLSpecificStyle (context->lastElement, attrValue,
                   1582:                                 context->doc, 200, FALSE);
1.48      vatton   1583:       done = TRUE;
                   1584:     }
                   1585:   else
                   1586:     {
                   1587:       if (!strcmp (lastMappedAttr->XMLattribute, "link"))
1.129     vatton   1588:         HTMLSetAlinkColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1589:       else if (!strcmp (lastMappedAttr->XMLattribute, "alink"))
1.129     vatton   1590:         HTMLSetAactiveColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1591:       else if (!strcmp (lastMappedAttr->XMLattribute, "vlink"))
1.129     vatton   1592:         HTMLSetAvisitedColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1593:     }
1.30      cvs      1594: 
1.48      vatton   1595:   if (!done)
                   1596:     {
1.109     vatton   1597:       elType = TtaGetElementType (lastAttrElement);
1.48      vatton   1598:       val = 0;
                   1599:       translation = lastMappedAttr->AttrOrContent;
                   1600:       switch (translation)
1.129     vatton   1601:         {
                   1602:         case 'C':      /* Content */
                   1603:           child = PutInContent (attrValue, context);
                   1604:           if (child != NULL)
                   1605:             TtaAppendTextContent (child, (unsigned char *)"\" ", context->doc);
                   1606:           break;
                   1607:         case 'A':
                   1608:           if (currentAttribute != NULL)
                   1609:             {
                   1610:               TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
                   1611:               switch (attrKind)
                   1612:                 {
                   1613:                 case 0:        /* enumerate */
                   1614:                   if (isXML)
                   1615:                     MapHTMLAttributeValue (attrValue, &attrType, &val);
                   1616:                   else
                   1617:                     val = MapAttrValue (lastMappedAttr->ThotAttribute,
                   1618:                                         attrValue);
                   1619:                   if (val < 0)
                   1620:                     {
                   1621:                       TtaGiveAttributeType (currentAttribute,
                   1622:                                             &attrType, &attrKind);
                   1623:                       attrName = TtaGetAttributeName (attrType);
                   1624:                       sprintf (msgBuffer,
                   1625:                                "Invalid attribute value \"%s = %s\"",
                   1626:                                attrName, attrValue);
                   1627:                       if (isXML)
                   1628:                         XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
                   1629:                       else
                   1630:                         /* we are parsing an HTML file, not an XHTML file */
                   1631:                         {
                   1632:                           /* generate an error message in the log */
                   1633:                           HTMLParseError (context->doc, msgBuffer, 0);
                   1634:                           /* special case for value POLYGON of attribute 
                   1635:                              shape (AREA element) */
                   1636:                           if (attrType.AttrTypeNum == HTML_ATTR_shape &&
                   1637:                               strcasecmp (attrValue, "POLYGON") == 0)
                   1638:                             {
                   1639:                               val = HTML_ATTR_shape_VAL_polygon;
                   1640:                               /* interpret it as if it were "poly" */
                   1641:                               TtaSetAttributeValue (currentAttribute, val,
                   1642:                                                     lastAttrElement, context->doc);
                   1643:                             }
                   1644:                           else
                   1645:                             /* remove the attribute and replace it by an */
                   1646:                             /* Invalid_attribute (not for XHTML) */
                   1647:                             {
                   1648:                               TtaRemoveAttribute (lastAttrElement,
                   1649:                                                   currentAttribute, context->doc);
                   1650:                               attrType.AttrSSchema = elType.ElSSchema;
                   1651:                               attrType.AttrTypeNum =
                   1652:                                 pHTMLAttributeMapping[0].ThotAttribute;
                   1653:                               sprintf (msgBuffer, "%s=%s", attrName,attrValue);
                   1654:                               CreateHTMLAttribute (lastAttrElement, attrType,
                   1655:                                                    msgBuffer, TRUE, context->doc,
                   1656:                                                    &currentAttribute, &lastAttrElement);
                   1657:                             }
                   1658:                         }
                   1659:                     }
                   1660:                   else
                   1661:                     TtaSetAttributeValue (currentAttribute, val,
                   1662:                                           lastAttrElement, context->doc);
                   1663:                   break;
                   1664:                 case 1:        /* integer */
                   1665:                   if (attrType.AttrTypeNum == HTML_ATTR_Border &&
                   1666:                       !strcasecmp (attrValue, "border"))
                   1667:                     {
                   1668:                       /* border="border" for a table */
                   1669:                       val = 1;
                   1670:                       TtaSetAttributeValue (currentAttribute, val,
                   1671:                                             lastAttrElement, context->doc);
                   1672:                     }
                   1673:                   else if (sscanf (attrValue, "%d", &val))
                   1674:                     TtaSetAttributeValue (currentAttribute, val,
                   1675:                                           lastAttrElement, context->doc);
                   1676:                   else
                   1677:                     {
                   1678:                       TtaRemoveAttribute (lastAttrElement, currentAttribute,
                   1679:                                           context->doc);
                   1680:                       sprintf (msgBuffer,
                   1681:                                "Unknown attribute value \"%s\"",
                   1682:                                attrValue);
                   1683:                       if (isXML)
                   1684:                         XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
                   1685:                       else
                   1686:                         HTMLParseError (context->doc, msgBuffer, 0);
                   1687:                     }
                   1688:                   break;
                   1689:                 case 2:        /* text */
                   1690:                   if (!UnknownAttr)
                   1691:                     {
                   1692:                       TtaSetAttributeText (currentAttribute, attrValue,
                   1693:                                            lastAttrElement, context->doc);
                   1694:                       if (attrType.AttrTypeNum == HTML_ATTR_Language)
                   1695:                         {
                   1696:                           /* it's a LANG attribute value */
                   1697:                           lang = TtaGetLanguageIdFromName (attrValue);
                   1698:                           if (lang < 0)
                   1699:                             {
                   1700:                               sprintf (msgBuffer,
                   1701:                                        "warning - unsupported language: %s",
                   1702:                                        attrValue);
                   1703:                               if (isXML)
                   1704:                                 XmlParseError (warningMessage, (unsigned char *)msgBuffer, 0);
                   1705:                               else
                   1706:                                 HTMLParseError (context->doc, msgBuffer, 0);
                   1707:                             }
                   1708:                           else
                   1709:                             {
                   1710:                               /* change current language */
                   1711:                               context->language = lang;
                   1712:                               if (isXML)
                   1713:                                 SetLanguagInXmlStack (lang);
                   1714:                               else
                   1715:                                 SetLanguagInHTMLStack (lang);
                   1716:                             }
                   1717:                           root = TtaGetRootElement (context->doc);
                   1718:                           if (lastAttrElement == root)
                   1719:                             /* it's a LANG attribute on the root element */
                   1720:                             /* set the RealLang attribute */
                   1721:                             {
                   1722:                               attrType1.AttrSSchema = elType.ElSSchema;
                   1723:                               attrType1.AttrTypeNum = HTML_ATTR_RealLang;
                   1724:                               /* this attribute could be already present,
                   1725:                                  (lang and xml:lang attributes) */
                   1726:                               if (!TtaGetAttribute (lastAttrElement,
                   1727:                                                     attrType1))
                   1728:                                 /* it's not present. Add it */
                   1729:                                 {
                   1730:                                   attr = TtaNewAttribute (attrType1);
                   1731:                                   TtaAttachAttribute (lastAttrElement,
                   1732:                                                       attr, context->doc);
                   1733:                                   TtaSetAttributeValue (attr,
                   1734:                                                         HTML_ATTR_RealLang_VAL_Yes_,
                   1735:                                                         lastAttrElement,
                   1736:                                                         context->doc);
                   1737:                                 }
                   1738:                             }
                   1739:                         }
                   1740:                       else if (attrType.AttrTypeNum == HTML_ATTR_ID ||
                   1741:                                attrType.AttrTypeNum == HTML_ATTR_NAME)
                   1742:                         CheckUniqueName (lastAttrElement, context->doc,
                   1743:                                          currentAttribute, attrType);
                   1744:                       else if (attrType.AttrTypeNum == HTML_ATTR_accesskey)
                   1745:                         TtaAddAccessKey (context->doc, (unsigned int)attrValue[0],
                   1746:                                          lastAttrElement);
                   1747:                     }
                   1748:                   else
                   1749:                     {
                   1750:                       /* this is the content of an invalid attribute */
                   1751:                       /* append it to the current Invalid_attribute */
                   1752:                       if (!isXML)
                   1753:                         {
                   1754:                           length = strlen (attrValue) + 2;
                   1755:                           length += TtaGetTextAttributeLength (currentAttribute);
                   1756:                           buffer = (char *)TtaGetMemory (length + 1);
                   1757:                           TtaGiveTextAttributeValue (currentAttribute,
                   1758:                                                      buffer, &length);
                   1759:                           strcat (buffer, "=");
                   1760:                           strcat (buffer, attrValue);
                   1761:                           TtaSetAttributeText (currentAttribute, buffer,
                   1762:                                                lastAttrElement, context->doc);
                   1763:                           TtaFreeMemory (buffer);
                   1764:                         }
                   1765:                     }
                   1766:                   break;
                   1767:                 case 3:        /* reference */
                   1768:                   break;
                   1769:                 }
                   1770:             }
                   1771:           break;
                   1772:         case SPACE:
                   1773:           if (isXML)
                   1774:             XhtmlTypeAttrValue (attrValue, currentAttribute,
                   1775:                                 lastAttrElement, context);
                   1776:           else
                   1777:             HTMLTypeAttrValue (attrValue, currentAttribute,
                   1778:                                lastAttrElement, context);
                   1779:           break;  
                   1780:         default:
                   1781:           break;
                   1782:         }
1.30      cvs      1783: 
                   1784:       if (lastMappedAttr->ThotAttribute == HTML_ATTR_Width__)
1.129     vatton   1785:         /* HTML attribute "width" */
                   1786:         {
                   1787:           /* if it's an Object element, wait until all attributes are handled,
                   1788:              especially the data attribute that may generate the image to
                   1789:              which the width has to be applied */
                   1790:           if (elType.ElTypeNum != HTML_EL_Object)
                   1791:             /* create the corresponding attribute IntWidthPercent or */
                   1792:             /* IntWidthPxl */
                   1793:             CreateAttrWidthPercentPxl (attrValue, lastAttrElement,
                   1794:                                        context->doc, -1);
                   1795:         }
1.58      vatton   1796:       else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Height_)
1.129     vatton   1797:         /* HTML attribute "height" */
                   1798:         {
                   1799:           /* if it's an Object element, wait until all attributes are handled,
                   1800:              especially the data attribute that may generate the image to
                   1801:              which the height has to be applied */
                   1802:           if (elType.ElTypeNum != HTML_EL_Object)
                   1803:             /* create the corresponding attribute IntHeightPercent or */
                   1804:             /* IntHeightPxl */
                   1805:             CreateAttrHeightPercentPxl (attrValue, lastAttrElement,
                   1806:                                         context->doc, -1);
                   1807:         }
1.91      quint    1808:       else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Area_Size)
1.129     vatton   1809:         /* HTML attribute "size" for an element "input" */
                   1810:         CreateAttrIntAreaSize (val, lastAttrElement, context->doc);
1.48      vatton   1811:       else if (!strcmp (lastMappedAttr->XMLattribute, "size"))
1.129     vatton   1812:         {
                   1813:           TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
                   1814:           if (attrType.AttrTypeNum == HTML_ATTR_Font_size)
                   1815:             CreateAttrIntSize (attrValue, lastAttrElement, context->doc);
                   1816:         }
1.48      vatton   1817:       else if (!strcmp (lastMappedAttr->XMLattribute, "shape"))
1.129     vatton   1818:         {
                   1819:           child = TtaGetFirstChild (lastAttrElement);
                   1820:           if (child != NULL)
                   1821:             {
                   1822:               switch (val)
                   1823:                 {
                   1824:                 case HTML_ATTR_shape_VAL_rectangle:
                   1825:                   shape = 'R';
                   1826:                   break;
                   1827:                 case HTML_ATTR_shape_VAL_circle:
                   1828:                   shape = 'a';
                   1829:                   break;
                   1830:                 case HTML_ATTR_shape_VAL_polygon:
                   1831:                   shape = 'p';
                   1832:                   break;
                   1833:                 default:
                   1834:                   shape = SPACE;
                   1835:                   break;
                   1836:                 }
                   1837:               TtaSetGraphicsShape (child, shape, context->doc);
                   1838:             }
                   1839:         }
1.48      vatton   1840:       else if (!strcmp (lastMappedAttr->XMLattribute, "value"))
1.129     vatton   1841:         {
                   1842:           if (elType.ElTypeNum == HTML_EL_Text_Input ||
                   1843:               elType.ElTypeNum == HTML_EL_Password_Input ||
                   1844:               elType.ElTypeNum == HTML_EL_File_Input ||
                   1845:               elType.ElTypeNum == HTML_EL_Input)
                   1846:             /* create a Default_Value attribute with the same content */
                   1847:             {
                   1848:               attrType1.AttrSSchema = attrType.AttrSSchema;
                   1849:               attrType1.AttrTypeNum = HTML_ATTR_Default_Value;
                   1850:               attr = TtaNewAttribute (attrType1);
                   1851:               TtaAttachAttribute (lastAttrElement, attr, context->doc);
                   1852:               TtaSetAttributeText (attr, attrValue,
                   1853:                                    lastAttrElement, context->doc);
                   1854:             }
                   1855:         }
1.30      cvs      1856:       else
1.129     vatton   1857:         {
                   1858:           /* Some HTML attributes are equivalent to a CSS property:      */
                   1859:           /*      background     ->                   background         */
                   1860:           /*      bgcolor        ->                   background         */
                   1861:           /*      text           ->                   color              */
                   1862:           /*      color          ->                   color              */
                   1863:           if (!strcmp (lastMappedAttr->XMLattribute, "background"))
                   1864:             {
                   1865:               if (strlen (attrValue) > MaxMsgLength - 30)
                   1866:                 attrValue[MaxMsgLength - 30] = EOS;
                   1867:               HTMLSetBackgroundImage (context->doc, context->lastElement,
                   1868:                                       REPEAT, 0, attrValue, FALSE);
                   1869:             }
                   1870:           else if (!strcmp (lastMappedAttr->XMLattribute, "bgcolor"))
                   1871:             HTMLSetBackgroundColor (context->doc, context->lastElement,
                   1872:                                     0, attrValue);
                   1873:           else if (!strcmp (lastMappedAttr->XMLattribute, "text") ||
                   1874:                    !strcmp (lastMappedAttr->XMLattribute, "color"))
                   1875:             HTMLSetForegroundColor (context->doc, context->lastElement,
                   1876:                                     0, attrValue);
                   1877:         }
1.48      vatton   1878:     }
1.30      cvs      1879: }
                   1880: 
                   1881: /*----------------------------------------------------------------------
1.129     vatton   1882:   MapHTMLAttributeValue
                   1883:   Search in the Attribute Value Mapping Table the entry for the attribute
                   1884:   ThotAtt and its value attVal. Returns the corresponding Thot value.
1.1       cvs      1885:   ----------------------------------------------------------------------*/
1.118     vatton   1886: void MapHTMLAttributeValue (char *attVal, const AttributeType *attrType,
1.129     vatton   1887:                             int *value)
1.1       cvs      1888: {
1.66      vatton   1889:   MapXMLAttributeValue (XHTML_TYPE, attVal, attrType, value);
1.1       cvs      1890: }

Webmaster