2
* Mesa 3-D graphics library
5
* Copyright (C) 2005-2007 Brian Paul All Rights Reserved.
6
* Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8
* Permission is hereby granted, free of charge, to any person obtaining a
9
* copy of this software and associated documentation files (the "Software"),
10
* to deal in the Software without restriction, including without limitation
11
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
* and/or sell copies of the Software, and to permit persons to whom the
13
* Software is furnished to do so, subject to the following conditions:
15
* The above copyright notice and this permission notice shall be included
16
* in all copies or substantial portions of the Software.
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
#include "main/imports.h"
27
#include "slang_log.h"
28
#include "slang_utility.h"
32
static char *out_of_memory = "Error: Out of memory.\n";
35
slang_info_log_construct(slang_info_log * log)
38
log->dont_free_text = GL_FALSE;
39
log->error_flag = GL_FALSE;
43
slang_info_log_destruct(slang_info_log * log)
45
if (!log->dont_free_text)
50
slang_info_log_message(slang_info_log * log, const char *prefix,
55
if (log->dont_free_text)
57
size = slang_string_length(msg) + 2;
59
size += slang_string_length(prefix) + 2;
60
if (log->text != NULL) {
61
GLuint old_len = slang_string_length(log->text);
63
_mesa_realloc(log->text, old_len + 1, old_len + size);
66
log->text = (char *) (malloc(size));
67
if (log->text != NULL)
70
if (log->text == NULL)
73
slang_string_concat(log->text, prefix);
74
slang_string_concat(log->text, ": ");
76
slang_string_concat(log->text, msg);
77
slang_string_concat(log->text, "\n");
83
slang_info_log_print(slang_info_log * log, const char *msg, ...)
89
vsprintf(buf, msg, va);
91
return slang_info_log_message(log, NULL, buf);
95
slang_info_log_error(slang_info_log * log, const char *msg, ...)
101
vsprintf(buf, msg, va);
103
log->error_flag = GL_TRUE;
104
if (slang_info_log_message(log, "Error", buf))
106
slang_info_log_memory(log);
111
slang_info_log_warning(slang_info_log * log, const char *msg, ...)
117
vsprintf(buf, msg, va);
119
if (slang_info_log_message(log, "Warning", buf))
121
slang_info_log_memory(log);
126
slang_info_log_memory(slang_info_log * log)
128
if (!slang_info_log_message(log, "Error", "Out of memory.")) {
129
log->dont_free_text = GL_TRUE;
130
log->error_flag = GL_TRUE;
131
log->text = out_of_memory;