summaryrefslogtreecommitdiffstats
path: root/unix/tkUnixSend.c
diff options
context:
space:
mode:
Diffstat (limited to 'unix/tkUnixSend.c')
-rw-r--r--unix/tkUnixSend.c292
1 files changed, 147 insertions, 145 deletions
diff --git a/unix/tkUnixSend.c b/unix/tkUnixSend.c
index 3fb745e..bbbdd77 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_CreateObjCommand(interp, "send", Tk_SendObjCmd, 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);
@@ -916,7 +914,7 @@ Tk_SetAppName(
/*
*--------------------------------------------------------------
*
- * Tk_SendCmd --
+ * Tk_SendObjCmd --
*
* This function is invoked to process the "send" Tcl command. See the
* user documentation for details on what it does.
@@ -931,27 +929,32 @@ Tk_SetAppName(
*/
int
-Tk_SendCmd(
+Tk_SendObjCmd(
ClientData clientData, /* Information about sender (only dispPtr
* field is used). */
Tcl_Interp *interp, /* Current interpreter. */
- int argc, /* Number of arguments. */
- CONST char **argv) /* Argument strings. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *const objv[]) /* Argument strings. */
{
+ enum {
+ SEND_ASYNC, SEND_DISPLAYOF, SEND_LAST
+ };
+ static const char *const sendOptions[] = {
+ "-async", "-displayof", "--", NULL
+ };
TkWindow *winPtr;
Window commWindow;
PendingCommand pending;
register RegisteredInterp *riPtr;
- CONST char *destName;
- int result, c, async, i, firstArg;
- size_t length;
- Tk_RestrictProc *prevRestrictProc;
+ const char *destName;
+ int result, index, async, i, firstArg;
+ 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. */
@@ -965,39 +968,31 @@ Tk_SendCmd(
if (winPtr == NULL) {
return TCL_ERROR;
}
- for (i = 1; i < (argc-1); ) {
- if (argv[i][0] != '-') {
+ for (i = 1; i < objc; i++) {
+ if (Tcl_GetIndexFromObjStruct(interp, objv[i], sendOptions,
+ sizeof(char *), "option", 0, &index) != TCL_OK) {
break;
}
- c = argv[i][1];
- length = strlen(argv[i]);
- if ((c == 'a') && (strncmp(argv[i], "-async", length) == 0)) {
- async = 1;
- i++;
- } else if ((c == 'd') && (strncmp(argv[i], "-displayof",
- length) == 0)) {
- winPtr = (TkWindow *) Tk_NameToWindow(interp, argv[i+1],
+ if (index == SEND_ASYNC) {
+ ++async;
+ } else if (index == SEND_DISPLAYOF) {
+ winPtr = (TkWindow *) Tk_NameToWindow(interp, Tcl_GetString(objv[++i]),
(Tk_Window) winPtr);
if (winPtr == NULL) {
return TCL_ERROR;
}
- i += 2;
- } else if (strcmp(argv[i], "--") == 0) {
+ } else if (index == SEND_LAST) {
i++;
break;
- } else {
- Tcl_AppendResult(interp, "bad option \"", argv[i],
- "\": must be -async, -displayof, or --", NULL);
- return TCL_ERROR;
}
}
- if (argc < (i+2)) {
- Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
- " ?options? interpName arg ?arg ...?\"", NULL);
+ if (objc < (i+2)) {
+ Tcl_WrongNumArgs(interp, 1, objv,
+ "?-option value ...? interpName arg ?arg ...?");
return TCL_ERROR;
}
- destName = argv[i];
+ destName = Tcl_GetString(objv[i]);
firstArg = i+1;
dispPtr = winPtr->dispPtr;
@@ -1018,17 +1013,17 @@ Tk_SendCmd(
|| (strcmp(riPtr->name, destName) != 0)) {
continue;
}
- Tcl_Preserve((ClientData) riPtr);
+ Tcl_Preserve(riPtr);
localInterp = riPtr->interp;
- Tcl_Preserve((ClientData) localInterp);
- if (firstArg == (argc-1)) {
- result = Tcl_EvalEx(localInterp, argv[firstArg], -1, TCL_EVAL_GLOBAL);
+ Tcl_Preserve(localInterp);
+ if (firstArg == (objc-1)) {
+ result = Tcl_EvalEx(localInterp, Tcl_GetString(objv[firstArg]), -1, TCL_EVAL_GLOBAL);
} else {
Tcl_DStringInit(&request);
- Tcl_DStringAppend(&request, argv[firstArg], -1);
- for (i = firstArg+1; i < argc; i++) {
+ Tcl_DStringAppend(&request, Tcl_GetString(objv[firstArg]), -1);
+ for (i = firstArg+1; i < objc; i++) {
Tcl_DStringAppend(&request, " ", 1);
- Tcl_DStringAppend(&request, argv[i], -1);
+ Tcl_DStringAppend(&request, Tcl_GetString(objv[i]), -1);
}
result = Tcl_EvalEx(localInterp, Tcl_DStringValue(&request), -1, TCL_EVAL_GLOBAL);
Tcl_DStringFree(&request);
@@ -1056,8 +1051,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 +1064,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,16 +1084,16 @@ 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);
}
Tcl_DStringAppend(&request, "\0-s ", 4);
- Tcl_DStringAppend(&request, argv[firstArg], -1);
- for (i = firstArg+1; i < argc; i++) {
+ Tcl_DStringAppend(&request, Tcl_GetString(objv[firstArg]), -1);
+ for (i = firstArg+1; i < objc; i++) {
Tcl_DStringAppend(&request, " ", 1);
- Tcl_DStringAppend(&request, argv[i], -1);
+ Tcl_DStringAppend(&request, Tcl_GetString(objv[i]), -1);
}
(void) AppendPropCarefully(dispPtr->display, commWindow,
dispPtr->commProperty, Tcl_DStringValue(&request),
@@ -1137,7 +1135,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 +1148,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 +1157,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 +1166,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 +1190,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 +1226,7 @@ TkGetInterpNames(
{
TkWindow *winPtr = (TkWindow *) tkwin;
NameRegistry *regPtr;
+ Tcl_Obj *resultObj = Tcl_NewObj();
char *p;
/*
@@ -1240,9 +1238,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 +1261,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 +1285,7 @@ TkGetInterpNames(
}
}
RegClose(regPtr);
+ Tcl_SetObjResult(interp, resultObj);
return TCL_OK;
}
@@ -1312,9 +1312,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 +1352,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 +1401,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 +1458,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 +1548,7 @@ SendEventProc(
break;
}
}
- Tcl_Preserve((ClientData) riPtr);
+ Tcl_Preserve(riPtr);
/*
* We must protect the interpreter because the script may enter
@@ -1554,7 +1556,7 @@ SendEventProc(
*/
remoteInterp = riPtr->interp;
- Tcl_Preserve((ClientData) remoteInterp);
+ Tcl_Preserve(remoteInterp);
result = Tcl_EvalEx(remoteInterp, script, -1, TCL_EVAL_GLOBAL);
@@ -1566,10 +1568,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 +1587,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 +1614,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 +1680,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 +1745,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 +1762,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 +1778,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 +1811,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 +1832,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 +1903,7 @@ UpdateCommWindow(
{
Tcl_DString names;
RegisteredInterp *riPtr;
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ ThreadSpecificData *tsdPtr =
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
Tcl_DStringInit(&names);
@@ -1943,44 +1941,55 @@ int
TkpTestsendCmd(
ClientData clientData, /* Main window for application. */
Tcl_Interp *interp, /* Current interpreter. */
- int argc, /* Number of arguments. */
- CONST char **argv) /* Argument strings. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *const objv[]) /* Argument strings. */
{
- TkWindow *winPtr = (TkWindow *) clientData;
-
- if (argc < 2) {
- Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0],
- " option ?arg ...?\"", NULL);
+ enum {
+ TESTSEND_BOGUS, TESTSEND_PROP, TESTSEND_SERIAL
+ };
+ static const char *const testsendOptions[] = {
+ "bogus", "prop", "serial", NULL
+ };
+ TkWindow *winPtr = clientData;
+ int index;
+
+ if (objc < 2) {
+ Tcl_WrongNumArgs(interp, 1, objv,
+ "option ?arg ...?");
return TCL_ERROR;
}
- if (strcmp(argv[1], "bogus") == 0) {
+ if (Tcl_GetIndexFromObjStruct(interp, objv[1], testsendOptions,
+ sizeof(char *), "option", 0, &index) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (index == TESTSEND_BOGUS) {
XChangeProperty(winPtr->dispPtr->display,
RootWindow(winPtr->dispPtr->display, 0),
winPtr->dispPtr->registryProperty, XA_INTEGER, 32,
PropModeReplace,
(unsigned char *) "This is bogus information", 6);
- } else if (strcmp(argv[1], "prop") == 0) {
+ } else if (index == TESTSEND_PROP) {
int result, actualFormat;
unsigned long length, bytesAfter;
Atom actualType, propName;
char *property, **propertyPtr = &property, *p, *end;
Window w;
- if ((argc != 4) && (argc != 5)) {
- Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0],
- " prop window name ?value ?\"", NULL);
+ if ((objc != 4) && (objc != 5)) {
+ Tcl_WrongNumArgs(interp, 1, objv,
+ "prop window name ?value ?");
return TCL_ERROR;
}
- if (strcmp(argv[2], "root") == 0) {
+ if (strcmp(Tcl_GetString(objv[2]), "root") == 0) {
w = RootWindow(winPtr->dispPtr->display, 0);
- } else if (strcmp(argv[2], "comm") == 0) {
+ } else if (strcmp(Tcl_GetString(objv[2]), "comm") == 0) {
w = Tk_WindowId(winPtr->dispPtr->commTkwin);
} else {
- w = strtoul(argv[2], &end, 0);
+ w = strtoul(Tcl_GetString(objv[2]), &end, 0);
}
- propName = Tk_InternAtom((Tk_Window) winPtr, argv[3]);
- if (argc == 4) {
+ propName = Tk_InternAtom((Tk_Window) winPtr, Tcl_GetString(objv[3]));
+ if (objc == 4) {
property = NULL;
result = XGetWindowProperty(winPtr->dispPtr->display, w, propName,
0, 100000, False, XA_STRING, &actualType, &actualFormat,
@@ -1992,19 +2001,19 @@ TkpTestsendCmd(
*p = '\n';
}
}
- Tcl_SetResult(interp, property, TCL_VOLATILE);
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(property, -1));
}
if (property != NULL) {
XFree(property);
}
- } else if (argv[4][0] == 0) {
+ } else if (Tcl_GetString(objv[4])[0] == 0) {
XDeleteProperty(winPtr->dispPtr->display, w, propName);
} else {
Tcl_DString tmp;
Tcl_DStringInit(&tmp);
- for (p = Tcl_DStringAppend(&tmp, argv[4],
- (int) strlen(argv[4])); *p != 0; p++) {
+ for (p = Tcl_DStringAppend(&tmp, Tcl_GetString(objv[4]),
+ (int) strlen(Tcl_GetString(objv[4]))); *p != 0; p++) {
if (*p == '\n') {
*p = 0;
}
@@ -2015,15 +2024,8 @@ TkpTestsendCmd(
p-Tcl_DStringValue(&tmp));
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);
- } else {
- Tcl_AppendResult(interp, "bad option \"", argv[1],
- "\": must be bogus, prop, or serial", NULL);
- return TCL_ERROR;
+ } else if (index == TESTSEND_SERIAL) {
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(localData.sendSerial+1));
}
return TCL_OK;
}