Debian Codegraph @

clients/mwm/WmWsmLib/debug.c

raw
1 /* $XConsortium: debug.c /main/5 1995/07/15 20:38:27 drk $ */
2 /*
3 * Motif
4 *
5 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
6 *
7 * These libraries and programs are free software; you can
8 * redistribute them and/or modify them under the terms of the GNU
9 * Lesser General Public License as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * These libraries and programs are distributed in the hope that
14 * they will be useful, but WITHOUT ANY WARRANTY; without even the
15 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU Lesser General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with these librararies and programs; if not, write
21 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
22 * Floor, Boston, MA 02110-1301 USA
23 *
24 */
25 /*
26 * HISTORY
27 */
28
29 #include "wsm_proto.h"
30
31 static void PrintWindowInfo(
32 String,
33 WSMWinInfo *
34 );
35 static void PrintWindowData(
36 String,
37 String,
38 WSMWinData *
39 );
40 static void PrintConfigFormat(
41 String,
42 WSMConfigFormatReply *
43 );
44
45 #define STRSIZE (BUFSIZ * 10)
46
47 /************************************************************
48 *
49 * This file contains routines to ease in debugging.
50 *
51 ************************************************************/
52
53 /* Function Name: PrintRequest
54 * Description: Prints out a request in human readable form.
55 * Arguments: request - The request to print.
56 * Returns: str - The string the request is printed to.
57 */
58
59 String
60 PrintRequest(WSMRequest *request)
61 {
62 static char str[STRSIZE]; /* The vile hacks we do in debugging code. */
63 String ptr;
64 register int i;
65
66 sprintf(str, "Request: %s\n", _WSMReqTypeToName(request->any.type));
67 ptr = str + strlen(str);
68
69 switch (request->any.type) {
70 case WSM_CONNECT:
71 sprintf(ptr, "Number of Versions: %d\nVersions: ",
72 request->connect.num_versions);
73 for (i = 0; i < request->connect.num_versions; i++) {
74 ptr += strlen(ptr);
75 sprintf(ptr, "%d", (int) request->connect.known_versions[i]);
76 if ((i + 1) < request->connect.num_versions)
77 strcat(ptr, ", ");
78 }
79 strcat(ptr, "\n");
80 break;
81 case WSM_EXTENSIONS:
82 sprintf(ptr, "Number of Extension Suggestions: %d\n%s",
83 request->extensions.num_extensions,
84 "Extension Suggestions:\n ");
85 for (i = 0; i < request->extensions.num_extensions; i++) {
86 ptr += strlen(ptr);
87 strcat(ptr, request->extensions.extension_suggestions[i]);
88 if ((i + 1) < request->extensions.num_extensions)
89 strcat(ptr, ", ");
90 }
91 strcat(ptr, "\n");
92 break;
93 case WSM_CONFIG_FMT:
94 sprintf(ptr, "No other data for this request.\n");
95 break;
96 case WSM_GET_STATE:
97 sprintf(ptr, "Window: 0x%lX\nDiffs Allowed: %s\n",
98 request->get_state.window,
99 request->get_state.diffs_allowed ? "True" : "False");
100 break;
101 case WSM_SET_STATE:
102 sprintf(ptr, "Number of Windows with Info: %d\n",
103 request->set_state.num_win_info_list);
104 for (i = 0; i < request->set_state.num_win_info_list; i++) {
105 ptr += strlen(ptr);
106 PrintWindowInfo(ptr, request->set_state.win_info_list + i);
107 }
108 break;
109 case WSM_REG_WINDOW:
110 sprintf(ptr, "Window: 0x%lX\n", request->register_window.window);
111 break;
112 case WSM_WM_GET_BACKGROUND_WINDOW:
113 case WSM_WM_SET_BACKGROUND_WINDOW:
114 case WSM_WM_WINDOWS:
115 case WSM_WM_FOCUS:
116 case WSM_WM_POINTER:
117 case WSM_UNKNOWN:
118 break;
119 }
120
121 return(str);
122 }
123
124 /* Function Name: PrintReply
125 * Description: Prints out a reply in human readable form.
126 * Arguments: reply - The reply to print.
127 * Returns: str - The string the reply is printed to.
128 */
129
130 String
131 PrintReply(WSMReply *reply)
132 {
133 static char str[STRSIZE]; /* The vile hacks we do in debugging code. */
134 register int i;
135 String ptr;
136
137 sprintf(str, "Reply: %s\n", _WSMReqTypeToName(reply->any.type));
138 ptr = str + strlen(str);
139
140 switch (reply->any.type) {
141 case WSM_CONNECT:
142 sprintf(ptr, "Version: %d\n", (int) reply->connect.version);
143 break;
144 case WSM_EXTENSIONS:
145 sprintf(ptr, "Number of Extensions: %d\n%s",
146 reply->extensions.num_extensions,
147 "Extensions:\n ");
148 for (i = 0; i < reply->extensions.num_extensions; i++) {
149 ptr += strlen(ptr);
150 strcat(ptr, reply->extensions.extensions[i]);
151 if ((i + 1) < reply->extensions.num_extensions)
152 strcat(ptr, ", ");
153 }
154 strcat(ptr, "\n");
155 break;
156 case WSM_CONFIG_FMT:
157 PrintConfigFormat(ptr, &(reply->config_format));
158 break;
159 case WSM_GET_STATE:
160 sprintf(ptr, "Number of Windows with Info: %d\n",
161 reply->get_state.num_win_info_list);
162 for (i = 0; i < reply->get_state.num_win_info_list; i++) {
163 ptr += strlen(ptr);
164 PrintWindowInfo(ptr, reply->get_state.win_info_list + i);
165 }
166 break;
167 case WSM_SET_STATE:
168 sprintf(ptr, "No other data for this reply.\n");
169 break;
170 case WSM_REG_WINDOW:
171 {
172 int num = reply->register_window.num_window_data;
173 WSMWinData *win_data = reply->register_window.window_data;
174
175 sprintf(ptr, "Number of Data Attributes: %d\n", num);
176 for (i = 0; i < num; i++, win_data++) {
177 ptr += strlen(ptr);
178 PrintWindowData(ptr, "", win_data);
179 }
180 }
181 break;
182 case WSM_WM_GET_BACKGROUND_WINDOW:
183 case WSM_WM_SET_BACKGROUND_WINDOW:
184 case WSM_WM_WINDOWS:
185 case WSM_WM_FOCUS:
186 case WSM_WM_POINTER:
187 case WSM_UNKNOWN:
188 break;
189 }
190
191 return(str);
192 }
193
194 /************************************************************
195 *
196 * Internal Routines.
197 *
198 ************************************************************/
199
200 /* Function Name: PrintWindowInfo
201 * Description: Prints the info about a single window.
202 * Arguments: str - String to stuff it into.
203 * win_info - The window info to print.
204 * Returns: none.
205 */
206
207 static void
208 PrintWindowInfo(
209 String str,
210 WSMWinInfo *win_info)
211 {
212 register int i;
213 int num = win_info->num_data_list;
214 WSMWinData *win_data = win_info->data_list;
215
216 sprintf(str, "Window: 0x%lX\nNumber of Data Attributes: %d\n",
217 win_info->window, num);
218
219 for (i = 0; i < num; i++, win_data++) {
220 str += strlen(str);
221 PrintWindowData(str, " ", win_data);
222 }
223 }
224
225 /* Function Name: PrintWindowData
226 * Description: Prints the data about a single window.
227 * Arguments: str - String to stuff it into.
228 * win_data - The window data to print.
229 * Returns: none.
230 */
231
232 static void
233 PrintWindowData(
234 String str,
235 String tab_str,
236 WSMWinData *win_data)
237 {
238 register int i;
239 char *type_str = NULL;
240
241 if (win_data->type == WSM_VALUE_DATA) {
242 sprintf(str, "%sName: %s, Type: Value, Value: %ld\n", tab_str,
243 XrmQuarkToString(win_data->nameq), win_data->data.value);
244 return;
245 }
246
247
248 switch(win_data->type) {
249 case WSM_CHAR_LIST_DATA:
250 type_str = "Char List";
251 break;
252 case WSM_SHORT_LIST_DATA:
253 type_str = "Short List";
254 break;
255 case WSM_LONG_LIST_DATA:
256 type_str = "Long List";
257 break;
258 case WSM_VALUE_DATA:
259 case WSM_NONE:
260 type_str = "<NONE>";
261 break;
262 }
263
264 sprintf(str, "%sName: %s, Type: %s, Len: %d\n%s%s", tab_str,
265 XrmQuarkToString(win_data->nameq), type_str,
266 win_data->data_len, tab_str, " ");
267
268 for (i = 0; i < win_data->data_len; i++) {
269 str += strlen(str);
270
271 switch(win_data->type) {
272 case WSM_CHAR_LIST_DATA:
273 sprintf(str, "%c(%d)", win_data->data.char_ptr[i],
274 (int) win_data->data.char_ptr[i]);
275 break;
276 case WSM_SHORT_LIST_DATA:
277 sprintf(str, "%d", (int) win_data->data.short_ptr[i]);
278 break;
279 case WSM_LONG_LIST_DATA:
280 sprintf(str, "%ld", win_data->data.long_ptr[i]);
281 break;
282 case WSM_VALUE_DATA:
283 case WSM_NONE:
284 break;
285 }
286 if (i < (win_data->data_len - 1))
287 strcat(str, ", ");
288 }
289
290 strcat(str, "\n");
291 }
292
293 /* Function Name: PrintConfigFormat
294 * Description: Prints the configuration format.
295 * Arguments: str - The string to print the conf info into.
296 * config_fmt - The configuration format reply.
297 * Returns: none
298 */
299
300 static void
301 PrintConfigFormat(
302 String str,
303 WSMConfigFormatReply *config_fmt)
304 {
305 register int i;
306
307 sprintf("Accepts Diffs: %s\n",
308 (config_fmt->accepts_diffs ? "True" : "False"));
309
310 for (i = 0; i < 3; i++) {
311 WSMAttribute *fmt;
312 register int j, num;
313
314 str += strlen(str);
315
316 switch (i) {
317 case WSM_GLOBAL_FMT:
318 fmt = config_fmt->global_formats;
319 num = config_fmt->num_global_formats;
320 sprintf(str, "Global Formats - Number: %d\n", num);
321 break;
322 case WSM_WINDOW_FMT:
323 fmt = config_fmt->window_formats;
324 num = config_fmt->num_window_formats;
325 sprintf(str, "Window Formats - Number: %d\n", num);
326 break;
327 case WSM_ICON_FMT:
328 fmt = config_fmt->icon_formats;
329 num = config_fmt->num_icon_formats;
330 sprintf(str, "Icon Formats - Number: %d\n", num);
331 break;
332 }
333
334 for (j = 0; j < num; j++) {
335 str += strlen(str);
336 sprintf(str, " Name: %s, Size: %d, Is_List: %s\n",
337 XrmQuarkToString(fmt[j].nameq), (int) fmt[j].size,
338 fmt[j].is_list ? "True" : "False");
339 }
340 }
341 }