2 #include "MEM_guardedalloc.h"
4 #include "DNA_windowmanager_types.h"
6 #include "BLI_blenlib.h"
8 #include "BKE_global.h"
19 #define vsnprintf _vsnprintf
23 static int wmReportLevel= WM_LOG_INFO;
24 static int wmReportPrint= 0;
26 static const char *wm_report_type_str(int type)
29 case WM_LOG_DEBUG: return "Debug";
30 case WM_LOG_INFO: return "Info";
31 case WM_LOG_WARNING: return "Warning";
32 case WM_ERROR_UNDEFINED: return "Error";
33 case WM_ERROR_INVALID_INPUT: return "Invalid Input Error";
34 case WM_ERROR_INVALID_CONTEXT: return "Invalid Context Error";
35 case WM_ERROR_OUT_OF_MEMORY: return "Out Of Memory Error";
36 default: return "Undefined Type";
40 static void wm_print_report(wmReport *report)
42 printf("%s: %s\n", report->typestr, report->message);
43 fflush(stdout); /* this ensures the message is printed before a crash */
46 void WM_report(bContext *C, int type, const char *message)
52 fprintf(stderr, "WM_report: can't report without windowmanager.\n");
55 if(type < wmReportLevel)
58 report= MEM_callocN(sizeof(wmReport), "wmReport");
60 report->typestr= wm_report_type_str(type);
63 report->message= MEM_callocN(sizeof(char)*(len+1), "wmReportMessage");
64 memcpy(report->message, message, sizeof(char)*(len+1));
67 wm_print_report(report);
69 BLI_addtail(&C->wm->reports, report);
72 void WM_reportf(bContext *C, int type, const char *format, ...)
77 int len= 256, maxlen= 65536, retval;
80 fprintf(stderr, "WM_report: can't report without windowmanager.\n");
83 if(type < wmReportLevel)
87 message= MEM_callocN(sizeof(char)*len+1, "wmReportMessage");
89 va_start(args, format);
90 retval= vsnprintf(message, len, format, args);
94 /* -1 means not enough space, but on windows it may also mean
95 * there is a formatting error, so we impose a maximum length */
101 fprintf(stderr, "WM_report message too long or format error.\n");
105 else if(retval > len) {
106 /* in C99 the actual length required is returned */
117 report= MEM_callocN(sizeof(wmReport), "wmReport");
119 report->typestr= wm_report_type_str(type);
120 report->message= message;
123 wm_print_report(report);
125 BLI_addtail(&C->wm->reports, report);
129 void wm_report_free(wmReport *report)
131 MEM_freeN(report->message);