Annotation of Amaya/amaya/fetchXMLname.c, revision 1.79

1.1       cvs         1: /*
                      2:  *
1.75      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: /*
                      9:  *
                     10:  * fetchXMLname
                     11:  *
1.46      cvs        12:  * Authors: I. Vatton
                     13:  *          L. Carcone
1.1       cvs        14:  *
                     15:  */
                     16: 
                     17: #define THOT_EXPORT extern
                     18: #include "amaya.h"
                     19: #include "parser.h"
1.24      cvs        20: #include "HTMLnames.h"
                     21: #include "MathMLnames.h"
1.49      vatton     22: #include "SVGnames.h"
1.24      cvs        23: #include "XLinknames.h"
1.77      tollenae   24: #include "Templatename.h"
1.24      cvs        25: 
1.35      cvs        26: /* define some pointers to let other parser functions access the local table */
1.24      cvs        27: int               HTML_ENTRIES = (sizeof(XHTMLElemMappingTable) / sizeof(ElemMapping));
                     28: ElemMapping      *pHTMLGIMapping = XHTMLElemMappingTable;
                     29: AttributeMapping *pHTMLAttributeMapping = XHTMLAttributeMappingTable;
1.14      cvs        30: 
1.35      cvs        31: XmlEntity        *pXhtmlEntityTable = XhtmlEntityTable;
                     32: XmlEntity        *pMathEntityTable = MathEntityTable;
1.1       cvs        33: 
                     34: #include "fetchXMLname_f.h"
                     35: 
1.39      cvs        36: /* Global variables used by the entity mapping */
                     37: static int        XHTMLSup = 0;
                     38: static int        MathSup = 0;
                     39: 
1.1       cvs        40: /*----------------------------------------------------------------------
1.14      cvs        41:    GetXHTMLSSchema returns the XHTML Thot schema for document doc.
                     42:   ----------------------------------------------------------------------*/
1.55      vatton     43: SSchema GetXHTMLSSchema (Document doc)
1.14      cvs        44: {
                     45:   SSchema      XHTMLSSchema;
                     46: 
1.43      cvs        47:    XHTMLSSchema = TtaGetSSchema ("HTML", doc);
1.14      cvs        48:    if (XHTMLSSchema == NULL)
1.72      quint      49:      XHTMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), NULL,
1.46      cvs        50:                                   "HTML", "HTMLP");
1.14      cvs        51:    return (XHTMLSSchema);
                     52: }
                     53: 
1.54      cvs        54: /*----------------------------------------------------------------------
1.1       cvs        55:    GetMathMLSSchema returns the MathML Thot schema for document doc.
                     56:   ----------------------------------------------------------------------*/
1.55      vatton     57: SSchema GetMathMLSSchema (Document doc)
1.1       cvs        58: {
                     59:   SSchema      MathMLSSchema;
                     60: 
1.43      cvs        61:   MathMLSSchema = TtaGetSSchema ("MathML", doc);
1.13      cvs        62:   if (MathMLSSchema == NULL)
1.17      cvs        63:      MathMLSSchema = TtaNewNature(doc, 
1.72      quint      64:                                  TtaGetDocumentSSchema(doc), NULL,
1.46      cvs        65:                                  "MathML", "MathMLP");
1.13      cvs        66:   return (MathMLSSchema);
1.1       cvs        67: }
                     68: 
                     69: /*----------------------------------------------------------------------
1.49      vatton     70:    GetSVGSSchema returns the SVG Thot schema for document doc.
1.1       cvs        71:   ----------------------------------------------------------------------*/
1.55      vatton     72: SSchema GetSVGSSchema (Document doc)
1.1       cvs        73: 
                     74: {
1.49      vatton     75:   SSchema      SVGSSchema;
1.1       cvs        76: 
1.49      vatton     77:   SVGSSchema = TtaGetSSchema ("SVG", doc);
                     78:   if (SVGSSchema == NULL)
1.72      quint      79:     SVGSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), NULL,
                     80:                              "SVG", "SVGP");
1.49      vatton     81:   return (SVGSSchema);
1.1       cvs        82: }
                     83: 
                     84: /*----------------------------------------------------------------------
1.13      cvs        85:    GetXLinkSSchema returns the XLink Thot schema for document doc.
                     86:   ----------------------------------------------------------------------*/
1.55      vatton     87: SSchema GetXLinkSSchema (Document doc)
1.13      cvs        88: 
                     89: {
                     90:   SSchema      XLinkSSchema;
                     91: 
1.43      cvs        92:   XLinkSSchema = TtaGetSSchema ("XLink", doc);
1.13      cvs        93:   if (XLinkSSchema == NULL)
1.72      quint      94:     XLinkSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), NULL,
1.46      cvs        95:                                "XLink", "XLinkP");
1.13      cvs        96:   return (XLinkSSchema);
                     97: }
                     98: 
1.76      tollenae   99: /* --------------------------------------------------------------------
                    100:    GetTemplateSSchema returns the Template Thot schema for document doc.
                    101:    --------------------------------------------------------------------*/
                    102: 
                    103: SSchema GetTemplateSSchema (Document doc)
                    104: {
                    105:   SSchema       TemplateSSchema;
                    106:   
                    107:   TemplateSSchema = TtaGetSSchema ("Template",doc);
                    108:   if (TemplateSSchema == NULL)
                    109:     TemplateSSchema = TtaNewNature (doc, TtaGetDocumentSSchema(doc), NULL,
                    110:                                    "Template", "TemplateP");
                    111:   
                    112:   return (TemplateSSchema);
                    113: }
                    114:     
                    115: 
                    116: 
1.13      cvs       117: /*----------------------------------------------------------------------
1.57      kahan     118:    GetTextSSchema returns the TextFile Thot schema for document doc.
                    119:    (this is not XML, but its useful to have this function here).
                    120:   ----------------------------------------------------------------------*/
1.66      vatton    121: SSchema GetTextSSchema (Document doc)
1.57      kahan     122: 
                    123: {
                    124:   SSchema      XLinkSSchema;
                    125: 
                    126:   XLinkSSchema = TtaGetSSchema ("TextFile", doc);
                    127:   if (XLinkSSchema == NULL)
1.72      quint     128:     XLinkSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), NULL,
1.57      kahan     129:                                "TextFile", "TextFileP");
                    130:   return (XLinkSSchema);
                    131: }
                    132: 
1.61      cvs       133: /*----------------------------------------------------------------------
                    134:    GetGenericXMLSSchema
                    135:    Returns the XML Thot schema of name schemaName for the document doc.
                    136:   ----------------------------------------------------------------------*/
                    137: SSchema GetGenericXMLSSchema (char *schemaName, Document doc)
                    138: 
                    139: {
                    140:   SSchema      XMLSSchema;
                    141: 
                    142:   XMLSSchema = TtaGetSSchema (schemaName, doc);
                    143:   if (XMLSSchema == NULL)
1.72      quint     144:     XMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), NULL,
                    145:                              "XML", "XMLP");
1.61      cvs       146:   return (XMLSSchema);
                    147: }
1.57      kahan     148: 
                    149: /*----------------------------------------------------------------------
1.61      cvs       150:    GetGenericXMLSSchemaByUri
                    151:    Returns the XML Thot schema for the document doc.
1.46      cvs       152:   ----------------------------------------------------------------------*/
1.55      vatton    153: SSchema GetGenericXMLSSchemaByUri (char *uriName, Document doc, ThotBool *isnew)
1.46      cvs       154: 
                    155: {
                    156:   SSchema      XMLSSchema;
                    157: 
1.73      cvs       158:   if (uriName == NULL)
                    159:     XMLSSchema = NULL;
                    160:   else
                    161:     XMLSSchema = TtaGetSSchemaByUri (uriName, doc);
                    162: 
1.46      cvs       163:   if (XMLSSchema == NULL)
                    164:     {
1.72      quint     165:       XMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), uriName,
1.46      cvs       166:                                "XML", "XMLP");
                    167:       *isnew = TRUE;
                    168:     }
                    169:   return (XMLSSchema);
                    170: }
                    171: 
1.76      tollenae  172: 
1.46      cvs       173: /*----------------------------------------------------------------------
1.13      cvs       174:    GetXMLSSchema returns the XML Thot schema for document doc.
1.1       cvs       175:   ----------------------------------------------------------------------*/
1.45      cvs       176: SSchema GetXMLSSchema (int XMLtype, Document doc)
1.38      cvs       177: 
1.1       cvs       178: {
1.14      cvs       179:   if (XMLtype == XHTML_TYPE)
                    180:     return GetXHTMLSSchema (doc);
                    181:   else if (XMLtype == MATH_TYPE)
1.13      cvs       182:     return GetMathMLSSchema (doc);
1.51      cvs       183:   else if (XMLtype == SVG_TYPE)
1.49      vatton    184:     return GetSVGSSchema (doc);
1.13      cvs       185:   else if (XMLtype == XLINK_TYPE)
1.15      cvs       186:     return GetXLinkSSchema (doc);
1.78      cvs       187:   else if (XMLtype == Template_TYPE)
                    188:     return GetTemplateSSchema (doc);
1.13      cvs       189:   else
                    190:     return NULL;
1.1       cvs       191: }
                    192: 
                    193: /*----------------------------------------------------------------------
1.22      cvs       194:   MapXMLElementType
                    195:   Generic function which searchs in the Element Mapping table, selected
                    196:   by the parameter XMLtype, the entry XMLname and returns the corresponding
                    197:   Thot element type.
1.55      vatton    198:   Returns:
1.22      cvs       199:     - ElTypeNum and ElSSchema into elType  ElTypeNum = 0 if not found.
1.55      vatton    200:     - content information about this entry
                    201:     - checkProfile TRUE if the entry is valid for the current Doc profile.
1.1       cvs       202:   ----------------------------------------------------------------------*/
1.55      vatton    203: void MapXMLElementType (int XMLtype, char *XMLname, ElementType *elType,
                    204:                        char **mappedName, char *content,
                    205:                        ThotBool *checkProfile, Document doc)
1.1       cvs       206: {
1.56      vatton    207:   ElemMapping        *ptr;
                    208:   char                c;
1.66      vatton    209:   int                 i, profile;
1.68      vatton    210:   ThotBool            xmlformat;
1.1       cvs       211: 
1.56      vatton    212:   /* Initialize variables */
                    213:   *mappedName = NULL;
                    214:   *checkProfile = TRUE;
                    215:   elType->ElTypeNum = 0;
1.66      vatton    216:   profile = TtaGetDocumentProfile (doc);
1.70      vatton    217:   if (profile == L_Annot)
                    218:     profile = L_Other;
1.68      vatton    219:   /* case sensitive comparison for xml documents */
                    220:   xmlformat = (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat);
                    221: 
1.56      vatton    222:   /* Select the right table */
                    223:   if (XMLtype == XHTML_TYPE)
1.69      vatton    224:     {
                    225:       ptr = XHTMLElemMappingTable;
                    226:       /* no case sensitive whent there is an explicit "text/html" content_type */
                    227:       if (xmlformat && DocumentMeta[doc] && DocumentMeta[doc]->content_type &&
                    228:          !strcmp (DocumentMeta[doc]->content_type, "text/html"))
                    229:        xmlformat = FALSE;
                    230:     }
1.56      vatton    231:   else if (XMLtype == MATH_TYPE)
                    232:     {
1.66      vatton    233:       if (profile == L_Basic && DocumentTypes[doc] == docHTML)
1.56      vatton    234:        {
                    235:          /* Maths are not allowed in this document */
                    236:          ptr = NULL;
                    237:          *checkProfile = FALSE;
                    238:        }
                    239:       else
                    240:        ptr = MathMLElemMappingTable;
                    241:     }
                    242:   else if (XMLtype == SVG_TYPE)
                    243:     {
1.66      vatton    244:       if (profile == L_Basic && DocumentTypes[doc] == docHTML)
1.56      vatton    245:        {
                    246:          /* Graphics are not allowed in this document */
                    247:          ptr = NULL;
                    248:          *checkProfile = FALSE;
                    249:        }
                    250:       else
                    251:        ptr = SVGElemMappingTable;
                    252:     }
1.77      tollenae  253:   else if (XMLtype == Template_TYPE)
                    254:     {
                    255:       if (profile == L_Basic && DocumentTypes[doc] == docHTML)
                    256:        {
                    257:          /* Graphics are not allowed in this document */
                    258:          ptr = NULL;
                    259:          *checkProfile = FALSE;
                    260:        }
                    261:       else
                    262:        ptr = TemplateElemMappingTable;
                    263:     }
1.56      vatton    264:   else
                    265:     ptr = NULL;
1.32      cvs       266:    
1.56      vatton    267:   if (ptr)
                    268:     {
                    269:       /* search in the ElemMappingTable */
                    270:       i = 0;
                    271:       /* case insensitive for HTML */
1.68      vatton    272:       if (!xmlformat && ptr == XHTMLElemMappingTable)
1.56      vatton    273:        c = tolower (XMLname[0]);
                    274:       else
                    275:        c = XMLname[0];
                    276:       /* look for the first concerned entry in the table */
                    277:       while (ptr[i].XMLname[0] < c && ptr[i].XMLname[0] != EOS)
                    278:        i++;     
                    279:       /* look at all entries starting with the right character */
                    280:       do
1.68      vatton    281:        if (!xmlformat && ptr == XHTMLElemMappingTable &&
                    282:            strcasecmp (ptr[i].XMLname, XMLname))
1.56      vatton    283:          /* it's not the tag */
                    284:          i++;
1.68      vatton    285:        else if ((xmlformat || ptr != XHTMLElemMappingTable) &&
                    286:                 strcmp (ptr[i].XMLname, XMLname))
1.56      vatton    287:          /* it's not the tag */
                    288:          i++;
1.66      vatton    289:        else if (profile != L_Other && !(ptr[i].Level & profile))
1.56      vatton    290:          {
                    291:            /* this tag is not valid in the document profile */
                    292:            *checkProfile = FALSE;
                    293:            i++;
                    294:          }
                    295:        else
                    296:          {
                    297:            elType->ElTypeNum = ptr[i].ThotType;
                    298:            if (elType->ElSSchema == NULL)
1.77      tollenae  299:              {
                    300:                if (XMLtype == Template_TYPE)
                    301:                    elType->ElSSchema = GetTemplateSSchema(doc);
                    302:                else
                    303:                  elType->ElSSchema = GetXMLSSchema (XMLtype, doc);
                    304:              }
1.56      vatton    305:            *mappedName = ptr[i].XMLname;
                    306:            *content = ptr[i].XMLcontents;
                    307:          }
                    308:       while (elType->ElTypeNum <= 0 && ptr[i].XMLname[0] == c);
                    309:     }
1.1       cvs       310: }
                    311: 
                    312: 
                    313: /*----------------------------------------------------------------------
                    314:    GetXMLElementName
1.52      cvs       315:    Generic function which searchs in the mapping tables the XML name for
1.22      cvs       316:    a given Thot type.
1.1       cvs       317:   ----------------------------------------------------------------------*/
1.55      vatton    318: char *GetXMLElementName (ElementType elType, Document doc)
1.1       cvs       319: {
1.46      cvs       320:   ElemMapping  *ptr;
                    321:   char         *name;
1.66      vatton    322:   int           i, profile;
1.46      cvs       323:   ThotBool      invalid = FALSE;
1.27      cvs       324: 
                    325:   if (elType.ElTypeNum > 0)
                    326:     {
                    327:       i = 0;
                    328:       /* Select the table which matches with the element schema */
                    329:       name = TtaGetSSchemaName (elType.ElSSchema);
1.44      cvs       330:       if (strcmp ("MathML", name) == 0)
1.27      cvs       331:        ptr = MathMLElemMappingTable;
1.49      vatton    332:       else if (strcmp ("SVG", name) == 0)
                    333:        ptr = SVGElemMappingTable;
1.63      quint     334:       else if (strcmp ("HTML", name) == 0)
                    335:        ptr = XHTMLElemMappingTable;
1.27      cvs       336:       else
1.63      quint     337:        ptr = NULL;
                    338: 
1.66      vatton    339:       profile = TtaGetDocumentProfile (doc);
1.70      vatton    340:       if (profile == L_Annot)
                    341:        profile = L_Other;
1.27      cvs       342:       if (ptr)
                    343:        do
                    344:          {
                    345:            if (ptr[i].ThotType == elType.ElTypeNum)
                    346:              {
1.37      cvs       347:                if (doc == 0 || 
1.66      vatton    348:                    profile == L_Other || (ptr[i].Level & profile))
1.27      cvs       349:                  return ptr[i].XMLname;
                    350:                else
                    351:                  invalid = TRUE;
                    352:              }
                    353:            i++;
                    354:          }
1.44      cvs       355:        while (ptr[i].XMLname[0] != EOS);         
1.27      cvs       356:     }
                    357:   if (invalid)
1.43      cvs       358:     return "";
1.27      cvs       359:   else
1.43      cvs       360:     return "???";
1.22      cvs       361: }
1.25      cvs       362: 
                    363: 
1.29      cvs       364: 
                    365: /*----------------------------------------------------------------------
1.30      cvs       366:    IsXMLElementInline
1.52      cvs       367:    Generic function which searchs in the mapping tables if a given
1.29      cvs       368:    Thot type is an inline character or not
                    369:   ----------------------------------------------------------------------*/
1.55      vatton    370: ThotBool IsXMLElementInline (ElementType elType, Document doc)
1.29      cvs       371: {
1.34      cvs       372:   int            i;
                    373:   ThotBool       ret = FALSE;
1.45      cvs       374:   char          *name;
1.34      cvs       375:   ElemMapping   *ptr;
1.29      cvs       376: 
                    377:   if (elType.ElTypeNum > 0)
                    378:     {
                    379:       i = 0;
                    380:       /* Select the table which matches with the element schema */
                    381:       name = TtaGetSSchemaName (elType.ElSSchema);
1.44      cvs       382:       if (strcmp ("MathML", name) == 0)
1.29      cvs       383:        ptr = MathMLElemMappingTable;
1.49      vatton    384:       else if (strcmp ("SVG", name) == 0)
                    385:        ptr = SVGElemMappingTable;
1.52      cvs       386:       else if (strcmp ("HTML", name) == 0)
                    387:        ptr = XHTMLElemMappingTable;
1.29      cvs       388:       else
1.52      cvs       389:        ptr = NULL;
1.29      cvs       390:       
                    391:       if (ptr)
                    392:        {
1.44      cvs       393:          while (ptr[i].XMLname[0] != EOS &&
1.29      cvs       394:                 ptr[i].ThotType != elType.ElTypeNum)
                    395:            i++;
                    396:          if (ptr[i].ThotType == elType.ElTypeNum)
1.58      quint     397:            ret = ptr[i].InlineElem;
1.29      cvs       398:        }
                    399:     }
                    400:   return ret;
                    401: }
                    402: 
1.22      cvs       403: /*----------------------------------------------------------------------
1.59      vatton    404:    MapMathMLAttributeValue
                    405:    Search in the Attribute Value Mapping Table the entry for the attribute
                    406:    ThotAtt and its value attVal. Returns the corresponding Thot value.
                    407:   ----------------------------------------------------------------------*/
1.64      gully     408: void MapXMLAttributeValue (int XMLtype, char *attVal, const AttributeType *attrType,
1.59      vatton    409:                              int *value)
                    410: {
                    411:   AttrValueMapping   *ptr;
                    412:   int                 i;
                    413: 
                    414:   /* Select the right table */
                    415:   if (XMLtype == XHTML_TYPE)
1.60      vatton    416:     ptr = XhtmlAttrValueMappingTable;
1.59      vatton    417:   else if (XMLtype == MATH_TYPE)
                    418:     ptr = MathMLAttrValueMappingTable;
                    419:   else if (XMLtype == SVG_TYPE)
1.60      vatton    420:     ptr = SVGAttrValueMappingTable;
1.59      vatton    421:   else
                    422:     ptr = NULL;
                    423:   
                    424:   *value = 0;
                    425:   i = 0;
                    426:   if (ptr == NULL)
                    427:     return;
1.64      gully     428:   while (ptr[i].ThotAttr != attrType->AttrTypeNum && ptr[i].ThotAttr != 0)
1.59      vatton    429:     i++;
1.64      gully     430:   if (ptr[i].ThotAttr == attrType->AttrTypeNum)
1.59      vatton    431:     do
                    432:       if (!strcmp (ptr[i].XMLattrValue, attVal))
                    433:        *value = ptr[i].ThotAttrValue;
                    434:       else
                    435:        i++;
1.64      gully     436:     while (*value == 0 && ptr[i].ThotAttr == attrType->AttrTypeNum);
1.59      vatton    437: }
                    438: 
                    439: 
                    440: /*----------------------------------------------------------------------
1.24      cvs       441:    MapXMLAttribute
1.22      cvs       442:    Generic function which searchs in the Attribute Mapping Table (table)
                    443:    the entry attrName associated to the element elementName.
1.24      cvs       444:    Returns the corresponding entry or -1.
1.22      cvs       445:   ----------------------------------------------------------------------*/
1.55      vatton    446: int MapXMLAttribute (int XMLtype, char *attrName, char *elementName,
                    447:                     ThotBool *checkProfile, Document doc, int *thotType)
1.22      cvs       448: {
1.56      vatton    449:   AttributeMapping   *ptr;
                    450:   char                c;
1.66      vatton    451:   int                 i, profile;
1.68      vatton    452:   ThotBool            xmlformat;
1.24      cvs       453: 
1.33      cvs       454:   /* Initialization */
1.55      vatton    455:   *checkProfile = TRUE;
1.33      cvs       456:   i = 1;
                    457:   *thotType = 0;
1.68      vatton    458:   /* case sensitive comparison for xml documents */
                    459:   xmlformat = (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat);
1.50      cvs       460:   
                    461:   /* Select the right table */
                    462:   if (XMLtype == XHTML_TYPE)
1.69      vatton    463:     {
                    464:       ptr = XHTMLAttributeMappingTable;
                    465:       /* no case sensitive whent there is an explicit "text/html" content_type */
                    466:       if (xmlformat && DocumentMeta[doc] && DocumentMeta[doc]->content_type &&
                    467:          !strcmp (DocumentMeta[doc]->content_type, "text/html"))
                    468:        xmlformat = FALSE;
                    469:     }
1.50      cvs       470:   else if (XMLtype == MATH_TYPE)
                    471:     ptr = MathMLAttributeMappingTable;
1.51      cvs       472:   else if (XMLtype == SVG_TYPE)
1.50      cvs       473:     ptr = SVGAttributeMappingTable;
1.79    ! tollenae  474: #ifdef TEMPLATES
        !           475:   else if (XMLtype == Template_TYPE)
        !           476:     ptr = TemplateAttributeMappingTable;
        !           477: #endif /* TEMPLATES */
1.50      cvs       478:   else if (XMLtype == XLINK_TYPE)
                    479:     ptr = XLinkAttributeMappingTable;
1.79    ! tollenae  480: 
1.50      cvs       481:   else
                    482:     ptr = NULL;
1.24      cvs       483:   if (ptr == NULL)
                    484:     return -1;
1.50      cvs       485:   if (strcmp (attrName, "unknown_attr") == 0)
                    486:     {
                    487:       *thotType = ptr[0].ThotAttribute;
                    488:       return 0;
                    489:     }
1.22      cvs       490: 
1.56      vatton    491:   /* case insensitive for HTML */
1.68      vatton    492:   if (!xmlformat && ptr == XHTMLAttributeMappingTable)
1.56      vatton    493:     c = tolower (attrName[0]);
                    494:   else
                    495:     c = attrName[0];
1.66      vatton    496: 
                    497:   profile = TtaGetDocumentProfile (doc);
1.70      vatton    498:   if (profile == L_Annot)
                    499:     profile = L_Other;
1.22      cvs       500:   /* look for the first concerned entry in the table */
1.56      vatton    501:   while (ptr[i].XMLattribute[0] < c &&  ptr[i].XMLattribute[0] != EOS)
1.22      cvs       502:     i++;
1.56      vatton    503:   while (ptr[i].XMLattribute[0] == c)
1.22      cvs       504:     {
1.68      vatton    505:       if (!xmlformat && ptr == XHTMLAttributeMappingTable &&
1.56      vatton    506:          (strcasecmp (ptr[i].XMLattribute, attrName) ||
1.74      vatton    507:           (ptr[i].XMLelement[0] != EOS && elementName &&
1.56      vatton    508:            strcasecmp (ptr[i].XMLelement, elementName))))
                    509:        i++;
1.68      vatton    510:       else if ((xmlformat || ptr != XHTMLAttributeMappingTable) &&
1.56      vatton    511:          (strcmp (ptr[i].XMLattribute, attrName) ||
1.74      vatton    512:           (ptr[i].XMLelement[0] != EOS && elementName &&
1.56      vatton    513:            strcmp (ptr[i].XMLelement, elementName))))
1.22      cvs       514:        i++;
1.66      vatton    515:       else if (profile != L_Other && !(ptr[i].Level & profile))
1.33      cvs       516:        {
1.55      vatton    517:          *checkProfile = FALSE;
1.33      cvs       518:          i++;
                    519:        }
1.22      cvs       520:       else
1.24      cvs       521:        {
1.67      cvs       522:          /* Special case for the 'name' attribute for 
                    523:             elements 'a' and 'map' in xhtml1.1 profile */
                    524:          if ((profile == L_Xhtml11) &&
1.74      vatton    525:              !strcmp (attrName, "name") && elementName &&
1.67      cvs       526:              (!strcmp (elementName, "a") || !strcmp (elementName, "map")))
                    527:            *checkProfile = FALSE;
                    528:          else
                    529:            *thotType = ptr[i].ThotAttribute;
1.24      cvs       530:          return (i);
                    531:        }
1.22      cvs       532:     }
1.24      cvs       533:   return (-1);
1.25      cvs       534: }
                    535: 
                    536: 
                    537: /*----------------------------------------------------------------------
1.37      cvs       538:    GetXMLAttributeName
1.52      cvs       539:    Generic function which searchs in the mapping tables the XML name for
1.25      cvs       540:    a given Thot type.
                    541:   ----------------------------------------------------------------------*/
1.55      vatton    542: char *GetXMLAttributeName (AttributeType attrType, ElementType elType,
                    543:                           Document doc)
1.25      cvs       544: {
                    545:   AttributeMapping   *ptr;
1.45      cvs       546:   char               *name, *tag;
1.66      vatton    547:   int                 i, profile;
1.27      cvs       548:   ThotBool            invalid = FALSE;
1.25      cvs       549: 
1.27      cvs       550:   if (attrType.AttrTypeNum > 0)
                    551:     {
1.28      cvs       552:       /* get the specific element tag */
                    553:       if (elType.ElTypeNum > 0)
                    554:        tag = GetXMLElementName (elType, doc);
                    555:       else
1.43      cvs       556:        tag = "";
1.28      cvs       557: 
1.27      cvs       558:       i = 0;
                    559:       /* Select the table which matches with the element schema */
                    560:       name = TtaGetSSchemaName (attrType.AttrSSchema);
1.44      cvs       561:       if (strcmp ("MathML", name) == 0)
1.79    ! tollenae  562:         ptr = MathMLAttributeMappingTable;
        !           563: #ifdef _SVG
1.49      vatton    564:       else if (strcmp ("SVG", name) == 0)
1.79    ! tollenae  565:         ptr = SVGAttributeMappingTable;
        !           566: #endif /* _SVG */
1.44      cvs       567:       else if (strcmp ("XLink", name) == 0)
1.79    ! tollenae  568:         ptr = XLinkAttributeMappingTable;
        !           569: #ifdef TEMPLATES
        !           570:       else if (strcmp ("Template",name) == 0)
        !           571:         ptr = TemplateAttributeMappingTable;
        !           572: #endif /* TEMPLATES */
1.27      cvs       573:       else
                    574:        ptr = XHTMLAttributeMappingTable;
                    575:       
1.66      vatton    576:       profile = TtaGetDocumentProfile (doc);
1.70      vatton    577:       if (profile == L_Annot)
                    578:        profile = L_Other;
1.27      cvs       579:       if (ptr)
                    580:        do
                    581:          {
1.28      cvs       582:            if (ptr[i].ThotAttribute == attrType.AttrTypeNum &&
1.44      cvs       583:                (ptr[i].XMLelement[0] == EOS ||
                    584:                 !strcmp (ptr[i].XMLelement, tag)))
1.25      cvs       585:              {
1.48      cvs       586:                if (doc != 0 &&
1.66      vatton    587:                    profile != L_Other &&
                    588:                    !(ptr[i].Level & profile))
1.48      cvs       589:                  invalid = TRUE;
                    590:                else
1.25      cvs       591:                  return ptr[i].XMLattribute;
                    592:              }
                    593:            i++;
1.27      cvs       594:          }
1.44      cvs       595:        while (ptr[i].XMLattribute[0] != EOS);    
1.27      cvs       596:     }
                    597:   if (invalid)
1.43      cvs       598:     return "";
1.27      cvs       599:   else
1.43      cvs       600:     return "???";
1.36      cvs       601: }
                    602: 
                    603: /*----------------------------------------------------------------------
1.71      vatton    604:   HasADoctype returns TRUE if the document includes a DocType
                    605:   ----------------------------------------------------------------------*/
                    606: ThotBool HasADoctype (Document doc)
                    607: {
                    608:   Element         el_doc, el_doctype;
                    609:   ElementType     elType;
                    610:   char           *s;
                    611: 
                    612:   /* Look for a doctype */
                    613:   el_doc = TtaGetMainRoot (doc);
                    614:   elType = TtaGetElementType (el_doc);
                    615:   /* Search the doctype declaration according to the main schema */
                    616:   s = TtaGetSSchemaName (elType.ElSSchema);
                    617:   if (strcmp (s, "HTML") == 0)
                    618:     elType.ElTypeNum = HTML_EL_DOCTYPE;
                    619:   else if (strcmp (s, "SVG") == 0)
                    620:     elType.ElTypeNum = SVG_EL_DOCTYPE;
                    621:   else if (strcmp (s, "MathML") == 0)
                    622:     elType.ElTypeNum = MathML_EL_DOCTYPE;
                    623:   else
                    624:     elType.ElTypeNum = XML_EL_doctype;
                    625:   el_doctype = TtaSearchTypedElement (elType, SearchInTree, el_doc);
                    626:   return (el_doctype != NULL);
                    627: }
                    628: 
                    629: 
                    630: /*----------------------------------------------------------------------
1.36      cvs       631:    MapXMLEntity
                    632:    Generic function which searchs in the Entity Mapping Table (table)
                    633:    the entry entityName and give the corresponding decimal value.
                    634:    Returns FALSE if entityName is not found.
                    635:   ----------------------------------------------------------------------*/
1.71      vatton    636: ThotBool MapXMLEntity (int XMLtype, char *entityName, int *entityValue)
1.36      cvs       637: {
                    638:   XmlEntity  *ptr;
                    639:   ThotBool    found;
1.38      cvs       640:   int         inf, sup, med, rescomp;
1.36      cvs       641: 
1.38      cvs       642:   /* Initialization */
1.36      cvs       643:   found = FALSE;
1.42      cvs       644:   sup = 0;
1.36      cvs       645: 
                    646:   /* Select the right table */
                    647:   if (XMLtype == XHTML_TYPE)
1.39      cvs       648:     {
                    649:       ptr = XhtmlEntityTable;
                    650:       if (XHTMLSup == 0)
                    651:        for (XHTMLSup = 0; ptr[XHTMLSup].charCode > 0; XHTMLSup++);
                    652:       sup = XHTMLSup;
                    653:     }
1.36      cvs       654:   else if (XMLtype == MATH_TYPE)
1.39      cvs       655:     {
                    656:       ptr = MathEntityTable;
                    657:       if (MathSup == 0)
                    658:        for (MathSup = 0; ptr[MathSup].charCode > 0; MathSup++);
                    659:       sup = MathSup;
                    660:     }
1.36      cvs       661:   else
                    662:     ptr = NULL;
                    663:   
1.71      vatton    664:   if (ptr)
1.36      cvs       665:     {
1.71      vatton    666:       inf = 0;
                    667:       while (sup >= inf && !found)
                    668:        /* Dichotomic research */
1.38      cvs       669:        {
1.71      vatton    670:          med = (sup + inf) / 2;
                    671:          rescomp = strcmp (ptr[med].charName, entityName);
                    672:          if (rescomp == 0)
                    673:            {
                    674:              /* entity found */
                    675:              *entityValue = ptr[med].charCode;
                    676:              found = TRUE;
                    677:            }
1.38      cvs       678:          else
1.71      vatton    679:            {
                    680:              if (rescomp > 0)
                    681:                sup = med - 1;
                    682:              else
                    683:                inf = med + 1;
                    684:            }
1.38      cvs       685:        }
1.36      cvs       686:     }
1.38      cvs       687:   return found;
                    688:  }
1.39      cvs       689: 
                    690: /*----------------------------------------------------------------------
                    691:    MapEntityByCode
                    692:    Generic function which searchs in the Entity Mapping Table (table)
                    693:    the entry with code entityValue and give the corresponding name.
                    694:    Returns FALSE if entityValue is not found.
                    695:   ----------------------------------------------------------------------*/
1.71      vatton    696: void MapEntityByCode (int entityValue, Document doc, char **entityName)
1.39      cvs       697: {
                    698:   XmlEntity  *ptr;
                    699:   ThotBool    found;
                    700:   int         i;
                    701: 
1.71      vatton    702:   if (!HasADoctype (doc))
                    703:     ptr = NULL;
                    704:   else
                    705:     /* Select the right table */
                    706:     ptr = XhtmlEntityTable;
                    707: 
1.40      cvs       708:   if (ptr)
                    709:     {
1.41      cvs       710:       /* look for in the HTML entities table */
1.40      cvs       711:       found = FALSE;
1.41      cvs       712:       while (ptr && !found)
                    713:        {
                    714:          for (i = 0; ptr[i].charCode >= 0 && !found; i++)
                    715:            found = (ptr[i].charCode == entityValue);
1.39      cvs       716:   
1.41      cvs       717:          if (found)
                    718:            {
                    719:              /* entity value found */
                    720:              i--;
                    721:              *entityName = (char *) (ptr[i].charName);
                    722:            }
                    723:          else if (ptr != MathEntityTable)
                    724:            /* look for in the Math entities table */
                    725:            ptr = MathEntityTable;
                    726:          else
                    727:            {
                    728:              *entityName = NULL;
                    729:              ptr = NULL;
                    730:            }
1.40      cvs       731:        }
                    732:     }
1.39      cvs       733:   else
1.40      cvs       734:     *entityName = NULL;
1.39      cvs       735: }

Webmaster