~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina5/tina-libs/tina/sys/sysGen_error.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/sys/sysGen_error.c,v $
 37  * Date    :  $Date: 2007/02/15 01:52:29 $
 38  * Version :  $Revision: 1.7 $
 39  * CVS Id  :  $Id: sysGen_error.c,v 1.7 2007/02/15 01:52:29 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42 */
 43 /**
 44  *  @file Output error messages  (Tina's fprintf(stderr, ...))
 45  *  @brief Normal output is to Top tool's text subwindow
 46  *  If 2 (or more) text subwindows, then output to most recently CREATED
 47  *  If no text subwindow, then output to shell. Warning level can be restricted.
 48  *
 49  *********
 50 */
 51 
 52 #include "sysGen_error.h"
 53 #include <stdlib.h>
 54 
 55 #if HAVE_CONFIG_H
 56   #include <config.h>
 57 #endif
 58 
 59 #include <stdio.h>
 60 #include <string.h>
 61 #include <errno.h>
 62 
 63 #if HAVE_STDARG_H
 64 #  include <stdarg.h>
 65 #  define VA_START(a, f)    va_start(a, f)
 66 #else
 67 #  if HAVE_VARARGS_H
 68 #    include <varargs.h>
 69 #    define VA_START(a, f)  va_start(a)
 70 #  endif
 71 #endif /* HAVE_STDARG_H */
 72 #ifndef VA_START
 73   error no variadic api available
 74 #endif
 75 
 76 
 77 #include <tina/sys/sys_GenDef.h>
 78 #include <tina/sys/sysGen_string.h>
 79 
 80 static Error max_type = warning;
 81 
 82 void set_max_error(Error type)
 83 {
 84         max_type = type;
 85 }
 86 
 87 int *get_max_error()
 88 {
 89         int i = max_type;
 90 
 91         return (int *) i;
 92 }
 93 
 94 void error_default_print(char *string)
 95 {
 96         (void) fprintf(stderr, "%s", string);
 97 }
 98 
 99 static void (*error_print) () = error_default_print;
100 
101 void error_set_print(void (*func) ( /* ??? */ ))
102 {
103         error_print = func;
104 }
105 
106 void (*error_get_print(void)) ( /* ??? */ )
107 {
108         return (error_print);
109 }
110 
111 void error(char *msg, Error type)
112 {
113         char string[256];
114 
115         if (type > max_type)
116                 return;
117         switch (type)
118         {
119                 case fatal:/** use only if ABSOLUTELY necessary **/
120                         (void) string_append(string, "fatal error: ", msg, "\n", NULL);
121                         error_default_print(string);
122                         (void) string_append(string, "perror: ", strerror(errno), "\n", NULL);
123                         exit(1);
124                         break;
125                 case non_fatal:/** a bad thing has happened **/
126                         (void) string_append(string, "non-fatal error: ", msg, "\n", NULL);
127                         error_print(string);
128                         (void) string_append(string, "perror: ", strerror(errno), "\n", NULL);
129                         error_print(string);
130                         break;
131                 case warning:/** e.g. unable to give response required **/
132                         (void) string_append(string, "warning: ", msg, "\n", NULL);
133                         error_print(string);
134                         break;
135                 case core_dump:/** force a core dump **/
136                         (void) string_append(string, "core-dump error: ", msg, "\n", NULL);
137                         error_default_print(string);
138                         error_default_print(" - forcing core dump - ");
139                         {
140                                 int i = *(int *) NULL;
141                                 i = i;
142                         }
143                         break;
144                 default:
145                         error("error: no such error type", non_fatal);
146         }
147 }
148 
149 
150 void 
151 #if HAVE_STDARG_H
152 errorf(Error type, char *format, ...)
153 #else
154 errorf(type, format, va_alist)
155         Error type;
156         char *format;
157         va_dcl
158 #endif /* HAVE_STDARG_H */
159 {
160         static char err_msg[BUFSIZ];            /* static data! */
161         static char format_new[BUFSIZ];         /* static data! */
162         va_list ap;
163         void exit(int);
164 
165         VA_START(ap, format);
166 
167         if (type >= max_type)
168                 return;
169         switch (type)
170         {
171                 case fatal:/** use only if ABSOLUTELY necessary **/
172                         (void) string_append(format_new, "fatal errorf: ", format, NULL);
173                         (void) vsprintf(err_msg, format_new, ap);
174                         error_default_print(err_msg);
175                         (void) string_append(err_msg, "perror: ", strerror(errno), "\n", NULL);
176                         error_print(err_msg);
177                         exit(1);
178                         break;
179                 case non_fatal:/** a bad thing has happened **/
180                         (void) string_append(format_new, "non-fatal errorf: ", format, NULL);
181                         (void) vsprintf(err_msg, format_new, ap);
182                         error_print(err_msg);
183                         (void) string_append(err_msg, "perror: ", strerror(errno), "\n", NULL);
184                         error_print(err_msg);
185                         break;
186                 case warning:/** e.g. unable to give response required **/
187                         (void) string_append(format_new, "warning: ", format, NULL);
188                         (void) vsprintf(err_msg, format_new, ap);
189                         error_print(err_msg);
190                         break;
191                 case core_dump:/** force a core dump **/
192                         (void) string_append(format_new, "core-dump errorf: ", format, NULL);
193                         (void) vsprintf(err_msg, format_new, ap);
194                         error_default_print(err_msg);
195                         error_default_print(" - forcing core dump - ");
196                         {
197                                 int i = *(int *) NULL;
198                                 i = i;
199                         }
200                         break;
201                 default:
202                         errorf(non_fatal, "error: no such error type");
203         }
204 }
205 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.