replace double prints in readfile.c with a BKE_reportf wrapper

This commit is contained in:
Campbell Barton 2012-01-05 09:50:07 +00:00
parent d560b33f74
commit 05436e9a45

@ -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 *read_struct(FileData *fd, BHead *bh, const char *blockname);
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,9 +4141,10 @@ static void lib_link_object(FileData *fd, Main *main)
ob= ob->id.next;
}
if(warn)
if(warn) {
BKE_report(fd->reports, RPT_WARNING, "Warning in console");
}
}
static void direct_link_pose(FileData *fd, bPose *pose)
@ -4697,8 +4724,9 @@ static void lib_link_scene(FileData *fd, Main *main)
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 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main)
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,17 +12869,18 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
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);
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;
}
}
}
}
}
}
/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
/* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
@ -14302,8 +14332,9 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
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 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
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 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
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 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
ID *idn= id->next;
if(id->flag & LIB_READ) {
BLI_remlink(lbarray[a], id);
BKE_reportf(basefd->reports, RPT_ERROR,
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);
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);
}
change_idid_adr(mainlist, basefd, id, NULL);
MEM_freeN(id);