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

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

Webmaster