Merge branch 'xa_branch'
[mesa.git] / src / gallium / auxiliary / util / u_debug.c
index f4ad545bee73559b9db127ac31f5fd7b83346067..004df439ff516b32a76a0bb044b165335006956e 100644 (file)
 #include "util/u_surface.h"
 
 #include <limits.h> /* CHAR_BIT */
+#include <ctype.h> /* isalnum */
 
 void _debug_vprintf(const char *format, va_list ap)
 {
-#if defined(PIPE_OS_WINDOWS) || defined(PIPE_OS_EMBEDDED)
+#if defined(PIPE_OS_WINDOWS) || defined(PIPE_SUBSYSTEM_EMBEDDED)
    /* We buffer until we find a newline. */
    static char buf[4096] = {'\0'};
    size_t len = strlen(buf);
@@ -180,6 +181,48 @@ debug_get_num_option(const char *name, long dfault)
    return result;
 }
 
+static boolean str_has_option(const char *str, const char *name)
+{
+   /* Empty string. */
+   if (!*str) {
+      return FALSE;
+   }
+
+   /* OPTION=all */
+   if (!util_strcmp(str, "all")) {
+      return TRUE;
+   }
+
+   /* Find 'name' in 'str' surrounded by non-alphanumeric characters. */
+   {
+      const char *start = str;
+      unsigned name_len = strlen(name);
+
+      /* 'start' is the beginning of the currently-parsed word,
+       * we increment 'str' each iteration.
+       * if we find either the end of string or a non-alphanumeric character,
+       * we compare 'start' up to 'str-1' with 'name'. */
+
+      while (1) {
+         if (!*str || !isalnum(*str)) {
+            if (str-start == name_len &&
+                !memcmp(start, name, name_len)) {
+               return TRUE;
+            }
+
+            if (!*str) {
+               return FALSE;
+            }
+
+            start = str+1;
+         }
+
+         str++;
+      }
+   }
+
+   return FALSE;
+}
 
 unsigned long
 debug_get_flags_option(const char *name, 
@@ -207,7 +250,7 @@ debug_get_flags_option(const char *name,
    else {
       result = 0;
       while( flags->name ) {
-        if (!util_strcmp(str, "all") || util_strstr(str, flags->name ))
+        if (str_has_option(str, flags->name))
            result |= flags->value;
         ++flags;
       }
@@ -359,6 +402,41 @@ const char *u_prim_name( unsigned prim )
 
 
 
+#ifdef DEBUG
+int fl_indent = 0;
+const char* fl_function[1024];
+
+int debug_funclog_enter(const char* f, const int line, const char* file)
+{
+   int i;
+
+   for (i = 0; i < fl_indent; i++)
+      debug_printf("  ");
+   debug_printf("%s\n", f);
+
+   assert(fl_indent < 1023);
+   fl_function[fl_indent++] = f;
+
+   return 0;
+}
+
+void debug_funclog_exit(const char* f, const int line, const char* file)
+{
+   --fl_indent;
+   assert(fl_indent >= 0);
+   assert(fl_function[fl_indent] == f);
+}
+
+void debug_funclog_enter_exit(const char* f, const int line, const char* file)
+{
+   int i;
+   for (i = 0; i < fl_indent; i++)
+      debug_printf("  ");
+   debug_printf("%s\n", f);
+}
+#endif
+
+
 
 #ifdef DEBUG
 /**