i certainly find this very helpful. maybe down the road the trace can
be put inside an ifdef DEBUG or something.
>From b2bdf5d91da05d34dd1292594369d4cd4be1aec3 Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Tue, 28 Sep 2010 01:34:33 +0200
Subject: [PATCH] Make w*() print message origins
Signed-off-by: Tamas TEVESZ <[email protected]>
---
WINGs/WINGs/WUtil.h | 11 ++++++-----
WINGs/error.c | 31 +++++++++++++++++++++----------
2 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h
index 357ff4a..0b401b2 100644
--- a/WINGs/WINGs/WUtil.h
+++ b/WINGs/WINGs/WUtil.h
@@ -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);
diff --git a/WINGs/error.c b/WINGs/error.c
index 3263dca..269aace 100644
--- a/WINGs/error.c
+++ b/WINGs/error.c
@@ -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
@@ -52,36 +53,46 @@ void __wmessage(int type, const char *msg, ...)
#endif /* HAVE_SYSCONF */
}
+ fprintf(stderr, "\n*** linemax = %d\n***\n", linemax);
+
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);
}
--
1.7.0.4
--
[-]
mkdir /nonexistentFrom b2bdf5d91da05d34dd1292594369d4cd4be1aec3 Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Tue, 28 Sep 2010 01:34:33 +0200
Subject: [PATCH] Make w*() print message origins
Signed-off-by: Tamas TEVESZ <[email protected]>
---
WINGs/WINGs/WUtil.h | 11 ++++++-----
WINGs/error.c | 31 +++++++++++++++++++++----------
2 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h
index 357ff4a..0b401b2 100644
--- a/WINGs/WINGs/WUtil.h
+++ b/WINGs/WINGs/WUtil.h
@@ -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);
diff --git a/WINGs/error.c b/WINGs/error.c
index 3263dca..269aace 100644
--- a/WINGs/error.c
+++ b/WINGs/error.c
@@ -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
@@ -52,36 +53,46 @@ void __wmessage(int type, const char *msg, ...)
#endif /* HAVE_SYSCONF */
}
+ fprintf(stderr, "\n*** linemax = %d\n***\n", linemax);
+
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);
}
--
1.7.0.4