xtrapout.c revision 876ff6fe
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 91876ff6feSmrg#include <stdio.h> 92876ff6feSmrg#include <X11/extensions/xtraplib.h> 93876ff6feSmrg#include <X11/extensions/xtraplibp.h> 94876ff6feSmrg#include <signal.h> 95876ff6feSmrg#include <X11/keysym.h> 96876ff6feSmrg#include <unistd.h> 97876ff6feSmrg#include <stdlib.h> 98876ff6feSmrg 99876ff6feSmrg#include "XEKeybCtrl.h" 100876ff6feSmrg 101876ff6feSmrg#ifndef vaxc 102876ff6feSmrg#define globalref extern 103876ff6feSmrg#endif 104876ff6feSmrg#ifdef Lynx 105876ff6feSmrgextern char *optarg; 106876ff6feSmrgextern int optind; 107876ff6feSmrgextern int opterr; 108876ff6feSmrg#endif 109876ff6feSmrg 110876ff6feSmrg 111876ff6feSmrg/* Forward declarations */ 112876ff6feSmrgstatic void SetGlobalDone (void ); 113876ff6feSmrgstatic void print_req_callback (XETC *tc , XETrapDatum *data , 114876ff6feSmrg char *my_buf ); 115876ff6feSmrgstatic void print_evt_callback (XETC *tc , XETrapDatum *data , 116876ff6feSmrg char *my_buf ); 117876ff6feSmrg 118876ff6feSmrg 119876ff6feSmrgFILE *ofp; 120876ff6feSmrgBool GlobalDone = False; 121876ff6feSmrgXrmOptionDescRec optionTable [] = 122876ff6feSmrg{ 123876ff6feSmrg {"-f", "*script", XrmoptionSepArg, (caddr_t) NULL}, 124876ff6feSmrg {"-e", "*eventFlag", XrmoptionSkipArg, (caddr_t) NULL}, 125876ff6feSmrg {"-v", "*verbose", XrmoptionSkipArg, (caddr_t) NULL}, 126876ff6feSmrg}; 127876ff6feSmrg 128876ff6feSmrgstatic void SetGlobalDone(void) 129876ff6feSmrg{ 130876ff6feSmrg GlobalDone = 1L; 131876ff6feSmrg fprintf(stderr,"Process Completed!\n"); 132876ff6feSmrg return; 133876ff6feSmrg} 134876ff6feSmrg 135876ff6feSmrgstatic void print_req_callback(XETC *tc, XETrapDatum *data, char *my_buf) 136876ff6feSmrg{ 137876ff6feSmrg char *req_type; 138876ff6feSmrg req_type = (data->u.req.reqType == XETrapGetExtOpcode(tc) ? "XTrap" : 139876ff6feSmrg XERequestIDToString(data->u.req.reqType,tc)); 140876ff6feSmrg fprintf(ofp,"Request: %-19s (%d): length '%ld' client '%d' window=%ld\n", 141876ff6feSmrg req_type, data->u.req.reqType, (long)data->hdr.count, data->hdr.client, 142876ff6feSmrg (long)data->u.req.id); 143876ff6feSmrg} 144876ff6feSmrg 145876ff6feSmrgstatic void print_evt_callback(XETC *tc, XETrapDatum *data, char *my_buf) 146876ff6feSmrg{ 147876ff6feSmrg static Time last_time = 0; 148876ff6feSmrg int delta; 149876ff6feSmrg 150876ff6feSmrg delta = abs((int)last_time ? data->u.event.u.keyButtonPointer.time - 151876ff6feSmrg (int)last_time : (int)last_time); 152876ff6feSmrg last_time = data->u.event.u.keyButtonPointer.time; 153876ff6feSmrg 154876ff6feSmrg /* The "screen" and "root" fields aren't valid until "event" 155876ff6feSmrg * vectoring becomes a reality. Currently, XTrap intercepts 156876ff6feSmrg * the core events prior to when fields other than rootX, rootY, 157876ff6feSmrg * type, detail, time, and state are filled in. This will be 158876ff6feSmrg * addressed in the next release of XTrap (3.2?). 159876ff6feSmrg */ 160876ff6feSmrg fprintf(ofp, 161876ff6feSmrg "Event: %-15s (%d):det=%d scr=%d (%d,%d) root=%d Msk=%d TS=%d\n", 162876ff6feSmrg XEEventIDToString(data->u.event.u.u.type,tc), data->u.event.u.u.type, 163876ff6feSmrg data->u.event.u.u.detail, data->hdr.screen, /* Not really valid yet */ 164876ff6feSmrg data->u.event.u.keyButtonPointer.rootX, 165876ff6feSmrg data->u.event.u.keyButtonPointer.rootY, 166876ff6feSmrg (int)data->u.event.u.keyButtonPointer.root, /* Not really valid yet */ 167876ff6feSmrg (int)data->u.event.u.keyButtonPointer.state, 168876ff6feSmrg (int)delta); 169876ff6feSmrg fflush(ofp); 170876ff6feSmrg} 171876ff6feSmrgstatic Boolean eventFlag = False; 172876ff6feSmrgstatic Boolean verboseFlag = False; 173876ff6feSmrgstatic Widget appW; 174876ff6feSmrgstatic Display *dpy; 175876ff6feSmrg 176876ff6feSmrgint 177876ff6feSmrgmain(int argc, char *argv[]) 178876ff6feSmrg{ 179876ff6feSmrg XETrapGetAvailRep ret_avail; 180876ff6feSmrg XETrapGetCurRep ret_cur; 181876ff6feSmrg XETC *tc; 182876ff6feSmrg ReqFlags requests; 183876ff6feSmrg EventFlags events; 184876ff6feSmrg XtAppContext app; 185876ff6feSmrg char *tmp = NULL; 186876ff6feSmrg INT16 ch; 187876ff6feSmrg int *popterr; 188876ff6feSmrg char **poptarg; 189876ff6feSmrg#ifndef vms 190876ff6feSmrg popterr = &opterr; 191876ff6feSmrg poptarg = &optarg; 192876ff6feSmrg#else 193876ff6feSmrg popterr = XEgetopterr(); 194876ff6feSmrg poptarg = XEgetoptarg(); 195876ff6feSmrg#endif 196876ff6feSmrg 197876ff6feSmrg eventFlag = False; 198876ff6feSmrg ofp = NULL; 199876ff6feSmrg *popterr = 0; /* don't complain about -d (display) */ 200876ff6feSmrg while ((ch = getopt(argc, argv, "d:evf:")) != EOF) 201876ff6feSmrg { 202876ff6feSmrg switch(ch) 203876ff6feSmrg { 204876ff6feSmrg case 'e': 205876ff6feSmrg eventFlag = True; 206876ff6feSmrg break; 207876ff6feSmrg case 'v': 208876ff6feSmrg verboseFlag = True; 209876ff6feSmrg break; 210876ff6feSmrg case 'f': 211876ff6feSmrg if ((ofp = fopen(*poptarg,"wb")) == NULL) 212876ff6feSmrg { /* can't open it */ 213876ff6feSmrg fprintf(stderr,"%s: could not open output file '%s'!\n", 214876ff6feSmrg ProgName, *poptarg); 215876ff6feSmrg } 216876ff6feSmrg break; 217876ff6feSmrg case 'd': /* -display, let's let the toolkit parse it */ 218876ff6feSmrg break; 219876ff6feSmrg default: 220876ff6feSmrg break; 221876ff6feSmrg } 222876ff6feSmrg } 223876ff6feSmrg ofp = (ofp ? ofp : stdout); 224876ff6feSmrg 225876ff6feSmrg appW = XtAppInitialize(&app,"XTrap",optionTable,(Cardinal)2L, 226876ff6feSmrg (int *)&argc, (String *)argv, (String *)NULL,(ArgList)&tmp, 227876ff6feSmrg (Cardinal)NULL); 228876ff6feSmrg 229876ff6feSmrg dpy = XtDisplay(appW); 230876ff6feSmrg#ifdef DEBUG 231876ff6feSmrg XSynchronize(dpy, True); 232876ff6feSmrg#endif 233876ff6feSmrg fprintf(stderr,"Display: %s \n", DisplayString(dpy)); 234876ff6feSmrg if ((tc = XECreateTC(dpy,0L, NULL)) == False) 235876ff6feSmrg { 236876ff6feSmrg fprintf(stderr,"%s: could not initialize XTrap extension\n",ProgName); 237876ff6feSmrg exit (1L); 238876ff6feSmrg } 239876ff6feSmrg XETrapSetTimestamps(tc,True, False); 240876ff6feSmrg (void)XEGetAvailableRequest(tc,&ret_avail); 241876ff6feSmrg XEPrintAvail(stderr,&ret_avail); 242876ff6feSmrg XEPrintTkFlags(stderr,tc); 243876ff6feSmrg 244876ff6feSmrg /* Need to prime events/requests initially turning all off */ 245876ff6feSmrg (void)memset(requests,0L,sizeof(requests)); 246876ff6feSmrg (void)memset(events,0L,sizeof(events)); 247876ff6feSmrg /* Now turn on the ones you really want */ 248876ff6feSmrg (void)memset(events,0xFFL,XETrapMaxEvent); 249876ff6feSmrg if (eventFlag == False) 250876ff6feSmrg { /* doesn't want just events */ 251876ff6feSmrg (void)memset(requests,0xFFL,XETrapMaxRequest); 252876ff6feSmrg /* Turn off XTrap Requests for multi-client regression tests & XLib */ 253876ff6feSmrg BitFalse(requests, XETrapGetExtOpcode(tc)); 254876ff6feSmrg /* Turn off noisy events */ 255876ff6feSmrg BitFalse(events, MotionNotify); 256876ff6feSmrg } 257876ff6feSmrg if (verboseFlag == True) 258876ff6feSmrg { /* want's *all* requests/events */ 259876ff6feSmrg (void)memset(requests,0xFFL,XETrapMaxRequest); 260876ff6feSmrg (void)memset(events,0xFFL,XETrapMaxEvent); 261876ff6feSmrg } 262876ff6feSmrg /* Tell the TC about it */ 263876ff6feSmrg XETrapSetRequests(tc, True, requests); 264876ff6feSmrg XETrapSetEvents(tc, True, events); 265876ff6feSmrg XETrapSetMaxPacket(tc, True, XETrapMinPktSize); /* just get the minimum */ 266876ff6feSmrg 267876ff6feSmrg /* Set up callbacks for data */ 268876ff6feSmrg XEAddRequestCBs(tc, requests, print_req_callback, NULL); 269876ff6feSmrg XEAddEventCBs(tc, events, print_evt_callback, NULL); 270876ff6feSmrg 271876ff6feSmrg (void)XEStartTrapRequest(tc); 272876ff6feSmrg (void)XEGetCurrentRequest(tc,&ret_cur); 273876ff6feSmrg XEPrintCurrent(stderr,&ret_cur); 274876ff6feSmrg 275876ff6feSmrg /* Add signal handlers so that we clean up properly */ 276876ff6feSmrg _InitExceptionHandling((void_function)SetGlobalDone); 277876ff6feSmrg (void)XEEnableCtrlKeys((void_function)SetGlobalDone); 278876ff6feSmrg 279876ff6feSmrg XETrapAppWhileLoop(app,tc,&GlobalDone); 280876ff6feSmrg 281876ff6feSmrg /* Make sure <CTRL> key is released */ 282876ff6feSmrg XESimulateXEventRequest(tc, KeyRelease, 283876ff6feSmrg XKeysymToKeycode(dpy, XK_Control_L), 0L, 0L, 0L); 284876ff6feSmrg 285876ff6feSmrg /* close down everything nicely */ 286876ff6feSmrg XEFreeTC(tc); 287876ff6feSmrg (void)XCloseDisplay(dpy); 288876ff6feSmrg (void)XEClearCtrlKeys(); 289876ff6feSmrg _ClearExceptionHandling(); 290876ff6feSmrg exit(0L); 291876ff6feSmrg} 292876ff6feSmrg 293