io.cpp

changeset 13
3955ff2a7d72
parent 12
8f6de46a27e2
child 14
6d9d8efae2f8
--- a/io.cpp	Sat Mar 16 00:35:36 2013 +0200
+++ b/io.cpp	Sat Mar 16 01:32:47 2013 +0200
@@ -30,14 +30,18 @@
 // Opens the given file and parses the LDraw code within.
 // =============================================================================
 OpenFile* IO_OpenLDrawFile (str path) {
+	logf ("Opening %s...\n", path.chars());
+	
 	FILE* fp = fopen (path.chars (), "r");
 	
 	if (!fp) {
-		printf ("Couldn't open %s!\n", path.chars ());
+		logf (LOG_Error, "Couldn't open %s: %s\n", path.chars (), strerror (errno));
 		return NULL;
 	}
 	
 	OpenFile* load = new OpenFile;
+	ulong numWarnings = 0;
+	
 	load->zFileName = path;
 	
 	vector<str> lines;
@@ -56,8 +60,18 @@
 	
 	fclose (fp);
 	
-	for (ulong i = 0; i < lines.size(); ++i)
-		load->objects.push_back (ParseLine (lines[i]));
+	for (ulong i = 0; i < lines.size(); ++i) {
+		LDObject* obj = ParseLine (lines[i]);
+		load->objects.push_back (obj);
+		
+		// Check for warnings
+		if (obj->getType() == OBJ_Gibberish) {
+			logf (LOG_Warning, "Couldn't parse line #%lu: %s\n",
+				i, static_cast<LDGibberish*> (obj)->zReason.chars());
+			logf (LOG_Warning, "- Line was: %s\n", lines[i].chars());
+			numWarnings++;
+		}
+	}
 	
 	g_LoadedFiles.push_back (load);
 	g_CurrentFile = g_LoadedFiles[g_LoadedFiles.size() - 1];
@@ -69,6 +83,9 @@
 	g_qWindow->buildObjList ();
 	g_qWindow->setTitle ();
 	
+	logf (LOG_Success, "File %s parsed successfully (%lu warnings).\n",
+		path.chars(), numWarnings);
+	
 	return g_CurrentFile;
 }
 

mercurial