SphinxBase 0.6
err_wince.c
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 * err_wince.c -- Package for checking and catching common errors, printing out
39 * errors nicely, etc.
40 * WinCE has no standard library worth the name so we need this
41 */
42
43
44#include <stdio.h>
45#include <stdlib.h>
46#include <string.h>
47#include <windows.h>
48#include <assert.h>
49
50#include "sphinxbase/err.h"
52
53int cst_verrmsg(const char *fmt, va_list args)
54{
55 char msg[256];
56 WCHAR *wmsg;
57 size_t len;
58
59 _vsnprintf(msg,256,fmt,args);
60
61 len = mbstowcs(NULL,msg,0) + 1;
62 wmsg = ckd_calloc(len,sizeof(*wmsg));
63 mbstowcs(wmsg,msg,len);
64
65 OutputDebugStringW(wmsg);
66 ckd_free(wmsg);
67 return 0;
68}
69
70int cst_errmsg(const char *fmt, ...)
71{
72 va_list args;
73
74 va_start(args,fmt);
75 cst_verrmsg(fmt, args);
76 va_end(args);
77 return 0;
78}
79
80void
81_E__pr_info_header_wofn(char const *msg)
82{
83 cst_errmsg("%s:\t", msg);
84}
85
86void
87_E__pr_header(char const *f, long ln, char const *msg)
88{
89 cst_errmsg("%s: \"%s\", line %ld: ", msg, f, ln);
90}
91
92void
93_E__pr_info_header(char const *f, long ln, char const *msg)
94{
95 cst_errmsg("%s: %s(%ld): ", msg, f, ln);
96}
97
98void
99_E__pr_warn(char const *fmt, ...)
100{
101 va_list pvar;
102
103 va_start(pvar, fmt);
104 cst_verrmsg(fmt, pvar);
105 va_end(pvar);
106}
107
108void
109_E__pr_info(char const *fmt, ...)
110{
111 va_list pvar;
112
113 va_start(pvar, fmt);
114 cst_verrmsg(fmt, pvar);
115 va_end(pvar);
116}
117
118void
119_E__die_error(char const *fmt, ...)
120{
121 va_list pvar;
122
123 va_start(pvar, fmt);
124 cst_verrmsg(fmt, pvar);
125 va_end(pvar);
126 exit(-1);
127}
128
129void
130_E__fatal_sys_error(char const *fmt, ...)
131{
132 LPVOID msg_buf;
133 DWORD error;
134 va_list pvar;
135
136 error = GetLastError();
137 va_start(pvar, fmt);
138 cst_verrmsg(fmt, pvar);
139 va_end(pvar);
140
141 OutputDebugStringW(L"; ");
142 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
143 FORMAT_MESSAGE_FROM_SYSTEM |
144 FORMAT_MESSAGE_IGNORE_INSERTS,
145 NULL,
146 error,
147 0, // Default language
148 (LPTSTR) &msg_buf,
149 0,
150 NULL);
151 OutputDebugString(msg_buf);
152 LocalFree(msg_buf);
153
154 exit(error);
155}
156
157void
158_E__sys_error(char const *fmt, ...)
159{
160 LPVOID msg_buf;
161 DWORD error;
162 va_list pvar;
163
164 error = GetLastError();
165 va_start(pvar, fmt);
166 cst_verrmsg(fmt, pvar);
167 va_end(pvar);
168
169 OutputDebugStringW(L"; ");
170 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
171 FORMAT_MESSAGE_FROM_SYSTEM |
172 FORMAT_MESSAGE_IGNORE_INSERTS,
173 NULL,
174 error,
175 0, // Default language
176 (LPTSTR) &msg_buf,
177 0,
178 NULL);
179 OutputDebugString(msg_buf);
180 LocalFree(msg_buf);
181}
182
183void
184_E__abort_error(char const *fmt, ...)
185{
186 va_list pvar;
187
188 va_start(pvar, fmt);
189 cst_verrmsg(fmt, pvar);
190 va_end(pvar);
191
192 assert(2+2 == 5);
193}
Sphinx's memory allocation/deallocation routines.
SPHINXBASE_EXPORT void ckd_free(void *ptr)
Test and free a 1-D array.
Definition ckd_alloc.c:241
#define ckd_calloc(n, sz)
Macros to simplify the use of above functions.
Definition ckd_alloc.h:248
Implementation of logging routines.