SphinxBase 0.6
include/sphinxbase/err.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
00002 /* ====================================================================
00003  * Copyright (c) 1999-2004 Carnegie Mellon University.  All rights
00004  * reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer. 
00012  *
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in
00015  *    the documentation and/or other materials provided with the
00016  *    distribution.
00017  *
00018  * This work was supported in part by funding from the Defense Advanced 
00019  * Research Projects Agency and the National Science Foundation of the 
00020  * United States of America, and the CMU Sphinx Speech Consortium.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 
00023  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
00024  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00025  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
00026  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00027  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00028  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00029  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00030  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00031  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00032  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * ====================================================================
00035  *
00036  */
00037 
00038 #ifndef _LIBUTIL_ERR_H_
00039 #define _LIBUTIL_ERR_H_
00040 
00041 #include <stdarg.h>
00042 #include <stdio.h>
00043 #ifndef _WIN32_WCE
00044 #include <errno.h>
00045 #endif
00046 
00047 /* Win32/WinCE DLL gunk */
00048 #include <sphinxbase/sphinxbase_export.h>
00049 
00067 #ifdef __cplusplus
00068 extern "C" {
00069 #endif
00070 #if 0
00071 /* Fool Emacs. */
00072 }
00073 #endif
00074 
00075 SPHINXBASE_EXPORT
00076 void _E__pr_header(char const *file, long line, char const *msg);
00077 SPHINXBASE_EXPORT
00078 void _E__pr_debug_header(char const *file, long line, int level);
00079 SPHINXBASE_EXPORT
00080 void _E__pr_info_header(char const *file, long line, char const *tag);
00081 SPHINXBASE_EXPORT
00082 void _E__pr_info_header_wofn(char const *msg);
00083 SPHINXBASE_EXPORT
00084 void _E__pr_warn(char const *fmt, ...);
00085 SPHINXBASE_EXPORT
00086 void _E__pr_info(char const *fmt, ...);
00087 SPHINXBASE_EXPORT
00088 void _E__die_error(char const *fmt, ...);
00089 SPHINXBASE_EXPORT
00090 void _E__abort_error(char const *fmt, ...);
00091 SPHINXBASE_EXPORT
00092 void _E__sys_error(char const *fmt, ...);
00093 SPHINXBASE_EXPORT
00094 void _E__fatal_sys_error(char const *fmt, ...);
00095 
00102 SPHINXBASE_EXPORT
00103 FILE *err_set_logfp(FILE *logfp);
00104 
00109 SPHINXBASE_EXPORT
00110 FILE * err_get_logfp(void);
00111 
00112 
00121 SPHINXBASE_EXPORT
00122 int err_set_logfile(char const *file);
00123 
00127 #define E_FATAL  _E__pr_header(__FILE__, __LINE__, "FATAL_ERROR"),_E__die_error
00128 
00132 #define E_FATAL_SYSTEM  _E__pr_header(__FILE__, __LINE__, "SYSTEM_ERROR"),_E__fatal_sys_error
00133 
00137 #define E_WARN_SYSTEM   _E__pr_header(__FILE__, __LINE__, "SYSTEM_ERROR"),_E__sys_error
00138 
00142 #define E_ERROR_SYSTEM  _E__pr_header(__FILE__, __LINE__, "SYSTEM_ERROR"),_E__sys_error
00143 
00147 #define E_INFO    _E__pr_info_header(__FILE__, __LINE__, "INFO"),_E__pr_info
00148 
00153 #define E_INFOCONT        _E__pr_info
00154 
00158 #define E_INFO_NOFN _E__pr_info_header_wofn("INFO"),_E__pr_info
00159 
00160 
00164 #define E_WARN    _E__pr_header(__FILE__, __LINE__, "WARNING"),_E__pr_warn
00165 
00169 #define E_ERROR   _E__pr_header(__FILE__, __LINE__, "ERROR"),_E__pr_warn
00170 
00178 SPHINXBASE_EXPORT
00179 int err_set_debug_level(int level);
00180 
00186 SPHINXBASE_EXPORT
00187 int err_get_debug_level(void);
00188 
00199 #ifdef SPHINX_DEBUG
00200 #define E_DEBUG(level,x) {                              \
00201         if (err_get_debug_level() >= level) {           \
00202             _E__pr_header(__FILE__, __LINE__, "DEBUG"); \
00203             _E__pr_info x;                              \
00204         }                                               \
00205     }
00206 #define E_DEBUGCONT(level,x) {                          \
00207         if (err_get_debug_level() >= level) {           \
00208             _E__pr_info x;                              \
00209         }                                               \
00210     }
00211 #else
00212 #define E_DEBUG(level,x)
00213 #define E_DEBUGCONT(level,x)
00214 #endif
00215 
00216 #ifdef __cplusplus
00217 }
00218 #endif
00219 
00220 
00221 #endif /* !_ERR_H */
00222 
00223