| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Blender Foundation (2008). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 20:40:57 +00:00
										 |  |  | /** \file blender/blenkernel/intern/report.c
 | 
					
						
							|  |  |  |  *  \ingroup bke | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-10 16:37:48 +00:00
										 |  |  | #include <stdarg.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <errno.h>
 | 
					
						
							| 
									
										
										
										
											2011-02-27 20:40:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_blenlib.h"
 | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | #include "BLI_dynstr.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-16 17:32:01 +10:00
										 |  |  | #include "BLT_translation.h"
 | 
					
						
							| 
									
										
										
										
											2012-10-13 13:55:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | #include "BKE_report.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-23 11:48:17 +00:00
										 |  |  | #include "BKE_global.h" /* G.background only */
 | 
					
						
							| 
									
										
										
										
											2011-01-07 19:18:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-13 15:26:22 +01:00
										 |  |  | const char *BKE_report_type_str(ReportType type) | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 	switch (type) { | 
					
						
							| 
									
										
										
										
											2012-10-13 15:44:50 +00:00
										 |  |  | 		case RPT_DEBUG: | 
					
						
							|  |  |  | 			return TIP_("Debug"); | 
					
						
							|  |  |  | 		case RPT_INFO: | 
					
						
							|  |  |  | 			return TIP_("Info"); | 
					
						
							|  |  |  | 		case RPT_OPERATOR: | 
					
						
							|  |  |  | 			return TIP_("Operator"); | 
					
						
							| 
									
										
										
										
											2012-12-18 15:22:06 +00:00
										 |  |  | 		case RPT_PROPERTY: | 
					
						
							|  |  |  | 			return TIP_("Property"); | 
					
						
							| 
									
										
										
										
											2012-10-13 15:44:50 +00:00
										 |  |  | 		case RPT_WARNING: | 
					
						
							|  |  |  | 			return TIP_("Warning"); | 
					
						
							|  |  |  | 		case RPT_ERROR: | 
					
						
							|  |  |  | 			return TIP_("Error"); | 
					
						
							|  |  |  | 		case RPT_ERROR_INVALID_INPUT: | 
					
						
							|  |  |  | 			return TIP_("Invalid Input Error"); | 
					
						
							|  |  |  | 		case RPT_ERROR_INVALID_CONTEXT: | 
					
						
							|  |  |  | 			return TIP_("Invalid Context Error"); | 
					
						
							|  |  |  | 		case RPT_ERROR_OUT_OF_MEMORY: | 
					
						
							|  |  |  | 			return TIP_("Out Of Memory Error"); | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			return TIP_("Undefined Type"); | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-19 00:50:21 +00:00
										 |  |  | void BKE_reports_init(ReportList *reports, int flag) | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 	if (!reports) | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | 	memset(reports, 0, sizeof(ReportList)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 	reports->storelevel = RPT_INFO; | 
					
						
							|  |  |  | 	reports->printlevel = RPT_ERROR; | 
					
						
							|  |  |  | 	reports->flag = flag; | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-19 00:50:21 +00:00
										 |  |  | void BKE_reports_clear(ReportList *reports) | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-07-19 04:50:10 +00:00
										 |  |  | 	Report *report, *report_next; | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 	if (!reports) | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 	report = reports->list.first; | 
					
						
							| 
									
										
										
										
											2009-07-19 04:50:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while (report) { | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 		report_next = report->next; | 
					
						
							| 
									
										
										
										
											2010-12-03 17:05:21 +00:00
										 |  |  | 		MEM_freeN((void *)report->message); | 
					
						
							| 
									
										
										
										
											2009-07-19 04:50:10 +00:00
										 |  |  | 		MEM_freeN(report); | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 		report = report_next; | 
					
						
							| 
									
										
										
										
											2009-07-19 04:50:10 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-08 06:07:10 +11:00
										 |  |  | 	BLI_listbase_clear(&reports->list); | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-13 13:55:14 +00:00
										 |  |  | void BKE_report(ReportList *reports, ReportType type, const char *_message) | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Report *report; | 
					
						
							|  |  |  | 	int len; | 
					
						
							| 
									
										
										
										
											2012-10-13 13:55:14 +00:00
										 |  |  | 	const char *message = TIP_(_message); | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-21 13:11:51 +00:00
										 |  |  | 	/* in background mode always print otherwise there are cases the errors wont be displayed,
 | 
					
						
							| 
									
										
										
										
											2011-01-20 07:41:25 +00:00
										 |  |  | 	 * but still add to the report list since this is used for python exception handling */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 	if (G.background || !reports || ((reports->flag & RPT_PRINT) && (type >= reports->printlevel))) { | 
					
						
							| 
									
										
										
										
											2015-11-13 15:26:22 +01:00
										 |  |  | 		printf("%s: %s\n", BKE_report_type_str(type), message); | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | 		fflush(stdout); /* this ensures the message is printed before a crash */ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 	if (reports && (reports->flag & RPT_STORE) && (type >= reports->storelevel)) { | 
					
						
							| 
									
										
										
										
											2010-12-03 17:05:21 +00:00
										 |  |  | 		char *message_alloc; | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 		report = MEM_callocN(sizeof(Report), "Report"); | 
					
						
							|  |  |  | 		report->type = type; | 
					
						
							| 
									
										
										
										
											2015-11-13 15:26:22 +01:00
										 |  |  | 		report->typestr = BKE_report_type_str(type); | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		len = strlen(message); | 
					
						
							|  |  |  | 		message_alloc = MEM_callocN(sizeof(char) * (len + 1), "ReportMessage"); | 
					
						
							|  |  |  | 		memcpy(message_alloc, message, sizeof(char) * (len + 1)); | 
					
						
							|  |  |  | 		report->message = message_alloc; | 
					
						
							|  |  |  | 		report->len = len; | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | 		BLI_addtail(&reports->list, report); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-13 13:55:14 +00:00
										 |  |  | void BKE_reportf(ReportList *reports, ReportType type, const char *_format, ...) | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 	DynStr *ds; | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | 	Report *report; | 
					
						
							|  |  |  | 	va_list args; | 
					
						
							| 
									
										
										
										
											2012-10-13 13:55:14 +00:00
										 |  |  | 	const char *format = TIP_(_format); | 
					
						
							| 
									
										
										
										
											2008-12-19 00:50:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 	if (G.background || !reports || ((reports->flag & RPT_PRINT) && (type >= reports->printlevel))) { | 
					
						
							| 
									
										
										
										
											2015-11-13 15:26:22 +01:00
										 |  |  | 		printf("%s: ", BKE_report_type_str(type)); | 
					
						
							| 
									
										
										
										
											2012-10-13 13:55:14 +00:00
										 |  |  | 		va_start(args, _format); | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | 		vprintf(format, args); | 
					
						
							|  |  |  | 		va_end(args); | 
					
						
							| 
									
										
										
										
											2010-10-04 01:18:47 +00:00
										 |  |  | 		fprintf(stdout, "\n"); /* otherise each report needs to include a \n */ | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | 		fflush(stdout); /* this ensures the message is printed before a crash */ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 	if (reports && (reports->flag & RPT_STORE) && (type >= reports->storelevel)) { | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 		report = MEM_callocN(sizeof(Report), "Report"); | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 		ds = BLI_dynstr_new(); | 
					
						
							| 
									
										
										
										
											2012-10-13 13:55:14 +00:00
										 |  |  | 		va_start(args, _format); | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 		BLI_dynstr_vappendf(ds, format, args); | 
					
						
							|  |  |  | 		va_end(args); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 		report->message = BLI_dynstr_get_cstring(ds); | 
					
						
							|  |  |  | 		report->len = BLI_dynstr_get_len(ds); | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 		BLI_dynstr_free(ds); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 		report->type = type; | 
					
						
							| 
									
										
										
										
											2015-11-13 15:26:22 +01:00
										 |  |  | 		report->typestr = BKE_report_type_str(type); | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		BLI_addtail(&reports->list, report); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-13 13:55:14 +00:00
										 |  |  | void BKE_reports_prepend(ReportList *reports, const char *_prepend) | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Report *report; | 
					
						
							|  |  |  | 	DynStr *ds; | 
					
						
							| 
									
										
										
										
											2012-10-13 13:55:14 +00:00
										 |  |  | 	const char *prepend = TIP_(_prepend); | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 	if (!reports) | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 	for (report = reports->list.first; report; report = report->next) { | 
					
						
							|  |  |  | 		ds = BLI_dynstr_new(); | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		BLI_dynstr_append(ds, prepend); | 
					
						
							|  |  |  | 		BLI_dynstr_append(ds, report->message); | 
					
						
							| 
									
										
										
										
											2010-12-03 17:05:21 +00:00
										 |  |  | 		MEM_freeN((void *)report->message); | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 		report->message = BLI_dynstr_get_cstring(ds); | 
					
						
							|  |  |  | 		report->len = BLI_dynstr_get_len(ds); | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		BLI_dynstr_free(ds); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-13 13:55:14 +00:00
										 |  |  | void BKE_reports_prependf(ReportList *reports, const char *_prepend, ...) | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Report *report; | 
					
						
							|  |  |  | 	DynStr *ds; | 
					
						
							|  |  |  | 	va_list args; | 
					
						
							| 
									
										
										
										
											2012-10-13 13:55:14 +00:00
										 |  |  | 	const char *prepend = TIP_(_prepend); | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 	if (!reports) | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 	for (report = reports->list.first; report; report = report->next) { | 
					
						
							|  |  |  | 		ds = BLI_dynstr_new(); | 
					
						
							| 
									
										
										
										
											2012-10-13 13:55:14 +00:00
										 |  |  | 		va_start(args, _prepend); | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 		BLI_dynstr_vappendf(ds, prepend, args); | 
					
						
							|  |  |  | 		va_end(args); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		BLI_dynstr_append(ds, report->message); | 
					
						
							| 
									
										
										
										
											2010-12-03 17:05:21 +00:00
										 |  |  | 		MEM_freeN((void *)report->message); | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 		report->message = BLI_dynstr_get_cstring(ds); | 
					
						
							|  |  |  | 		report->len = BLI_dynstr_get_len(ds); | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		BLI_dynstr_free(ds); | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-19 00:50:21 +00:00
										 |  |  | ReportType BKE_report_print_level(ReportList *reports) | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 	if (!reports) | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 		return RPT_ERROR; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-19 00:50:21 +00:00
										 |  |  | 	return reports->printlevel; | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-19 00:50:21 +00:00
										 |  |  | void BKE_report_print_level_set(ReportList *reports, ReportType level) | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 	if (!reports) | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 	reports->printlevel = level; | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-19 00:50:21 +00:00
										 |  |  | ReportType BKE_report_store_level(ReportList *reports) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 	if (!reports) | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 		return RPT_ERROR; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-19 00:50:21 +00:00
										 |  |  | 	return reports->storelevel; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BKE_report_store_level_set(ReportList *reports, ReportType level) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 	if (!reports) | 
					
						
							| 
									
										
										
										
											2008-12-29 13:38:08 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 	reports->storelevel = level; | 
					
						
							| 
									
										
										
										
											2008-12-19 00:50:21 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-02 07:54:38 +00:00
										 |  |  | char *BKE_reports_string(ReportList *reports, ReportType level) | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Report *report; | 
					
						
							| 
									
										
										
										
											2009-01-02 07:54:38 +00:00
										 |  |  | 	DynStr *ds; | 
					
						
							|  |  |  | 	char *cstring; | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 	if (!reports || !reports->list.first) | 
					
						
							| 
									
										
										
										
											2009-01-02 07:54:38 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 	ds = BLI_dynstr_new(); | 
					
						
							|  |  |  | 	for (report = reports->list.first; report; report = report->next) | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 		if (report->type >= level) | 
					
						
							| 
									
										
										
										
											2009-01-02 07:54:38 +00:00
										 |  |  | 			BLI_dynstr_appendf(ds, "%s: %s\n", report->typestr, report->message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (BLI_dynstr_get_len(ds)) | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 		cstring = BLI_dynstr_get_cstring(ds); | 
					
						
							| 
									
										
										
										
											2009-01-02 07:54:38 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 		cstring = NULL; | 
					
						
							| 
									
										
										
										
											2008-12-19 00:50:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-02 07:54:38 +00:00
										 |  |  | 	BLI_dynstr_free(ds); | 
					
						
							|  |  |  | 	return cstring; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BKE_reports_print(ReportList *reports, ReportType level) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char *cstring = BKE_reports_string(reports, level); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (cstring == NULL) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-18 06:01:33 +00:00
										 |  |  | 	puts(cstring); | 
					
						
							| 
									
										
										
										
											2008-12-19 00:50:21 +00:00
										 |  |  | 	fflush(stdout); | 
					
						
							| 
									
										
										
										
											2009-01-02 09:35:33 +00:00
										 |  |  | 	MEM_freeN(cstring); | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-03 07:27:55 +00:00
										 |  |  | Report *BKE_reports_last_displayable(ReportList *reports) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-12 11:32:23 +00:00
										 |  |  | 	Report *report; | 
					
						
							| 
									
										
										
										
											2010-06-03 07:27:55 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 	for (report = reports->list.last; report; report = report->prev) { | 
					
						
							| 
									
										
										
										
											2014-07-20 01:30:29 +10:00
										 |  |  | 		if (ELEM(report->type, RPT_ERROR, RPT_WARNING, RPT_INFO)) | 
					
						
							| 
									
										
										
										
											2010-06-03 07:27:55 +00:00
										 |  |  | 			return report; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							| 
									
										
										
										
											2010-09-03 03:30:20 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-03-12 11:32:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-01 11:34:00 +11:00
										 |  |  | bool BKE_reports_contain(ReportList *reports, ReportType level) | 
					
						
							| 
									
										
										
										
											2012-03-12 11:32:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Report *report; | 
					
						
							| 
									
										
										
										
											2012-03-14 12:03:49 +00:00
										 |  |  | 	if (reports != NULL) { | 
					
						
							| 
									
										
										
										
											2012-05-12 16:11:34 +00:00
										 |  |  | 		for (report = reports->list.first; report; report = report->next) | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 			if (report->type >= level) | 
					
						
							| 
									
										
										
										
											2014-04-01 11:34:00 +11:00
										 |  |  | 				return true; | 
					
						
							| 
									
										
										
										
											2012-03-14 12:03:49 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-04-01 11:34:00 +11:00
										 |  |  | 	return false; | 
					
						
							| 
									
										
										
										
											2012-03-12 11:32:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-11 01:30:44 +00:00
										 |  |  | bool BKE_report_write_file_fp(FILE *fp, ReportList *reports, const char *header) | 
					
						
							| 
									
										
										
										
											2013-01-10 16:37:48 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Report *report; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (header) { | 
					
						
							|  |  |  | 		fputs(header, fp); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (report = reports->list.first; report; report = report->next) { | 
					
						
							|  |  |  | 		fprintf((FILE *)fp, "%s  # %s\n", report->message, report->typestr); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool BKE_report_write_file(const char *filepath, ReportList *reports, const char *header) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	FILE *fp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	errno = 0; | 
					
						
							|  |  |  | 	fp = BLI_fopen(filepath, "wb"); | 
					
						
							|  |  |  | 	if (fp == NULL) { | 
					
						
							|  |  |  | 		fprintf(stderr, "Unable to save '%s': %s\n", | 
					
						
							|  |  |  | 		        filepath, errno ? strerror(errno) : "Unknown error opening file"); | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BKE_report_write_file_fp(fp, reports, header); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fclose(fp); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } |