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

Linux Cross Reference
Tina4/src/sys/gen/error.c

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

  1 /**@(#)Output error messages  (Tina's fprintf(stderr, ...))
  2  * @(#)Norm is output to Top tool's text subwindow
  3  * @(#)If 2 (or more) text subwindows, then output to most recently CREATED
  4  * @(#)If no text subwindow, then output to shell
  5 **/
  6 
  7 #include <stdio.h>
  8 #include <stdarg.h>
  9 #include <tina/sys.h>
 10 #include <tina/sysfuncs.h>
 11 #include <errno.h>
 12 
 13 /**Error print function called when text window is not available**/
 14 #ifndef _PCC
 15 #ifndef _BSD_SOURCE
 16 #ifdef _ICC
 17 
 18 static char *sys_errlist[37][256];
 19 static int sys_nerr = 0;
 20 
 21 #else 
 22 extern char *sys_errlist[];
 23 extern int sys_nerr;
 24 
 25 #endif /* end _ICC */
 26 #endif /* end _BSD_SOURCE */
 27 #endif /* end _PCC */
 28 
 29 static Error max_type = core_dump; 
 30 
 31 void set_max_error(type)
 32 {
 33    max_type = type;
 34 }
 35 
 36 int *get_max_error()
 37 {
 38    return((int *)&max_type);
 39 }
 40 
 41 void    error_default_print(char *string)
 42 {
 43     (void) fprintf(stderr, "%s", string);
 44 }
 45 
 46 static void (*error_print) () = error_default_print;
 47 
 48 void    error_set_print(void (*func) ( /* ??? */ ))
 49 {
 50     error_print = func;
 51 }
 52 
 53 void    (*error_get_print(void)) ( /* ??? */ )
 54 {
 55     return (error_print);
 56 }
 57 
 58 void    error(char *msg, Error type)
 59 {
 60     void    exit(int);
 61 
 62     char    string[256];
 63 
 64     if (type>=max_type) return;
 65     switch (type)
 66     {
 67     case fatal:         /** use only if ABSOLUTELY necessary **/
 68         (void) string_append(string, "fatal error: ", msg, "\n", NULL);
 69         error_default_print(string);
 70         if (errno < sys_nerr)
 71         {
 72             (void) string_append(string, "perror: ", sys_errlist[errno], "\n", NULL);
 73             error_default_print(string);
 74         }
 75         exit(1);
 76         break;
 77     case non_fatal:             /** a bad thing has happened **/
 78         (void) string_append(string, "non-fatal error: ", msg, "\n", NULL);
 79         error_print(string);
 80         if (errno < sys_nerr)
 81         {
 82             (void) string_append(string, "perror: ", sys_errlist[errno], "\n", NULL);
 83             error_print(string);
 84         }
 85         break;
 86     case warning:               /** e.g. unable to give response required **/
 87         (void) string_append(string, "warning: ", msg, "\n", NULL);
 88         error_print(string);
 89         break;
 90     case core_dump:             /** force a core dump **/
 91         (void) string_append(string, "core-dump error: ", msg, "\n", NULL);
 92         error_default_print(string);
 93         error_default_print(" - forcing core dump - ");
 94         {
 95             int     i = *(int *) NULL;
 96 
 97             i = i;
 98 
 99         }
100         break;
101     default:
102         error("error: no such error type", non_fatal);
103     }
104 }
105 
106 
107 void    errorf(Error type, char *format,...)
108 {
109     static char err_msg[BUFSIZ];
110     static char format_new[BUFSIZ];
111     va_list ap;
112     void    exit(int);
113 
114     va_start(ap, format);
115 
116     if (type>=max_type) return;
117     switch (type)
118     {
119     case fatal:         /** use only if ABSOLUTELY necessary **/
120         (void) string_append(format_new, "fatal errorf: ", format, NULL);
121         (void) vsprintf(err_msg, format_new, ap);
122         error_default_print(err_msg);
123         if (errno < sys_nerr)
124         {
125             (void) string_append(err_msg, "perror: ", sys_errlist[errno], "\n", NULL);
126             error_print(err_msg);
127         }
128         exit(1);
129         break;
130     case non_fatal:             /** a bad thing has happened **/
131         (void) string_append(format_new, "non-fatal errorf: ", format, NULL);
132         (void) vsprintf(err_msg, format_new, ap);
133         error_print(err_msg);
134         if (errno < sys_nerr)
135         {
136             (void) string_append(err_msg, "perror: ", sys_errlist[errno], "\n", NULL);
137             error_print(err_msg);
138         }
139         break;
140     case warning:               /** e.g. unable to give response required **/
141         (void) string_append(format_new, "warning: ", format, NULL);
142         (void) vsprintf(err_msg, format_new, ap);
143         error_print(err_msg);
144         break;
145     case core_dump:             /** force a core dump **/
146         (void) string_append(format_new, "core-dump errorf: ", format, NULL);
147         (void) vsprintf(err_msg, format_new, ap);
148         error_default_print(err_msg);
149         error_default_print(" - forcing core dump - ");
150         {
151             int     i = *(int *) NULL;
152 
153             i = i;
154 
155         }
156         break;
157     default:
158         errorf(non_fatal, "error: no such error type");
159     }
160 }
161 

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