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