diff options
Diffstat (limited to 'unix/tkUnixSend.c')
-rw-r--r-- | unix/tkUnixSend.c | 188 |
1 files changed, 95 insertions, 93 deletions
diff --git a/unix/tkUnixSend.c b/unix/tkUnixSend.c index 3fb745e..53a2196 100644 --- a/unix/tkUnixSend.c +++ b/unix/tkUnixSend.c @@ -77,7 +77,7 @@ typedef struct NameRegistry { typedef struct PendingCommand { int serial; /* Serial number expected in result. */ TkDisplay *dispPtr; /* Display being used for communication. */ - CONST char *target; /* Name of interpreter command is being sent + const char *target; /* Name of interpreter command is being sent * to. */ Window commWindow; /* Target's communication window. */ Tcl_Interp *interp; /* Interpreter from which the send was @@ -210,19 +210,18 @@ static void AppendPropCarefully(Display *display, int length, PendingCommand *pendingPtr); static void DeleteProc(ClientData clientData); static void RegAddName(NameRegistry *regPtr, - CONST char *name, Window commWindow); + const char *name, Window commWindow); static void RegClose(NameRegistry *regPtr); -static void RegDeleteName(NameRegistry *regPtr, CONST char *name); -static Window RegFindName(NameRegistry *regPtr, CONST char *name); +static void RegDeleteName(NameRegistry *regPtr, const char *name); +static Window RegFindName(NameRegistry *regPtr, const char *name); static NameRegistry * RegOpen(Tcl_Interp *interp, TkDisplay *dispPtr, int lock); static void SendEventProc(ClientData clientData, XEvent *eventPtr); static int SendInit(Tcl_Interp *interp, TkDisplay *dispPtr); -static Tk_RestrictAction SendRestrictProc(ClientData clientData, - XEvent *eventPtr); +static Tk_RestrictProc SendRestrictProc; static int ServerSecure(TkDisplay *dispPtr); static void UpdateCommWindow(TkDisplay *dispPtr); -static int ValidateName(TkDisplay *dispPtr, CONST char *name, +static int ValidateName(TkDisplay *dispPtr, const char *name, Window commWindow, int oldOK); /* @@ -267,7 +266,7 @@ RegOpen( SendInit(interp, dispPtr); } - regPtr = (NameRegistry *) ckalloc(sizeof(NameRegistry)); + regPtr = ckalloc(sizeof(NameRegistry)); regPtr->dispPtr = dispPtr; regPtr->locked = 0; regPtr->modified = 0; @@ -347,7 +346,7 @@ static Window RegFindName( NameRegistry *regPtr, /* Pointer to a registry opened with a * previous call to RegOpen. */ - CONST char *name) /* Name of an application. */ + const char *name) /* Name of an application. */ { char *p; @@ -358,7 +357,7 @@ RegFindName( p++; } if ((*p != 0) && (strcmp(name, p+1) == 0)) { - unsigned int id; + unsigned id; if (sscanf(entry, "%x", &id) == 1) { /* @@ -400,7 +399,7 @@ static void RegDeleteName( NameRegistry *regPtr, /* Pointer to a registry opened with a * previous call to RegOpen. */ - CONST char *name) /* Name of an application. */ + const char *name) /* Name of an application. */ { char *p; @@ -462,7 +461,7 @@ static void RegAddName( NameRegistry *regPtr, /* Pointer to a registry opened with a * previous call to RegOpen. */ - CONST char *name, /* Name of an application. The caller must + const char *name, /* Name of an application. The caller must * ensure that this name isn't already * registered. */ Window commWindow) /* X identifier for comm. window of @@ -471,10 +470,10 @@ RegAddName( char id[30], *newProp; int idLength, newBytes; - sprintf(id, "%x ", (unsigned int) commWindow); + sprintf(id, "%x ", (unsigned) commWindow); idLength = strlen(id); newBytes = idLength + strlen(name) + 1; - newProp = ckalloc((unsigned) (regPtr->propLength + newBytes)); + newProp = ckalloc(regPtr->propLength + newBytes); strcpy(newProp, id); strcpy(newProp+idLength, name); if (regPtr->property != NULL) { @@ -548,7 +547,7 @@ RegClose( ckfree(regPtr->property); } } - ckfree((char *) regPtr); + ckfree(regPtr); } /* @@ -573,7 +572,7 @@ static int ValidateName( TkDisplay *dispPtr, /* Display for which to perform the * validation. */ - CONST char *name, /* The name of an application. */ + const char *name, /* The name of an application. */ Window commWindow, /* X identifier for the application's comm. * window. */ int oldOK) /* Non-zero means that we should consider an @@ -586,7 +585,7 @@ ValidateName( Atom actualType; char *property, **propertyPtr = &property; Tk_ErrorHandler handler; - CONST char **argv; + const char **argv; property = NULL; @@ -634,7 +633,7 @@ ValidateName( break; } } - ckfree((char *) argv); + ckfree(argv); } } else { result = 0; @@ -743,7 +742,7 @@ ServerSecure( * the side of safety. */ - goto insecure; + secure = 0; #endif /* FamilyServerInterpreted */ } if (addrPtr != NULL) { @@ -754,7 +753,7 @@ ServerSecure( } /* - *-------------------------------------------------------------- + *---------------------------------------------------------------------- * * Tk_SetAppName -- * @@ -775,15 +774,15 @@ ServerSecure( * registration will be removed automatically if the interpreter is * deleted or the "send" command is removed. * - *-------------------------------------------------------------- + *---------------------------------------------------------------------- */ -CONST char * +const char * Tk_SetAppName( Tk_Window tkwin, /* Token for any window in the application to * be named: it is just used to identify the * application and the display. */ - CONST char *name) /* The name that will be used to refer to the + const char *name) /* The name that will be used to refer to the * interpreter in later "send" commands. Must * be globally unique. */ { @@ -793,10 +792,10 @@ Tk_SetAppName( TkDisplay *dispPtr = winPtr->dispPtr; NameRegistry *regPtr; Tcl_Interp *interp; - CONST char *actualName; + const char *actualName; Tcl_DString dString; int offset, i; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); interp = winPtr->mainPtr->interp; @@ -818,14 +817,13 @@ Tk_SetAppName( * the "send" command to the interpreter. */ - riPtr = (RegisteredInterp *) ckalloc(sizeof(RegisteredInterp)); + riPtr = ckalloc(sizeof(RegisteredInterp)); riPtr->interp = interp; riPtr->dispPtr = winPtr->dispPtr; riPtr->nextPtr = tsdPtr->interpListPtr; tsdPtr->interpListPtr = riPtr; riPtr->name = NULL; - Tcl_CreateCommand(interp, "send", Tk_SendCmd, (ClientData) riPtr, - DeleteProc); + Tcl_CreateCommand(interp, "send", Tk_SendCmd, riPtr, DeleteProc); if (Tcl_IsSafe(interp)) { Tcl_HideCommand(interp, "send", "send"); } @@ -903,7 +901,7 @@ Tk_SetAppName( RegAddName(regPtr, actualName, Tk_WindowId(dispPtr->commTkwin)); RegClose(regPtr); - riPtr->name = (char *) ckalloc((unsigned) (strlen(actualName) + 1)); + riPtr->name = ckalloc(strlen(actualName) + 1); strcpy(riPtr->name, actualName); if (actualName != name) { Tcl_DStringFree(&dString); @@ -936,22 +934,22 @@ Tk_SendCmd( * field is used). */ Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ - CONST char **argv) /* Argument strings. */ + const char **argv) /* Argument strings. */ { TkWindow *winPtr; Window commWindow; PendingCommand pending; register RegisteredInterp *riPtr; - CONST char *destName; + const char *destName; int result, c, async, i, firstArg; size_t length; - Tk_RestrictProc *prevRestrictProc; + Tk_RestrictProc *prevProc; ClientData prevArg; TkDisplay *dispPtr; Tcl_Time timeout; NameRegistry *regPtr; Tcl_DString request; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); Tcl_Interp *localInterp; /* Used when the interpreter to send the * command to is within the same process. */ @@ -986,15 +984,19 @@ Tk_SendCmd( i++; break; } else { - Tcl_AppendResult(interp, "bad option \"", argv[i], - "\": must be -async, -displayof, or --", NULL); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "bad option \"%s\": must be -async, -displayof, or --", + argv[i])); + Tcl_SetErrorCode(interp, "TK", "SEND", "OPTION", NULL); return TCL_ERROR; } } if (argc < (i+2)) { - Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], - " ?options? interpName arg ?arg ...?\"", NULL); + Tcl_SetObjResult(interp, Tcl_ObjPrintf("wrong # args: should be " + "\"%s ?-option value ...? interpName arg ?arg ...?\"", + argv[0])); + Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", NULL); return TCL_ERROR; } destName = argv[i]; @@ -1018,9 +1020,9 @@ Tk_SendCmd( || (strcmp(riPtr->name, destName) != 0)) { continue; } - Tcl_Preserve((ClientData) riPtr); + Tcl_Preserve(riPtr); localInterp = riPtr->interp; - Tcl_Preserve((ClientData) localInterp); + Tcl_Preserve(localInterp); if (firstArg == (argc-1)) { result = Tcl_EvalEx(localInterp, argv[firstArg], -1, TCL_EVAL_GLOBAL); } else { @@ -1056,8 +1058,8 @@ Tk_SendCmd( Tcl_SetObjResult(interp, Tcl_GetObjResult(localInterp)); Tcl_ResetResult(localInterp); } - Tcl_Release((ClientData) riPtr); - Tcl_Release((ClientData) localInterp); + Tcl_Release(riPtr); + Tcl_Release(localInterp); return result; } @@ -1069,7 +1071,10 @@ Tk_SendCmd( commWindow = RegFindName(regPtr, destName); RegClose(regPtr); if (commWindow == None) { - Tcl_AppendResult(interp, "no application named \"",destName,"\"",NULL); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "no application named \"%s\"", destName)); + Tcl_SetErrorCode(interp, "TK", "LOOKUP", "APPLICATION", destName, + NULL); return TCL_ERROR; } @@ -1086,7 +1091,7 @@ Tk_SendCmd( char buffer[TCL_INTEGER_SPACE * 2]; sprintf(buffer, "%x %d", - (unsigned int) Tk_WindowId(dispPtr->commTkwin), + (unsigned) Tk_WindowId(dispPtr->commTkwin), localData.sendSerial); Tcl_DStringAppend(&request, "\0-r ", 4); Tcl_DStringAppend(&request, buffer, -1); @@ -1137,7 +1142,7 @@ Tk_SendCmd( * other events in the application. */ - prevRestrictProc = Tk_RestrictEvents(SendRestrictProc, NULL, &prevArg); + prevProc = Tk_RestrictEvents(SendRestrictProc, NULL, &prevArg); Tcl_GetTime(&timeout); timeout.sec += 2; while (!pending.gotResponse) { @@ -1150,7 +1155,7 @@ Tk_SendCmd( if (!ValidateName(pending.dispPtr, pending.target, pending.commWindow, 0)) { - char *msg; + const char *msg; if (ValidateName(pending.dispPtr, pending.target, pending.commWindow, 1)) { @@ -1159,7 +1164,7 @@ Tk_SendCmd( msg = "target application died"; } pending.code = TCL_ERROR; - pending.result = (char *) ckalloc((unsigned) (strlen(msg) + 1)); + pending.result = ckalloc(strlen(msg) + 1); strcpy(pending.result, msg); pending.gotResponse = 1; } else { @@ -1168,7 +1173,7 @@ Tk_SendCmd( } } } - (void) Tk_RestrictEvents(prevRestrictProc, prevArg, &prevArg); + Tk_RestrictEvents(prevProc, prevArg, &prevArg); /* * Unregister the information about the pending command and return the @@ -1192,12 +1197,11 @@ Tk_SendCmd( ckfree(pending.errorInfo); } if (pending.errorCode != NULL) { - Tcl_Obj *errorObjPtr = Tcl_NewStringObj(pending.errorCode, -1); - - Tcl_SetObjErrorCode(interp, errorObjPtr); + Tcl_SetObjErrorCode(interp, Tcl_NewStringObj(pending.errorCode, -1)); ckfree(pending.errorCode); } - Tcl_SetResult(interp, pending.result, TCL_DYNAMIC); + Tcl_SetObjResult(interp, Tcl_NewStringObj(pending.result, -1)); + ckfree(pending.result); return pending.code; } @@ -1229,6 +1233,7 @@ TkGetInterpNames( { TkWindow *winPtr = (TkWindow *) tkwin; NameRegistry *regPtr; + Tcl_Obj *resultObj = Tcl_NewObj(); char *p; /* @@ -1240,9 +1245,9 @@ TkGetInterpNames( for (p=regPtr->property ; p-regPtr->property<(int)regPtr->propLength ;) { char *entry = p, *entryName; Window commWindow; - unsigned int id; + unsigned id; - if (sscanf(p, "%x",(unsigned int *) &id) != 1) { + if (sscanf(p, "%x", (unsigned *) &id) != 1) { commWindow = None; } else { commWindow = id; @@ -1263,7 +1268,8 @@ TkGetInterpNames( * The application still exists; add its name to the result. */ - Tcl_AppendElement(interp, entryName); + Tcl_ListObjAppendElement(NULL, resultObj, + Tcl_NewStringObj(entryName, -1)); } else { int count; @@ -1286,6 +1292,7 @@ TkGetInterpNames( } } RegClose(regPtr); + Tcl_SetObjResult(interp, resultObj); return TCL_OK; } @@ -1312,9 +1319,9 @@ TkSendCleanup( { if (dispPtr->commTkwin != NULL) { Tk_DeleteEventHandler(dispPtr->commTkwin, PropertyChangeMask, - SendEventProc, (ClientData) dispPtr); + SendEventProc, dispPtr); Tk_DestroyWindow(dispPtr->commTkwin); - Tcl_Release((ClientData) dispPtr->commTkwin); + Tcl_Release(dispPtr->commTkwin); dispPtr->commTkwin = NULL; } } @@ -1352,14 +1359,15 @@ SendInit( dispPtr->commTkwin = (Tk_Window) TkAllocWindow(dispPtr, DefaultScreen(dispPtr->display), NULL); - Tcl_Preserve((ClientData) dispPtr->commTkwin); - ((TkWindow *) dispPtr->commTkwin)->flags |=TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED; + Tcl_Preserve(dispPtr->commTkwin); + ((TkWindow *) dispPtr->commTkwin)->flags |= + TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED; TkWmNewWindow((TkWindow *) dispPtr->commTkwin); atts.override_redirect = True; Tk_ChangeWindowAttributes(dispPtr->commTkwin, CWOverrideRedirect, &atts); Tk_CreateEventHandler(dispPtr->commTkwin, PropertyChangeMask, - SendEventProc, (ClientData) dispPtr); + SendEventProc, dispPtr); Tk_MakeWindowExist(dispPtr->commTkwin); /* @@ -1400,14 +1408,14 @@ SendEventProc( ClientData clientData, /* Display information. */ XEvent *eventPtr) /* Information about event. */ { - TkDisplay *dispPtr = (TkDisplay *) clientData; + TkDisplay *dispPtr = clientData; char *propInfo, **propInfoPtr = &propInfo; - register char *p; + const char *p; int result, actualFormat; unsigned long numItems, bytesAfter; Atom actualType; Tcl_Interp *remoteInterp; /* Interp in which to execute the command. */ - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); if ((eventPtr->xproperty.atom != dispPtr->commProperty) @@ -1457,7 +1465,8 @@ SendEventProc( if ((*p == 'c') && (p[1] == 0)) { Window commWindow; - char *interpName, *script, *serial, *end; + const char *interpName, *script, *serial; + char *end; Tcl_DString reply; RegisteredInterp *riPtr; @@ -1546,7 +1555,7 @@ SendEventProc( break; } } - Tcl_Preserve((ClientData) riPtr); + Tcl_Preserve(riPtr); /* * We must protect the interpreter because the script may enter @@ -1554,7 +1563,7 @@ SendEventProc( */ remoteInterp = riPtr->interp; - Tcl_Preserve((ClientData) remoteInterp); + Tcl_Preserve(remoteInterp); result = Tcl_EvalEx(remoteInterp, script, -1, TCL_EVAL_GLOBAL); @@ -1566,10 +1575,10 @@ SendEventProc( */ if (commWindow != None) { - Tcl_DStringAppend(&reply, Tcl_GetStringResult(remoteInterp), + Tcl_DStringAppend(&reply, Tcl_GetString(Tcl_GetObjResult(remoteInterp)), -1); if (result == TCL_ERROR) { - CONST char *varValue; + const char *varValue; varValue = Tcl_GetVar2(remoteInterp, "errorInfo", NULL, TCL_GLOBAL_ONLY); @@ -1585,8 +1594,8 @@ SendEventProc( } } } - Tcl_Release((ClientData) remoteInterp); - Tcl_Release((ClientData) riPtr); + Tcl_Release(remoteInterp); + Tcl_Release(riPtr); /* * Return the result to the sender if a commWindow was specified @@ -1612,7 +1621,7 @@ SendEventProc( } } else if ((*p == 'r') && (p[1] == 0)) { int serial, code, gotSerial; - char *errorInfo, *errorCode, *resultString; + const char *errorInfo, *errorCode, *resultString; PendingCommand *pcPtr; /* @@ -1678,19 +1687,16 @@ SendEventProc( } pcPtr->code = code; if (resultString != NULL) { - pcPtr->result = (char *) ckalloc((unsigned) - (strlen(resultString) + 1)); + pcPtr->result = ckalloc(strlen(resultString) + 1); strcpy(pcPtr->result, resultString); } if (code == TCL_ERROR) { if (errorInfo != NULL) { - pcPtr->errorInfo = (char *) ckalloc((unsigned) - (strlen(errorInfo) + 1)); + pcPtr->errorInfo = ckalloc(strlen(errorInfo) + 1); strcpy(pcPtr->errorInfo, errorInfo); } if (errorCode != NULL) { - pcPtr->errorCode = (char *) ckalloc((unsigned) - (strlen(errorCode) + 1)); + pcPtr->errorCode = ckalloc(strlen(errorCode) + 1); strcpy(pcPtr->errorCode, errorCode); } } @@ -1746,7 +1752,7 @@ AppendPropCarefully( Tk_ErrorHandler handler; handler = Tk_CreateErrorHandler(display, -1, -1, -1, AppendErrorProc, - (ClientData) pendingPtr); + pendingPtr); XChangeProperty(display, window, property, XA_STRING, 8, PropModeAppend, (unsigned char *) value, length); Tk_DeleteErrorHandler(handler); @@ -1763,9 +1769,9 @@ AppendErrorProc( ClientData clientData, /* Command to mark complete, or NULL. */ XErrorEvent *errorPtr) /* Information about error. */ { - PendingCommand *pendingPtr = (PendingCommand *) clientData; + PendingCommand *pendingPtr = clientData; register PendingCommand *pcPtr; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); if (pendingPtr == NULL) { @@ -1779,8 +1785,7 @@ AppendErrorProc( for (pcPtr = tsdPtr->pendingCommands; pcPtr != NULL; pcPtr = pcPtr->nextPtr) { if ((pcPtr == pendingPtr) && (pcPtr->result == NULL)) { - pcPtr->result = (char *) ckalloc((unsigned) - (strlen(pcPtr->target) + 50)); + pcPtr->result = ckalloc(strlen(pcPtr->target) + 50); sprintf(pcPtr->result, "no application named \"%s\"", pcPtr->target); pcPtr->code = TCL_ERROR; @@ -1813,10 +1818,10 @@ DeleteProc( ClientData clientData) /* Info about registration, passed as * ClientData. */ { - RegisteredInterp *riPtr = (RegisteredInterp *) clientData; + RegisteredInterp *riPtr = clientData; register RegisteredInterp *riPtr2; NameRegistry *regPtr; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); regPtr = RegOpen(riPtr->interp, riPtr->dispPtr, 1); @@ -1834,10 +1839,10 @@ DeleteProc( } } } - ckfree((char *) riPtr->name); + ckfree(riPtr->name); riPtr->interp = NULL; UpdateCommWindow(riPtr->dispPtr); - Tcl_EventuallyFree((ClientData) riPtr, TCL_DYNAMIC); + Tcl_EventuallyFree(riPtr, TCL_DYNAMIC); } /* @@ -1905,7 +1910,7 @@ UpdateCommWindow( { Tcl_DString names; RegisteredInterp *riPtr; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); Tcl_DStringInit(&names); @@ -1944,9 +1949,9 @@ TkpTestsendCmd( ClientData clientData, /* Main window for application. */ Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ - CONST char **argv) /* Argument strings. */ + const char **argv) /* Argument strings. */ { - TkWindow *winPtr = (TkWindow *) clientData; + TkWindow *winPtr = clientData; if (argc < 2) { Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0], @@ -1992,7 +1997,7 @@ TkpTestsendCmd( *p = '\n'; } } - Tcl_SetResult(interp, property, TCL_VOLATILE); + Tcl_SetObjResult(interp, Tcl_NewStringObj(property, -1)); } if (property != NULL) { XFree(property); @@ -2016,10 +2021,7 @@ TkpTestsendCmd( Tcl_DStringFree(&tmp); } } else if (strcmp(argv[1], "serial") == 0) { - char buf[TCL_INTEGER_SPACE]; - - sprintf(buf, "%d", localData.sendSerial+1); - Tcl_SetResult(interp, buf, TCL_VOLATILE); + Tcl_SetObjResult(interp, Tcl_NewIntObj(localData.sendSerial+1)); } else { Tcl_AppendResult(interp, "bad option \"", argv[1], "\": must be bogus, prop, or serial", NULL); |