PocketSphinx  5.0.0
A small speech recognizer
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 #include <stdlib.h>
44 #include <errno.h>
45 
46 #include <pocketsphinx/export.h>
47 
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 #if 0
69 /* Fool Emacs. */
70 }
71 #endif
72 
73 #define E_SYSCALL(stmt, ...) if (stmt) E_FATAL_SYSTEM(__VA_ARGS__);
74 
75 #define FILELINE __FILE__ , __LINE__
76 
80 #define E_FATAL(...) \
81  do { \
82  err_msg(ERR_FATAL, FILELINE, __VA_ARGS__); \
83  exit(EXIT_FAILURE); \
84  } while (0)
85 
89 #define E_FATAL_SYSTEM(...) \
90  do { \
91  err_msg_system(ERR_FATAL, FILELINE, __VA_ARGS__); \
92  exit(EXIT_FAILURE); \
93  } while (0)
94 
98 #define E_ERROR_SYSTEM(...) err_msg_system(ERR_ERROR, FILELINE, __VA_ARGS__)
99 
103 #define E_ERROR(...) err_msg(ERR_ERROR, FILELINE, __VA_ARGS__)
104 
108 #define E_WARN(...) err_msg(ERR_WARN, FILELINE, __VA_ARGS__)
109 
113 #define E_INFO(...) err_msg(ERR_INFO, FILELINE, __VA_ARGS__)
114 
118 #define E_INFOCONT(...) err_msg(ERR_INFO, NULL, 0, __VA_ARGS__)
119 
123 #define E_INFO_NOFN(...) err_msg(ERR_INFO, NULL, 0, __VA_ARGS__)
124 
128 #ifdef SPHINX_DEBUG
129 #define E_DEBUG(...) err_msg(ERR_DEBUG, NULL, 0, __VA_ARGS__)
130 #else
131 #define E_DEBUG(...)
132 #endif
133 
134 typedef enum err_e {
135  ERR_DEBUG,
136  ERR_INFO,
137  ERR_WARN,
138  ERR_ERROR,
139  ERR_FATAL,
140  ERR_MAX
141 } err_lvl_t;
142 
143 POCKETSPHINX_EXPORT
144 void err_msg(err_lvl_t lvl, const char *path, long ln, const char *fmt, ...);
145 
146 POCKETSPHINX_EXPORT
147 void err_msg_system(err_lvl_t lvl, const char *path, long ln, const char *fmt, ...);
148 
149 POCKETSPHINX_EXPORT
150 void err_logfp_cb(void * user_data, err_lvl_t level, const char *fmt, ...);
151 
152 typedef void (*err_cb_f)(void* user_data, err_lvl_t, const char *, ...);
153 
162 POCKETSPHINX_EXPORT
163 int err_set_loglevel(err_lvl_t lvl);
164 
174 POCKETSPHINX_EXPORT
175 const char *err_set_loglevel_str(const char *lvl);
176 
185 POCKETSPHINX_EXPORT
186 void err_set_callback(err_cb_f callback, void *user_data);
187 
193 POCKETSPHINX_EXPORT
194 void err_set_logfp(FILE *stream);
195 
202 POCKETSPHINX_EXPORT
203 FILE *err_get_logfp(void);
204 
213 POCKETSPHINX_EXPORT
214 int err_set_logfile(const char *path);
215 
216 #ifdef __cplusplus
217 }
218 #endif
219 
220 #endif /* !_ERR_H */
err_get_logfp
POCKETSPHINX_EXPORT FILE * err_get_logfp(void)
err_set_callback
POCKETSPHINX_EXPORT void err_set_callback(err_cb_f callback, void *user_data)
err_set_loglevel
POCKETSPHINX_EXPORT int err_set_loglevel(err_lvl_t lvl)
err_set_logfile
POCKETSPHINX_EXPORT int err_set_logfile(const char *path)
err_set_logfp
POCKETSPHINX_EXPORT void err_set_logfp(FILE *stream)
err_set_loglevel_str
const POCKETSPHINX_EXPORT char * err_set_loglevel_str(const char *lvl)