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