os/ossrv/genericopenlibs/liboil/src/liboildebug.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2  * LIBOIL - Library of Optimized Inner Loops
     3  * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
     4  * All rights reserved.
     5  *
     6  * Redistribution and use in source and binary forms, with or without
     7  * modification, are permitted provided that the following conditions
     8  * are met:
     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.
    14  * 
    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.
    26  */
    27 //Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
    28 
    29 #ifdef HAVE_CONFIG_H
    30 #include "config.h"
    31 #endif
    32 #include <liboil/liboilfunction.h>
    33 #include <liboil/liboildebug.h>
    34 
    35 #include <stdio.h>
    36 #include <string.h>
    37 #include <stdarg.h>
    38 #include <stdlib.h>
    39 
    40 /**
    41  * SECTION:liboildebug
    42  * @title: Debug
    43  * @short_description: Printing and formatting debug information
    44  */
    45 
    46 static void oil_debug_print_valist (int level, const char *file,
    47     const char *func, int line, const char *format, va_list args);
    48 
    49 static int _oil_debug_level = OIL_DEBUG_ERROR;
    50 
    51 static OilDebugPrintFunc _oil_debug_print_func = oil_debug_print_valist;
    52 
    53 #ifdef __SYMBIAN32__
    54  
    55 #endif
    56 void
    57 _oil_debug_init(void)
    58 {
    59   const char *envvar;
    60 
    61   envvar = getenv ("OIL_DEBUG");
    62   if (envvar != NULL) {
    63     char *end = NULL;
    64     int level;
    65     level = strtol (envvar, &end, 0);
    66     if (end > envvar) {
    67       _oil_debug_level = level;
    68     }
    69   }
    70 
    71   OIL_INFO ("liboil-" VERSION " debug init");
    72 }
    73 
    74 static void
    75 oil_debug_print_valist (int level, const char *file, const char *func,
    76         int line, const char *format, va_list args)
    77 {
    78   static const char *level_names[] = { "NONE", "ERROR", "WARNING", "INFO",
    79     "DEBUG", "LOG" };
    80   const char *level_name = "unknown";
    81 
    82   if (level > _oil_debug_level) return;
    83 
    84   if(level>=OIL_DEBUG_NONE && level<=OIL_DEBUG_LOG){
    85     level_name = level_names[level];
    86   }
    87   
    88   fprintf (stderr, "OIL: %s %s %d: %s(): ", level_name, file, line, func);
    89   vfprintf (stderr, format, args);
    90   fprintf (stderr, "\n");
    91 }
    92 
    93 #ifdef __SYMBIAN32__
    94 EXPORT_C 
    95 #endif
    96 void
    97 oil_debug_print (int level, const char *file, const char *func,
    98         int line, const char *format, ...)
    99 {
   100   va_list var_args;
   101 
   102   va_start (var_args, format);
   103   _oil_debug_print_func (level, file, func, line, format, var_args);
   104   va_end (var_args);
   105 }
   106 
   107 /**
   108  * oil_debug_get_level:
   109  *
   110  * Gets the current debug level.
   111  *
   112  * Returns: the current debug level
   113  */
   114  #ifdef __SYMBIAN32__
   115  EXPORT_C
   116 #endif
   117 int
   118 oil_debug_get_level (void)
   119 {
   120   return _oil_debug_level;
   121 }
   122 
   123 /**
   124  * oil_debug_set_level:
   125  * @level: the new debug level
   126  *
   127  * Sets the current debug level.
   128  */
   129 #ifdef __SYMBIAN32__
   130  EXPORT_C
   131 #endif 
   132 void
   133 oil_debug_set_level (int level)
   134 {
   135   _oil_debug_level = level;
   136 }
   137 
   138 /**
   139  * oil_debug_set_print_function:
   140  * @func:
   141  *
   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.
   145  */
   146 #ifdef __SYMBIAN32__
   147  EXPORT_C
   148 #endif
   149 void
   150 oil_debug_set_print_function (OilDebugPrintFunc func)
   151 {
   152   if (func) {
   153     _oil_debug_print_func = func;
   154   } else {
   155     _oil_debug_print_func = oil_debug_print_valist;
   156   }
   157 }
   158