sl@0
|
1 |
/*
|
sl@0
|
2 |
* tclXtTest.c --
|
sl@0
|
3 |
*
|
sl@0
|
4 |
* Contains commands for Xt notifier specific tests on Unix.
|
sl@0
|
5 |
*
|
sl@0
|
6 |
* Copyright (c) 1997 by Sun Microsystems, Inc.
|
sl@0
|
7 |
*
|
sl@0
|
8 |
* See the file "license.terms" for information on usage and redistribution
|
sl@0
|
9 |
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
10 |
*
|
sl@0
|
11 |
* RCS: @(#) $Id: tclXtTest.c,v 1.5 2002/08/05 03:24:41 dgp Exp $
|
sl@0
|
12 |
*/
|
sl@0
|
13 |
|
sl@0
|
14 |
#include <X11/Intrinsic.h>
|
sl@0
|
15 |
#include "tcl.h"
|
sl@0
|
16 |
|
sl@0
|
17 |
static int TesteventloopCmd _ANSI_ARGS_((ClientData clientData,
|
sl@0
|
18 |
Tcl_Interp *interp, int argc, CONST char **argv));
|
sl@0
|
19 |
extern void InitNotifier _ANSI_ARGS_((void));
|
sl@0
|
20 |
|
sl@0
|
21 |
|
sl@0
|
22 |
/*
|
sl@0
|
23 |
*----------------------------------------------------------------------
|
sl@0
|
24 |
*
|
sl@0
|
25 |
* Tclxttest_Init --
|
sl@0
|
26 |
*
|
sl@0
|
27 |
* This procedure performs application-specific initialization.
|
sl@0
|
28 |
* Most applications, especially those that incorporate additional
|
sl@0
|
29 |
* packages, will have their own version of this procedure.
|
sl@0
|
30 |
*
|
sl@0
|
31 |
* Results:
|
sl@0
|
32 |
* Returns a standard Tcl completion code, and leaves an error
|
sl@0
|
33 |
* message in the interp's result if an error occurs.
|
sl@0
|
34 |
*
|
sl@0
|
35 |
* Side effects:
|
sl@0
|
36 |
* Depends on the startup script.
|
sl@0
|
37 |
*
|
sl@0
|
38 |
*----------------------------------------------------------------------
|
sl@0
|
39 |
*/
|
sl@0
|
40 |
|
sl@0
|
41 |
int
|
sl@0
|
42 |
Tclxttest_Init(interp)
|
sl@0
|
43 |
Tcl_Interp *interp; /* Interpreter for application. */
|
sl@0
|
44 |
{
|
sl@0
|
45 |
if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
|
sl@0
|
46 |
return TCL_ERROR;
|
sl@0
|
47 |
}
|
sl@0
|
48 |
XtToolkitInitialize();
|
sl@0
|
49 |
InitNotifier();
|
sl@0
|
50 |
Tcl_CreateCommand(interp, "testeventloop", TesteventloopCmd,
|
sl@0
|
51 |
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
sl@0
|
52 |
return TCL_OK;
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
/*
|
sl@0
|
56 |
*----------------------------------------------------------------------
|
sl@0
|
57 |
*
|
sl@0
|
58 |
* TesteventloopCmd --
|
sl@0
|
59 |
*
|
sl@0
|
60 |
* This procedure implements the "testeventloop" command. It is
|
sl@0
|
61 |
* used to test the Tcl notifier from an "external" event loop
|
sl@0
|
62 |
* (i.e. not Tcl_DoOneEvent()).
|
sl@0
|
63 |
*
|
sl@0
|
64 |
* Results:
|
sl@0
|
65 |
* A standard Tcl result.
|
sl@0
|
66 |
*
|
sl@0
|
67 |
* Side effects:
|
sl@0
|
68 |
* None.
|
sl@0
|
69 |
*
|
sl@0
|
70 |
*----------------------------------------------------------------------
|
sl@0
|
71 |
*/
|
sl@0
|
72 |
|
sl@0
|
73 |
static int
|
sl@0
|
74 |
TesteventloopCmd(clientData, interp, argc, argv)
|
sl@0
|
75 |
ClientData clientData; /* Not used. */
|
sl@0
|
76 |
Tcl_Interp *interp; /* Current interpreter. */
|
sl@0
|
77 |
int argc; /* Number of arguments. */
|
sl@0
|
78 |
CONST char **argv; /* Argument strings. */
|
sl@0
|
79 |
{
|
sl@0
|
80 |
static int *framePtr = NULL; /* Pointer to integer on stack frame of
|
sl@0
|
81 |
* innermost invocation of the "wait"
|
sl@0
|
82 |
* subcommand. */
|
sl@0
|
83 |
|
sl@0
|
84 |
if (argc < 2) {
|
sl@0
|
85 |
Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0],
|
sl@0
|
86 |
" option ... \"", (char *) NULL);
|
sl@0
|
87 |
return TCL_ERROR;
|
sl@0
|
88 |
}
|
sl@0
|
89 |
if (strcmp(argv[1], "done") == 0) {
|
sl@0
|
90 |
*framePtr = 1;
|
sl@0
|
91 |
} else if (strcmp(argv[1], "wait") == 0) {
|
sl@0
|
92 |
int *oldFramePtr;
|
sl@0
|
93 |
int done;
|
sl@0
|
94 |
int oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
|
sl@0
|
95 |
|
sl@0
|
96 |
/*
|
sl@0
|
97 |
* Save the old stack frame pointer and set up the current frame.
|
sl@0
|
98 |
*/
|
sl@0
|
99 |
|
sl@0
|
100 |
oldFramePtr = framePtr;
|
sl@0
|
101 |
framePtr = &done;
|
sl@0
|
102 |
|
sl@0
|
103 |
/*
|
sl@0
|
104 |
* Enter an Xt event loop until the flag changes.
|
sl@0
|
105 |
* Note that we do not explicitly call Tcl_ServiceEvent().
|
sl@0
|
106 |
*/
|
sl@0
|
107 |
|
sl@0
|
108 |
done = 0;
|
sl@0
|
109 |
while (!done) {
|
sl@0
|
110 |
XtAppProcessEvent(TclSetAppContext(NULL), XtIMAll);
|
sl@0
|
111 |
}
|
sl@0
|
112 |
(void) Tcl_SetServiceMode(oldMode);
|
sl@0
|
113 |
framePtr = oldFramePtr;
|
sl@0
|
114 |
} else {
|
sl@0
|
115 |
Tcl_AppendResult(interp, "bad option \"", argv[1],
|
sl@0
|
116 |
"\": must be done or wait", (char *) NULL);
|
sl@0
|
117 |
return TCL_ERROR;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
return TCL_OK;
|
sl@0
|
120 |
}
|