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

1.1       cvs         1: /*
                      2:  *
1.65      vatton      3:  *  (c) COPYRIGHT INRIA and W3C, 1996-2004
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"
                     24: 
1.35      cvs        25: /* define some pointers to let other parser functions access the local table */
1.24      cvs        26: int               HTML_ENTRIES = (sizeof(XHTMLElemMappingTable) / sizeof(ElemMapping));
                     27: ElemMapping      *pHTMLGIMapping = XHTMLElemMappingTable;
                     28: AttributeMapping *pHTMLAttributeMapping = XHTMLAttributeMappingTable;
1.14      cvs        29: 
1.35      cvs        30: XmlEntity        *pXhtmlEntityTable = XhtmlEntityTable;
                     31: XmlEntity        *pMathEntityTable = MathEntityTable;
1.1       cvs        32: 
                     33: #include "fetchXMLname_f.h"
                     34: 
1.39      cvs        35: /* Global variables used by the entity mapping */
                     36: static int        XHTMLSup = 0;
                     37: static int        MathSup = 0;
                     38: 
1.1       cvs        39: /*----------------------------------------------------------------------
1.14      cvs        40:    GetXHTMLSSchema returns the XHTML Thot schema for document doc.
                     41:   ----------------------------------------------------------------------*/
1.55      vatton     42: SSchema GetXHTMLSSchema (Document doc)
1.14      cvs        43: {
                     44:   SSchema      XHTMLSSchema;
                     45: 
1.43      cvs        46:    XHTMLSSchema = TtaGetSSchema ("HTML", doc);
1.14      cvs        47:    if (XHTMLSSchema == NULL)
1.17      cvs        48:        XHTMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc),
1.46      cvs        49:                                   "HTML", "HTMLP");
1.14      cvs        50:    return (XHTMLSSchema);
                     51: }
                     52: 
1.54      cvs        53: /*----------------------------------------------------------------------
1.1       cvs        54:    GetMathMLSSchema returns the MathML Thot schema for document doc.
                     55:   ----------------------------------------------------------------------*/
1.55      vatton     56: SSchema GetMathMLSSchema (Document doc)
1.1       cvs        57: {
                     58:   SSchema      MathMLSSchema;
                     59: 
1.43      cvs        60:   MathMLSSchema = TtaGetSSchema ("MathML", doc);
1.13      cvs        61:   if (MathMLSSchema == NULL)
1.17      cvs        62:      MathMLSSchema = TtaNewNature(doc, 
1.46      cvs        63:                                  TtaGetDocumentSSchema(doc),
                     64:                                  "MathML", "MathMLP");
1.13      cvs        65:   return (MathMLSSchema);
1.1       cvs        66: }
                     67: 
                     68: /*----------------------------------------------------------------------
1.49      vatton     69:    GetSVGSSchema returns the SVG Thot schema for document doc.
1.1       cvs        70:   ----------------------------------------------------------------------*/
1.55      vatton     71: SSchema GetSVGSSchema (Document doc)
1.1       cvs        72: 
                     73: {
1.49      vatton     74:   SSchema      SVGSSchema;
1.1       cvs        75: 
1.49      vatton     76:   SVGSSchema = TtaGetSSchema ("SVG", doc);
                     77:   if (SVGSSchema == NULL)
                     78:     SVGSSchema = TtaNewNature(doc,
1.46      cvs        79:                                  TtaGetDocumentSSchema(doc),
1.49      vatton     80:                                  "SVG", "SVGP");
                     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.46      cvs        94:     XLinkSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc),
                     95:                                "XLink", "XLinkP");
1.13      cvs        96:   return (XLinkSSchema);
                     97: }
                     98: 
                     99: /*----------------------------------------------------------------------
1.57      kahan     100:    GetTextSSchema returns the TextFile Thot schema for document doc.
                    101:    (this is not XML, but its useful to have this function here).
                    102:   ----------------------------------------------------------------------*/
1.66    ! vatton    103: SSchema GetTextSSchema (Document doc)
1.57      kahan     104: 
                    105: {
                    106:   SSchema      XLinkSSchema;
                    107: 
                    108:   XLinkSSchema = TtaGetSSchema ("TextFile", doc);
                    109:   if (XLinkSSchema == NULL)
                    110:     XLinkSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc),
                    111:                                "TextFile", "TextFileP");
                    112:   return (XLinkSSchema);
                    113: }
                    114: 
1.61      cvs       115: /*----------------------------------------------------------------------
                    116:    GetGenericXMLSSchema
                    117:    Returns the XML Thot schema of name schemaName for the document doc.
                    118:   ----------------------------------------------------------------------*/
                    119: SSchema GetGenericXMLSSchema (char *schemaName, Document doc)
                    120: 
                    121: {
                    122:   SSchema      XMLSSchema;
                    123: 
                    124:   XMLSSchema = TtaGetSSchema (schemaName, doc);
                    125:   if (XMLSSchema == NULL)
                    126:       XMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc),
                    127:                                "XML", "XMLP");
                    128:   return (XMLSSchema);
                    129: }
1.57      kahan     130: 
                    131: /*----------------------------------------------------------------------
1.61      cvs       132:    GetGenericXMLSSchemaByUri
                    133:    Returns the XML Thot schema for the document doc.
1.46      cvs       134:   ----------------------------------------------------------------------*/
1.55      vatton    135: SSchema GetGenericXMLSSchemaByUri (char *uriName, Document doc, ThotBool *isnew)
1.46      cvs       136: 
                    137: {
                    138:   SSchema      XMLSSchema;
                    139: 
                    140:   XMLSSchema = TtaGetSSchemaByUri (uriName, doc);
                    141:   if (XMLSSchema == NULL)
                    142:     {
                    143:       XMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc),
                    144:                                "XML", "XMLP");
                    145:       *isnew = TRUE;
                    146:     }
                    147:   return (XMLSSchema);
                    148: }
                    149: 
                    150: /*----------------------------------------------------------------------
1.13      cvs       151:    GetXMLSSchema returns the XML Thot schema for document doc.
1.1       cvs       152:   ----------------------------------------------------------------------*/
1.45      cvs       153: SSchema GetXMLSSchema (int XMLtype, Document doc)
1.38      cvs       154: 
1.1       cvs       155: {
1.14      cvs       156:   if (XMLtype == XHTML_TYPE)
                    157:     return GetXHTMLSSchema (doc);
                    158:   else if (XMLtype == MATH_TYPE)
1.13      cvs       159:     return GetMathMLSSchema (doc);
1.51      cvs       160:   else if (XMLtype == SVG_TYPE)
1.49      vatton    161:     return GetSVGSSchema (doc);
1.13      cvs       162:   else if (XMLtype == XLINK_TYPE)
1.15      cvs       163:     return GetXLinkSSchema (doc);
1.13      cvs       164:   else
                    165:     return NULL;
1.1       cvs       166: }
                    167: 
                    168: /*----------------------------------------------------------------------
1.22      cvs       169:   MapXMLElementType
                    170:   Generic function which searchs in the Element Mapping table, selected
                    171:   by the parameter XMLtype, the entry XMLname and returns the corresponding
                    172:   Thot element type.
1.55      vatton    173:   Returns:
1.22      cvs       174:     - ElTypeNum and ElSSchema into elType  ElTypeNum = 0 if not found.
1.55      vatton    175:     - content information about this entry
                    176:     - checkProfile TRUE if the entry is valid for the current Doc profile.
1.1       cvs       177:   ----------------------------------------------------------------------*/
1.55      vatton    178: void MapXMLElementType (int XMLtype, char *XMLname, ElementType *elType,
                    179:                        char **mappedName, char *content,
                    180:                        ThotBool *checkProfile, Document doc)
1.1       cvs       181: {
1.56      vatton    182:   ElemMapping        *ptr;
                    183:   char                c;
1.66    ! vatton    184:   int                 i, profile;
1.1       cvs       185: 
1.56      vatton    186:   /* Initialize variables */
                    187:   *mappedName = NULL;
                    188:   *checkProfile = TRUE;
                    189:   elType->ElTypeNum = 0;
1.66    ! vatton    190:   profile = TtaGetDocumentProfile (doc);
1.56      vatton    191:   /* Select the right table */
                    192:   if (XMLtype == XHTML_TYPE)
                    193:     ptr = XHTMLElemMappingTable;
                    194:   else if (XMLtype == MATH_TYPE)
                    195:     {
1.66    ! vatton    196:       if (profile == L_Basic && DocumentTypes[doc] == docHTML)
1.56      vatton    197:        {
                    198:          /* Maths are not allowed in this document */
                    199:          ptr = NULL;
                    200:          *checkProfile = FALSE;
                    201:        }
                    202:       else
                    203:        ptr = MathMLElemMappingTable;
                    204:     }
                    205:   else if (XMLtype == SVG_TYPE)
                    206:     {
1.66    ! vatton    207:       if (profile == L_Basic && DocumentTypes[doc] == docHTML)
1.56      vatton    208:        {
                    209:          /* Graphics are not allowed in this document */
                    210:          ptr = NULL;
                    211:          *checkProfile = FALSE;
                    212:        }
                    213:       else
                    214:        ptr = SVGElemMappingTable;
                    215:     }
                    216:   else
                    217:     ptr = NULL;
1.32      cvs       218:    
1.56      vatton    219:   if (ptr)
                    220:     {
                    221:       /* search in the ElemMappingTable */
                    222:       i = 0;
                    223:       /* case insensitive for HTML */
                    224:       if (ptr == XHTMLElemMappingTable)
                    225:        c = tolower (XMLname[0]);
                    226:       else
                    227:        c = XMLname[0];
                    228:       /* look for the first concerned entry in the table */
                    229:       while (ptr[i].XMLname[0] < c && ptr[i].XMLname[0] != EOS)
                    230:        i++;     
                    231:       /* look at all entries starting with the right character */
                    232:       do
                    233:        if (ptr == XHTMLElemMappingTable && strcasecmp (ptr[i].XMLname, XMLname))
                    234:          /* it's not the tag */
                    235:          i++;
                    236:        else if (ptr != XHTMLElemMappingTable && strcmp (ptr[i].XMLname, XMLname))
                    237:          /* it's not the tag */
                    238:          i++;
1.66    ! vatton    239:        else if (profile != L_Other && !(ptr[i].Level & profile))
1.56      vatton    240:          {
                    241:            /* this tag is not valid in the document profile */
                    242:            *checkProfile = FALSE;
                    243:            i++;
                    244:          }
                    245:        else
                    246:          {
                    247:            elType->ElTypeNum = ptr[i].ThotType;
                    248:            if (elType->ElSSchema == NULL)
                    249:              elType->ElSSchema = GetXMLSSchema (XMLtype, doc);
                    250:            *mappedName = ptr[i].XMLname;
                    251:            *content = ptr[i].XMLcontents;
                    252:          }
                    253:       while (elType->ElTypeNum <= 0 && ptr[i].XMLname[0] == c);
                    254:     }
1.1       cvs       255: }
                    256: 
                    257: 
                    258: /*----------------------------------------------------------------------
                    259:    GetXMLElementName
1.52      cvs       260:    Generic function which searchs in the mapping tables the XML name for
1.22      cvs       261:    a given Thot type.
1.1       cvs       262:   ----------------------------------------------------------------------*/
1.55      vatton    263: char *GetXMLElementName (ElementType elType, Document doc)
1.1       cvs       264: {
1.46      cvs       265:   ElemMapping  *ptr;
                    266:   char         *name;
1.66    ! vatton    267:   int           i, profile;
1.46      cvs       268:   ThotBool      invalid = FALSE;
1.27      cvs       269: 
                    270:   if (elType.ElTypeNum > 0)
                    271:     {
                    272:       i = 0;
                    273:       /* Select the table which matches with the element schema */
                    274:       name = TtaGetSSchemaName (elType.ElSSchema);
1.44      cvs       275:       if (strcmp ("MathML", name) == 0)
1.27      cvs       276:        ptr = MathMLElemMappingTable;
1.49      vatton    277:       else if (strcmp ("SVG", name) == 0)
                    278:        ptr = SVGElemMappingTable;
1.63      quint     279:       else if (strcmp ("HTML", name) == 0)
                    280:        ptr = XHTMLElemMappingTable;
1.27      cvs       281:       else
1.63      quint     282:        ptr = NULL;
                    283: 
1.66    ! vatton    284:       profile = TtaGetDocumentProfile (doc);
1.27      cvs       285:       if (ptr)
                    286:        do
                    287:          {
                    288:            if (ptr[i].ThotType == elType.ElTypeNum)
                    289:              {
1.37      cvs       290:                if (doc == 0 || 
1.66    ! vatton    291:                    profile == L_Other || (ptr[i].Level & profile))
1.27      cvs       292:                  return ptr[i].XMLname;
                    293:                else
                    294:                  invalid = TRUE;
                    295:              }
                    296:            i++;
                    297:          }
1.44      cvs       298:        while (ptr[i].XMLname[0] != EOS);         
1.27      cvs       299:     }
                    300:   if (invalid)
1.43      cvs       301:     return "";
1.27      cvs       302:   else
1.43      cvs       303:     return "???";
1.22      cvs       304: }
1.25      cvs       305: 
                    306: 
1.29      cvs       307: 
                    308: /*----------------------------------------------------------------------
1.30      cvs       309:    IsXMLElementInline
1.52      cvs       310:    Generic function which searchs in the mapping tables if a given
1.29      cvs       311:    Thot type is an inline character or not
                    312:   ----------------------------------------------------------------------*/
1.55      vatton    313: ThotBool IsXMLElementInline (ElementType elType, Document doc)
1.29      cvs       314: {
1.34      cvs       315:   int            i;
                    316:   ThotBool       ret = FALSE;
1.45      cvs       317:   char          *name;
1.34      cvs       318:   ElemMapping   *ptr;
1.29      cvs       319: 
                    320:   if (elType.ElTypeNum > 0)
                    321:     {
                    322:       i = 0;
                    323:       /* Select the table which matches with the element schema */
                    324:       name = TtaGetSSchemaName (elType.ElSSchema);
1.44      cvs       325:       if (strcmp ("MathML", name) == 0)
1.29      cvs       326:        ptr = MathMLElemMappingTable;
1.49      vatton    327:       else if (strcmp ("SVG", name) == 0)
                    328:        ptr = SVGElemMappingTable;
1.52      cvs       329:       else if (strcmp ("HTML", name) == 0)
                    330:        ptr = XHTMLElemMappingTable;
1.29      cvs       331:       else
1.52      cvs       332:        ptr = NULL;
1.29      cvs       333:       
                    334:       if (ptr)
                    335:        {
1.44      cvs       336:          while (ptr[i].XMLname[0] != EOS &&
1.29      cvs       337:                 ptr[i].ThotType != elType.ElTypeNum)
                    338:            i++;
                    339:          if (ptr[i].ThotType == elType.ElTypeNum)
1.58      quint     340:            ret = ptr[i].InlineElem;
1.29      cvs       341:        }
                    342:     }
                    343:   return ret;
                    344: }
                    345: 
1.22      cvs       346: /*----------------------------------------------------------------------
1.59      vatton    347:    MapMathMLAttributeValue
                    348:    Search in the Attribute Value Mapping Table the entry for the attribute
                    349:    ThotAtt and its value attVal. Returns the corresponding Thot value.
                    350:   ----------------------------------------------------------------------*/
1.64      gully     351: void MapXMLAttributeValue (int XMLtype, char *attVal, const AttributeType *attrType,
1.59      vatton    352:                              int *value)
                    353: {
                    354:   AttrValueMapping   *ptr;
                    355:   int                 i;
                    356: 
                    357:   /* Select the right table */
                    358:   if (XMLtype == XHTML_TYPE)
1.60      vatton    359:     ptr = XhtmlAttrValueMappingTable;
1.59      vatton    360:   else if (XMLtype == MATH_TYPE)
                    361:     ptr = MathMLAttrValueMappingTable;
                    362:   else if (XMLtype == SVG_TYPE)
1.60      vatton    363:     ptr = SVGAttrValueMappingTable;
1.59      vatton    364:   else
                    365:     ptr = NULL;
                    366:   
                    367:   *value = 0;
                    368:   i = 0;
                    369:   if (ptr == NULL)
                    370:     return;
1.64      gully     371:   while (ptr[i].ThotAttr != attrType->AttrTypeNum && ptr[i].ThotAttr != 0)
1.59      vatton    372:     i++;
1.64      gully     373:   if (ptr[i].ThotAttr == attrType->AttrTypeNum)
1.59      vatton    374:     do
                    375:       if (!strcmp (ptr[i].XMLattrValue, attVal))
                    376:        *value = ptr[i].ThotAttrValue;
                    377:       else
                    378:        i++;
1.64      gully     379:     while (*value == 0 && ptr[i].ThotAttr == attrType->AttrTypeNum);
1.59      vatton    380: }
                    381: 
                    382: 
                    383: /*----------------------------------------------------------------------
1.24      cvs       384:    MapXMLAttribute
1.22      cvs       385:    Generic function which searchs in the Attribute Mapping Table (table)
                    386:    the entry attrName associated to the element elementName.
1.24      cvs       387:    Returns the corresponding entry or -1.
1.22      cvs       388:   ----------------------------------------------------------------------*/
1.55      vatton    389: int MapXMLAttribute (int XMLtype, char *attrName, char *elementName,
                    390:                     ThotBool *checkProfile, Document doc, int *thotType)
1.22      cvs       391: {
1.56      vatton    392:   AttributeMapping   *ptr;
                    393:   char                c;
1.66    ! vatton    394:   int                 i, profile;
1.24      cvs       395: 
1.33      cvs       396:   /* Initialization */
1.55      vatton    397:   *checkProfile = TRUE;
1.33      cvs       398:   i = 1;
                    399:   *thotType = 0;
1.50      cvs       400:   
                    401:   /* Select the right table */
                    402:   if (XMLtype == XHTML_TYPE)
                    403:     ptr = XHTMLAttributeMappingTable;
                    404:   else if (XMLtype == MATH_TYPE)
                    405:     ptr = MathMLAttributeMappingTable;
1.51      cvs       406:   else if (XMLtype == SVG_TYPE)
1.50      cvs       407:     ptr = SVGAttributeMappingTable;
                    408:   else if (XMLtype == XLINK_TYPE)
                    409:     ptr = XLinkAttributeMappingTable;
                    410:   else
                    411:     ptr = NULL;
                    412:   
1.24      cvs       413:   if (ptr == NULL)
                    414:     return -1;
1.50      cvs       415:   
                    416:   if (strcmp (attrName, "unknown_attr") == 0)
                    417:     {
                    418:       *thotType = ptr[0].ThotAttribute;
                    419:       return 0;
                    420:     }
1.22      cvs       421: 
1.56      vatton    422:   /* case insensitive for HTML */
                    423:   if (ptr == XHTMLAttributeMappingTable)
                    424:     c = tolower (attrName[0]);
                    425:   else
                    426:     c = attrName[0];
1.66    ! vatton    427: 
        !           428:   profile = TtaGetDocumentProfile (doc);
1.22      cvs       429:   /* look for the first concerned entry in the table */
1.56      vatton    430:   while (ptr[i].XMLattribute[0] < c &&  ptr[i].XMLattribute[0] != EOS)
1.22      cvs       431:     i++;
1.56      vatton    432:   while (ptr[i].XMLattribute[0] == c)
1.22      cvs       433:     {
1.56      vatton    434:       if (ptr == XHTMLAttributeMappingTable &&
                    435:          (strcasecmp (ptr[i].XMLattribute, attrName) ||
                    436:           (ptr[i].XMLelement[0] != EOS &&
                    437:            strcasecmp (ptr[i].XMLelement, elementName))))
                    438:        i++;
                    439:       else if (ptr != XHTMLAttributeMappingTable &&
                    440:          (strcmp (ptr[i].XMLattribute, attrName) ||
                    441:           (ptr[i].XMLelement[0] != EOS &&
                    442:            strcmp (ptr[i].XMLelement, elementName))))
1.22      cvs       443:        i++;
1.66    ! vatton    444:       else if (profile != L_Other && !(ptr[i].Level & profile))
1.33      cvs       445:        {
1.55      vatton    446:          *checkProfile = FALSE;
1.33      cvs       447:          i++;
                    448:        }
1.22      cvs       449:       else
1.24      cvs       450:        {
                    451:          *thotType = ptr[i].ThotAttribute;
                    452:          return (i);
                    453:        }
1.22      cvs       454:     }
1.24      cvs       455:   return (-1);
1.25      cvs       456: }
                    457: 
                    458: 
                    459: /*----------------------------------------------------------------------
1.37      cvs       460:    GetXMLAttributeName
1.52      cvs       461:    Generic function which searchs in the mapping tables the XML name for
1.25      cvs       462:    a given Thot type.
                    463:   ----------------------------------------------------------------------*/
1.55      vatton    464: char *GetXMLAttributeName (AttributeType attrType, ElementType elType,
                    465:                           Document doc)
1.25      cvs       466: {
                    467:   AttributeMapping   *ptr;
1.45      cvs       468:   char               *name, *tag;
1.66    ! vatton    469:   int                 i, profile;
1.27      cvs       470:   ThotBool            invalid = FALSE;
1.25      cvs       471: 
1.27      cvs       472:   if (attrType.AttrTypeNum > 0)
                    473:     {
1.28      cvs       474:       /* get the specific element tag */
                    475:       if (elType.ElTypeNum > 0)
                    476:        tag = GetXMLElementName (elType, doc);
                    477:       else
1.43      cvs       478:        tag = "";
1.28      cvs       479: 
1.27      cvs       480:       i = 0;
                    481:       /* Select the table which matches with the element schema */
                    482:       name = TtaGetSSchemaName (attrType.AttrSSchema);
1.44      cvs       483:       if (strcmp ("MathML", name) == 0)
1.27      cvs       484:        ptr = MathMLAttributeMappingTable;
1.49      vatton    485:       else if (strcmp ("SVG", name) == 0)
                    486:        ptr = SVGAttributeMappingTable;
1.44      cvs       487:       else if (strcmp ("XLink", name) == 0)
1.27      cvs       488:        ptr = XLinkAttributeMappingTable;
                    489:       else
                    490:        ptr = XHTMLAttributeMappingTable;
                    491:       
1.66    ! vatton    492:       profile = TtaGetDocumentProfile (doc);
1.27      cvs       493:       if (ptr)
                    494:        do
                    495:          {
1.28      cvs       496:            if (ptr[i].ThotAttribute == attrType.AttrTypeNum &&
1.44      cvs       497:                (ptr[i].XMLelement[0] == EOS ||
                    498:                 !strcmp (ptr[i].XMLelement, tag)))
1.25      cvs       499:              {
1.48      cvs       500:                if (doc != 0 &&
1.66    ! vatton    501:                    profile != L_Other &&
        !           502:                    !(ptr[i].Level & profile))
1.48      cvs       503:                  invalid = TRUE;
                    504:                else
1.25      cvs       505:                  return ptr[i].XMLattribute;
                    506:              }
                    507:            i++;
1.27      cvs       508:          }
1.44      cvs       509:        while (ptr[i].XMLattribute[0] != EOS);    
1.27      cvs       510:     }
                    511:   if (invalid)
1.43      cvs       512:     return "";
1.27      cvs       513:   else
1.43      cvs       514:     return "???";
1.36      cvs       515: }
                    516: 
                    517: /*----------------------------------------------------------------------
                    518:    MapXMLEntity
                    519:    Generic function which searchs in the Entity Mapping Table (table)
                    520:    the entry entityName and give the corresponding decimal value.
                    521:    Returns FALSE if entityName is not found.
                    522:   ----------------------------------------------------------------------*/
1.46      cvs       523: ThotBool      MapXMLEntity (int XMLtype, char *entityName, int *entityValue)
1.36      cvs       524: {
                    525:   XmlEntity  *ptr;
                    526:   ThotBool    found;
1.38      cvs       527:   int         inf, sup, med, rescomp;
1.36      cvs       528: 
1.38      cvs       529:   /* Initialization */
1.36      cvs       530:   found = FALSE;
1.42      cvs       531:   sup = 0;
1.36      cvs       532: 
                    533:   /* Select the right table */
                    534:   if (XMLtype == XHTML_TYPE)
1.39      cvs       535:     {
                    536:       ptr = XhtmlEntityTable;
                    537:       if (XHTMLSup == 0)
                    538:        for (XHTMLSup = 0; ptr[XHTMLSup].charCode > 0; XHTMLSup++);
                    539:       sup = XHTMLSup;
                    540:     }
1.36      cvs       541:   else if (XMLtype == MATH_TYPE)
1.39      cvs       542:     {
                    543:       ptr = MathEntityTable;
                    544:       if (MathSup == 0)
                    545:        for (MathSup = 0; ptr[MathSup].charCode > 0; MathSup++);
                    546:       sup = MathSup;
                    547:     }
1.36      cvs       548:   else
                    549:     ptr = NULL;
                    550:   
                    551:   if (ptr == NULL)
1.38      cvs       552:     return found;
                    553: 
                    554:   inf = 0;
                    555:   while (sup >= inf && !found)
                    556:     /* Dichotomic research */
1.36      cvs       557:     {
1.38      cvs       558:       med = (sup + inf) / 2;
1.44      cvs       559:       rescomp = strcmp (ptr[med].charName, entityName);
1.38      cvs       560:       if (rescomp == 0)
                    561:        {
                    562:          /* entity found */
                    563:          *entityValue = ptr[med].charCode;
                    564:          found = TRUE;
                    565:        }
                    566:       else
                    567:        {
                    568:          if (rescomp > 0)
                    569:            sup = med - 1;
                    570:          else
                    571:            inf = med + 1;
                    572:        }
1.36      cvs       573:     }
1.38      cvs       574:   return found;
                    575:  }
1.39      cvs       576: 
                    577: /*----------------------------------------------------------------------
                    578:    MapEntityByCode
                    579:    Generic function which searchs in the Entity Mapping Table (table)
                    580:    the entry with code entityValue and give the corresponding name.
                    581:    Returns FALSE if entityValue is not found.
                    582:   ----------------------------------------------------------------------*/
1.40      cvs       583: void MapEntityByCode (int entityValue, char **entityName)
1.39      cvs       584: {
                    585:   XmlEntity  *ptr;
                    586:   ThotBool    found;
                    587:   int         i;
                    588: 
                    589:   /* Select the right table */
1.40      cvs       590:   ptr = XhtmlEntityTable;
                    591:   if (ptr)
                    592:     {
1.41      cvs       593:       /* look for in the HTML entities table */
1.40      cvs       594:       found = FALSE;
1.41      cvs       595:       while (ptr && !found)
                    596:        {
                    597:          for (i = 0; ptr[i].charCode >= 0 && !found; i++)
                    598:            found = (ptr[i].charCode == entityValue);
1.39      cvs       599:   
1.41      cvs       600:          if (found)
                    601:            {
                    602:              /* entity value found */
                    603:              i--;
                    604:              *entityName = (char *) (ptr[i].charName);
                    605:            }
                    606:          else if (ptr != MathEntityTable)
                    607:            /* look for in the Math entities table */
                    608:            ptr = MathEntityTable;
                    609:          else
                    610:            {
                    611:              *entityName = NULL;
                    612:              ptr = NULL;
                    613:            }
1.40      cvs       614:        }
                    615:     }
1.39      cvs       616:   else
1.40      cvs       617:     *entityName = NULL;
1.39      cvs       618: }

Webmaster