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

1.1       cvs         1: /*
                      2:  *
                      3:  *  (c) COPYRIGHT MIT and INRIA, 1996.
                      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"
                     19: 
                     20: /* mapping table of MathML elements */
                     21: #include "MathML.h"
                     22: static ElemMapping    MathMLElemMappingTable[] =
                     23: {
                     24:    /* This table MUST be in alphabetical order */
1.9       cvs        25:    {TEXT("XMLcomment"), SPACE, MathML_EL_XMLcomment},
                     26:    {TEXT("XMLcomment_line"), SPACE, MathML_EL_XMLcomment_line},
                     27:    {TEXT("maligngroup"), 'E', MathML_EL_MALIGNGROUP},
                     28:    {TEXT("malignmark"), 'E', MathML_EL_MALIGNMARK},
1.10    ! cvs        29:    {TEXT("mchar"), 'E', MathML_EL_MCHAR},
        !            30:    {TEXT("menclose"), SPACE, MathML_EL_MENCLOSE},
1.9       cvs        31:    {TEXT("merror"), SPACE, MathML_EL_MERROR},
                     32:    {TEXT("mf"), SPACE, MathML_EL_MF},  /* for compatibility with an old version of
1.1       cvs        33:                                    MathML: WD-math-970704 */
1.9       cvs        34:    {TEXT("mfenced"), SPACE, MathML_EL_MFENCED},
                     35:    {TEXT("mfrac"), SPACE, MathML_EL_MFRAC},
1.10    ! cvs        36:    {TEXT("mglyph"), 'E', MathML_EL_MGLYPH},
1.9       cvs        37:    {TEXT("mi"), SPACE, MathML_EL_MI},
1.10    ! cvs        38:    {TEXT("mlabeledtr"), SPACE, MathML_EL_MLABELEDTR},
1.9       cvs        39:    {TEXT("mmultiscripts"), SPACE, MathML_EL_MMULTISCRIPTS},
                     40:    {TEXT("mn"), SPACE, MathML_EL_MN},
                     41:    {TEXT("mo"), SPACE, MathML_EL_MO},
                     42:    {TEXT("mover"), SPACE, MathML_EL_MOVER},
                     43:    {TEXT("mpadded"), SPACE, MathML_EL_MPADDED},
                     44:    {TEXT("mphantom"), SPACE, MathML_EL_MPHANTOM},
                     45:    {TEXT("mprescripts"), SPACE, MathML_EL_PrescriptPairs},
                     46:    {TEXT("mroot"), SPACE, MathML_EL_MROOT},
                     47:    {TEXT("mrow"), SPACE, MathML_EL_MROW},
                     48:    {TEXT("ms"), SPACE, MathML_EL_MS},
                     49:    {TEXT("mspace"), 'E', MathML_EL_MSPACE},
                     50:    {TEXT("msqrt"), SPACE, MathML_EL_MSQRT},
                     51:    {TEXT("mstyle"), SPACE, MathML_EL_MSTYLE},
                     52:    {TEXT("msub"), SPACE, MathML_EL_MSUB},
                     53:    {TEXT("msubsup"), SPACE, MathML_EL_MSUBSUP},
                     54:    {TEXT("msup"), SPACE, MathML_EL_MSUP},
                     55:    {TEXT("mtable"), SPACE, MathML_EL_MTABLE},
                     56:    {TEXT("mtd"), SPACE, MathML_EL_MTD},
                     57:    {TEXT("mtext"), SPACE, MathML_EL_MTEXT},
                     58:    {TEXT("mtr"), SPACE, MathML_EL_MTR},
                     59:    {TEXT("munder"), SPACE, MathML_EL_MUNDER},
                     60:    {TEXT("munderover"), SPACE, MathML_EL_MUNDEROVER},
                     61:    {TEXT("none"), SPACE, MathML_EL_Construct},
                     62:    {TEXT("sep"), 'E', MathML_EL_SEP},
                     63:    {TEXT(""), SPACE, 0}        /* Last entry. Mandatory */
1.1       cvs        64: };
                     65: 
                     66: #ifdef GRAPHML
                     67: /* mapping table of GraphML elements */
                     68: #include "GraphML.h"
                     69: static ElemMapping    GraphMLElemMappingTable[] =
                     70: {
                     71:    /* This table MUST be in alphabetical order */
1.9       cvs        72:    {TEXT("XMLcomment"), SPACE, GraphML_EL_XMLcomment},
                     73:    {TEXT("XMLcomment_line"), SPACE, GraphML_EL_XMLcomment_line},
                     74:    {TEXT("circle"), SPACE, GraphML_EL_Circle},
                     75:    {TEXT("closedspline"), SPACE, GraphML_EL_ClosedSpline},
                     76:    {TEXT("group"), SPACE, GraphML_EL_Group},
                     77:    {TEXT("label"), 'X', GraphML_EL_Label},     /* see function GraphMLGetDTDName */
                     78:    {TEXT("line"), 'E', GraphML_EL_Line_},
                     79:    {TEXT("math"), 'X', GraphML_EL_Math},       /* see function GraphMLGetDTDName */
                     80:    {TEXT("oval"), SPACE, GraphML_EL_Oval},
                     81:    {TEXT("polygon"), SPACE, GraphML_EL_Polygon},
                     82:    {TEXT("polyline"), 'E', GraphML_EL_Polyline},
                     83:    {TEXT("rect"), SPACE, GraphML_EL_Rectangle},
                     84:    {TEXT("roundrect"), SPACE, GraphML_EL_RoundRect},
                     85:    {TEXT("spline"), 'E', GraphML_EL_Spline},
                     86:    {TEXT("text"), 'X', GraphML_EL_Text_},      /* see function GraphMLGetDTDName */
                     87:    {TEXT(""), SPACE, 0}        /* Last entry. Mandatory */
1.1       cvs        88: };
                     89: #else /* GRAPHML */
                     90: /* there is no mapping table of GraphML elements */
                     91: 
                     92: static ElemMapping *GraphMLElemMappingTable = NULL;
                     93: #endif /* GRAPHML */
                     94: 
                     95: #include "fetchXMLname_f.h"
                     96: 
                     97: /*----------------------------------------------------------------------
                     98:    GetMathMLSSchema returns the MathML Thot schema for document doc.
                     99:   ----------------------------------------------------------------------*/
                    100: #ifdef __STDC__
                    101: SSchema            GetMathMLSSchema (Document doc)
                    102: #else
                    103: SSchema            GetMathMLSSchema (doc)
                    104: Document          doc;
                    105: 
                    106: #endif
                    107: {
                    108:   SSchema      MathMLSSchema;
                    109: 
1.8       cvs       110:    MathMLSSchema = TtaGetSSchema (TEXT("MathML"), doc);
1.1       cvs       111:    if (MathMLSSchema == NULL)
1.8       cvs       112:       MathMLSSchema = TtaNewNature(TtaGetDocumentSSchema(doc), TEXT("MathML"), TEXT("MathMLP"));
1.1       cvs       113:    return (MathMLSSchema);
                    114: }
                    115: 
                    116: /*----------------------------------------------------------------------
                    117:    GetGraphMLSSchema returns the GraphML Thot schema for document doc.
                    118:   ----------------------------------------------------------------------*/
                    119: #ifdef __STDC__
                    120: SSchema            GetGraphMLSSchema (Document doc)
                    121: #else
                    122: SSchema            GetGraphMLSSchema (doc)
                    123: Document          doc;
                    124: 
                    125: #endif
                    126: {
                    127:   SSchema      GraphMLSSchema;
                    128: 
1.8       cvs       129:   GraphMLSSchema = TtaGetSSchema (TEXT("GraphML"), doc);
1.1       cvs       130:   if (GraphMLSSchema == NULL)
1.8       cvs       131:     GraphMLSSchema = TtaNewNature(TtaGetDocumentSSchema(doc), TEXT("GraphML"), TEXT("GraphMLP"));
1.1       cvs       132:   return (GraphMLSSchema);
                    133: }
                    134: 
                    135: /*----------------------------------------------------------------------
                    136:    GetXMLSSchema returns the XMLML Thot schema for document doc.
                    137:   ----------------------------------------------------------------------*/
                    138: #ifdef __STDC__
                    139: SSchema            GetXMLSSchema (int XMLtype, Document doc)
                    140: #else
                    141: SSchema            GetXMLSSchema (XMLtype, doc)
                    142: Document          doc;
                    143: int                XMLtype;
                    144: #endif
                    145: {
                    146:    if (XMLtype == MATH_TYPE)
                    147:      return GetMathMLSSchema (doc);
                    148:    else if (XMLtype == GRAPH_TYPE)
                    149:      return GetGraphMLSSchema (doc);
                    150:    else
                    151:      return NULL;
                    152: }
                    153: 
                    154: 
                    155: /*----------------------------------------------------------------------
                    156:    MapXMLElementType
                    157:    search in the mapping tables the entry for the element type of name
                    158:    XMLname and returns the corresponding Thot element type.
                    159:    Returns:
                    160:     - ElTypeNum and ElSSchema inelType  ElTypeNum = 0 if not found.
                    161:     - content 
                    162:   ----------------------------------------------------------------------*/
                    163: #ifdef __STDC__
1.9       cvs       164: void               MapXMLElementType (int XMLtype, CHAR_T* XMLname, ElementType *elType, CHAR_T** mappedName, CHAR_T* content, Document doc)
1.1       cvs       165: #else
                    166: void               MapXMLElementType (XMLtype, XMLname, elType, mappedName, content, doc)
1.6       cvs       167: int                XMLtype;
1.9       cvs       168: CHAR_T*            XMLname;
1.6       cvs       169: ElementType*       elType;
1.9       cvs       170: CHAR_T**           mappedName;
                    171: CHAR_T*               content;
1.6       cvs       172: Document           doc;
1.1       cvs       173: #endif
                    174: {
                    175:    int                 i;
                    176:    ElemMapping        *ptr;
                    177: 
                    178:    /* Select the right table */
                    179:    if (XMLtype == MATH_TYPE)
                    180:      ptr = MathMLElemMappingTable;
                    181:    else if (XMLtype == GRAPH_TYPE)
                    182:      ptr = GraphMLElemMappingTable;
                    183:    else
                    184:      ptr = NULL;
                    185: 
                    186:    elType->ElTypeNum = 0;
                    187:    if (ptr != NULL)
                    188:      {
                    189:        /* search in the ElemMappingTable */
                    190:        i = 0;
                    191:        /* look for the first concerned entry in the table */
                    192:        while (ptr[i].XMLname[0] < XMLname[0] && ptr[i].XMLname[0] != EOS)
                    193:         i++;
                    194:        /* look at all entries starting with the right character */
                    195:        do
1.9       cvs       196:         if (ustrcmp (ptr[i].XMLname, XMLname))
1.1       cvs       197:           i++;
                    198:         else
                    199:           {
                    200:             elType->ElTypeNum = ptr[i].ThotType;
                    201:             if (elType->ElSSchema == NULL)
                    202:               elType->ElSSchema = GetXMLSSchema (XMLtype, doc);
                    203:             *mappedName = ptr[i].XMLname;
                    204:             *content = ptr[i].XMLcontents;
                    205:           }
                    206:        while (elType->ElTypeNum <= 0 && ptr[i].XMLname[0] == XMLname[0]);
                    207:      }
                    208: }
                    209: 
                    210: 
                    211: /*----------------------------------------------------------------------
                    212:    GetXMLElementName
                    213:    search in the mapping tables the XML name for a given Thot type
                    214:   ----------------------------------------------------------------------*/
                    215: #ifdef __STDC__
1.9       cvs       216: void              GetXMLElementName (ElementType elType, CHAR_T** buffer)
1.1       cvs       217: #else
                    218: void              GetXMLElementName (elType, buffer)
                    219: ElementType       elType;
1.9       cvs       220: CHAR_T**          buffer;
1.1       cvs       221: #endif
                    222: {
                    223:    int                 i;
                    224:    ElemMapping        *ptr;
                    225:    STRING              name;
                    226: 
                    227:    if (elType.ElTypeNum > 0)
                    228:      {
                    229:        i = 0;
                    230:        /* Select the table which matches with the element schema */
                    231:        name = TtaGetSSchemaName (elType.ElSSchema);
                    232:        if (ustrcmp (TEXT("MathML"), name) == 0)
                    233:          ptr = MathMLElemMappingTable;
1.4       cvs       234:        else if (ustrcmp (TEXT("GraphML"), name) == 0)
1.1       cvs       235:          ptr = GraphMLElemMappingTable;
1.4       cvs       236:         else
                    237:          ptr = NULL;
1.1       cvs       238: 
1.4       cvs       239:        if (ptr)
                    240:          do
                    241:            {
1.1       cvs       242:            if (ptr[i].ThotType == elType.ElTypeNum)
                    243:              {
                    244:                *buffer = ptr[i].XMLname;
                    245:                return;
                    246:              }
                    247:            i++;
1.4       cvs       248:            }
                    249:          while (ptr[i].XMLname[0] != EOS);       
1.1       cvs       250:      }
                    251:    *buffer = TEXT("???");
                    252:    return;
                    253: }

Webmaster