1
/* $XFree86: xc/programs/xtrap/xtrapout.c,v 1.2 2001/12/12 00:43:50 dawes Exp $ */
8
* Revision 1.1.4.2 1993/12/14 12:37:28 Kenneth_Miller
9
* ANSI-standardize code and turn client build on
10
* [1993/12/09 20:16:01 Kenneth_Miller]
12
* Revision 1.1.2.2 1992/04/27 13:51:57 Leela_Obilichetti
13
* initial load of xtrap clients - from silver BL6 pool
14
* [92/04/27 13:49:33 Leela_Obilichetti]
18
/*****************************************************************************
19
Copyright 1987, 1988, 1989, 1990, 1991, 1993 by Digital Equipment Corp.,
22
Permission to use, copy, modify, and distribute this software and its
23
documentation for any purpose and without fee is hereby granted,
24
provided that the above copyright notice appear in all copies and that
25
both that copyright notice and this permission notice appear in
26
supporting documentation, and that the name of Digital not be
27
used in advertising or publicity pertaining to distribution of the
28
software without specific, written prior permission.
30
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
31
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
32
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
33
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
34
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
35
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
38
*****************************************************************************/
53
#define ProgName "xtrapout"
56
** FACILITY: xtrapout - Sample client to test output from XTrap extension
58
** MODULE DESCRIPTION:
60
** This is the main module for a sample/test client
61
** for the XTrap X11 Server Extension. It accepts
62
** a script output file, a transport method,
63
** and an "events mode" flag (-e) as input,
64
** in addition to the standard X arguments (-d, etc.).
65
** If no script file is provided, stdout is the default
66
** and can be piped to the companion "xtrapin"
67
** client (normally used with the -e argument which
68
** sends all core input events to stdout).
75
** CREATION DATE: March 28, 1990
79
** See the companion "xtrapin" client.
81
** Also, getopt() is used to parse the command
82
** line arguments prior to calling XtAppInitialize().
83
** This is because DECwindows appears to remove the user-
84
** defined arguments from the argv[] vector without actually
92
#include <X11/extensions/xtraplib.h>
93
#include <X11/extensions/xtraplibp.h>
95
#include <X11/keysym.h>
99
#include "XEKeybCtrl.h"
102
#define globalref extern
106
/* Forward declarations */
107
static void SetGlobalDone (void );
108
static void print_req_callback (XETC *tc , XETrapDatum *data ,
110
static void print_evt_callback (XETC *tc , XETrapDatum *data ,
115
Bool GlobalDone = False;
116
XrmOptionDescRec optionTable [] =
118
{"-f", "*script", XrmoptionSepArg, (caddr_t) NULL},
119
{"-e", "*eventFlag", XrmoptionSkipArg, (caddr_t) NULL},
120
{"-v", "*verbose", XrmoptionSkipArg, (caddr_t) NULL},
123
static void SetGlobalDone(void)
126
fprintf(stderr,"Process Completed!\n");
130
static void print_req_callback(XETC *tc, XETrapDatum *data, char *my_buf)
133
req_type = (data->u.req.reqType == XETrapGetExtOpcode(tc) ? "XTrap" :
134
XERequestIDToString(data->u.req.reqType,tc));
135
fprintf(ofp,"Request: %-19s (%d): length '%ld' client '%d' window=%ld\n",
136
req_type, data->u.req.reqType, (long)data->hdr.count, data->hdr.client,
137
(long)data->u.req.id);
140
static void print_evt_callback(XETC *tc, XETrapDatum *data, char *my_buf)
142
static Time last_time = 0;
145
delta = abs((int)last_time ? data->u.event.u.keyButtonPointer.time -
146
(int)last_time : (int)last_time);
147
last_time = data->u.event.u.keyButtonPointer.time;
149
/* The "screen" and "root" fields aren't valid until "event"
150
* vectoring becomes a reality. Currently, XTrap intercepts
151
* the core events prior to when fields other than rootX, rootY,
152
* type, detail, time, and state are filled in. This will be
153
* addressed in the next release of XTrap (3.2?).
156
"Event: %-15s (%d):det=%d scr=%d (%d,%d) root=%d Msk=%d TS=%d\n",
157
XEEventIDToString(data->u.event.u.u.type,tc), data->u.event.u.u.type,
158
data->u.event.u.u.detail, data->hdr.screen, /* Not really valid yet */
159
data->u.event.u.keyButtonPointer.rootX,
160
data->u.event.u.keyButtonPointer.rootY,
161
(int)data->u.event.u.keyButtonPointer.root, /* Not really valid yet */
162
(int)data->u.event.u.keyButtonPointer.state,
166
static Boolean eventFlag = False;
167
static Boolean verboseFlag = False;
172
main(int argc, char *argv[])
174
XETrapGetAvailRep ret_avail;
175
XETrapGetCurRep ret_cur;
188
popterr = XEgetopterr();
189
poptarg = XEgetoptarg();
194
*popterr = 0; /* don't complain about -d (display) */
195
while ((ch = getopt(argc, argv, "d:evf:")) != EOF)
206
if ((ofp = fopen(*poptarg,"wb")) == NULL)
207
{ /* can't open it */
208
fprintf(stderr,"%s: could not open output file '%s'!\n",
212
case 'd': /* -display, let's let the toolkit parse it */
218
ofp = (ofp ? ofp : stdout);
220
appW = XtAppInitialize(&app,"XTrap",optionTable,(Cardinal)2L,
221
(int *)&argc, (String *)argv, (String *)NULL,(ArgList)&tmp,
224
dpy = XtDisplay(appW);
226
XSynchronize(dpy, True);
228
fprintf(stderr,"Display: %s \n", DisplayString(dpy));
229
if ((tc = XECreateTC(dpy,0L, NULL)) == False)
231
fprintf(stderr,"%s: could not initialize XTrap extension\n",ProgName);
234
XETrapSetTimestamps(tc,True, False);
235
(void)XEGetAvailableRequest(tc,&ret_avail);
236
XEPrintAvail(stderr,&ret_avail);
237
XEPrintTkFlags(stderr,tc);
239
/* Need to prime events/requests initially turning all off */
240
(void)memset(requests,0L,sizeof(requests));
241
(void)memset(events,0L,sizeof(events));
242
/* Now turn on the ones you really want */
243
(void)memset(events,0xFFL,XETrapMaxEvent);
244
if (eventFlag == False)
245
{ /* doesn't want just events */
246
(void)memset(requests,0xFFL,XETrapMaxRequest);
247
/* Turn off XTrap Requests for multi-client regression tests & XLib */
248
BitFalse(requests, XETrapGetExtOpcode(tc));
249
/* Turn off noisy events */
250
BitFalse(events, MotionNotify);
252
if (verboseFlag == True)
253
{ /* want's *all* requests/events */
254
(void)memset(requests,0xFFL,XETrapMaxRequest);
255
(void)memset(events,0xFFL,XETrapMaxEvent);
257
/* Tell the TC about it */
258
XETrapSetRequests(tc, True, requests);
259
XETrapSetEvents(tc, True, events);
260
XETrapSetMaxPacket(tc, True, XETrapMinPktSize); /* just get the minimum */
262
/* Set up callbacks for data */
263
XEAddRequestCBs(tc, requests, print_req_callback, NULL);
264
XEAddEventCBs(tc, events, print_evt_callback, NULL);
266
(void)XEStartTrapRequest(tc);
267
(void)XEGetCurrentRequest(tc,&ret_cur);
268
XEPrintCurrent(stderr,&ret_cur);
270
/* Add signal handlers so that we clean up properly */
271
_InitExceptionHandling((void_function)SetGlobalDone);
272
(void)XEEnableCtrlKeys((void_function)SetGlobalDone);
274
XETrapAppWhileLoop(app,tc,&GlobalDone);
276
/* Make sure <CTRL> key is released */
277
XESimulateXEventRequest(tc, KeyRelease,
278
XKeysymToKeycode(dpy, XK_Control_L), 0L, 0L, 0L);
280
/* close down everything nicely */
282
(void)XCloseDisplay(dpy);
283
(void)XEClearCtrlKeys();
284
_ClearExceptionHandling();