xref: /aoo41x/main/xml2cmp/source/xcd/parse.cxx (revision 2afa04a6)
1ab595ff6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ab595ff6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ab595ff6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ab595ff6SAndrew Rist  * distributed with this work for additional information
6ab595ff6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ab595ff6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ab595ff6SAndrew Rist  * "License"); you may not use this file except in compliance
9ab595ff6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10ab595ff6SAndrew Rist  *
11ab595ff6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ab595ff6SAndrew Rist  *
13ab595ff6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ab595ff6SAndrew Rist  * software distributed under the License is distributed on an
15ab595ff6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ab595ff6SAndrew Rist  * KIND, either express or implied.  See the License for the
17ab595ff6SAndrew Rist  * specific language governing permissions and limitations
18ab595ff6SAndrew Rist  * under the License.
19ab595ff6SAndrew Rist  *
20ab595ff6SAndrew Rist  *************************************************************/
21ab595ff6SAndrew Rist 
22ab595ff6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <parse.hxx>
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <string.h>
28cdf0e10cSrcweir #include <iostream>
29cdf0e10cSrcweir #include <xmlelem.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #if (_MSC_VER >=1400)
32cdf0e10cSrcweir #pragma warning(disable:4365)
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #ifdef UNX
36cdf0e10cSrcweir #define strnicmp strncasecmp
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #define AssertionOf(x)	\
46cdf0e10cSrcweir 	{if (!(x)) {std::cerr << "Assertion failed: " << #x << __FILE__ << __LINE__ << std::endl; exit(3); }}
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 
X2CParser(XmlElement & o_rDocumentData)50cdf0e10cSrcweir X2CParser::X2CParser( XmlElement & o_rDocumentData )
51cdf0e10cSrcweir 	:	// sFileName,
52cdf0e10cSrcweir 		nFileLine(0),
53cdf0e10cSrcweir 		pDocumentData(&o_rDocumentData),
54cdf0e10cSrcweir         // sWord,
55cdf0e10cSrcweir 		text(0)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
~X2CParser()59cdf0e10cSrcweir X2CParser::~X2CParser()
60cdf0e10cSrcweir {
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 
64cdf0e10cSrcweir bool
LoadFile(const char * i_sFilename)65cdf0e10cSrcweir X2CParser::LoadFile( const char * i_sFilename )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	sFileName = i_sFilename;
68cdf0e10cSrcweir 	nFileLine = 1;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	// Load file:
71cdf0e10cSrcweir 	if ( ! LoadXmlFile( aFile, i_sFilename ) )
72cdf0e10cSrcweir 		return false;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	// Test correct end:
75cdf0e10cSrcweir 	const char * pLastTag = strrchr(aFile.operator const char *(),'<');
76cdf0e10cSrcweir 	if (pLastTag == 0)
77cdf0e10cSrcweir 		return false;
78cdf0e10cSrcweir 	if ( strnicmp(pLastTag+2, pDocumentData->Name().str(), pDocumentData->Name().l()) != 0
79cdf0e10cSrcweir 		 || strnicmp(pLastTag, "</", 2) != 0 )
80cdf0e10cSrcweir 		return false;
81cdf0e10cSrcweir 	if (strchr(pLastTag,'>') == 0)
82cdf0e10cSrcweir 		return false;
83cdf0e10cSrcweir 	return true;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir void
Parse()87cdf0e10cSrcweir X2CParser::Parse()
88cdf0e10cSrcweir {
89cdf0e10cSrcweir 	// Parse:
90cdf0e10cSrcweir 	text = aFile.operator const char *();
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	Parse_XmlDeclaration();
93cdf0e10cSrcweir 	Parse_Doctype();
94cdf0e10cSrcweir 
95*2afa04a6SOliver-Rainer Wittmann     // skip XML comment
96*2afa04a6SOliver-Rainer Wittmann     Goto('<');
97*2afa04a6SOliver-Rainer Wittmann     if ( IsText("<!--") )
98*2afa04a6SOliver-Rainer Wittmann         Goto_And_Pass('>');
99*2afa04a6SOliver-Rainer Wittmann 
100cdf0e10cSrcweir 	pDocumentData->Parse(*this);
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir bool
Parse(const char * i_sFilename)104cdf0e10cSrcweir X2CParser::Parse( const char * i_sFilename )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir 	bool ret = LoadFile(i_sFilename);
107cdf0e10cSrcweir 	if (ret)
108cdf0e10cSrcweir 		Parse();
109cdf0e10cSrcweir 	return ret;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir void
Parse_XmlDeclaration()113cdf0e10cSrcweir X2CParser::Parse_XmlDeclaration()
114cdf0e10cSrcweir {
115cdf0e10cSrcweir 	Goto('<');
116cdf0e10cSrcweir 	if ( IsText("<?xml") )
117cdf0e10cSrcweir 	{
118cdf0e10cSrcweir 		Goto_And_Pass('>');
119cdf0e10cSrcweir 	}
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir void
Parse_Doctype()123cdf0e10cSrcweir X2CParser::Parse_Doctype()
124cdf0e10cSrcweir {
125cdf0e10cSrcweir 	Goto('<');
126cdf0e10cSrcweir 	if ( IsText("<!DOCTYPE") )
127cdf0e10cSrcweir 		Goto_And_Pass('>');
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir void
Parse_Sequence(DynamicList<XmlElement> & o_rElements,const Simstr & i_sElementName)131cdf0e10cSrcweir X2CParser::Parse_Sequence( DynamicList<XmlElement> & o_rElements,
132cdf0e10cSrcweir 						   const Simstr &			 i_sElementName  )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	CheckAndPassBeginTag(i_sElementName.str());
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	unsigned int i_max = o_rElements.size();
137cdf0e10cSrcweir 	for (unsigned i = 0; i < i_max; ++i)
138cdf0e10cSrcweir 	{
139cdf0e10cSrcweir 		o_rElements[i]->Parse(*this);
140cdf0e10cSrcweir 	}  // end for
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	CheckAndPassEndTag(i_sElementName.str());
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir void
Parse_FreeChoice(DynamicList<XmlElement> & o_rElements)146cdf0e10cSrcweir X2CParser::Parse_FreeChoice( DynamicList<XmlElement> & o_rElements )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir 	unsigned     	nSize = o_rElements.size();
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 	for ( bool bBreak = false;  !bBreak; )
151cdf0e10cSrcweir 	{
152cdf0e10cSrcweir 		bBreak = true;
153cdf0e10cSrcweir 		for ( unsigned i = 0; i < nSize; ++i )
154cdf0e10cSrcweir 		{
155cdf0e10cSrcweir 			Goto('<');
156cdf0e10cSrcweir 			if ( IsBeginTag(o_rElements[i]->Name().str()) )
157cdf0e10cSrcweir 			{
158cdf0e10cSrcweir 				o_rElements[i]->Parse(*this);
159cdf0e10cSrcweir 				bBreak = false;
160cdf0e10cSrcweir 				break;
161cdf0e10cSrcweir 			}
162cdf0e10cSrcweir 		}  	// end for i
163cdf0e10cSrcweir 	} 	// end for !bBreak
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir void
Parse_List(ListElement & o_rListElem)167cdf0e10cSrcweir X2CParser::Parse_List( ListElement &  o_rListElem )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 	for ( Goto('<'); IsBeginTag(o_rListElem.Name().str()); Goto('<') )
171cdf0e10cSrcweir 	{
172cdf0e10cSrcweir 		XmlElement * pNew = o_rListElem.Create_and_Add_NewElement();
173cdf0e10cSrcweir 		pNew->Parse(*this);
174cdf0e10cSrcweir 	}
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir void
Parse_Text(Simstr & o_sText,const Simstr & i_sElementName,bool i_bReverseName)178cdf0e10cSrcweir X2CParser::Parse_Text( Simstr &			o_sText,
179cdf0e10cSrcweir 					   const Simstr &	i_sElementName,
180cdf0e10cSrcweir 					   bool				i_bReverseName )
181cdf0e10cSrcweir {
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 	if ( ! CheckAndPassBeginTag(i_sElementName.str()) )
184cdf0e10cSrcweir         return;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 	// Add new Element
187cdf0e10cSrcweir 	GetTextTill( o_sText, '<', i_bReverseName );
188cdf0e10cSrcweir 	o_sText.remove_trailing_blanks();
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	CheckAndPassEndTag(i_sElementName.str());
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir void
Parse_MultipleText(List<Simstr> & o_rTexts,const Simstr & i_sElementName,bool i_bReverseName)194cdf0e10cSrcweir X2CParser::Parse_MultipleText( List<Simstr> &	o_rTexts,
195cdf0e10cSrcweir 							   const Simstr &	i_sElementName,
196cdf0e10cSrcweir 							   bool				i_bReverseName )
197cdf0e10cSrcweir {
198cdf0e10cSrcweir 	for ( Goto('<'); IsBeginTag(i_sElementName.str()); Goto('<') )
199cdf0e10cSrcweir 	{
200cdf0e10cSrcweir         Simstr sNew;
201cdf0e10cSrcweir 		Parse_Text(sNew, i_sElementName, i_bReverseName);
202cdf0e10cSrcweir         if (sNew.l() > 0)
203cdf0e10cSrcweir     		o_rTexts.push_back(sNew);
204cdf0e10cSrcweir 	}
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir void
Parse_SglAttr(Simstr & o_sAttrValue,const Simstr & i_sElementName,const Simstr & i_sAttrName)208cdf0e10cSrcweir X2CParser::Parse_SglAttr( Simstr &			o_sAttrValue,
209cdf0e10cSrcweir 						  const Simstr &	i_sElementName,
210cdf0e10cSrcweir 						  const Simstr &	i_sAttrName )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir 	Goto('<');
213cdf0e10cSrcweir 	if ( !IsBeginTag(i_sElementName.str()) )
214cdf0e10cSrcweir 		SyntaxError("unexpected element");
215cdf0e10cSrcweir 	Move( i_sElementName.l() + 1 );
216cdf0e10cSrcweir 
217cdf0e10cSrcweir 	Pass_White();
218cdf0e10cSrcweir 	if (*text == '>')
219cdf0e10cSrcweir 		SyntaxError("no attribute found, where one was expected");
220cdf0e10cSrcweir 	Simstr sAttrName;
221cdf0e10cSrcweir 	Get_Attribute(o_sAttrValue, sAttrName);
222cdf0e10cSrcweir 	if (sAttrName != i_sAttrName)
223cdf0e10cSrcweir 		SyntaxError("unknown attribute found");
224cdf0e10cSrcweir 	Pass_White();
225cdf0e10cSrcweir 	if (strncmp(text,"/>",2) != 0)
226cdf0e10cSrcweir 		SyntaxError("missing \"/>\" at end of empty element");
227cdf0e10cSrcweir 	Move(2);
228cdf0e10cSrcweir }
229cdf0e10cSrcweir 
230cdf0e10cSrcweir void
Parse_MultipleAttr(List<Simstr> & o_rAttrValues,const Simstr & i_sElementName,const List<Simstr> & i_rAttrNames)231cdf0e10cSrcweir X2CParser::Parse_MultipleAttr( List<Simstr> &		o_rAttrValues,
232cdf0e10cSrcweir 							   const Simstr &		i_sElementName,
233cdf0e10cSrcweir 							   const List<Simstr> &	i_rAttrNames )
234cdf0e10cSrcweir {
235cdf0e10cSrcweir 	Goto('<');
236cdf0e10cSrcweir 	if ( !IsBeginTag(i_sElementName.str()) )
237cdf0e10cSrcweir 		SyntaxError("unexpected element");
238cdf0e10cSrcweir 	Move( i_sElementName.l() + 1 );
239cdf0e10cSrcweir 	Simstr sAttrName;
240cdf0e10cSrcweir 	Simstr sAttrValue;
241cdf0e10cSrcweir 	unsigned nSize = i_rAttrNames.size();
242cdf0e10cSrcweir 	unsigned i;
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 	for ( Pass_White(); *text != '/'; Pass_White() )
245cdf0e10cSrcweir 	{
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 		Get_Attribute(sAttrValue, sAttrName);
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 		for ( i = 0; i < nSize; ++i )
250cdf0e10cSrcweir 		{
251cdf0e10cSrcweir 			if ( i_rAttrNames[i] == sAttrName )
252cdf0e10cSrcweir             {
253cdf0e10cSrcweir 				o_rAttrValues[i] = sAttrValue;
254cdf0e10cSrcweir 				break;
255cdf0e10cSrcweir 			}
256cdf0e10cSrcweir 		}
257cdf0e10cSrcweir 		if (i == nSize)
258cdf0e10cSrcweir 			SyntaxError("unknown attribute found");
259cdf0e10cSrcweir 	}
260cdf0e10cSrcweir 	Move(2);
261cdf0e10cSrcweir }
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 
264cdf0e10cSrcweir void
Get_Attribute(Simstr & o_rAttrValue,Simstr & o_rAttrName)265cdf0e10cSrcweir X2CParser::Get_Attribute( Simstr & o_rAttrValue,
266cdf0e10cSrcweir 						  Simstr & o_rAttrName )
267cdf0e10cSrcweir {
268cdf0e10cSrcweir 	GetTextTill( o_rAttrName, '=');
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 	while (*(++text) != '"')
271cdf0e10cSrcweir 	{
272cdf0e10cSrcweir 		if (*text == '\0')
273cdf0e10cSrcweir 			SyntaxError("unexpected end of file");
274cdf0e10cSrcweir 	}
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 	++text;
277cdf0e10cSrcweir 	GetTextTill( o_rAttrValue, '"');
278cdf0e10cSrcweir 	++text;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir bool
IsText(const char * i_sComparedText)282cdf0e10cSrcweir X2CParser::IsText( const char *	i_sComparedText )
283cdf0e10cSrcweir {
284cdf0e10cSrcweir 	return strnicmp( text, i_sComparedText, strlen(i_sComparedText) ) == 0;
285cdf0e10cSrcweir }
286cdf0e10cSrcweir 
287cdf0e10cSrcweir bool
IsBeginTag(const char * i_sTagName)288cdf0e10cSrcweir X2CParser::IsBeginTag( const char *	i_sTagName )
289cdf0e10cSrcweir {
290cdf0e10cSrcweir 	return strnicmp( text+1, i_sTagName, strlen(i_sTagName) ) == 0
291cdf0e10cSrcweir 		   && *text == '<';
292cdf0e10cSrcweir }
293cdf0e10cSrcweir 
294cdf0e10cSrcweir bool
IsEndTag(const char * i_sTagName)295cdf0e10cSrcweir X2CParser::IsEndTag( const char * i_sTagName )
296cdf0e10cSrcweir {
297cdf0e10cSrcweir 	return strnicmp( text+2, i_sTagName, strlen(i_sTagName) ) == 0
298cdf0e10cSrcweir 		   && strnicmp( text, "</", 2 ) == 0;
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir void
Goto(char i_cNext)302cdf0e10cSrcweir X2CParser::Goto( char i_cNext )
303cdf0e10cSrcweir {
304cdf0e10cSrcweir 	while (*text != i_cNext)
305cdf0e10cSrcweir 	{
306cdf0e10cSrcweir 		TestCurChar();
307cdf0e10cSrcweir 		++text;
308cdf0e10cSrcweir 	}
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
311cdf0e10cSrcweir void
Goto_And_Pass(char i_cNext)312cdf0e10cSrcweir X2CParser::Goto_And_Pass( char i_cNext )
313cdf0e10cSrcweir {
314cdf0e10cSrcweir 	Goto(i_cNext);
315cdf0e10cSrcweir 	++text;
316cdf0e10cSrcweir }
317cdf0e10cSrcweir 
318cdf0e10cSrcweir void
Move(int i_nForward)319cdf0e10cSrcweir X2CParser::Move( int i_nForward )
320cdf0e10cSrcweir {
321cdf0e10cSrcweir 	text += i_nForward;
322cdf0e10cSrcweir }
323cdf0e10cSrcweir 
324cdf0e10cSrcweir void
Pass_White()325cdf0e10cSrcweir X2CParser::Pass_White()
326cdf0e10cSrcweir {
327cdf0e10cSrcweir 	while (*text <= 32)
328cdf0e10cSrcweir 	{
329cdf0e10cSrcweir 		TestCurChar();
330cdf0e10cSrcweir 		++text;
331cdf0e10cSrcweir 	}
332cdf0e10cSrcweir }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir void
GetTextTill(Simstr & o_rText,char i_cEnd,bool i_bReverseName)335cdf0e10cSrcweir X2CParser::GetTextTill( Simstr & o_rText,
336cdf0e10cSrcweir 						char     i_cEnd,
337cdf0e10cSrcweir 						bool     i_bReverseName )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir 	char * pResult = &sWord[0];
340cdf0e10cSrcweir 	char * pSet;
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 	for ( pSet = pResult;
343cdf0e10cSrcweir 		  *text != i_cEnd;
344cdf0e10cSrcweir 		  ++text )
345cdf0e10cSrcweir 	{
346cdf0e10cSrcweir 		TestCurChar();
347cdf0e10cSrcweir 		*pSet++ = *text;
348cdf0e10cSrcweir 	}
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 	while ( *pResult < 33 && *pResult > 0 )
351cdf0e10cSrcweir 		++pResult;
352cdf0e10cSrcweir 	while ( pSet > pResult ? *(pSet-1) < 33 : false )
353cdf0e10cSrcweir 		pSet--;
354cdf0e10cSrcweir 	*pSet = '\0';
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 
357cdf0e10cSrcweir 	if (i_bReverseName)
358cdf0e10cSrcweir 	{
359cdf0e10cSrcweir         const unsigned int nMaxLen = 1000;
360cdf0e10cSrcweir         if (strlen(pResult) < nMaxLen)
361cdf0e10cSrcweir         {
362cdf0e10cSrcweir     		char * sBreak = strrchr(pResult,'.');
363cdf0e10cSrcweir 	    	if (sBreak != 0)
364cdf0e10cSrcweir 		    {
365cdf0e10cSrcweir 			    static char sScope[nMaxLen+10];
366cdf0e10cSrcweir     			static char sName[nMaxLen+10];
367cdf0e10cSrcweir 
368cdf0e10cSrcweir         		unsigned nScopeLen = sBreak - pResult;
369cdf0e10cSrcweir 		    	strncpy ( sScope, pResult, nScopeLen ); // STRNCPY SAFE HERE
370cdf0e10cSrcweir 			    sScope[nScopeLen] = '\0';
371cdf0e10cSrcweir 			    strcpy( sName, sBreak + 1 );            // STRCPY SAFE HERE
372cdf0e10cSrcweir 			    strcat( sName, " in " );                // STRCAT SAFE HERE
373cdf0e10cSrcweir 			    strcat( sName, sScope );                // STRCAT SAFE HERE
374cdf0e10cSrcweir 
375cdf0e10cSrcweir 			    o_rText = sName;
376cdf0e10cSrcweir 			    return;
377cdf0e10cSrcweir 		    }
378cdf0e10cSrcweir         }
379cdf0e10cSrcweir 	}   // endif (i_bReverseName)
380cdf0e10cSrcweir 
381cdf0e10cSrcweir 	o_rText = &sWord[0];
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
384cdf0e10cSrcweir bool
CheckAndPassBeginTag(const char * i_sElementName)385cdf0e10cSrcweir X2CParser::CheckAndPassBeginTag( const char * i_sElementName )
386cdf0e10cSrcweir {
387cdf0e10cSrcweir     bool ret = true;
388cdf0e10cSrcweir 	Goto('<');
389cdf0e10cSrcweir 	if ( ! IsBeginTag(i_sElementName) )
390cdf0e10cSrcweir 		SyntaxError( "unexpected element");
391cdf0e10cSrcweir     if (IsAbsoluteEmpty())
392cdf0e10cSrcweir         ret = false;
393cdf0e10cSrcweir 	Goto_And_Pass('>');
394cdf0e10cSrcweir     if (ret)
395cdf0e10cSrcweir 	    Pass_White();
396cdf0e10cSrcweir     return ret;
397cdf0e10cSrcweir }
398cdf0e10cSrcweir 
399cdf0e10cSrcweir void
CheckAndPassEndTag(const char * i_sElementName)400cdf0e10cSrcweir X2CParser::CheckAndPassEndTag( const char *	i_sElementName )
401cdf0e10cSrcweir {
402cdf0e10cSrcweir 	Pass_White();
403cdf0e10cSrcweir 	if ( !IsEndTag(i_sElementName) )
404cdf0e10cSrcweir 		SyntaxError("missing or not matching end tag");
405cdf0e10cSrcweir 	Goto_And_Pass('>');
406cdf0e10cSrcweir }
407cdf0e10cSrcweir 
408cdf0e10cSrcweir bool
IsAbsoluteEmpty() const409cdf0e10cSrcweir X2CParser::IsAbsoluteEmpty() const
410cdf0e10cSrcweir {
411cdf0e10cSrcweir 	const char * pEnd = strchr(text+1, '>');
412cdf0e10cSrcweir     if (pEnd != 0)
413cdf0e10cSrcweir     {
414cdf0e10cSrcweir         if ( *(pEnd-1) == '/' )
415cdf0e10cSrcweir         {
416cdf0e10cSrcweir             const char * pAttr = strchr(text+1, '"');
417cdf0e10cSrcweir          	if (pAttr == 0)
418cdf0e10cSrcweir                 return true;
419cdf0e10cSrcweir             else if ( (pAttr-text) > (pEnd-text) )
420cdf0e10cSrcweir                 return true;
421cdf0e10cSrcweir         }
422cdf0e10cSrcweir     }
423cdf0e10cSrcweir     return false;
424cdf0e10cSrcweir }
425cdf0e10cSrcweir 
426cdf0e10cSrcweir void
SyntaxError(const char * i_sText)427cdf0e10cSrcweir X2CParser::SyntaxError( const char * i_sText )
428cdf0e10cSrcweir {
429cdf0e10cSrcweir 	std::cerr
430cdf0e10cSrcweir          << "Syntax error "
431cdf0e10cSrcweir 		 << i_sText
432cdf0e10cSrcweir 		 << " in file: "
433cdf0e10cSrcweir 		 << sFileName.str()
434cdf0e10cSrcweir 		 << " in line "
435cdf0e10cSrcweir 		 << nFileLine
436cdf0e10cSrcweir 		 << "."
437cdf0e10cSrcweir 		 << std::endl;
438cdf0e10cSrcweir 
439cdf0e10cSrcweir 	 exit(3);
440cdf0e10cSrcweir }
441cdf0e10cSrcweir 
442cdf0e10cSrcweir void
TestCurChar()443cdf0e10cSrcweir X2CParser::TestCurChar()
444cdf0e10cSrcweir {
445cdf0e10cSrcweir //	if (*text == '\0')
446cdf0e10cSrcweir //		SyntaxError("unexpected end of file");
447cdf0e10cSrcweir //	else
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 	if (*text == '\n')
450cdf0e10cSrcweir 		nFileLine++;
451cdf0e10cSrcweir }
452cdf0e10cSrcweir 
453cdf0e10cSrcweir 
454