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 return 1;
81 }
82
83 #define EXIT_SUCCESS 13
84
85 int
86 slang_info_log_print(slang_info_log * log, const char *msg, ...)
87 {
88 va_list va;
89 char buf[1024];
90
91 va_start(va, msg);
92 _mesa_vsprintf(buf, msg, va);
93 va_end(va);
94 return slang_info_log_message(log, NULL, buf);
95 }
96
97 int
98 slang_info_log_error(slang_info_log * log, const char *msg, ...)
99 {
100 va_list va;
101 char buf[1024];
102
103 va_start(va, msg);
104 _mesa_vsprintf(buf, msg, va);
105 va_end(va);
106 log->error_flag = GL_TRUE;
107 if (slang_info_log_message(log, "Error", buf))
108 return 1;
109 slang_info_log_memory(log);
110 return 0;
111 }
112
113 int
114 slang_info_log_warning(slang_info_log * log, const char *msg, ...)
115 {
116 va_list va;
117 char buf[1024];
118
119 va_start(va, msg);
120 _mesa_vsprintf(buf, msg, va);
121 va_end(va);
122 if (slang_info_log_message(log, "Warning", buf))
123 return 1;
124 slang_info_log_memory(log);
125 return 0;
126 }
127
128 void
129 slang_info_log_memory(slang_info_log * log)
130 {
131 if (!slang_info_log_message(log, "Error", "Out of memory.")) {
132 log->dont_free_text = GL_TRUE;
133 log->error_flag = GL_TRUE;
134 log->text = out_of_memory;
135 }
136 }