diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-12-19 03:50:21 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-12-19 03:50:21 +0300 |
commit | d9de6fca6cda2a7ddeeb936692b529182a14dec9 (patch) | |
tree | 63b5384fe03297bdfb40205c280b36ec043d0ed1 /source/blender/blenkernel | |
parent | ea81c58429ecd51752e2abb7d756ef1d09514b84 (diff) |
2.5: Change blenloader module to use the Report system for reporting errors.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_report.h | 21 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/blender.c | 40 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/report.c | 59 |
3 files changed, 80 insertions, 40 deletions
diff --git a/source/blender/blenkernel/BKE_report.h b/source/blender/blenkernel/BKE_report.h index 39a50769234..f87910d7872 100644 --- a/source/blender/blenkernel/BKE_report.h +++ b/source/blender/blenkernel/BKE_report.h @@ -48,7 +48,8 @@ typedef enum ReportType { enum ReportListFlags { RPT_PRINT = 1, - RPT_STORE = 2 + RPT_STORE = 2, + RPT_HAS_ERROR = 4 }; typedef struct Report { @@ -60,20 +61,24 @@ typedef struct Report { typedef struct ReportList { ListBase list; - ReportType level; - int flags; + ReportType printlevel; + ReportType storelevel; + int flag; } ReportList; -void BKE_report_list_init(ReportList *reports, int flag); -void BKE_report_list_clear(ReportList *reports); +void BKE_reports_init(ReportList *reports, int flag); +void BKE_reports_clear(ReportList *reports); void BKE_report(ReportList *reports, ReportType type, const char *message); void BKE_reportf(ReportList *reports, ReportType type, const char *format, ...); -ReportType BKE_report_level(ReportList *reports); -void BKE_report_level_set(ReportList *reports, ReportType level); +ReportType BKE_report_print_level(ReportList *reports); +void BKE_report_print_level_set(ReportList *reports, ReportType level); -int BKE_report_has_error(ReportList *reports); +ReportType BKE_report_store_level(ReportList *reports); +void BKE_report_store_level_set(ReportList *reports, ReportType level); + +void BKE_reports_print(ReportList *reports, ReportType level); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index b891e75a71b..ed2b8238dae 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -77,6 +77,7 @@ #include "BKE_main.h" #include "BKE_node.h" #include "BKE_object.h" +#include "BKE_report.h" #include "BKE_scene.h" #include "BKE_screen.h" #include "BKE_sound.h" @@ -435,11 +436,13 @@ static void handle_subversion_warning(Main *main) int BKE_read_file(bContext *C, char *dir, void *unused) { - BlendReadError bre; + ReportList reports; BlendFileData *bfd; int retval= 1; - bfd= BLO_read_from_file(dir, &bre); + BKE_reports_init(&reports, RPT_STORE); + + bfd= BLO_read_from_file(dir, &reports); if (bfd) { if(bfd->user) retval= 2; @@ -450,38 +453,48 @@ int BKE_read_file(bContext *C, char *dir, void *unused) else { // XXX error("Loading %s failed: %s", dir, BLO_bre_as_string(bre)); } + + BKE_reports_clear(&reports); return (bfd?retval:0); } int BKE_read_file_from_memory(bContext *C, char* filebuf, int filelength, void *unused) { - BlendReadError bre; + ReportList reports; BlendFileData *bfd; - - bfd= BLO_read_from_memory(filebuf, filelength, &bre); + + BKE_reports_init(&reports, RPT_STORE); + + bfd= BLO_read_from_memory(filebuf, filelength, &reports); if (bfd) { setup_app_data(C, bfd, "<memory2>"); } else { // XXX error("Loading failed: %s", BLO_bre_as_string(bre)); } + BKE_reports_clear(&reports); + return (bfd?1:0); } /* memfile is the undo buffer */ int BKE_read_file_from_memfile(bContext *C, MemFile *memfile) { - BlendReadError bre; + ReportList reports; BlendFileData *bfd; - bfd= BLO_read_from_memfile(G.sce, memfile, &bre); + BKE_reports_init(&reports, RPT_STORE); + + bfd= BLO_read_from_memfile(G.sce, memfile, &reports); if (bfd) { setup_app_data(C, bfd, "<memory1>"); } else { // XXX error("Loading failed: %s", BLO_bre_as_string(bre)); } + BKE_reports_clear(&reports); + return (bfd?1:0); } @@ -568,8 +581,9 @@ void BKE_write_undo(bContext *C, char *name) /* disk save version */ if(UNDO_DISK) { + ReportList reports; static int counter= 0; - char *err, tstr[FILE_MAXDIR+FILE_MAXFILE]; + char tstr[FILE_MAXDIR+FILE_MAXFILE]; char numstr[32]; /* calculate current filename */ @@ -579,18 +593,22 @@ void BKE_write_undo(bContext *C, char *name) sprintf(numstr, "%d.blend", counter); BLI_make_file_string("/", tstr, btempdir, numstr); - success= BLO_write_file(C, tstr, G.fileflags, &err); + BKE_reports_init(&reports, 0); + success= BLO_write_file(C, tstr, G.fileflags, &reports); + BKE_reports_clear(&reports); strcpy(curundo->str, tstr); } else { + ReportList reports; MemFile *prevfile=NULL; - char *err; if(curundo->prev) prevfile= &(curundo->prev->memfile); memused= MEM_get_memory_in_use(); - success= BLO_write_file_mem(C, prevfile, &curundo->memfile, G.fileflags, &err); + BKE_reports_init(&reports, 0); + success= BLO_write_file_mem(C, prevfile, &curundo->memfile, G.fileflags, &reports); + BKE_reports_clear(&reports); curundo->undosize= MEM_get_memory_in_use() - memused; } diff --git a/source/blender/blenkernel/intern/report.c b/source/blender/blenkernel/intern/report.c index 569377a1c2f..12fbaf806d5 100644 --- a/source/blender/blenkernel/intern/report.c +++ b/source/blender/blenkernel/intern/report.c @@ -57,15 +57,16 @@ static char *report_type_str(int type) } } -void BKE_report_list_init(ReportList *reports, int flags) +void BKE_reports_init(ReportList *reports, int flag) { memset(reports, 0, sizeof(ReportList)); - reports->level= RPT_WARNING; - reports->flags= flags; + reports->storelevel= RPT_WARNING; + reports->printlevel= RPT_WARNING; + reports->flag= flag; } -void BKE_report_list_clear(ReportList *reports) +void BKE_reports_clear(ReportList *reports) { Report *report; @@ -80,15 +81,18 @@ void BKE_report(ReportList *reports, ReportType type, const char *message) Report *report; int len; - if(!reports || type < reports->level) + if(!reports) return; + + if(type >= RPT_ERROR) + reports->flag |= RPT_HAS_ERROR; - if(reports->flags & RPT_PRINT) { + if((reports->flag & RPT_PRINT) && (type >= reports->printlevel)) { printf("%s: %s\n", report_type_str(type), message); fflush(stdout); /* this ensures the message is printed before a crash */ } - if(reports->flags & RPT_STORE) { + if((reports->flag & RPT_STORE) && (type >= reports->storelevel)) { report= MEM_callocN(sizeof(Report), "Report"); report->type= type; report->typestr= report_type_str(type); @@ -108,17 +112,20 @@ void BKE_reportf(ReportList *reports, ReportType type, const char *format, ...) char *message; int len= 256, maxlen= 65536, retval; - if(!reports || type < reports->level) + if(!reports) return; - if(reports->flags & RPT_PRINT) { + if(type >= RPT_ERROR) + reports->flag |= RPT_HAS_ERROR; + + if((reports->flag & RPT_PRINT) && (type >= reports->printlevel)) { va_start(args, format); vprintf(format, args); va_end(args); fflush(stdout); /* this ensures the message is printed before a crash */ } - if(reports->flags & RPT_STORE) { + if((reports->flag & RPT_STORE) && (type >= reports->storelevel)) { while(1) { message= MEM_callocN(sizeof(char)*len+1, "ReportMessage"); @@ -160,27 +167,37 @@ void BKE_reportf(ReportList *reports, ReportType type, const char *format, ...) } } -ReportType BKE_report_level(ReportList *reports) +ReportType BKE_report_print_level(ReportList *reports) { - return reports->level; + return reports->printlevel; } -void BKE_report_level_set(ReportList *reports, ReportType level) +void BKE_report_print_level_set(ReportList *reports, ReportType level) { - reports->level= level; + reports->printlevel= level; } -int BKE_report_has_error(ReportList *reports) +ReportType BKE_report_store_level(ReportList *reports) +{ + return reports->storelevel; +} + +void BKE_report_store_level_set(ReportList *reports, ReportType level) +{ + reports->storelevel= level; +} + +void BKE_reports_print(ReportList *reports, ReportType level) { Report *report; if(!reports) - return 0; - - for(report=reports->list.first; report; report=report->next) - if(report->type >= RPT_ERROR) - return 1; + return; - return 0; + for(report=reports->list.first; report; report=report->next) + if(report->type >= level) + printf("%s: %s\n", report->typestr, report->message); + + fflush(stdout); } |