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

1.1       cvs         1: /*
                      2:  *
1.13      cvs         3:  *  (c) COPYRIGHT MIT and INRIA, 1996-2000
1.1       cvs         4:  *  Please first read the full copyright statement in file COPYRIGHT.
                      5:  *
                      6:  */
                      7:  
                      8: /*
                      9:  *
                     10:  * fetchXMLname
                     11:  *
                     12:  * Author: I. Vatton
                     13:  *
                     14:  */
                     15: 
                     16: #define THOT_EXPORT extern
                     17: #include "amaya.h"
                     18: #include "parser.h"
1.24      cvs        19: #include "HTMLnames.h"
                     20: #include "MathMLnames.h"
                     21: #include "GraphMLnames.h"
                     22: #include "XLinknames.h"
                     23: 
1.35      cvs        24: /* define some pointers to let other parser functions access the local table */
1.24      cvs        25: int               HTML_ENTRIES = (sizeof(XHTMLElemMappingTable) / sizeof(ElemMapping));
                     26: ElemMapping      *pHTMLGIMapping = XHTMLElemMappingTable;
                     27: AttributeMapping *pHTMLAttributeMapping = XHTMLAttributeMappingTable;
1.14      cvs        28: 
1.35      cvs        29: XmlEntity        *pXhtmlEntityTable = XhtmlEntityTable;
                     30: XmlEntity        *pMathEntityTable = MathEntityTable;
1.1       cvs        31: 
                     32: #include "fetchXMLname_f.h"
                     33: 
                     34: /*----------------------------------------------------------------------
1.14      cvs        35:    GetXHTMLSSchema returns the XHTML Thot schema for document doc.
                     36:   ----------------------------------------------------------------------*/
                     37: #ifdef __STDC__
                     38: SSchema            GetXHTMLSSchema (Document doc)
                     39: #else
                     40: SSchema            GetXHTMLSSchema (doc)
                     41: Document          doc;
                     42: 
                     43: #endif
                     44: {
                     45:   SSchema      XHTMLSSchema;
                     46: 
                     47:    XHTMLSSchema = TtaGetSSchema (TEXT("HTML"), doc);
                     48:    if (XHTMLSSchema == NULL)
1.17      cvs        49:        XHTMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc),
1.14      cvs        50:                                    TEXT("HTML"), TEXT("HTMLP"));
                     51:    return (XHTMLSSchema);
                     52: }
                     53: 
                     54: /*----------------------------------------------------------------------
1.1       cvs        55:    GetMathMLSSchema returns the MathML Thot schema for document doc.
                     56:   ----------------------------------------------------------------------*/
                     57: #ifdef __STDC__
                     58: SSchema            GetMathMLSSchema (Document doc)
                     59: #else
                     60: SSchema            GetMathMLSSchema (doc)
                     61: Document          doc;
                     62: 
                     63: #endif
                     64: {
                     65:   SSchema      MathMLSSchema;
                     66: 
1.13      cvs        67:   MathMLSSchema = TtaGetSSchema (TEXT("MathML"), doc);
                     68:   if (MathMLSSchema == NULL)
1.17      cvs        69:      MathMLSSchema = TtaNewNature(doc, 
                     70:                                  TtaGetDocumentSSchema(doc), TEXT("MathML"),
1.13      cvs        71:                                  TEXT("MathMLP"));
                     72:   return (MathMLSSchema);
1.1       cvs        73: }
                     74: 
                     75: /*----------------------------------------------------------------------
                     76:    GetGraphMLSSchema returns the GraphML Thot schema for document doc.
                     77:   ----------------------------------------------------------------------*/
                     78: #ifdef __STDC__
                     79: SSchema            GetGraphMLSSchema (Document doc)
                     80: #else
                     81: SSchema            GetGraphMLSSchema (doc)
                     82: Document          doc;
                     83: 
                     84: #endif
                     85: {
                     86:   SSchema      GraphMLSSchema;
                     87: 
1.8       cvs        88:   GraphMLSSchema = TtaGetSSchema (TEXT("GraphML"), doc);
1.1       cvs        89:   if (GraphMLSSchema == NULL)
1.17      cvs        90:     GraphMLSSchema = TtaNewNature(doc,
                     91:                                  TtaGetDocumentSSchema(doc), TEXT("GraphML"),
1.13      cvs        92:                                  TEXT("GraphMLP"));
1.1       cvs        93:   return (GraphMLSSchema);
                     94: }
                     95: 
                     96: /*----------------------------------------------------------------------
1.13      cvs        97:    GetXLinkSSchema returns the XLink Thot schema for document doc.
                     98:   ----------------------------------------------------------------------*/
                     99: #ifdef __STDC__
                    100: SSchema            GetXLinkSSchema (Document doc)
                    101: #else
                    102: SSchema            GetXLinkSSchema (doc)
                    103: Document          doc;
                    104: 
                    105: #endif
                    106: {
                    107:   SSchema      XLinkSSchema;
                    108: 
                    109:   XLinkSSchema = TtaGetSSchema (TEXT("XLink"), doc);
                    110:   if (XLinkSSchema == NULL)
1.17      cvs       111:     XLinkSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), TEXT("XLink"),
1.13      cvs       112:                                TEXT("XLinkP"));
                    113:   return (XLinkSSchema);
                    114: }
                    115: 
                    116: /*----------------------------------------------------------------------
                    117:    GetXMLSSchema returns the XML Thot schema for document doc.
1.1       cvs       118:   ----------------------------------------------------------------------*/
                    119: #ifdef __STDC__
                    120: SSchema            GetXMLSSchema (int XMLtype, Document doc)
                    121: #else
                    122: SSchema            GetXMLSSchema (XMLtype, doc)
                    123: Document          doc;
                    124: int                XMLtype;
                    125: #endif
                    126: {
1.14      cvs       127:   if (XMLtype == XHTML_TYPE)
                    128:     return GetXHTMLSSchema (doc);
                    129:   else if (XMLtype == MATH_TYPE)
1.13      cvs       130:     return GetMathMLSSchema (doc);
                    131:   else if (XMLtype == GRAPH_TYPE)
                    132:     return GetGraphMLSSchema (doc);
                    133:   else if (XMLtype == XLINK_TYPE)
1.15      cvs       134:     return GetXLinkSSchema (doc);
1.13      cvs       135:   else
                    136:     return NULL;
1.1       cvs       137: }
                    138: 
                    139: 
                    140: /*----------------------------------------------------------------------
1.22      cvs       141:   MapXMLElementType
                    142:   Generic function which searchs in the Element Mapping table, selected
                    143:   by the parameter XMLtype, the entry XMLname and returns the corresponding
                    144:   Thot element type.
1.1       cvs       145:    Returns:
1.22      cvs       146:     - ElTypeNum and ElSSchema into elType  ElTypeNum = 0 if not found.
1.1       cvs       147:     - content 
                    148:   ----------------------------------------------------------------------*/
                    149: #ifdef __STDC__
1.32      cvs       150: void         MapXMLElementType (int XMLtype,
                    151:                                STRING XMLname,
                    152:                                ElementType *elType,
                    153:                                STRING *mappedName,
                    154:                                CHAR_T *content,
                    155:                                ThotBool *highEnoughLevel,
                    156:                                Document doc)
1.1       cvs       157: #else
1.32      cvs       158: void         MapXMLElementType (XMLtype, XMLname, elType, mappedName,
                    159:                                content, highEnoughLevel, doc)
                    160: int            XMLtype;
                    161: STRING         XMLname;
                    162: ElementType   *elType;
                    163: STRING        *mappedName;
                    164: CHAR_T        *content;
                    165: ThotBool      *highEnoughLevel;
                    166: Document       doc;
1.1       cvs       167: #endif
                    168: {
                    169:    int                 i;
                    170:    ElemMapping        *ptr;
                    171: 
1.32      cvs       172:    /* Initialize variables */
                    173:    *mappedName = NULL;
                    174:    *highEnoughLevel = TRUE;
                    175:    elType->ElTypeNum = 0;
                    176: 
1.1       cvs       177:    /* Select the right table */
1.14      cvs       178:    if (XMLtype == XHTML_TYPE)
                    179:      ptr = XHTMLElemMappingTable;
                    180:    else if (XMLtype == MATH_TYPE)
1.31      cvs       181:      {
                    182:        if (ParsingLevel[doc] == L_Basic && DocumentTypes[doc] == docHTML)
1.32      cvs       183:         {
                    184:           /* Maths are not allowed in this document */
                    185:           ptr = NULL;
                    186:           *highEnoughLevel = FALSE;
                    187:         }
1.31      cvs       188:        else
                    189:         ptr = MathMLElemMappingTable;
                    190:      }
1.1       cvs       191:    else if (XMLtype == GRAPH_TYPE)
1.31      cvs       192:      {
                    193:        if (ParsingLevel[doc] == L_Basic && DocumentTypes[doc] == docHTML)
1.32      cvs       194:         {
                    195:           /* Graphics are not allowed in this document */
                    196:           ptr = NULL;
                    197:           *highEnoughLevel = FALSE;
                    198:         }
1.31      cvs       199:        else
                    200:         ptr = GraphMLElemMappingTable;
                    201:      }
1.1       cvs       202:    else
                    203:      ptr = NULL;
1.32      cvs       204:    
1.1       cvs       205:    if (ptr != NULL)
                    206:      {
                    207:        /* search in the ElemMappingTable */
                    208:        i = 0;
                    209:        /* look for the first concerned entry in the table */
1.22      cvs       210:        while (ptr[i].XMLname[0] < XMLname[0] && ptr[i].XMLname[0] != WC_EOS)
1.32      cvs       211:         i++;     
1.1       cvs       212:        /* look at all entries starting with the right character */
                    213:        do
1.32      cvs       214:         if (ustrcmp (ptr[i].XMLname, XMLname))
                    215:           /* it's not the tag */
1.1       cvs       216:           i++;
1.37    ! cvs       217:         else if (ParsingLevel[doc] != L_Other &&
        !           218:                  ptr[i].Level > ParsingLevel[doc])
1.32      cvs       219:           {
                    220:             /* this tag is not valid for the current parsing level */
                    221:             *highEnoughLevel = FALSE;
                    222:             i++;
                    223:           }
1.1       cvs       224:         else
                    225:           {
                    226:             elType->ElTypeNum = ptr[i].ThotType;
                    227:             if (elType->ElSSchema == NULL)
                    228:               elType->ElSSchema = GetXMLSSchema (XMLtype, doc);
                    229:             *mappedName = ptr[i].XMLname;
                    230:             *content = ptr[i].XMLcontents;
                    231:           }
                    232:        while (elType->ElTypeNum <= 0 && ptr[i].XMLname[0] == XMLname[0]);
                    233:      }
                    234: }
                    235: 
                    236: 
                    237: /*----------------------------------------------------------------------
                    238:    GetXMLElementName
1.22      cvs       239:    Generic function which searchs in the mapping table the XML name for
                    240:    a given Thot type.
1.1       cvs       241:   ----------------------------------------------------------------------*/
                    242: #ifdef __STDC__
1.25      cvs       243: CHAR_T*           GetXMLElementName (ElementType elType, Document doc)
1.1       cvs       244: #else
1.25      cvs       245: CHAR_T*           GetXMLElementName (elType, doc)
1.1       cvs       246: ElementType       elType;
1.25      cvs       247: Document          doc;
1.1       cvs       248: #endif
                    249: {
1.27      cvs       250:   ElemMapping        *ptr;
                    251:   STRING              name;
                    252:   int                 i;
                    253:   ThotBool            invalid = FALSE;
                    254: 
                    255:   if (elType.ElTypeNum > 0)
                    256:     {
                    257:       i = 0;
                    258:       /* Select the table which matches with the element schema */
                    259:       name = TtaGetSSchemaName (elType.ElSSchema);
                    260:       if (ustrcmp (TEXT("MathML"), name) == 0)
                    261:        ptr = MathMLElemMappingTable;
                    262:       else if (ustrcmp (TEXT("GraphML"), name) == 0)
                    263:        ptr = GraphMLElemMappingTable;
                    264:       else
                    265:        ptr = XHTMLElemMappingTable;
                    266:       
                    267:       if (ptr)
                    268:        do
                    269:          {
                    270:            if (ptr[i].ThotType == elType.ElTypeNum)
                    271:              {
1.37    ! cvs       272:                if (doc == 0 || 
        !           273:                    ParsingLevel[doc] == L_Other ||
        !           274:                    ptr[i].Level <= ParsingLevel[doc])
1.27      cvs       275:                  return ptr[i].XMLname;
                    276:                else
                    277:                  invalid = TRUE;
                    278:              }
                    279:            i++;
                    280:          }
                    281:        while (ptr[i].XMLname[0] != WC_EOS);      
                    282:     }
                    283:   if (invalid)
                    284:     return TEXT("");
                    285:   else
                    286:     return TEXT("???");
1.22      cvs       287: }
1.25      cvs       288: 
                    289: 
1.29      cvs       290: 
                    291: /*----------------------------------------------------------------------
1.30      cvs       292:    IsXMLElementInline
1.29      cvs       293:    Generic function which searchs in the mapping table if a given
                    294:    Thot type is an inline character or not
                    295:   ----------------------------------------------------------------------*/
                    296: #ifdef __STDC__
1.34      cvs       297: ThotBool         IsXMLElementInline (ElementType elType)
1.29      cvs       298: #else
1.34      cvs       299: ThotBool         IsXMLElementInline (elType)
                    300: ElementType      el;
1.29      cvs       301: #endif
                    302: {
1.34      cvs       303:   int            i;
                    304:   ThotBool       ret = FALSE;
                    305:   STRING         name;
                    306:   ElemMapping   *ptr;
1.29      cvs       307: 
                    308:   if (elType.ElTypeNum > 0)
                    309:     {
                    310:       i = 0;
                    311:       /* Select the table which matches with the element schema */
                    312:       name = TtaGetSSchemaName (elType.ElSSchema);
                    313:       if (ustrcmp (TEXT("MathML"), name) == 0)
                    314:        ptr = MathMLElemMappingTable;
                    315:       else if (ustrcmp (TEXT("GraphML"), name) == 0)
                    316:        ptr = GraphMLElemMappingTable;
                    317:       else
                    318:        ptr = XHTMLElemMappingTable;
                    319:       
                    320:       if (ptr)
                    321:        {
                    322:          while (ptr[i].XMLname[0] != WC_EOS &&
                    323:                 ptr[i].ThotType != elType.ElTypeNum)
                    324:            i++;
                    325:          if (ptr[i].ThotType == elType.ElTypeNum)
                    326:            ret = ptr[i].Inline;
                    327:        }
                    328:     }
                    329:   return ret;
                    330: }
                    331: 
1.22      cvs       332: /*----------------------------------------------------------------------
1.24      cvs       333:    MapXMLAttribute
1.22      cvs       334:    Generic function which searchs in the Attribute Mapping Table (table)
                    335:    the entry attrName associated to the element elementName.
1.24      cvs       336:    Returns the corresponding entry or -1.
1.22      cvs       337:   ----------------------------------------------------------------------*/
                    338: #ifdef __STDC__
1.33      cvs       339: int       MapXMLAttribute (int XMLtype, CHAR_T *attrName,
                    340:                           CHAR_T *elementName, ThotBool *highEnoughLevel,
                    341:                           Document doc, int *thotType)
1.22      cvs       342: #else
1.33      cvs       343: int       MapXMLAttribute (XMLtype, attrName, elementName,
                    344:                           highEnoughLevel, doc, thotType)
                    345: int          XMLtype;
                    346: CHAR_T      *attrName;
                    347: CHAR_T      *elementName;
                    348: ThotBool    *highEnoughLevel;
                    349: Document     doc;
                    350: int         *thotType;
1.22      cvs       351: #endif
                    352: {
1.24      cvs       353:   int               i;
                    354:   AttributeMapping *ptr;
                    355: 
1.33      cvs       356:   /* Initialization */
                    357:   *highEnoughLevel = TRUE;
                    358:   i = 1;
                    359:   *thotType = 0;
                    360: 
1.24      cvs       361:    /* Select the right table */
                    362:    if (XMLtype == XHTML_TYPE)
                    363:      ptr = XHTMLAttributeMappingTable;
                    364:    else if (XMLtype == MATH_TYPE)
                    365:      ptr = MathMLAttributeMappingTable;
                    366:    else if (XMLtype == GRAPH_TYPE)
                    367:      ptr = GraphMLAttributeMappingTable;
                    368:    else if (XMLtype == XLINK_TYPE)
                    369:      ptr = XLinkAttributeMappingTable;
                    370:    else
                    371:      ptr = NULL;
                    372: 
                    373:   if (ptr == NULL)
                    374:     return -1;
1.22      cvs       375: 
                    376:   /* look for the first concerned entry in the table */
1.33      cvs       377:   while (ptr[i].XMLattribute[0] < attrName[0] && 
                    378:         ptr[i].XMLattribute[0] != WC_EOS)
1.22      cvs       379:     i++;
1.33      cvs       380: 
1.24      cvs       381:   while (ptr[i].XMLattribute[0] == attrName[0])
1.22      cvs       382:     {
1.33      cvs       383:       if (ustrcmp (ptr[i].XMLattribute, attrName) ||
                    384:          (ptr[i].XMLelement[0] != WC_EOS &&
                    385:           ustrcmp (ptr[i].XMLelement, elementName)))
1.22      cvs       386:        i++;
1.33      cvs       387:       else if (ptr[i].Level > ParsingLevel[doc])
                    388:        {
                    389:          *highEnoughLevel = FALSE;
                    390:          i++;
                    391:        }
1.22      cvs       392:       else
1.24      cvs       393:        {
                    394:          *thotType = ptr[i].ThotAttribute;
                    395:          return (i);
                    396:        }
1.22      cvs       397:     }
1.24      cvs       398:   return (-1);
1.25      cvs       399: }
                    400: 
                    401: 
                    402: /*----------------------------------------------------------------------
1.37    ! cvs       403:    GetXMLAttributeName
1.25      cvs       404:    Generic function which searchs in the mapping table the XML name for
                    405:    a given Thot type.
                    406:   ----------------------------------------------------------------------*/
                    407: #ifdef __STDC__
1.28      cvs       408: CHAR_T*           GetXMLAttributeName (AttributeType attrType, ElementType elType, Document doc)
1.25      cvs       409: #else
1.28      cvs       410: CHAR_T*           GetXMLAttributeName (attrType, elType, doc)
1.25      cvs       411: AttributeType     attrType;
1.28      cvs       412: ElementType       elType;
1.25      cvs       413: Document          doc;
                    414: #endif
                    415: {
                    416:   AttributeMapping   *ptr;
1.28      cvs       417:   STRING              name, tag;
1.25      cvs       418:   int                 i;
1.27      cvs       419:   ThotBool            invalid = FALSE;
1.25      cvs       420: 
1.27      cvs       421:   if (attrType.AttrTypeNum > 0)
                    422:     {
1.28      cvs       423:       /* get the specific element tag */
                    424:       if (elType.ElTypeNum > 0)
                    425:        tag = GetXMLElementName (elType, doc);
                    426:       else
                    427:        tag = TEXT("");
                    428: 
1.27      cvs       429:       i = 0;
                    430:       /* Select the table which matches with the element schema */
                    431:       name = TtaGetSSchemaName (attrType.AttrSSchema);
                    432:       if (ustrcmp (TEXT("MathML"), name) == 0)
                    433:        ptr = MathMLAttributeMappingTable;
                    434:       else if (ustrcmp (TEXT("GraphML"), name) == 0)
                    435:        ptr = GraphMLAttributeMappingTable;
                    436:       else if (ustrcmp (TEXT("XLink"), name) == 0)
                    437:        ptr = XLinkAttributeMappingTable;
                    438:       else
                    439:        ptr = XHTMLAttributeMappingTable;
                    440:       
                    441:       if (ptr)
                    442:        do
                    443:          {
1.28      cvs       444:            if (ptr[i].ThotAttribute == attrType.AttrTypeNum &&
                    445:                (ptr[i].XMLelement[0] == WC_EOS ||
                    446:                 !ustrcmp (ptr[i].XMLelement, tag)))
1.25      cvs       447:              {
1.26      cvs       448:                if (doc == 0 || ptr[i].Level <= ParsingLevel[doc])
1.25      cvs       449:                  return ptr[i].XMLattribute;
                    450:                else
1.27      cvs       451:                  invalid = TRUE;
1.25      cvs       452:              }
                    453:            i++;
1.27      cvs       454:          }
                    455:        while (ptr[i].XMLattribute[0] != WC_EOS);         
                    456:     }
                    457:   if (invalid)
                    458:     return TEXT("");
                    459:   else
                    460:     return TEXT("???");
1.36      cvs       461: }
                    462: 
                    463: /*----------------------------------------------------------------------
                    464:    MapXMLEntity
                    465:    Generic function which searchs in the Entity Mapping Table (table)
                    466:    the entry entityName and give the corresponding decimal value.
                    467:    Returns FALSE if entityName is not found.
                    468:   ----------------------------------------------------------------------*/
                    469: #ifdef __STDC__
                    470: ThotBool   MapXMLEntity (int XMLtype, STRING entityName, int *entityValue)
                    471: #else
                    472: ThotBool   MapXMLEntity (XMLtype, entityName, entityValue)
                    473: int        XMLtype;
                    474: STRING     entityName
                    475: int       *entityValue
                    476: #endif
                    477: {
                    478:   int         i;
                    479:   XmlEntity  *ptr;
                    480:   ThotBool    found;
                    481: 
                    482:   i = 1;
                    483:   found = FALSE;
                    484: 
                    485:   /* Select the right table */
                    486:   if (XMLtype == XHTML_TYPE)
                    487:     ptr = XhtmlEntityTable;
                    488:   else if (XMLtype == MATH_TYPE)
                    489:     ptr = MathEntityTable;
                    490:   else
                    491:     ptr = NULL;
                    492:   
                    493:   if (ptr == NULL)
                    494:     return FALSE;
                    495: 
                    496:   /* look for the first concerned entry in the table */
                    497:   for (i = 0; ptr[i].charCode >= 0 && !found; i++)
                    498:     found = !ustrcmp (ptr[i].charName, entityName);
                    499:   
                    500:   if (found)
                    501:     {
                    502:       /* entity found */
                    503:       i--;
                    504:       *entityValue = ptr[i].charCode;
                    505:       return TRUE;
                    506:     }
                    507:   else
                    508:     return FALSE;
1.1       cvs       509: }

Webmaster