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

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.80      vatton     41:   GetXHTMLSSchema returns the XHTML Thot schema for document doc.
1.14      cvs        42:   ----------------------------------------------------------------------*/
1.55      vatton     43: SSchema GetXHTMLSSchema (Document doc)
1.14      cvs        44: {
                     45:   SSchema      XHTMLSSchema;
                     46: 
1.80      vatton     47:   XHTMLSSchema = TtaGetSSchema ("HTML", doc);
                     48:   if (XHTMLSSchema == NULL)
                     49:     XHTMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), NULL,
                     50:                                 "HTML", "HTMLP");
                     51:   return (XHTMLSSchema);
1.14      cvs        52: }
                     53: 
1.54      cvs        54: /*----------------------------------------------------------------------
1.80      vatton     55:   GetMathMLSSchema returns the MathML Thot schema for document doc.
1.1       cvs        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.80      vatton     63:     MathMLSSchema = TtaNewNature(doc, 
                     64:                                  TtaGetDocumentSSchema(doc), NULL,
                     65:                                  "MathML", "MathMLP");
1.13      cvs        66:   return (MathMLSSchema);
1.1       cvs        67: }
                     68: 
                     69: /*----------------------------------------------------------------------
1.80      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,
1.80      vatton     80:                               "SVG", "SVGP");
1.49      vatton     81:   return (SVGSSchema);
1.1       cvs        82: }
                     83: 
                     84: /*----------------------------------------------------------------------
1.80      vatton     85:   GetXLinkSSchema returns the XLink Thot schema for document doc.
1.13      cvs        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.80      vatton     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,
1.80      vatton    110:                                     "Template", "TemplateP");
1.76      tollenae  111:   
                    112:   return (TemplateSSchema);
                    113: }
                    114:     
                    115: 
                    116: 
1.13      cvs       117: /*----------------------------------------------------------------------
1.80      vatton    118:   GetTextSSchema returns the TextFile Thot schema for document doc.
                    119:   (this is not XML, but its useful to have this function here).
1.57      kahan     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.80      vatton    129:                                 "TextFile", "TextFileP");
1.57      kahan     130:   return (XLinkSSchema);
                    131: }
                    132: 
1.61      cvs       133: /*----------------------------------------------------------------------
1.80      vatton    134:   GetGenericXMLSSchema
                    135:   Returns the XML Thot schema of name schemaName for the document doc.
1.61      cvs       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,
1.80      vatton    145:                               "XML", "XMLP");
1.61      cvs       146:   return (XMLSSchema);
                    147: }
1.57      kahan     148: 
                    149: /*----------------------------------------------------------------------
1.80      vatton    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.80      vatton    166:                                 "XML", "XMLP");
1.46      cvs       167:       *isnew = TRUE;
                    168:     }
                    169:   return (XMLSSchema);
                    170: }
                    171: 
1.76      tollenae  172: 
1.46      cvs       173: /*----------------------------------------------------------------------
1.80      vatton    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: 
1.82      vatton    193: /*--------------------------------------------------------------------------
                    194:   HasNatures
                    195:   Check if there are MathML and/or SVG natures
                    196:   --------------------------------------------------------------------------*/
                    197: void HasNatures (Document document, ThotBool *useMathML, ThotBool *useSVG)
                    198: {
                    199:   SSchema         nature;
                    200:   char           *ptr;
                    201: 
                    202:   /* look for a MathML or SVG nature within the document */
                    203:   nature = NULL;
                    204:   *useMathML = FALSE;
                    205:   *useSVG = FALSE;
1.83      vatton    206:   if (DocumentMeta[document] && DocumentMeta[document]->compound)
                    207:     do
                    208:       {
                    209:         TtaNextNature (document, &nature);
                    210:         if (nature)
                    211:           {
                    212:             ptr = TtaGetSSchemaName (nature);
                    213:             if (!strcmp (ptr, "MathML"))
                    214:               *useMathML = TRUE;
                    215:             if (!strcmp (ptr, "SVG"))
                    216:               *useSVG = TRUE;
                    217:           }
                    218:       }
                    219:     while (nature);
1.82      vatton    220: }
                    221: 
1.1       cvs       222: /*----------------------------------------------------------------------
1.22      cvs       223:   MapXMLElementType
                    224:   Generic function which searchs in the Element Mapping table, selected
                    225:   by the parameter XMLtype, the entry XMLname and returns the corresponding
                    226:   Thot element type.
1.88      kia       227:   If SSchema is specified (not NULL)in elType, only it is searched.
1.55      vatton    228:   Returns:
1.80      vatton    229:   - ElTypeNum and ElSSchema into elType  ElTypeNum = 0 if not found.
                    230:   - content information about this entry
                    231:   - checkProfile TRUE if the entry is valid for the current Doc profile.
1.1       cvs       232:   ----------------------------------------------------------------------*/
1.55      vatton    233: void MapXMLElementType (int XMLtype, char *XMLname, ElementType *elType,
1.80      vatton    234:                         char **mappedName, char *content,
                    235:                         ThotBool *checkProfile, Document doc)
1.1       cvs       236: {
1.56      vatton    237:   ElemMapping        *ptr;
                    238:   char                c;
1.66      vatton    239:   int                 i, profile;
1.68      vatton    240:   ThotBool            xmlformat;
1.1       cvs       241: 
1.56      vatton    242:   /* Initialize variables */
                    243:   *mappedName = NULL;
                    244:   *checkProfile = TRUE;
                    245:   elType->ElTypeNum = 0;
1.66      vatton    246:   profile = TtaGetDocumentProfile (doc);
1.70      vatton    247:   if (profile == L_Annot)
                    248:     profile = L_Other;
1.68      vatton    249:   /* case sensitive comparison for xml documents */
                    250:   xmlformat = (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat);
                    251: 
1.56      vatton    252:   /* Select the right table */
                    253:   if (XMLtype == XHTML_TYPE)
1.69      vatton    254:     {
                    255:       ptr = XHTMLElemMappingTable;
                    256:       /* no case sensitive whent there is an explicit "text/html" content_type */
                    257:       if (xmlformat && DocumentMeta[doc] && DocumentMeta[doc]->content_type &&
1.80      vatton    258:           !strcmp (DocumentMeta[doc]->content_type, "text/html"))
                    259:         xmlformat = FALSE;
1.69      vatton    260:     }
1.56      vatton    261:   else if (XMLtype == MATH_TYPE)
                    262:     {
1.66      vatton    263:       if (profile == L_Basic && DocumentTypes[doc] == docHTML)
1.80      vatton    264:         {
                    265:           /* Maths are not allowed in this document */
                    266:           ptr = NULL;
                    267:           *checkProfile = FALSE;
                    268:         }
1.56      vatton    269:       else
1.80      vatton    270:         ptr = MathMLElemMappingTable;
1.56      vatton    271:     }
                    272:   else if (XMLtype == SVG_TYPE)
                    273:     {
1.66      vatton    274:       if (profile == L_Basic && DocumentTypes[doc] == docHTML)
1.80      vatton    275:         {
                    276:           /* Graphics are not allowed in this document */
                    277:           ptr = NULL;
                    278:           *checkProfile = FALSE;
                    279:         }
1.56      vatton    280:       else
1.80      vatton    281:         ptr = SVGElemMappingTable;
1.56      vatton    282:     }
1.77      tollenae  283:   else if (XMLtype == Template_TYPE)
                    284:     {
                    285:       if (profile == L_Basic && DocumentTypes[doc] == docHTML)
1.80      vatton    286:         {
                    287:           /* Graphics are not allowed in this document */
                    288:           ptr = NULL;
                    289:           *checkProfile = FALSE;
                    290:         }
1.77      tollenae  291:       else
1.80      vatton    292:         ptr = TemplateElemMappingTable;
1.77      tollenae  293:     }
1.56      vatton    294:   else
                    295:     ptr = NULL;
1.32      cvs       296:    
1.56      vatton    297:   if (ptr)
                    298:     {
                    299:       /* search in the ElemMappingTable */
                    300:       i = 0;
                    301:       /* case insensitive for HTML */
1.68      vatton    302:       if (!xmlformat && ptr == XHTMLElemMappingTable)
1.80      vatton    303:         c = tolower (XMLname[0]);
1.56      vatton    304:       else
1.80      vatton    305:         c = XMLname[0];
1.56      vatton    306:       /* look for the first concerned entry in the table */
                    307:       while (ptr[i].XMLname[0] < c && ptr[i].XMLname[0] != EOS)
1.80      vatton    308:         i++;     
1.56      vatton    309:       /* look at all entries starting with the right character */
                    310:       do
1.80      vatton    311:         if (!xmlformat && ptr == XHTMLElemMappingTable &&
                    312:             strcasecmp (ptr[i].XMLname, XMLname))
                    313:           /* it's not the tag */
                    314:           i++;
                    315:         else if ((xmlformat || ptr != XHTMLElemMappingTable) &&
                    316:                  strcmp (ptr[i].XMLname, XMLname))
                    317:           /* it's not the tag */
                    318:           i++;
                    319:         else if (profile != L_Other && !(ptr[i].Level & profile))
                    320:           {
                    321:             /* this tag is not valid in the document profile */
                    322:             *checkProfile = FALSE;
                    323:             i++;
                    324:           }
                    325:         else
                    326:           {
                    327:             elType->ElTypeNum = ptr[i].ThotType;
                    328:             if (elType->ElSSchema == NULL)
                    329:               {
                    330:                 if (XMLtype == Template_TYPE)
                    331:                   elType->ElSSchema = GetTemplateSSchema(doc);
                    332:                 else
                    333:                   elType->ElSSchema = GetXMLSSchema (XMLtype, doc);
                    334:               }
                    335:             *mappedName = ptr[i].XMLname;
                    336:             *content = ptr[i].XMLcontents;
                    337:           }
1.56      vatton    338:       while (elType->ElTypeNum <= 0 && ptr[i].XMLname[0] == c);
                    339:     }
1.1       cvs       340: }
                    341: 
                    342: 
                    343: /*----------------------------------------------------------------------
1.80      vatton    344:   GetXMLElementName
                    345:   Generic function which searchs in the mapping tables the XML name for
                    346:   a given Thot type.
1.1       cvs       347:   ----------------------------------------------------------------------*/
1.55      vatton    348: char *GetXMLElementName (ElementType elType, Document doc)
1.1       cvs       349: {
1.46      cvs       350:   ElemMapping  *ptr;
                    351:   char         *name;
1.66      vatton    352:   int           i, profile;
1.46      cvs       353:   ThotBool      invalid = FALSE;
1.27      cvs       354: 
                    355:   if (elType.ElTypeNum > 0)
                    356:     {
                    357:       i = 0;
                    358:       /* Select the table which matches with the element schema */
                    359:       name = TtaGetSSchemaName (elType.ElSSchema);
1.44      cvs       360:       if (strcmp ("MathML", name) == 0)
1.80      vatton    361:         ptr = MathMLElemMappingTable;
1.49      vatton    362:       else if (strcmp ("SVG", name) == 0)
1.80      vatton    363:         ptr = SVGElemMappingTable;
1.63      quint     364:       else if (strcmp ("HTML", name) == 0)
1.80      vatton    365:         ptr = XHTMLElemMappingTable;
1.27      cvs       366:       else
1.80      vatton    367:         ptr = NULL;
1.63      quint     368: 
1.66      vatton    369:       profile = TtaGetDocumentProfile (doc);
1.70      vatton    370:       if (profile == L_Annot)
1.80      vatton    371:         profile = L_Other;
1.27      cvs       372:       if (ptr)
1.80      vatton    373:         do
                    374:           {
                    375:             if (ptr[i].ThotType == elType.ElTypeNum)
                    376:               {
                    377:                 if (doc == 0 || 
                    378:                     profile == L_Other || (ptr[i].Level & profile))
                    379:                   return ptr[i].XMLname;
                    380:                 else
                    381:                   invalid = TRUE;
                    382:               }
                    383:             i++;
                    384:           }
                    385:         while (ptr[i].XMLname[0] != EOS);        
1.27      cvs       386:     }
                    387:   if (invalid)
1.43      cvs       388:     return "";
1.27      cvs       389:   else
1.43      cvs       390:     return "???";
1.22      cvs       391: }
1.25      cvs       392: 
                    393: 
1.29      cvs       394: /*----------------------------------------------------------------------
1.80      vatton    395:   IsXMLElementInline
                    396:   Generic function which searchs in the mapping tables if a given
                    397:   Thot type is an inline character or not
1.29      cvs       398:   ----------------------------------------------------------------------*/
1.55      vatton    399: ThotBool IsXMLElementInline (ElementType elType, Document doc)
1.29      cvs       400: {
1.34      cvs       401:   int            i;
                    402:   ThotBool       ret = FALSE;
1.45      cvs       403:   char          *name;
1.34      cvs       404:   ElemMapping   *ptr;
1.29      cvs       405: 
                    406:   if (elType.ElTypeNum > 0)
                    407:     {
                    408:       i = 0;
                    409:       /* Select the table which matches with the element schema */
                    410:       name = TtaGetSSchemaName (elType.ElSSchema);
1.44      cvs       411:       if (strcmp ("MathML", name) == 0)
1.80      vatton    412:         ptr = MathMLElemMappingTable;
1.49      vatton    413:       else if (strcmp ("SVG", name) == 0)
1.80      vatton    414:         ptr = SVGElemMappingTable;
1.52      cvs       415:       else if (strcmp ("HTML", name) == 0)
1.80      vatton    416:         ptr = XHTMLElemMappingTable;
1.29      cvs       417:       else
1.80      vatton    418:         ptr = NULL;
1.29      cvs       419:       
                    420:       if (ptr)
1.80      vatton    421:         {
                    422:           while (ptr[i].XMLname[0] != EOS &&
                    423:                  ptr[i].ThotType != elType.ElTypeNum)
                    424:             i++;
                    425:           if (ptr[i].ThotType == elType.ElTypeNum)
                    426:             ret = ptr[i].InlineElem;
                    427:         }
1.29      cvs       428:     }
                    429:   return ret;
                    430: }
                    431: 
1.22      cvs       432: /*----------------------------------------------------------------------
1.85      vatton    433:   MapXMLAttributeValue
1.80      vatton    434:   Search in the Attribute Value Mapping Table the entry for the attribute
                    435:   ThotAtt and its value attVal. Returns the corresponding Thot value.
1.59      vatton    436:   ----------------------------------------------------------------------*/
1.64      gully     437: void MapXMLAttributeValue (int XMLtype, char *attVal, const AttributeType *attrType,
1.80      vatton    438:                            int *value)
1.59      vatton    439: {
                    440:   AttrValueMapping   *ptr;
                    441:   int                 i;
                    442: 
                    443:   /* Select the right table */
                    444:   if (XMLtype == XHTML_TYPE)
1.60      vatton    445:     ptr = XhtmlAttrValueMappingTable;
1.59      vatton    446:   else if (XMLtype == MATH_TYPE)
                    447:     ptr = MathMLAttrValueMappingTable;
                    448:   else if (XMLtype == SVG_TYPE)
1.60      vatton    449:     ptr = SVGAttrValueMappingTable;
1.89    ! vatton    450: #ifdef TEMPLATES
        !           451:   else if (XMLtype == Template_TYPE)
        !           452:     ptr = TemplateAttrValueMappingTable;
        !           453: #endif /* TEMPLATES */
1.59      vatton    454:   else
                    455:     ptr = NULL;
                    456:   
                    457:   *value = 0;
                    458:   i = 0;
                    459:   if (ptr == NULL)
                    460:     return;
1.64      gully     461:   while (ptr[i].ThotAttr != attrType->AttrTypeNum && ptr[i].ThotAttr != 0)
1.59      vatton    462:     i++;
1.64      gully     463:   if (ptr[i].ThotAttr == attrType->AttrTypeNum)
1.59      vatton    464:     do
                    465:       if (!strcmp (ptr[i].XMLattrValue, attVal))
1.80      vatton    466:         *value = ptr[i].ThotAttrValue;
1.59      vatton    467:       else
1.80      vatton    468:         i++;
1.64      gully     469:     while (*value == 0 && ptr[i].ThotAttr == attrType->AttrTypeNum);
1.59      vatton    470: }
                    471: 
                    472: 
                    473: /*----------------------------------------------------------------------
1.80      vatton    474:   MapXMLAttribute
                    475:   Generic function which searchs in the Attribute Mapping Table (table)
                    476:   the entry attrName associated to the element elementName.
                    477:   Returns the corresponding entry or -1.
1.22      cvs       478:   ----------------------------------------------------------------------*/
1.55      vatton    479: int MapXMLAttribute (int XMLtype, char *attrName, char *elementName,
1.80      vatton    480:                      ThotBool *checkProfile, Document doc, int *thotType)
1.22      cvs       481: {
1.56      vatton    482:   AttributeMapping   *ptr;
                    483:   char                c;
1.66      vatton    484:   int                 i, profile;
1.68      vatton    485:   ThotBool            xmlformat;
1.24      cvs       486: 
1.33      cvs       487:   /* Initialization */
1.55      vatton    488:   *checkProfile = TRUE;
1.33      cvs       489:   i = 1;
                    490:   *thotType = 0;
1.68      vatton    491:   /* case sensitive comparison for xml documents */
                    492:   xmlformat = (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat);
1.50      cvs       493:   
                    494:   /* Select the right table */
                    495:   if (XMLtype == XHTML_TYPE)
1.69      vatton    496:     {
                    497:       ptr = XHTMLAttributeMappingTable;
                    498:       /* no case sensitive whent there is an explicit "text/html" content_type */
                    499:       if (xmlformat && DocumentMeta[doc] && DocumentMeta[doc]->content_type &&
1.80      vatton    500:           !strcmp (DocumentMeta[doc]->content_type, "text/html"))
                    501:         xmlformat = FALSE;
1.69      vatton    502:     }
1.50      cvs       503:   else if (XMLtype == MATH_TYPE)
                    504:     ptr = MathMLAttributeMappingTable;
1.51      cvs       505:   else if (XMLtype == SVG_TYPE)
1.50      cvs       506:     ptr = SVGAttributeMappingTable;
1.79      tollenae  507: #ifdef TEMPLATES
                    508:   else if (XMLtype == Template_TYPE)
                    509:     ptr = TemplateAttributeMappingTable;
                    510: #endif /* TEMPLATES */
1.50      cvs       511:   else if (XMLtype == XLINK_TYPE)
                    512:     ptr = XLinkAttributeMappingTable;
1.79      tollenae  513: 
1.50      cvs       514:   else
                    515:     ptr = NULL;
1.24      cvs       516:   if (ptr == NULL)
                    517:     return -1;
1.50      cvs       518:   if (strcmp (attrName, "unknown_attr") == 0)
                    519:     {
                    520:       *thotType = ptr[0].ThotAttribute;
                    521:       return 0;
                    522:     }
1.22      cvs       523: 
1.56      vatton    524:   /* case insensitive for HTML */
1.68      vatton    525:   if (!xmlformat && ptr == XHTMLAttributeMappingTable)
1.56      vatton    526:     c = tolower (attrName[0]);
                    527:   else
                    528:     c = attrName[0];
1.66      vatton    529: 
                    530:   profile = TtaGetDocumentProfile (doc);
1.70      vatton    531:   if (profile == L_Annot)
                    532:     profile = L_Other;
1.22      cvs       533:   /* look for the first concerned entry in the table */
1.56      vatton    534:   while (ptr[i].XMLattribute[0] < c &&  ptr[i].XMLattribute[0] != EOS)
1.22      cvs       535:     i++;
1.56      vatton    536:   while (ptr[i].XMLattribute[0] == c)
1.22      cvs       537:     {
1.68      vatton    538:       if (!xmlformat && ptr == XHTMLAttributeMappingTable &&
1.80      vatton    539:           (strcasecmp (ptr[i].XMLattribute, attrName) ||
                    540:            (ptr[i].XMLelement[0] != EOS && elementName &&
                    541:             strcasecmp (ptr[i].XMLelement, elementName))))
                    542:         i++;
1.68      vatton    543:       else if ((xmlformat || ptr != XHTMLAttributeMappingTable) &&
1.80      vatton    544:                (strcmp (ptr[i].XMLattribute, attrName) ||
                    545:                 (ptr[i].XMLelement[0] != EOS && elementName &&
                    546:                  strcmp (ptr[i].XMLelement, elementName))))
                    547:         i++;
1.66      vatton    548:       else if (profile != L_Other && !(ptr[i].Level & profile))
1.80      vatton    549:         {
                    550:           *checkProfile = FALSE;
                    551:           i++;
                    552:         }
1.22      cvs       553:       else
1.80      vatton    554:         {
                    555:           /* Special case for the 'name' attribute for 
                    556:              elements 'a' and 'map' in xhtml1.1 profile */
                    557:           if ((profile == L_Xhtml11) &&
                    558:               !strcmp (attrName, "name") && elementName &&
                    559:               (!strcmp (elementName, "a") || !strcmp (elementName, "map")))
                    560:             *checkProfile = FALSE;
                    561:           else
                    562:             *thotType = ptr[i].ThotAttribute;
                    563:           return (i);
                    564:         }
1.22      cvs       565:     }
1.24      cvs       566:   return (-1);
1.25      cvs       567: }
                    568: 
                    569: 
                    570: /*----------------------------------------------------------------------
1.80      vatton    571:   GetXMLAttributeName
                    572:   Generic function which searchs in the mapping tables the XML name for
                    573:   a given Thot type.
1.25      cvs       574:   ----------------------------------------------------------------------*/
1.55      vatton    575: char *GetXMLAttributeName (AttributeType attrType, ElementType elType,
1.80      vatton    576:                            Document doc)
1.25      cvs       577: {
                    578:   AttributeMapping   *ptr;
1.45      cvs       579:   char               *name, *tag;
1.66      vatton    580:   int                 i, profile;
1.27      cvs       581:   ThotBool            invalid = FALSE;
1.25      cvs       582: 
1.27      cvs       583:   if (attrType.AttrTypeNum > 0)
                    584:     {
1.28      cvs       585:       /* get the specific element tag */
                    586:       if (elType.ElTypeNum > 0)
1.80      vatton    587:         tag = GetXMLElementName (elType, doc);
1.28      cvs       588:       else
1.80      vatton    589:         tag = "";
1.28      cvs       590: 
1.27      cvs       591:       i = 0;
                    592:       /* Select the table which matches with the element schema */
                    593:       name = TtaGetSSchemaName (attrType.AttrSSchema);
1.44      cvs       594:       if (strcmp ("MathML", name) == 0)
1.79      tollenae  595:         ptr = MathMLAttributeMappingTable;
                    596: #ifdef _SVG
1.49      vatton    597:       else if (strcmp ("SVG", name) == 0)
1.79      tollenae  598:         ptr = SVGAttributeMappingTable;
                    599: #endif /* _SVG */
1.44      cvs       600:       else if (strcmp ("XLink", name) == 0)
1.79      tollenae  601:         ptr = XLinkAttributeMappingTable;
                    602: #ifdef TEMPLATES
                    603:       else if (strcmp ("Template",name) == 0)
                    604:         ptr = TemplateAttributeMappingTable;
                    605: #endif /* TEMPLATES */
1.27      cvs       606:       else
1.80      vatton    607:         ptr = XHTMLAttributeMappingTable;
1.27      cvs       608:       
1.66      vatton    609:       profile = TtaGetDocumentProfile (doc);
1.70      vatton    610:       if (profile == L_Annot)
1.80      vatton    611:         profile = L_Other;
1.27      cvs       612:       if (ptr)
1.80      vatton    613:         do
                    614:           {
                    615:             if (ptr[i].ThotAttribute == attrType.AttrTypeNum &&
                    616:                 (ptr[i].XMLelement[0] == EOS ||
                    617:                  !strcmp (ptr[i].XMLelement, tag)))
                    618:               {
                    619:                 if (doc != 0 &&
                    620:                     profile != L_Other &&
                    621:                     !(ptr[i].Level & profile))
                    622:                   invalid = TRUE;
                    623:                 else
                    624:                   return ptr[i].XMLattribute;
                    625:               }
                    626:             i++;
                    627:           }
                    628:         while (ptr[i].XMLattribute[0] != EOS);   
1.27      cvs       629:     }
                    630:   if (invalid)
1.43      cvs       631:     return "";
1.27      cvs       632:   else
1.43      cvs       633:     return "???";
1.36      cvs       634: }
                    635: 
                    636: /*----------------------------------------------------------------------
1.71      vatton    637:   HasADoctype returns TRUE if the document includes a DocType
                    638:   ----------------------------------------------------------------------*/
1.82      vatton    639: void HasADoctype (Document doc, ThotBool *found, ThotBool *useMath)
1.71      vatton    640: {
                    641:   Element         el_doc, el_doctype;
                    642:   ElementType     elType;
                    643:   char           *s;
1.82      vatton    644:   ThotBool        useSVG;
1.71      vatton    645: 
                    646:   /* Look for a doctype */
                    647:   el_doc = TtaGetMainRoot (doc);
                    648:   elType = TtaGetElementType (el_doc);
                    649:   /* Search the doctype declaration according to the main schema */
                    650:   s = TtaGetSSchemaName (elType.ElSSchema);
                    651:   if (strcmp (s, "HTML") == 0)
                    652:     elType.ElTypeNum = HTML_EL_DOCTYPE;
                    653:   else if (strcmp (s, "SVG") == 0)
                    654:     elType.ElTypeNum = SVG_EL_DOCTYPE;
                    655:   else if (strcmp (s, "MathML") == 0)
1.81      vatton    656:     elType.ElTypeNum = MathML_EL_DOCTYPE;
1.71      vatton    657:   else
                    658:     elType.ElTypeNum = XML_EL_doctype;
                    659:   el_doctype = TtaSearchTypedElement (elType, SearchInTree, el_doc);
1.81      vatton    660:   *found = (el_doctype != NULL);
1.82      vatton    661:   HasNatures (doc, useMath, &useSVG);
1.71      vatton    662: }
                    663: 
                    664: 
                    665: /*----------------------------------------------------------------------
1.80      vatton    666:   MapXMLEntity
                    667:   Generic function which searchs in the Entity Mapping Table (table)
                    668:   the entry entityName and give the corresponding decimal value.
                    669:   Returns FALSE if entityName is not found.
1.36      cvs       670:   ----------------------------------------------------------------------*/
1.71      vatton    671: ThotBool MapXMLEntity (int XMLtype, char *entityName, int *entityValue)
1.36      cvs       672: {
                    673:   XmlEntity  *ptr;
                    674:   ThotBool    found;
1.38      cvs       675:   int         inf, sup, med, rescomp;
1.36      cvs       676: 
1.38      cvs       677:   /* Initialization */
1.36      cvs       678:   found = FALSE;
1.42      cvs       679:   sup = 0;
1.36      cvs       680: 
                    681:   /* Select the right table */
1.86      vatton    682:   if (XMLtype == XHTML_TYPE || XMLtype == Template_TYPE)
1.39      cvs       683:     {
                    684:       ptr = XhtmlEntityTable;
                    685:       if (XHTMLSup == 0)
1.80      vatton    686:         for (XHTMLSup = 0; ptr[XHTMLSup].charCode > 0; XHTMLSup++);
1.39      cvs       687:       sup = XHTMLSup;
                    688:     }
1.36      cvs       689:   else if (XMLtype == MATH_TYPE)
1.39      cvs       690:     {
                    691:       ptr = MathEntityTable;
                    692:       if (MathSup == 0)
1.80      vatton    693:         for (MathSup = 0; ptr[MathSup].charCode > 0; MathSup++);
1.39      cvs       694:       sup = MathSup;
                    695:     }
1.36      cvs       696:   else
                    697:     ptr = NULL;
                    698:   
1.71      vatton    699:   if (ptr)
1.36      cvs       700:     {
1.71      vatton    701:       inf = 0;
                    702:       while (sup >= inf && !found)
1.80      vatton    703:         /* Dichotomic research */
                    704:         {
                    705:           med = (sup + inf) / 2;
                    706:           rescomp = strcmp (ptr[med].charName, entityName);
                    707:           if (rescomp == 0)
                    708:             {
                    709:               /* entity found */
                    710:               *entityValue = ptr[med].charCode;
                    711:               found = TRUE;
                    712:             }
                    713:           else
                    714:             {
                    715:               if (rescomp > 0)
                    716:                 sup = med - 1;
                    717:               else
                    718:                 inf = med + 1;
                    719:             }
                    720:         }
1.36      cvs       721:     }
1.82      vatton    722:   if (!found && ptr == XhtmlEntityTable)
                    723:     // check MathML entities
                    724:     return MapXMLEntity (MATH_TYPE, entityName, entityValue);
1.38      cvs       725:   return found;
1.80      vatton    726: }
1.39      cvs       727: 
                    728: /*----------------------------------------------------------------------
1.80      vatton    729:   MapEntityByCode
                    730:   Generic function which searchs in the Entity Mapping Table (table)
                    731:   the entry with code entityValue and give the corresponding name.
1.81      vatton    732:   withMath is TRUE when MathML entities are accepted.
1.80      vatton    733:   Returns FALSE if entityValue is not found.
1.39      cvs       734:   ----------------------------------------------------------------------*/
1.81      vatton    735: void MapEntityByCode (int entityValue, Document doc, ThotBool withMath,
                    736:                       char **entityName)
1.39      cvs       737: {
                    738:   XmlEntity  *ptr;
1.81      vatton    739:   ThotBool    found;
1.39      cvs       740:   int         i;
                    741: 
1.81      vatton    742:   /* Select the right table */
1.87      vatton    743:   if (withMath)
                    744:     /* look for in the Math entities table */
                    745:     ptr = MathEntityTable;
                    746:   else
                    747:     ptr = XhtmlEntityTable;
1.40      cvs       748:   if (ptr)
                    749:     {
1.41      cvs       750:       /* look for in the HTML entities table */
1.40      cvs       751:       found = FALSE;
1.41      cvs       752:       while (ptr && !found)
1.80      vatton    753:         {
1.82      vatton    754:           for (i = 0; ptr[i].charCode != 0 && !found; i++)
1.80      vatton    755:             found = (ptr[i].charCode == entityValue);
1.39      cvs       756:   
1.80      vatton    757:           if (found)
                    758:             {
                    759:               /* entity value found */
                    760:               i--;
                    761:               *entityName = (char *) (ptr[i].charName);
                    762:             }
1.87      vatton    763:           else if (withMath && ptr != XhtmlEntityTable)
1.80      vatton    764:             /* look for in the Math entities table */
1.87      vatton    765:             ptr = XhtmlEntityTable;
1.80      vatton    766:           else
                    767:             {
                    768:               *entityName = NULL;
                    769:               ptr = NULL;
                    770:             }
                    771:         }
1.40      cvs       772:     }
1.39      cvs       773:   else
1.40      cvs       774:     *entityName = NULL;
1.39      cvs       775: }

Webmaster