1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-24 07:02:30 +01:00

WINGs: Make w*() print message origins

Signed-off-by: Tamas TEVESZ <ice@extreme.hu>
This commit is contained in:
Tamas TEVESZ
2010-09-28 01:34:33 +02:00
committed by Carlos R. Mafra
parent 34293e072a
commit 8594c39a0b
2 changed files with 25 additions and 15 deletions

View File

@@ -173,12 +173,13 @@ enum {
WMESSAGE_TYPE_FATAL
};
#define wmessage(fmt, args...) __wmessage( WMESSAGE_TYPE_MESSAGE, fmt, ## args)
#define wwarning(fmt, args...) __wmessage( WMESSAGE_TYPE_WARNING, fmt, ## args)
#define werror(fmt, args...) __wmessage( WMESSAGE_TYPE_ERROR, fmt, ## args)
#define wfatal(fmt, args...) __wmessage( WMESSAGE_TYPE_FATAL, fmt, ## args)
#define wmessage(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_MESSAGE, fmt, ## args)
#define wwarning(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_WARNING, fmt, ## args)
#define werror(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_ERROR, fmt, ## args)
#define wfatal(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_FATAL, fmt, ## args)
void __wmessage(int type, const char *msg, ...) __attribute__((__format__(printf,2,3)));
void __wmessage(const char *func, const char *file, int line, int type, const char *msg, ...)
__attribute__((__format__(printf,5,6)));
char* wfindfile(char *paths, char *file);

View File

@@ -30,11 +30,12 @@
extern char *_WINGS_progname;
void __wmessage(int type, const char *msg, ...)
void __wmessage(const char *func, const char *file, int line, int type, const char *msg, ...)
{
va_list args;
char *buf;
static int linemax = 0;
int truncated = 0;
if (linemax == 0) {
#ifdef HAVE_SYSCONF
@@ -55,33 +56,41 @@ void __wmessage(int type, const char *msg, ...)
buf = wmalloc(linemax);
fflush(stdout);
/* message format: <wings_progname>: <qualifier>: <message>"\n" */
snprintf(buf, linemax, "%s: ", _WINGS_progname ? _WINGS_progname : "WINGs");
/* message format: <wings_progname>(function(file:line): <type?>: <message>"\n" */
strncat(buf, _WINGS_progname ? _WINGS_progname : "WINGs", linemax - 1);
snprintf(buf + strlen(buf), linemax - strlen(buf), "(%s(%s:%d))", func, file, line);
strncat(buf, ": ", linemax - 1 - strlen(buf));
switch (type) {
case WMESSAGE_TYPE_FATAL:
snprintf(buf + strlen(buf), linemax - strlen(buf) - 1, _("fatal error: "));
strncat(buf, _("fatal error: "), linemax - 1 - strlen(buf));
break;
case WMESSAGE_TYPE_ERROR:
snprintf(buf + strlen(buf), linemax - strlen(buf) - 1, _("error: "));
strncat(buf, _("error: "), linemax - 1 - strlen(buf));
break;
case WMESSAGE_TYPE_WARNING:
snprintf(buf + strlen(buf), linemax - strlen(buf) - 1, _("warning: "));
break;
strncat(buf, _("warning: "), linemax - 1 - strlen(buf));
break;
case WMESSAGE_TYPE_MESSAGE:
/* FALLTHROUGH */
default: /* should not happen, but doesn't hurt either */
strncat(buf, ": ", linemax - strlen(buf));
break;
}
va_start(args, msg);
vsnprintf(buf + strlen(buf), linemax - strlen(buf) - 1, msg, args);
if (vsnprintf(buf + strlen(buf), linemax - strlen(buf), msg, args) >= linemax - strlen(buf))
truncated = 1;
va_end(args);
strncat(buf, "\n", linemax - strlen(buf));
fputs(buf, stderr);
if (truncated)
fputs("*** message truncated ***", stderr);
fputs("\n", stderr);
wfree(buf);
}