fix w component of glsl vec4 asin
[mesa.git] / src / mesa / shader / slang / slang_log.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.3
4 *
5 * Copyright (C) 2005-2007 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25 #include "imports.h"
26 #include "slang_log.h"
27 #include "slang_utility.h"
28
29
30
31 static char *out_of_memory = "Error: Out of memory.\n";
32
33 void
34 slang_info_log_construct(slang_info_log * log)
35 {
36 log->text = NULL;
37 log->dont_free_text = GL_FALSE;
38 log->error_flag = GL_FALSE;
39 }
40
41 void
42 slang_info_log_destruct(slang_info_log * log)
43 {
44 if (!log->dont_free_text)
45 #if 0
46 slang_alloc_free(log->text);
47 #else
48 _mesa_free(log->text);
49 #endif
50 }
51
52 static int
53 slang_info_log_message(slang_info_log * log, const char *prefix,
54 const char *msg)
55 {
56 GLuint size;
57
58 if (log->dont_free_text)
59 return 0;
60 size = slang_string_length(msg) + 2;
61 if (prefix != NULL)
62 size += slang_string_length(prefix) + 2;
63 if (log->text != NULL) {
64 GLuint old_len = slang_string_length(log->text);
65 log->text = (char *)
66 #if 0
67 slang_alloc_realloc(log->text, old_len + 1, old_len + size);
68 #else
69 _mesa_realloc(log->text, old_len + 1, old_len + size);
70 #endif
71 }
72 else {
73 #if 0
74 log->text = (char *) (slang_alloc_malloc(size));
75 #else
76 log->text = (char *) (_mesa_malloc(size));
77 #endif
78 if (log->text != NULL)
79 log->text[0] = '\0';
80 }
81 if (log->text == NULL)
82 return 0;
83 if (prefix != NULL) {
84 slang_string_concat(log->text, prefix);
85 slang_string_concat(log->text, ": ");
86 }
87 slang_string_concat(log->text, msg);
88 slang_string_concat(log->text, "\n");
89 return 1;
90 }
91
92 int
93 slang_info_log_print(slang_info_log * log, const char *msg, ...)
94 {
95 va_list va;
96 char buf[1024];
97
98 va_start(va, msg);
99 _mesa_vsprintf(buf, msg, va);
100 va_end(va);
101 return slang_info_log_message(log, NULL, buf);
102 }
103
104 int
105 slang_info_log_error(slang_info_log * log, const char *msg, ...)
106 {
107 va_list va;
108 char buf[1024];
109
110 va_start(va, msg);
111 _mesa_vsprintf(buf, msg, va);
112 va_end(va);
113 log->error_flag = GL_TRUE;
114 if (slang_info_log_message(log, "Error", buf))
115 return 1;
116 slang_info_log_memory(log);
117 return 0;
118 }
119
120 int
121 slang_info_log_warning(slang_info_log * log, const char *msg, ...)
122 {
123 va_list va;
124 char buf[1024];
125
126 va_start(va, msg);
127 _mesa_vsprintf(buf, msg, va);
128 va_end(va);
129 if (slang_info_log_message(log, "Warning", buf))
130 return 1;
131 slang_info_log_memory(log);
132 return 0;
133 }
134
135 void
136 slang_info_log_memory(slang_info_log * log)
137 {
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;
142 }
143 }