/****************************************************************************
- * Copyright (c) 1998-2002,2005 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2012,2014 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
#include <curses.priv.h>
-MODULE_ID("$Id: lib_tracemse.c,v 1.12 2005/06/11 19:53:50 tom Exp $")
+MODULE_ID("$Id: lib_tracemse.c,v 1.22 2014/10/10 09:06:26 tom Exp $")
#ifdef TRACE
+#define my_buffer sp->tracemse_buf
+
NCURSES_EXPORT(char *)
-_tracemouse(MEVENT const *ep)
+_nc_trace_mmask_t(SCREEN *sp, mmask_t code)
{
- /*
- * hmm - format is no longer than 80 columns, there are 5 numbers that
- * could at most have 10 digits, and the mask contains no more than 32 bits
- * with each bit representing less than 15 characters. Usually the whole
- * string is less than 80 columns, but this buffer size is an absolute
- * limit.
- */
- static char buf[80 + (5 * 10) + (32 * 15)];
-
- (void) sprintf(buf, "id %2d at (%2d, %2d, %2d) state %4lx = {",
- ep->id,
- ep->x,
- ep->y,
- ep->z,
- (unsigned long) ep->bstate);
-
-#define SHOW(m, s) if ((ep->bstate & m) == m) strcat(strcat(buf, s), ", ")
+#define SHOW(m, s) \
+ if ((code & m) == m) { \
+ size_t n = strlen(my_buffer); \
+ if (n && (my_buffer[n-1] != '{')) \
+ _nc_STRCAT(my_buffer, ", ", sizeof(my_buffer)); \
+ _nc_STRCAT(my_buffer, s, sizeof(my_buffer)); \
+ }
SHOW(BUTTON1_RELEASED, "release-1");
SHOW(BUTTON1_PRESSED, "press-1");
#undef SHOW
- if (buf[strlen(buf) - 1] == ' ')
- buf[strlen(buf) - 2] = '\0';
- (void) strcat(buf, "}");
- return (buf);
+ if (my_buffer[strlen(my_buffer) - 1] == ' ')
+ my_buffer[strlen(my_buffer) - 2] = '\0';
+
+ return (my_buffer);
+}
+
+NCURSES_EXPORT(char *)
+_nc_tracemouse(SCREEN *sp, MEVENT const *ep)
+{
+ char *result = 0;
+
+ if (sp != 0) {
+ _nc_SPRINTF(my_buffer, _nc_SLIMIT(sizeof(my_buffer))
+ TRACEMSE_FMT,
+ ep->id,
+ ep->x,
+ ep->y,
+ ep->z,
+ (unsigned long) ep->bstate);
+
+ (void) _nc_trace_mmask_t(sp, ep->bstate);
+ _nc_STRCAT(my_buffer, "}", sizeof(my_buffer));
+ result = (my_buffer);
+ }
+ return result;
+}
+
+NCURSES_EXPORT(mmask_t)
+_nc_retrace_mmask_t(SCREEN *sp, mmask_t code)
+{
+ if (sp != 0) {
+ *my_buffer = '\0';
+ T((T_RETURN("{%s}"), _nc_trace_mmask_t(sp, code)));
+ } else {
+ T((T_RETURN("{?}")));
+ }
+ return code;
+}
+
+NCURSES_EXPORT(char *)
+_tracemouse(MEVENT const *ep)
+{
+ return _nc_tracemouse(CURRENT_SCREEN, ep);
}
#else /* !TRACE */
-empty_module(_nc_lib_tracemouse)
+EMPTY_MODULE(_nc_lib_tracemouse)
#endif