SphinxBase 5prealpha
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/* Win32/WinCE DLL gunk */
47#include <sphinxbase/sphinxbase_export.h>
48
66#ifdef __cplusplus
67extern "C" {
68#endif
69#if 0
70/* Fool Emacs. */
71}
72#endif
73
74#define E_SYSCALL(stmt, ...) if (stmt) E_FATAL_SYSTEM(__VA_ARGS__);
75
76#define FILELINE __FILE__ , __LINE__
77
81#define E_FATAL(...) \
82 do { \
83 err_msg(ERR_FATAL, FILELINE, __VA_ARGS__); \
84 exit(EXIT_FAILURE); \
85 } while (0)
86
90#define E_FATAL_SYSTEM(...) \
91 do { \
92 err_msg_system(ERR_FATAL, FILELINE, __VA_ARGS__); \
93 exit(EXIT_FAILURE); \
94 } while (0)
95
99#define E_ERROR_SYSTEM(...) err_msg_system(ERR_ERROR, FILELINE, __VA_ARGS__)
100
104#define E_ERROR(...) err_msg(ERR_ERROR, FILELINE, __VA_ARGS__)
105
109#define E_WARN(...) err_msg(ERR_WARN, FILELINE, __VA_ARGS__)
110
114#define E_INFO(...) err_msg(ERR_INFO, FILELINE, __VA_ARGS__)
115
119#define E_INFOCONT(...) err_msg(ERR_INFOCONT, NULL, 0, __VA_ARGS__)
120
124#define E_INFO_NOFN(...) err_msg(ERR_INFO, NULL, 0, __VA_ARGS__)
125
129#ifdef SPHINX_DEBUG
130#define E_DEBUG(...) err_msg(ERR_DEBUG, NULL, 0, __VA_ARGS__)
131#else
132#define E_DEBUG(...)
133#endif
134
135typedef enum err_e {
136 ERR_DEBUG,
137 ERR_INFO,
138 ERR_INFOCONT,
139 ERR_WARN,
140 ERR_ERROR,
141 ERR_FATAL,
142 ERR_MAX
143} err_lvl_t;
144
145SPHINXBASE_EXPORT void
146err_msg(err_lvl_t lvl, const char *path, long ln, const char *fmt, ...);
147
148SPHINXBASE_EXPORT void
149err_msg_system(err_lvl_t lvl, const char *path, long ln, const char *fmt, ...);
150
151SPHINXBASE_EXPORT void
152err_logfp_cb(void * user_data, err_lvl_t level, const char *fmt, ...);
153
154typedef void (*err_cb_f)(void* user_data, err_lvl_t, const char *, ...);
155
164SPHINXBASE_EXPORT void
165err_set_callback(err_cb_f callback, void *user_data);
166
172SPHINXBASE_EXPORT void
173err_set_logfp(FILE *stream);
174
181SPHINXBASE_EXPORT FILE *
182err_get_logfp(void);
183
192SPHINXBASE_EXPORT int
193err_set_logfile(const char *path);
194
195#ifdef __cplusplus
196}
197#endif
198
199#endif /* !_ERR_H */
SPHINXBASE_EXPORT int err_set_logfile(const char *path)
Append all log messages to a given file.
Definition: err.c:240
SPHINXBASE_EXPORT void err_set_logfp(FILE *stream)
Direct all logging to a given filehandle if default logfp callback is set.
Definition: err.c:254
SPHINXBASE_EXPORT void err_set_callback(err_cb_f callback, void *user_data)
Sets function to output error messages.
Definition: err.c:278
SPHINXBASE_EXPORT FILE * err_get_logfp(void)
Get the current logging filehandle.
Definition: err.c:267