SphinxBase 0.6
|
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 * err_wince.c -- Package for checking and catching common errors, printing out 00039 * errors nicely, etc. 00040 * WinCE has no standard library worth the name so we need this 00041 */ 00042 00043 00044 #include <stdio.h> 00045 #include <stdlib.h> 00046 #include <string.h> 00047 #include <windows.h> 00048 #include <assert.h> 00049 00050 #include "sphinxbase/err.h" 00051 #include "sphinxbase/ckd_alloc.h" 00052 00053 int cst_verrmsg(const char *fmt, va_list args) 00054 { 00055 char msg[256]; 00056 WCHAR *wmsg; 00057 size_t len; 00058 00059 _vsnprintf(msg,256,fmt,args); 00060 00061 len = mbstowcs(NULL,msg,0) + 1; 00062 wmsg = ckd_calloc(len,sizeof(*wmsg)); 00063 mbstowcs(wmsg,msg,len); 00064 00065 OutputDebugStringW(wmsg); 00066 ckd_free(wmsg); 00067 return 0; 00068 } 00069 00070 int cst_errmsg(const char *fmt, ...) 00071 { 00072 va_list args; 00073 00074 va_start(args,fmt); 00075 cst_verrmsg(fmt, args); 00076 va_end(args); 00077 return 0; 00078 } 00079 00080 void 00081 _E__pr_info_header_wofn(char const *msg) 00082 { 00083 cst_errmsg("%s:\t", msg); 00084 } 00085 00086 void 00087 _E__pr_header(char const *f, long ln, char const *msg) 00088 { 00089 cst_errmsg("%s: \"%s\", line %ld: ", msg, f, ln); 00090 } 00091 00092 void 00093 _E__pr_info_header(char const *f, long ln, char const *msg) 00094 { 00095 cst_errmsg("%s: %s(%ld): ", msg, f, ln); 00096 } 00097 00098 void 00099 _E__pr_warn(char const *fmt, ...) 00100 { 00101 va_list pvar; 00102 00103 va_start(pvar, fmt); 00104 cst_verrmsg(fmt, pvar); 00105 va_end(pvar); 00106 } 00107 00108 void 00109 _E__pr_info(char const *fmt, ...) 00110 { 00111 va_list pvar; 00112 00113 va_start(pvar, fmt); 00114 cst_verrmsg(fmt, pvar); 00115 va_end(pvar); 00116 } 00117 00118 void 00119 _E__die_error(char const *fmt, ...) 00120 { 00121 va_list pvar; 00122 00123 va_start(pvar, fmt); 00124 cst_verrmsg(fmt, pvar); 00125 va_end(pvar); 00126 exit(-1); 00127 } 00128 00129 void 00130 _E__fatal_sys_error(char const *fmt, ...) 00131 { 00132 LPVOID msg_buf; 00133 DWORD error; 00134 va_list pvar; 00135 00136 error = GetLastError(); 00137 va_start(pvar, fmt); 00138 cst_verrmsg(fmt, pvar); 00139 va_end(pvar); 00140 00141 OutputDebugStringW(L"; "); 00142 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 00143 FORMAT_MESSAGE_FROM_SYSTEM | 00144 FORMAT_MESSAGE_IGNORE_INSERTS, 00145 NULL, 00146 error, 00147 0, // Default language 00148 (LPTSTR) &msg_buf, 00149 0, 00150 NULL); 00151 OutputDebugString(msg_buf); 00152 LocalFree(msg_buf); 00153 00154 exit(error); 00155 } 00156 00157 void 00158 _E__sys_error(char const *fmt, ...) 00159 { 00160 LPVOID msg_buf; 00161 DWORD error; 00162 va_list pvar; 00163 00164 error = GetLastError(); 00165 va_start(pvar, fmt); 00166 cst_verrmsg(fmt, pvar); 00167 va_end(pvar); 00168 00169 OutputDebugStringW(L"; "); 00170 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 00171 FORMAT_MESSAGE_FROM_SYSTEM | 00172 FORMAT_MESSAGE_IGNORE_INSERTS, 00173 NULL, 00174 error, 00175 0, // Default language 00176 (LPTSTR) &msg_buf, 00177 0, 00178 NULL); 00179 OutputDebugString(msg_buf); 00180 LocalFree(msg_buf); 00181 } 00182 00183 void 00184 _E__abort_error(char const *fmt, ...) 00185 { 00186 va_list pvar; 00187 00188 va_start(pvar, fmt); 00189 cst_verrmsg(fmt, pvar); 00190 va_end(pvar); 00191 00192 assert(2+2 == 5); 00193 }