2 * Mesa 3-D graphics library
5 * Copyright (C) 2005-2007 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include "slang_log.h"
27 #include "slang_utility.h"
31 static char *out_of_memory
= "Error: Out of memory.\n";
34 slang_info_log_construct(slang_info_log
* log
)
37 log
->dont_free_text
= GL_FALSE
;
38 log
->error_flag
= GL_FALSE
;
42 slang_info_log_destruct(slang_info_log
* log
)
44 if (!log
->dont_free_text
)
46 slang_alloc_free(log
->text
);
48 _mesa_free(log
->text
);
53 slang_info_log_message(slang_info_log
* log
, const char *prefix
,
58 if (log
->dont_free_text
)
60 size
= slang_string_length(msg
) + 2;
62 size
+= slang_string_length(prefix
) + 2;
63 if (log
->text
!= NULL
) {
64 GLuint old_len
= slang_string_length(log
->text
);
67 slang_alloc_realloc(log
->text
, old_len
+ 1, old_len
+ size
);
69 _mesa_realloc(log
->text
, old_len
+ 1, old_len
+ size
);
74 log
->text
= (char *) (slang_alloc_malloc(size
));
76 log
->text
= (char *) (_mesa_malloc(size
));
78 if (log
->text
!= NULL
)
81 if (log
->text
== NULL
)
84 slang_string_concat(log
->text
, prefix
);
85 slang_string_concat(log
->text
, ": ");
87 slang_string_concat(log
->text
, msg
);
88 slang_string_concat(log
->text
, "\n");
93 slang_info_log_print(slang_info_log
* log
, const char *msg
, ...)
99 _mesa_vsprintf(buf
, msg
, va
);
101 return slang_info_log_message(log
, NULL
, buf
);
105 slang_info_log_error(slang_info_log
* log
, const char *msg
, ...)
111 _mesa_vsprintf(buf
, msg
, va
);
113 log
->error_flag
= GL_TRUE
;
114 if (slang_info_log_message(log
, "Error", buf
))
116 slang_info_log_memory(log
);
121 slang_info_log_warning(slang_info_log
* log
, const char *msg
, ...)
127 _mesa_vsprintf(buf
, msg
, va
);
129 if (slang_info_log_message(log
, "Warning", buf
))
131 slang_info_log_memory(log
);
136 slang_info_log_memory(slang_info_log
* log
)
138 if (!slang_info_log_message(log
, "Error", "Out of memory.")) {
139 log
->dont_free_text
= GL_TRUE
;
140 log
->error_flag
= GL_TRUE
;
141 log
->text
= out_of_memory
;