chiark / gitweb /
Initial revision
[ssr] / StraySrc / SDLS / cdll / c / error
1 /*
2  * error.h
3  *
4  * Error messages and handling
5  *
6  * © 1994-1998 Straylight
7  */
8
9 /*----- Licensing note ----------------------------------------------------*
10  *
11  * This file is part of Straylight's Dynamic Linking System (SDLS)
12  *
13  * SDLS is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2, or (at your option)
16  * any later version.
17  *
18  * SDLS is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with SDLS.  If not, write to the Free Software Foundation,
25  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26  */
27
28 #include <stdio.h>
29 #include <string.h>
30 #include <stdarg.h>
31 #include <stdlib.h>
32
33 #define error__MAKETABLE
34 #include "error.h"
35
36 static char *error__progname;
37 static int error__count[5];
38 static int error__retcode=0;
39
40 void error_setProgName(char *name)
41 {
42   error__progname=strrchr(name,'.');
43   if (!error__progname)
44     error__progname=name;
45   else
46     error__progname++;
47 }
48
49 char *error_progname(void)
50 {
51   return (error__progname);
52 }
53
54 void error(int message,...)
55 {
56   static char const *types[]={"Informational",
57                               "Warning",
58                               "Error",
59                               "Serious error",
60                               "Fatal error"};
61
62   va_list ap;
63   va_start(ap,message);
64   fprintf(stderr,
65           "%s: (%s) ",
66           error__progname,
67           types[error__table[message].sev]);
68   vfprintf(stderr,error__table[message].msg,ap);
69   va_end(ap);
70   if (error__table[message].sev==error_FATAL)
71     exit(error_FATAL);
72   error__count[error__table[message].sev]++;
73   if (error__table[message].sev>error__retcode)
74     error__retcode=error__table[message].sev;
75 }
76
77 void error_show(void)
78 {
79   if (error__retcode)
80   {
81     fprintf(stderr,
82             "%s: completed with %i warning%s, "
83             "%i error%s and %i serious error%s.\n",
84             error__progname,
85             error__count[error_WARN],
86             error__count[error_WARN]==1 ? "" : "s",
87             error__count[error_ERROR],
88             error__count[error_ERROR]==1 ? "" : "s",
89             error__count[error_SEVERE],
90             error__count[error_SEVERE]==1 ? "" : "s");
91   }
92 }
93
94 int error_returnCode(void)
95 {
96   return (error__retcode);
97 }
98
99 extern void aof_error(void)
100 {
101   error(0);
102 }