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

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:   ----------------------------------------------------------------------*/
                    103: SSchema         GetTextSSchema (Document doc)
                    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;
                    184:   int                 i;
1.1       cvs       185: 
1.56      vatton    186:   /* Initialize variables */
                    187:   *mappedName = NULL;
                    188:   *checkProfile = TRUE;
                    189:   elType->ElTypeNum = 0;
                    190: 
                    191:   /* Select the right table */
                    192:   if (XMLtype == XHTML_TYPE)
                    193:     ptr = XHTMLElemMappingTable;
                    194:   else if (XMLtype == MATH_TYPE)
                    195:     {
                    196:       if (TtaGetDocumentProfile(doc) == L_Basic &&
                    197:          DocumentTypes[doc] == docHTML)
                    198:        {
                    199:          /* Maths are not allowed in this document */
                    200:          ptr = NULL;
                    201:          *checkProfile = FALSE;
                    202:        }
                    203:       else
                    204:        ptr = MathMLElemMappingTable;
                    205:     }
                    206:   else if (XMLtype == SVG_TYPE)
                    207:     {
                    208:       if (TtaGetDocumentProfile(doc) == L_Basic &&
                    209:          DocumentTypes[doc] == docHTML)
                    210:        {
                    211:          /* Graphics are not allowed in this document */
                    212:          ptr = NULL;
                    213:          *checkProfile = FALSE;
                    214:        }
                    215:       else
                    216:        ptr = SVGElemMappingTable;
                    217:     }
                    218:   else
                    219:     ptr = NULL;
1.32      cvs       220:    
1.56      vatton    221:   if (ptr)
                    222:     {
                    223:       /* search in the ElemMappingTable */
                    224:       i = 0;
                    225:       /* case insensitive for HTML */
                    226:       if (ptr == XHTMLElemMappingTable)
                    227:        c = tolower (XMLname[0]);
                    228:       else
                    229:        c = XMLname[0];
                    230:       /* look for the first concerned entry in the table */
                    231:       while (ptr[i].XMLname[0] < c && ptr[i].XMLname[0] != EOS)
                    232:        i++;     
                    233:       /* look at all entries starting with the right character */
                    234:       do
                    235:        if (ptr == XHTMLElemMappingTable && strcasecmp (ptr[i].XMLname, XMLname))
                    236:          /* it's not the tag */
                    237:          i++;
                    238:        else if (ptr != XHTMLElemMappingTable && strcmp (ptr[i].XMLname, XMLname))
                    239:          /* it's not the tag */
                    240:          i++;
                    241:        else if (TtaGetDocumentProfile(doc) != L_Other &&
                    242:                 !(ptr[i].Level & TtaGetDocumentProfile(doc)))
                    243:          {
                    244:            /* this tag is not valid in the document profile */
                    245:            *checkProfile = FALSE;
                    246:            i++;
                    247:          }
                    248:        else
                    249:          {
                    250:            elType->ElTypeNum = ptr[i].ThotType;
                    251:            if (elType->ElSSchema == NULL)
                    252:              elType->ElSSchema = GetXMLSSchema (XMLtype, doc);
                    253:            *mappedName = ptr[i].XMLname;
                    254:            *content = ptr[i].XMLcontents;
                    255:          }
                    256:       while (elType->ElTypeNum <= 0 && ptr[i].XMLname[0] == c);
                    257:     }
1.1       cvs       258: }
                    259: 
                    260: 
                    261: /*----------------------------------------------------------------------
                    262:    GetXMLElementName
1.52      cvs       263:    Generic function which searchs in the mapping tables the XML name for
1.22      cvs       264:    a given Thot type.
1.1       cvs       265:   ----------------------------------------------------------------------*/
1.55      vatton    266: char *GetXMLElementName (ElementType elType, Document doc)
1.1       cvs       267: {
1.46      cvs       268:   ElemMapping  *ptr;
                    269:   char         *name;
                    270:   int           i;
                    271:   ThotBool      invalid = FALSE;
1.27      cvs       272: 
                    273:   if (elType.ElTypeNum > 0)
                    274:     {
                    275:       i = 0;
                    276:       /* Select the table which matches with the element schema */
                    277:       name = TtaGetSSchemaName (elType.ElSSchema);
1.44      cvs       278:       if (strcmp ("MathML", name) == 0)
1.27      cvs       279:        ptr = MathMLElemMappingTable;
1.49      vatton    280:       else if (strcmp ("SVG", name) == 0)
                    281:        ptr = SVGElemMappingTable;
1.63      quint     282:       else if (strcmp ("HTML", name) == 0)
                    283:        ptr = XHTMLElemMappingTable;
1.27      cvs       284:       else
1.63      quint     285:        ptr = NULL;
                    286: 
1.27      cvs       287:       if (ptr)
                    288:        do
                    289:          {
                    290:            if (ptr[i].ThotType == elType.ElTypeNum)
                    291:              {
1.37      cvs       292:                if (doc == 0 || 
1.53      cvs       293:                    TtaGetDocumentProfile(doc) == L_Other ||
                    294:                    (ptr[i].Level & TtaGetDocumentProfile(doc)))
1.27      cvs       295:                  return ptr[i].XMLname;
                    296:                else
                    297:                  invalid = TRUE;
                    298:              }
                    299:            i++;
                    300:          }
1.44      cvs       301:        while (ptr[i].XMLname[0] != EOS);         
1.27      cvs       302:     }
                    303:   if (invalid)
1.43      cvs       304:     return "";
1.27      cvs       305:   else
1.43      cvs       306:     return "???";
1.22      cvs       307: }
1.25      cvs       308: 
                    309: 
1.29      cvs       310: 
                    311: /*----------------------------------------------------------------------
1.30      cvs       312:    IsXMLElementInline
1.52      cvs       313:    Generic function which searchs in the mapping tables if a given
1.29      cvs       314:    Thot type is an inline character or not
                    315:   ----------------------------------------------------------------------*/
1.55      vatton    316: ThotBool IsXMLElementInline (ElementType elType, Document doc)
1.29      cvs       317: {
1.34      cvs       318:   int            i;
                    319:   ThotBool       ret = FALSE;
1.45      cvs       320:   char          *name;
1.34      cvs       321:   ElemMapping   *ptr;
1.29      cvs       322: 
                    323:   if (elType.ElTypeNum > 0)
                    324:     {
                    325:       i = 0;
                    326:       /* Select the table which matches with the element schema */
                    327:       name = TtaGetSSchemaName (elType.ElSSchema);
1.44      cvs       328:       if (strcmp ("MathML", name) == 0)
1.29      cvs       329:        ptr = MathMLElemMappingTable;
1.49      vatton    330:       else if (strcmp ("SVG", name) == 0)
                    331:        ptr = SVGElemMappingTable;
1.52      cvs       332:       else if (strcmp ("HTML", name) == 0)
                    333:        ptr = XHTMLElemMappingTable;
1.29      cvs       334:       else
1.52      cvs       335:        ptr = NULL;
1.29      cvs       336:       
                    337:       if (ptr)
                    338:        {
1.44      cvs       339:          while (ptr[i].XMLname[0] != EOS &&
1.29      cvs       340:                 ptr[i].ThotType != elType.ElTypeNum)
                    341:            i++;
                    342:          if (ptr[i].ThotType == elType.ElTypeNum)
1.58      quint     343:            ret = ptr[i].InlineElem;
1.29      cvs       344:        }
                    345:     }
                    346:   return ret;
                    347: }
                    348: 
1.22      cvs       349: /*----------------------------------------------------------------------
1.59      vatton    350:    MapMathMLAttributeValue
                    351:    Search in the Attribute Value Mapping Table the entry for the attribute
                    352:    ThotAtt and its value attVal. Returns the corresponding Thot value.
                    353:   ----------------------------------------------------------------------*/
1.64      gully     354: void MapXMLAttributeValue (int XMLtype, char *attVal, const AttributeType *attrType,
1.59      vatton    355:                              int *value)
                    356: {
                    357:   AttrValueMapping   *ptr;
                    358:   int                 i;
                    359: 
                    360:   /* Select the right table */
                    361:   if (XMLtype == XHTML_TYPE)
1.60      vatton    362:     ptr = XhtmlAttrValueMappingTable;
1.59      vatton    363:   else if (XMLtype == MATH_TYPE)
                    364:     ptr = MathMLAttrValueMappingTable;
                    365:   else if (XMLtype == SVG_TYPE)
1.60      vatton    366:     ptr = SVGAttrValueMappingTable;
1.59      vatton    367:   else
                    368:     ptr = NULL;
                    369:   
                    370:   *value = 0;
                    371:   i = 0;
                    372:   if (ptr == NULL)
                    373:     return;
1.64      gully     374:   while (ptr[i].ThotAttr != attrType->AttrTypeNum && ptr[i].ThotAttr != 0)
1.59      vatton    375:     i++;
1.64      gully     376:   if (ptr[i].ThotAttr == attrType->AttrTypeNum)
1.59      vatton    377:     do
                    378:       if (!strcmp (ptr[i].XMLattrValue, attVal))
                    379:        *value = ptr[i].ThotAttrValue;
                    380:       else
                    381:        i++;
1.64      gully     382:     while (*value == 0 && ptr[i].ThotAttr == attrType->AttrTypeNum);
1.59      vatton    383: }
                    384: 
                    385: 
                    386: /*----------------------------------------------------------------------
1.24      cvs       387:    MapXMLAttribute
1.22      cvs       388:    Generic function which searchs in the Attribute Mapping Table (table)
                    389:    the entry attrName associated to the element elementName.
1.24      cvs       390:    Returns the corresponding entry or -1.
1.22      cvs       391:   ----------------------------------------------------------------------*/
1.55      vatton    392: int MapXMLAttribute (int XMLtype, char *attrName, char *elementName,
                    393:                     ThotBool *checkProfile, Document doc, int *thotType)
1.22      cvs       394: {
1.56      vatton    395:   AttributeMapping   *ptr;
                    396:   char                c;
                    397:   int                 i;
1.24      cvs       398: 
1.33      cvs       399:   /* Initialization */
1.55      vatton    400:   *checkProfile = TRUE;
1.33      cvs       401:   i = 1;
                    402:   *thotType = 0;
1.50      cvs       403:   
                    404:   /* Select the right table */
                    405:   if (XMLtype == XHTML_TYPE)
                    406:     ptr = XHTMLAttributeMappingTable;
                    407:   else if (XMLtype == MATH_TYPE)
                    408:     ptr = MathMLAttributeMappingTable;
1.51      cvs       409:   else if (XMLtype == SVG_TYPE)
1.50      cvs       410:     ptr = SVGAttributeMappingTable;
                    411:   else if (XMLtype == XLINK_TYPE)
                    412:     ptr = XLinkAttributeMappingTable;
                    413:   else
                    414:     ptr = NULL;
                    415:   
1.24      cvs       416:   if (ptr == NULL)
                    417:     return -1;
1.50      cvs       418:   
                    419:   if (strcmp (attrName, "unknown_attr") == 0)
                    420:     {
                    421:       *thotType = ptr[0].ThotAttribute;
                    422:       return 0;
                    423:     }
1.22      cvs       424: 
1.56      vatton    425:   /* case insensitive for HTML */
                    426:   if (ptr == XHTMLAttributeMappingTable)
                    427:     c = tolower (attrName[0]);
                    428:   else
                    429:     c = attrName[0];
1.22      cvs       430:   /* look for the first concerned entry in the table */
1.56      vatton    431:   while (ptr[i].XMLattribute[0] < c &&  ptr[i].XMLattribute[0] != EOS)
1.22      cvs       432:     i++;
1.56      vatton    433:   while (ptr[i].XMLattribute[0] == c)
1.22      cvs       434:     {
1.56      vatton    435:       if (ptr == XHTMLAttributeMappingTable &&
                    436:          (strcasecmp (ptr[i].XMLattribute, attrName) ||
                    437:           (ptr[i].XMLelement[0] != EOS &&
                    438:            strcasecmp (ptr[i].XMLelement, elementName))))
                    439:        i++;
                    440:       else if (ptr != XHTMLAttributeMappingTable &&
                    441:          (strcmp (ptr[i].XMLattribute, attrName) ||
                    442:           (ptr[i].XMLelement[0] != EOS &&
                    443:            strcmp (ptr[i].XMLelement, elementName))))
1.22      cvs       444:        i++;
1.53      cvs       445:       else if (TtaGetDocumentProfile(doc) != L_Other &&
                    446:               !(ptr[i].Level & TtaGetDocumentProfile(doc)))
1.33      cvs       447:        {
1.55      vatton    448:          *checkProfile = FALSE;
1.33      cvs       449:          i++;
                    450:        }
1.22      cvs       451:       else
1.24      cvs       452:        {
                    453:          *thotType = ptr[i].ThotAttribute;
                    454:          return (i);
                    455:        }
1.22      cvs       456:     }
1.24      cvs       457:   return (-1);
1.25      cvs       458: }
                    459: 
                    460: 
                    461: /*----------------------------------------------------------------------
1.37      cvs       462:    GetXMLAttributeName
1.52      cvs       463:    Generic function which searchs in the mapping tables the XML name for
1.25      cvs       464:    a given Thot type.
                    465:   ----------------------------------------------------------------------*/
1.55      vatton    466: char *GetXMLAttributeName (AttributeType attrType, ElementType elType,
                    467:                           Document doc)
1.25      cvs       468: {
                    469:   AttributeMapping   *ptr;
1.45      cvs       470:   char               *name, *tag;
1.25      cvs       471:   int                 i;
1.27      cvs       472:   ThotBool            invalid = FALSE;
1.25      cvs       473: 
1.27      cvs       474:   if (attrType.AttrTypeNum > 0)
                    475:     {
1.28      cvs       476:       /* get the specific element tag */
                    477:       if (elType.ElTypeNum > 0)
                    478:        tag = GetXMLElementName (elType, doc);
                    479:       else
1.43      cvs       480:        tag = "";
1.28      cvs       481: 
1.27      cvs       482:       i = 0;
                    483:       /* Select the table which matches with the element schema */
                    484:       name = TtaGetSSchemaName (attrType.AttrSSchema);
1.44      cvs       485:       if (strcmp ("MathML", name) == 0)
1.27      cvs       486:        ptr = MathMLAttributeMappingTable;
1.49      vatton    487:       else if (strcmp ("SVG", name) == 0)
                    488:        ptr = SVGAttributeMappingTable;
1.44      cvs       489:       else if (strcmp ("XLink", name) == 0)
1.27      cvs       490:        ptr = XLinkAttributeMappingTable;
                    491:       else
                    492:        ptr = XHTMLAttributeMappingTable;
                    493:       
                    494:       if (ptr)
                    495:        do
                    496:          {
1.28      cvs       497:            if (ptr[i].ThotAttribute == attrType.AttrTypeNum &&
1.44      cvs       498:                (ptr[i].XMLelement[0] == EOS ||
                    499:                 !strcmp (ptr[i].XMLelement, tag)))
1.25      cvs       500:              {
1.48      cvs       501:                if (doc != 0 &&
1.53      cvs       502:                    TtaGetDocumentProfile(doc) != L_Other &&
                    503:                    !(ptr[i].Level & TtaGetDocumentProfile(doc)))
1.48      cvs       504:                  invalid = TRUE;
                    505:                else
1.25      cvs       506:                  return ptr[i].XMLattribute;
                    507:              }
                    508:            i++;
1.27      cvs       509:          }
1.44      cvs       510:        while (ptr[i].XMLattribute[0] != EOS);    
1.27      cvs       511:     }
                    512:   if (invalid)
1.43      cvs       513:     return "";
1.27      cvs       514:   else
1.43      cvs       515:     return "???";
1.36      cvs       516: }
                    517: 
                    518: /*----------------------------------------------------------------------
                    519:    MapXMLEntity
                    520:    Generic function which searchs in the Entity Mapping Table (table)
                    521:    the entry entityName and give the corresponding decimal value.
                    522:    Returns FALSE if entityName is not found.
                    523:   ----------------------------------------------------------------------*/
1.46      cvs       524: ThotBool      MapXMLEntity (int XMLtype, char *entityName, int *entityValue)
1.36      cvs       525: {
                    526:   XmlEntity  *ptr;
                    527:   ThotBool    found;
1.38      cvs       528:   int         inf, sup, med, rescomp;
1.36      cvs       529: 
1.38      cvs       530:   /* Initialization */
1.36      cvs       531:   found = FALSE;
1.42      cvs       532:   sup = 0;
1.36      cvs       533: 
                    534:   /* Select the right table */
                    535:   if (XMLtype == XHTML_TYPE)
1.39      cvs       536:     {
                    537:       ptr = XhtmlEntityTable;
                    538:       if (XHTMLSup == 0)
                    539:        for (XHTMLSup = 0; ptr[XHTMLSup].charCode > 0; XHTMLSup++);
                    540:       sup = XHTMLSup;
                    541:     }
1.36      cvs       542:   else if (XMLtype == MATH_TYPE)
1.39      cvs       543:     {
                    544:       ptr = MathEntityTable;
                    545:       if (MathSup == 0)
                    546:        for (MathSup = 0; ptr[MathSup].charCode > 0; MathSup++);
                    547:       sup = MathSup;
                    548:     }
1.36      cvs       549:   else
                    550:     ptr = NULL;
                    551:   
                    552:   if (ptr == NULL)
1.38      cvs       553:     return found;
                    554: 
                    555:   inf = 0;
                    556:   while (sup >= inf && !found)
                    557:     /* Dichotomic research */
1.36      cvs       558:     {
1.38      cvs       559:       med = (sup + inf) / 2;
1.44      cvs       560:       rescomp = strcmp (ptr[med].charName, entityName);
1.38      cvs       561:       if (rescomp == 0)
                    562:        {
                    563:          /* entity found */
                    564:          *entityValue = ptr[med].charCode;
                    565:          found = TRUE;
                    566:        }
                    567:       else
                    568:        {
                    569:          if (rescomp > 0)
                    570:            sup = med - 1;
                    571:          else
                    572:            inf = med + 1;
                    573:        }
1.36      cvs       574:     }
1.38      cvs       575:   return found;
                    576:  }
1.39      cvs       577: 
                    578: /*----------------------------------------------------------------------
                    579:    MapEntityByCode
                    580:    Generic function which searchs in the Entity Mapping Table (table)
                    581:    the entry with code entityValue and give the corresponding name.
                    582:    Returns FALSE if entityValue is not found.
                    583:   ----------------------------------------------------------------------*/
1.40      cvs       584: void MapEntityByCode (int entityValue, char **entityName)
1.39      cvs       585: {
                    586:   XmlEntity  *ptr;
                    587:   ThotBool    found;
                    588:   int         i;
                    589: 
                    590:   /* Select the right table */
1.40      cvs       591:   ptr = XhtmlEntityTable;
                    592:   if (ptr)
                    593:     {
1.41      cvs       594:       /* look for in the HTML entities table */
1.40      cvs       595:       found = FALSE;
1.41      cvs       596:       while (ptr && !found)
                    597:        {
                    598:          for (i = 0; ptr[i].charCode >= 0 && !found; i++)
                    599:            found = (ptr[i].charCode == entityValue);
1.39      cvs       600:   
1.41      cvs       601:          if (found)
                    602:            {
                    603:              /* entity value found */
                    604:              i--;
                    605:              *entityName = (char *) (ptr[i].charName);
                    606:            }
                    607:          else if (ptr != MathEntityTable)
                    608:            /* look for in the Math entities table */
                    609:            ptr = MathEntityTable;
                    610:          else
                    611:            {
                    612:              *entityName = NULL;
                    613:              ptr = NULL;
                    614:            }
1.40      cvs       615:        }
                    616:     }
1.39      cvs       617:   else
1.40      cvs       618:     *entityName = NULL;
1.39      cvs       619: }

Webmaster