SphinxBase  0.6
err.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 1999-2004 Carnegie Mellon University. All rights
4  * 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  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * This work was supported in part by funding from the Defense Advanced
19  * Research Projects Agency and the National Science Foundation of the
20  * United States of America, and the CMU Sphinx Speech Consortium.
21  *
22  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * ====================================================================
35  *
36  */
37 
38 #ifndef _LIBUTIL_ERR_H_
39 #define _LIBUTIL_ERR_H_
40 
41 #include <stdarg.h>
42 #include <stdio.h>
43 #ifndef _WIN32_WCE
44 #include <errno.h>
45 #endif
46 
47 /* Win32/WinCE DLL gunk */
48 #include <sphinxbase/sphinxbase_export.h>
49 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 #if 0
71 /* Fool Emacs. */
72 }
73 #endif
74 
75 SPHINXBASE_EXPORT
76 void _E__pr_header(char const *file, long line, char const *msg);
77 SPHINXBASE_EXPORT
78 void _E__pr_debug_header(char const *file, long line, int level);
79 SPHINXBASE_EXPORT
80 void _E__pr_info_header(char const *file, long line, char const *tag);
81 SPHINXBASE_EXPORT
82 void _E__pr_info_header_wofn(char const *msg);
83 SPHINXBASE_EXPORT
84 void _E__pr_warn(char const *fmt, ...);
85 SPHINXBASE_EXPORT
86 void _E__pr_info(char const *fmt, ...);
87 SPHINXBASE_EXPORT
88 void _E__die_error(char const *fmt, ...);
89 SPHINXBASE_EXPORT
90 void _E__abort_error(char const *fmt, ...);
91 SPHINXBASE_EXPORT
92 void _E__sys_error(char const *fmt, ...);
93 SPHINXBASE_EXPORT
94 void _E__fatal_sys_error(char const *fmt, ...);
95 
102 SPHINXBASE_EXPORT
103 FILE *err_set_logfp(FILE *logfp);
104 
109 SPHINXBASE_EXPORT
110 FILE * err_get_logfp(void);
111 
112 
121 SPHINXBASE_EXPORT
122 int err_set_logfile(char const *file);
123 
127 #define E_FATAL _E__pr_header(__FILE__, __LINE__, "FATAL_ERROR"),_E__die_error
128 
132 #define E_FATAL_SYSTEM _E__pr_header(__FILE__, __LINE__, "SYSTEM_ERROR"),_E__fatal_sys_error
133 
137 #define E_WARN_SYSTEM _E__pr_header(__FILE__, __LINE__, "SYSTEM_ERROR"),_E__sys_error
138 
142 #define E_ERROR_SYSTEM _E__pr_header(__FILE__, __LINE__, "SYSTEM_ERROR"),_E__sys_error
143 
147 #define E_INFO _E__pr_info_header(__FILE__, __LINE__, "INFO"),_E__pr_info
148 
153 #define E_INFOCONT _E__pr_info
154 
158 #define E_INFO_NOFN _E__pr_info_header_wofn("INFO"),_E__pr_info
159 
160 
164 #define E_WARN _E__pr_header(__FILE__, __LINE__, "WARNING"),_E__pr_warn
165 
169 #define E_ERROR _E__pr_header(__FILE__, __LINE__, "ERROR"),_E__pr_warn
170 
178 SPHINXBASE_EXPORT
179 int err_set_debug_level(int level);
180 
186 SPHINXBASE_EXPORT
187 int err_get_debug_level(void);
188 
199 #ifdef SPHINX_DEBUG
200 #define E_DEBUG(level,x) { \
201  if (err_get_debug_level() >= level) { \
202  _E__pr_header(__FILE__, __LINE__, "DEBUG"); \
203  _E__pr_info x; \
204  } \
205  }
206 #define E_DEBUGCONT(level,x) { \
207  if (err_get_debug_level() >= level) { \
208  _E__pr_info x; \
209  } \
210  }
211 #else
212 #define E_DEBUG(level,x)
213 #define E_DEBUGCONT(level,x)
214 #endif
215 
216 #ifdef __cplusplus
217 }
218 #endif
219 
220 
221 #endif /* !_ERR_H */
222 
223 
SPHINXBASE_EXPORT FILE * err_get_logfp(void)
Get the current logging filehandle.
Definition: err.c:157
SPHINXBASE_EXPORT int err_set_debug_level(int level)
Set debugging verbosity level.
Definition: err.c:68
SPHINXBASE_EXPORT int err_get_debug_level(void)
Get debugging verbosity level.
Definition: err.c:74
SPHINXBASE_EXPORT int err_set_logfile(char const *file)
Append all log messages to a given file.
Definition: err.c:190
SPHINXBASE_EXPORT FILE * err_set_logfp(FILE *logfp)
Direct all logging to a given filehandle.
Definition: err.c:179