[xiph-commits] r10058 - trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse

davidb at svn.xiph.org davidb at svn.xiph.org
Sat Sep 24 15:02:06 PDT 2005


Author: davidb
Date: 2005-09-24 15:02:05 -0700 (Sat, 24 Sep 2005)
New Revision: 10058

Modified:
   trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse/CMMLParser.cpp
   trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse/CMMLParser.h
   trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse/xtag.c
   trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse/xtag.h
Log:
Pass some error information out for use of the calling processes.

Modified: trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse/CMMLParser.cpp
===================================================================
--- trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse/CMMLParser.cpp	2005-09-24 10:21:13 UTC (rev 10057)
+++ trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse/CMMLParser.cpp	2005-09-24 22:02:05 UTC (rev 10058)
@@ -56,7 +56,7 @@
 {
 }
 
-bool CMMLParser::parseDoc(wstring locCMMLFileWString, C_CMMLDoc* outCMMLDoc)
+bool CMMLParser::parseDoc(wstring locCMMLFileWString, C_CMMLDoc* outCMMLDoc, C_CMMLError* outCMMLError)
 {
 	// Assume we are unsuccessful unless we explicitly change that
 	bool locReturnValue = false;
@@ -71,24 +71,27 @@
 	// we don't need to scan for "<CMML")
 	size_t locCMMLTagIndex = locCMMLFileWString.find(L"<cmml", 0);
 	if (locCMMLTagIndex != string::npos) {
-		locCMMLFileWString = locCMMLFileWString.substr(locCMMLTagIndex);
-	}
+		wstring locCMMLFileWString1 = locCMMLFileWString.substr(locCMMLTagIndex);
 
-	// Parse ourselves the CMML
-	C_CMMLRootTag* locRootTag = new C_CMMLRootTag;
-	locReturnValue = parseCMMLRootTag(locCMMLFileWString, locRootTag);
-	if (locReturnValue) {
-		// Successfully parsed the CMML
-		outCMMLDoc->setRoot(locRootTag);
+		// Parse ourselves the CMML
+		C_CMMLRootTag* locRootTag = new C_CMMLRootTag;
+		locReturnValue = parseCMMLRootTag(locCMMLFileWString1, locRootTag, outCMMLError);
+		if (locReturnValue) {
+			// Successfully parsed the CMML
+			outCMMLDoc->setRoot(locRootTag);
+		} else {
+			// Parsing CMML failed
+			outCMMLDoc = NULL;
+		}
 	} else {
-		// Parsing CMML failed
+		// No <CMML> tag
 		outCMMLDoc = NULL;
 	}
 
 	return locReturnValue;
 }
 
-bool CMMLParser::parseDocFromFile(wstring inFilename, C_CMMLDoc* outCMMLDoc)
+bool CMMLParser::parseDocFromFile(wstring inFilename, C_CMMLDoc* outCMMLDoc, C_CMMLError* outCMMLError)
 {
 	// Assume we are unsuccessful unless we explicitly change that
 	bool locReturnValue = false;
@@ -142,7 +145,7 @@
 
 	// Parse ourselves the CMML
 	C_CMMLRootTag* locRootTag = new C_CMMLRootTag;
-	locReturnValue = parseCMMLRootTag(locCMMLFileWString, locRootTag);
+	locReturnValue = parseCMMLRootTag(locCMMLFileWString, locRootTag, outCMMLError);
 	if (locReturnValue) {
 		// Successfully parsed the CMML
 		outCMMLDoc->setRoot(locRootTag);
@@ -157,11 +160,9 @@
 	return locReturnValue;
 }
 
-
-bool CMMLParser::parseCMMLRootTag(wstring inCMMLRootText, C_CMMLRootTag* outCMMLRoot)
+bool CMMLParser::parseCMMLRootTag(wstring inCMMLRootText, C_CMMLRootTag* outCMMLRoot, C_CMMLError* outCMMLError )
 {
 	// Assume we are unsuccessful unless we explicitly change that
-
 	bool locReturnValue = false;
 
 	// Sanity check against a NULL output pointer
@@ -176,7 +177,8 @@
 
 	// Look for a tag, any tag
 	XTag *locRootParser = NULL;
-	locRootParser = xtag_new_parse(locCMMLRootText.c_str(), (int)locCMMLRootText.size());
+	int ErrorOffset = 0;
+	locRootParser = xtag_new_parse(locCMMLRootText.c_str(), (int)locCMMLRootText.size(), &ErrorOffset);
 	if (locRootParser) {
 		// Is it a <cmml> tag?
 		if (strcmp(xtag_get_name(locRootParser), "cmml") == 0) {
@@ -184,7 +186,27 @@
 			locReturnValue = parseRootTag(locRootParser, outCMMLRoot);
 		}
 	}
+	else
+	{
+		// Count the number of lines down we are
+		int LineNumber = 0;
+		size_t Offset=0;
+		for ( ;Offset != string::npos, Offset < ErrorOffset; Offset++)
+		{
+			Offset = locCMMLRootText.find("\n", Offset);
+			LineNumber++;
+			if (Offset == string::npos)
+			{
+				break;
+			}
+		}
 
+		if (outCMMLError != NULL)
+		{
+			outCMMLError->SetLineNumber(LineNumber);
+		}
+	}
+
 	if (locRootParser) {
 		xtag_free(locRootParser);
 	}
@@ -211,7 +233,8 @@
 
 	// Look for a <clip> tag
 	XTag *locClipParser = NULL;
-	locClipParser = xtag_new_parse(locClipText.c_str(), (int)locClipText.size());
+	int ErrorOffset = 0;
+	locClipParser = xtag_new_parse(locClipText.c_str(), (int)locClipText.size(), &ErrorOffset);
 	if (locClipParser) {
 		// Found some sort of tag
 		if (strcmp(xtag_get_name(locClipParser), "clip") == 0) {
@@ -246,7 +269,8 @@
 
 	// Set up an XTag parser
 	XTag *locHeadParser = NULL;
-	locHeadParser = xtag_new_parse(locHeadText.c_str(), (int)locHeadText.size());
+	int ErrorOffset = 0;
+	locHeadParser = xtag_new_parse(locHeadText.c_str(), (int)locHeadText.size(), &ErrorOffset);
 	if (locHeadParser) {
 		if (strcmp(xtag_get_name(locHeadParser), "head") == 0) {
 			locReturnValue = parseHeadTag(locHeadParser, outHead);

Modified: trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse/CMMLParser.h
===================================================================
--- trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse/CMMLParser.h	2005-09-24 10:21:13 UTC (rev 10057)
+++ trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse/CMMLParser.h	2005-09-24 22:02:05 UTC (rev 10058)
@@ -43,7 +43,30 @@
 
 using namespace std;
 
+// DLB. 21/9/2005. Allow parse error information to be sent back to caller
+class LIBCMMLPARSE_API C_CMMLError
+{
+public:
+	C_CMMLError()
+	{
+		// DLB. 20/9/2005. Clear the return ERROR info to start with
+		this->LineNumber = 0;
+	}
 
+	void SetLineNumber(int lLineNumber)
+	{
+		LineNumber = lLineNumber;
+	}
+
+	int GetLineNumber()
+	{
+		return LineNumber;
+	}
+
+private:
+	int   LineNumber;
+};
+
 class LIBCMMLPARSE_API CMMLParser
 {
 public:
@@ -57,13 +80,13 @@
 	bool parseHeadTag(wstring inHeadText, C_HeadTag* outHead);
 
 	/// Parse a string representation of a cmml root tag into the provided CMMLRoot object.
-	bool parseCMMLRootTag(wstring inCMMLRootText, C_CMMLRootTag* outCMMLRoot);
+	bool parseCMMLRootTag(wstring inCMMLRootText, C_CMMLRootTag* outCMMLRoot, C_CMMLError* outCMMLError=NULL);
 
 	/// Parse a string representation of a cmml document into the provided CMMLDoc object.
-	bool parseDocFromFile(wstring inFilename, C_CMMLDoc* outCMMLDoc);
+	bool parseDocFromFile(wstring inFilename, C_CMMLDoc* outCMMLDoc, C_CMMLError* outCMMLError=NULL);
 
 	/// DLB. 9/9/2005. Parse a string representation of a cmml document into the provided CMMLDoc object.
-	bool parseDoc(wstring inBuffer, C_CMMLDoc* outCMMLDoc);
+	bool parseDoc(wstring inBuffer, C_CMMLDoc* outCMMLDoc, C_CMMLError* outCMMLError=NULL);
 
 protected:
 	/// Parse an XTag representation of a cmml root tag into the provided CMMLRoot object.

Modified: trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse/xtag.c
===================================================================
--- trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse/xtag.c	2005-09-24 10:21:13 UTC (rev 10057)
+++ trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse/xtag.c	2005-09-24 22:02:05 UTC (rev 10058)
@@ -444,7 +444,7 @@
 }
 
 XTag *
-xtag_new_parse (const char * s, int n)
+xtag_new_parse (const char * s, int n, int* ErrorOffset)
 {
   XTagParser parser;
   XTag * tag, * ttag, * wrapper;
@@ -464,6 +464,7 @@
 
   if (!parser.valid) {
     xtag_free (tag);
+	*ErrorOffset = parser.start - s;	// DLB. 20/9/05
     return NULL;
   }
 
@@ -471,6 +472,7 @@
 
     if (!parser.valid) {
       xtag_free (ttag);
+	  ErrorOffset = parser.start - s;	// DLB. 20/9/05
       return tag;
     }
 
@@ -489,14 +491,18 @@
 
       if (!parser.valid) {
         xtag_free (ttag);
+		ErrorOffset = parser.start - s;	// DLB. 20/9/05
         return wrapper;
       }
 
       wrapper->children = xlist_append (wrapper->children, ttag);
     }
+
+	ErrorOffset = parser.start - s;	// DLB. 20/9/05
     return wrapper;
   }
 
+  ErrorOffset = parser.start - s;	// DLB. 20/9/05
   return tag;
 }
 

Modified: trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse/xtag.h
===================================================================
--- trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse/xtag.h	2005-09-24 10:21:13 UTC (rev 10057)
+++ trunk/oggdsf/src/lib/codecs/cmml/libCMMLParse/xtag.h	2005-09-24 22:02:05 UTC (rev 10058)
@@ -42,7 +42,8 @@
 typedef void XTag;
 #endif /* XTAG_INTERNAL */
 
-XTag * xtag_new_parse (const char * s, int n);
+//XTag * xtag_new_parse (const char * s, int n);
+XTag * xtag_new_parse (const char * s, int n, int* ErrorOffset);
 
 char * xtag_get_name (XTag * xtag);
 



More information about the commits mailing list