more code for proplist handling (almost finished)
[wmaker-crm.git] / WINGs / error.c
blobcd07fca487a28180e16c9a46ffcaefdba7221b42
1 /*
2 * Window Maker miscelaneous function library
3 *
4 * Copyright (c) 1997 Alfredo K. Kojima
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "../src/config.h"
24 #include "wconfig.h"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <string.h>
30 #include <errno.h>
32 extern char *_WINGS_progname;
35 #define MAXLINE 1024
38 /*********************************************************************
39 * Returns the system error message associated with error code 'errnum'
40 *********************************************************************/
41 char*
42 wstrerror(int errnum)
44 #if defined(HAVE_STRERROR)
45 return strerror(errnum);
46 #elif !defined(HAVE_STRERROR) && defined(BSD)
47 extern int errno, sys_nerr;
48 # ifndef __DECC
49 extern char *sys_errlist[];
50 # endif
51 static char buf[] = "Unknown error 12345678901234567890";
53 if (errno < sys_nerr)
54 return sys_errlist[errnum];
56 sprintf (buf, _("Unknown error %d"), errnum);
57 return buf;
58 #else /* no strerror() and no sys_errlist[] */
59 static char buf[] = "Error 12345678901234567890";
61 sprintf(buf, _("Error %d"), errnum);
62 return buf;
63 #endif
67 /*********************************************************************
68 * Prints a message with variable arguments
70 * msg - message to print with optional formatting
71 * ... - arguments to use on formatting
72 *********************************************************************/
73 void
74 wmessage(const char *msg, ...)
76 va_list args;
77 char buf[MAXLINE];
79 va_start(args, msg);
81 vsnprintf(buf, MAXLINE-3, msg, args);
82 strcat(buf,"\n");
83 fflush(stdout);
84 fputs(_WINGS_progname ? _WINGS_progname : "WINGs", stderr);
85 fputs(": ",stderr);
86 fputs(buf, stderr);
87 fflush(stdout);
88 fflush(stderr);
90 va_end(args);
94 /*********************************************************************
95 * Prints a warning message with variable arguments
97 * msg - message to print with optional formatting
98 * ... - arguments to use on formatting
99 *********************************************************************/
100 void
101 wwarning(const char *msg, ...)
103 va_list args;
104 char buf[MAXLINE];
106 va_start(args, msg);
108 vsnprintf(buf, MAXLINE-3, msg, args);
109 strcat(buf,"\n");
110 fflush(stdout);
111 fputs(_WINGS_progname ? _WINGS_progname : "WINGs", stderr);
112 fputs(_(" warning: "),stderr);
113 fputs(buf, stderr);
114 fflush(stdout);
115 fflush(stderr);
117 va_end(args);
121 /**************************************************************************
122 * Prints a fatal error message with variable arguments and terminates
124 * msg - message to print with optional formatting
125 * ... - arguments to use on formatting
126 **************************************************************************/
127 void
128 wfatal(const char *msg, ...)
130 va_list args;
131 char buf[MAXLINE];
133 va_start(args, msg);
135 vsnprintf(buf, MAXLINE-3, msg, args);
136 strcat(buf,"\n");
137 fflush(stdout);
138 fputs(_WINGS_progname ? _WINGS_progname : "WINGs", stderr);
139 fputs(_(" fatal error: "),stderr);
140 fputs(buf, stderr);
141 fflush(stdout);
142 fflush(stderr);
144 va_end(args);
148 /*********************************************************************
149 * Prints a system error message with variable arguments
151 * msg - message to print with optional formatting
152 * ... - arguments to use on formatting
153 *********************************************************************/
154 void
155 wsyserror(const char *msg, ...)
157 va_list args;
158 char buf[MAXLINE];
159 int error=errno;
161 va_start(args, msg);
162 vsnprintf(buf, MAXLINE-3, msg, args);
163 fflush(stdout);
164 fputs(_WINGS_progname ? _WINGS_progname : "WINGs", stderr);
165 fputs(_(" error: "), stderr);
166 fputs(buf, stderr);
167 fputs(": ", stderr);
168 fputs(wstrerror(error), stderr);
169 fputs("\n", stderr);
170 fflush(stderr);
171 fflush(stdout);
172 va_end(args);
176 /*********************************************************************
177 * Prints a system error message with variable arguments, being given
178 * the error code.
180 * error - the error code foe which to print the message
181 * msg - message to print with optional formatting
182 * ... - arguments to use on formatting
183 *********************************************************************/
184 void
185 wsyserrorwithcode(int error, const char *msg, ...)
187 va_list args;
188 char buf[MAXLINE];
190 va_start(args, msg);
191 vsnprintf(buf, MAXLINE-3, msg, args);
192 fflush(stdout);
193 fputs(_WINGS_progname ? _WINGS_progname : "WINGs", stderr);
194 fputs(_(" error: "), stderr);
195 fputs(buf, stderr);
196 fputs(": ", stderr);
197 fputs(wstrerror(error), stderr);
198 fputs("\n", stderr);
199 fflush(stderr);
200 fflush(stdout);
201 va_end(args);