Update contrib.
2 * LIBOIL - Library of Optimized Inner Loops
3 * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
27 //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
32 #include <liboil/liboilfunction.h>
33 #include <liboil/liboildebug.h>
43 * @short_description: Printing and formatting debug information
46 static void oil_debug_print_valist (int level, const char *file,
47 const char *func, int line, const char *format, va_list args);
49 static int _oil_debug_level = OIL_DEBUG_ERROR;
51 static OilDebugPrintFunc _oil_debug_print_func = oil_debug_print_valist;
61 envvar = getenv ("OIL_DEBUG");
65 level = strtol (envvar, &end, 0);
67 _oil_debug_level = level;
71 OIL_INFO ("liboil-" VERSION " debug init");
75 oil_debug_print_valist (int level, const char *file, const char *func,
76 int line, const char *format, va_list args)
78 static const char *level_names[] = { "NONE", "ERROR", "WARNING", "INFO",
80 const char *level_name = "unknown";
82 if (level > _oil_debug_level) return;
84 if(level>=OIL_DEBUG_NONE && level<=OIL_DEBUG_LOG){
85 level_name = level_names[level];
88 fprintf (stderr, "OIL: %s %s %d: %s(): ", level_name, file, line, func);
89 vfprintf (stderr, format, args);
90 fprintf (stderr, "\n");
97 oil_debug_print (int level, const char *file, const char *func,
98 int line, const char *format, ...)
102 va_start (var_args, format);
103 _oil_debug_print_func (level, file, func, line, format, var_args);
108 * oil_debug_get_level:
110 * Gets the current debug level.
112 * Returns: the current debug level
118 oil_debug_get_level (void)
120 return _oil_debug_level;
124 * oil_debug_set_level:
125 * @level: the new debug level
127 * Sets the current debug level.
133 oil_debug_set_level (int level)
135 _oil_debug_level = level;
139 * oil_debug_set_print_function:
142 * Sets the function to call when outputting debugging information.
143 * A value of NULL for @func will restore the default handler,
144 * which prints debugging information to stderr.
150 oil_debug_set_print_function (OilDebugPrintFunc func)
153 _oil_debug_print_func = func;
155 _oil_debug_print_func = oil_debug_print_valist;