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

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: 
        !            24: /* define a pointer to let other parser functions access the local table */
        !            25: int               HTML_ENTRIES = (sizeof(XHTMLElemMappingTable) / sizeof(ElemMapping));
        !            26: ElemMapping      *pHTMLGIMapping = XHTMLElemMappingTable;
        !            27: AttributeMapping *pHTMLAttributeMapping = XHTMLAttributeMappingTable;
1.14      cvs        28: 
1.1       cvs        29: 
                     30: #include "fetchXMLname_f.h"
                     31: 
                     32: /*----------------------------------------------------------------------
1.14      cvs        33:    GetXHTMLSSchema returns the XHTML Thot schema for document doc.
                     34:   ----------------------------------------------------------------------*/
                     35: #ifdef __STDC__
                     36: SSchema            GetXHTMLSSchema (Document doc)
                     37: #else
                     38: SSchema            GetXHTMLSSchema (doc)
                     39: Document          doc;
                     40: 
                     41: #endif
                     42: {
                     43:   SSchema      XHTMLSSchema;
                     44: 
                     45:    XHTMLSSchema = TtaGetSSchema (TEXT("HTML"), doc);
                     46:    if (XHTMLSSchema == NULL)
1.17      cvs        47:        XHTMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc),
1.14      cvs        48:                                    TEXT("HTML"), TEXT("HTMLP"));
                     49:    return (XHTMLSSchema);
                     50: }
                     51: 
                     52: /*----------------------------------------------------------------------
1.1       cvs        53:    GetMathMLSSchema returns the MathML Thot schema for document doc.
                     54:   ----------------------------------------------------------------------*/
                     55: #ifdef __STDC__
                     56: SSchema            GetMathMLSSchema (Document doc)
                     57: #else
                     58: SSchema            GetMathMLSSchema (doc)
                     59: Document          doc;
                     60: 
                     61: #endif
                     62: {
                     63:   SSchema      MathMLSSchema;
                     64: 
1.13      cvs        65:   MathMLSSchema = TtaGetSSchema (TEXT("MathML"), doc);
                     66:   if (MathMLSSchema == NULL)
1.17      cvs        67:      MathMLSSchema = TtaNewNature(doc, 
                     68:                                  TtaGetDocumentSSchema(doc), TEXT("MathML"),
1.13      cvs        69:                                  TEXT("MathMLP"));
                     70:   return (MathMLSSchema);
1.1       cvs        71: }
                     72: 
                     73: /*----------------------------------------------------------------------
                     74:    GetGraphMLSSchema returns the GraphML Thot schema for document doc.
                     75:   ----------------------------------------------------------------------*/
                     76: #ifdef __STDC__
                     77: SSchema            GetGraphMLSSchema (Document doc)
                     78: #else
                     79: SSchema            GetGraphMLSSchema (doc)
                     80: Document          doc;
                     81: 
                     82: #endif
                     83: {
                     84:   SSchema      GraphMLSSchema;
                     85: 
1.8       cvs        86:   GraphMLSSchema = TtaGetSSchema (TEXT("GraphML"), doc);
1.1       cvs        87:   if (GraphMLSSchema == NULL)
1.17      cvs        88:     GraphMLSSchema = TtaNewNature(doc,
                     89:                                  TtaGetDocumentSSchema(doc), TEXT("GraphML"),
1.13      cvs        90:                                  TEXT("GraphMLP"));
1.1       cvs        91:   return (GraphMLSSchema);
                     92: }
                     93: 
                     94: /*----------------------------------------------------------------------
1.13      cvs        95:    GetXLinkSSchema returns the XLink Thot schema for document doc.
                     96:   ----------------------------------------------------------------------*/
                     97: #ifdef __STDC__
                     98: SSchema            GetXLinkSSchema (Document doc)
                     99: #else
                    100: SSchema            GetXLinkSSchema (doc)
                    101: Document          doc;
                    102: 
                    103: #endif
                    104: {
                    105:   SSchema      XLinkSSchema;
                    106: 
                    107:   XLinkSSchema = TtaGetSSchema (TEXT("XLink"), doc);
                    108:   if (XLinkSSchema == NULL)
1.17      cvs       109:     XLinkSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), TEXT("XLink"),
1.13      cvs       110:                                TEXT("XLinkP"));
                    111:   return (XLinkSSchema);
                    112: }
                    113: 
                    114: /*----------------------------------------------------------------------
                    115:    GetXMLSSchema returns the XML Thot schema for document doc.
1.1       cvs       116:   ----------------------------------------------------------------------*/
                    117: #ifdef __STDC__
                    118: SSchema            GetXMLSSchema (int XMLtype, Document doc)
                    119: #else
                    120: SSchema            GetXMLSSchema (XMLtype, doc)
                    121: Document          doc;
                    122: int                XMLtype;
                    123: #endif
                    124: {
1.14      cvs       125:   if (XMLtype == XHTML_TYPE)
                    126:     return GetXHTMLSSchema (doc);
                    127:   else if (XMLtype == MATH_TYPE)
1.13      cvs       128:     return GetMathMLSSchema (doc);
                    129:   else if (XMLtype == GRAPH_TYPE)
                    130:     return GetGraphMLSSchema (doc);
                    131:   else if (XMLtype == XLINK_TYPE)
1.15      cvs       132:     return GetXLinkSSchema (doc);
1.13      cvs       133:   else
                    134:     return NULL;
1.1       cvs       135: }
                    136: 
                    137: 
                    138: /*----------------------------------------------------------------------
1.22      cvs       139:   MapXMLElementType
                    140:   Generic function which searchs in the Element Mapping table, selected
                    141:   by the parameter XMLtype, the entry XMLname and returns the corresponding
                    142:   Thot element type.
1.1       cvs       143:    Returns:
1.22      cvs       144:     - ElTypeNum and ElSSchema into elType  ElTypeNum = 0 if not found.
1.1       cvs       145:     - content 
                    146:   ----------------------------------------------------------------------*/
                    147: #ifdef __STDC__
1.14      cvs       148: void               MapXMLElementType (int XMLtype,
                    149:                                      STRING XMLname,
                    150:                                      ElementType *elType,
                    151:                                      STRING *mappedName,
                    152:                                      CHAR_T *content,
                    153:                                      Document doc)
1.1       cvs       154: #else
1.14      cvs       155: void               MapXMLElementType (XMLtype,
                    156:                                      XMLname,
                    157:                                      elType,
                    158:                                      mappedName,
                    159:                                      content,
                    160:                                      doc)
1.6       cvs       161: int                XMLtype;
1.12      cvs       162: STRING             XMLname;
                    163: ElementType       *elType;
                    164: STRING            *mappedName;
                    165: CHAR_T           *content;
1.6       cvs       166: Document           doc;
1.1       cvs       167: #endif
                    168: {
                    169:    int                 i;
                    170:    ElemMapping        *ptr;
                    171: 
                    172:    /* Select the right table */
1.14      cvs       173:    if (XMLtype == XHTML_TYPE)
                    174:      ptr = XHTMLElemMappingTable;
                    175:    else if (XMLtype == MATH_TYPE)
1.1       cvs       176:      ptr = MathMLElemMappingTable;
                    177:    else if (XMLtype == GRAPH_TYPE)
                    178:      ptr = GraphMLElemMappingTable;
                    179:    else
                    180:      ptr = NULL;
1.16      cvs       181:    *mappedName = NULL;
1.1       cvs       182:    elType->ElTypeNum = 0;
                    183:    if (ptr != NULL)
                    184:      {
                    185:        /* search in the ElemMappingTable */
                    186:        i = 0;
                    187:        /* look for the first concerned entry in the table */
1.22      cvs       188:        while (ptr[i].XMLname[0] < XMLname[0] && ptr[i].XMLname[0] != WC_EOS)
1.1       cvs       189:         i++;
1.22      cvs       190: 
1.1       cvs       191:        /* look at all entries starting with the right character */
                    192:        do
1.22      cvs       193:         if (ustrcmp (ptr[i].XMLname, XMLname) || ptr[i].Level > ParsingLevel[doc])
                    194:           /* it's not the tag or this tag is not valid for the current parsing level */
1.1       cvs       195:           i++;
                    196:         else
                    197:           {
                    198:             elType->ElTypeNum = ptr[i].ThotType;
                    199:             if (elType->ElSSchema == NULL)
                    200:               elType->ElSSchema = GetXMLSSchema (XMLtype, doc);
                    201:             *mappedName = ptr[i].XMLname;
                    202:             *content = ptr[i].XMLcontents;
                    203:           }
                    204:        while (elType->ElTypeNum <= 0 && ptr[i].XMLname[0] == XMLname[0]);
                    205:      }
                    206: }
                    207: 
                    208: 
                    209: /*----------------------------------------------------------------------
                    210:    GetXMLElementName
1.22      cvs       211:    Generic function which searchs in the mapping table the XML name for
                    212:    a given Thot type.
1.1       cvs       213:   ----------------------------------------------------------------------*/
                    214: #ifdef __STDC__
1.9       cvs       215: void              GetXMLElementName (ElementType elType, CHAR_T** buffer)
1.1       cvs       216: #else
                    217: void              GetXMLElementName (elType, buffer)
                    218: ElementType       elType;
1.9       cvs       219: CHAR_T**          buffer;
1.1       cvs       220: #endif
                    221: {
                    222:    int                 i;
                    223:    ElemMapping        *ptr;
                    224:    STRING              name;
                    225: 
                    226:    if (elType.ElTypeNum > 0)
                    227:      {
                    228:        i = 0;
                    229:        /* Select the table which matches with the element schema */
                    230:        name = TtaGetSSchemaName (elType.ElSSchema);
                    231:        if (ustrcmp (TEXT("MathML"), name) == 0)
                    232:          ptr = MathMLElemMappingTable;
1.4       cvs       233:        else if (ustrcmp (TEXT("GraphML"), name) == 0)
1.1       cvs       234:          ptr = GraphMLElemMappingTable;
1.4       cvs       235:         else
                    236:          ptr = NULL;
1.1       cvs       237: 
1.4       cvs       238:        if (ptr)
                    239:          do
                    240:            {
1.1       cvs       241:            if (ptr[i].ThotType == elType.ElTypeNum)
                    242:              {
                    243:                *buffer = ptr[i].XMLname;
                    244:                return;
                    245:              }
                    246:            i++;
1.4       cvs       247:            }
1.22      cvs       248:          while (ptr[i].XMLname[0] != WC_EOS);    
1.1       cvs       249:      }
                    250:    *buffer = TEXT("???");
                    251:    return;
1.22      cvs       252: }
                    253: /*----------------------------------------------------------------------
1.24    ! cvs       254:    MapXMLAttribute
1.22      cvs       255:    Generic function which searchs in the Attribute Mapping Table (table)
                    256:    the entry attrName associated to the element elementName.
1.24    ! cvs       257:    Returns the corresponding entry or -1.
1.22      cvs       258:   ----------------------------------------------------------------------*/
                    259: #ifdef __STDC__
1.24    ! cvs       260: int               MapXMLAttribute (int XMLtype,
        !           261:                                   CHAR_T *attrName,
1.22      cvs       262:                                   CHAR_T *elementName,
                    263:                                   Document doc,
1.24    ! cvs       264:                                   int *thotType)
1.22      cvs       265: #else
1.24    ! cvs       266: int               MapXMLAttribute (XMLtype,
        !           267:                                   attrName,
1.22      cvs       268:                                   elementName,
                    269:                                   doc,
1.24    ! cvs       270:                                   thotType)
        !           271: int               XMLtype;
1.22      cvs       272: CHAR_T           *attrName;
                    273: CHAR_T           *elementName;
                    274: Document          doc;
1.24    ! cvs       275: int              *thotType;
1.22      cvs       276: #endif
                    277: {
1.24    ! cvs       278:   int               i;
        !           279:   AttributeMapping *ptr;
        !           280: 
        !           281:    /* Select the right table */
        !           282:    if (XMLtype == XHTML_TYPE)
        !           283:      ptr = XHTMLAttributeMappingTable;
        !           284:    else if (XMLtype == MATH_TYPE)
        !           285:      ptr = MathMLAttributeMappingTable;
        !           286:    else if (XMLtype == GRAPH_TYPE)
        !           287:      ptr = GraphMLAttributeMappingTable;
        !           288:    else if (XMLtype == XLINK_TYPE)
        !           289:      ptr = XLinkAttributeMappingTable;
        !           290:    else
        !           291:      ptr = NULL;
        !           292: 
        !           293:   i = 1;
        !           294:   *thotType = 0;
        !           295:   if (ptr == NULL)
        !           296:     return -1;
1.22      cvs       297: 
                    298:   /* look for the first concerned entry in the table */
1.24    ! cvs       299:   while (ptr[i].XMLattribute[0] < attrName[0] && ptr[i].XMLattribute[0] != WC_EOS)
1.22      cvs       300:     i++;
1.24    ! cvs       301:   while (ptr[i].XMLattribute[0] == attrName[0])
1.22      cvs       302:     {
1.24    ! cvs       303:       if (ptr[i].Level > ParsingLevel[doc] ||
        !           304:          ustrcmp (ptr[i].XMLattribute, attrName) ||
        !           305:          (ptr[i].XMLelement[0] != WC_EOS && ustrcmp (ptr[i].XMLelement, elementName)))
1.22      cvs       306:        i++;
                    307:       else
1.24    ! cvs       308:        {
        !           309:          *thotType = ptr[i].ThotAttribute;
        !           310:          return (i);
        !           311:        }
1.22      cvs       312:     }
1.24    ! cvs       313:   return (-1);
1.1       cvs       314: }

Webmaster