[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43157] trunk/blender/source/blender/ blenloader/intern/readfile.c: replace double prints in readfile. c with a BKE_reportf wrapper

Campbell Barton ideasman42 at gmail.com
Thu Jan 5 10:50:15 CET 2012


Revision: 43157
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43157
Author:   campbellbarton
Date:     2012-01-05 09:50:07 +0000 (Thu, 05 Jan 2012)
Log Message:
-----------
replace double prints in readfile.c with a BKE_reportf wrapper

Modified Paths:
--------------
    trunk/blender/source/blender/blenloader/intern/readfile.c

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2012-01-05 08:08:58 UTC (rev 43156)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2012-01-05 09:50:07 UTC (rev 43157)
@@ -39,6 +39,7 @@
 #include <fcntl.h> // for open
 #include <string.h> // for strrchr strncmp strstr
 #include <math.h> // for fabs
+#include <stdarg.h> /* for va_start/end */
 
 #ifndef WIN32
 	#include <unistd.h> // for read close
@@ -249,6 +250,31 @@
 static void direct_link_modifiers(FileData *fd, ListBase *lb);
 static void convert_tface_mt(FileData *fd, Main *main);
 
+/* this function ensures that reports are printed,
+ * in the case of libraray linking errors this is important!
+ *
+ * bit kludge but better then doubling up on prints,
+ * we could alternatively have a versions of a report function which foces printing - campbell
+ */
+static void BKE_reportf_wrap(ReportList *reports, ReportType type, const char *format, ...)
+{
+	char fixed_buf[1024]; /* should be long enough */
+
+	va_list args;
+
+	va_start(args, format);
+	vsnprintf(fixed_buf, sizeof(fixed_buf), format, args);
+	va_end(args);
+
+	fixed_buf[sizeof(fixed_buf) - 1] = '\0';
+
+	BKE_report(reports, type, fixed_buf);
+
+	if(G.background==0) {
+		printf("%s\n", fixed_buf);
+	}
+}
+
 static OldNewMap *oldnewmap_new(void) 
 {
 	OldNewMap *onm= MEM_callocN(sizeof(*onm), "OldNewMap");
@@ -4115,8 +4141,9 @@
 		ob= ob->id.next;
 	}
 
-	if(warn)
+	if(warn) {
 		BKE_report(fd->reports, RPT_WARNING, "Warning in console");
+	}
 }
 
 
@@ -4697,8 +4724,9 @@
 				base->object= newlibadr_us(fd, sce->id.lib, base->object);
 				
 				if(base->object==NULL) {
-					BKE_reportf(fd->reports, RPT_ERROR, "LIB ERROR: Object lost from scene:'%s\'\n", sce->id.name+2);
-					if(G.background==0) printf("LIB ERROR: base removed from scene:'%s\'\n", sce->id.name+2);
+					BKE_reportf_wrap(fd->reports, RPT_ERROR,
+					                 "LIB ERROR: Object lost from scene:'%s\'\n",
+					                 sce->id.name+2);
 					BLI_remlink(&sce->base, base);
 					if(base==sce->basact) sce->basact= NULL;
 					MEM_freeN(base);
@@ -5798,8 +5826,9 @@
 	for(newmain= fd->mainlist.first; newmain; newmain= newmain->next) {
 		if(newmain->curlib) {
 			if(BLI_path_cmp(newmain->curlib->filepath, lib->filepath) == 0) {
-				printf("Fixed error in file; multiple instances of lib:\n %s\n", lib->filepath);
-				BKE_reportf(fd->reports, RPT_WARNING, "Library '%s', '%s' had multiple instances, save and reload!", lib->name, lib->filepath);
+				BKE_reportf_wrap(fd->reports, RPT_WARNING,
+				                 "Library '%s', '%s' had multiple instances, save and reload!",
+				                 lib->name, lib->filepath);
 
 				change_idid_adr(&fd->mainlist, fd, lib, newmain->curlib);
 //				change_idid_adr_fd(fd, lib, newmain->curlib);
@@ -12840,12 +12869,13 @@
 
 			for (ob= main->object.first; ob; ob= ob->id.next) {
 				if (ob->type == OB_FONT) {
-					for (prop=ob->prop.first;prop;prop=prop->next) {
-						if (strcmp(prop->name, "Text") == 0) {
-							BKE_reportf(fd->reports, RPT_WARNING, "Game property name conflict in object: \"%s\".\nText objects reserve the [\"Text\"] game property to change their content through Logic Bricks.\n", ob->id.name+2);
-							if(G.background==0) printf("Game property conflict in object: \"%s\". Texts reserve the [\"Text\"] game property to change their content through Logic Bricks.\n", ob->id.name+2);
-							break;
-						}
+					prop = get_ob_property(ob, "Text");
+					if (prop) {
+						BKE_reportf_wrap(fd->reports, RPT_WARNING,
+						                 "Game property name conflict in object: \"%s\".\nText objects reserve the "
+						                 "[\"Text\"] game property to change their content through Logic Bricks.\n",
+						                 ob->id.name+2);
+						break;
 					}
 				}
 			}
@@ -14302,8 +14332,9 @@
 				if(fd==NULL) {
 
 					/* printf and reports for now... its important users know this */
-					BKE_reportf(basefd->reports, RPT_INFO, "read library:  '%s', '%s'\n", mainptr->curlib->filepath, mainptr->curlib->name);
-					if(!G.background && basefd->reports) printf("read library: '%s', '%s'\n", mainptr->curlib->filepath, mainptr->curlib->name);
+					BKE_reportf_wrap(basefd->reports, RPT_INFO,
+					                 "read library:  '%s', '%s'\n",
+					                 mainptr->curlib->filepath, mainptr->curlib->name);
 
 					fd= blo_openblenderfile(mainptr->curlib->filepath, basefd->reports);
 					
@@ -14348,8 +14379,9 @@
 					else mainptr->curlib->filedata= NULL;
 
 					if (fd==NULL) {
-						BKE_reportf(basefd->reports, RPT_ERROR, "Can't find lib '%s'\n", mainptr->curlib->filepath);
-						if(!G.background && basefd->reports) printf("ERROR: can't find lib %s \n", mainptr->curlib->filepath);
+						BKE_reportf_wrap(basefd->reports, RPT_ERROR,
+						                 "Can't find lib '%s'\n",
+						                 mainptr->curlib->filepath);
 					}
 				}
 				if(fd) {
@@ -14366,8 +14398,10 @@
 
 								append_id_part(fd, mainptr, id, &realid);
 								if (!realid) {
-									BKE_reportf(fd->reports, RPT_ERROR, "LIB ERROR: %s:'%s' missing from '%s'\n", BKE_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
-									if(!G.background && basefd->reports) printf("LIB ERROR: %s:'%s' missing from '%s'\n", BKE_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
+									BKE_reportf_wrap(fd->reports, RPT_ERROR,
+									                 "LIB ERROR: %s:'%s' missing from '%s'\n",
+									                 BKE_idcode_to_name(GS(id->name)),
+									                 id->name+2, mainptr->curlib->filepath);
 								}
 								
 								change_idid_adr(mainlist, basefd, id, realid);
@@ -14403,13 +14437,9 @@
 				ID *idn= id->next;
 				if(id->flag & LIB_READ) {
 					BLI_remlink(lbarray[a], id);
-					BKE_reportf(basefd->reports, RPT_ERROR,
-					            "LIB ERROR: %s:'%s' unread libblock missing from '%s'\n",
-					            BKE_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
-					if (!G.background && basefd->reports) {
-						printf("LIB ERROR: %s:'%s' unread libblock missing from '%s'\n",
-						       BKE_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
-					}
+					BKE_reportf_wrap(basefd->reports, RPT_ERROR,
+					                 "LIB ERROR: %s:'%s' unread libblock missing from '%s'\n",
+					                 BKE_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
 					change_idid_adr(mainlist, basefd, id, NULL);
 
 					MEM_freeN(id);



More information about the Bf-blender-cvs mailing list