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

Linux Cross Reference
Tina6/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 Error get_max_error()
 88 {
 89 
 90         return max_type;
 91 }
 92 
 93 void error_default_print(char *string)
 94 {
 95         (void) fprintf(stderr, "%s", string);
 96 }
 97 
 98 static void (*error_print) () = error_default_print;
 99 
100 void error_set_print(void (*func) ( /* ??? */ ))
101 {
102         error_print = func;
103 }
104 
105 void (*error_get_print(void)) ( /* ??? */ )
106 {
107         return (error_print);
108 }
109 
110 void error(char *msg, Error type)
111 {
112         char string[256];
113 
114         if (type > max_type)
115                 return;
116         switch (type)
117         {
118                 case fatal:/** use only if ABSOLUTELY necessary **/
119                         (void) string_append(string, "fatal error: ", msg, "\n", NULL);
120                         error_default_print(string);
121                         (void) string_append(string, "perror: ", strerror(errno), "\n", NULL);
122                         exit(1);
123                         break;
124                 case non_fatal:/** a bad thing has happened **/
125                         (void) string_append(string, "non-fatal error: ", msg, "\n", NULL);
126                         error_print(string);
127                         (void) string_append(string, "perror: ", strerror(errno), "\n", NULL);
128                         error_print(string);
129                         break;
130                 case warning:/** e.g. unable to give response required **/
131                         (void) string_append(string, "warning: ", msg, "\n", NULL);
132                         error_print(string);
133                         break;
134                 case core_dump:/** force a core dump **/
135                         (void) string_append(string, "core-dump error: ", msg, "\n", NULL);
136                         error_default_print(string);
137                         error_default_print(" - forcing core dump - ");
138                         {
139                                 int i = *(int *) NULL;
140                                 i = i;
141                         }
142                         break;
143                 default:
144                         error("error: no such error type", non_fatal);
145         }
146 }
147 
148 
149 void 
150 #if HAVE_STDARG_H
151 errorf(Error type, char *format, ...)
152 #else
153 errorf(type, format, va_alist)
154         Error type;
155         char *format;
156         va_dcl
157 #endif /* HAVE_STDARG_H */
158 {
159         static char err_msg[BUFSIZ];            /* static data! */
160         static char format_new[BUFSIZ];         /* static data! */
161         va_list ap;
162         void exit(int);
163 
164         VA_START(ap, format);
165 
166         if (type >= max_type)
167                 return;
168         switch (type)
169         {
170                 case fatal:/** use only if ABSOLUTELY necessary **/
171                         (void) string_append(format_new, "fatal errorf: ", format, NULL);
172                         (void) vsprintf(err_msg, format_new, ap);
173                         error_default_print(err_msg);
174                         (void) string_append(err_msg, "perror: ", strerror(errno), "\n", NULL);
175                         error_print(err_msg);
176                         exit(1);
177                         break;
178                 case non_fatal:/** a bad thing has happened **/
179                         (void) string_append(format_new, "non-fatal errorf: ", format, NULL);
180                         (void) vsprintf(err_msg, format_new, ap);
181                         error_print(err_msg);
182                         (void) string_append(err_msg, "perror: ", strerror(errno), "\n", NULL);
183                         error_print(err_msg);
184                         break;
185                 case warning:/** e.g. unable to give response required **/
186                         (void) string_append(format_new, "warning: ", format, NULL);
187                         (void) vsprintf(err_msg, format_new, ap);
188                         error_print(err_msg);
189                         break;
190                 case core_dump:/** force a core dump **/
191                         (void) string_append(format_new, "core-dump errorf: ", format, NULL);
192                         (void) vsprintf(err_msg, format_new, ap);
193                         error_default_print(err_msg);
194                         error_default_print(" - forcing core dump - ");
195                         {
196                                 int i = *(int *) NULL;
197                                 i = i;
198                         }
199                         break;
200                 default:
201                         errorf(non_fatal, "error: no such error type");
202         }
203 }
204 

~ [ 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.