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

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

Webmaster