Add more pretty names for wmgenmenu apps
[wmaker-crm.git] / WINGs / error.c
blob0e3597fb8ea36cda4e334d69b01265b47b7fd116
1 /*
2 * Window Maker miscelaneous function library
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
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.
21 #include "wconfig.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <stdarg.h>
26 #include <string.h>
27 #include <errno.h>
29 #include <WUtil.h>
31 extern char *_WINGS_progname;
33 #define MAXLINE 1024
35 /*********************************************************************
36 * Returns the system error message associated with error code 'errnum'
37 *********************************************************************/
38 char *wstrerror(int errnum)
40 #if defined(HAVE_STRERROR)
41 return strerror(errnum);
42 #elif !defined(HAVE_STRERROR) && defined(BSD)
43 extern int errno, sys_nerr;
44 # ifndef __DECC
45 extern char *sys_errlist[];
46 # endif
47 static char buf[] = "Unknown error 12345678901234567890";
49 if (errno < sys_nerr)
50 return sys_errlist[errnum];
52 snprintf(buf, sizeof(buf), _("Unknown error %d"), errnum);
53 return buf;
54 #else /* no strerror() and no sys_errlist[] */
55 static char buf[] = "Error 12345678901234567890";
57 snprintf(buf, sizeof(buf), _("Error %d"), errnum);
58 return buf;
59 #endif
62 void __wmessage(int type, void *extra, const char *msg, ...)
64 va_list args;
65 char buf[MAXLINE];
67 fflush(stdout);
68 /* message format: <wings_progname>: <qualifier>: <message>[: <extra info>]"\n" */
69 snprintf(buf, sizeof(buf), "%s: ", _WINGS_progname ? _WINGS_progname : "WINGs");
70 va_start(args, msg);
71 switch (type) {
72 case WMESSAGE_TYPE_WARNING:
73 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
74 _("warning: "));
75 vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
76 msg, args);
77 break;
78 case WMESSAGE_TYPE_FATAL:
79 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
80 _("fatal error: "));
81 vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
82 msg, args);
83 break;
84 case WMESSAGE_TYPE_WSYSERROR:
85 case WMESSAGE_TYPE_WSYSERRORWITHCODE:
86 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
87 _("error: "));
88 vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
89 msg, args);
90 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
91 ": %s", type == WMESSAGE_TYPE_WSYSERROR ?
92 wstrerror(errno) : wstrerror(*(int *)extra));
93 break;
94 case WMESSAGE_TYPE_MESSAGE:
95 /* FALLTHROUGH */
96 default:
97 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ": ");
98 vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), msg, args);
99 break;
101 va_end(args);
102 strncat(buf + strlen(buf), "\n", sizeof(buf) - strlen(buf) - 1);
103 fputs(buf, stderr);