1
/* $XFree86: xc/programs/xtrap/xtrapin.c,v 1.2tsi Exp $ */
8
* Revision 1.1.4.2 1993/12/14 12:37:20 Kenneth_Miller
9
* ANSI-standardize code and turn client build on
10
* [1993/12/09 20:15:45 Kenneth_Miller]
12
* Revision 1.1.2.2 1992/04/27 13:51:39 Leela_Obilichetti
13
* Initial load of xtrap clients - from silver BL6
14
* [92/04/27 13:49:16 Leela_Obilichetti]
18
/*****************************************************************************
19
Copyright 1987, 1988, 1989, 1990, 1991 by Digital Equipment Corp., Maynard, MA
21
Permission to use, copy, modify, and distribute this software and its
22
documentation for any purpose and without fee is hereby granted,
23
provided that the above copyright notice appear in all copies and that
24
both that copyright notice and this permission notice appear in
25
supporting documentation, and that the name of Digital not be
26
used in advertising or publicity pertaining to distribution of the
27
software without specific, written prior permission.
29
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
30
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
31
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
32
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
33
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
34
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
37
*****************************************************************************/
52
#define ProgName "xtrapin"
55
** FACILITY: xtrapin - Sample client to test input to XTrap extension
57
** MODULE DESCRIPTION:
59
** This is the main module for a sample/test client
60
** for the XTrap X11 Server Extension. It accepts
61
** a script file and a transport method as input
62
** in addition to the standard X arguments (-d, etc.).
63
** If no script file is provided, stdin is the default
64
** and can be piped from the companion "xtrapout"
65
** client (normally used with the -e argument which
66
** sends all core input events to stdout).
73
** CREATION DATE: December 15, 1990
77
** See the companion "xtrapout" client.
79
** Also, getopt() is used to parse the command
80
** line arguments prior to calling XtAppInitialize().
81
** This is because DECwindows appears to remove the user-
82
** defined arguments from the argv[] vector without actually
89
#include <X11/extensions/xtraplib.h>
90
#include <X11/extensions/xtraplibp.h>
95
#define globalref extern
103
static Boolean grabFlag = False;
106
XrmOptionDescRec optionTable [] =
108
{"-f", "*script", XrmoptionSepArg, (caddr_t) NULL},
109
{"-g", "*grabServer",XrmoptionSkipArg, (caddr_t) NULL},
113
{ /* longword-align fields for arg passing */
119
int screen; /* this will always be 0 till vectored events! */
122
/* Forward declarations */
123
static Bool found_input_rec (FILE *ifp , file_rec *rec );
130
main(int argc, char *argv[])
132
XETrapGetAvailRep ret_avail;
133
XETrapGetCurRep ret_cur;
146
popterr = XEgetopterr();
147
poptarg = XEgetoptarg();
151
*popterr = 0; /* don't complain about -d for display */
153
while ((ch = getopt(argc, argv, "d:f:g")) != EOF)
158
if ((ifp = fopen(*poptarg,"rb")) == NULL)
159
{ /* can't open it */
160
fprintf(stderr,"%s: could not open output file '%s'!\n",
164
case 'd': /* -display, let's let the toolkit parse it */
172
ifp = (ifp ? ifp : stdin);
174
appW = XtAppInitialize(&app,"XTrap",optionTable,(Cardinal)1L,
175
(int *)&argc, (String *)argv, (String *)NULL,(ArgList)&tmp,
178
dpy = XtDisplay(appW);
180
XSynchronize(dpy, True);
182
printf("Display: %s \n", DisplayString(dpy));
184
if ((tc = XECreateTC(dpy,0L, NULL)) == False)
186
fprintf(stderr,"%s: could not initialize XTrap extension\n", ProgName);
189
(void)XEGetAvailableRequest(tc,&ret_avail);
190
XEPrintAvail(stderr,&ret_avail);
191
XEPrintTkFlags(stderr,tc);
193
if (grabFlag == True)
195
* In order to ignore GrabServer's we must configure at least one
196
* trap. Let's make it X_GrabServer. We don't have to receive
197
* a callback, though.
200
(void)memset(requests,0L,sizeof(requests));
201
BitTrue(requests, X_GrabServer);
202
XETrapSetRequests(tc, True, requests);
203
(void)XETrapSetGrabServer(tc, True);
206
(void)XEStartTrapRequest(tc);
207
(void)XEGetCurrentRequest(tc,&ret_cur);
208
XEPrintCurrent(stderr,&ret_cur);
210
/* Open up script file */
211
while (found_input_rec(ifp,&rec) == True)
213
/* if not pipe'd, delay time delta time recorded */
216
register INT32 delta, t1, t2;
217
last_time = (last_time ? last_time : rec.ts); /* first rec */
218
rec.ts = (rec.ts ? rec.ts : last_time); /* dual monitor bug! */
219
t1 = rec.ts; t2 = last_time; /* move to signed variables */
220
delta = abs(t1 - t2); /* protect from clock roll-over */
224
XESimulateXEventRequest(tc, rec.type, rec.detail, rec.x, rec.y,
228
(void)XCloseDisplay(dpy);
232
static Bool found_input_rec(FILE *ifp, file_rec *rec)
239
while ((found != True) && (fgets(buff,BUFSIZ,ifp) != NULL))
241
if (!strncmp(buff, "Event:", strlen("Event:")))
242
{ /* we want this record */
244
"Event: %s (%d):det=%d scr=%d (%d,%d) root=%d Msk=%d TS=%d\n",
245
junk, &(tmp[0L]), &(tmp[1L]), &(tmp[2L]), &(tmp[3L]),
246
&(tmp[4L]), &(tmp[5L]), &(tmp[6L]), &(tmp[7L])) != 9L)
248
fprintf(stderr, "%s: Error parsing script input!\n\t'%s'\n",
254
/* Sun's have problems with "byte" fields passed to scanf */
256
rec->detail = tmp[1L];
257
rec->screen = tmp[2L];
263
else if (!strncmp(buff, "Request:", strlen("Request:")))
264
{ /* a valid thing to see */
268
{ /* this stuff doesn't look like what we'd expect */
269
fprintf(stderr, "%s: Not a valid script record!\n\t'%s'\n",