mirror of
https://github.com/gryf/wmaker.git
synced 2026-02-15 05:25:53 +01:00
WINGs: Less ad-hoc approach for __wmessage()
Signed-off-by: Tamas TEVESZ <ice@extreme.hu>
This commit is contained in:
committed by
Carlos R. Mafra
parent
d2853c8584
commit
4478f21b7f
@@ -20,59 +20,81 @@
|
|||||||
|
|
||||||
#include "wconfig.h"
|
#include "wconfig.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <WUtil.h>
|
#include <WUtil.h>
|
||||||
|
|
||||||
extern char *_WINGS_progname;
|
extern char *_WINGS_progname;
|
||||||
|
|
||||||
#define MAXLINE 1024
|
|
||||||
|
|
||||||
void __wmessage(int type, void *extra, const char *msg, ...)
|
void __wmessage(int type, void *extra, const char *msg, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char buf[MAXLINE];
|
char *buf;
|
||||||
|
static int linemax = 0;
|
||||||
|
|
||||||
|
if (linemax == 0) {
|
||||||
|
#ifdef HAVE_SYSCONF
|
||||||
|
linemax = sysconf(_SC_LINE_MAX);
|
||||||
|
if (linemax == -1) {
|
||||||
|
/* I'd like to know of this ever fires */
|
||||||
|
fprintf(stderr, "%s %d: sysconf(_SC_LINE_MAX) returned error\n",
|
||||||
|
__FILE__, __LINE__);
|
||||||
|
linemax = 512;
|
||||||
|
}
|
||||||
|
#else /* !HAVE_SYSCONF */
|
||||||
|
fprintf(stderr, "%s %d: Your system does not have sysconf(3); "
|
||||||
|
"let wmaker-dev@windowmaker.org know.\n", __FILE__, __LINE__);
|
||||||
|
linemax = 512;
|
||||||
|
#endif /* HAVE_SYSCONF */
|
||||||
|
}
|
||||||
|
|
||||||
|
buf = wmalloc(linemax);
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
/* message format: <wings_progname>: <qualifier>: <message>[: <extra info>]"\n" */
|
/* message format: <wings_progname>: <qualifier>: <message>[: <extra info>]"\n" */
|
||||||
snprintf(buf, sizeof(buf), "%s: ", _WINGS_progname ? _WINGS_progname : "WINGs");
|
snprintf(buf, linemax, "%s: ", _WINGS_progname ? _WINGS_progname : "WINGs");
|
||||||
va_start(args, msg);
|
va_start(args, msg);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case WMESSAGE_TYPE_WARNING:
|
case WMESSAGE_TYPE_WARNING:
|
||||||
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf) - 1,
|
snprintf(buf + strlen(buf), linemax - strlen(buf) - 1,
|
||||||
_("warning: "));
|
_("warning: "));
|
||||||
vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf) - 1,
|
vsnprintf(buf + strlen(buf), linemax - strlen(buf) - 1,
|
||||||
msg, args);
|
msg, args);
|
||||||
break;
|
break;
|
||||||
case WMESSAGE_TYPE_FATAL:
|
case WMESSAGE_TYPE_FATAL:
|
||||||
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf) - 1,
|
snprintf(buf + strlen(buf), linemax - strlen(buf) - 1,
|
||||||
_("fatal error: "));
|
_("fatal error: "));
|
||||||
vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf) - 1,
|
vsnprintf(buf + strlen(buf), linemax - strlen(buf) - 1,
|
||||||
msg, args);
|
msg, args);
|
||||||
break;
|
break;
|
||||||
case WMESSAGE_TYPE_WSYSERROR:
|
case WMESSAGE_TYPE_WSYSERROR:
|
||||||
case WMESSAGE_TYPE_WSYSERRORWITHCODE:
|
case WMESSAGE_TYPE_WSYSERRORWITHCODE:
|
||||||
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf) - 1,
|
snprintf(buf + strlen(buf), linemax - strlen(buf) - 1,
|
||||||
_("error: "));
|
_("error: "));
|
||||||
vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf) - 1,
|
vsnprintf(buf + strlen(buf), linemax - strlen(buf) - 1,
|
||||||
msg, args);
|
msg, args);
|
||||||
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf) - 1,
|
snprintf(buf + strlen(buf), linemax - strlen(buf) - 1,
|
||||||
": %s", type == WMESSAGE_TYPE_WSYSERROR ?
|
": %s", type == WMESSAGE_TYPE_WSYSERROR ?
|
||||||
strerror(errno) : strerror(*(int *)extra));
|
strerror(errno) : strerror(*(int *)extra));
|
||||||
break;
|
break;
|
||||||
case WMESSAGE_TYPE_MESSAGE:
|
case WMESSAGE_TYPE_MESSAGE:
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
default:
|
default:
|
||||||
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf) - 1, ": ");
|
strncat(buf, ": ", linemax - strlen(buf));
|
||||||
vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf) - 1, msg, args);
|
vsnprintf(buf + strlen(buf), linemax - strlen(buf) - 1, msg, args);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
strncat(buf + strlen(buf), "\n", sizeof(buf) - strlen(buf));
|
|
||||||
|
strncat(buf, "\n", linemax - strlen(buf));
|
||||||
fputs(buf, stderr);
|
fputs(buf, stderr);
|
||||||
|
|
||||||
|
wfree(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ dnl not used anywhere
|
|||||||
AC_FUNC_MEMCMP
|
AC_FUNC_MEMCMP
|
||||||
AC_FUNC_VPRINTF
|
AC_FUNC_VPRINTF
|
||||||
AC_CHECK_FUNCS(gethostname select poll strcasecmp strncasecmp \
|
AC_CHECK_FUNCS(gethostname select poll strcasecmp strncasecmp \
|
||||||
setsid atexit mallinfo mkstemp)
|
setsid atexit mallinfo mkstemp sysconf)
|
||||||
|
|
||||||
dnl Check for strlcat/strlcpy
|
dnl Check for strlcat/strlcpy
|
||||||
dnl =========================
|
dnl =========================
|
||||||
|
|||||||
Reference in New Issue
Block a user