xref: /freebsd/contrib/ncurses/ncurses/trace/lib_tracemse.c (revision 43c7dd6b597947c27cab4ebc5a67a8a3f5b7c58d)
1 /****************************************************************************
2  * Copyright 2020 Thomas E. Dickey                                          *
3  * Copyright 1998-2012,2014 Free Software Foundation, Inc.                  *
4  *                                                                          *
5  * Permission is hereby granted, free of charge, to any person obtaining a  *
6  * copy of this software and associated documentation files (the            *
7  * "Software"), to deal in the Software without restriction, including      *
8  * without limitation the rights to use, copy, modify, merge, publish,      *
9  * distribute, distribute with modifications, sublicense, and/or sell       *
10  * copies of the Software, and to permit persons to whom the Software is    *
11  * furnished to do so, subject to the following conditions:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23  *                                                                          *
24  * Except as contained in this notice, the name(s) of the above copyright   *
25  * holders shall not be used in advertising or otherwise to promote the     *
26  * sale, use or other dealings in this Software without prior written       *
27  * authorization.                                                           *
28  ****************************************************************************/
29 
30 /****************************************************************************
31  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
32  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
33  *     and: Thomas E. Dickey                        1996-on                 *
34  ****************************************************************************/
35 
36 /*
37  *	lib_tracemse.c - Tracing/Debugging routines (mouse events)
38  */
39 
40 #include <curses.priv.h>
41 
42 MODULE_ID("$Id: lib_tracemse.c,v 1.23 2020/02/02 23:34:34 tom Exp $")
43 
44 #ifdef TRACE
45 
46 #define my_buffer sp->tracemse_buf
47 
NCURSES_EXPORT(char *)48 NCURSES_EXPORT(char *)
49 _nc_trace_mmask_t(SCREEN *sp, mmask_t code)
50 {
51 #define SHOW(m, s) \
52     if ((code & m) == m) { \
53 	size_t n = strlen(my_buffer); \
54 	if (n && (my_buffer[n-1] != '{')) \
55 	_nc_STRCAT(my_buffer, ", ", sizeof(my_buffer)); \
56 	_nc_STRCAT(my_buffer, s, sizeof(my_buffer)); \
57     }
58 
59     SHOW(BUTTON1_RELEASED, "release-1");
60     SHOW(BUTTON1_PRESSED, "press-1");
61     SHOW(BUTTON1_CLICKED, "click-1");
62     SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
63     SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
64 #if NCURSES_MOUSE_VERSION == 1
65     SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
66 #endif
67 
68     SHOW(BUTTON2_RELEASED, "release-2");
69     SHOW(BUTTON2_PRESSED, "press-2");
70     SHOW(BUTTON2_CLICKED, "click-2");
71     SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
72     SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
73 #if NCURSES_MOUSE_VERSION == 1
74     SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
75 #endif
76 
77     SHOW(BUTTON3_RELEASED, "release-3");
78     SHOW(BUTTON3_PRESSED, "press-3");
79     SHOW(BUTTON3_CLICKED, "click-3");
80     SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
81     SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
82 #if NCURSES_MOUSE_VERSION == 1
83     SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
84 #endif
85 
86     SHOW(BUTTON4_RELEASED, "release-4");
87     SHOW(BUTTON4_PRESSED, "press-4");
88     SHOW(BUTTON4_CLICKED, "click-4");
89     SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
90     SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
91 #if NCURSES_MOUSE_VERSION == 1
92     SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
93 #endif
94 
95 #if NCURSES_MOUSE_VERSION == 2
96     SHOW(BUTTON5_RELEASED, "release-5");
97     SHOW(BUTTON5_PRESSED, "press-5");
98     SHOW(BUTTON5_CLICKED, "click-5");
99     SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
100     SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
101 #endif
102 
103     SHOW(BUTTON_CTRL, "ctrl");
104     SHOW(BUTTON_SHIFT, "shift");
105     SHOW(BUTTON_ALT, "alt");
106     SHOW(ALL_MOUSE_EVENTS, "all-events");
107     SHOW(REPORT_MOUSE_POSITION, "position");
108 
109 #undef SHOW
110 
111     if (my_buffer[strlen(my_buffer) - 1] == ' ')
112 	my_buffer[strlen(my_buffer) - 2] = '\0';
113 
114     return (my_buffer);
115 }
116 
117 NCURSES_EXPORT(char *)
_nc_tracemouse(SCREEN * sp,MEVENT const * ep)118 _nc_tracemouse(SCREEN *sp, MEVENT const *ep)
119 {
120     char *result = 0;
121 
122     if (sp != 0) {
123 	_nc_SPRINTF(my_buffer, _nc_SLIMIT(sizeof(my_buffer))
124 		    TRACEMSE_FMT,
125 		    ep->id,
126 		    ep->x,
127 		    ep->y,
128 		    ep->z,
129 		    (unsigned long) ep->bstate);
130 
131 	(void) _nc_trace_mmask_t(sp, ep->bstate);
132 	_nc_STRCAT(my_buffer, "}", sizeof(my_buffer));
133 	result = (my_buffer);
134     }
135     return result;
136 }
137 
138 NCURSES_EXPORT(mmask_t)
_nc_retrace_mmask_t(SCREEN * sp,mmask_t code)139 _nc_retrace_mmask_t(SCREEN *sp, mmask_t code)
140 {
141     if (sp != 0) {
142 	*my_buffer = '\0';
143 	T((T_RETURN("{%s}"), _nc_trace_mmask_t(sp, code)));
144     } else {
145 	T((T_RETURN("{?}")));
146     }
147     return code;
148 }
149 
150 NCURSES_EXPORT(char *)
_tracemouse(MEVENT const * ep)151 _tracemouse(MEVENT const *ep)
152 {
153     return _nc_tracemouse(CURRENT_SCREEN, ep);
154 }
155 
156 #else /* !TRACE */
157 EMPTY_MODULE(_nc_lib_tracemouse)
158 #endif
159