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

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

Webmaster