Edinburgh Speech Tools  2.4-release
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
EST_error.c
1  /************************************************************************/
2  /* */
3  /* Centre for Speech Technology Research */
4  /* University of Edinburgh, UK */
5  /* Copyright (c) 1996,1997 */
6  /* All Rights Reserved. */
7  /* */
8  /* Permission is hereby granted, free of charge, to use and distribute */
9  /* this software and its documentation without restriction, including */
10  /* without limitation the rights to use, copy, modify, merge, publish, */
11  /* distribute, sublicense, and/or sell copies of this work, and to */
12  /* permit persons to whom this work is furnished to do so, subject to */
13  /* the following conditions: */
14  /* 1. The code must retain the above copyright notice, this list of */
15  /* conditions and the following disclaimer. */
16  /* 2. Any modifications must be clearly marked as such. */
17  /* 3. Original authors' names are not deleted. */
18  /* 4. The authors' names are not used to endorse or promote products */
19  /* derived from this software without specific prior written */
20  /* permission. */
21  /* */
22  /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23  /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24  /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25  /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26  /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27  /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28  /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29  /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30  /* THIS SOFTWARE. */
31  /* */
32  /*************************************************************************/
33  /* */
34  /* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
35  /* Date: Thu Aug 14 1997 */
36  /* -------------------------------------------------------------------- */
37  /* Fatal error calls. */
38  /* */
39  /*************************************************************************/
40 
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <errno.h>
44 #include <string.h>
45 #include "EST_error.h"
46 
47 const char * EST_error_where=NULL;
48 static char EST_error_message_buf[MAX_ERROR_MESSAGE_LENGTH];
49 char *EST_error_message = EST_error_message_buf;
50 
51 void EST_default_bug_fn(const char *format, ...)
52 {
53  va_list ap;
54  char *p=EST_error_message;
55 
56  if (EST_error_stream==NULL)
57  EST_error_stream = stderr;
58 
59  fprintf(EST_error_stream, "-=-=-=-=-=- EST Bug! -=-=-=-=-=-\n");
60  if (EST_error_where)
61  fprintf(EST_error_stream," %s\n", EST_error_where);
62 
63  va_start(ap, format);
64  vsprintf(p, format, ap);
65  va_end(ap);
66  fprintf(EST_error_stream, "%s\n", p);
67 
68  fprintf(EST_error_stream, "Please report this in as much detail as possible\n to festival@cstr.ed.ac.uk\n");
69  putc('\n', EST_error_stream);
70  fprintf(EST_error_stream, "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
71  est_error_throw();
72 }
73 
74 void EST_default_error_fn(const char *format, ...)
75 {
76  va_list ap;
77  char *p=EST_error_message;
78 
79  if (EST_error_stream==NULL)
80  EST_error_stream = stderr;
81 
82  fprintf(EST_error_stream, "-=-=-=-=-=- EST Error -=-=-=-=-=-\n");
83  if (EST_error_where)
84  fprintf(EST_error_stream," %s\n", EST_error_where);
85 
86  va_start(ap, format);
87  vsprintf(p, format, ap);
88  va_end(ap);
89  fprintf(EST_error_stream, "%s\n", p);
90 
91  fprintf(EST_error_stream, "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
92  est_error_throw();
93 }
94 
95 void EST_quiet_error_fn(const char *format, ...)
96 {
97  va_list ap;
98  char *p=EST_error_message;
99 
100  va_start(ap, format);
101  vsprintf(p, format, ap);
102  va_end(ap);
103 
104  est_error_throw();
105 }
106 
107 void EST_default_warning_fn(const char *format, ...)
108 {
109  va_list ap;
110  char *p=EST_error_message;
111 
112  if (EST_warning_stream==NULL)
113  EST_warning_stream = stderr;
114 
115  fprintf(EST_warning_stream, "-=-=-=-=-=- EST Warning -=-=-=-=-=-\n");
116  if (EST_error_where)
117  fprintf(EST_warning_stream," %s\n", EST_error_where);
118 
119  va_start(ap, format);
120  vsprintf(p, format, ap);
121  va_end(ap);
122  fprintf(EST_warning_stream, "%s\n", p);
123 
124  fprintf(EST_warning_stream, "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
125 }
126 
127 void EST_quiet_warning_fn(const char *format, ...)
128 {
129  va_list ap;
130  char *p=EST_error_message;
131 
132  va_start(ap, format);
133  vsprintf(p, format, ap);
134  va_end(ap);
135 }
136 
137 void EST_default_sys_error_fn(const char *format, ...)
138 {
139  va_list ap;
140  char *p=EST_error_message;
141  const char *msg = strerror(errno);
142 
143  if (EST_error_stream==NULL)
144  EST_error_stream = stderr;
145 
146  fprintf(EST_error_stream, "-=-=-=-=-=- EST IO Error -=-=-=-=-\n");
147  if (EST_error_where)
148  fprintf(EST_error_stream," %s\n", EST_error_where);
149 
150  va_start(ap, format);
151  vsprintf(p, format, ap);
152  va_end(ap);
153  fprintf(EST_error_stream, "%s - %s\n", p, msg);
154 
155  fprintf(EST_error_stream, "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
156  est_error_throw();
157 }
158 
159 void EST_quiet_sys_error_fn(const char *format, ...)
160 {
161  va_list ap;
162  char *p=EST_error_message;
163  const char *msg = strerror(errno);
164 
165  va_start(ap, format);
166  vsprintf(p, format, ap);
167  va_end(ap);
168 
169  while (*p)
170  ++p;
171  strcat(p, " - ");
172  p+=3;
173  strcat(p, msg);
174 
175  est_error_throw();
176 }
177 
178 void EST_errors_default()
179 {
180  EST_bug_func = EST_default_bug_fn;
181  EST_error_func = EST_default_error_fn;
182  EST_sys_error_func = EST_default_sys_error_fn;
183 }
184 
185 void EST_errors_quiet()
186 {
187  EST_bug_func = EST_default_bug_fn;
188  EST_error_func = EST_quiet_error_fn;
189  EST_sys_error_func = EST_quiet_sys_error_fn;
190 }
191 
192 EST_error_handler EST_bug_func = EST_default_bug_fn;
193 EST_error_handler EST_error_func = EST_default_error_fn;
194 EST_error_handler EST_sys_error_func = EST_default_sys_error_fn;
195 EST_error_handler EST_warning_func = EST_default_warning_fn;
196 
197 EST_error_handler old_error_function;
198 EST_error_handler old_sys_error_function;
199 
200 FILE *EST_error_stream=NULL;
201 FILE *EST_warning_stream=NULL;
202 
203 jmp_buf *est_errjmp = 0;
204 long errjmp_ok=0;
205 
206 
207 
208 
209