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

1.1       cvs         1: /*
                      2:  *
1.64      vatton      3:  *  (c) COPYRIGHT MIT and INRIA, 1996-2002
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"
                     24: #include "fetchXMLname_f.h"
1.30      cvs        25: #include "fetchHTMLname_f.h"
1.22      cvs        26: #include "html2thot_f.h"
1.1       cvs        27: #include "HTMLactions_f.h"
                     28: #include "HTMLedit_f.h"
1.22      cvs        29: #include "HTMLform_f.h"
1.1       cvs        30: #include "HTMLimage_f.h"
                     31: #include "HTMLtable_f.h"
                     32: #include "HTMLimage_f.h"
                     33: #include "UIcss_f.h"
1.13      cvs        34: #include "styleparser_f.h"
1.2       cvs        35: #include "XHTMLbuilder_f.h"
1.13      cvs        36: #include "Xml2thot_f.h"
1.1       cvs        37: 
                     38: /* maximum length of a Thot structure schema name */
                     39: #define MAX_SS_NAME_LENGTH 32
                     40: 
1.30      cvs        41: #define MaxMsgLength 200
                     42: 
1.47      cvs        43: /* Elements that cannot contain text as immediate children.
                     44:    When some text is present in the HTML file it must be 
                     45:    surrounded by a Pseudo_paragraph element */
                     46: static int          NoTextChild[] =
                     47: {
                     48:    HTML_EL_Document, HTML_EL_HTML, HTML_EL_HEAD, HTML_EL_BODY,
                     49:    HTML_EL_Definition_List, HTML_EL_Block_Quote, HTML_EL_Directory,
                     50:    HTML_EL_Form, HTML_EL_Menu, HTML_EL_FIELDSET,
                     51:    HTML_EL_Numbered_List, HTML_EL_Option_Menu,
                     52:    HTML_EL_Unnumbered_List, HTML_EL_Definition, HTML_EL_List_Item,
                     53:    HTML_EL_MAP, HTML_EL_map, HTML_EL_Applet,
                     54:    HTML_EL_Object, HTML_EL_IFRAME, HTML_EL_NOFRAMES,
                     55:    HTML_EL_Division, HTML_EL_Center, HTML_EL_NOSCRIPT,
                     56:    HTML_EL_Data_cell, HTML_EL_Heading_cell,
                     57:    0};
                     58: 
1.28      cvs        59: /* Define a pointer to let parser functions access the HTML entity table */
                     60: extern XmlEntity *pXhtmlEntityTable;
1.6       cvs        61: 
1.30      cvs        62: /* maximum size of error messages */
                     63: #define MaxMsgLength 200
                     64: 
1.6       cvs        65: /*----------------------------------------------------------------------
1.15      cvs        66:   ParseCharset:
1.6       cvs        67:   Parses the element HTTP-EQUIV and looks for the charset value.
                     68:   ----------------------------------------------------------------------*/
1.30      cvs        69: void             ParseCharset (Element el, Document doc) 
                     70: 
1.6       cvs        71: {
1.15      cvs        72:    AttributeType attrType;
                     73:    Attribute     attr;
                     74:    SSchema       docSSchema;
                     75:    CHARSET       charset;
1.39      cvs        76:    char         *text, *text2, *ptrText, *str;
                     77:    char          charsetname[MAX_LENGTH];
1.15      cvs        78:    int           length;
1.6       cvs        79:    int           pos, index = 0;
                     80: 
1.15      cvs        81:    charset = TtaGetDocumentCharset (doc);
                     82:    if (charset != UNDEFINED_CHARSET)
                     83:      /* the charset was already defined by the http header */
                     84:      return;
1.6       cvs        85: 
                     86:    docSSchema = TtaGetDocumentSSchema (doc);
                     87:    attrType.AttrSSchema = docSSchema;
                     88:    attrType.AttrTypeNum = HTML_ATTR_http_equiv;
                     89:    attr = TtaGetAttribute (el, attrType);
                     90:    if (attr != NULL)
                     91:      {
                     92:        /* There is a HTTP-EQUIV attribute */
                     93:        length = TtaGetTextAttributeLength (attr);
                     94:        if (length > 0)
                     95:         {
1.37      cvs        96:           text = TtaGetMemory (length + 1);
1.6       cvs        97:           TtaGiveTextAttributeValue (attr, text, &length);
1.37      cvs        98:           if (!strcasecmp (text, "content-type"))
1.6       cvs        99:             {
                    100:               attrType.AttrTypeNum = HTML_ATTR_meta_content;
                    101:               attr = TtaGetAttribute (el, attrType);
                    102:               if (attr != NULL)
                    103:                 {
                    104:                   length = TtaGetTextAttributeLength (attr);
                    105:                   if (length > 0)
                    106:                     {
1.37      cvs       107:                       text2 = TtaGetMemory (length + 1);
1.6       cvs       108:                       TtaGiveTextAttributeValue (attr, text2, &length);
                    109:                       ptrText = text2;
                    110:                       while (*ptrText)
                    111:                         {
1.53      vatton    112:                           *ptrText = tolower (*ptrText);
1.6       cvs       113:                           ptrText++;
                    114:                         }
                    115:                       
1.37      cvs       116:                       str = strstr (text2, "charset=");
1.6       cvs       117:                       if (str)
                    118:                         {
                    119:                           pos = str - text2 + 8;
1.37      cvs       120:                           while (text2[pos] != SPACE &&
                    121:                                  text2[pos] != TAB && text2[pos] != EOS)
1.6       cvs       122:                             charsetname[index++] = text2[pos++];
1.37      cvs       123:                           charsetname[index] = EOS;
1.15      cvs       124:                           charset = TtaGetCharset (charsetname);
                    125:                           if (charset != UNDEFINED_CHARSET)
                    126:                             TtaSetDocumentCharset (doc, charset);
1.6       cvs       127:                         }
                    128:                       TtaFreeMemory (text2);
                    129:                     }       
                    130:                 } 
                    131:             }
                    132:           TtaFreeMemory (text);
                    133:         }
                    134:      }
                    135: }
                    136: 
1.23      cvs       137: /*----------------------------------------------------------------------
1.47      cvs       138:    XhtmlCannotContainText 
                    139:    Return TRUE if element el is a block element.
                    140:   ----------------------------------------------------------------------*/
                    141: ThotBool      XhtmlCannotContainText (ElementType elType)
                    142: 
                    143: {
                    144:    int        i;
                    145:    ThotBool   ret;
                    146: 
                    147:    if (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML"))
                    148:       /* not an HTML element */
                    149:       ret = TRUE;
                    150:    else
                    151:      {
                    152:        ret = FALSE;
                    153:        i = 0;
                    154:        while (NoTextChild[i] > 0 && NoTextChild[i] != elType.ElTypeNum)
                    155:            i++;
                    156:        if (NoTextChild[i] == elType.ElTypeNum)
                    157:            ret = TRUE;
                    158:      }
                    159:    return ret;
1.23      cvs       160: }
                    161: 
1.6       cvs       162: /*----------------------------------------------------------------------
                    163:   XhtmlElementComplete
1.20      cvs       164:   Complete Xhtml elements.
1.6       cvs       165:   Check its attributes and its contents.
                    166:   ----------------------------------------------------------------------*/
1.51      cvs       167: void       XhtmlElementComplete (Element el, Document doc, int *error)
1.30      cvs       168: 
                    169: {
                    170:    ElementType    elType, newElType, childType;
                    171:    Element        constElem, child, desc, leaf, prev, next, last,
1.62      quint     172:                  elFrames, lastFrame, lastChild, parent, picture, content;
1.30      cvs       173:    Attribute      attr;
                    174:    AttributeType  attrType;
                    175:    Language       lang;
1.41      cvs       176:    char           *text;
1.39      cvs       177:    char           lastChar[2];
                    178:    char           *name1;
1.30      cvs       179:    int            length;
                    180:    SSchema        docSSchema;
1.62      quint     181:    ThotBool       isImage;
                    182:    PresentationValue    pval;
                    183:    PresentationContext  ctxt;
1.6       cvs       184: 
                    185:    *error = 0;
                    186:    docSSchema = TtaGetDocumentSSchema (doc);
                    187: 
                    188:    elType = TtaGetElementType (el);
                    189:    /* is this a block-level element in a character-level element? */
1.56      cvs       190:    if (!IsXMLElementInline (elType, doc) &&
1.24      cvs       191:        elType.ElTypeNum != HTML_EL_Comment_ &&
                    192:        elType.ElTypeNum != HTML_EL_XMLPI)
1.6       cvs       193:        BlockInCharLevelElem (el);
                    194: 
                    195:    newElType.ElSSchema = elType.ElSSchema;
                    196:    switch (elType.ElTypeNum)
                    197:      {
1.62      quint     198:      case HTML_EL_Object:      /* it's an object */
                    199:        isImage = FALSE;
                    200:        /* is there a type attribute on the object element? */
                    201:        attrType.AttrSSchema = elType.ElSSchema;
                    202:        attrType.AttrTypeNum = HTML_ATTR_Object_type;
1.6       cvs       203:        attr = TtaGetAttribute (el, attrType);
1.62      quint     204:        if (attr)
                    205:         /* there is a type attribute. Get its value to see if the object
                    206:            represents an image */
1.6       cvs       207:         {
                    208:           length = TtaGetTextAttributeLength (attr);
                    209:           if (length > 0)
                    210:             {
1.37      cvs       211:               name1 = TtaGetMemory (length + 1);
1.6       cvs       212:               TtaGiveTextAttributeValue (attr, name1, &length);
1.68      kahan     213:               if (!strcmp (name1, AM_MATHML_MIME_TYPE) ||
1.62      quint     214:                   !strcmp (name1, "application/postscript") ||
                    215:                   !strcmp (name1, "image/x-bitmap") ||
                    216:                   !strcmp (name1, "image/x-xpixmap") ||
                    217:                   !strcmp (name1, "image/gif") ||
                    218:                   !strcmp (name1, "image/jpeg") ||
                    219:                   !strcmp (name1, "image/png") ||
1.67      kahan     220:                   !strcmp (name1, "image/svg") ||
1.68      kahan     221:                   !strcmp (name1, AM_SVG_MIME_TYPE))
1.62      quint     222:                 isImage = TRUE;
                    223:               TtaFreeMemory (name1);
                    224:             }
                    225:         }
                    226:        
                    227:        picture = NULL;     /* no PICTURE element yet */
                    228:        child = TtaGetFirstChild (el);
                    229:        if (isImage)
                    230:         /* the object represents an image. We need a PICTURE element as
                    231:            child of the object to hold the image */
                    232:         {
                    233:           if (child)
                    234:             {
                    235:               elType = TtaGetElementType (child);
                    236:               if (elType.ElTypeNum == HTML_EL_PICTURE_UNIT)
                    237:                 /* there is already a PICTURE element */
                    238:                 picture = child;
                    239:             }
                    240:           /* if the object element has no PICTURE element as first child
                    241:              create one */
                    242:           if (!picture)
                    243:             {
                    244:               elType.ElTypeNum = HTML_EL_PICTURE_UNIT;
                    245:               picture = TtaNewTree (doc, elType, "");
                    246:               if (child)
                    247:                 TtaInsertSibling (picture, child, TRUE, doc);
                    248:               else
                    249:                 TtaInsertFirstChild (&picture, el, doc);
                    250:               child = picture;
                    251:             }
                    252:           /* copy attribute data of the object into the SRC attribute of
                    253:              the PICTURE element */
                    254:           attrType.AttrSSchema = elType.ElSSchema;
                    255:           attrType.AttrTypeNum = HTML_ATTR_data;
                    256:           attr = TtaGetAttribute (el, attrType);
                    257:           if (attr)
                    258:             /* the object has a data attribute */
                    259:             {
                    260:               length = TtaGetTextAttributeLength (attr);
                    261:               if (length > 0)
1.6       cvs       262:                 {
1.62      quint     263:                   name1 = TtaGetMemory (length + 1);
                    264:                   TtaGiveTextAttributeValue (attr, name1, &length);
                    265:                   attrType.AttrTypeNum = HTML_ATTR_SRC;
                    266:                   attr = TtaGetAttribute (picture, attrType);
                    267:                   if (attr == NULL)
                    268:                     {
                    269:                       attr = TtaNewAttribute (attrType);
                    270:                       TtaAttachAttribute (picture, attr, doc);
                    271:                     }
                    272:                   TtaSetAttributeText (attr, name1, picture, doc);
                    273:                   TtaFreeMemory (name1);
1.6       cvs       274:                 }
                    275:             }
                    276:         }
                    277:        /* is the Object_Content element already created ? */
1.62      quint     278:        if (child)
                    279:         /* the object element has at least 1 child element */
                    280:         {
                    281:           content = NULL;
                    282:           desc = child;
1.6       cvs       283:           elType = TtaGetElementType (desc);
1.62      quint     284:           if (elType.ElTypeNum != HTML_EL_Object_Content)
                    285:             {
                    286:               TtaNextSibling(&desc);
                    287:               if (desc)
                    288:                 elType = TtaGetElementType (desc);
                    289:             }
                    290:           /* is it the Object_Content element ? */
                    291:           if (elType.ElTypeNum == HTML_EL_Object_Content)
                    292:             content = desc;
                    293:           else
1.6       cvs       294:             {
1.62      quint     295:               /* create an Object_Content element */
                    296:               elType.ElTypeNum = HTML_EL_Object_Content;
                    297:               content = TtaNewElement (doc, elType);
                    298:               if (picture)
                    299:                 TtaInsertSibling (content, picture, FALSE, doc);
                    300:               else
                    301:                 TtaInsertSibling (content, child, TRUE, doc);
                    302:               /* move previous existing children into Object_Content */
1.6       cvs       303:               child = TtaGetLastChild(el);
1.62      quint     304:               while (child != content)
                    305:                 {
                    306:                   TtaRemoveTree (child, doc);
                    307:                   TtaInsertFirstChild (&child, content, doc);
                    308:                   child = TtaGetLastChild(el);
                    309:                 }
                    310:             }
                    311:           if (picture && content)
                    312:             /* there is a picture element. The Object_Content must not be
                    313:                displayed in the main view */
                    314:             {
                    315:               ctxt = TtaGetSpecificStyleContext (doc);
                    316:               /* the presentation rule to be set is not a CSS rule */
                    317:               ctxt->cssSpecificity = 0;
                    318:               ctxt->destroy = FALSE;
                    319:               pval.typed_data.unit = STYLE_UNIT_PX;
                    320:               pval.typed_data.value = 0;
                    321:               pval.typed_data.real = FALSE;
                    322:               TtaSetStylePresentation (PRVisibility, content, NULL, ctxt, pval);
1.6       cvs       323:             }
                    324:         }
                    325:        break;
1.62      quint     326: 
1.6       cvs       327:      case HTML_EL_Unnumbered_List:
                    328:      case HTML_EL_Numbered_List:
                    329:      case HTML_EL_Menu:
                    330:      case HTML_EL_Directory:
                    331:        /* It's a List element. It should only have List_Item children.
                    332:          If it has List element chidren, move these List elements
                    333:          within their previous List_Item sibling.  This is to fix
                    334:          a bug in document generated by Mozilla. */
                    335:        prev = NULL;
                    336:        next = NULL;
                    337:        child = TtaGetFirstChild (el);
                    338:        while (child != NULL)
                    339:         {
                    340:           next = child;
                    341:           TtaNextSibling (&next);
                    342:           elType = TtaGetElementType (child);
                    343:           if (elType.ElTypeNum == HTML_EL_Unnumbered_List ||
                    344:               elType.ElTypeNum == HTML_EL_Numbered_List ||
                    345:               elType.ElTypeNum == HTML_EL_Menu ||
                    346:               elType.ElTypeNum == HTML_EL_Directory)
                    347:             /* this list element is a child of another list element */
                    348:             if (prev)
                    349:               {
                    350:                 elType = TtaGetElementType (prev);
                    351:                 if (elType.ElTypeNum == HTML_EL_List_Item)
                    352:                   {
                    353:                     /* get the last child of the previous List_Item */
                    354:                     desc = TtaGetFirstChild (prev);
                    355:                     last = NULL;
                    356:                     while (desc)
                    357:                       {
                    358:                         last = desc;
                    359:                         TtaNextSibling (&desc);
                    360:                       }
                    361:                     /* move the list element after the last child of the
                    362:                        previous List_Item */
                    363:                     TtaRemoveTree (child, doc);
                    364:                     if (last)
                    365:                       TtaInsertSibling (child, last, FALSE, doc);
                    366:                     else
                    367:                       TtaInsertFirstChild (&child, prev, doc);
                    368:                     child = prev;
                    369:                   }
                    370:               }
                    371:           prev = child;
                    372:           child = next;
                    373:         }
                    374:        break;
                    375:        
                    376:      case HTML_EL_FRAMESET:
                    377:        /* The FRAMESET element is now complete.  Gather all its FRAMESET
                    378:          and FRAME children and wrap them up in a Frames element */
                    379:        elFrames = NULL; lastFrame = NULL;
                    380:        lastChild = NULL;
                    381:        child = TtaGetFirstChild (el);
                    382:        while (child != NULL)
                    383:         {
                    384:           next = child;
                    385:           TtaNextSibling (&next);
                    386:           elType = TtaGetElementType (child);
                    387:           if (elType.ElTypeNum == HTML_EL_FRAMESET ||
                    388:               elType.ElTypeNum == HTML_EL_FRAME ||
                    389:               elType.ElTypeNum == HTML_EL_Comment_)
                    390:             {
                    391:               /* create the Frames element if it does not exist */
                    392:               if (elFrames == NULL)
                    393:                 {
                    394:                   newElType.ElSSchema = docSSchema;
                    395:                   newElType.ElTypeNum = HTML_EL_Frames;
                    396:                   elFrames = TtaNewElement (doc, newElType);
1.63      cvs       397:                   if (DocumentMeta[doc]->xmlformat)
                    398:                     XmlSetElemLineNumber (elFrames);
                    399:                   else
                    400:                     SetHtmlElemLineNumber (elFrames);
1.6       cvs       401:                   TtaInsertSibling (elFrames, child, TRUE, doc);
                    402:                 }
                    403:               /* move the element as the last child of the Frames element */
                    404:               TtaRemoveTree (child, doc);
                    405:               if (lastFrame == NULL)
                    406:                 TtaInsertFirstChild (&child, elFrames, doc);
                    407:               else
                    408:                 TtaInsertSibling (child, lastFrame, FALSE, doc);
                    409:               lastFrame = child;
                    410:             }
                    411:           child = next;
                    412:         }
                    413:        break;
                    414:        
                    415:      case HTML_EL_Input:       /* it's an INPUT without any TYPE attribute */
                    416:        /* Create a child of type Text_Input */
                    417:        elType.ElTypeNum = HTML_EL_Text_Input;
                    418:        child = TtaNewTree (doc, elType, "");
1.63      cvs       419:        if (DocumentMeta[doc]->xmlformat)
                    420:         XmlSetElemLineNumber (child);
                    421:        else
                    422:         SetHtmlElemLineNumber (child);
1.6       cvs       423:        TtaInsertFirstChild (&child, el, doc);
                    424:        /* now, process it like a Text_Input element */
                    425: 
                    426:      case HTML_EL_Text_Input:
                    427:      case HTML_EL_Password_Input:
                    428:      case HTML_EL_File_Input:
                    429:        /* get element Inserted_Text */
                    430:        child = TtaGetFirstChild (el);
                    431:        if (child != NULL)
                    432:         {
                    433:           attrType.AttrSSchema = docSSchema;
                    434:           attrType.AttrTypeNum = HTML_ATTR_Value_;
                    435:           attr = TtaGetAttribute (el, attrType);
                    436:           if (attr != NULL)
                    437:             {
                    438:               /* copy the value of attribute "value" into the first text
                    439:                  leaf of element */
                    440:               length = TtaGetTextAttributeLength (attr);
                    441:               if (length > 0)
                    442:                 {
                    443:                   /* get the text leaf */
                    444:                   leaf = TtaGetFirstChild (child);
                    445:                   if (leaf != NULL)
                    446:                     {
                    447:                       childType = TtaGetElementType (leaf);
                    448:                       if (childType.ElTypeNum == HTML_EL_TEXT_UNIT)
                    449:                         {
                    450:                           /* copy attribute value into the text leaf */
1.37      cvs       451:                           text = TtaGetMemory (length + 1);
1.6       cvs       452:                           TtaGiveTextAttributeValue (attr, text, &length);
                    453:                           TtaSetTextContent (leaf, text, 
                    454:                                              TtaGetDefaultLanguage (), doc);
                    455:                           TtaFreeMemory (text);
                    456:                         }
                    457:                     }
                    458:                 }
                    459:             }
                    460:         }
                    461:        break;
                    462:        
                    463:      case HTML_EL_META:
1.15      cvs       464:        ParseCharset (el, doc);
1.6       cvs       465:        break;
                    466: 
                    467:      case HTML_EL_STYLE_:      /* it's a STYLE element */
1.60      vatton    468:      case HTML_EL_SCRIPT_:     /* it's a SCRIPT element */
1.6       cvs       469:      case HTML_EL_Preformatted:        /* it's a PRE */
                    470:        /* if the last line of the Preformatted is empty, remove it */
                    471:        leaf = XmlLastLeafInElement (el);
                    472:        if (leaf != NULL)
                    473:         {
                    474:           elType = TtaGetElementType (leaf);
                    475:           if (elType.ElTypeNum == HTML_EL_TEXT_UNIT)
                    476:             /* the last leaf is a TEXT element */
                    477:             {
                    478:               length = TtaGetTextLength (leaf);
                    479:               if (length > 0)
                    480:                 {
                    481:                   TtaGiveSubString (leaf, lastChar, length, 1);
                    482:                   if (lastChar[0] == EOL)
                    483:                     /* last character is new line, delete it */
                    484:                     {
                    485:                       if (length == 1)
                    486:                         /* empty TEXT element */
                    487:                         TtaDeleteTree (leaf, doc);
                    488:                       else
                    489:                         /* remove the last character */
                    490:                         TtaDeleteTextContent (leaf, length, 1, doc);
                    491:                     }
                    492:                 }
                    493:             }
                    494:         }
1.63      cvs       495:        if (DocumentMeta[doc]->xmlformat)
                    496:         {
                    497:           if (IsXmlParsingCSS ())
                    498:             {
                    499:               text = GetStyleContents (el);
                    500:               if (text)
                    501:                 {
                    502:                   ReadCSSRules (doc, NULL, text,
                    503:                                 TtaGetElementLineNumber (el), FALSE);
                    504:                   TtaFreeMemory (text);
                    505:                 }
                    506:               SetXmlParsingCSS (FALSE);
                    507:             }
                    508:         }
                    509:        else
1.6       cvs       510:         {
1.63      cvs       511:           if (IsHtmlParsingCSS ())
1.6       cvs       512:             {
1.63      cvs       513:               text = GetStyleContents (el);
                    514:               if (text)
                    515:                 {
                    516:                   ReadCSSRules (doc, NULL, text,
                    517:                                 TtaGetElementLineNumber (el), FALSE);
                    518:                   TtaFreeMemory (text);
                    519:                 }
                    520:               SetHtmlParsingCSS (FALSE);
1.6       cvs       521:             }
                    522:         }
                    523:        /* and continue as if it were a Preformatted or a Script */
                    524:        break;
                    525:        
                    526:      case HTML_EL_Text_Area:   /* it's a Text_Area */
1.69    ! cvs       527:        if (DocumentMeta[doc]->xmlformat)
        !           528:         SetParsingTextArea (FALSE);
        !           529:        else
        !           530:         SetHtmlParsingTextArea (FALSE);
1.6       cvs       531:        child = TtaGetFirstChild (el);
                    532:        if (child == NULL)
                    533:         /* it's an empty Text_Area */
                    534:         /* insert a Inserted_Text element in the element */
                    535:         {
                    536:           newElType.ElTypeNum = HTML_EL_Inserted_Text;
                    537:           child = TtaNewTree (doc, newElType, "");
                    538:           TtaInsertFirstChild (&child, el, doc);
                    539:         }
                    540:        else
                    541:         {
                    542:           /* save the text into Default_Value attribute */
                    543:           attrType.AttrSSchema = docSSchema;
                    544:           attrType.AttrTypeNum = HTML_ATTR_Default_Value;
                    545:           if (TtaGetAttribute (el, attrType) == NULL)
                    546:             /* attribute Default_Value is missing */
                    547:             {
                    548:               attr = TtaNewAttribute (attrType);
                    549:               TtaAttachAttribute (el, attr, doc);
                    550:               desc = TtaGetFirstChild (child);
                    551:               length = TtaGetTextLength (desc) + 1;
1.37      cvs       552:               text = TtaGetMemory (length);
1.6       cvs       553:               TtaGiveTextContent (desc, text, &length, &lang);
                    554:               TtaSetAttributeText (attr, text, el, doc);
                    555:               TtaFreeMemory (text);
                    556:             }
                    557:         }
                    558:        /* insert a Frame element */
                    559:        newElType.ElTypeNum = HTML_EL_Frame;
                    560:        constElem = TtaNewTree (doc, newElType, "");
                    561:        TtaInsertSibling (constElem, child, FALSE, doc);
                    562:        break;
                    563:        
                    564:      case HTML_EL_Radio_Input:
                    565:      case HTML_EL_Checkbox_Input:
                    566:        /* put an attribute Checked if it is missing */
                    567:        attrType.AttrSSchema = docSSchema;
                    568:        attrType.AttrTypeNum = HTML_ATTR_Checked;
                    569:        if (TtaGetAttribute (el, attrType) == NULL)
                    570:         /* attribute Checked is missing */
                    571:         {
                    572:           attr = TtaNewAttribute (attrType);
                    573:           TtaAttachAttribute (el, attr, doc);
                    574:           TtaSetAttributeValue (attr, HTML_ATTR_Checked_VAL_No_, el, doc);
                    575:         }
                    576:        break;
                    577:        
                    578:      case HTML_EL_Option_Menu:
                    579:        /* Check that at least one option has a SELECTED attribute */
                    580:        OnlyOneOptionSelected (el, doc, TRUE);
                    581:        break;
                    582: 
                    583:      case HTML_EL_PICTURE_UNIT:
                    584:        break;
                    585:        
                    586:      case HTML_EL_LINK:
                    587:        CheckCSSLink (el, doc, docSSchema);
                    588:        break;
                    589:        
                    590:      case HTML_EL_Data_cell:
                    591:      case HTML_EL_Heading_cell:
                    592:        /* insert a pseudo paragraph into empty cells */
                    593:        child = TtaGetFirstChild (el);
                    594:        if (child == NULL)
                    595:         {
                    596:           elType.ElTypeNum = HTML_EL_Pseudo_paragraph;
                    597:           child = TtaNewTree (doc, elType, "");
                    598:           if (child != NULL)
                    599:               TtaInsertFirstChild (&child, el, doc);
                    600:         }
                    601:        
                    602:        /* detect whether we're parsing a whole table or just a cell */
1.63      cvs       603:        if (DocumentMeta[doc]->xmlformat)
                    604:         {
                    605:           if (IsWithinXmlTable ())
                    606:             NewCell (el, doc, FALSE);
                    607:         }
                    608:        else
                    609:         {
                    610:           if (IsWithinHtmlTable ())
                    611:             NewCell (el, doc, FALSE);
                    612:         }
1.6       cvs       613:        break;
                    614:        
                    615:      case HTML_EL_Table:
                    616:        CheckTable (el, doc);
                    617:        SubWithinTable ();
                    618:        break;
                    619:        
                    620:      case HTML_EL_TITLE:
                    621:        /* show the TITLE in the main window */
                    622:        UpdateTitle (el, doc);
                    623:        break;
1.41      cvs       624: 
                    625:      case HTML_EL_rbc:
                    626:        /* an rbc element has been read. Its parent should be a complex_ruby.
                    627:          Change the type of the parent, as simple_ruby are created by
                    628:          default */
                    629:        parent = TtaGetParent (el);
                    630:        if (parent)
                    631:         {
                    632:           newElType = TtaGetElementType (parent);
                    633:           if (newElType.ElSSchema == elType.ElSSchema &&
                    634:               newElType.ElTypeNum == HTML_EL_simple_ruby)
                    635:              ChangeElementType (parent, HTML_EL_complex_ruby);
                    636:         }
                    637:        break;
                    638: 
                    639:      case HTML_EL_rtc1:
                    640:        /* an rtc element has been parsed. If it has already a rtc1 sibling,
                    641:          change its type to rtc2 */
                    642:        prev = el;
                    643:        do
                    644:         {
                    645:           TtaPreviousSibling(&prev);
                    646:           if (prev)
                    647:             {
                    648:               newElType = TtaGetElementType (prev);
                    649:               if (newElType.ElSSchema == elType.ElSSchema &&
                    650:                   newElType.ElTypeNum == HTML_EL_rtc1)
                    651:                 {
                    652:                   ChangeElementType (el, HTML_EL_rtc2);
                    653:                   prev = NULL;
                    654:                 }
                    655:             }
                    656:         }
                    657:        while (prev);
                    658:        break;
                    659: 
1.6       cvs       660:      default:
                    661:        break;
                    662:      }
                    663: }
1.1       cvs       664: 
                    665: /*----------------------------------------------------------------------
1.30      cvs       666:    PutInContent    
                    667:    Put the string ChrString in the leaf of current element.
                    668:   ----------------------------------------------------------------------*/
1.39      cvs       669: Element         PutInContent (char *ChrString, ParserData *context)
1.30      cvs       670: 
                    671: {
                    672:    Element      el, child;
                    673:    ElementType  elType;
                    674:    int          length;
                    675: 
                    676:    el = NULL;
                    677:    if (context->lastElement != NULL)
                    678:      {
                    679:        /* search first leaf of current element */
                    680:        el = context->lastElement;
                    681:        do
                    682:          {
                    683:             child = TtaGetFirstChild (el);
                    684:             if (child != NULL)
                    685:                el = child;
                    686:          }
                    687:        while (child != NULL);
                    688:        elType = TtaGetElementType (el);
                    689:        length = 0;
                    690:        if (elType.ElTypeNum == 1)
                    691:           length = TtaGetTextLength (el);
                    692:        if (length == 0)
                    693:           TtaSetTextContent (el, ChrString, context->language, context->doc);
                    694:        else
                    695:           TtaAppendTextContent (el, ChrString, context->doc);
                    696:      }
                    697:    return el;
                    698: }
                    699: 
                    700: /*----------------------------------------------------------------------
1.51      cvs       701:    UnknownXhtmlNameSpace
1.65      cvs       702:    The element doesn't belong to a supported namespace
1.51      cvs       703:   ----------------------------------------------------------------------*/
1.65      cvs       704: void               UnknownXhtmlNameSpace (ParserData *context,
                    705:                                          Element *unknownEl,
                    706:                                          char* content)
1.51      cvs       707: {
                    708:    ElementType     elType;
1.65      cvs       709:    Element         elText;
1.51      cvs       710: 
                    711:    /* Create a new Invalid_element */
                    712:    elType.ElSSchema = GetXMLSSchema (XHTML_TYPE, context->doc);
                    713:    elType.ElTypeNum = HTML_EL_Unknown_namespace;
1.65      cvs       714:    *unknownEl = TtaNewElement (context->doc, elType);
                    715:    if (*unknownEl != NULL)
1.51      cvs       716:      {
1.65      cvs       717:        XmlSetElemLineNumber (*unknownEl);
                    718:        InsertXmlElement (unknownEl);
1.51      cvs       719:        context->lastElementClosed = TRUE;
                    720:        elType.ElTypeNum = HTML_EL_TEXT_UNIT;
                    721:        elText = TtaNewElement (context->doc, elType);
                    722:        XmlSetElemLineNumber (elText);
1.65      cvs       723:        TtaInsertFirstChild (&elText, *unknownEl, context->doc);
1.51      cvs       724:        TtaSetTextContent (elText, content, context->language, context->doc);
                    725:        TtaSetAccessRight (elText, ReadOnly, context->doc);
                    726:      }
                    727: }
                    728: 
                    729: /*----------------------------------------------------------------------
1.30      cvs       730:    CreateHTMLAttribute
                    731:    create an attribute of type attrType for the element el.
                    732:   ----------------------------------------------------------------------*/
                    733: void           CreateHTMLAttribute (Element       el,
                    734:                                    AttributeType attrType,
1.46      cvs       735:                                    char*         text,
1.30      cvs       736:                                    ThotBool      isInvalid,
                    737:                                    Document      doc,
                    738:                                    Attribute    *lastAttribute,
                    739:                                    Element      *lastAttrElement)
                    740:      
                    741: {
                    742:    int         attrKind;
                    743:    int         length;
1.39      cvs       744:    char       *buffer;
1.30      cvs       745:    Attribute   attr, oldAttr;
                    746: 
                    747:    if (attrType.AttrTypeNum != 0)
                    748:      {
                    749:        oldAttr = TtaGetAttribute (el, attrType);
                    750:        if (oldAttr != NULL)
                    751:         /* this attribute already exists */
                    752:         attr = oldAttr;
                    753:        else
                    754:         /* create a new attribute and attach it to the element */
                    755:         {
                    756:           attr = TtaNewAttribute (attrType);
                    757:           TtaAttachAttribute (el, attr, doc);
                    758:         }
                    759:        *lastAttribute = attr;
                    760:        *lastAttrElement = el;
                    761: 
                    762:        TtaGiveAttributeType (attr, &attrType, &attrKind);
                    763:        if (attrKind == 0)      /* enumerate */
                    764:         TtaSetAttributeValue (attr, 1, el, doc);
                    765: 
                    766:        /* attribute BORDER without any value (ThotBool attribute) is */
                    767:        /* considered as BORDER=1 */
                    768:        if (attrType.AttrTypeNum == HTML_ATTR_Border)
                    769:         TtaSetAttributeValue (attr, 1, el, doc);
                    770: 
                    771:        if (isInvalid)
                    772:         /* Copy the name of the invalid attribute as the content */
                    773:         /* of the Invalid_attribute attribute. */
                    774:         {
1.37      cvs       775:           length = strlen (text) + 2;
1.30      cvs       776:           length += TtaGetTextAttributeLength (attr);
1.37      cvs       777:           buffer = TtaGetMemory (length + 1);
1.30      cvs       778:           TtaGiveTextAttributeValue (attr, buffer, &length);
1.37      cvs       779:           strcat (buffer, " ");
                    780:           strcat (buffer, text);
1.30      cvs       781:           TtaSetAttributeText (attr, buffer, el, doc);
                    782:           TtaFreeMemory (buffer);
                    783:         }
                    784:      }
                    785: }
                    786: 
                    787: /*----------------------------------------------------------------------
                    788:    HTMLTypeAttrValue
                    789:    Value val has been read for the HTML attribute TYPE.
                    790:    Create a child for the current Thot element INPUT accordingly.
                    791:   ----------------------------------------------------------------------*/
1.46      cvs       792: void               HTMLTypeAttrValue (char       *val,
1.30      cvs       793:                                      Attribute   lastAttribute,
                    794:                                      Element     lastAttrElement,
                    795:                                      ParserData *context)
                    796: 
                    797: {
                    798:   ElementType      elType;
                    799:   Element          newChild;
                    800:   AttributeType    attrType;
                    801:   Attribute        attr;
1.39      cvs       802:   char             msgBuffer[MaxMsgLength];
1.30      cvs       803:   int              value;
                    804:   int              numberOfLinesRead;
                    805: 
                    806:   value = MapAttrValue (DummyAttribute, val);
                    807:   if (value < 0)
                    808:     {
1.37      cvs       809:       if (strlen (val) > MaxMsgLength - 40)
                    810:          val[MaxMsgLength - 40] = EOS;
                    811:       sprintf (msgBuffer, "Unknown attribute value \"type = %s\"", val);
1.42      cvs       812:       HTMLParseError (context->doc, msgBuffer);
1.30      cvs       813:       attrType.AttrSSchema = TtaGetDocumentSSchema (context->doc);
                    814:       attrType.AttrTypeNum = pHTMLAttributeMapping[0].ThotAttribute;
1.37      cvs       815:       sprintf (msgBuffer, "type=%s", val);
1.30      cvs       816:       CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
                    817:                           context->doc, &lastAttribute, &lastAttrElement);
                    818:     }
                    819:   else
                    820:     {
                    821:       elType = TtaGetElementType (context->lastElement);
                    822:       if (elType.ElTypeNum != HTML_EL_Input)
                    823:        {
1.37      cvs       824:          if (strlen (val) > MaxMsgLength - 40)
                    825:            val[MaxMsgLength - 40] = EOS;
                    826:          sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.30      cvs       827:        }
                    828:       else
                    829:        {
                    830:          elType.ElSSchema = TtaGetDocumentSSchema (context->doc);
                    831:          elType.ElTypeNum = value;
                    832:          newChild = TtaNewTree (context->doc, elType, "");
                    833:          numberOfLinesRead = 0;
                    834:          TtaSetElementLineNumber (newChild, numberOfLinesRead);
                    835:          TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
                    836:          if (value == HTML_EL_PICTURE_UNIT)
                    837:            {
                    838:              /* add the attribute IsInput to input pictures */
                    839:              attrType.AttrSSchema = elType.ElSSchema;
                    840:              attrType.AttrTypeNum = HTML_ATTR_IsInput;
                    841:              attr = TtaNewAttribute (attrType);
                    842:              TtaAttachAttribute (newChild, attr, context->doc);
                    843:            }
                    844:        }
                    845:     }
                    846: }
                    847: 
                    848: /*----------------------------------------------------------------------
                    849:    XhtmlTypeAttrValue 
                    850:    Value val has been read for the HTML attribute TYPE.
                    851:    Create a child for the current Thot element INPUT accordingly.
                    852:   ----------------------------------------------------------------------*/
1.46      cvs       853: void              XhtmlTypeAttrValue (char       *val,
1.30      cvs       854:                                      Attribute   currentAttribute,
                    855:                                      Element     lastAttrElement,
                    856:                                      ParserData *context)
                    857: 
                    858: {
                    859:   ElementType     elType;
                    860:   Element         newChild;
                    861:   AttributeType   attrType;
                    862:   Attribute       attr;
1.39      cvs       863:   char            msgBuffer[MaxMsgLength];
1.30      cvs       864:   int             value;
                    865:   ThotBool        level;
                    866: 
                    867:   attrType.AttrTypeNum = DummyAttribute;
                    868:   MapHTMLAttributeValue (val, attrType, &value);
                    869:   if (value < 0)
                    870:     {
1.37      cvs       871:       sprintf (msgBuffer, "Unknown attribute value \"type=%s\"", val);
1.30      cvs       872:       XmlParseError (errorParsing, msgBuffer, 0);
1.36      cvs       873:       MapHTMLAttribute ("unknown_attr", &attrType, NULL,
1.30      cvs       874:                        &level, context->doc);
1.37      cvs       875:       sprintf (msgBuffer, "type=%s", val);
1.30      cvs       876:       CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
                    877:                           context->doc, &currentAttribute, &lastAttrElement);
                    878:     }
                    879:   else
                    880:     {
                    881:       elType = TtaGetElementType (context->lastElement);
                    882:       if (elType.ElTypeNum != HTML_EL_Input)
                    883:        {
1.37      cvs       884:          sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.30      cvs       885:          XmlParseError (errorParsing, msgBuffer, 0);
                    886:        }
                    887:       else
                    888:        {
                    889:          elType.ElTypeNum = value;
                    890:          newChild = TtaNewTree (context->doc, elType, "");
                    891:          XmlSetElemLineNumber (newChild);
                    892:          TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
                    893:          if (value == HTML_EL_PICTURE_UNIT)
                    894:            {
                    895:              /* add the attribute IsInput to input pictures */
                    896:              attrType.AttrSSchema = elType.ElSSchema;
                    897:              attrType.AttrTypeNum = HTML_ATTR_IsInput;
                    898:              attr = TtaNewAttribute (attrType);
                    899:              TtaAttachAttribute (newChild, attr, context->doc);
                    900:            }
                    901:        }
                    902:     }
                    903: }
                    904: 
                    905: /*----------------------------------------------------------------------
                    906:    CreateAttrWidthPercentPxl
                    907:    an HTML attribute "width" has been created for a Table of a HR.
                    908:    Create the corresponding attribute IntWidthPercent or IntWidthPxl.
                    909:    oldWidth is -1 or the old image width.
                    910:   ----------------------------------------------------------------------*/
1.58      vatton    911: void CreateAttrWidthPercentPxl (char *buffer, Element el,
                    912:                                Document doc, int oldWidth)
1.30      cvs       913: {
                    914:   AttributeType   attrTypePxl, attrTypePercent;
                    915:   Attribute       attrOld, attrNew;
                    916:   int             length, val;
1.39      cvs       917:   char            msgBuffer[MaxMsgLength];
1.30      cvs       918:   ElementType    elType;
                    919:   int             w, h;
                    920:   ThotBool        isImage;
                    921: 
                    922:   elType = TtaGetElementType (el);
                    923:   isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
                    924:             elType.ElTypeNum == HTML_EL_Data_cell ||
                    925:             elType.ElTypeNum == HTML_EL_Heading_cell);
                    926: 
                    927:   /* remove trailing spaces */
1.37      cvs       928:   length = strlen (buffer) - 1;
1.30      cvs       929:   while (length > 0 && buffer[length] <= SPACE)
                    930:     length--;
                    931:   attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc);
                    932:   attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc);
                    933:   attrTypePxl.AttrTypeNum = HTML_ATTR_IntWidthPxl;
                    934:   attrTypePercent.AttrTypeNum = HTML_ATTR_IntWidthPercent;
                    935:   /* is the last character a '%' ? */
                    936:   if (buffer[length] == '%')
                    937:     {
                    938:       /* remove IntWidthPxl */
                    939:       attrOld = TtaGetAttribute (el, attrTypePxl);
                    940:       /* update IntWidthPercent */
                    941:       attrNew = TtaGetAttribute (el, attrTypePercent);
                    942:       if (attrNew == NULL)
                    943:        {
                    944:          attrNew = TtaNewAttribute (attrTypePercent);
                    945:          TtaAttachAttribute (el, attrNew, doc);
                    946:        }
                    947:       else if (isImage && oldWidth == -1)
                    948:        {
                    949:          if (attrOld == NULL)
                    950:            oldWidth = TtaGetAttributeValue (attrNew);
                    951:          else
                    952:            oldWidth = TtaGetAttributeValue (attrOld);
                    953:        }
                    954:     }
                    955:   else
                    956:     {
                    957:       /* remove IntWidthPercent */
                    958:       attrOld = TtaGetAttribute (el, attrTypePercent);
                    959:       /* update IntWidthPxl */
                    960:       attrNew = TtaGetAttribute (el, attrTypePxl);
                    961:       if (attrNew == NULL)
                    962:        {
                    963:          attrNew = TtaNewAttribute (attrTypePxl);
                    964:          TtaAttachAttribute (el, attrNew, doc);
                    965:        }
                    966:       else if (isImage && oldWidth == -1)
                    967:        {
                    968:          TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
                    969:          if (attrOld == NULL)
                    970:            oldWidth = w * TtaGetAttributeValue (attrNew) / 100;
                    971:          else
                    972:            oldWidth = w * TtaGetAttributeValue (attrOld) / 100;          
                    973:        }
                    974:     }
                    975: 
                    976:   if (attrOld != NULL)
                    977:     TtaRemoveAttribute (el, attrOld, doc);
1.43      cvs       978:   if (sscanf (buffer, "%d", &val))
1.30      cvs       979:     TtaSetAttributeValue (attrNew, val, el, doc);
                    980:   else
                    981:     /* its not a number. Delete attribute and send an error message */
                    982:     {
                    983:     TtaRemoveAttribute (el, attrNew, doc);
1.37      cvs       984:     if (strlen (buffer) > MaxMsgLength - 30)
1.30      cvs       985:         buffer[MaxMsgLength - 30] = EOS;
1.37      cvs       986:     sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.42      cvs       987:     HTMLParseError (doc, msgBuffer);
1.30      cvs       988:     }
                    989:   if (isImage)
                    990:     UpdateImageMap (el, doc, oldWidth, -1);
                    991: }
                    992: 
                    993: /*----------------------------------------------------------------------
1.58      vatton    994:    CreateAttrHeightPercentPxl
                    995:    an HTML attribute "width" has been created for a Table of a HR.
                    996:    Create the corresponding attribute IntHeightPercent or IntHeightPxl.
                    997:    oldHeight is -1 or the old image width.
                    998:   ----------------------------------------------------------------------*/
                    999: void CreateAttrHeightPercentPxl (char *buffer, Element el,
                   1000:                                Document doc, int oldHeight)
                   1001: {
                   1002:   AttributeType   attrTypePxl, attrTypePercent;
                   1003:   Attribute       attrOld, attrNew;
                   1004:   int             length, val;
                   1005:   char            msgBuffer[MaxMsgLength];
                   1006:   ElementType    elType;
                   1007:   int             w, h;
                   1008:   ThotBool        isImage;
                   1009: 
                   1010:   elType = TtaGetElementType (el);
                   1011:   isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
                   1012:             elType.ElTypeNum == HTML_EL_Data_cell ||
                   1013:             elType.ElTypeNum == HTML_EL_Heading_cell);
                   1014: 
                   1015:   /* remove trailing spaces */
                   1016:   length = strlen (buffer) - 1;
                   1017:   while (length > 0 && buffer[length] <= SPACE)
                   1018:     length--;
                   1019:   attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc);
                   1020:   attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc);
                   1021:   attrTypePxl.AttrTypeNum = HTML_ATTR_IntHeightPxl;
                   1022:   attrTypePercent.AttrTypeNum = HTML_ATTR_IntHeightPercent;
                   1023:   /* is the last character a '%' ? */
                   1024:   if (buffer[length] == '%')
                   1025:     {
                   1026:       /* remove IntHeightPxl */
                   1027:       attrOld = TtaGetAttribute (el, attrTypePxl);
                   1028:       /* update IntHeightPercent */
                   1029:       attrNew = TtaGetAttribute (el, attrTypePercent);
                   1030:       if (attrNew == NULL)
                   1031:        {
                   1032:          attrNew = TtaNewAttribute (attrTypePercent);
                   1033:          TtaAttachAttribute (el, attrNew, doc);
                   1034:        }
                   1035:       else if (isImage && oldHeight == -1)
                   1036:        {
                   1037:          if (attrOld == NULL)
                   1038:            oldHeight = TtaGetAttributeValue (attrNew);
                   1039:          else
                   1040:            oldHeight = TtaGetAttributeValue (attrOld);
                   1041:        }
                   1042:     }
                   1043:   else
                   1044:     {
                   1045:       /* remove IntHeightPercent */
                   1046:       attrOld = TtaGetAttribute (el, attrTypePercent);
                   1047:       /* update IntHeightPxl */
                   1048:       attrNew = TtaGetAttribute (el, attrTypePxl);
                   1049:       if (attrNew == NULL)
                   1050:        {
                   1051:          attrNew = TtaNewAttribute (attrTypePxl);
                   1052:          TtaAttachAttribute (el, attrNew, doc);
                   1053:        }
                   1054:       else if (isImage && oldHeight == -1)
                   1055:        {
                   1056:          TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
                   1057:          if (attrOld == NULL)
                   1058:            oldHeight = w * TtaGetAttributeValue (attrNew) / 100;
                   1059:          else
                   1060:            oldHeight = w * TtaGetAttributeValue (attrOld) / 100;         
                   1061:        }
                   1062:     }
                   1063: 
                   1064:   if (attrOld != NULL)
                   1065:     TtaRemoveAttribute (el, attrOld, doc);
                   1066:   if (sscanf (buffer, "%d", &val))
                   1067:     TtaSetAttributeValue (attrNew, val, el, doc);
                   1068:   else
                   1069:     /* its not a number. Delete attribute and send an error message */
                   1070:     {
                   1071:     TtaRemoveAttribute (el, attrNew, doc);
                   1072:     if (strlen (buffer) > MaxMsgLength - 30)
                   1073:         buffer[MaxMsgLength - 30] = EOS;
                   1074:     sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
                   1075:     HTMLParseError (doc, msgBuffer);
                   1076:     }
                   1077:   if (isImage)
                   1078:     UpdateImageMap (el, doc, oldHeight, -1);
                   1079: }
                   1080: 
                   1081: /*----------------------------------------------------------------------
1.30      cvs      1082:    CreateAttrIntSize
                   1083:    an HTML attribute "size" has been created for a Font element.
                   1084:    Create the corresponding internal attribute.
                   1085:   ----------------------------------------------------------------------*/
1.46      cvs      1086: void              CreateAttrIntSize (char *buffer, Element el, Document doc)
1.30      cvs      1087: 
                   1088: {
                   1089:    AttributeType  attrType;
                   1090:    int            val, ind, factor, delta;
                   1091:    Attribute      attr;
1.37      cvs      1092:    char         msgBuffer[MaxMsgLength];
1.30      cvs      1093: 
                   1094:    /* is the first character a '+' or a '-' ? */
                   1095:    ind = 0;
                   1096:    factor = 1;
                   1097:    delta = 0;
                   1098:    if (buffer[0] == '+')
                   1099:      {
                   1100:        attrType.AttrTypeNum = HTML_ATTR_IntSizeIncr;
                   1101:        ind++;
                   1102:        factor = 2;
                   1103:      }
                   1104:    else if (buffer[0] == '-')
                   1105:      {
                   1106:        attrType.AttrTypeNum = HTML_ATTR_IntSizeDecr;
                   1107:        ind++;
                   1108:        factor = 2;
                   1109:      }
                   1110:    else
                   1111:      {
                   1112:        attrType.AttrTypeNum = HTML_ATTR_IntSizeRel;
                   1113:        delta = 1;
                   1114:      }
                   1115:    attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
                   1116:    attr = TtaGetAttribute (el, attrType);
1.43      cvs      1117:    if (sscanf (&buffer[ind], "%d", &val))
1.30      cvs      1118:      {
                   1119:        val = val * factor + delta;
                   1120:        if (attr == NULL)
                   1121:         {
                   1122:           /* this attribute doesn't exist, create it */
                   1123:           attr = TtaNewAttribute (attrType);
                   1124:           TtaAttachAttribute (el, attr, doc);
                   1125:         }
                   1126:        TtaSetAttributeValue (attr, val, el, doc);
                   1127:      }
                   1128:    else
                   1129:      /* its not a number. Delete attribute and send an error message */
                   1130:      {
                   1131:        if (attr)
                   1132:          TtaRemoveAttribute (el, attr, doc);
1.37      cvs      1133:        if (strlen (buffer) > MaxMsgLength - 30)
1.30      cvs      1134:          buffer[MaxMsgLength - 30] = EOS;
1.37      cvs      1135:        sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.42      cvs      1136:        HTMLParseError (doc, msgBuffer);
1.30      cvs      1137:      }
                   1138: }
                   1139: /*----------------------------------------------------------------------
                   1140:    EndOfHTMLAttributeValue
                   1141:    Filling of an HTML attribute value
                   1142:   ----------------------------------------------------------------------*/
1.48      vatton   1143: void EndOfHTMLAttributeValue (char *attrValue,
                   1144:                              AttributeMapping *lastMappedAttr,
                   1145:                              Attribute currentAttribute,
                   1146:                              Element lastAttrElement,
                   1147:                              ThotBool UnknownAttr,
                   1148:                              ParserData *context,
                   1149:                              ThotBool isXML)
1.30      cvs      1150: {
1.48      vatton   1151:   AttributeType   attrType, attrType1;
                   1152:   Attribute       attr;
                   1153:   ElementType     elType;
                   1154:   Element         child, root;
                   1155:   Language        lang;
                   1156:   char            translation;
                   1157:   char            shape;
                   1158:   char           *buffer;
                   1159:   char           *attrName;
                   1160:   char            msgBuffer[MaxMsgLength];
                   1161:   int             val;
                   1162:   int             length;
                   1163:   int             attrKind;
                   1164:   ThotBool        done = FALSE;
1.30      cvs      1165: 
1.48      vatton   1166:   /* treatments of some particular HTML attributes */
                   1167:   if (!strcmp (lastMappedAttr->XMLattribute, "style"))
                   1168:     {
                   1169:       TtaSetAttributeText (currentAttribute, attrValue,
                   1170:                           lastAttrElement, context->doc);
                   1171:       ParseHTMLSpecificStyle (context->lastElement, attrValue,
1.61      quint    1172:                              context->doc, 100, FALSE);
1.48      vatton   1173:       done = TRUE;
                   1174:     }
                   1175:   else
                   1176:     {
                   1177:       if (!strcmp (lastMappedAttr->XMLattribute, "link"))
                   1178:        HTMLSetAlinkColor (context->doc, attrValue);
                   1179:       else if (!strcmp (lastMappedAttr->XMLattribute, "alink"))
                   1180:        HTMLSetAactiveColor (context->doc, attrValue);
                   1181:       else if (!strcmp (lastMappedAttr->XMLattribute, "vlink"))
                   1182:        HTMLSetAvisitedColor (context->doc, attrValue);
                   1183:     }
1.30      cvs      1184: 
1.48      vatton   1185:   if (!done)
                   1186:     {
                   1187:       val = 0;
                   1188:       translation = lastMappedAttr->AttrOrContent;
                   1189:       switch (translation)
                   1190:        {
                   1191:        case 'C':       /* Content */
                   1192:          child = PutInContent (attrValue, context);
                   1193:          if (child != NULL)
                   1194:            TtaAppendTextContent (child, "\" ", context->doc);
                   1195:          break;
                   1196:          
                   1197:        case 'A':
                   1198:          if (currentAttribute != NULL)
                   1199:            {
                   1200:              TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
                   1201:              switch (attrKind)
                   1202:                {
                   1203:                case 0: /* enumerate */
                   1204:                  if (isXML)
                   1205:                    MapHTMLAttributeValue (attrValue, attrType, &val);
                   1206:                  else
                   1207:                    val = MapAttrValue (lastMappedAttr->ThotAttribute,
1.40      cvs      1208:                                        attrValue);
1.48      vatton   1209:                  if (val < 0)
                   1210:                    {
                   1211:                      TtaGiveAttributeType (currentAttribute,
                   1212:                                            &attrType, &attrKind);
                   1213:                      attrName = TtaGetAttributeName (attrType);
                   1214:                      sprintf (msgBuffer,
1.51      cvs      1215:                               "Invalid attribute value \"%s = %s\"",
1.48      vatton   1216:                               attrName, attrValue);
                   1217:                      if (isXML)
                   1218:                        XmlParseError (errorParsing, msgBuffer, 0);
                   1219:                      else
1.51      cvs      1220:                        {
                   1221:                          HTMLParseError (context->doc, msgBuffer);
1.48      vatton   1222:                      /* remove the attribute and replace it by an */
1.51      cvs      1223:                      /* Invalid_attribute (not for XHTML) */
                   1224:                          TtaRemoveAttribute (lastAttrElement,
                   1225:                                              currentAttribute, context->doc);
1.48      vatton   1226:                          attrType.AttrSSchema = 
                   1227:                            TtaGetDocumentSSchema (context->doc);
                   1228:                          attrType.AttrTypeNum =
                   1229:                            pHTMLAttributeMapping[0].ThotAttribute;
1.51      cvs      1230:                          sprintf (msgBuffer, "%s=%s", attrName, attrValue);
                   1231:                          CreateHTMLAttribute (lastAttrElement, attrType,
                   1232:                                               msgBuffer, TRUE, context->doc,
                   1233:                                               &currentAttribute,
                   1234:                                               &lastAttrElement);
1.48      vatton   1235:                        }
                   1236:                    }
                   1237:                  else
                   1238:                    TtaSetAttributeValue (currentAttribute, val,
                   1239:                                          lastAttrElement, context->doc);
                   1240:                  break;
                   1241:                case 1: /* integer */
                   1242:                  if (attrType.AttrTypeNum == HTML_ATTR_Border &&
                   1243:                      !strcasecmp (attrValue, "border"))
                   1244:                    {
                   1245:                      /* border="border" for a table */
                   1246:                      val = 1;
                   1247:                      TtaSetAttributeValue (currentAttribute, val,
1.30      cvs      1248:                                            lastAttrElement, context->doc);
1.48      vatton   1249:                    }
                   1250:                  else if (sscanf (attrValue, "%d", &val))
                   1251:                    TtaSetAttributeValue (currentAttribute, val,
                   1252:                                          lastAttrElement, context->doc);
                   1253:                  else
                   1254:                    {
                   1255:                      TtaRemoveAttribute (lastAttrElement, currentAttribute,
                   1256:                                          context->doc);
                   1257:                      sprintf (msgBuffer,
                   1258:                               "Unknown attribute value \"%s\"",
                   1259:                               attrValue);
                   1260:                      if (isXML)
                   1261:                        XmlParseError (errorParsing, msgBuffer, 0);
                   1262:                      else
                   1263:                        HTMLParseError (context->doc, msgBuffer);
                   1264:                    }
                   1265:                  break;
                   1266:                case 2: /* text */
                   1267:                  if (!UnknownAttr)
                   1268:                    {
                   1269:                      TtaSetAttributeText (currentAttribute, attrValue,
                   1270:                                           lastAttrElement, context->doc);
1.55      cvs      1271:                      if (attrType.AttrTypeNum == HTML_ATTR_Language)
1.48      vatton   1272:                        {
                   1273:                          /* it's a LANG attribute value */
                   1274:                          lang = TtaGetLanguageIdFromName (attrValue);
                   1275:                          if (lang == 0)
                   1276:                            {
                   1277:                              sprintf (msgBuffer,
                   1278:                                       "warning - unsupported language: %s",
                   1279:                                       attrValue);
                   1280:                              if (isXML)
                   1281:                                XmlParseError (errorParsing, msgBuffer, 0);
                   1282:                              else
                   1283:                                HTMLParseError (context->doc, msgBuffer);
                   1284:                            }
                   1285:                          else
                   1286:                            {
                   1287:                              /* change current language */
                   1288:                              context->language = lang;
                   1289:                              if (isXML)
                   1290:                                SetLanguagInXmlStack (lang);
                   1291:                              else
                   1292:                                SetLanguagInHTMLStack (lang);
                   1293:                            }
                   1294:                          root = TtaGetRootElement (context->doc);
                   1295:                          if (lastAttrElement == root)
                   1296:                            /* it's a LANG attribute on the root element */
                   1297:                            /* set the RealLang attribute */
                   1298:                            {
                   1299:                              attrType1.AttrSSchema = TtaGetDocumentSSchema (context->doc);
                   1300:                              attrType1.AttrTypeNum = HTML_ATTR_RealLang;
                   1301:                              /* this attribute could be already present,
                   1302:                                 (lang and xml:lang attributes) */
                   1303:                              if (!TtaGetAttribute (lastAttrElement,
                   1304:                                                    attrType1))
                   1305:                                /* it's not present. Add it */
                   1306:                                {
                   1307:                                  attr = TtaNewAttribute (attrType1);
                   1308:                                  TtaAttachAttribute (lastAttrElement,
                   1309:                                                      attr, context->doc);
                   1310:                                  TtaSetAttributeValue (attr,
                   1311:                                                        HTML_ATTR_RealLang_VAL_Yes_,
                   1312:                                                        lastAttrElement,
                   1313:                                                        context->doc);
                   1314:                                }
                   1315:                            }
                   1316:                        }
                   1317:                      else if (attrType.AttrTypeNum == HTML_ATTR_accesskey)
                   1318:                        TtaAddAccessKey (context->doc, (unsigned int)attrValue[0],
                   1319:                                         lastAttrElement);
                   1320:                    }
                   1321:                  else
                   1322:                    {
1.51      cvs      1323:                      /* this is the content of an invalid attribute */
                   1324:                      /* append it to the current Invalid_attribute */
                   1325:                      if (!isXML)
                   1326:                        {
                   1327:                          length = strlen (attrValue) + 2;
                   1328:                          length += TtaGetTextAttributeLength (currentAttribute);
                   1329:                          buffer = TtaGetMemory (length + 1);
                   1330:                          TtaGiveTextAttributeValue (currentAttribute,
                   1331:                                                     buffer, &length);
                   1332:                          strcat (buffer, "=");
                   1333:                          strcat (buffer, attrValue);
                   1334:                          TtaSetAttributeText (currentAttribute, buffer,
                   1335:                                               lastAttrElement, context->doc);
                   1336:                          TtaFreeMemory (buffer);
                   1337:                        }
1.48      vatton   1338:                    }
                   1339:                  break;
                   1340:                case 3: /* reference */
                   1341:                  break;
                   1342:                }
                   1343:            }
                   1344:          break;
                   1345:          
                   1346:        case SPACE:
                   1347:          if (isXML)
                   1348:            XhtmlTypeAttrValue (attrValue, currentAttribute,
1.30      cvs      1349:                                lastAttrElement, context);
1.48      vatton   1350:          else
                   1351:            HTMLTypeAttrValue (attrValue, currentAttribute,
                   1352:                               lastAttrElement, context);
                   1353:          break;
                   1354:          
1.30      cvs      1355:         default:
                   1356:           break;
1.48      vatton   1357:        }
1.30      cvs      1358: 
                   1359:       if (lastMappedAttr->ThotAttribute == HTML_ATTR_Width__)
1.48      vatton   1360:        /* HTML attribute "width" for a table or a hr */
                   1361:        /* create the corresponding attribute IntWidthPercent or */
                   1362:        /* IntWidthPxl */
                   1363:        CreateAttrWidthPercentPxl (attrValue, lastAttrElement, context->doc, -1);
1.58      vatton   1364:       else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Height_)
                   1365:        /* HTML attribute "width" for a table or a hr */
                   1366:        /* create the corresponding attribute IntHeightPercent or */
                   1367:        /* IntHeightPxl */
                   1368:        CreateAttrHeightPercentPxl (attrValue, lastAttrElement, context->doc, -1);
1.48      vatton   1369:       else if (!strcmp (lastMappedAttr->XMLattribute, "size"))
                   1370:        {
                   1371:          TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
                   1372:          if (attrType.AttrTypeNum == HTML_ATTR_Font_size)
                   1373:            CreateAttrIntSize (attrValue, lastAttrElement, context->doc);
                   1374:        }
                   1375:       else if (!strcmp (lastMappedAttr->XMLattribute, "shape"))
                   1376:        {
                   1377:          child = TtaGetFirstChild (lastAttrElement);
                   1378:          if (child != NULL)
                   1379:            {
                   1380:              switch (val)
                   1381:                {
                   1382:                case HTML_ATTR_shape_VAL_rectangle:
                   1383:                  shape = 'R';
                   1384:                  break;
                   1385:                case HTML_ATTR_shape_VAL_circle:
                   1386:                  shape = 'a';
                   1387:                  break;
                   1388:                case HTML_ATTR_shape_VAL_polygon:
                   1389:                  shape = 'p';
                   1390:                  break;
                   1391:                default:
                   1392:                  shape = SPACE;
                   1393:                  break;
                   1394:                }
                   1395:              TtaSetGraphicsShape (child, shape, context->doc);
                   1396:            }
                   1397:        }
                   1398:       else if (!strcmp (lastMappedAttr->XMLattribute, "value"))
                   1399:        {
                   1400:          elType = TtaGetElementType (lastAttrElement);
                   1401:          if (elType.ElTypeNum == HTML_EL_Text_Input ||
                   1402:              elType.ElTypeNum == HTML_EL_Password_Input ||
                   1403:              elType.ElTypeNum == HTML_EL_File_Input ||
                   1404:              elType.ElTypeNum == HTML_EL_Input)
                   1405:            /* create a Default_Value attribute with the same content */
                   1406:            {
                   1407:              attrType1.AttrSSchema = attrType.AttrSSchema;
                   1408:              attrType1.AttrTypeNum = HTML_ATTR_Default_Value;
                   1409:              attr = TtaNewAttribute (attrType1);
                   1410:              TtaAttachAttribute (lastAttrElement, attr, context->doc);
                   1411:              TtaSetAttributeText (attr, attrValue,
                   1412:                                   lastAttrElement, context->doc);
                   1413:            }
                   1414:        }
1.30      cvs      1415:       else
1.48      vatton   1416:        {
                   1417:          /* Some HTML attributes are equivalent to a CSS property:      */
                   1418:          /*      background     ->                   background         */
                   1419:          /*      bgcolor        ->                   background         */
                   1420:          /*      text           ->                   color              */
                   1421:          /*      color          ->                   color              */
                   1422:          if (!strcmp (lastMappedAttr->XMLattribute, "background"))
                   1423:            {
                   1424:              if (strlen (attrValue) > MaxMsgLength - 30)
                   1425:                attrValue[MaxMsgLength - 30] = EOS;
                   1426:              HTMLSetBackgroundImage (context->doc,
                   1427:                                      context->lastElement, STYLE_REPEAT, attrValue);
                   1428:            }
                   1429:          else if (!strcmp (lastMappedAttr->XMLattribute, "bgcolor"))
                   1430:            HTMLSetBackgroundColor (context->doc,
                   1431:                                    context->lastElement, attrValue);
                   1432:          else if (!strcmp (lastMappedAttr->XMLattribute, "text") ||
                   1433:                   !strcmp (lastMappedAttr->XMLattribute, "color"))
                   1434:            HTMLSetForegroundColor (context->doc,
                   1435:                                    context->lastElement, attrValue);
                   1436:        }
                   1437:     }
1.30      cvs      1438: }
                   1439: 
                   1440: /*----------------------------------------------------------------------
1.16      cvs      1441:    MapHTMLAttributeValue
1.2       cvs      1442:    Search in the Attribute Value Mapping Table the entry for the attribute
1.66      vatton   1443:    ThotAtt and its value attVal. Returns the corresponding Thot value.
1.1       cvs      1444:   ----------------------------------------------------------------------*/
1.66      vatton   1445: void MapHTMLAttributeValue (char *attVal, AttributeType attrType, int *value)
1.1       cvs      1446: {
1.66      vatton   1447:   MapXMLAttributeValue (XHTML_TYPE, attVal, attrType, value);
1.1       cvs      1448: }

Webmaster