/amaya/Xml2thot.c
C | 6164 lines | 4635 code | 463 blank | 1066 comment | 1209 complexity | 9aeb6c61af3f76763d5692ef2d9acfff MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- /*
- *
- * (c) COPYRIGHT INRIA and W3C, 1996-2009
- * Please first read the full copyright statement in file COPYRIGHT.
- *
- */
- /*
- * Xml2thot.c
- *
- * Initializes and launches Expat parser and processes all the events it sent
- * Builds the Thot abstract tree corresponding to the XML document.
- *
- * Authors: L. Carcone
- * V. Quint
- */
- #undef THOT_EXPORT
- #define THOT_EXPORT extern
- #include "amaya.h"
- #include "css.h"
- #include "parser.h"
- #include "zlib.h"
- #include "MathML.h"
- #include "fetchHTMLname.h"
- #include "document.h"
- #include "AHTURLTools_f.h"
- #include "EDITstyle_f.h"
- #include "HTMLactions_f.h"
- #include "HTMLedit_f.h"
- #include "HTMLimage_f.h"
- #include "HTMLtable_f.h"
- #include "HTMLimage_f.h"
- #include "HTMLbook_f.h"
- #include "css_f.h"
- #include "UIcss_f.h"
- #include "fetchHTMLname_f.h"
- #include "fetchXMLname_f.h"
- #include "html2thot_f.h"
- #include "Xml2thot_f.h"
- #include "init_f.h"
- #include "styleparser_f.h"
- #include "XHTMLbuilder_f.h"
- #include "MathMLbuilder_f.h"
- #include "SVGbuilder_f.h"
- #ifdef XML_GENERIC
- #include "Xmlbuilder_f.h"
- #endif /* XML_GENERIC */
- #include "Elemlist.h"
- #ifdef TEMPLATES
- #include "MENUconf.h"
- #include "templates.h"
- #include "Elemlist.h"
- #include "Templatebuilder_f.h"
- #include "templates_f.h"
- #endif /* TEMPLATES */
- #include "XLinkbuilder_f.h"
- #ifdef ANNOTATIONS
- #include "annotlib.h"
- #include "ANNOTtools_f.h"
- #endif /* ANNOTATIONS */
- #include "expat.h"
- #define NS_SEP '|'
- #define NS_COLON ':'
- /* ---------------------- static variables ---------------------- */
- /* Expat parser identifier */
- static XML_Parser Parser = NULL;
- /* global data used by the HTML parser */
- static ParserData XMLcontext = {0, UTF_8, 0, NULL, 0,
- FALSE, FALSE, FALSE, FALSE, FALSE, FALSE};
- /* a parser context. It describes the specific actions to be executed
- when parsing an XML document fragment according to a given DTD */
- typedef struct _XMLparserContext *PtrParserCtxt;
- typedef struct _XMLparserContext
- {
- char *UriName; /* URI of namespaces for that DTD */
- PtrParserCtxt NextParserCtxt; /* next parser context */
- char *SSchemaName; /* name of Thot structure schema */
- SSchema XMLSSchema; /* the Thot structure schema */
- int XMLtype; /* indentifier used by fetchname */
- Proc MapAttribute; /* returns the Thot attribute corresp.
- to an XML attribute name */
- Proc MapAttributeValue; /* returns the Thot value corresp. to
- the name of an XML attribute value */
- Proc CheckContext; /* action to be called to verify if an
- element is allowed in the current
- structural context */
- Proc CheckInsert; /* action to be called to insert an
- element in the abstract tree */
- Proc ElementCreated; /* action to be called when an element
- has been created and inserted */
- Proc ElementComplete; /* action to be called when an element
- has been generated completely */
- Proc AttributeComplete; /* action to be called when an
- attribute has been generated */
- Proc GetDTDName; /* returns the name of the DTD to be
- used for parsing the contents of an
- element that uses a different DTD */
- Proc UnknownNameSpace; /* action to be called if an element
- belongs to a not-suported namespace */
- ThotBool DefaultLineBreak; /* default treatment for white-space */
- ThotBool DefaultLeadingSpace;
- ThotBool DefaultTrailingSpace;
- ThotBool DefaultContiguousSpace;
- /* preserve treatment for white-space */
- ThotBool PreserveLineBreak;
- ThotBool PreserveLeadingSpace;
- ThotBool PreserveTrailingSpace;
- ThotBool PreserveContiguousSpace;
- }
- XMLparserContext;
- /* information about XML languages */
- /* All parser contexts describing known XML DTDs constitute a chain */
- /* first context in the chain*/
- static PtrParserCtxt FirstParserCtxt = NULL;
- /* current context */
- static PtrParserCtxt CurrentParserCtxt = NULL;
- /* XHTML context */
- static PtrParserCtxt XhtmlParserCtxt = NULL;
- /* Generic XML context */
- static PtrParserCtxt GenericXmlParserCtxt = NULL;
- /* Namespaces table */
- #define MAX_NS_TABLE 50
- /* NameSpace prefix (if defined) */
- static char *Ns_Prefix[MAX_NS_TABLE];
- /* NameSpace URI */
- static char *Ns_Uri[MAX_NS_TABLE];
- /* first free element on the table */
- static int Ns_Level = 0;
- /* Current namespaces table */
- static char *CurNs_Prefix[MAX_NS_TABLE];
- static char *CurNs_Uri[MAX_NS_TABLE];
- static int CurNs_Level = 0;
- /* XML Style Sheets table */
- static char *XML_CSS_Href[MAX_NS_TABLE];
- static Document XML_CSS_Doc[MAX_NS_TABLE];
- static Element XML_CSS_El[MAX_NS_TABLE];
- static CSSmedia XML_CSS_Media[MAX_NS_TABLE];
- static int XML_CSS_Level = 0;
- /* Parser Stack */
- /* maximum stack height */
- #define MAX_STACK_HEIGHT 100
- /* XML element name */
- static char *nameElementStack[MAX_STACK_HEIGHT];
- /* element in the Thot abstract tree */
- static Element elementStack[MAX_STACK_HEIGHT];
- /* element language */
- static Language languageStack[MAX_STACK_HEIGHT];
- /* is space preserved for that element */
- static char spacePreservedStack[MAX_STACK_HEIGHT];
- /* context of the element */
- static PtrParserCtxt parserCtxtStack[MAX_STACK_HEIGHT];
- /* first free element on the stack */
- static int stackLevel = 1;
- static gzFile stream = 0;
- /* path or URL of the document */
- static char *docURL = NULL;
- /* save the docURL for some cases of parsing errors */
- static char *docURL2 = NULL;
- /* information about the Thot document under construction */
- /* Document structure schema */
- static SSchema DocumentSSchema = NULL;
- /* root element of the document */
- static Element RootElement;
- /* name of the root element */
- static char *XMLRootName;
- /* root element is closed */
- static ThotBool XMLrootClosed = FALSE;
- /* the last start tag is unknown in the current NS */
- static ThotBool UnknownElement = FALSE;
- /* the last start tag belongs to a non-supported NS */
- static ThotBool UnknownNS = FALSE;
- /* last attribute created */
- static Attribute currentAttribute = NULL;
- /* last created attribute is "unknown_attr"*/
- static ThotBool UnknownAttr;
- /* element with which the last */
- /* attribute has been associated */
- static Element lastAttrElement = NULL;
- /* entry in the AttributeMappingTable */
- /* of the attribute being created */
- static AttributeMapping* lastMappedAttr = NULL;
- /* Comments and PI generated by Amaya are skipped */
- static ThotBool ExtraPI = FALSE;
- /* the document DOCTYPE is currently parsed */
- static ThotBool WithinDoctype = FALSE;
- /* the content of a buffer is being parsed */
- static ThotBool PARSING_BUFFER = FALSE;
- /* parsing errors are not reported for external resources */
- static ThotBool ShowParsingErrors = FALSE;;
- static ThotBool ParsingSubTree = FALSE;
- static ThotBool ImmediatelyAfterTag = FALSE;
- static ThotBool HTMLStyleAttribute = FALSE;
- static ThotBool XMLSpaceAttribute = FALSE;
- static ThotBool ParsingCDATA = FALSE;
- static char currentElementContent = ' ';
- static char currentElementName[100];
- /* Global variable to handle white-space in XML documents */
- static ThotBool RemoveLineBreak = FALSE;
- static ThotBool RemoveLeadingSpace = FALSE;
- static ThotBool RemoveTrailingSpace = FALSE;
- static ThotBool RemoveContiguousSpace = FALSE;
- /* "Extra" counters for the characters and the lines read */
- static int ExtraLineRead = 0;
- static int ExtraOffset = 0;
- static int HtmlLineRead = 0;
- static int HtmlCharRead = 0;
- /* Virtual DOCTYPE Declaration */
- #define DECL_DOCTYPE "<!DOCTYPE html PUBLIC \"\" \"\">\n"
- #define DECL_DOCTYPE_LEN 29
- #define DECL_XML "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"
- #define DECL_XML_LEN 44
- static ThotBool VirtualDoctype = FALSE;
- /* maximum size of error messages */
- #define MaxMsgLength 200
- static void StartOfXmlStartElement (const char *name);
- static void DisableExpatParser ();
- static void XhtmlCheckInsert (Element *el, Element parent, Document doc,
- ThotBool *inserted);
- static void XmlCheckInsert (Element *el, Element parent, Document doc,
- ThotBool *inserted);
- static void XhtmlCheckContext (char *elName, const ElementType * elType,
- ThotBool *isAllowed);
- static void XmlCheckContext (char *elName, const ElementType *elType,
- ThotBool *isAllowed);
- static void XmlParse (FILE *infile, CHARSET charset, ThotBool *xmlDec,
- ThotBool *xmlDoctype);
- /*----------------------------------------------------------------------
- ChangeXmlParserContextByDTD
- Get the parser context correponding to a given DTD
- ----------------------------------------------------------------------*/
- static void ChangeXmlParserContextByDTD (const char *DTDname)
- {
- CurrentParserCtxt = FirstParserCtxt;
- while (CurrentParserCtxt != NULL &&
- strcmp ((char *)DTDname, CurrentParserCtxt->SSchemaName))
- CurrentParserCtxt = CurrentParserCtxt->NextParserCtxt;
- /* initialize the corresponding entry */
- if (CurrentParserCtxt != NULL &&
- CurrentParserCtxt != GenericXmlParserCtxt &&
- CurrentParserCtxt->XMLSSchema == NULL)
- {
- CurrentParserCtxt->XMLSSchema =
- GetXMLSSchema (CurrentParserCtxt->XMLtype, XMLcontext.doc);
- TtaSetUriSSchema (CurrentParserCtxt->XMLSSchema, CurrentParserCtxt->UriName);
- }
- }
- /*----------------------------------------------------------------------
- ChangeXmlParserContextByUri
- Get the parser context correponding to a given namespace uri
- ----------------------------------------------------------------------*/
- static ThotBool ChangeXmlParserContextByUri (char *uriName)
- {
- ThotBool found = FALSE;
- CurrentParserCtxt = FirstParserCtxt;
- while (!found && CurrentParserCtxt)
- {
- if (CurrentParserCtxt->UriName == NULL)
- found = uriName == NULL;
- else if (!strcmp (CurrentParserCtxt->UriName, Template_URI))
- {
- /* Templates */
- if (!strcmp ((char *)uriName, Template_URI) ||
- !strcmp ((char *)uriName, Template_URI_o) ||
- !strcmp ((char *)uriName, Template_URI_f))
- found = TRUE;
- }
- else if (!strcmp ((char *)uriName, CurrentParserCtxt->UriName))
- found = TRUE;
- if (!found)
- CurrentParserCtxt = CurrentParserCtxt->NextParserCtxt;
- }
- /* Initialize the corresponding Thot schema */
- if (CurrentParserCtxt != NULL &&
- CurrentParserCtxt != GenericXmlParserCtxt &&
- CurrentParserCtxt->XMLSSchema == NULL)
- {
- CurrentParserCtxt->XMLSSchema =
- GetXMLSSchema (CurrentParserCtxt->XMLtype, XMLcontext.doc);
- TtaSetUriSSchema (CurrentParserCtxt->XMLSSchema, CurrentParserCtxt->UriName);
- return TRUE;
- }
- return FALSE;
- }
- /*----------------------------------------------------------------------
- InitXmlParserContexts
- Create the chain of parser contexts decribing all recognized XML DTDs
- ----------------------------------------------------------------------*/
- static void InitXmlParserContexts (void)
- {
- PtrParserCtxt ctxt, prevCtxt;
- FirstParserCtxt = NULL;
- prevCtxt = NULL;
- ctxt = NULL;
- /* create and initialize a context for XHTML */
- ctxt = (XMLparserContext*)TtaGetMemory (sizeof (XMLparserContext));
- if (prevCtxt == NULL)
- FirstParserCtxt = ctxt;
- else
- prevCtxt->NextParserCtxt = ctxt;
- ctxt->NextParserCtxt = NULL;
- ctxt->SSchemaName = (char *)TtaGetMemory (NAME_LENGTH);
- strcpy ((char *)ctxt->SSchemaName, "HTML");
- ctxt->UriName = (char *)TtaGetMemory (MAX_URI_NAME_LENGTH);
- strcpy ((char *)ctxt->UriName, (char *)XHTML_URI);
- ctxt->XMLSSchema = NULL;
- ctxt->XMLtype = XHTML_TYPE;
- ctxt->MapAttribute = (Proc) MapHTMLAttribute;
- ctxt->MapAttributeValue = (Proc) MapHTMLAttributeValue;
- ctxt->CheckContext = (Proc) XhtmlCheckContext;
- ctxt->CheckInsert = (Proc) XhtmlCheckInsert;
- ctxt->ElementCreated = NULL;
- ctxt->ElementComplete = (Proc) XhtmlElementComplete;
- ctxt->AttributeComplete = NULL;
- ctxt->GetDTDName = NULL;
- ctxt->UnknownNameSpace = (Proc)UnknownXhtmlNameSpace;
- ctxt->DefaultLineBreak = TRUE;
- ctxt->DefaultLeadingSpace = TRUE;
- ctxt->DefaultTrailingSpace = TRUE;
- ctxt->DefaultContiguousSpace = TRUE;
- ctxt->PreserveLineBreak = FALSE;
- ctxt->PreserveLeadingSpace = FALSE;
- ctxt->PreserveTrailingSpace = FALSE;
- ctxt->PreserveContiguousSpace = FALSE;
- XhtmlParserCtxt = ctxt;
- prevCtxt = ctxt;
- /* create and initialize a context for MathML */
- ctxt = (XMLparserContext*)TtaGetMemory (sizeof (XMLparserContext));
- if (prevCtxt == NULL)
- FirstParserCtxt = ctxt;
- else
- prevCtxt->NextParserCtxt = ctxt;
- ctxt->NextParserCtxt = NULL;
- ctxt->SSchemaName = (char *)TtaGetMemory (NAME_LENGTH);
- strcpy ((char *)ctxt->SSchemaName, "MathML");
- ctxt->UriName = (char *)TtaGetMemory (MAX_URI_NAME_LENGTH);
- strcpy ((char *)ctxt->UriName, (char *)MathML_URI);
- ctxt->XMLSSchema = NULL;
- ctxt->XMLtype = MATH_TYPE;
- ctxt->MapAttribute = (Proc) MapMathMLAttribute;
- ctxt->MapAttributeValue = (Proc) MapMathMLAttributeValue;
- ctxt->CheckContext = (Proc) XmlCheckContext;
- ctxt->CheckInsert = (Proc) XmlCheckInsert;
- ctxt->ElementCreated = (Proc) MathMLElementCreated;
- ctxt->ElementComplete = (Proc) MathMLElementComplete;
- ctxt->AttributeComplete = (Proc) MathMLAttributeComplete;
- ctxt->GetDTDName = (Proc) MathMLGetDTDName;
- ctxt->UnknownNameSpace = (Proc)UnknownMathMLNameSpace;
- ctxt->DefaultLineBreak = TRUE;
- ctxt->DefaultLeadingSpace = TRUE;
- ctxt->DefaultTrailingSpace = TRUE;
- ctxt->DefaultContiguousSpace = TRUE;
- ctxt->PreserveLineBreak = FALSE;
- ctxt->PreserveLeadingSpace = FALSE;
- ctxt->PreserveTrailingSpace = FALSE;
- ctxt->PreserveContiguousSpace = FALSE;
- prevCtxt = ctxt;
- /* create and initialize a context for SVG */
- ctxt = (XMLparserContext*)TtaGetMemory (sizeof (XMLparserContext));
- if (prevCtxt == NULL)
- FirstParserCtxt = ctxt;
- else
- prevCtxt->NextParserCtxt = ctxt;
- ctxt->NextParserCtxt = NULL;
- ctxt->SSchemaName = (char *)TtaGetMemory (NAME_LENGTH);
- strcpy ((char *)ctxt->SSchemaName, "SVG");
- ctxt->UriName = (char *)TtaGetMemory (MAX_URI_NAME_LENGTH);
- strcpy ((char *)ctxt->UriName, (char *)SVG_URI);
- ctxt->XMLSSchema = NULL;
- ctxt->XMLtype = SVG_TYPE;
- ctxt->MapAttribute = (Proc) MapSVGAttribute;
- ctxt->MapAttributeValue = (Proc) MapSVGAttributeValue;
- ctxt->CheckContext = (Proc) XmlCheckContext;
- ctxt->CheckInsert = (Proc) SVGCheckInsert;
- ctxt->ElementCreated = (Proc) SVGElementCreated;
- ctxt->ElementComplete = (Proc) SVGElementComplete;
- ctxt->AttributeComplete = (Proc) SVGAttributeComplete;
- ctxt->GetDTDName = (Proc) SVGGetDTDName;
- ctxt->UnknownNameSpace = (Proc)UnknownSVGNameSpace;
- ctxt->DefaultLineBreak = TRUE;
- ctxt->DefaultLeadingSpace = TRUE;
- ctxt->DefaultTrailingSpace = TRUE;
- ctxt->DefaultContiguousSpace = TRUE;
- ctxt->PreserveLineBreak = TRUE;
- ctxt->PreserveLeadingSpace = FALSE;
- ctxt->PreserveTrailingSpace = FALSE;
- ctxt->PreserveContiguousSpace = FALSE;
- prevCtxt = ctxt;
- #ifdef TEMPLATES
- /* create and initialize a context for Templates */
- ctxt = (XMLparserContext*)TtaGetMemory (sizeof (XMLparserContext));
- if (prevCtxt == NULL)
- FirstParserCtxt = ctxt;
- else
- prevCtxt->NextParserCtxt = ctxt;
- ctxt->NextParserCtxt = NULL;
- ctxt->SSchemaName = (char *)TtaGetMemory (NAME_LENGTH);
- strcpy ((char *)ctxt->SSchemaName, "Template");
- ctxt->UriName = (char *)TtaGetMemory (MAX_URI_NAME_LENGTH);
- strcpy ((char *)ctxt->UriName, (char *)Template_URI);
- ctxt->XMLSSchema = NULL;
- ctxt->XMLtype = Template_TYPE;
- ctxt->MapAttribute = (Proc) MapTemplateAttribute;
- ctxt->MapAttributeValue = (Proc) MapTemplateAttributeValue;
- ctxt->CheckContext = (Proc) XmlCheckContext;
- ctxt->CheckInsert = (Proc) TemplateCheckInsert;
- ctxt->ElementCreated = NULL;
- ctxt->ElementComplete = (Proc) TemplateElementComplete;
- ctxt->AttributeComplete = (Proc) TemplateAttributeComplete;
- ctxt->GetDTDName = (Proc) TemplateGetDTDName;
- ctxt->UnknownNameSpace = (Proc)UnknownTemplateNameSpace;
- ctxt->DefaultLineBreak = TRUE;
- ctxt->DefaultLeadingSpace = TRUE;
- ctxt->DefaultTrailingSpace = TRUE;
- ctxt->DefaultContiguousSpace = TRUE;
- ctxt->PreserveLineBreak = TRUE;
- ctxt->PreserveLeadingSpace = FALSE;
- ctxt->PreserveTrailingSpace = FALSE;
- ctxt->PreserveContiguousSpace = FALSE;
- prevCtxt = ctxt;
- #endif /* TEMPLATES */
- /* create and initialize a context for XLink */
- ctxt = (XMLparserContext*)TtaGetMemory (sizeof (XMLparserContext));
- if (prevCtxt == NULL)
- FirstParserCtxt = ctxt;
- else
- prevCtxt->NextParserCtxt = ctxt;
- ctxt->NextParserCtxt = NULL; /* last context */
- ctxt->SSchemaName = (char *)TtaGetMemory (NAME_LENGTH);
- strcpy ((char *)ctxt->SSchemaName, "XLink");
- ctxt->UriName = (char *)TtaGetMemory (MAX_URI_NAME_LENGTH);
- strcpy ((char *)ctxt->UriName, (char *)XLink_URI);
- ctxt->XMLSSchema = NULL;
- ctxt->XMLtype = XLINK_TYPE;
- ctxt->MapAttribute = (Proc) MapXLinkAttribute;
- ctxt->MapAttributeValue = (Proc) MapXLinkAttributeValue;
- ctxt->CheckContext = (Proc) XmlCheckContext;
- ctxt->CheckInsert = (Proc) XmlCheckInsert;
- ctxt->ElementCreated = NULL;
- ctxt->ElementComplete = NULL;
- ctxt->AttributeComplete = (Proc) XLinkAttributeComplete;
- ctxt->GetDTDName = NULL;
- ctxt->UnknownNameSpace = NULL;
- ctxt->DefaultLineBreak = TRUE;
- ctxt->DefaultLeadingSpace = TRUE;
- ctxt->DefaultTrailingSpace = TRUE;
- ctxt->DefaultContiguousSpace = TRUE;
- ctxt->PreserveLineBreak = FALSE;
- ctxt->PreserveLeadingSpace = FALSE;
- ctxt->PreserveTrailingSpace = FALSE;
- ctxt->PreserveContiguousSpace = FALSE;
- prevCtxt = ctxt;
- #ifdef XML_GENERIC
- /* create and initialize a context for generic XML */
- ctxt = (XMLparserContext*)TtaGetMemory (sizeof (XMLparserContext));
- if (prevCtxt == NULL)
- FirstParserCtxt = ctxt;
- else
- prevCtxt->NextParserCtxt = ctxt;
- ctxt->NextParserCtxt = NULL; /* last context */
- ctxt->SSchemaName = (char *)TtaGetMemory (NAME_LENGTH);
- strcpy ((char *)ctxt->SSchemaName, "XML");
- ctxt->UriName = (char *)TtaGetMemory (MAX_URI_NAME_LENGTH);
- ctxt->UriName[0] = EOS;
- ctxt->XMLSSchema = NULL;
- ctxt->XMLtype = XML_TYPE;
- ctxt->MapAttribute = NULL;
- ctxt->MapAttributeValue = (Proc) MapXmlAttributeValue;
- ctxt->CheckContext = (Proc) XmlCheckContext;
- ctxt->CheckInsert = (Proc) XmlCheckInsert;
- ctxt->ElementCreated = NULL;
- ctxt->ElementComplete = (Proc) XmlElementComplete;
- ctxt->AttributeComplete = (Proc) XmlAttributeComplete;
- ctxt->GetDTDName = NULL;
- ctxt->UnknownNameSpace = NULL;
- ctxt->DefaultLineBreak = TRUE;
- ctxt->DefaultLeadingSpace = TRUE;
- ctxt->DefaultTrailingSpace = TRUE;
- ctxt->DefaultContiguousSpace = TRUE;
- ctxt->PreserveLineBreak = FALSE;
- ctxt->PreserveLeadingSpace = FALSE;
- ctxt->PreserveTrailingSpace = FALSE;
- ctxt->PreserveContiguousSpace = FALSE;
- prevCtxt = ctxt;
- GenericXmlParserCtxt = ctxt;
- #endif /* XML_GENERIC */
- CurrentParserCtxt = NULL;
- }
- /*----------------------------------------------------------------------
- XmlSetElemLineNumber
- Assigns the current line number (number given by EXPAT parser.
- ----------------------------------------------------------------------*/
- void XmlSetElemLineNumber (Element el)
- {
- int lineNumber;
- if (ParsingSubTree)
- lineNumber = 0;
- else
- lineNumber = XML_GetCurrentLineNumber (Parser) + HtmlLineRead - ExtraLineRead;
- TtaSetElementLineNumber (el, lineNumber);
- }
- /*----------------------------------------------------------------------
- XmlParseError
- Print the error message msg on stderr.
- When the line is 0 ask to expat the current line number
- When the variable ShowParsingErrors is set to FALSE,
- the message is ignored (we are parsing an external resource).
- ----------------------------------------------------------------------*/
- void XmlParseError (ErrorType type, unsigned char *msg, int line)
- {
- int pos, n;
- const char *c;
- unsigned char val;
- if (IgnoreErrors)
- return;
- if (!ShowParsingErrors)
- return;
- if (line == 0 && Parser == NULL)
- return;
- if (!ErrFile)
- if (OpenParsingErrors (XMLcontext.doc) == FALSE)
- return;
-
- if (docURL)
- {
- fprintf (ErrFile, "\n*** Errors/warnings in %s\n", docURL);
- TtaFreeMemory (docURL);
- docURL = NULL;
- }
- else
- {
- if (CSSErrorsFound && docURL2)
- {
- fprintf (ErrFile, "\n*** Errors/warnings in %s\n", docURL2);
- TtaFreeMemory (docURL2);
- docURL2 = NULL;
- }
- }
-
- switch (type)
- {
- case errorEncoding:
- fprintf (ErrFile, "@ line 1, char 0: %s\n", msg);
- XMLCharacterNotSupported = TRUE;
- break;
- case errorNotWellFormed:
- if (line == 0)
- {
- if (Parser != NULL)
- {
- line = XML_GetCurrentLineNumber (Parser) + HtmlLineRead - ExtraLineRead;
- /* check if expat found an invalid utf-8 character or an error
- in an attribute value or an invalid entity */
- c = XML_GetInputContext (Parser, &pos, &n);
- if (c)
- val = (unsigned char)(c[pos]);
- else
- val = EOS;
- if (strstr ((char *)msg, "invalid token") && val > 127)
- XMLInvalidToken = TRUE;
- else
- XMLNotWellFormed = TRUE;
- fprintf (ErrFile, "@ line %d, char %d: %s\n", line,
- (int)XML_GetCurrentColumnNumber (Parser), msg);
- }
- }
- else
- {
- fprintf (ErrFile, "@ line %d: %s\n", line, msg);
- XMLNotWellFormed = TRUE;
- }
- break;
- case errorCharacterNotSupported:
- if (line == 0)
- {
- if (Parser != NULL)
- {
- fprintf (ErrFile, "@ line %d, char %d: %s\n",
- (int)XML_GetCurrentLineNumber (Parser) + HtmlLineRead - ExtraLineRead,
- (int)XML_GetCurrentColumnNumber (Parser),
- msg);
- }
- }
- else
- fprintf (ErrFile, "@ line %d: %s\n", line, msg);
- XMLCharacterNotSupported = TRUE;
- break;
- case errorParsing:
- XMLErrorsFound = TRUE;
- case warningMessage:
- if (line == 0)
- {
- if (Parser != NULL)
- {
- fprintf (ErrFile, "@ line %d, char %d: %s\n",
- (int)XML_GetCurrentLineNumber (Parser) + HtmlLineRead - ExtraLineRead,
- (int)XML_GetCurrentColumnNumber (Parser),
- msg);
- }
- }
- else
- fprintf (ErrFile, "@ line %d: %s\n", line, msg);
- break;
- case errorParsingProfile:
- if (line == 0)
- {
- if (Parser != NULL)
- {
- fprintf (ErrFile, "@ line %d, char %d: %s\n",
- (int)XML_GetCurrentLineNumber (Parser) + HtmlLineRead - ExtraLineRead,
- (int)XML_GetCurrentColumnNumber (Parser),
- msg);
- }
- }
- else
- fprintf (ErrFile, "@ line %d: %s\n", line, msg);
- XMLErrorsFoundInProfile = TRUE;
- break;
- case undefinedEncoding:
- fprintf (ErrFile, "@ %s\n", msg);
- break;
- }
- }
- /*----------------------------------------------------------------------
- IsXmlParsingCSS
- Returns the value of ParsingCSS boolean.
- ----------------------------------------------------------------------*/
- ThotBool IsXmlParsingCSS ()
- {
- return XMLcontext.parsingCSS;
- }
- /*----------------------------------------------------------------------
- SetXmlParsingCSS
- Sets the value of ParsingCSS boolean.
- ----------------------------------------------------------------------*/
- void SetXmlParsingCSS (ThotBool value)
- {
- XMLcontext.parsingCSS = value;
- }
- /*----------------------------------------------------------------------
- SetParsingTextArea
- Sets the value of ParsingTextArea boolean.
- ----------------------------------------------------------------------*/
- void SetParsingTextArea (ThotBool value)
- {
- XMLcontext.parsingTextArea = value;
- }
- /*----------------------------------------------------------------------
- SetParsingScript
- Sets the value of ParsingScript boolean.
- ----------------------------------------------------------------------*/
- void SetParsingScript (ThotBool value)
- {
- XMLcontext.parsingScript = value;
- }
- /*----------------------------------------------------------------------
- SetLanguagInXmlStack
- Sets the value of the language.
- ----------------------------------------------------------------------*/
- void SetLanguagInXmlStack (Language lang)
- {
- languageStack[stackLevel - 1] = lang;
- }
- /*----------------------------------------------------------------------
- IsWithinXmlTable
- Returns the value of WithinTable integer.
- ----------------------------------------------------------------------*/
- int IsWithinXmlTable ()
- {
- return XMLcontext.withinTable;
- }
- /*----------------------------------------------------------------------
- SubWithinTable
- ----------------------------------------------------------------------*/
- void SubWithinTable ()
- {
- XMLcontext.withinTable--;
- }
- /*----------------------------------------------------------------------
- XmlWhiteSpaceHandling
- Is there an openend element with a xml:space attribute ?
- ----------------------------------------------------------------------*/
- static void XmlWhiteSpaceHandling ()
- {
- int i;
- ThotBool found;
- if (CurrentParserCtxt == NULL)
- return;
- found = FALSE;
- i = stackLevel - 1;
- while (i > 0 && !found)
- {
- if (spacePreservedStack[i] == ' ')
- i--;
- else
- {
- found = TRUE;
- if (spacePreservedStack[i] == 'D')
- {
- RemoveLineBreak = CurrentParserCtxt->DefaultLineBreak;
- RemoveLeadingSpace = CurrentParserCtxt->DefaultLeadingSpace;
- RemoveTrailingSpace = CurrentParserCtxt->DefaultTrailingSpace;
- RemoveContiguousSpace = CurrentParserCtxt->DefaultContiguousSpace;
- }
- else
- {
- RemoveLineBreak = CurrentParserCtxt->PreserveLineBreak;
- RemoveLeadingSpace = CurrentParserCtxt->PreserveLeadingSpace;
- RemoveTrailingSpace = CurrentParserCtxt->PreserveTrailingSpace;
- RemoveContiguousSpace = CurrentParserCtxt->PreserveContiguousSpace;
- }
- }
- }
-
- if (!found)
- {
- RemoveLineBreak = CurrentParserCtxt->DefaultLineBreak;
- RemoveLeadingSpace = CurrentParserCtxt->DefaultLeadingSpace;
- RemoveTrailingSpace = CurrentParserCtxt->DefaultTrailingSpace;
- RemoveContiguousSpace = CurrentParserCtxt->DefaultContiguousSpace;
- }
- }
- /*----------------------------------------------------------------------
- XmlWhiteInStack
- The last element in stack has a xml:space attribute
- (or it is a pre, style, textarea or script element in XHTML)
- ----------------------------------------------------------------------*/
- static void XmlWhiteSpaceInStack (char *attrValue)
- {
- if (attrValue == NULL)
- spacePreservedStack[stackLevel-1] = 'P';
- else
- {
- if ((strcmp ((char *)attrValue, "default") == 0))
- spacePreservedStack[stackLevel-1] = 'D';
- else
- spacePreservedStack[stackLevel-1] = 'P';
- }
- }
- /*----------------------------------------------------------------------
- XmlWithinStack
- Checks if an element of type ThotType is in the stack.
- ----------------------------------------------------------------------*/
- static ThotBool XmlWithinStack (int ThotType, SSchema ThotSSchema)
- {
- ThotBool ret;
- int i;
- ElementType elType;
- ret = FALSE;
- i = stackLevel - 1;
- while (i >= 0 && !ret)
- {
- if (elementStack[i] != NULL)
- {
- elType = TtaGetElementType (elementStack[i]);
- if (elType.ElTypeNum == ThotType &&
- elType.ElSSchema == ThotSSchema)
- ret = TRUE;
- }
- i--;
- }
- return ret;
- }
- /*----------------------------------------------------------------------
- InsertingSibling
- Return TRUE if the new element must be inserted in the Thot document
- as a sibling of lastElement;
- Return FALSE if it must be inserted as a child.
- ----------------------------------------------------------------------*/
- static ThotBool InsertingSibling ()
- {
- if (stackLevel == 0)
- return FALSE;
- else
- if (XMLcontext.lastElementClosed ||
- TtaIsLeaf (TtaGetElementType (XMLcontext.lastElement)))
- return TRUE;
- else
- return FALSE;
- }
- /*----------------------------------------------------------------------
- XmlGetFallbackCharacter
- Tries to find a fallback character and generates a symbol if necessary
- ----------------------------------------------------------------------*/
- static void XmlGetFallbackCharacter (wchar_t wcharRead, char *entityName,
- Element el)
- {
- ElementType elType;
- Element elLeaf, lastChild;
- AttributeType attrType;
- Attribute attr;
- Language lang;
- unsigned char fallback[5];
- unsigned char bufName[10];
- unsigned char buffer[10];
- unsigned char *ptr;
- int len, i, j;
- lang = XMLcontext.language;
- GetFallbackCharacter ((int) wcharRead, fallback, &lang);
- if (fallback[0] == '?')
- {
- /* Character not found in the fallback table */
- /* Create a symbol leaf */
- elType = TtaGetElementType (el);
- elType.ElTypeNum = 3;
- elLeaf = TtaNewElement (XMLcontext.doc, elType);
- XmlSetElemLineNumber (elLeaf);
- if (el == XMLcontext.lastElement)
- InsertXmlElement (&elLeaf);
- else
- {
- /* within a comment */
- lastChild = TtaGetLastChild (el);
- if (lastChild == NULL)
- TtaInsertFirstChild (&elLeaf, el, XMLcontext.doc);
- else
- TtaInsertSibling (elLeaf, lastChild, FALSE, XMLcontext.doc);
- }
- /* Put the symbol '?' into the new symbol leaf */
- TtaSetGraphicsShape (elLeaf, fallback[0], XMLcontext.doc);
- /* Changes the wide char code associated with that symbol */
- TtaSetSymbolCode (elLeaf, wcharRead, XMLcontext.doc);
- /* Make that leaf read-only */
- TtaSetAccessRight (elLeaf, ReadOnly, XMLcontext.doc);
- }
- else
- {
- /* Character found in the fallback table */
- /* Create a new text leaf */
- elType = TtaGetElementType (el);
- elType.ElTypeNum = 1;
- elLeaf = TtaNewElement (XMLcontext.doc, elType);
- XmlSetElemLineNumber (elLeaf);
- if (el == XMLcontext.lastElement)
- InsertXmlElement (&elLeaf);
- else
- {
- /* within a comment */
- lastChild = TtaGetLastChild (el);
- if (lastChild == NULL)
- TtaInsertFirstChild (&elLeaf, el, XMLcontext.doc);
- else
- TtaInsertSibling (elLeaf, lastChild, FALSE, XMLcontext.doc);
- }
- /* Put the fallback character into the new text leaf */
- TtaSetTextContent (elLeaf, (unsigned char *)fallback, lang, XMLcontext.doc);
- }
-
- /* Associate an attribute EntityName with the new leaf */
- #ifdef TEST
- /* Old treatment to generate an 'entityName' attribute, useless now */
- attrType.AttrSSchema = elType.ElSSchema;
- ptr = (unsigned char*)TtaGetSSchemaName (elType.ElSSchema);
- if (strcmp ((char *)ptr, "MathML") == 0)
- attrType.AttrTypeNum = MathML_ATTR_EntityName;
- else if (strcmp ((char *)ptr, "HTML") == 0)
- attrType.AttrTypeNum = HTML_ATTR_EntityName;
- else
- attrType.AttrTypeNum = HTML_ATTR_EntityName;
- attr = TtaNewAttribute (attrType);
- TtaAttachAttribute (elLeaf, attr, XMLcontext.doc);
- if (entityName)
- /* store the given entity name */
- TtaSetAttributeText (attr, (char *)entityName, elLeaf, XMLcontext.doc);
- else
- {
- /* it's a numerical entity */
- len = sprintf ((char *)buffer, "%d", (int) wcharRead);
- i = 0;
- bufName[i++] = START_ENTITY;
- bufName[i++] = '#';
- for (j = 0; j < len; j++)
- bufName[i++] = buffer[j];
- bufName[i++] = ';';
- bufName[i] = EOS;
- TtaSetAttributeText (attr, (char *)bufName, elLeaf, XMLcontext.doc);
- }
- #endif
- /* genete the 'entityName' attribute for MathML only */
- attrType.AttrSSchema = elType.ElSSchema;
- ptr = (unsigned char*)TtaGetSSchemaName (elType.ElSSchema);
- if (strcmp ((char *)ptr, "MathML") == 0)
- {
- attrType.AttrTypeNum = MathML_ATTR_EntityName;
- attr = TtaNewAttribute (attrType);
- TtaAttachAttribute (elLeaf, attr, XMLcontext.doc);
- if (entityName)
- /* store the given entity name */
- TtaSetAttributeText (attr, (char *)entityName, elLeaf, XMLcontext.doc);
- else
- {
- /* it's a numerical entity */
- len = sprintf ((char *)buffer, "%d", (int) wcharRead);
- i = 0;
- bufName[i++] = START_ENTITY;
- bufName[i++] = '#';
- for (j = 0; j < len; j++)
- bufName[i++] = buffer[j];
- bufName[i++] = ';';
- bufName[i] = EOS;
- TtaSetAttributeText (attr, (char *)bufName, elLeaf, XMLcontext.doc);
- }
- }
- }
- /*----------------------------------------------------------------------
- XmlCheckInsert
- Inserts a Pseudo_paragraph element in the abstract tree if el
- is a math within a XHTML element
- ----------------------------------------------------------------------*/
- static void XmlCheckInsert (Element *el, Element parent,
- Document doc, ThotBool *inserted)
- {
- ElementType newElType, elType, prevType;
- Element newEl, ancestor, prev, prevprev;
-
- if (parent == NULL)
- return;
- elType = TtaGetElementType (*el);
- if (elType.ElTypeNum == MathML_EL_MathML &&
- strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
- {
- ancestor = parent;
- elType = TtaGetElementType (ancestor);
- if (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML"))
- return;
- while (ancestor != NULL &&
- IsXMLElementInline (elType, doc))
- {
- ancestor = TtaGetParent (ancestor);
- elType = TtaGetElementType (ancestor);
- }
-
- if (ancestor != NULL)
- {
- elType = TtaGetElementType (ancestor);
- if (XhtmlCannotContainText (elType) &&
- !XmlWithinStack (HTML_EL_Option_Menu, XhtmlParserCtxt->XMLSSchema))
- {
- /* Element ancestor cannot contain math directly. Create a */
- /* Pseudo_paragraph element as the parent of the math element */
- newElType.ElSSchema = XhtmlParserCtxt->XMLSSchema;
- newElType.ElTypeNum = HTML_EL_Pseudo_paragraph;
- newEl = TtaNewElement (doc, newElType);
- XmlSetElemLineNumber (newEl);
- /* insert the new Pseudo_paragraph element */
- InsertXmlElement (&newEl);
- BlockInCharLevelElem (newEl);
- if (newEl != NULL)
- {
- /* insert the Text element in the tree */
- TtaInsertFirstChild (el, newEl, doc);
- *inserted = TRUE;
-
- /* if previous siblings of the new Pseudo_paragraph element
- are inline elements, move them within the new
- Pseudo_paragraph element */
- prev = newEl;
- TtaPreviousSibling (&prev);
- while (prev != NULL)
- {
- prevType = TtaGetElementType (prev);
- if (IsXMLElementInline (prevType, doc))
- {
- prevprev = prev; TtaPreviousSibling (&prevprev);
- TtaRemoveTree (prev, doc);
- TtaInsertFirstChild (&prev, newEl, doc);
- prev = prevprev;
- }
- else
- prev = NULL;
- }
- }
- }
- }
- }
- return;
- }
- /*----------------------------------------------------------------------
- XhtmlCheckInsert
- Inserts an element Pseudo_paragraph in the abstract tree of
- the Thot document if el is a leaf and is not allowed to be
- a child of element parent.
- If element *el is not a character level element and parent is
- a Pseudo_paragraph, insert *el as a sibling of element parent.
- Return TRUE if element *el has been inserted in the tree.
- ----------------------------------------------------------------------*/
- static void XhtmlCheckInsert (Element *el, Element parent,
- Document doc, ThotBool *inserted)
- {
- ElementType parentType, newElType, elType, prevType, ancestorType;
- Element newEl, ancestor, prev, prevprev;
- int profile;
- char msgBuffer[MaxMsgLength];
- char *typeName;
- if (parent == NULL)
- return;
-
- elType = TtaGetElementType (*el);
- typeName = TtaGetElementTypeName (elType);
- if (elType.ElTypeNum == HTML_EL_TEXT_UNIT ||
- elType.ElTypeNum == HTML_EL_BR ||
- elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
- elType.ElTypeNum == HTML_EL_Input ||
- elType.ElTypeNum == HTML_EL_Text_Area ||
- IsXMLElementInline (elType, doc))
- {
- /* the element to be inserted is a character string */
- /* Search the ancestor that is not a character level element */
- ancestor = parent;
- ancestorType = TtaGetElementType (ancestor);
- while (ancestor &&
- !strcmp (TtaGetSSchemaName (ancestorType.ElSSchema), "Template"))
- {
- // skip template ancestors
- ancestor = TtaGetParent (ancestor);
- ancestorType = TtaGetElementType (ancestor);
- }
- if (strcmp (TtaGetSSchemaName (ancestorType.ElSSchema), "HTML"))
- /* parent is not a HTML element */
- return;
- while (ancestor &&
- IsXMLElementInline (ancestorType, doc))
- {
- ancestor = TtaGetParent (ancestor);
- ancestorType = TtaGetElementType (ancestor);
- }
-
- if (ancestor != NULL)
- {
- elType = TtaGetElementType (ancestor);
- if (XhtmlCannotContainText (elType) &&
- !XmlWithinStack (HTML_EL_Option_Menu, XhtmlParserCtxt->XMLSSchema))
- {
- profile = TtaGetDocumentProfile (XMLcontext.doc);
- if ((profile == L_Basic || profile == L_Strict) &&
- !strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML") &&
- elType.ElTypeNum == HTML_EL_BODY)
- {
- snprintf ((char *)msgBuffer, MaxMsgLength,
- "Element <%s> not allowed outside a block Element - <p> forced", typeName);
- XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
- newElType.ElTypeNum = HTML_EL_Paragraph;
- }
- else
- {
- newElType.ElTypeNum = HTML_EL_Pseudo_paragraph;
- }
- /* Element ancestor cannot contain text directly. Create a */
- /* Pseudo_paragraph element as the parent of the text element */
- newElType.ElSSchema = XhtmlParserCtxt->XMLSSchema;
- newEl = TtaNewElement (doc, newElType);
- XmlSetElemLineNumber (newEl);
- /* insert the new Pseudo_paragraph element */
- InsertXmlElement (&newEl);
- if (newEl != NULL)
- {
- /* insert the Text element in the tree */
- TtaInsertFirstChild (el, newEl, doc);
- BlockInCharLevelElem (newEl);
- *inserted = TRUE;
-
- /* if previous siblings of the new Pseudo_paragraph element
- are character level elements, move them within the new
- Pseudo_paragraph element */
- prev = newEl;
- TtaPreviousSibling (&prev);
- while (prev != NULL)
- {
- prevType = TtaGetElementType (prev);
- if (!IsXMLElementInline (prevType, doc))
- prev = NULL;
- else
- {
- prevprev = prev;
- TtaPreviousSibling (&prevprev);
- TtaRemoveTree (prev, doc);
- TtaInsertFirstChild (&prev, newEl, doc);
- prev = prevprev;
- }
- }
- }
- }
- }
- }
- else
- if (!IsXMLElementInline (elType, doc) &&
- elType.ElTypeNum != HTML_EL_Comment_ &&
- elType.ElTypeNum != HTML_EL_XMLPI)
- /* it is not a character level element nor a comment or a PI */
- /* don't insert it as a child of a Pseudo_paragraph, but as a sibling */
- {
- parentType = TtaGetElementType (parent);
- if (parentType.ElTypeNum == HTML_EL_Pseudo_paragraph)
- {
- TtaInsertSibling (*el, parent, FALSE, doc);
- *inserted = TRUE;
- }
- }
- if (!*inserted)
- if (elType.ElTypeNum == HTML_EL_TEXT_UNIT ||
- (elType.ElTypeNum != HTML_EL_Inserted_Text &&
- IsXMLElementInline (TtaGetElementType (*el), doc)))
- {
- /* it is a character level element */
- parentType = TtaGetElementType (parent);
- if (parentType.ElTypeNum == HTML_EL_Text_Area)
- {
- /* A basic element cannot be a child of a Text_Area */
- /* create a Inserted_Text element as a child of Text_Area */
- newElType.ElSSchema = CurrentParserCtxt->XMLSSchema;
- newElType.ElTypeNum = HTML_EL_Inserted_Text;
- newEl = TtaNewElement (doc, newElType);
- XmlSetElemLineNumber (newEl);
- InsertXmlElement (&newEl);
- if (newEl != NULL)
- {
- TtaInsertFirstChild (el, newEl, doc);
- *inserted = TRUE;
- }
- }
- }
- return;
- }
- /*---------------------------------------------------------------------------
- InsertXmlElement
- Inserts an element el in the Thot abstract tree at the current position.
- ---------------------------------------------------------------------------*/
- void InsertXmlElement (Element *el)
- {
- Element parent;
- ThotBool inserted = FALSE;
- if (CurrentParserCtxt != NULL)
- {
- if (InsertingSibling ())
- {
- if (XMLcontext.lastElement == NULL)
- parent = NULL;
- else
- parent = TtaGetParent (XMLcontext.lastElement);
- (*((Proc4)CurrentParserCtxt->CheckInsert)) ((void *)el,
- (void *)parent,
- (void *)XMLcontext.doc,
- (void *)&inserted);
- if (!inserted)
- {
- if (parent != NULL)
- TtaInsertSibling (*el, XMLcontext.lastElement,
- FALSE, XMLcontext.doc);
- else
- {
- TtaDeleteTree (*el, XMLcontext.doc);
- *el = NULL;
- }
- }
- }
- else
- {
- (*((Proc4)CurrentParserCtxt->CheckInsert)) (
- (void *)el,
- (void *)XMLcontext.lastElement,
- (void *)XMLcontext.doc,
- (void *)&inserted);
- if (!inserted)
- TtaInsertFirstChild (el, XMLcontext.lastElement, XMLcontext.doc);
- }
- if (*el)
- {
- XMLcontext.lastElement = *el;
- XMLcontext.lastElementClosed = FALSE;
- }
- }
- }
- /*----------------------------------------------------------------------
- XmlLastLeafInElement
- return the last leaf element in element el.
- ----------------------------------------------------------------------*/
- Element XmlLastLeafInElement (Element el)
- {
- Element child, lastLeaf;
- ElementType childType;
- child = el;
- lastLeaf = NULL;
- while (child != NULL)
- {
- child = TtaGetLastChild (child);
- if (child != NULL)
- {
- childType = TtaGetElementType (child);
- if (TtaHasReturnCreateNLException (childType))
- child = NULL;
- else
- lastLeaf = child;
- }
- }
- return lastLeaf;
- }
- /*----------------------------------------------------------------------
- RemoveTrailingSpaces
- Removes all trailing spaces at the end of the element.
- ----------------------------------------------------------------------*/
- static void RemoveTrailingSpaces (Element el)
- {
- int length;
- ElementType elType;
- Element lastLeaf, lastChild;
- /* Search the last leaf in the element's tree */
- lastLeaf = XmlLastLeafInElement (el);
- if (lastLeaf)
- {
- elType = TtaGetElementType (lastLeaf);
- if (elType.ElTypeNum == 1)
- /* the last leaf is a TEXT element */
- {
- length = TtaGetElementVolume (lastLeaf);
- if (length > 0)
- TtaRemoveFinalSpaces (lastLeaf, XMLcontext.doc,
- RemoveTrailingSpace);
- }
- }
- /* create an empty text element after the math element */
- if (CurrentParserCtxt &&
- strcmp ((char *)CurrentParserCtxt->SSchemaName, "HTML") == 0)
- {
- lastChild = TtaGetLastChild (el);
- if (lastChild)
- {
- elType = TtaGetElementType (lastChild);
- if (elType.ElTypeNum == MathML_EL_MathML &&
- !strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
- /* the last child of this HTML element is a <math> element */
- {
- /* create an empty text element after the math element */
- elType.ElSSchema = CurrentParserCtxt->XMLSSchema;
- elType.ElTypeNum = HTML_EL_TEXT_UNIT;
- lastLeaf = TtaNewElement (XMLcontext.doc, elType);
- TtaInsertSibling (lastLeaf, lastChild, FALSE, XMLcontext.doc);
- }
- }
- }
- }
- /*----------------------------------------------------------------------
- XmlCloseElement
- Terminate the corresponding Thot element.
- ----------------------------------------------------------------------*/
- static ThotBool XmlCloseElement (char *mappedName)
- {
- int i, error;
- Element el, parent, pseudo;
- ElementType parentType, elType;
- ThotBool ret, spacesDeleted;
- ret = FALSE;
- if (stackLevel > 0)
- {
- el = XMLcontext.lastElement;
- if (XMLcontext.lastElementClosed)
- el = TtaGetParent (el);
- i = stackLevel - 1;
- if (i >= 0 && mappedName == nameElementStack[i])
- /* element found in the stack */
- {
- /* This element and its whole subtree are closed */
- stackLevel = i;
- XMLcontext.lastElement = elementStack[i];
- XMLcontext.lastElementClosed = TRUE;
- ret = TRUE;
- }
- else
- {
- /* element not found in the stack */
- if (XMLcontext.lastElement != NULL)
- {
- /* implicit close. Check the parent of current element */
- if (InsertingSibling ())
- parent = TtaGetParent (XMLcontext.lastElement);
- else
- parent = XMLcontext.lastElement;
- if (parent != NULL)
- {
- parentType = TtaGetElementType (parent);
- if ((!strcmp (TtaGetSSchemaName (parentType.ElSSchema), "HTML")) &&
- parentType.ElTypeNum == HTML_EL_Pseudo_paragraph)
- {
- XMLcontext.lastElement = parent;
- XMLcontext.lastElementClosed = TRUE;
- ret = TRUE;
- }
- }
- }
- }
- if (ret)
- /* successful close */
- {
- /* remove closed elements from the stack */
- while (i > 0)
- if (elementStack[i] == XMLcontext.lastElement)
- {
- stackLevel = i;
- i = 0;
- }
- else
- {
- if (TtaIsAncestor (elementStack[i], XMLcontext.lastElement))
- stackLevel = i;
- i--;
- }
- /* complete all closed elements */
- if (el != XMLcontext.lastElement)
- if (!TtaIsAncestor (el, XMLcontext.lastElement))
- el = NULL;
-
- spacesDeleted = FALSE;
- while (el != NULL)
- {
- /* If the element closed is a block-element, remove */
- /* spaces contained at the end of that element */
- /*
- if (!spacesDeleted)
- spacesDeleted = RemoveEndingSpaces (el);
- */
- /* Remove the trailing spaces of that element */
- RemoveTrailingSpaces (el);
-
- /* Remove the trailing spaces for included pseudo-paragraph */
- elType = TtaGetElementType (el);
- if (!strcmp (TtaGetSSchemaName (elType…
Large files files are truncated, but you can click here to view the full file