Annotation of Amaya/amaya/fetchHTMLname.c, revision 1.35

1.1       cvs         1: /*
                      2:  *
1.35    ! vatton      3:  *  (c) COPYRIGHT INRIA and W3C, 1996-2005
1.1       cvs         4:  *  Please first read the full copyright statement in file COPYRIGHT.
                      5:  *
                      6:  */
                      7: 
                      8: /*
                      9:  *
                     10:  * fetchHTMLname
                     11:  *
                     12:  * Author: I. Vatton
                     13:  *
                     14:  */
1.13      cvs        15:  
1.1       cvs        16: /* This module is used by the html2thot parser and the css parser. */
                     17: 
1.32      gully      18: #define THOT_EXPORT extern
1.1       cvs        19: #include "amaya.h"
                     20: #include "fetchHTMLname.h"
                     21: #include "parser.h"
                     22: 
1.3       cvs        23: #include "fetchHTMLname_f.h"
                     24: #include "fetchXMLname_f.h"
                     25: 
1.20      cvs        26: 
                     27: /*----------------------------------------------------------------------
                     28:   LowercaseGI converts uppercases into lovercases
                     29:   GI is the input string
                     30:   gi is the output string
                     31:   ----------------------------------------------------------------------*/
1.34      vatton     32: static void LowercaseGI (char *GI, char *gi)
1.4       cvs        33: {
1.20      cvs        34:   int        i;
1.1       cvs        35: 
1.26      cvs        36:   for (i = 0; GI[i] != EOS && i < MaxTypeNameLength-1; i++)
1.20      cvs        37:     {
1.25      cvs        38:       if (GI[i] >= 'A' && GI[i] <= 'Z')
1.26      cvs        39:        gi[i] = (char) ((int) GI[i] + 32);
1.20      cvs        40:       else
                     41:        gi[i] = GI[i];
                     42:     }
1.26      cvs        43:   gi[i] = EOS;
1.20      cvs        44: }
1.4       cvs        45: 
1.1       cvs        46: 
                     47: /*----------------------------------------------------------------------
                     48:    MapGI
                     49:    search in the mapping tables the entry for the element of
                     50:    name GI and returns the rank of that entry.
                     51:    When returning, schema contains the Thot SSchema that defines that element,
                     52:    Returns -1 and schema = NULL if not found.
                     53:   ----------------------------------------------------------------------*/
1.27      cvs        54: int MapGI (char *gi, SSchema *schema, Document doc)
1.1       cvs        55: {
1.9       cvs        56:   ElementType     elType;
1.27      cvs        57:   char           *ptr; 
                     58:   char            c;
1.9       cvs        59:   int             i;
                     60:   int             entry;
1.23      cvs        61:   ThotBool       isHTML; 
                     62:   ThotBool       level; 
1.1       cvs        63: 
                     64:   /* TODO: use NameSpaces to search in the right table */
                     65:   entry = -1;
                     66:   if (*schema == NULL)
                     67:     {
                     68:       isHTML = FALSE;
                     69:       ptr = NULL;
                     70:     }
                     71:   else
                     72:     {
                     73:       ptr = TtaGetSSchemaName (*schema);
1.26      cvs        74:       isHTML = !strcmp (ptr, "HTML");
1.1       cvs        75:     }
                     76: 
                     77:   i = 0;
                     78:   if (*schema == NULL || isHTML)
                     79:     {
                     80:       /*
                     81:        First convert the first char into lower case to locate
                     82:        registered tags in the HTML mapping table.
                     83:        Entries are registered in upper case and in alphabetic order.
                     84:       */
                     85: 
                     86:       /* TODO: define a function which works on unicode */
1.30      vatton     87:       c = tolower (gi[0]);
1.1       cvs        88:       /* look for the first concerned entry in the table */
1.16      cvs        89:       while (pHTMLGIMapping[i].XMLname[0] < c
                     90:             && pHTMLGIMapping[i].XMLname[0] != EOS)
1.1       cvs        91:        i++;
                     92: 
                     93:       /* look at all entries starting with the right character */
                     94:       do
                     95:        {
1.26      cvs        96:          if (strcasecmp (pHTMLGIMapping[i].XMLname, gi))
1.1       cvs        97:            i++;
                     98:          else
                     99:            entry = i;
                    100:        }
1.16      cvs       101:       while (entry < 0 && pHTMLGIMapping[i].XMLname[0] == c);
1.1       cvs       102:     }
                    103: 
                    104:   if (entry < 0)
1.22      cvs       105:     {
                    106:       if (*schema != NULL && isHTML)
                    107:        *schema = NULL;
                    108:       else
                    109:        /* not found. Look at the XML mapping tables */
                    110:        {
                    111:          elType.ElTypeNum = 0;
                    112:          elType.ElSSchema = *schema;
                    113:          
1.26      cvs       114:          if (!ptr || !strcmp (ptr, "MathML"))
1.23      cvs       115:            MapXMLElementType (MATH_TYPE, gi, &elType, &ptr, &c, &level, doc);
1.28      vatton    116:          if (elType.ElTypeNum == 0 && (!ptr || !strcmp (ptr, "SVG")))
1.29      cvs       117:            MapXMLElementType (SVG_TYPE, gi, &elType, &ptr, &c, &level, doc);
1.22      cvs       118:          if (elType.ElTypeNum == 0)
                    119:            {
                    120:              entry = -1;
                    121:              elType.ElSSchema = NULL;
                    122:              *schema = NULL;
                    123:            }
                    124:          else
                    125:            {
                    126:              entry = elType.ElTypeNum;
                    127:              *schema = elType.ElSSchema;
                    128:            }
                    129:        }
                    130:     }
1.1       cvs       131:   return entry;
                    132: }
                    133: 
                    134: /*----------------------------------------------------------------------
                    135:    GIType  search in mapping tables the Element type associated with
                    136:    a given GI Name. If not found returns zero.
                    137:   ----------------------------------------------------------------------*/
1.30      vatton    138: void GIType (char *gi, ElementType *elType, Document doc)
1.1       cvs       139: {
1.26      cvs       140:   char              c;
1.27      cvs       141:   char             *ptr;
                    142:   int               i;
                    143:   ThotBool         level; 
1.1       cvs       144: 
                    145:   /* TODO: use NameSpaces to search in the right table */
                    146:   elType->ElSSchema = NULL;
                    147:   elType->ElTypeNum = 0;
                    148: 
                    149:   /*
                    150:     First convert the first char into lower case to locate
                    151:     registered tags in the HTML mapping table.
                    152:     Entries are registered in upper case and in alphabetic order.
                    153:   */
                    154: 
                    155:   /* TODO: define a function which works on unicode */
1.30      vatton    156:   c = tolower (gi[0]);
1.1       cvs       157: 
                    158:   i = 0;
                    159:   /* look for the first concerned entry in the table */
1.16      cvs       160:   while (pHTMLGIMapping[i].XMLname[0] < c &&
                    161:         pHTMLGIMapping[i].XMLname[0] != EOS)
1.1       cvs       162:     i++;
                    163:   /* look at all entries starting with the right character */
                    164:   do
                    165:     {
1.26      cvs       166:       if (!strcasecmp (pHTMLGIMapping[i].XMLname, gi))
1.4       cvs       167:       {
                    168:        if (doc != 0)
1.25      cvs       169:         elType->ElSSchema = TtaGetSSchema ("HTML", doc);
1.16      cvs       170:        elType->ElTypeNum = pHTMLGIMapping[i].ThotType;
1.4       cvs       171:        return;
                    172:       }
1.1       cvs       173:       i++;
                    174:     }
1.16      cvs       175:   while (pHTMLGIMapping[i].XMLname[0] == c);
1.1       cvs       176: 
                    177:   /* if not found, look at the XML mapping tables */
1.23      cvs       178:   MapXMLElementType (MATH_TYPE, gi, elType, &ptr, &c, &level, doc);
1.1       cvs       179:   if (elType->ElTypeNum == 0)
1.29      cvs       180:   MapXMLElementType (SVG_TYPE, gi, elType, &ptr, &c, &level, doc);
1.4       cvs       181: }
                    182: 
                    183: /*----------------------------------------------------------------------
                    184:    MapAttr search in all AttributeMappingTables the entry for the
                    185:    attribute of name Attr and returns a pointer to that entry,
                    186:    as well as the corresponding Thot SSchema
                    187:   ----------------------------------------------------------------------*/
1.26      cvs       188: AttributeMapping   *MapAttr (char *attrName, SSchema *schema,
1.24      cvs       189:                             int elemEntry, ThotBool *level, Document doc)
1.4       cvs       190: {
1.20      cvs       191:   typeName          attr, elem;
1.18      cvs       192:   int               i;
1.20      cvs       193:   int               thotType;
                    194: 
1.18      cvs       195:   *schema = TtaGetDocumentSSchema (doc);
1.20      cvs       196:   LowercaseGI (attrName, attr);
                    197:   LowercaseGI (pHTMLGIMapping[elemEntry].XMLname, elem);
1.24      cvs       198:   i = MapXMLAttribute (XHTML_TYPE, attr, elem, level, doc, &thotType);
1.20      cvs       199:   if (i < 0)
1.18      cvs       200:     /* not found */
                    201:     return (NULL);
1.4       cvs       202:   else
1.20      cvs       203:     return (&(pHTMLAttributeMapping[i]));
1.4       cvs       204: }
                    205: 
1.18      cvs       206: 
1.4       cvs       207: /*----------------------------------------------------------------------
1.18      cvs       208:    MapHTMLAttribute
                    209:    Search in the Attribute Mapping Table the entry for the attribute
                    210:    of name Attr and returns the corresponding Thot attribute type.
1.4       cvs       211:   ----------------------------------------------------------------------*/
1.26      cvs       212: AttributeMapping *MapHTMLAttribute (char *attrName,
1.18      cvs       213:                                    AttributeType *attrType,
1.26      cvs       214:                                    char *elementName,
1.24      cvs       215:                                    ThotBool *level,
1.18      cvs       216:                                    Document doc)
1.4       cvs       217: {
1.24      cvs       218:   int             i;
1.4       cvs       219: 
1.18      cvs       220:   attrType->AttrSSchema = GetXHTMLSSchema (doc);
1.24      cvs       221:   i = MapXMLAttribute (XHTML_TYPE, attrName, elementName,
                    222:                       level, doc, &(attrType->AttrTypeNum));
1.20      cvs       223:   if (i < 0)
                    224:     return (NULL);
1.4       cvs       225:   else
1.20      cvs       226:     return (&(pHTMLAttributeMapping[i]));
1.1       cvs       227: }
1.18      cvs       228: 

Webmaster