xtrapout.c revision 1e036838
1876ff6feSmrg/* $XFree86: xc/programs/xtrap/xtrapout.c,v 1.1 2001/11/02 23:29:34 dawes Exp $ */ 2876ff6feSmrg/* 3876ff6feSmrg * @DEC_COPYRIGHT@ 4876ff6feSmrg */ 5876ff6feSmrg/* 6876ff6feSmrg * HISTORY 7876ff6feSmrg * Log: xtrapout.c,v $ 8876ff6feSmrg * Revision 1.1.4.2 1993/12/14 12:37:28 Kenneth_Miller 9876ff6feSmrg * ANSI-standardize code and turn client build on 10876ff6feSmrg * [1993/12/09 20:16:01 Kenneth_Miller] 11876ff6feSmrg * 12876ff6feSmrg * Revision 1.1.2.2 1992/04/27 13:51:57 Leela_Obilichetti 13876ff6feSmrg * initial load of xtrap clients - from silver BL6 pool 14876ff6feSmrg * [92/04/27 13:49:33 Leela_Obilichetti] 15876ff6feSmrg * 16876ff6feSmrg * EndLog$ 17876ff6feSmrg */ 18876ff6feSmrg/***************************************************************************** 19876ff6feSmrgCopyright 1987, 1988, 1989, 1990, 1991, 1993 by Digital Equipment Corp., 20876ff6feSmrgMaynard, MA 21876ff6feSmrg 22876ff6feSmrgPermission to use, copy, modify, and distribute this software and its 23876ff6feSmrgdocumentation for any purpose and without fee is hereby granted, 24876ff6feSmrgprovided that the above copyright notice appear in all copies and that 25876ff6feSmrgboth that copyright notice and this permission notice appear in 26876ff6feSmrgsupporting documentation, and that the name of Digital not be 27876ff6feSmrgused in advertising or publicity pertaining to distribution of the 28876ff6feSmrgsoftware without specific, written prior permission. 29876ff6feSmrg 30876ff6feSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 31876ff6feSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 32876ff6feSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 33876ff6feSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 34876ff6feSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 35876ff6feSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 36876ff6feSmrgSOFTWARE. 37876ff6feSmrg 38876ff6feSmrg*****************************************************************************/ 39876ff6feSmrg/* 40876ff6feSmrg * 41876ff6feSmrg * CONTRIBUTORS: 42876ff6feSmrg * 43876ff6feSmrg * Dick Annicchiarico 44876ff6feSmrg * Robert Chesler 45876ff6feSmrg * Dan Coutu 46876ff6feSmrg * Gene Durso 47876ff6feSmrg * Marc Evans 48876ff6feSmrg * Alan Jamison 49876ff6feSmrg * Mark Henry 50876ff6feSmrg * Ken Miller 51876ff6feSmrg * 52876ff6feSmrg */ 53876ff6feSmrg#define ProgName "xtrapout" 54876ff6feSmrg/* 55876ff6feSmrg**++ 56876ff6feSmrg** FACILITY: xtrapout - Sample client to test output from XTrap extension 57876ff6feSmrg** 58876ff6feSmrg** MODULE DESCRIPTION: 59876ff6feSmrg** 60876ff6feSmrg** This is the main module for a sample/test client 61876ff6feSmrg** for the XTrap X11 Server Extension. It accepts 62876ff6feSmrg** a script output file, a transport method, 63876ff6feSmrg** and an "events mode" flag (-e) as input, 64876ff6feSmrg** in addition to the standard X arguments (-d, etc.). 65876ff6feSmrg** If no script file is provided, stdout is the default 66876ff6feSmrg** and can be piped to the companion "xtrapin" 67876ff6feSmrg** client (normally used with the -e argument which 68876ff6feSmrg** sends all core input events to stdout). 69876ff6feSmrg** 70876ff6feSmrg** 71876ff6feSmrg** AUTHORS: 72876ff6feSmrg** 73876ff6feSmrg** Kenneth B. Miller 74876ff6feSmrg** 75876ff6feSmrg** CREATION DATE: March 28, 1990 76876ff6feSmrg** 77876ff6feSmrg** DESIGN ISSUES: 78876ff6feSmrg** 79876ff6feSmrg** See the companion "xtrapin" client. 80876ff6feSmrg** 81876ff6feSmrg** Also, getopt() is used to parse the command 82876ff6feSmrg** line arguments prior to calling XtAppInitialize(). 83876ff6feSmrg** This is because DECwindows appears to remove the user- 84876ff6feSmrg** defined arguments from the argv[] vector without actually 85876ff6feSmrg** acting upon them. 86876ff6feSmrg** 87876ff6feSmrg** 88876ff6feSmrg**-- 89876ff6feSmrg*/ 90876ff6feSmrg 912f9f5fecSjoerg#include <inttypes.h> 92876ff6feSmrg#include <stdio.h> 93876ff6feSmrg#include <X11/extensions/xtraplib.h> 94876ff6feSmrg#include <X11/extensions/xtraplibp.h> 95876ff6feSmrg#include <signal.h> 96876ff6feSmrg#include <X11/keysym.h> 97876ff6feSmrg#include <unistd.h> 98876ff6feSmrg#include <stdlib.h> 99876ff6feSmrg 100876ff6feSmrg#include "XEKeybCtrl.h" 101876ff6feSmrg 102876ff6feSmrg#ifndef vaxc 103876ff6feSmrg#define globalref extern 104876ff6feSmrg#endif 105876ff6feSmrg#ifdef Lynx 106876ff6feSmrgextern char *optarg; 107876ff6feSmrgextern int optind; 108876ff6feSmrgextern int opterr; 109876ff6feSmrg#endif 110876ff6feSmrg 111876ff6feSmrg 112876ff6feSmrg/* Forward declarations */ 1131e036838Sjoergstatic void SetGlobalDone (int); 114876ff6feSmrgstatic void print_req_callback (XETC *tc , XETrapDatum *data , 1151e036838Sjoerg unsigned char *my_buf ); 116876ff6feSmrgstatic void print_evt_callback (XETC *tc , XETrapDatum *data , 1171e036838Sjoerg unsigned char *my_buf ); 118876ff6feSmrg 119876ff6feSmrg 120876ff6feSmrgFILE *ofp; 121876ff6feSmrgBool GlobalDone = False; 122876ff6feSmrgXrmOptionDescRec optionTable [] = 123876ff6feSmrg{ 124876ff6feSmrg {"-f", "*script", XrmoptionSepArg, (caddr_t) NULL}, 125876ff6feSmrg {"-e", "*eventFlag", XrmoptionSkipArg, (caddr_t) NULL}, 126876ff6feSmrg {"-v", "*verbose", XrmoptionSkipArg, (caddr_t) NULL}, 127876ff6feSmrg}; 128876ff6feSmrg 1291e036838Sjoergstatic void SetGlobalDone(int unused) 130876ff6feSmrg{ 131876ff6feSmrg GlobalDone = 1L; 132876ff6feSmrg fprintf(stderr,"Process Completed!\n"); 133876ff6feSmrg return; 134876ff6feSmrg} 135876ff6feSmrg 1361e036838Sjoergstatic void print_req_callback(XETC *tc, XETrapDatum *data, unsigned char *my_buf) 137876ff6feSmrg{ 138876ff6feSmrg char *req_type; 139876ff6feSmrg req_type = (data->u.req.reqType == XETrapGetExtOpcode(tc) ? "XTrap" : 140876ff6feSmrg XERequestIDToString(data->u.req.reqType,tc)); 141876ff6feSmrg fprintf(ofp,"Request: %-19s (%d): length '%ld' client '%d' window=%ld\n", 142876ff6feSmrg req_type, data->u.req.reqType, (long)data->hdr.count, data->hdr.client, 143876ff6feSmrg (long)data->u.req.id); 144876ff6feSmrg} 145876ff6feSmrg 1461e036838Sjoergstatic void print_evt_callback(XETC *tc, XETrapDatum *data, unsigned char *my_buf) 147876ff6feSmrg{ 148876ff6feSmrg static Time last_time = 0; 149876ff6feSmrg int delta; 150876ff6feSmrg 1512f9f5fecSjoerg delta = imaxabs((int)last_time ? (intmax_t)data->u.event.u.keyButtonPointer.time - 152876ff6feSmrg (int)last_time : (int)last_time); 153876ff6feSmrg last_time = data->u.event.u.keyButtonPointer.time; 154876ff6feSmrg 155876ff6feSmrg /* The "screen" and "root" fields aren't valid until "event" 156876ff6feSmrg * vectoring becomes a reality. Currently, XTrap intercepts 157876ff6feSmrg * the core events prior to when fields other than rootX, rootY, 158876ff6feSmrg * type, detail, time, and state are filled in. This will be 159876ff6feSmrg * addressed in the next release of XTrap (3.2?). 160876ff6feSmrg */ 161876ff6feSmrg fprintf(ofp, 162876ff6feSmrg "Event: %-15s (%d):det=%d scr=%d (%d,%d) root=%d Msk=%d TS=%d\n", 163876ff6feSmrg XEEventIDToString(data->u.event.u.u.type,tc), data->u.event.u.u.type, 164876ff6feSmrg data->u.event.u.u.detail, data->hdr.screen, /* Not really valid yet */ 165876ff6feSmrg data->u.event.u.keyButtonPointer.rootX, 166876ff6feSmrg data->u.event.u.keyButtonPointer.rootY, 167876ff6feSmrg (int)data->u.event.u.keyButtonPointer.root, /* Not really valid yet */ 168876ff6feSmrg (int)data->u.event.u.keyButtonPointer.state, 169876ff6feSmrg (int)delta); 170876ff6feSmrg fflush(ofp); 171876ff6feSmrg} 172876ff6feSmrgstatic Boolean eventFlag = False; 173876ff6feSmrgstatic Boolean verboseFlag = False; 174876ff6feSmrgstatic Widget appW; 175876ff6feSmrgstatic Display *dpy; 176876ff6feSmrg 177876ff6feSmrgint 178876ff6feSmrgmain(int argc, char *argv[]) 179876ff6feSmrg{ 180876ff6feSmrg XETrapGetAvailRep ret_avail; 181876ff6feSmrg XETrapGetCurRep ret_cur; 182876ff6feSmrg XETC *tc; 183876ff6feSmrg ReqFlags requests; 184876ff6feSmrg EventFlags events; 185876ff6feSmrg XtAppContext app; 186876ff6feSmrg char *tmp = NULL; 187876ff6feSmrg INT16 ch; 188876ff6feSmrg int *popterr; 189876ff6feSmrg char **poptarg; 190876ff6feSmrg#ifndef vms 191876ff6feSmrg popterr = &opterr; 192876ff6feSmrg poptarg = &optarg; 193876ff6feSmrg#else 194876ff6feSmrg popterr = XEgetopterr(); 195876ff6feSmrg poptarg = XEgetoptarg(); 196876ff6feSmrg#endif 197876ff6feSmrg 198876ff6feSmrg eventFlag = False; 199876ff6feSmrg ofp = NULL; 200876ff6feSmrg *popterr = 0; /* don't complain about -d (display) */ 201876ff6feSmrg while ((ch = getopt(argc, argv, "d:evf:")) != EOF) 202876ff6feSmrg { 203876ff6feSmrg switch(ch) 204876ff6feSmrg { 205876ff6feSmrg case 'e': 206876ff6feSmrg eventFlag = True; 207876ff6feSmrg break; 208876ff6feSmrg case 'v': 209876ff6feSmrg verboseFlag = True; 210876ff6feSmrg break; 211876ff6feSmrg case 'f': 212876ff6feSmrg if ((ofp = fopen(*poptarg,"wb")) == NULL) 213876ff6feSmrg { /* can't open it */ 214876ff6feSmrg fprintf(stderr,"%s: could not open output file '%s'!\n", 215876ff6feSmrg ProgName, *poptarg); 216876ff6feSmrg } 217876ff6feSmrg break; 218876ff6feSmrg case 'd': /* -display, let's let the toolkit parse it */ 219876ff6feSmrg break; 220876ff6feSmrg default: 221876ff6feSmrg break; 222876ff6feSmrg } 223876ff6feSmrg } 224876ff6feSmrg ofp = (ofp ? ofp : stdout); 225876ff6feSmrg 226876ff6feSmrg appW = XtAppInitialize(&app,"XTrap",optionTable,(Cardinal)2L, 227876ff6feSmrg (int *)&argc, (String *)argv, (String *)NULL,(ArgList)&tmp, 22847cb5690Schristos (Cardinal)0); 229876ff6feSmrg 230876ff6feSmrg dpy = XtDisplay(appW); 231876ff6feSmrg#ifdef DEBUG 232876ff6feSmrg XSynchronize(dpy, True); 233876ff6feSmrg#endif 234876ff6feSmrg fprintf(stderr,"Display: %s \n", DisplayString(dpy)); 235876ff6feSmrg if ((tc = XECreateTC(dpy,0L, NULL)) == False) 236876ff6feSmrg { 237876ff6feSmrg fprintf(stderr,"%s: could not initialize XTrap extension\n",ProgName); 238876ff6feSmrg exit (1L); 239876ff6feSmrg } 240876ff6feSmrg XETrapSetTimestamps(tc,True, False); 241876ff6feSmrg (void)XEGetAvailableRequest(tc,&ret_avail); 242876ff6feSmrg XEPrintAvail(stderr,&ret_avail); 243876ff6feSmrg XEPrintTkFlags(stderr,tc); 244876ff6feSmrg 245876ff6feSmrg /* Need to prime events/requests initially turning all off */ 246876ff6feSmrg (void)memset(requests,0L,sizeof(requests)); 247876ff6feSmrg (void)memset(events,0L,sizeof(events)); 248876ff6feSmrg /* Now turn on the ones you really want */ 249876ff6feSmrg (void)memset(events,0xFFL,XETrapMaxEvent); 250876ff6feSmrg if (eventFlag == False) 251876ff6feSmrg { /* doesn't want just events */ 252876ff6feSmrg (void)memset(requests,0xFFL,XETrapMaxRequest); 253876ff6feSmrg /* Turn off XTrap Requests for multi-client regression tests & XLib */ 254876ff6feSmrg BitFalse(requests, XETrapGetExtOpcode(tc)); 255876ff6feSmrg /* Turn off noisy events */ 256876ff6feSmrg BitFalse(events, MotionNotify); 257876ff6feSmrg } 258876ff6feSmrg if (verboseFlag == True) 259876ff6feSmrg { /* want's *all* requests/events */ 260876ff6feSmrg (void)memset(requests,0xFFL,XETrapMaxRequest); 261876ff6feSmrg (void)memset(events,0xFFL,XETrapMaxEvent); 262876ff6feSmrg } 263876ff6feSmrg /* Tell the TC about it */ 264876ff6feSmrg XETrapSetRequests(tc, True, requests); 265876ff6feSmrg XETrapSetEvents(tc, True, events); 266876ff6feSmrg XETrapSetMaxPacket(tc, True, XETrapMinPktSize); /* just get the minimum */ 267876ff6feSmrg 268876ff6feSmrg /* Set up callbacks for data */ 269876ff6feSmrg XEAddRequestCBs(tc, requests, print_req_callback, NULL); 270876ff6feSmrg XEAddEventCBs(tc, events, print_evt_callback, NULL); 271876ff6feSmrg 272876ff6feSmrg (void)XEStartTrapRequest(tc); 273876ff6feSmrg (void)XEGetCurrentRequest(tc,&ret_cur); 274876ff6feSmrg XEPrintCurrent(stderr,&ret_cur); 275876ff6feSmrg 276876ff6feSmrg /* Add signal handlers so that we clean up properly */ 2771e036838Sjoerg _InitExceptionHandling(SetGlobalDone); 2781e036838Sjoerg (void)XEEnableCtrlKeys(SetGlobalDone); 279876ff6feSmrg 280876ff6feSmrg XETrapAppWhileLoop(app,tc,&GlobalDone); 281876ff6feSmrg 282876ff6feSmrg /* Make sure <CTRL> key is released */ 283876ff6feSmrg XESimulateXEventRequest(tc, KeyRelease, 284876ff6feSmrg XKeysymToKeycode(dpy, XK_Control_L), 0L, 0L, 0L); 285876ff6feSmrg 286876ff6feSmrg /* close down everything nicely */ 287876ff6feSmrg XEFreeTC(tc); 288876ff6feSmrg (void)XCloseDisplay(dpy); 289876ff6feSmrg (void)XEClearCtrlKeys(); 290876ff6feSmrg _ClearExceptionHandling(); 291876ff6feSmrg exit(0L); 292876ff6feSmrg} 293876ff6feSmrg 294