nv50: fix build-predicate function
[mesa.git] / src / mesa / 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 "slang_log.h"
28 #include "slang_utility.h"
29
30
31
32 static char *out_of_memory = "Error: Out of memory.\n";
33
34 void
35 slang_info_log_construct(slang_info_log * log)
36 {
37 log->text = NULL;
38 log->dont_free_text = GL_FALSE;
39 log->error_flag = GL_FALSE;
40 }
41
42 void
43 slang_info_log_destruct(slang_info_log * log)
44 {
45 if (!log->dont_free_text)
46 free(log->text);
47 }
48
49 static int
50 slang_info_log_message(slang_info_log * log, const char *prefix,
51 const char *msg)
52 {
53 GLuint size;
54
55 if (log->dont_free_text)
56 return 0;
57 size = slang_string_length(msg) + 2;
58 if (prefix != NULL)
59 size += slang_string_length(prefix) + 2;
60 if (log->text != NULL) {
61 GLuint old_len = slang_string_length(log->text);
62 log->text = (char *)
63 _mesa_realloc(log->text, old_len + 1, old_len + size);
64 }
65 else {
66 log->text = (char *) (malloc(size));
67 if (log->text != NULL)
68 log->text[0] = '\0';
69 }
70 if (log->text == NULL)
71 return 0;
72 if (prefix != NULL) {
73 slang_string_concat(log->text, prefix);
74 slang_string_concat(log->text, ": ");
75 }
76 slang_string_concat(log->text, msg);
77 slang_string_concat(log->text, "\n");
78
79 return 1;
80 }
81
82 int
83 slang_info_log_print(slang_info_log * log, const char *msg, ...)
84 {
85 va_list va;
86 char buf[1024];
87
88 va_start(va, msg);
89 vsprintf(buf, msg, va);
90 va_end(va);
91 return slang_info_log_message(log, NULL, buf);
92 }
93
94 int
95 slang_info_log_error(slang_info_log * log, const char *msg, ...)
96 {
97 va_list va;
98 char buf[1024];
99
100 va_start(va, msg);
101 vsprintf(buf, msg, va);
102 va_end(va);
103 log->error_flag = GL_TRUE;
104 if (slang_info_log_message(log, "Error", buf))
105 return 1;
106 slang_info_log_memory(log);
107 return 0;
108 }
109
110 int
111 slang_info_log_warning(slang_info_log * log, const char *msg, ...)
112 {
113 va_list va;
114 char buf[1024];
115
116 va_start(va, msg);
117 vsprintf(buf, msg, va);
118 va_end(va);
119 if (slang_info_log_message(log, "Warning", buf))
120 return 1;
121 slang_info_log_memory(log);
122 return 0;
123 }
124
125 void
126 slang_info_log_memory(slang_info_log * log)
127 {
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;
132 }
133 }