Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "../../stdafx.h"
00013 #include "script_log.hpp"
00014 #include "../../core/alloc_func.hpp"
00015 #include "../../debug.h"
00016 #include "../../window_func.h"
00017
00018 void ScriptLog::Info(const char *message)
00019 {
00020 ScriptLog::Log(LOG_INFO, message);
00021 }
00022
00023 void ScriptLog::Warning(const char *message)
00024 {
00025 ScriptLog::Log(LOG_WARNING, message);
00026 }
00027
00028 void ScriptLog::Error(const char *message)
00029 {
00030 ScriptLog::Log(LOG_ERROR, message);
00031 }
00032
00033 void ScriptLog::Log(ScriptLog::ScriptLogType level, const char *message)
00034 {
00035 if (ScriptObject::GetLogPointer() == NULL) {
00036 ScriptObject::GetLogPointer() = new LogData();
00037 LogData *log = (LogData *)ScriptObject::GetLogPointer();
00038
00039 log->lines = CallocT<char *>(400);
00040 log->type = CallocT<ScriptLog::ScriptLogType>(400);
00041 log->count = 400;
00042 log->pos = log->count - 1;
00043 log->used = 0;
00044 }
00045 LogData *log = (LogData *)ScriptObject::GetLogPointer();
00046
00047
00048 log->pos = (log->pos + 1) % log->count;
00049
00050 if (log->used != log->count) log->used++;
00051
00052
00053 free(log->lines[log->pos]);
00054 log->lines[log->pos] = strdup(message);
00055 log->type[log->pos] = level;
00056
00057
00058 char *p;
00059 while ((p = strchr(log->lines[log->pos], '\n')) != NULL) {
00060 *p = '\0';
00061 break;
00062 }
00063
00064 char logc;
00065
00066 switch (level) {
00067 case LOG_SQ_ERROR: logc = 'S'; break;
00068 case LOG_ERROR: logc = 'E'; break;
00069 case LOG_SQ_INFO: logc = 'P'; break;
00070 case LOG_WARNING: logc = 'W'; break;
00071 case LOG_INFO: logc = 'I'; break;
00072 default: logc = '?'; break;
00073 }
00074
00075
00076 DEBUG(script, level, "[%d] [%c] %s", (uint)ScriptObject::GetRootCompany(), logc, log->lines[log->pos]);
00077 InvalidateWindowData(WC_AI_DEBUG, 0, ScriptObject::GetRootCompany());
00078 }
00079
00080 void ScriptLog::FreeLogPointer()
00081 {
00082 LogData *log = (LogData *)ScriptObject::GetLogPointer();
00083
00084 for (int i = 0; i < log->count; i++) {
00085 free(log->lines[i]);
00086 }
00087
00088 free(log->lines);
00089 free(log->type);
00090 delete log;
00091 }