Change error/warning functions to print to the info log.
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 17 Jun 2010 22:15:35 +0000 (15:15 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Sat, 19 Jun 2010 18:44:21 +0000 (11:44 -0700)
glsl_parser_extras.cpp
ir_reader.cpp

index 8cf765f95de528a34a5be6dd377d3c8e22ccbfce..7bd30de7c2441fc85a5a78a1328d2f831fa066d9 100644 (file)
 #include <string.h>
 #include <assert.h>
 
+extern "C" {
+#include <talloc.h>
+}
+
 #include "ast.h"
 #include "glsl_parser_extras.h"
 #include "glsl_parser.h"
@@ -47,24 +51,20 @@ void
 _mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state,
                 const char *fmt, ...)
 {
-   char buf[1024];
-   int len;
    va_list ap;
 
    state->error = true;
 
-   len = snprintf(buf, sizeof(buf), "%u:%u(%u): error: ",
-                 locp->source, locp->first_line, locp->first_column);
-
+   assert(state->info_log != NULL);
+   state->info_log = talloc_asprintf_append(state->info_log,
+                                           "%u:%u(%u): error: ",
+                                           locp->source,
+                                           locp->first_line,
+                                           locp->first_column);
    va_start(ap, fmt);
-   vsnprintf(buf + len, sizeof(buf) - len, fmt, ap);
+   state->info_log = talloc_vasprintf_append(state->info_log, fmt, ap);
    va_end(ap);
-
-   printf("%s\n", buf);
-
-   if (state->info_log)
-      free(state->info_log);
-   state->info_log = strdup(buf);
+   state->info_log = talloc_strdup_append(state->info_log, "\n");
 }
 
 
@@ -72,22 +72,18 @@ void
 _mesa_glsl_warning(const YYLTYPE *locp, _mesa_glsl_parse_state *state,
                   const char *fmt, ...)
 {
-   char buf[1024];
-   int len;
    va_list ap;
 
-   len = snprintf(buf, sizeof(buf), "%u:%u(%u): warning: ",
-                 locp->source, locp->first_line, locp->first_column);
-
+   assert(state->info_log != NULL);
+   state->info_log = talloc_asprintf_append(state->info_log,
+                                           "%u:%u(%u): warning: ",
+                                           locp->source,
+                                           locp->first_line,
+                                           locp->first_column);
    va_start(ap, fmt);
-   vsnprintf(buf + len, sizeof(buf) - len, fmt, ap);
+   state->info_log = talloc_vasprintf_append(state->info_log, fmt, ap);
    va_end(ap);
-
-   printf("%s\n", buf);
-
-   if (!state->info_log) {
-      state->info_log = strdup(buf);
-   }
+   state->info_log = talloc_strdup_append(state->info_log, "\n");
 }
 
 
index 23981a0f51402952291e7a7b36f0b1a8e25da0cf..5cbce333f41a669bf3fdcef86cc13e7d54cace0e 100644 (file)
  */
 #include <cstdio>
 #include <cstdarg>
+
+extern "C" {
+#include <talloc.h>
+}
+
 #include "ir_reader.h"
 #include "glsl_parser_extras.h"
 #include "glsl_types.h"
@@ -86,17 +91,18 @@ ir_read_error(_mesa_glsl_parse_state *state, s_expression *expr,
 
    state->error = true;
 
-   printf("error: ");
+   state->info_log = talloc_strdup_append(state->info_log, "error: ");
 
    va_start(ap, fmt);
-   vprintf(fmt, ap);
+   state->info_log = talloc_vasprintf_append(state->info_log, fmt, ap);
    va_end(ap);
-   printf("\n");
+   state->info_log = talloc_strdup_append(state->info_log, "\n");
 
    if (expr != NULL) {
-      printf("...in this context:\n   ");
+      state->info_log = talloc_strdup_append(state->info_log,
+                                            "...in this context:\n   ");
       expr->print();
-      printf("\n\n");
+      state->info_log = talloc_strdup_append(state->info_log, "\n\n");
    }
 }