Annotation of Amaya/amaya/fetchXMLname.c, revision 1.69
1.1 cvs 1: /*
2: *
1.65 vatton 3: * (c) COPYRIGHT INRIA and W3C, 1996-2004
1.1 cvs 4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
7:
8: /*
9: *
10: * fetchXMLname
11: *
1.46 cvs 12: * Authors: I. Vatton
13: * L. Carcone
1.1 cvs 14: *
15: */
16:
17: #define THOT_EXPORT extern
18: #include "amaya.h"
19: #include "parser.h"
1.24 cvs 20: #include "HTMLnames.h"
21: #include "MathMLnames.h"
1.49 vatton 22: #include "SVGnames.h"
1.24 cvs 23: #include "XLinknames.h"
24:
1.35 cvs 25: /* define some pointers to let other parser functions access the local table */
1.24 cvs 26: int HTML_ENTRIES = (sizeof(XHTMLElemMappingTable) / sizeof(ElemMapping));
27: ElemMapping *pHTMLGIMapping = XHTMLElemMappingTable;
28: AttributeMapping *pHTMLAttributeMapping = XHTMLAttributeMappingTable;
1.14 cvs 29:
1.35 cvs 30: XmlEntity *pXhtmlEntityTable = XhtmlEntityTable;
31: XmlEntity *pMathEntityTable = MathEntityTable;
1.1 cvs 32:
33: #include "fetchXMLname_f.h"
34:
1.39 cvs 35: /* Global variables used by the entity mapping */
36: static int XHTMLSup = 0;
37: static int MathSup = 0;
38:
1.1 cvs 39: /*----------------------------------------------------------------------
1.14 cvs 40: GetXHTMLSSchema returns the XHTML Thot schema for document doc.
41: ----------------------------------------------------------------------*/
1.55 vatton 42: SSchema GetXHTMLSSchema (Document doc)
1.14 cvs 43: {
44: SSchema XHTMLSSchema;
45:
1.43 cvs 46: XHTMLSSchema = TtaGetSSchema ("HTML", doc);
1.14 cvs 47: if (XHTMLSSchema == NULL)
1.17 cvs 48: XHTMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc),
1.46 cvs 49: "HTML", "HTMLP");
1.14 cvs 50: return (XHTMLSSchema);
51: }
52:
1.54 cvs 53: /*----------------------------------------------------------------------
1.1 cvs 54: GetMathMLSSchema returns the MathML Thot schema for document doc.
55: ----------------------------------------------------------------------*/
1.55 vatton 56: SSchema GetMathMLSSchema (Document doc)
1.1 cvs 57: {
58: SSchema MathMLSSchema;
59:
1.43 cvs 60: MathMLSSchema = TtaGetSSchema ("MathML", doc);
1.13 cvs 61: if (MathMLSSchema == NULL)
1.17 cvs 62: MathMLSSchema = TtaNewNature(doc,
1.46 cvs 63: TtaGetDocumentSSchema(doc),
64: "MathML", "MathMLP");
1.13 cvs 65: return (MathMLSSchema);
1.1 cvs 66: }
67:
68: /*----------------------------------------------------------------------
1.49 vatton 69: GetSVGSSchema returns the SVG Thot schema for document doc.
1.1 cvs 70: ----------------------------------------------------------------------*/
1.55 vatton 71: SSchema GetSVGSSchema (Document doc)
1.1 cvs 72:
73: {
1.49 vatton 74: SSchema SVGSSchema;
1.1 cvs 75:
1.49 vatton 76: SVGSSchema = TtaGetSSchema ("SVG", doc);
77: if (SVGSSchema == NULL)
78: SVGSSchema = TtaNewNature(doc,
1.46 cvs 79: TtaGetDocumentSSchema(doc),
1.49 vatton 80: "SVG", "SVGP");
81: return (SVGSSchema);
1.1 cvs 82: }
83:
84: /*----------------------------------------------------------------------
1.13 cvs 85: GetXLinkSSchema returns the XLink Thot schema for document doc.
86: ----------------------------------------------------------------------*/
1.55 vatton 87: SSchema GetXLinkSSchema (Document doc)
1.13 cvs 88:
89: {
90: SSchema XLinkSSchema;
91:
1.43 cvs 92: XLinkSSchema = TtaGetSSchema ("XLink", doc);
1.13 cvs 93: if (XLinkSSchema == NULL)
1.46 cvs 94: XLinkSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc),
95: "XLink", "XLinkP");
1.13 cvs 96: return (XLinkSSchema);
97: }
98:
99: /*----------------------------------------------------------------------
1.57 kahan 100: GetTextSSchema returns the TextFile Thot schema for document doc.
101: (this is not XML, but its useful to have this function here).
102: ----------------------------------------------------------------------*/
1.66 vatton 103: SSchema GetTextSSchema (Document doc)
1.57 kahan 104:
105: {
106: SSchema XLinkSSchema;
107:
108: XLinkSSchema = TtaGetSSchema ("TextFile", doc);
109: if (XLinkSSchema == NULL)
110: XLinkSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc),
111: "TextFile", "TextFileP");
112: return (XLinkSSchema);
113: }
114:
1.61 cvs 115: /*----------------------------------------------------------------------
116: GetGenericXMLSSchema
117: Returns the XML Thot schema of name schemaName for the document doc.
118: ----------------------------------------------------------------------*/
119: SSchema GetGenericXMLSSchema (char *schemaName, Document doc)
120:
121: {
122: SSchema XMLSSchema;
123:
124: XMLSSchema = TtaGetSSchema (schemaName, doc);
125: if (XMLSSchema == NULL)
126: XMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc),
127: "XML", "XMLP");
128: return (XMLSSchema);
129: }
1.57 kahan 130:
131: /*----------------------------------------------------------------------
1.61 cvs 132: GetGenericXMLSSchemaByUri
133: Returns the XML Thot schema for the document doc.
1.46 cvs 134: ----------------------------------------------------------------------*/
1.55 vatton 135: SSchema GetGenericXMLSSchemaByUri (char *uriName, Document doc, ThotBool *isnew)
1.46 cvs 136:
137: {
138: SSchema XMLSSchema;
139:
140: XMLSSchema = TtaGetSSchemaByUri (uriName, doc);
141: if (XMLSSchema == NULL)
142: {
143: XMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc),
144: "XML", "XMLP");
145: *isnew = TRUE;
146: }
147: return (XMLSSchema);
148: }
149:
150: /*----------------------------------------------------------------------
1.13 cvs 151: GetXMLSSchema returns the XML Thot schema for document doc.
1.1 cvs 152: ----------------------------------------------------------------------*/
1.45 cvs 153: SSchema GetXMLSSchema (int XMLtype, Document doc)
1.38 cvs 154:
1.1 cvs 155: {
1.14 cvs 156: if (XMLtype == XHTML_TYPE)
157: return GetXHTMLSSchema (doc);
158: else if (XMLtype == MATH_TYPE)
1.13 cvs 159: return GetMathMLSSchema (doc);
1.51 cvs 160: else if (XMLtype == SVG_TYPE)
1.49 vatton 161: return GetSVGSSchema (doc);
1.13 cvs 162: else if (XMLtype == XLINK_TYPE)
1.15 cvs 163: return GetXLinkSSchema (doc);
1.13 cvs 164: else
165: return NULL;
1.1 cvs 166: }
167:
168: /*----------------------------------------------------------------------
1.22 cvs 169: MapXMLElementType
170: Generic function which searchs in the Element Mapping table, selected
171: by the parameter XMLtype, the entry XMLname and returns the corresponding
172: Thot element type.
1.55 vatton 173: Returns:
1.22 cvs 174: - ElTypeNum and ElSSchema into elType ElTypeNum = 0 if not found.
1.55 vatton 175: - content information about this entry
176: - checkProfile TRUE if the entry is valid for the current Doc profile.
1.1 cvs 177: ----------------------------------------------------------------------*/
1.55 vatton 178: void MapXMLElementType (int XMLtype, char *XMLname, ElementType *elType,
179: char **mappedName, char *content,
180: ThotBool *checkProfile, Document doc)
1.1 cvs 181: {
1.56 vatton 182: ElemMapping *ptr;
183: char c;
1.66 vatton 184: int i, profile;
1.68 vatton 185: ThotBool xmlformat;
1.1 cvs 186:
1.56 vatton 187: /* Initialize variables */
188: *mappedName = NULL;
189: *checkProfile = TRUE;
190: elType->ElTypeNum = 0;
1.66 vatton 191: profile = TtaGetDocumentProfile (doc);
1.68 vatton 192: /* case sensitive comparison for xml documents */
193: xmlformat = (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat);
194:
1.56 vatton 195: /* Select the right table */
196: if (XMLtype == XHTML_TYPE)
1.69 ! vatton 197: {
! 198: ptr = XHTMLElemMappingTable;
! 199: /* no case sensitive whent there is an explicit "text/html" content_type */
! 200: if (xmlformat && DocumentMeta[doc] && DocumentMeta[doc]->content_type &&
! 201: !strcmp (DocumentMeta[doc]->content_type, "text/html"))
! 202: xmlformat = FALSE;
! 203: }
1.56 vatton 204: else if (XMLtype == MATH_TYPE)
205: {
1.66 vatton 206: if (profile == L_Basic && DocumentTypes[doc] == docHTML)
1.56 vatton 207: {
208: /* Maths are not allowed in this document */
209: ptr = NULL;
210: *checkProfile = FALSE;
211: }
212: else
213: ptr = MathMLElemMappingTable;
214: }
215: else if (XMLtype == SVG_TYPE)
216: {
1.66 vatton 217: if (profile == L_Basic && DocumentTypes[doc] == docHTML)
1.56 vatton 218: {
219: /* Graphics are not allowed in this document */
220: ptr = NULL;
221: *checkProfile = FALSE;
222: }
223: else
224: ptr = SVGElemMappingTable;
225: }
226: else
227: ptr = NULL;
1.32 cvs 228:
1.56 vatton 229: if (ptr)
230: {
231: /* search in the ElemMappingTable */
232: i = 0;
233: /* case insensitive for HTML */
1.68 vatton 234: if (!xmlformat && ptr == XHTMLElemMappingTable)
1.56 vatton 235: c = tolower (XMLname[0]);
236: else
237: c = XMLname[0];
238: /* look for the first concerned entry in the table */
239: while (ptr[i].XMLname[0] < c && ptr[i].XMLname[0] != EOS)
240: i++;
241: /* look at all entries starting with the right character */
242: do
1.68 vatton 243: if (!xmlformat && ptr == XHTMLElemMappingTable &&
244: strcasecmp (ptr[i].XMLname, XMLname))
1.56 vatton 245: /* it's not the tag */
246: i++;
1.68 vatton 247: else if ((xmlformat || ptr != XHTMLElemMappingTable) &&
248: strcmp (ptr[i].XMLname, XMLname))
1.56 vatton 249: /* it's not the tag */
250: i++;
1.66 vatton 251: else if (profile != L_Other && !(ptr[i].Level & profile))
1.56 vatton 252: {
253: /* this tag is not valid in the document profile */
254: *checkProfile = FALSE;
255: i++;
256: }
257: else
258: {
259: elType->ElTypeNum = ptr[i].ThotType;
260: if (elType->ElSSchema == NULL)
261: elType->ElSSchema = GetXMLSSchema (XMLtype, doc);
262: *mappedName = ptr[i].XMLname;
263: *content = ptr[i].XMLcontents;
264: }
265: while (elType->ElTypeNum <= 0 && ptr[i].XMLname[0] == c);
266: }
1.1 cvs 267: }
268:
269:
270: /*----------------------------------------------------------------------
271: GetXMLElementName
1.52 cvs 272: Generic function which searchs in the mapping tables the XML name for
1.22 cvs 273: a given Thot type.
1.1 cvs 274: ----------------------------------------------------------------------*/
1.55 vatton 275: char *GetXMLElementName (ElementType elType, Document doc)
1.1 cvs 276: {
1.46 cvs 277: ElemMapping *ptr;
278: char *name;
1.66 vatton 279: int i, profile;
1.46 cvs 280: ThotBool invalid = FALSE;
1.27 cvs 281:
282: if (elType.ElTypeNum > 0)
283: {
284: i = 0;
285: /* Select the table which matches with the element schema */
286: name = TtaGetSSchemaName (elType.ElSSchema);
1.44 cvs 287: if (strcmp ("MathML", name) == 0)
1.27 cvs 288: ptr = MathMLElemMappingTable;
1.49 vatton 289: else if (strcmp ("SVG", name) == 0)
290: ptr = SVGElemMappingTable;
1.63 quint 291: else if (strcmp ("HTML", name) == 0)
292: ptr = XHTMLElemMappingTable;
1.27 cvs 293: else
1.63 quint 294: ptr = NULL;
295:
1.66 vatton 296: profile = TtaGetDocumentProfile (doc);
1.27 cvs 297: if (ptr)
298: do
299: {
300: if (ptr[i].ThotType == elType.ElTypeNum)
301: {
1.37 cvs 302: if (doc == 0 ||
1.66 vatton 303: profile == L_Other || (ptr[i].Level & profile))
1.27 cvs 304: return ptr[i].XMLname;
305: else
306: invalid = TRUE;
307: }
308: i++;
309: }
1.44 cvs 310: while (ptr[i].XMLname[0] != EOS);
1.27 cvs 311: }
312: if (invalid)
1.43 cvs 313: return "";
1.27 cvs 314: else
1.43 cvs 315: return "???";
1.22 cvs 316: }
1.25 cvs 317:
318:
1.29 cvs 319:
320: /*----------------------------------------------------------------------
1.30 cvs 321: IsXMLElementInline
1.52 cvs 322: Generic function which searchs in the mapping tables if a given
1.29 cvs 323: Thot type is an inline character or not
324: ----------------------------------------------------------------------*/
1.55 vatton 325: ThotBool IsXMLElementInline (ElementType elType, Document doc)
1.29 cvs 326: {
1.34 cvs 327: int i;
328: ThotBool ret = FALSE;
1.45 cvs 329: char *name;
1.34 cvs 330: ElemMapping *ptr;
1.29 cvs 331:
332: if (elType.ElTypeNum > 0)
333: {
334: i = 0;
335: /* Select the table which matches with the element schema */
336: name = TtaGetSSchemaName (elType.ElSSchema);
1.44 cvs 337: if (strcmp ("MathML", name) == 0)
1.29 cvs 338: ptr = MathMLElemMappingTable;
1.49 vatton 339: else if (strcmp ("SVG", name) == 0)
340: ptr = SVGElemMappingTable;
1.52 cvs 341: else if (strcmp ("HTML", name) == 0)
342: ptr = XHTMLElemMappingTable;
1.29 cvs 343: else
1.52 cvs 344: ptr = NULL;
1.29 cvs 345:
346: if (ptr)
347: {
1.44 cvs 348: while (ptr[i].XMLname[0] != EOS &&
1.29 cvs 349: ptr[i].ThotType != elType.ElTypeNum)
350: i++;
351: if (ptr[i].ThotType == elType.ElTypeNum)
1.58 quint 352: ret = ptr[i].InlineElem;
1.29 cvs 353: }
354: }
355: return ret;
356: }
357:
1.22 cvs 358: /*----------------------------------------------------------------------
1.59 vatton 359: MapMathMLAttributeValue
360: Search in the Attribute Value Mapping Table the entry for the attribute
361: ThotAtt and its value attVal. Returns the corresponding Thot value.
362: ----------------------------------------------------------------------*/
1.64 gully 363: void MapXMLAttributeValue (int XMLtype, char *attVal, const AttributeType *attrType,
1.59 vatton 364: int *value)
365: {
366: AttrValueMapping *ptr;
367: int i;
368:
369: /* Select the right table */
370: if (XMLtype == XHTML_TYPE)
1.60 vatton 371: ptr = XhtmlAttrValueMappingTable;
1.59 vatton 372: else if (XMLtype == MATH_TYPE)
373: ptr = MathMLAttrValueMappingTable;
374: else if (XMLtype == SVG_TYPE)
1.60 vatton 375: ptr = SVGAttrValueMappingTable;
1.59 vatton 376: else
377: ptr = NULL;
378:
379: *value = 0;
380: i = 0;
381: if (ptr == NULL)
382: return;
1.64 gully 383: while (ptr[i].ThotAttr != attrType->AttrTypeNum && ptr[i].ThotAttr != 0)
1.59 vatton 384: i++;
1.64 gully 385: if (ptr[i].ThotAttr == attrType->AttrTypeNum)
1.59 vatton 386: do
387: if (!strcmp (ptr[i].XMLattrValue, attVal))
388: *value = ptr[i].ThotAttrValue;
389: else
390: i++;
1.64 gully 391: while (*value == 0 && ptr[i].ThotAttr == attrType->AttrTypeNum);
1.59 vatton 392: }
393:
394:
395: /*----------------------------------------------------------------------
1.24 cvs 396: MapXMLAttribute
1.22 cvs 397: Generic function which searchs in the Attribute Mapping Table (table)
398: the entry attrName associated to the element elementName.
1.24 cvs 399: Returns the corresponding entry or -1.
1.22 cvs 400: ----------------------------------------------------------------------*/
1.55 vatton 401: int MapXMLAttribute (int XMLtype, char *attrName, char *elementName,
402: ThotBool *checkProfile, Document doc, int *thotType)
1.22 cvs 403: {
1.56 vatton 404: AttributeMapping *ptr;
405: char c;
1.66 vatton 406: int i, profile;
1.68 vatton 407: ThotBool xmlformat;
1.24 cvs 408:
1.33 cvs 409: /* Initialization */
1.55 vatton 410: *checkProfile = TRUE;
1.33 cvs 411: i = 1;
412: *thotType = 0;
1.68 vatton 413: /* case sensitive comparison for xml documents */
414: xmlformat = (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat);
1.50 cvs 415:
416: /* Select the right table */
417: if (XMLtype == XHTML_TYPE)
1.69 ! vatton 418: {
! 419: ptr = XHTMLAttributeMappingTable;
! 420: /* no case sensitive whent there is an explicit "text/html" content_type */
! 421: if (xmlformat && DocumentMeta[doc] && DocumentMeta[doc]->content_type &&
! 422: !strcmp (DocumentMeta[doc]->content_type, "text/html"))
! 423: xmlformat = FALSE;
! 424: }
1.50 cvs 425: else if (XMLtype == MATH_TYPE)
426: ptr = MathMLAttributeMappingTable;
1.51 cvs 427: else if (XMLtype == SVG_TYPE)
1.50 cvs 428: ptr = SVGAttributeMappingTable;
429: else if (XMLtype == XLINK_TYPE)
430: ptr = XLinkAttributeMappingTable;
431: else
432: ptr = NULL;
1.24 cvs 433: if (ptr == NULL)
434: return -1;
1.50 cvs 435: if (strcmp (attrName, "unknown_attr") == 0)
436: {
437: *thotType = ptr[0].ThotAttribute;
438: return 0;
439: }
1.22 cvs 440:
1.56 vatton 441: /* case insensitive for HTML */
1.68 vatton 442: if (!xmlformat && ptr == XHTMLAttributeMappingTable)
1.56 vatton 443: c = tolower (attrName[0]);
444: else
445: c = attrName[0];
1.66 vatton 446:
447: profile = TtaGetDocumentProfile (doc);
1.22 cvs 448: /* look for the first concerned entry in the table */
1.56 vatton 449: while (ptr[i].XMLattribute[0] < c && ptr[i].XMLattribute[0] != EOS)
1.22 cvs 450: i++;
1.56 vatton 451: while (ptr[i].XMLattribute[0] == c)
1.22 cvs 452: {
1.68 vatton 453: if (!xmlformat && ptr == XHTMLAttributeMappingTable &&
1.56 vatton 454: (strcasecmp (ptr[i].XMLattribute, attrName) ||
455: (ptr[i].XMLelement[0] != EOS &&
456: strcasecmp (ptr[i].XMLelement, elementName))))
457: i++;
1.68 vatton 458: else if ((xmlformat || ptr != XHTMLAttributeMappingTable) &&
1.56 vatton 459: (strcmp (ptr[i].XMLattribute, attrName) ||
460: (ptr[i].XMLelement[0] != EOS &&
461: strcmp (ptr[i].XMLelement, elementName))))
1.22 cvs 462: i++;
1.66 vatton 463: else if (profile != L_Other && !(ptr[i].Level & profile))
1.33 cvs 464: {
1.55 vatton 465: *checkProfile = FALSE;
1.33 cvs 466: i++;
467: }
1.22 cvs 468: else
1.24 cvs 469: {
1.67 cvs 470: /* Special case for the 'name' attribute for
471: elements 'a' and 'map' in xhtml1.1 profile */
472: if ((profile == L_Xhtml11) &&
473: !strcmp (attrName, "name") &&
474: (!strcmp (elementName, "a") || !strcmp (elementName, "map")))
475: *checkProfile = FALSE;
476: else
477: *thotType = ptr[i].ThotAttribute;
1.24 cvs 478: return (i);
479: }
1.22 cvs 480: }
1.24 cvs 481: return (-1);
1.25 cvs 482: }
483:
484:
485: /*----------------------------------------------------------------------
1.37 cvs 486: GetXMLAttributeName
1.52 cvs 487: Generic function which searchs in the mapping tables the XML name for
1.25 cvs 488: a given Thot type.
489: ----------------------------------------------------------------------*/
1.55 vatton 490: char *GetXMLAttributeName (AttributeType attrType, ElementType elType,
491: Document doc)
1.25 cvs 492: {
493: AttributeMapping *ptr;
1.45 cvs 494: char *name, *tag;
1.66 vatton 495: int i, profile;
1.27 cvs 496: ThotBool invalid = FALSE;
1.25 cvs 497:
1.27 cvs 498: if (attrType.AttrTypeNum > 0)
499: {
1.28 cvs 500: /* get the specific element tag */
501: if (elType.ElTypeNum > 0)
502: tag = GetXMLElementName (elType, doc);
503: else
1.43 cvs 504: tag = "";
1.28 cvs 505:
1.27 cvs 506: i = 0;
507: /* Select the table which matches with the element schema */
508: name = TtaGetSSchemaName (attrType.AttrSSchema);
1.44 cvs 509: if (strcmp ("MathML", name) == 0)
1.27 cvs 510: ptr = MathMLAttributeMappingTable;
1.49 vatton 511: else if (strcmp ("SVG", name) == 0)
512: ptr = SVGAttributeMappingTable;
1.44 cvs 513: else if (strcmp ("XLink", name) == 0)
1.27 cvs 514: ptr = XLinkAttributeMappingTable;
515: else
516: ptr = XHTMLAttributeMappingTable;
517:
1.66 vatton 518: profile = TtaGetDocumentProfile (doc);
1.27 cvs 519: if (ptr)
520: do
521: {
1.28 cvs 522: if (ptr[i].ThotAttribute == attrType.AttrTypeNum &&
1.44 cvs 523: (ptr[i].XMLelement[0] == EOS ||
524: !strcmp (ptr[i].XMLelement, tag)))
1.25 cvs 525: {
1.48 cvs 526: if (doc != 0 &&
1.66 vatton 527: profile != L_Other &&
528: !(ptr[i].Level & profile))
1.48 cvs 529: invalid = TRUE;
530: else
1.25 cvs 531: return ptr[i].XMLattribute;
532: }
533: i++;
1.27 cvs 534: }
1.44 cvs 535: while (ptr[i].XMLattribute[0] != EOS);
1.27 cvs 536: }
537: if (invalid)
1.43 cvs 538: return "";
1.27 cvs 539: else
1.43 cvs 540: return "???";
1.36 cvs 541: }
542:
543: /*----------------------------------------------------------------------
544: MapXMLEntity
545: Generic function which searchs in the Entity Mapping Table (table)
546: the entry entityName and give the corresponding decimal value.
547: Returns FALSE if entityName is not found.
548: ----------------------------------------------------------------------*/
1.46 cvs 549: ThotBool MapXMLEntity (int XMLtype, char *entityName, int *entityValue)
1.36 cvs 550: {
551: XmlEntity *ptr;
552: ThotBool found;
1.38 cvs 553: int inf, sup, med, rescomp;
1.36 cvs 554:
1.38 cvs 555: /* Initialization */
1.36 cvs 556: found = FALSE;
1.42 cvs 557: sup = 0;
1.36 cvs 558:
559: /* Select the right table */
560: if (XMLtype == XHTML_TYPE)
1.39 cvs 561: {
562: ptr = XhtmlEntityTable;
563: if (XHTMLSup == 0)
564: for (XHTMLSup = 0; ptr[XHTMLSup].charCode > 0; XHTMLSup++);
565: sup = XHTMLSup;
566: }
1.36 cvs 567: else if (XMLtype == MATH_TYPE)
1.39 cvs 568: {
569: ptr = MathEntityTable;
570: if (MathSup == 0)
571: for (MathSup = 0; ptr[MathSup].charCode > 0; MathSup++);
572: sup = MathSup;
573: }
1.36 cvs 574: else
575: ptr = NULL;
576:
577: if (ptr == NULL)
1.38 cvs 578: return found;
579:
580: inf = 0;
581: while (sup >= inf && !found)
582: /* Dichotomic research */
1.36 cvs 583: {
1.38 cvs 584: med = (sup + inf) / 2;
1.44 cvs 585: rescomp = strcmp (ptr[med].charName, entityName);
1.38 cvs 586: if (rescomp == 0)
587: {
588: /* entity found */
589: *entityValue = ptr[med].charCode;
590: found = TRUE;
591: }
592: else
593: {
594: if (rescomp > 0)
595: sup = med - 1;
596: else
597: inf = med + 1;
598: }
1.36 cvs 599: }
1.38 cvs 600: return found;
601: }
1.39 cvs 602:
603: /*----------------------------------------------------------------------
604: MapEntityByCode
605: Generic function which searchs in the Entity Mapping Table (table)
606: the entry with code entityValue and give the corresponding name.
607: Returns FALSE if entityValue is not found.
608: ----------------------------------------------------------------------*/
1.40 cvs 609: void MapEntityByCode (int entityValue, char **entityName)
1.39 cvs 610: {
611: XmlEntity *ptr;
612: ThotBool found;
613: int i;
614:
615: /* Select the right table */
1.40 cvs 616: ptr = XhtmlEntityTable;
617: if (ptr)
618: {
1.41 cvs 619: /* look for in the HTML entities table */
1.40 cvs 620: found = FALSE;
1.41 cvs 621: while (ptr && !found)
622: {
623: for (i = 0; ptr[i].charCode >= 0 && !found; i++)
624: found = (ptr[i].charCode == entityValue);
1.39 cvs 625:
1.41 cvs 626: if (found)
627: {
628: /* entity value found */
629: i--;
630: *entityName = (char *) (ptr[i].charName);
631: }
632: else if (ptr != MathEntityTable)
633: /* look for in the Math entities table */
634: ptr = MathEntityTable;
635: else
636: {
637: *entityName = NULL;
638: ptr = NULL;
639: }
1.40 cvs 640: }
641: }
1.39 cvs 642: else
1.40 cvs 643: *entityName = NULL;
1.39 cvs 644: }
Webmaster