Icon creation in only one function
[wmaker-crm.git] / WINGs / error.c
blob7cfc9464799326fa169c5814f75e7f2e7de6fa38
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 <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <unistd.h>
29 #include <WUtil.h>
31 extern char *_WINGS_progname;
33 void __wmessage(const char *func, const char *file, int line, int type, const char *msg, ...)
35 va_list args;
36 char *buf;
37 static int linemax = 0;
38 int truncated = 0;
40 if (linemax == 0) {
41 #ifdef HAVE_SYSCONF
42 linemax = sysconf(_SC_LINE_MAX);
43 if (linemax == -1) {
44 /* I'd like to know of this ever fires */
45 fprintf(stderr, "%s %d: sysconf(_SC_LINE_MAX) returned error\n",
46 __FILE__, __LINE__);
47 linemax = 512;
49 #else /* !HAVE_SYSCONF */
50 fprintf(stderr, "%s %d: Your system does not have sysconf(3); "
51 "let wmaker-dev@windowmaker.org know.\n", __FILE__, __LINE__);
52 linemax = 512;
53 #endif /* HAVE_SYSCONF */
56 buf = wmalloc(linemax);
58 fflush(stdout);
60 /* message format: <wings_progname>(function(file:line): <type?>: <message>"\n" */
61 strncat(buf, _WINGS_progname ? _WINGS_progname : "WINGs", linemax - 1);
62 snprintf(buf + strlen(buf), linemax - strlen(buf), "(%s(%s:%d))", func, file, line);
63 strncat(buf, ": ", linemax - 1 - strlen(buf));
65 switch (type) {
66 case WMESSAGE_TYPE_FATAL:
67 strncat(buf, _("fatal error: "), linemax - 1 - strlen(buf));
68 break;
69 case WMESSAGE_TYPE_ERROR:
70 strncat(buf, _("error: "), linemax - 1 - strlen(buf));
71 break;
72 case WMESSAGE_TYPE_WARNING:
73 strncat(buf, _("warning: "), linemax - 1 - strlen(buf));
74 break;
75 case WMESSAGE_TYPE_MESSAGE:
76 /* FALLTHROUGH */
77 default: /* should not happen, but doesn't hurt either */
78 break;
81 va_start(args, msg);
82 if (vsnprintf(buf + strlen(buf), linemax - strlen(buf), msg, args) >= linemax - strlen(buf))
83 truncated = 1;
85 va_end(args);
87 fputs(buf, stderr);
89 if (truncated)
90 fputs("*** message truncated ***", stderr);
92 fputs("\n", stderr);
94 wfree(buf);