tclXtTest.c

Go to the documentation of this file.
00001 /* 
00002  * tclXtTest.c --
00003  *
00004  *      Contains commands for Xt notifier specific tests on Unix.
00005  *
00006  * Copyright (c) 1997 by Sun Microsystems, Inc.
00007  *
00008  * See the file "license.terms" for information on usage and redistribution of
00009  * this file, and for a DISCLAIMER OF ALL WARRANTIES.
00010  *
00011  * RCS: @(#) $Id: tclXtTest.c,v 1.6 2005/11/02 23:26:50 dkf Exp $
00012  */
00013 
00014 #include <X11/Intrinsic.h>
00015 #include "tcl.h"
00016 
00017 static int      TesteventloopCmd(ClientData clientData,
00018                     Tcl_Interp *interp, int argc, CONST char **argv);
00019 extern void     InitNotifier(void);
00020 
00021 /*
00022  *----------------------------------------------------------------------
00023  *
00024  * Tclxttest_Init --
00025  *
00026  *      This procedure performs application-specific initialization. Most
00027  *      applications, especially those that incorporate additional packages,
00028  *      will have their own version of this procedure.
00029  *
00030  * Results:
00031  *      Returns a standard Tcl completion code, and leaves an error message in
00032  *      the interp's result if an error occurs.
00033  *
00034  * Side effects:
00035  *      Depends on the startup script.
00036  *
00037  *----------------------------------------------------------------------
00038  */
00039 
00040 int
00041 Tclxttest_Init(
00042     Tcl_Interp *interp)         /* Interpreter for application. */
00043 {
00044     if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
00045         return TCL_ERROR;
00046     }
00047     XtToolkitInitialize();
00048     InitNotifier();
00049     Tcl_CreateCommand(interp, "testeventloop", TesteventloopCmd,
00050             (ClientData) 0, NULL);
00051     return TCL_OK;
00052 }
00053 
00054 /*
00055  *----------------------------------------------------------------------
00056  *
00057  * TesteventloopCmd --
00058  *
00059  *      This procedure implements the "testeventloop" command. It is used to
00060  *      test the Tcl notifier from an "external" event loop (i.e. not
00061  *      Tcl_DoOneEvent()).
00062  *
00063  * Results:
00064  *      A standard Tcl result.
00065  *
00066  * Side effects:
00067  *      None.
00068  *
00069  *----------------------------------------------------------------------
00070  */
00071 
00072 static int
00073 TesteventloopCmd(
00074     ClientData clientData,      /* Not used. */
00075     Tcl_Interp *interp,         /* Current interpreter. */
00076     int argc,                   /* Number of arguments. */
00077     CONST char **argv)          /* Argument strings. */
00078 {
00079     static int *framePtr = NULL;/* Pointer to integer on stack frame of
00080                                  * innermost invocation of the "wait"
00081                                  * subcommand. */
00082 
00083    if (argc < 2) {
00084         Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0],
00085                 " option ... \"", NULL);
00086         return TCL_ERROR;
00087     }
00088     if (strcmp(argv[1], "done") == 0) {
00089         *framePtr = 1;
00090     } else if (strcmp(argv[1], "wait") == 0) {
00091         int *oldFramePtr;
00092         int done;
00093         int oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
00094 
00095         /*
00096          * Save the old stack frame pointer and set up the current frame.
00097          */
00098 
00099         oldFramePtr = framePtr;
00100         framePtr = &done;
00101 
00102         /*
00103          * Enter an Xt event loop until the flag changes. Note that we do not
00104          * explicitly call Tcl_ServiceEvent().
00105          */
00106 
00107         done = 0;
00108         while (!done) {
00109             XtAppProcessEvent(TclSetAppContext(NULL), XtIMAll);
00110         }
00111         (void) Tcl_SetServiceMode(oldMode);
00112         framePtr = oldFramePtr;
00113     } else {
00114         Tcl_AppendResult(interp, "bad option \"", argv[1],
00115                 "\": must be done or wait", NULL);
00116         return TCL_ERROR;
00117     }
00118     return TCL_OK;
00119 }



Generated on Wed Mar 12 12:18:27 2008 by  doxygen 1.5.1