| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "tclInt.h" |
| 20 |
#include "tclCompile.h" |
| 21 |
#ifndef TCL_GENERIC_ONLY |
| 22 |
# include "tclPort.h" |
| 23 |
#endif |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
static char * CallCommandTraces _ANSI_ARGS_((Interp *iPtr, |
| 30 |
Command *cmdPtr, CONST char *oldName, |
| 31 |
CONST char* newName, int flags)); |
| 32 |
static void DeleteInterpProc _ANSI_ARGS_((Tcl_Interp *interp)); |
| 33 |
static void ProcessUnexpectedResult _ANSI_ARGS_(( |
| 34 |
Tcl_Interp *interp, int returnCode)); |
| 35 |
static int StringTraceProc _ANSI_ARGS_((ClientData clientData, |
| 36 |
Tcl_Interp* interp, |
| 37 |
int level, |
| 38 |
CONST char* command, |
| 39 |
Tcl_Command commandInfo, |
| 40 |
int objc, |
| 41 |
Tcl_Obj *CONST objv[])); |
| 42 |
static void StringTraceDeleteProc _ANSI_ARGS_((ClientData clientData)); |
| 43 |
|
| 44 |
extern TclStubs tclStubs; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
typedef struct { |
| 51 |
char *name; |
| 52 |
Tcl_CmdProc *proc; |
| 53 |
Tcl_ObjCmdProc *objProc; |
| 54 |
CompileProc *compileProc; |
| 55 |
int isSafe; |
| 56 |
|
| 57 |
|
| 58 |
} CmdInfo; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
static CmdInfo builtInCmds[] = { |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
{"append", (Tcl_CmdProc *) NULL, Tcl_AppendObjCmd, |
| 74 |
TclCompileAppendCmd, 1}, |
| 75 |
{"array", (Tcl_CmdProc *) NULL, Tcl_ArrayObjCmd, |
| 76 |
(CompileProc *) NULL, 1}, |
| 77 |
{"binary", (Tcl_CmdProc *) NULL, Tcl_BinaryObjCmd, |
| 78 |
(CompileProc *) NULL, 1}, |
| 79 |
{"break", (Tcl_CmdProc *) NULL, Tcl_BreakObjCmd, |
| 80 |
TclCompileBreakCmd, 1}, |
| 81 |
{"case", (Tcl_CmdProc *) NULL, Tcl_CaseObjCmd, |
| 82 |
(CompileProc *) NULL, 1}, |
| 83 |
{"catch", (Tcl_CmdProc *) NULL, Tcl_CatchObjCmd, |
| 84 |
TclCompileCatchCmd, 1}, |
| 85 |
{"clock", (Tcl_CmdProc *) NULL, Tcl_ClockObjCmd, |
| 86 |
(CompileProc *) NULL, 1}, |
| 87 |
{"concat", (Tcl_CmdProc *) NULL, Tcl_ConcatObjCmd, |
| 88 |
(CompileProc *) NULL, 1}, |
| 89 |
{"continue", (Tcl_CmdProc *) NULL, Tcl_ContinueObjCmd, |
| 90 |
TclCompileContinueCmd, 1}, |
| 91 |
{"encoding", (Tcl_CmdProc *) NULL, Tcl_EncodingObjCmd, |
| 92 |
(CompileProc *) NULL, 0}, |
| 93 |
{"error", (Tcl_CmdProc *) NULL, Tcl_ErrorObjCmd, |
| 94 |
(CompileProc *) NULL, 1}, |
| 95 |
{"eval", (Tcl_CmdProc *) NULL, Tcl_EvalObjCmd, |
| 96 |
(CompileProc *) NULL, 1}, |
| 97 |
{"exit", (Tcl_CmdProc *) NULL, Tcl_ExitObjCmd, |
| 98 |
(CompileProc *) NULL, 0}, |
| 99 |
{"expr", (Tcl_CmdProc *) NULL, Tcl_ExprObjCmd, |
| 100 |
TclCompileExprCmd, 1}, |
| 101 |
{"fcopy", (Tcl_CmdProc *) NULL, Tcl_FcopyObjCmd, |
| 102 |
(CompileProc *) NULL, 1}, |
| 103 |
{"fileevent", (Tcl_CmdProc *) NULL, Tcl_FileEventObjCmd, |
| 104 |
(CompileProc *) NULL, 1}, |
| 105 |
{"for", (Tcl_CmdProc *) NULL, Tcl_ForObjCmd, |
| 106 |
TclCompileForCmd, 1}, |
| 107 |
{"foreach", (Tcl_CmdProc *) NULL, Tcl_ForeachObjCmd, |
| 108 |
TclCompileForeachCmd, 1}, |
| 109 |
{"format", (Tcl_CmdProc *) NULL, Tcl_FormatObjCmd, |
| 110 |
(CompileProc *) NULL, 1}, |
| 111 |
{"global", (Tcl_CmdProc *) NULL, Tcl_GlobalObjCmd, |
| 112 |
(CompileProc *) NULL, 1}, |
| 113 |
{"if", (Tcl_CmdProc *) NULL, Tcl_IfObjCmd, |
| 114 |
TclCompileIfCmd, 1}, |
| 115 |
{"incr", (Tcl_CmdProc *) NULL, Tcl_IncrObjCmd, |
| 116 |
TclCompileIncrCmd, 1}, |
| 117 |
{"info", (Tcl_CmdProc *) NULL, Tcl_InfoObjCmd, |
| 118 |
(CompileProc *) NULL, 1}, |
| 119 |
{"join", (Tcl_CmdProc *) NULL, Tcl_JoinObjCmd, |
| 120 |
(CompileProc *) NULL, 1}, |
| 121 |
{"lappend", (Tcl_CmdProc *) NULL, Tcl_LappendObjCmd, |
| 122 |
TclCompileLappendCmd, 1}, |
| 123 |
{"lindex", (Tcl_CmdProc *) NULL, Tcl_LindexObjCmd, |
| 124 |
TclCompileLindexCmd, 1}, |
| 125 |
{"linsert", (Tcl_CmdProc *) NULL, Tcl_LinsertObjCmd, |
| 126 |
(CompileProc *) NULL, 1}, |
| 127 |
{"list", (Tcl_CmdProc *) NULL, Tcl_ListObjCmd, |
| 128 |
TclCompileListCmd, 1}, |
| 129 |
{"llength", (Tcl_CmdProc *) NULL, Tcl_LlengthObjCmd, |
| 130 |
TclCompileLlengthCmd, 1}, |
| 131 |
{"load", (Tcl_CmdProc *) NULL, Tcl_LoadObjCmd, |
| 132 |
(CompileProc *) NULL, 0}, |
| 133 |
{"lrange", (Tcl_CmdProc *) NULL, Tcl_LrangeObjCmd, |
| 134 |
(CompileProc *) NULL, 1}, |
| 135 |
{"lreplace", (Tcl_CmdProc *) NULL, Tcl_LreplaceObjCmd, |
| 136 |
(CompileProc *) NULL, 1}, |
| 137 |
{"lsearch", (Tcl_CmdProc *) NULL, Tcl_LsearchObjCmd, |
| 138 |
(CompileProc *) NULL, 1}, |
| 139 |
{"lset", (Tcl_CmdProc *) NULL, Tcl_LsetObjCmd, |
| 140 |
TclCompileLsetCmd, 1}, |
| 141 |
{"lsort", (Tcl_CmdProc *) NULL, Tcl_LsortObjCmd, |
| 142 |
(CompileProc *) NULL, 1}, |
| 143 |
{"namespace", (Tcl_CmdProc *) NULL, Tcl_NamespaceObjCmd, |
| 144 |
(CompileProc *) NULL, 1}, |
| 145 |
{"package", (Tcl_CmdProc *) NULL, Tcl_PackageObjCmd, |
| 146 |
(CompileProc *) NULL, 1}, |
| 147 |
{"proc", (Tcl_CmdProc *) NULL, Tcl_ProcObjCmd, |
| 148 |
(CompileProc *) NULL, 1}, |
| 149 |
{"regexp", (Tcl_CmdProc *) NULL, Tcl_RegexpObjCmd, |
| 150 |
TclCompileRegexpCmd, 1}, |
| 151 |
{"regsub", (Tcl_CmdProc *) NULL, Tcl_RegsubObjCmd, |
| 152 |
(CompileProc *) NULL, 1}, |
| 153 |
{"rename", (Tcl_CmdProc *) NULL, Tcl_RenameObjCmd, |
| 154 |
(CompileProc *) NULL, 1}, |
| 155 |
{"return", (Tcl_CmdProc *) NULL, Tcl_ReturnObjCmd, |
| 156 |
TclCompileReturnCmd, 1}, |
| 157 |
{"scan", (Tcl_CmdProc *) NULL, Tcl_ScanObjCmd, |
| 158 |
(CompileProc *) NULL, 1}, |
| 159 |
{"set", (Tcl_CmdProc *) NULL, Tcl_SetObjCmd, |
| 160 |
TclCompileSetCmd, 1}, |
| 161 |
{"split", (Tcl_CmdProc *) NULL, Tcl_SplitObjCmd, |
| 162 |
(CompileProc *) NULL, 1}, |
| 163 |
{"string", (Tcl_CmdProc *) NULL, Tcl_StringObjCmd, |
| 164 |
TclCompileStringCmd, 1}, |
| 165 |
{"subst", (Tcl_CmdProc *) NULL, Tcl_SubstObjCmd, |
| 166 |
(CompileProc *) NULL, 1}, |
| 167 |
{"switch", (Tcl_CmdProc *) NULL, Tcl_SwitchObjCmd, |
| 168 |
(CompileProc *) NULL, 1}, |
| 169 |
{"trace", (Tcl_CmdProc *) NULL, Tcl_TraceObjCmd, |
| 170 |
(CompileProc *) NULL, 1}, |
| 171 |
{"unset", (Tcl_CmdProc *) NULL, Tcl_UnsetObjCmd, |
| 172 |
(CompileProc *) NULL, 1}, |
| 173 |
{"uplevel", (Tcl_CmdProc *) NULL, Tcl_UplevelObjCmd, |
| 174 |
(CompileProc *) NULL, 1}, |
| 175 |
{"upvar", (Tcl_CmdProc *) NULL, Tcl_UpvarObjCmd, |
| 176 |
(CompileProc *) NULL, 1}, |
| 177 |
{"variable", (Tcl_CmdProc *) NULL, Tcl_VariableObjCmd, |
| 178 |
(CompileProc *) NULL, 1}, |
| 179 |
{"while", (Tcl_CmdProc *) NULL, Tcl_WhileObjCmd, |
| 180 |
TclCompileWhileCmd, 1}, |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
#ifndef TCL_GENERIC_ONLY |
| 187 |
{"after", (Tcl_CmdProc *) NULL, Tcl_AfterObjCmd, |
| 188 |
(CompileProc *) NULL, 1}, |
| 189 |
{"cd", (Tcl_CmdProc *) NULL, Tcl_CdObjCmd, |
| 190 |
(CompileProc *) NULL, 0}, |
| 191 |
{"close", (Tcl_CmdProc *) NULL, Tcl_CloseObjCmd, |
| 192 |
(CompileProc *) NULL, 1}, |
| 193 |
{"eof", (Tcl_CmdProc *) NULL, Tcl_EofObjCmd, |
| 194 |
(CompileProc *) NULL, 1}, |
| 195 |
{"fblocked", (Tcl_CmdProc *) NULL, Tcl_FblockedObjCmd, |
| 196 |
(CompileProc *) NULL, 1}, |
| 197 |
{"fconfigure", (Tcl_CmdProc *) NULL, Tcl_FconfigureObjCmd, |
| 198 |
(CompileProc *) NULL, 0}, |
| 199 |
{"file", (Tcl_CmdProc *) NULL, Tcl_FileObjCmd, |
| 200 |
(CompileProc *) NULL, 0}, |
| 201 |
{"flush", (Tcl_CmdProc *) NULL, Tcl_FlushObjCmd, |
| 202 |
(CompileProc *) NULL, 1}, |
| 203 |
{"gets", (Tcl_CmdProc *) NULL, Tcl_GetsObjCmd, |
| 204 |
(CompileProc *) NULL, 1}, |
| 205 |
{"glob", (Tcl_CmdProc *) NULL, Tcl_GlobObjCmd, |
| 206 |
(CompileProc *) NULL, 0}, |
| 207 |
{"open", (Tcl_CmdProc *) NULL, Tcl_OpenObjCmd, |
| 208 |
(CompileProc *) NULL, 0}, |
| 209 |
{"pid", (Tcl_CmdProc *) NULL, Tcl_PidObjCmd, |
| 210 |
(CompileProc *) NULL, 1}, |
| 211 |
{"puts", (Tcl_CmdProc *) NULL, Tcl_PutsObjCmd, |
| 212 |
(CompileProc *) NULL, 1}, |
| 213 |
{"pwd", (Tcl_CmdProc *) NULL, Tcl_PwdObjCmd, |
| 214 |
(CompileProc *) NULL, 0}, |
| 215 |
{"read", (Tcl_CmdProc *) NULL, Tcl_ReadObjCmd, |
| 216 |
(CompileProc *) NULL, 1}, |
| 217 |
{"seek", (Tcl_CmdProc *) NULL, Tcl_SeekObjCmd, |
| 218 |
(CompileProc *) NULL, 1}, |
| 219 |
{"socket", (Tcl_CmdProc *) NULL, Tcl_SocketObjCmd, |
| 220 |
(CompileProc *) NULL, 0}, |
| 221 |
{"tell", (Tcl_CmdProc *) NULL, Tcl_TellObjCmd, |
| 222 |
(CompileProc *) NULL, 1}, |
| 223 |
{"time", (Tcl_CmdProc *) NULL, Tcl_TimeObjCmd, |
| 224 |
(CompileProc *) NULL, 1}, |
| 225 |
{"update", (Tcl_CmdProc *) NULL, Tcl_UpdateObjCmd, |
| 226 |
(CompileProc *) NULL, 1}, |
| 227 |
{"vwait", (Tcl_CmdProc *) NULL, Tcl_VwaitObjCmd, |
| 228 |
(CompileProc *) NULL, 1}, |
| 229 |
|
| 230 |
#ifdef MAC_TCL |
| 231 |
{"beep", (Tcl_CmdProc *) NULL, Tcl_BeepObjCmd, |
| 232 |
(CompileProc *) NULL, 0}, |
| 233 |
{"echo", Tcl_EchoCmd, (Tcl_ObjCmdProc *) NULL, |
| 234 |
(CompileProc *) NULL, 0}, |
| 235 |
{"ls", (Tcl_CmdProc *) NULL, Tcl_LsObjCmd, |
| 236 |
(CompileProc *) NULL, 0}, |
| 237 |
{"resource", (Tcl_CmdProc *) NULL, Tcl_ResourceObjCmd, |
| 238 |
(CompileProc *) NULL, 1}, |
| 239 |
{"source", (Tcl_CmdProc *) NULL, Tcl_MacSourceObjCmd, |
| 240 |
(CompileProc *) NULL, 0}, |
| 241 |
#else |
| 242 |
{"exec", (Tcl_CmdProc *) NULL, Tcl_ExecObjCmd, |
| 243 |
(CompileProc *) NULL, 0}, |
| 244 |
{"source", (Tcl_CmdProc *) NULL, Tcl_SourceObjCmd, |
| 245 |
(CompileProc *) NULL, 0}, |
| 246 |
#endif |
| 247 |
|
| 248 |
#endif |
| 249 |
{NULL, (Tcl_CmdProc *) NULL, (Tcl_ObjCmdProc *) NULL, |
| 250 |
(CompileProc *) NULL, 0} |
| 251 |
}; |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
typedef struct StringTraceData { |
| 259 |
ClientData clientData; |
| 260 |
Tcl_CmdTraceProc* proc; |
| 261 |
} StringTraceData; |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
Tcl_Interp * |
| 283 |
Tcl_CreateInterp() |
| 284 |
{ |
| 285 |
Interp *iPtr; |
| 286 |
Tcl_Interp *interp; |
| 287 |
Command *cmdPtr; |
| 288 |
BuiltinFunc *builtinFuncPtr; |
| 289 |
MathFunc *mathFuncPtr; |
| 290 |
Tcl_HashEntry *hPtr; |
| 291 |
CmdInfo *cmdInfoPtr; |
| 292 |
int i; |
| 293 |
union { |
| 294 |
char c[sizeof(short)]; |
| 295 |
short s; |
| 296 |
} order; |
| 297 |
#ifdef TCL_COMPILE_STATS |
| 298 |
ByteCodeStats *statsPtr; |
| 299 |
#endif |
| 300 |
|
| 301 |
TclInitSubsystems(NULL); |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
if (sizeof(Tcl_CallFrame) != sizeof(CallFrame)) { |
| 309 |
|
| 310 |
panic("Tcl_CallFrame and CallFrame are not the same size"); |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
iPtr = (Interp *) ckalloc(sizeof(Interp)); |
| 320 |
interp = (Tcl_Interp *) iPtr; |
| 321 |
|
| 322 |
iPtr->result = iPtr->resultSpace; |
| 323 |
iPtr->freeProc = NULL; |
| 324 |
iPtr->errorLine = 0; |
| 325 |
iPtr->objResultPtr = Tcl_NewObj(); |
| 326 |
Tcl_IncrRefCount(iPtr->objResultPtr); |
| 327 |
iPtr->handle = TclHandleCreate(iPtr); |
| 328 |
iPtr->globalNsPtr = NULL; |
| 329 |
iPtr->hiddenCmdTablePtr = NULL; |
| 330 |
iPtr->interpInfo = NULL; |
| 331 |
Tcl_InitHashTable(&iPtr->mathFuncTable, TCL_STRING_KEYS); |
| 332 |
|
| 333 |
iPtr->numLevels = 0; |
| 334 |
iPtr->maxNestingDepth = MAX_NESTING_DEPTH; |
| 335 |
iPtr->framePtr = NULL; |
| 336 |
iPtr->varFramePtr = NULL; |
| 337 |
iPtr->activeVarTracePtr = NULL; |
| 338 |
iPtr->returnCode = TCL_OK; |
| 339 |
iPtr->errorInfo = NULL; |
| 340 |
iPtr->errorCode = NULL; |
| 341 |
|
| 342 |
iPtr->appendResult = NULL; |
| 343 |
iPtr->appendAvl = 0; |
| 344 |
iPtr->appendUsed = 0; |
| 345 |
|
| 346 |
Tcl_InitHashTable(&iPtr->packageTable, TCL_STRING_KEYS); |
| 347 |
iPtr->packageUnknown = NULL; |
| 348 |
iPtr->cmdCount = 0; |
| 349 |
iPtr->termOffset = 0; |
| 350 |
TclInitLiteralTable(&(iPtr->literalTable)); |
| 351 |
iPtr->compileEpoch = 0; |
| 352 |
iPtr->compiledProcPtr = NULL; |
| 353 |
iPtr->resolverPtr = NULL; |
| 354 |
iPtr->evalFlags = 0; |
| 355 |
iPtr->scriptFile = NULL; |
| 356 |
iPtr->flags = 0; |
| 357 |
iPtr->tracePtr = NULL; |
| 358 |
iPtr->tracesForbiddingInline = 0; |
| 359 |
iPtr->activeCmdTracePtr = NULL; |
| 360 |
iPtr->activeInterpTracePtr = NULL; |
| 361 |
iPtr->assocData = (Tcl_HashTable *) NULL; |
| 362 |
iPtr->execEnvPtr = NULL; |
| 363 |
iPtr->emptyObjPtr = Tcl_NewObj(); |
| 364 |
Tcl_IncrRefCount(iPtr->emptyObjPtr); |
| 365 |
iPtr->resultSpace[0] = 0; |
| 366 |
|
| 367 |
iPtr->globalNsPtr = NULL; |
| 368 |
iPtr->globalNsPtr = (Namespace *) Tcl_CreateNamespace(interp, "", |
| 369 |
(ClientData) NULL, (Tcl_NamespaceDeleteProc *) NULL); |
| 370 |
if (iPtr->globalNsPtr == NULL) { |
| 371 |
panic("Tcl_CreateInterp: can't create global namespace"); |
| 372 |
} |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
iPtr->execEnvPtr = TclCreateExecEnv(interp); |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
#ifdef TCL_COMPILE_STATS |
| 389 |
statsPtr = &(iPtr->stats); |
| 390 |
statsPtr->numExecutions = 0; |
| 391 |
statsPtr->numCompilations = 0; |
| 392 |
statsPtr->numByteCodesFreed = 0; |
| 393 |
(VOID *) memset(statsPtr->instructionCount, 0, |
| 394 |
sizeof(statsPtr->instructionCount)); |
| 395 |
|
| 396 |
statsPtr->totalSrcBytes = 0.0; |
| 397 |
statsPtr->totalByteCodeBytes = 0.0; |
| 398 |
statsPtr->currentSrcBytes = 0.0; |
| 399 |
statsPtr->currentByteCodeBytes = 0.0; |
| 400 |
(VOID *) memset(statsPtr->srcCount, 0, sizeof(statsPtr->srcCount)); |
| 401 |
(VOID *) memset(statsPtr->byteCodeCount, 0, |
| 402 |
sizeof(statsPtr->byteCodeCount)); |
| 403 |
(VOID *) memset(statsPtr->lifetimeCount, 0, |
| 404 |
sizeof(statsPtr->lifetimeCount)); |
| 405 |
|
| 406 |
statsPtr->currentInstBytes = 0.0; |
| 407 |
statsPtr->currentLitBytes = 0.0; |
| 408 |
statsPtr->currentExceptBytes = 0.0; |
| 409 |
statsPtr->currentAuxBytes = 0.0; |
| 410 |
statsPtr->currentCmdMapBytes = 0.0; |
| 411 |
|
| 412 |
statsPtr->numLiteralsCreated = 0; |
| 413 |
statsPtr->totalLitStringBytes = 0.0; |
| 414 |
statsPtr->currentLitStringBytes = 0.0; |
| 415 |
(VOID *) memset(statsPtr->literalCount, 0, |
| 416 |
sizeof(statsPtr->literalCount)); |
| 417 |
#endif |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
iPtr->stubTable = &tclStubs; |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
for (cmdInfoPtr = builtInCmds; cmdInfoPtr->name != NULL; |
| 438 |
cmdInfoPtr++) { |
| 439 |
int new; |
| 440 |
Tcl_HashEntry *hPtr; |
| 441 |
|
| 442 |
if ((cmdInfoPtr->proc == (Tcl_CmdProc *) NULL) |
| 443 |
&& (cmdInfoPtr->objProc == (Tcl_ObjCmdProc *) NULL) |
| 444 |
&& (cmdInfoPtr->compileProc == (CompileProc *) NULL)) { |
| 445 |
panic("Tcl_CreateInterp: builtin command with NULL string and object command procs and a NULL compile proc\n"); |
| 446 |
} |
| 447 |
|
| 448 |
hPtr = Tcl_CreateHashEntry(&iPtr->globalNsPtr->cmdTable, |
| 449 |
cmdInfoPtr->name, &new); |
| 450 |
if (new) { |
| 451 |
cmdPtr = (Command *) ckalloc(sizeof(Command)); |
| 452 |
cmdPtr->hPtr = hPtr; |
| 453 |
cmdPtr->nsPtr = iPtr->globalNsPtr; |
| 454 |
cmdPtr->refCount = 1; |
| 455 |
cmdPtr->cmdEpoch = 0; |
| 456 |
cmdPtr->compileProc = cmdInfoPtr->compileProc; |
| 457 |
if (cmdInfoPtr->proc == (Tcl_CmdProc *) NULL) { |
| 458 |
cmdPtr->proc = TclInvokeObjectCommand; |
| 459 |
cmdPtr->clientData = (ClientData) cmdPtr; |
| 460 |
} else { |
| 461 |
cmdPtr->proc = cmdInfoPtr->proc; |
| 462 |
cmdPtr->clientData = (ClientData) NULL; |
| 463 |
} |
| 464 |
if (cmdInfoPtr->objProc == (Tcl_ObjCmdProc *) NULL) { |
| 465 |
cmdPtr->objProc = TclInvokeStringCommand; |
| 466 |
cmdPtr->objClientData = (ClientData) cmdPtr; |
| 467 |
} else { |
| 468 |
cmdPtr->objProc = cmdInfoPtr->objProc; |
| 469 |
cmdPtr->objClientData = (ClientData) NULL; |
| 470 |
} |
| 471 |
cmdPtr->deleteProc = NULL; |
| 472 |
cmdPtr->deleteData = (ClientData) NULL; |
| 473 |
cmdPtr->flags = 0; |
| 474 |
cmdPtr->importRefPtr = NULL; |
| 475 |
cmdPtr->tracePtr = NULL; |
| 476 |
Tcl_SetHashValue(hPtr, cmdPtr); |
| 477 |
} |
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
i = 0; |
| 485 |
for (builtinFuncPtr = tclBuiltinFuncTable; builtinFuncPtr->name != NULL; |
| 486 |
builtinFuncPtr++) { |
| 487 |
Tcl_CreateMathFunc((Tcl_Interp *) iPtr, builtinFuncPtr->name, |
| 488 |
builtinFuncPtr->numArgs, builtinFuncPtr->argTypes, |
| 489 |
(Tcl_MathProc *) NULL, (ClientData) 0); |
| 490 |
hPtr = Tcl_FindHashEntry(&iPtr->mathFuncTable, |
| 491 |
builtinFuncPtr->name); |
| 492 |
if (hPtr == NULL) { |
| 493 |
panic("Tcl_CreateInterp: Tcl_CreateMathFunc incorrectly registered '%s'", builtinFuncPtr->name); |
| 494 |
return NULL; |
| 495 |
} |
| 496 |
mathFuncPtr = (MathFunc *) Tcl_GetHashValue(hPtr); |
| 497 |
mathFuncPtr->builtinFuncIndex = i; |
| 498 |
i++; |
| 499 |
} |
| 500 |
iPtr->flags |= EXPR_INITIALIZED; |
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
TclInterpInit(interp); |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
#ifndef TCL_GENERIC_ONLY |
| 533 |
TclSetupEnv(interp); |
| 534 |
#endif |
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
order.s = 1; |
| 541 |
Tcl_SetVar2(interp, "tcl_platform", "byteOrder", |
| 542 |
((order.c[0] == 1) ? "littleEndian" : "bigEndian"), |
| 543 |
TCL_GLOBAL_ONLY); |
| 544 |
|
| 545 |
Tcl_SetVar2Ex(interp, "tcl_platform", "wordSize", |
| 546 |
Tcl_NewLongObj((long) sizeof(long)), TCL_GLOBAL_ONLY); |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
Tcl_SetVar(interp, "tcl_patchLevel", TCL_PATCH_LEVEL, TCL_GLOBAL_ONLY); |
| 553 |
Tcl_SetVar(interp, "tcl_version", TCL_VERSION, TCL_GLOBAL_ONLY); |
| 554 |
Tcl_TraceVar2(interp, "tcl_precision", (char *) NULL, |
| 555 |
TCL_GLOBAL_ONLY|TCL_TRACE_READS|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, |
| 556 |
TclPrecTraceProc, (ClientData) NULL); |
| 557 |
TclpSetVariables(interp); |
| 558 |
|
| 559 |
#ifdef TCL_THREADS |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
Tcl_SetVar2(interp, "tcl_platform", "threaded", "1", |
| 569 |
TCL_GLOBAL_ONLY); |
| 570 |
#endif |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
Tcl_PkgProvideEx(interp, "Tcl", TCL_VERSION, (ClientData) &tclStubs); |
| 577 |
|
| 578 |
#ifdef Tcl_InitStubs |
| 579 |
#undef Tcl_InitStubs |
| 580 |
#endif |
| 581 |
Tcl_InitStubs(interp, TCL_VERSION, 1); |
| 582 |
|
| 583 |
return interp; |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
int |
| 604 |
TclHideUnsafeCommands(interp) |
| 605 |
Tcl_Interp *interp; |
| 606 |
{ |
| 607 |
register CmdInfo *cmdInfoPtr; |
| 608 |
|
| 609 |
if (interp == (Tcl_Interp *) NULL) { |
| 610 |
return TCL_ERROR; |
| 611 |
} |
| 612 |
for (cmdInfoPtr = builtInCmds; cmdInfoPtr->name != NULL; cmdInfoPtr++) { |
| 613 |
if (!cmdInfoPtr->isSafe) { |
| 614 |
Tcl_HideCommand(interp, cmdInfoPtr->name, cmdInfoPtr->name); |
| 615 |
} |
| 616 |
} |
| 617 |
return TCL_OK; |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
void |
| 644 |
Tcl_CallWhenDeleted(interp, proc, clientData) |
| 645 |
Tcl_Interp *interp; |
| 646 |
Tcl_InterpDeleteProc *proc; |
| 647 |
|
| 648 |
ClientData clientData; |
| 649 |
{ |
| 650 |
Interp *iPtr = (Interp *) interp; |
| 651 |
static int assocDataCounter = 0; |
| 652 |
#ifdef TCL_THREADS |
| 653 |
static Tcl_Mutex assocMutex; |
| 654 |
#endif |
| 655 |
int new; |
| 656 |
char buffer[32 + TCL_INTEGER_SPACE]; |
| 657 |
AssocData *dPtr = (AssocData *) ckalloc(sizeof(AssocData)); |
| 658 |
Tcl_HashEntry *hPtr; |
| 659 |
|
| 660 |
Tcl_MutexLock(&assocMutex); |
| 661 |
sprintf(buffer, "Assoc Data Key #%d", assocDataCounter); |
| 662 |
assocDataCounter++; |
| 663 |
Tcl_MutexUnlock(&assocMutex); |
| 664 |
|
| 665 |
if (iPtr->assocData == (Tcl_HashTable *) NULL) { |
| 666 |
iPtr->assocData = (Tcl_HashTable *) ckalloc(sizeof(Tcl_HashTable)); |
| 667 |
Tcl_InitHashTable(iPtr->assocData, TCL_STRING_KEYS); |
| 668 |
} |
| 669 |
hPtr = Tcl_CreateHashEntry(iPtr->assocData, buffer, &new); |
| 670 |
dPtr->proc = proc; |
| 671 |
dPtr->clientData = clientData; |
| 672 |
Tcl_SetHashValue(hPtr, dPtr); |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
void |
| 696 |
Tcl_DontCallWhenDeleted(interp, proc, clientData) |
| 697 |
Tcl_Interp *interp; |
| 698 |
Tcl_InterpDeleteProc *proc; |
| 699 |
|
| 700 |
ClientData clientData; |
| 701 |
{ |
| 702 |
Interp *iPtr = (Interp *) interp; |
| 703 |
Tcl_HashTable *hTablePtr; |
| 704 |
Tcl_HashSearch hSearch; |
| 705 |
Tcl_HashEntry *hPtr; |
| 706 |
AssocData *dPtr; |
| 707 |
|
| 708 |
hTablePtr = iPtr->assocData; |
| 709 |
if (hTablePtr == (Tcl_HashTable *) NULL) { |
| 710 |
return; |
| 711 |
} |
| 712 |
for (hPtr = Tcl_FirstHashEntry(hTablePtr, &hSearch); hPtr != NULL; |
| 713 |
hPtr = Tcl_NextHashEntry(&hSearch)) { |
| 714 |
dPtr = (AssocData *) Tcl_GetHashValue(hPtr); |
| 715 |
if ((dPtr->proc == proc) && (dPtr->clientData == clientData)) { |
| 716 |
ckfree((char *) dPtr); |
| 717 |
Tcl_DeleteHashEntry(hPtr); |
| 718 |
return; |
| 719 |
} |
| 720 |
} |
| 721 |
} |
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
void |
| 743 |
Tcl_SetAssocData(interp, name, proc, clientData) |
| 744 |
Tcl_Interp *interp; |
| 745 |
CONST char *name; |
| 746 |
Tcl_InterpDeleteProc *proc; |
| 747 |
|
| 748 |
ClientData clientData; |
| 749 |
{ |
| 750 |
Interp *iPtr = (Interp *) interp; |
| 751 |
AssocData *dPtr; |
| 752 |
Tcl_HashEntry *hPtr; |
| 753 |
int new; |
| 754 |
|
| 755 |
if (iPtr->assocData == (Tcl_HashTable *) NULL) { |
| 756 |
iPtr->assocData = (Tcl_HashTable *) ckalloc(sizeof(Tcl_HashTable)); |
| 757 |
Tcl_InitHashTable(iPtr->assocData, TCL_STRING_KEYS); |
| 758 |
} |
| 759 |
hPtr = Tcl_CreateHashEntry(iPtr->assocData, name, &new); |
| 760 |
if (new == 0) { |
| 761 |
dPtr = (AssocData *) Tcl_GetHashValue(hPtr); |
| 762 |
} else { |
| 763 |
dPtr = (AssocData *) ckalloc(sizeof(AssocData)); |
| 764 |
} |
| 765 |
dPtr->proc = proc; |
| 766 |
dPtr->clientData = clientData; |
| 767 |
|
| 768 |
Tcl_SetHashValue(hPtr, dPtr); |
| 769 |
} |
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
void |
| 789 |
Tcl_DeleteAssocData(interp, name) |
| 790 |
Tcl_Interp *interp; |
| 791 |
CONST char *name; |
| 792 |
{ |
| 793 |
Interp *iPtr = (Interp *) interp; |
| 794 |
AssocData *dPtr; |
| 795 |
Tcl_HashEntry *hPtr; |
| 796 |
|
| 797 |
if (iPtr->assocData == (Tcl_HashTable *) NULL) { |
| 798 |
return; |
| 799 |
} |
| 800 |
hPtr = Tcl_FindHashEntry(iPtr->assocData, name); |
| 801 |
if (hPtr == (Tcl_HashEntry *) NULL) { |
| 802 |
return; |
| 803 |
} |
| 804 |
dPtr = (AssocData *) Tcl_GetHashValue(hPtr); |
| 805 |
if (dPtr->proc != NULL) { |
| 806 |
(dPtr->proc) (dPtr->clientData, interp); |
| 807 |
} |
| 808 |
ckfree((char *) dPtr); |
| 809 |
Tcl_DeleteHashEntry(hPtr); |
| 810 |
} |
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
ClientData |
| 831 |
Tcl_GetAssocData(interp, name, procPtr) |
| 832 |
Tcl_Interp *interp; |
| 833 |
CONST char *name; |
| 834 |
Tcl_InterpDeleteProc **procPtr; |
| 835 |
|
| 836 |
{ |
| 837 |
Interp *iPtr = (Interp *) interp; |
| 838 |
AssocData *dPtr; |
| 839 |
Tcl_HashEntry *hPtr; |
| 840 |
|
| 841 |
if (iPtr->assocData == (Tcl_HashTable *) NULL) { |
| 842 |
return (ClientData) NULL; |
| 843 |
} |
| 844 |
hPtr = Tcl_FindHashEntry(iPtr->assocData, name); |
| 845 |
if (hPtr == (Tcl_HashEntry *) NULL) { |
| 846 |
return (ClientData) NULL; |
| 847 |
} |
| 848 |
dPtr = (AssocData *) Tcl_GetHashValue(hPtr); |
| 849 |
if (procPtr != (Tcl_InterpDeleteProc **) NULL) { |
| 850 |
*procPtr = dPtr->proc; |
| 851 |
} |
| 852 |
return dPtr->clientData; |
| 853 |
} |
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
int |
| 873 |
Tcl_InterpDeleted(interp) |
| 874 |
Tcl_Interp *interp; |
| 875 |
{ |
| 876 |
return (((Interp *) interp)->flags & DELETED) ? 1 : 0; |
| 877 |
} |
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
void |
| 903 |
Tcl_DeleteInterp(interp) |
| 904 |
Tcl_Interp *interp; |
| 905 |
|
| 906 |
{ |
| 907 |
Interp *iPtr = (Interp *) interp; |
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
if (iPtr->flags & DELETED) { |
| 914 |
return; |
| 915 |
} |
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
iPtr->flags |= DELETED; |
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
Tcl_EventuallyFree((ClientData) interp, |
| 928 |
(Tcl_FreeProc *) DeleteInterpProc); |
| 929 |
} |
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
static void |
| 953 |
DeleteInterpProc(interp) |
| 954 |
Tcl_Interp *interp; |
| 955 |
{ |
| 956 |
Interp *iPtr = (Interp *) interp; |
| 957 |
Tcl_HashEntry *hPtr; |
| 958 |
Tcl_HashSearch search; |
| 959 |
Tcl_HashTable *hTablePtr; |
| 960 |
ResolverScheme *resPtr, *nextResPtr; |
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
if (iPtr->numLevels > 0) { |
| 967 |
panic("DeleteInterpProc called with active evals"); |
| 968 |
} |
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
if (!(iPtr->flags & DELETED)) { |
| 976 |
panic("DeleteInterpProc called on interpreter not marked deleted"); |
| 977 |
} |
| 978 |
|
| 979 |
TclHandleFree(iPtr->handle); |
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
TclTeardownNamespace(iPtr->globalNsPtr); |
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
hTablePtr = iPtr->hiddenCmdTablePtr; |
| 997 |
if (hTablePtr != NULL) { |
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
hPtr = Tcl_FirstHashEntry(hTablePtr, &search); |
| 1006 |
for ( ; hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { |
| 1007 |
Tcl_DeleteCommandFromToken(interp, |
| 1008 |
(Tcl_Command) Tcl_GetHashValue(hPtr)); |
| 1009 |
} |
| 1010 |
Tcl_DeleteHashTable(hTablePtr); |
| 1011 |
ckfree((char *) hTablePtr); |
| 1012 |
} |
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
for (hPtr = Tcl_FirstHashEntry(&iPtr->mathFuncTable, &search); |
| 1018 |
hPtr != NULL; |
| 1019 |
hPtr = Tcl_NextHashEntry(&search)) { |
| 1020 |
ckfree((char *) Tcl_GetHashValue(hPtr)); |
| 1021 |
} |
| 1022 |
Tcl_DeleteHashTable(&iPtr->mathFuncTable); |
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
while (iPtr->assocData != (Tcl_HashTable *) NULL) { |
| 1030 |
AssocData *dPtr; |
| 1031 |
|
| 1032 |
hTablePtr = iPtr->assocData; |
| 1033 |
iPtr->assocData = (Tcl_HashTable *) NULL; |
| 1034 |
for (hPtr = Tcl_FirstHashEntry(hTablePtr, &search); |
| 1035 |
hPtr != NULL; |
| 1036 |
hPtr = Tcl_FirstHashEntry(hTablePtr, &search)) { |
| 1037 |
dPtr = (AssocData *) Tcl_GetHashValue(hPtr); |
| 1038 |
Tcl_DeleteHashEntry(hPtr); |
| 1039 |
if (dPtr->proc != NULL) { |
| 1040 |
(*dPtr->proc)(dPtr->clientData, interp); |
| 1041 |
} |
| 1042 |
ckfree((char *) dPtr); |
| 1043 |
} |
| 1044 |
Tcl_DeleteHashTable(hTablePtr); |
| 1045 |
ckfree((char *) hTablePtr); |
| 1046 |
} |
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
Tcl_DeleteNamespace((Tcl_Namespace *) iPtr->globalNsPtr); |
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
Tcl_FreeResult(interp); |
| 1061 |
interp->result = NULL; |
| 1062 |
Tcl_DecrRefCount(iPtr->objResultPtr); |
| 1063 |
iPtr->objResultPtr = NULL; |
| 1064 |
if (iPtr->errorInfo != NULL) { |
| 1065 |
ckfree(iPtr->errorInfo); |
| 1066 |
iPtr->errorInfo = NULL; |
| 1067 |
} |
| 1068 |
if (iPtr->errorCode != NULL) { |
| 1069 |
ckfree(iPtr->errorCode); |
| 1070 |
iPtr->errorCode = NULL; |
| 1071 |
} |
| 1072 |
if (iPtr->appendResult != NULL) { |
| 1073 |
ckfree(iPtr->appendResult); |
| 1074 |
iPtr->appendResult = NULL; |
| 1075 |
} |
| 1076 |
TclFreePackageInfo(iPtr); |
| 1077 |
while (iPtr->tracePtr != NULL) { |
| 1078 |
Tcl_DeleteTrace((Tcl_Interp*) iPtr, (Tcl_Trace) iPtr->tracePtr); |
| 1079 |
} |
| 1080 |
if (iPtr->execEnvPtr != NULL) { |
| 1081 |
TclDeleteExecEnv(iPtr->execEnvPtr); |
| 1082 |
} |
| 1083 |
Tcl_DecrRefCount(iPtr->emptyObjPtr); |
| 1084 |
iPtr->emptyObjPtr = NULL; |
| 1085 |
|
| 1086 |
resPtr = iPtr->resolverPtr; |
| 1087 |
while (resPtr) { |
| 1088 |
nextResPtr = resPtr->nextPtr; |
| 1089 |
ckfree(resPtr->name); |
| 1090 |
ckfree((char *) resPtr); |
| 1091 |
resPtr = nextResPtr; |
| 1092 |
} |
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
TclDeleteLiteralTable(interp, &(iPtr->literalTable)); |
| 1100 |
ckfree((char *) iPtr); |
| 1101 |
} |
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
int |
| 1123 |
Tcl_HideCommand(interp, cmdName, hiddenCmdToken) |
| 1124 |
Tcl_Interp *interp; |
| 1125 |
CONST char *cmdName; |
| 1126 |
CONST char *hiddenCmdToken; |
| 1127 |
{ |
| 1128 |
Interp *iPtr = (Interp *) interp; |
| 1129 |
Tcl_Command cmd; |
| 1130 |
Command *cmdPtr; |
| 1131 |
Tcl_HashTable *hiddenCmdTablePtr; |
| 1132 |
Tcl_HashEntry *hPtr; |
| 1133 |
int new; |
| 1134 |
|
| 1135 |
if (iPtr->flags & DELETED) { |
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
return TCL_ERROR; |
| 1143 |
} |
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
if (strstr(hiddenCmdToken, "::") != NULL) { |
| 1168 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 1169 |
"cannot use namespace qualifiers in hidden command", |
| 1170 |
" token (rename)", (char *) NULL); |
| 1171 |
return TCL_ERROR; |
| 1172 |
} |
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
cmd = Tcl_FindCommand(interp, cmdName, (Tcl_Namespace *) NULL, |
| 1181 |
TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
| 1182 |
if (cmd == (Tcl_Command) NULL) { |
| 1183 |
return TCL_ERROR; |
| 1184 |
} |
| 1185 |
cmdPtr = (Command *) cmd; |
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
if ( cmdPtr->nsPtr != iPtr->globalNsPtr ) { |
| 1192 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 1193 |
"can only hide global namespace commands", |
| 1194 |
" (use rename then hide)", (char *) NULL); |
| 1195 |
return TCL_ERROR; |
| 1196 |
} |
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
hiddenCmdTablePtr = iPtr->hiddenCmdTablePtr; |
| 1203 |
if (hiddenCmdTablePtr == NULL) { |
| 1204 |
hiddenCmdTablePtr = (Tcl_HashTable *) |
| 1205 |
ckalloc((unsigned) sizeof(Tcl_HashTable)); |
| 1206 |
Tcl_InitHashTable(hiddenCmdTablePtr, TCL_STRING_KEYS); |
| 1207 |
iPtr->hiddenCmdTablePtr = hiddenCmdTablePtr; |
| 1208 |
} |
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
hPtr = Tcl_CreateHashEntry(hiddenCmdTablePtr, hiddenCmdToken, &new); |
| 1217 |
if (!new) { |
| 1218 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 1219 |
"hidden command named \"", hiddenCmdToken, "\" already exists", |
| 1220 |
(char *) NULL); |
| 1221 |
return TCL_ERROR; |
| 1222 |
} |
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
if (cmdPtr->hPtr != NULL) { |
| 1238 |
Tcl_DeleteHashEntry(cmdPtr->hPtr); |
| 1239 |
cmdPtr->hPtr = (Tcl_HashEntry *) NULL; |
| 1240 |
cmdPtr->cmdEpoch++; |
| 1241 |
} |
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
cmdPtr->hPtr = hPtr; |
| 1249 |
Tcl_SetHashValue(hPtr, (ClientData) cmdPtr); |
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
if (cmdPtr->compileProc != NULL) { |
| 1261 |
iPtr->compileEpoch++; |
| 1262 |
} |
| 1263 |
return TCL_OK; |
| 1264 |
} |
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
int |
| 1285 |
Tcl_ExposeCommand(interp, hiddenCmdToken, cmdName) |
| 1286 |
Tcl_Interp *interp; |
| 1287 |
|
| 1288 |
CONST char *hiddenCmdToken; |
| 1289 |
CONST char *cmdName; |
| 1290 |
{ |
| 1291 |
Interp *iPtr = (Interp *) interp; |
| 1292 |
Command *cmdPtr; |
| 1293 |
Namespace *nsPtr; |
| 1294 |
Tcl_HashEntry *hPtr; |
| 1295 |
Tcl_HashTable *hiddenCmdTablePtr; |
| 1296 |
int new; |
| 1297 |
|
| 1298 |
if (iPtr->flags & DELETED) { |
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
return TCL_ERROR; |
| 1305 |
} |
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
if (strstr(cmdName, "::") != NULL) { |
| 1314 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 1315 |
"can not expose to a namespace ", |
| 1316 |
"(use expose to toplevel, then rename)", |
| 1317 |
(char *) NULL); |
| 1318 |
return TCL_ERROR; |
| 1319 |
} |
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
hPtr = NULL; |
| 1326 |
hiddenCmdTablePtr = iPtr->hiddenCmdTablePtr; |
| 1327 |
if (hiddenCmdTablePtr != NULL) { |
| 1328 |
hPtr = Tcl_FindHashEntry(hiddenCmdTablePtr, hiddenCmdToken); |
| 1329 |
} |
| 1330 |
if (hPtr == (Tcl_HashEntry *) NULL) { |
| 1331 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 1332 |
"unknown hidden command \"", hiddenCmdToken, |
| 1333 |
"\"", (char *) NULL); |
| 1334 |
return TCL_ERROR; |
| 1335 |
} |
| 1336 |
cmdPtr = (Command *) Tcl_GetHashValue(hPtr); |
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
if ( cmdPtr->nsPtr != iPtr->globalNsPtr ) { |
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 1351 |
"trying to expose a non global command name space command", |
| 1352 |
(char *) NULL); |
| 1353 |
return TCL_ERROR; |
| 1354 |
} |
| 1355 |
|
| 1356 |
|
| 1357 |
nsPtr = cmdPtr->nsPtr; |
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
hPtr = Tcl_CreateHashEntry(&nsPtr->cmdTable, cmdName, &new); |
| 1365 |
if (!new) { |
| 1366 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 1367 |
"exposed command \"", cmdName, |
| 1368 |
"\" already exists", (char *) NULL); |
| 1369 |
return TCL_ERROR; |
| 1370 |
} |
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
if (cmdPtr->hPtr != NULL) { |
| 1378 |
Tcl_DeleteHashEntry(cmdPtr->hPtr); |
| 1379 |
cmdPtr->hPtr = NULL; |
| 1380 |
} |
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
cmdPtr->hPtr = hPtr; |
| 1389 |
|
| 1390 |
Tcl_SetHashValue(hPtr, (ClientData) cmdPtr); |
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
if (cmdPtr->compileProc != NULL) { |
| 1410 |
iPtr->compileEpoch++; |
| 1411 |
} |
| 1412 |
return TCL_OK; |
| 1413 |
} |
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
Tcl_Command |
| 1439 |
Tcl_CreateCommand(interp, cmdName, proc, clientData, deleteProc) |
| 1440 |
Tcl_Interp *interp; |
| 1441 |
|
| 1442 |
CONST char *cmdName; |
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
Tcl_CmdProc *proc; |
| 1447 |
ClientData clientData; |
| 1448 |
Tcl_CmdDeleteProc *deleteProc; |
| 1449 |
|
| 1450 |
|
| 1451 |
{ |
| 1452 |
Interp *iPtr = (Interp *) interp; |
| 1453 |
ImportRef *oldRefPtr = NULL; |
| 1454 |
Namespace *nsPtr, *dummy1, *dummy2; |
| 1455 |
Command *cmdPtr, *refCmdPtr; |
| 1456 |
Tcl_HashEntry *hPtr; |
| 1457 |
CONST char *tail; |
| 1458 |
int new; |
| 1459 |
ImportedCmdData *dataPtr; |
| 1460 |
|
| 1461 |
if (iPtr->flags & DELETED) { |
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
return (Tcl_Command) NULL; |
| 1468 |
} |
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
if (strstr(cmdName, "::") != NULL) { |
| 1477 |
TclGetNamespaceForQualName(interp, cmdName, (Namespace *) NULL, |
| 1478 |
CREATE_NS_IF_UNKNOWN, &nsPtr, &dummy1, &dummy2, &tail); |
| 1479 |
if ((nsPtr == NULL) || (tail == NULL)) { |
| 1480 |
return (Tcl_Command) NULL; |
| 1481 |
} |
| 1482 |
} else { |
| 1483 |
nsPtr = iPtr->globalNsPtr; |
| 1484 |
tail = cmdName; |
| 1485 |
} |
| 1486 |
|
| 1487 |
hPtr = Tcl_CreateHashEntry(&nsPtr->cmdTable, tail, &new); |
| 1488 |
if (!new) { |
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
cmdPtr = (Command *) Tcl_GetHashValue(hPtr); |
| 1497 |
oldRefPtr = cmdPtr->importRefPtr; |
| 1498 |
cmdPtr->importRefPtr = NULL; |
| 1499 |
|
| 1500 |
Tcl_DeleteCommandFromToken(interp, (Tcl_Command) cmdPtr); |
| 1501 |
hPtr = Tcl_CreateHashEntry(&nsPtr->cmdTable, tail, &new); |
| 1502 |
if (!new) { |
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
ckfree((char*) Tcl_GetHashValue(hPtr)); |
| 1510 |
} |
| 1511 |
} |
| 1512 |
cmdPtr = (Command *) ckalloc(sizeof(Command)); |
| 1513 |
Tcl_SetHashValue(hPtr, cmdPtr); |
| 1514 |
cmdPtr->hPtr = hPtr; |
| 1515 |
cmdPtr->nsPtr = nsPtr; |
| 1516 |
cmdPtr->refCount = 1; |
| 1517 |
cmdPtr->cmdEpoch = 0; |
| 1518 |
cmdPtr->compileProc = (CompileProc *) NULL; |
| 1519 |
cmdPtr->objProc = TclInvokeStringCommand; |
| 1520 |
cmdPtr->objClientData = (ClientData) cmdPtr; |
| 1521 |
cmdPtr->proc = proc; |
| 1522 |
cmdPtr->clientData = clientData; |
| 1523 |
cmdPtr->deleteProc = deleteProc; |
| 1524 |
cmdPtr->deleteData = clientData; |
| 1525 |
cmdPtr->flags = 0; |
| 1526 |
cmdPtr->importRefPtr = NULL; |
| 1527 |
cmdPtr->tracePtr = NULL; |
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
if (oldRefPtr != NULL) { |
| 1535 |
cmdPtr->importRefPtr = oldRefPtr; |
| 1536 |
while (oldRefPtr != NULL) { |
| 1537 |
refCmdPtr = oldRefPtr->importedCmdPtr; |
| 1538 |
dataPtr = (ImportedCmdData*)refCmdPtr->objClientData; |
| 1539 |
dataPtr->realCmdPtr = cmdPtr; |
| 1540 |
oldRefPtr = oldRefPtr->nextPtr; |
| 1541 |
} |
| 1542 |
} |
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
TclResetShadowedCmdRefs(interp, cmdPtr); |
| 1552 |
return (Tcl_Command) cmdPtr; |
| 1553 |
} |
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
Tcl_Command |
| 1584 |
Tcl_CreateObjCommand(interp, cmdName, proc, clientData, deleteProc) |
| 1585 |
Tcl_Interp *interp; |
| 1586 |
|
| 1587 |
CONST char *cmdName; |
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
Tcl_ObjCmdProc *proc; |
| 1592 |
|
| 1593 |
ClientData clientData; |
| 1594 |
|
| 1595 |
Tcl_CmdDeleteProc *deleteProc; |
| 1596 |
|
| 1597 |
|
| 1598 |
{ |
| 1599 |
Interp *iPtr = (Interp *) interp; |
| 1600 |
ImportRef *oldRefPtr = NULL; |
| 1601 |
Namespace *nsPtr, *dummy1, *dummy2; |
| 1602 |
Command *cmdPtr, *refCmdPtr; |
| 1603 |
Tcl_HashEntry *hPtr; |
| 1604 |
CONST char *tail; |
| 1605 |
int new; |
| 1606 |
ImportedCmdData *dataPtr; |
| 1607 |
|
| 1608 |
if (iPtr->flags & DELETED) { |
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
return (Tcl_Command) NULL; |
| 1615 |
} |
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
if (strstr(cmdName, "::") != NULL) { |
| 1624 |
TclGetNamespaceForQualName(interp, cmdName, (Namespace *) NULL, |
| 1625 |
CREATE_NS_IF_UNKNOWN, &nsPtr, &dummy1, &dummy2, &tail); |
| 1626 |
if ((nsPtr == NULL) || (tail == NULL)) { |
| 1627 |
return (Tcl_Command) NULL; |
| 1628 |
} |
| 1629 |
} else { |
| 1630 |
nsPtr = iPtr->globalNsPtr; |
| 1631 |
tail = cmdName; |
| 1632 |
} |
| 1633 |
|
| 1634 |
hPtr = Tcl_CreateHashEntry(&nsPtr->cmdTable, tail, &new); |
| 1635 |
if (!new) { |
| 1636 |
cmdPtr = (Command *) Tcl_GetHashValue(hPtr); |
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
if (cmdPtr->objProc == TclInvokeStringCommand) { |
| 1645 |
cmdPtr->objProc = proc; |
| 1646 |
cmdPtr->objClientData = clientData; |
| 1647 |
cmdPtr->deleteProc = deleteProc; |
| 1648 |
cmdPtr->deleteData = clientData; |
| 1649 |
return (Tcl_Command) cmdPtr; |
| 1650 |
} |
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
oldRefPtr = cmdPtr->importRefPtr; |
| 1660 |
cmdPtr->importRefPtr = NULL; |
| 1661 |
|
| 1662 |
Tcl_DeleteCommandFromToken(interp, (Tcl_Command) cmdPtr); |
| 1663 |
hPtr = Tcl_CreateHashEntry(&nsPtr->cmdTable, tail, &new); |
| 1664 |
if (!new) { |
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
ckfree((char *) Tcl_GetHashValue(hPtr)); |
| 1672 |
} |
| 1673 |
} |
| 1674 |
cmdPtr = (Command *) ckalloc(sizeof(Command)); |
| 1675 |
Tcl_SetHashValue(hPtr, cmdPtr); |
| 1676 |
cmdPtr->hPtr = hPtr; |
| 1677 |
cmdPtr->nsPtr = nsPtr; |
| 1678 |
cmdPtr->refCount = 1; |
| 1679 |
cmdPtr->cmdEpoch = 0; |
| 1680 |
cmdPtr->compileProc = (CompileProc *) NULL; |
| 1681 |
cmdPtr->objProc = proc; |
| 1682 |
cmdPtr->objClientData = clientData; |
| 1683 |
cmdPtr->proc = TclInvokeObjectCommand; |
| 1684 |
cmdPtr->clientData = (ClientData) cmdPtr; |
| 1685 |
cmdPtr->deleteProc = deleteProc; |
| 1686 |
cmdPtr->deleteData = clientData; |
| 1687 |
cmdPtr->flags = 0; |
| 1688 |
cmdPtr->importRefPtr = NULL; |
| 1689 |
cmdPtr->tracePtr = NULL; |
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
if (oldRefPtr != NULL) { |
| 1697 |
cmdPtr->importRefPtr = oldRefPtr; |
| 1698 |
while (oldRefPtr != NULL) { |
| 1699 |
refCmdPtr = oldRefPtr->importedCmdPtr; |
| 1700 |
dataPtr = (ImportedCmdData*)refCmdPtr->objClientData; |
| 1701 |
dataPtr->realCmdPtr = cmdPtr; |
| 1702 |
oldRefPtr = oldRefPtr->nextPtr; |
| 1703 |
} |
| 1704 |
} |
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
TclResetShadowedCmdRefs(interp, cmdPtr); |
| 1714 |
return (Tcl_Command) cmdPtr; |
| 1715 |
} |
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
int |
| 1739 |
TclInvokeStringCommand(clientData, interp, objc, objv) |
| 1740 |
ClientData clientData; |
| 1741 |
Tcl_Interp *interp; |
| 1742 |
register int objc; |
| 1743 |
Tcl_Obj *CONST objv[]; |
| 1744 |
{ |
| 1745 |
register Command *cmdPtr = (Command *) clientData; |
| 1746 |
register int i; |
| 1747 |
int result; |
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
#define NUM_ARGS 20 |
| 1756 |
CONST char *(argStorage[NUM_ARGS]); |
| 1757 |
CONST char **argv = argStorage; |
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
if ((objc + 1) > NUM_ARGS) { |
| 1766 |
argv = (CONST char **) ckalloc((unsigned)(objc + 1) * sizeof(char *)); |
| 1767 |
} |
| 1768 |
|
| 1769 |
for (i = 0; i < objc; i++) { |
| 1770 |
argv[i] = Tcl_GetString(objv[i]); |
| 1771 |
} |
| 1772 |
argv[objc] = 0; |
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
result = (*cmdPtr->proc)(cmdPtr->clientData, interp, objc, argv); |
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
if (argv != argStorage) { |
| 1785 |
ckfree((char *) argv); |
| 1786 |
} |
| 1787 |
return result; |
| 1788 |
#undef NUM_ARGS |
| 1789 |
} |
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
int |
| 1813 |
TclInvokeObjectCommand(clientData, interp, argc, argv) |
| 1814 |
ClientData clientData; |
| 1815 |
Tcl_Interp *interp; |
| 1816 |
int argc; |
| 1817 |
register CONST char **argv; |
| 1818 |
{ |
| 1819 |
Command *cmdPtr = (Command *) clientData; |
| 1820 |
register Tcl_Obj *objPtr; |
| 1821 |
register int i; |
| 1822 |
int length, result; |
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
#define NUM_ARGS 20 |
| 1831 |
Tcl_Obj *(argStorage[NUM_ARGS]); |
| 1832 |
register Tcl_Obj **objv = argStorage; |
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
if (argc > NUM_ARGS) { |
| 1841 |
objv = (Tcl_Obj **) |
| 1842 |
ckalloc((unsigned)(argc * sizeof(Tcl_Obj *))); |
| 1843 |
} |
| 1844 |
|
| 1845 |
for (i = 0; i < argc; i++) { |
| 1846 |
length = strlen(argv[i]); |
| 1847 |
TclNewObj(objPtr); |
| 1848 |
TclInitStringRep(objPtr, argv[i], length); |
| 1849 |
Tcl_IncrRefCount(objPtr); |
| 1850 |
objv[i] = objPtr; |
| 1851 |
} |
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
result = (*cmdPtr->objProc)(cmdPtr->objClientData, interp, argc, objv); |
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
|
| 1863 |
|
| 1864 |
Tcl_SetResult(interp, TclGetString(Tcl_GetObjResult(interp)), |
| 1865 |
TCL_VOLATILE); |
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
for (i = 0; i < argc; i++) { |
| 1873 |
objPtr = objv[i]; |
| 1874 |
Tcl_DecrRefCount(objPtr); |
| 1875 |
} |
| 1876 |
if (objv != argStorage) { |
| 1877 |
ckfree((char *) objv); |
| 1878 |
} |
| 1879 |
return result; |
| 1880 |
#undef NUM_ARGS |
| 1881 |
} |
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
int |
| 1908 |
TclRenameCommand(interp, oldName, newName) |
| 1909 |
Tcl_Interp *interp; |
| 1910 |
char *oldName; |
| 1911 |
char *newName; |
| 1912 |
{ |
| 1913 |
Interp *iPtr = (Interp *) interp; |
| 1914 |
CONST char *newTail; |
| 1915 |
Namespace *cmdNsPtr, *newNsPtr, *dummy1, *dummy2; |
| 1916 |
Tcl_Command cmd; |
| 1917 |
Command *cmdPtr; |
| 1918 |
Tcl_HashEntry *hPtr, *oldHPtr; |
| 1919 |
int new, result; |
| 1920 |
Tcl_Obj* oldFullName; |
| 1921 |
Tcl_DString newFullName; |
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
cmd = Tcl_FindCommand(interp, oldName, (Tcl_Namespace *) NULL, |
| 1929 |
0); |
| 1930 |
cmdPtr = (Command *) cmd; |
| 1931 |
if (cmdPtr == NULL) { |
| 1932 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "can't ", |
| 1933 |
((newName == NULL)||(*newName == '\0'))? "delete":"rename", |
| 1934 |
" \"", oldName, "\": command doesn't exist", (char *) NULL); |
| 1935 |
return TCL_ERROR; |
| 1936 |
} |
| 1937 |
cmdNsPtr = cmdPtr->nsPtr; |
| 1938 |
oldFullName = Tcl_NewObj(); |
| 1939 |
Tcl_IncrRefCount( oldFullName ); |
| 1940 |
Tcl_GetCommandFullName( interp, cmd, oldFullName ); |
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
if ((newName == NULL) || (*newName == '\0')) { |
| 1948 |
Tcl_DeleteCommandFromToken(interp, cmd); |
| 1949 |
result = TCL_OK; |
| 1950 |
goto done; |
| 1951 |
} |
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
TclGetNamespaceForQualName(interp, newName, (Namespace *) NULL, |
| 1961 |
CREATE_NS_IF_UNKNOWN, &newNsPtr, &dummy1, &dummy2, &newTail); |
| 1962 |
|
| 1963 |
if ((newNsPtr == NULL) || (newTail == NULL)) { |
| 1964 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 1965 |
"can't rename to \"", newName, "\": bad command name", |
| 1966 |
(char *) NULL); |
| 1967 |
result = TCL_ERROR; |
| 1968 |
goto done; |
| 1969 |
} |
| 1970 |
if (Tcl_FindHashEntry(&newNsPtr->cmdTable, newTail) != NULL) { |
| 1971 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 1972 |
"can't rename to \"", newName, |
| 1973 |
"\": command already exists", (char *) NULL); |
| 1974 |
result = TCL_ERROR; |
| 1975 |
goto done; |
| 1976 |
} |
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
oldHPtr = cmdPtr->hPtr; |
| 1991 |
hPtr = Tcl_CreateHashEntry(&newNsPtr->cmdTable, newTail, &new); |
| 1992 |
Tcl_SetHashValue(hPtr, (ClientData) cmdPtr); |
| 1993 |
cmdPtr->hPtr = hPtr; |
| 1994 |
cmdPtr->nsPtr = newNsPtr; |
| 1995 |
TclResetShadowedCmdRefs(interp, cmdPtr); |
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
result = TclPreventAliasLoop(interp, interp, (Tcl_Command) cmdPtr); |
| 2003 |
if (result != TCL_OK) { |
| 2004 |
Tcl_DeleteHashEntry(cmdPtr->hPtr); |
| 2005 |
cmdPtr->hPtr = oldHPtr; |
| 2006 |
cmdPtr->nsPtr = cmdNsPtr; |
| 2007 |
goto done; |
| 2008 |
} |
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
Tcl_DStringInit( &newFullName ); |
| 2023 |
Tcl_DStringAppend( &newFullName, newNsPtr->fullName, -1 ); |
| 2024 |
if ( newNsPtr != iPtr->globalNsPtr ) { |
| 2025 |
Tcl_DStringAppend( &newFullName, "::", 2 ); |
| 2026 |
} |
| 2027 |
Tcl_DStringAppend( &newFullName, newTail, -1 ); |
| 2028 |
cmdPtr->refCount++; |
| 2029 |
CallCommandTraces( iPtr, cmdPtr, |
| 2030 |
Tcl_GetString( oldFullName ), |
| 2031 |
Tcl_DStringValue( &newFullName ), |
| 2032 |
TCL_TRACE_RENAME); |
| 2033 |
Tcl_DStringFree( &newFullName ); |
| 2034 |
|
| 2035 |
|
| 2036 |
|
| 2037 |
|
| 2038 |
|
| 2039 |
|
| 2040 |
|
| 2041 |
Tcl_DeleteHashEntry(oldHPtr); |
| 2042 |
cmdPtr->cmdEpoch++; |
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
|
| 2051 |
if (cmdPtr->compileProc != NULL) { |
| 2052 |
iPtr->compileEpoch++; |
| 2053 |
} |
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
TclCleanupCommand(cmdPtr); |
| 2060 |
result = TCL_OK; |
| 2061 |
|
| 2062 |
done: |
| 2063 |
TclDecrRefCount( oldFullName ); |
| 2064 |
return result; |
| 2065 |
} |
| 2066 |
|
| 2067 |
|
| 2068 |
|
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
int |
| 2090 |
Tcl_SetCommandInfo(interp, cmdName, infoPtr) |
| 2091 |
Tcl_Interp *interp; |
| 2092 |
|
| 2093 |
CONST char *cmdName; |
| 2094 |
CONST Tcl_CmdInfo *infoPtr; |
| 2095 |
|
| 2096 |
{ |
| 2097 |
Tcl_Command cmd; |
| 2098 |
|
| 2099 |
cmd = Tcl_FindCommand(interp, cmdName, (Tcl_Namespace *) NULL, |
| 2100 |
0); |
| 2101 |
|
| 2102 |
return Tcl_SetCommandInfoFromToken( cmd, infoPtr ); |
| 2103 |
|
| 2104 |
} |
| 2105 |
|
| 2106 |
|
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
|
| 2111 |
|
| 2112 |
|
| 2113 |
|
| 2114 |
|
| 2115 |
|
| 2116 |
|
| 2117 |
|
| 2118 |
|
| 2119 |
|
| 2120 |
|
| 2121 |
|
| 2122 |
|
| 2123 |
|
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
int |
| 2129 |
Tcl_SetCommandInfoFromToken( cmd, infoPtr ) |
| 2130 |
Tcl_Command cmd; |
| 2131 |
CONST Tcl_CmdInfo* infoPtr; |
| 2132 |
{ |
| 2133 |
Command* cmdPtr; |
| 2134 |
|
| 2135 |
if (cmd == (Tcl_Command) NULL) { |
| 2136 |
return 0; |
| 2137 |
} |
| 2138 |
|
| 2139 |
|
| 2140 |
|
| 2141 |
|
| 2142 |
|
| 2143 |
cmdPtr = (Command *) cmd; |
| 2144 |
cmdPtr->proc = infoPtr->proc; |
| 2145 |
cmdPtr->clientData = infoPtr->clientData; |
| 2146 |
if (infoPtr->objProc == (Tcl_ObjCmdProc *) NULL) { |
| 2147 |
cmdPtr->objProc = TclInvokeStringCommand; |
| 2148 |
cmdPtr->objClientData = (ClientData) cmdPtr; |
| 2149 |
} else { |
| 2150 |
cmdPtr->objProc = infoPtr->objProc; |
| 2151 |
cmdPtr->objClientData = infoPtr->objClientData; |
| 2152 |
} |
| 2153 |
cmdPtr->deleteProc = infoPtr->deleteProc; |
| 2154 |
cmdPtr->deleteData = infoPtr->deleteData; |
| 2155 |
return 1; |
| 2156 |
} |
| 2157 |
|
| 2158 |
|
| 2159 |
|
| 2160 |
|
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
int |
| 2178 |
Tcl_GetCommandInfo(interp, cmdName, infoPtr) |
| 2179 |
Tcl_Interp *interp; |
| 2180 |
|
| 2181 |
CONST char *cmdName; |
| 2182 |
Tcl_CmdInfo *infoPtr; |
| 2183 |
|
| 2184 |
{ |
| 2185 |
Tcl_Command cmd; |
| 2186 |
|
| 2187 |
cmd = Tcl_FindCommand(interp, cmdName, (Tcl_Namespace *) NULL, |
| 2188 |
0); |
| 2189 |
|
| 2190 |
return Tcl_GetCommandInfoFromToken( cmd, infoPtr ); |
| 2191 |
|
| 2192 |
} |
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
|
| 2202 |
|
| 2203 |
|
| 2204 |
|
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
int |
| 2213 |
Tcl_GetCommandInfoFromToken( cmd, infoPtr ) |
| 2214 |
Tcl_Command cmd; |
| 2215 |
Tcl_CmdInfo* infoPtr; |
| 2216 |
{ |
| 2217 |
|
| 2218 |
Command* cmdPtr; |
| 2219 |
|
| 2220 |
if ( cmd == (Tcl_Command) NULL ) { |
| 2221 |
return 0; |
| 2222 |
} |
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
|
| 2228 |
|
| 2229 |
cmdPtr = (Command *) cmd; |
| 2230 |
infoPtr->isNativeObjectProc = |
| 2231 |
(cmdPtr->objProc != TclInvokeStringCommand); |
| 2232 |
infoPtr->objProc = cmdPtr->objProc; |
| 2233 |
infoPtr->objClientData = cmdPtr->objClientData; |
| 2234 |
infoPtr->proc = cmdPtr->proc; |
| 2235 |
infoPtr->clientData = cmdPtr->clientData; |
| 2236 |
infoPtr->deleteProc = cmdPtr->deleteProc; |
| 2237 |
infoPtr->deleteData = cmdPtr->deleteData; |
| 2238 |
infoPtr->namespacePtr = (Tcl_Namespace *) cmdPtr->nsPtr; |
| 2239 |
|
| 2240 |
return 1; |
| 2241 |
|
| 2242 |
} |
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
|
| 2247 |
|
| 2248 |
|
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
|
| 2255 |
|
| 2256 |
|
| 2257 |
|
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
|
| 2262 |
CONST char * |
| 2263 |
Tcl_GetCommandName(interp, command) |
| 2264 |
Tcl_Interp *interp; |
| 2265 |
Tcl_Command command; |
| 2266 |
|
| 2267 |
|
| 2268 |
{ |
| 2269 |
Command *cmdPtr = (Command *) command; |
| 2270 |
|
| 2271 |
if ((cmdPtr == NULL) || (cmdPtr->hPtr == NULL)) { |
| 2272 |
|
| 2273 |
|
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
return ""; |
| 2280 |
} |
| 2281 |
return Tcl_GetHashKey(cmdPtr->hPtr->tablePtr, cmdPtr->hPtr); |
| 2282 |
} |
| 2283 |
|
| 2284 |
|
| 2285 |
|
| 2286 |
|
| 2287 |
|
| 2288 |
|
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
|
| 2293 |
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
void |
| 2305 |
Tcl_GetCommandFullName(interp, command, objPtr) |
| 2306 |
Tcl_Interp *interp; |
| 2307 |
Tcl_Command command; |
| 2308 |
|
| 2309 |
|
| 2310 |
Tcl_Obj *objPtr; |
| 2311 |
|
| 2312 |
|
| 2313 |
{ |
| 2314 |
Interp *iPtr = (Interp *) interp; |
| 2315 |
register Command *cmdPtr = (Command *) command; |
| 2316 |
char *name; |
| 2317 |
|
| 2318 |
|
| 2319 |
|
| 2320 |
|
| 2321 |
|
| 2322 |
|
| 2323 |
if (cmdPtr != NULL) { |
| 2324 |
if (cmdPtr->nsPtr != NULL) { |
| 2325 |
Tcl_AppendToObj(objPtr, cmdPtr->nsPtr->fullName, -1); |
| 2326 |
if (cmdPtr->nsPtr != iPtr->globalNsPtr) { |
| 2327 |
Tcl_AppendToObj(objPtr, "::", 2); |
| 2328 |
} |
| 2329 |
} |
| 2330 |
if (cmdPtr->hPtr != NULL) { |
| 2331 |
name = Tcl_GetHashKey(cmdPtr->hPtr->tablePtr, cmdPtr->hPtr); |
| 2332 |
Tcl_AppendToObj(objPtr, name, -1); |
| 2333 |
} |
| 2334 |
} |
| 2335 |
} |
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
|
| 2344 |
|
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
|
| 2349 |
|
| 2350 |
|
| 2351 |
|
| 2352 |
|
| 2353 |
|
| 2354 |
|
| 2355 |
int |
| 2356 |
Tcl_DeleteCommand(interp, cmdName) |
| 2357 |
Tcl_Interp *interp; |
| 2358 |
|
| 2359 |
CONST char *cmdName; |
| 2360 |
{ |
| 2361 |
Tcl_Command cmd; |
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
cmd = Tcl_FindCommand(interp, cmdName, (Tcl_Namespace *) NULL, |
| 2368 |
0); |
| 2369 |
if (cmd == (Tcl_Command) NULL) { |
| 2370 |
return -1; |
| 2371 |
} |
| 2372 |
return Tcl_DeleteCommandFromToken(interp, cmd); |
| 2373 |
} |
| 2374 |
|
| 2375 |
|
| 2376 |
|
| 2377 |
|
| 2378 |
|
| 2379 |
|
| 2380 |
|
| 2381 |
|
| 2382 |
|
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
int |
| 2396 |
Tcl_DeleteCommandFromToken(interp, cmd) |
| 2397 |
Tcl_Interp *interp; |
| 2398 |
|
| 2399 |
Tcl_Command cmd; |
| 2400 |
{ |
| 2401 |
Interp *iPtr = (Interp *) interp; |
| 2402 |
Command *cmdPtr = (Command *) cmd; |
| 2403 |
ImportRef *refPtr, *nextRefPtr; |
| 2404 |
Tcl_Command importCmd; |
| 2405 |
|
| 2406 |
|
| 2407 |
|
| 2408 |
|
| 2409 |
|
| 2410 |
|
| 2411 |
|
| 2412 |
|
| 2413 |
|
| 2414 |
|
| 2415 |
if (cmdPtr->flags & CMD_IS_DELETED) { |
| 2416 |
|
| 2417 |
|
| 2418 |
|
| 2419 |
|
| 2420 |
|
| 2421 |
|
| 2422 |
Tcl_DeleteHashEntry(cmdPtr->hPtr); |
| 2423 |
cmdPtr->hPtr = NULL; |
| 2424 |
return 0; |
| 2425 |
} |
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
cmdPtr->flags |= CMD_IS_DELETED; |
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
|
| 2440 |
|
| 2441 |
if (cmdPtr->tracePtr != NULL) { |
| 2442 |
CommandTrace *tracePtr; |
| 2443 |
CallCommandTraces(iPtr,cmdPtr,NULL,NULL,TCL_TRACE_DELETE); |
| 2444 |
|
| 2445 |
tracePtr = cmdPtr->tracePtr; |
| 2446 |
while (tracePtr != NULL) { |
| 2447 |
CommandTrace *nextPtr = tracePtr->nextPtr; |
| 2448 |
if ((--tracePtr->refCount) <= 0) { |
| 2449 |
ckfree((char*)tracePtr); |
| 2450 |
} |
| 2451 |
tracePtr = nextPtr; |
| 2452 |
} |
| 2453 |
cmdPtr->tracePtr = NULL; |
| 2454 |
} |
| 2455 |
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
|
| 2460 |
|
| 2461 |
|
| 2462 |
|
| 2463 |
|
| 2464 |
|
| 2465 |
if (cmdPtr->compileProc != NULL) { |
| 2466 |
iPtr->compileEpoch++; |
| 2467 |
} |
| 2468 |
|
| 2469 |
if (cmdPtr->deleteProc != NULL) { |
| 2470 |
|
| 2471 |
|
| 2472 |
|
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
|
| 2477 |
|
| 2478 |
|
| 2479 |
|
| 2480 |
|
| 2481 |
|
| 2482 |
|
| 2483 |
|
| 2484 |
|
| 2485 |
|
| 2486 |
|
| 2487 |
(*cmdPtr->deleteProc)(cmdPtr->deleteData); |
| 2488 |
} |
| 2489 |
|
| 2490 |
|
| 2491 |
|
| 2492 |
|
| 2493 |
|
| 2494 |
|
| 2495 |
cmdPtr->cmdEpoch++; |
| 2496 |
|
| 2497 |
|
| 2498 |
|
| 2499 |
|
| 2500 |
|
| 2501 |
|
| 2502 |
|
| 2503 |
for (refPtr = cmdPtr->importRefPtr; refPtr != NULL; |
| 2504 |
refPtr = nextRefPtr) { |
| 2505 |
nextRefPtr = refPtr->nextPtr; |
| 2506 |
importCmd = (Tcl_Command) refPtr->importedCmdPtr; |
| 2507 |
Tcl_DeleteCommandFromToken(interp, importCmd); |
| 2508 |
} |
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
|
| 2513 |
|
| 2514 |
|
| 2515 |
|
| 2516 |
|
| 2517 |
if (cmdPtr->hPtr != NULL) { |
| 2518 |
Tcl_DeleteHashEntry(cmdPtr->hPtr); |
| 2519 |
} |
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
|
| 2525 |
|
| 2526 |
|
| 2527 |
|
| 2528 |
|
| 2529 |
cmdPtr->objProc = NULL; |
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
|
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
|
| 2538 |
|
| 2539 |
|
| 2540 |
TclCleanupCommand(cmdPtr); |
| 2541 |
return 0; |
| 2542 |
} |
| 2543 |
|
| 2544 |
static char * |
| 2545 |
CallCommandTraces(iPtr, cmdPtr, oldName, newName, flags) |
| 2546 |
Interp *iPtr; |
| 2547 |
Command *cmdPtr; |
| 2548 |
|
| 2549 |
CONST char *oldName; |
| 2550 |
|
| 2551 |
CONST char *newName; |
| 2552 |
|
| 2553 |
int flags; |
| 2554 |
|
| 2555 |
|
| 2556 |
{ |
| 2557 |
register CommandTrace *tracePtr; |
| 2558 |
ActiveCommandTrace active; |
| 2559 |
char *result; |
| 2560 |
Tcl_Obj *oldNamePtr = NULL; |
| 2561 |
int mask = (TCL_TRACE_DELETE | TCL_TRACE_RENAME); |
| 2562 |
|
| 2563 |
flags &= mask; |
| 2564 |
|
| 2565 |
if (cmdPtr->flags & CMD_TRACE_ACTIVE) { |
| 2566 |
|
| 2567 |
|
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
|
| 2572 |
|
| 2573 |
|
| 2574 |
|
| 2575 |
|
| 2576 |
if (cmdPtr->flags & TCL_TRACE_RENAME) { |
| 2577 |
flags &= ~TCL_TRACE_RENAME; |
| 2578 |
} |
| 2579 |
if (flags == 0) { |
| 2580 |
return NULL; |
| 2581 |
} |
| 2582 |
} |
| 2583 |
cmdPtr->flags |= CMD_TRACE_ACTIVE; |
| 2584 |
cmdPtr->refCount++; |
| 2585 |
|
| 2586 |
result = NULL; |
| 2587 |
active.nextPtr = iPtr->activeCmdTracePtr; |
| 2588 |
iPtr->activeCmdTracePtr = &active; |
| 2589 |
|
| 2590 |
if (flags & TCL_TRACE_DELETE) { |
| 2591 |
flags |= TCL_TRACE_DESTROYED; |
| 2592 |
} |
| 2593 |
active.cmdPtr = cmdPtr; |
| 2594 |
|
| 2595 |
Tcl_Preserve((ClientData) iPtr); |
| 2596 |
|
| 2597 |
for (tracePtr = cmdPtr->tracePtr; tracePtr != NULL; |
| 2598 |
tracePtr = active.nextTracePtr) { |
| 2599 |
int traceFlags = (tracePtr->flags & mask); |
| 2600 |
|
| 2601 |
active.nextTracePtr = tracePtr->nextPtr; |
| 2602 |
if (!(traceFlags & flags)) { |
| 2603 |
continue; |
| 2604 |
} |
| 2605 |
cmdPtr->flags |= traceFlags; |
| 2606 |
if (oldName == NULL) { |
| 2607 |
TclNewObj(oldNamePtr); |
| 2608 |
Tcl_IncrRefCount(oldNamePtr); |
| 2609 |
Tcl_GetCommandFullName((Tcl_Interp *) iPtr, |
| 2610 |
(Tcl_Command) cmdPtr, oldNamePtr); |
| 2611 |
oldName = TclGetString(oldNamePtr); |
| 2612 |
} |
| 2613 |
tracePtr->refCount++; |
| 2614 |
(*tracePtr->traceProc)(tracePtr->clientData, |
| 2615 |
(Tcl_Interp *) iPtr, oldName, newName, flags); |
| 2616 |
cmdPtr->flags &= ~traceFlags; |
| 2617 |
if ((--tracePtr->refCount) <= 0) { |
| 2618 |
ckfree((char*)tracePtr); |
| 2619 |
} |
| 2620 |
} |
| 2621 |
|
| 2622 |
|
| 2623 |
|
| 2624 |
|
| 2625 |
|
| 2626 |
|
| 2627 |
if (oldNamePtr != NULL) { |
| 2628 |
TclDecrRefCount(oldNamePtr); |
| 2629 |
} |
| 2630 |
|
| 2631 |
|
| 2632 |
|
| 2633 |
|
| 2634 |
|
| 2635 |
|
| 2636 |
cmdPtr->flags &= ~CMD_TRACE_ACTIVE; |
| 2637 |
cmdPtr->refCount--; |
| 2638 |
iPtr->activeCmdTracePtr = active.nextPtr; |
| 2639 |
Tcl_Release((ClientData) iPtr); |
| 2640 |
return result; |
| 2641 |
} |
| 2642 |
|
| 2643 |
|
| 2644 |
|
| 2645 |
|
| 2646 |
|
| 2647 |
|
| 2648 |
|
| 2649 |
|
| 2650 |
|
| 2651 |
|
| 2652 |
|
| 2653 |
|
| 2654 |
|
| 2655 |
|
| 2656 |
|
| 2657 |
|
| 2658 |
|
| 2659 |
|
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
|
| 2664 |
void |
| 2665 |
TclCleanupCommand(cmdPtr) |
| 2666 |
register Command *cmdPtr; |
| 2667 |
|
| 2668 |
{ |
| 2669 |
cmdPtr->refCount--; |
| 2670 |
if (cmdPtr->refCount <= 0) { |
| 2671 |
ckfree((char *) cmdPtr); |
| 2672 |
} |
| 2673 |
} |
| 2674 |
|
| 2675 |
|
| 2676 |
|
| 2677 |
|
| 2678 |
|
| 2679 |
|
| 2680 |
|
| 2681 |
|
| 2682 |
|
| 2683 |
|
| 2684 |
|
| 2685 |
|
| 2686 |
|
| 2687 |
|
| 2688 |
|
| 2689 |
|
| 2690 |
|
| 2691 |
|
| 2692 |
|
| 2693 |
|
| 2694 |
|
| 2695 |
|
| 2696 |
|
| 2697 |
|
| 2698 |
void |
| 2699 |
Tcl_CreateMathFunc(interp, name, numArgs, argTypes, proc, clientData) |
| 2700 |
Tcl_Interp *interp; |
| 2701 |
|
| 2702 |
CONST char *name; |
| 2703 |
int numArgs; |
| 2704 |
|
| 2705 |
Tcl_ValueType *argTypes; |
| 2706 |
|
| 2707 |
Tcl_MathProc *proc; |
| 2708 |
|
| 2709 |
ClientData clientData; |
| 2710 |
|
| 2711 |
{ |
| 2712 |
Interp *iPtr = (Interp *) interp; |
| 2713 |
Tcl_HashEntry *hPtr; |
| 2714 |
MathFunc *mathFuncPtr; |
| 2715 |
int new, i; |
| 2716 |
|
| 2717 |
hPtr = Tcl_CreateHashEntry(&iPtr->mathFuncTable, name, &new); |
| 2718 |
if (new) { |
| 2719 |
Tcl_SetHashValue(hPtr, ckalloc(sizeof(MathFunc))); |
| 2720 |
} |
| 2721 |
mathFuncPtr = (MathFunc *) Tcl_GetHashValue(hPtr); |
| 2722 |
|
| 2723 |
if (!new) { |
| 2724 |
if (mathFuncPtr->builtinFuncIndex >= 0) { |
| 2725 |
|
| 2726 |
|
| 2727 |
|
| 2728 |
|
| 2729 |
|
| 2730 |
|
| 2731 |
|
| 2732 |
|
| 2733 |
|
| 2734 |
iPtr->compileEpoch++; |
| 2735 |
} else { |
| 2736 |
|
| 2737 |
|
| 2738 |
|
| 2739 |
|
| 2740 |
|
| 2741 |
|
| 2742 |
if (numArgs != mathFuncPtr->numArgs) { |
| 2743 |
iPtr->compileEpoch++; |
| 2744 |
} |
| 2745 |
} |
| 2746 |
} |
| 2747 |
|
| 2748 |
mathFuncPtr->builtinFuncIndex = -1; |
| 2749 |
if (numArgs > MAX_MATH_ARGS) { |
| 2750 |
numArgs = MAX_MATH_ARGS; |
| 2751 |
} |
| 2752 |
mathFuncPtr->numArgs = numArgs; |
| 2753 |
for (i = 0; i < numArgs; i++) { |
| 2754 |
mathFuncPtr->argTypes[i] = argTypes[i]; |
| 2755 |
} |
| 2756 |
mathFuncPtr->proc = proc; |
| 2757 |
mathFuncPtr->clientData = clientData; |
| 2758 |
} |
| 2759 |
|
| 2760 |
|
| 2761 |
|
| 2762 |
|
| 2763 |
|
| 2764 |
|
| 2765 |
|
| 2766 |
|
| 2767 |
|
| 2768 |
|
| 2769 |
|
| 2770 |
|
| 2771 |
|
| 2772 |
|
| 2773 |
|
| 2774 |
|
| 2775 |
|
| 2776 |
|
| 2777 |
|
| 2778 |
|
| 2779 |
|
| 2780 |
|
| 2781 |
|
| 2782 |
|
| 2783 |
|
| 2784 |
int |
| 2785 |
Tcl_GetMathFuncInfo(interp, name, numArgsPtr, argTypesPtr, procPtr, |
| 2786 |
clientDataPtr) |
| 2787 |
Tcl_Interp *interp; |
| 2788 |
CONST char *name; |
| 2789 |
int *numArgsPtr; |
| 2790 |
Tcl_ValueType **argTypesPtr; |
| 2791 |
Tcl_MathProc **procPtr; |
| 2792 |
ClientData *clientDataPtr; |
| 2793 |
{ |
| 2794 |
Interp *iPtr = (Interp *) interp; |
| 2795 |
Tcl_HashEntry *hPtr; |
| 2796 |
MathFunc *mathFuncPtr; |
| 2797 |
Tcl_ValueType *argTypes; |
| 2798 |
int i,numArgs; |
| 2799 |
|
| 2800 |
hPtr = Tcl_FindHashEntry(&iPtr->mathFuncTable, name); |
| 2801 |
if (hPtr == NULL) { |
| 2802 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 2803 |
"math function \"", name, "\" not known in this interpreter", |
| 2804 |
(char *) NULL); |
| 2805 |
return TCL_ERROR; |
| 2806 |
} |
| 2807 |
mathFuncPtr = (MathFunc *) Tcl_GetHashValue(hPtr); |
| 2808 |
|
| 2809 |
*numArgsPtr = numArgs = mathFuncPtr->numArgs; |
| 2810 |
if (numArgs == 0) { |
| 2811 |
|
| 2812 |
numArgs = 1; |
| 2813 |
} |
| 2814 |
*argTypesPtr = argTypes = |
| 2815 |
(Tcl_ValueType *)ckalloc(numArgs * sizeof(Tcl_ValueType)); |
| 2816 |
for (i = 0; i < mathFuncPtr->numArgs; i++) { |
| 2817 |
argTypes[i] = mathFuncPtr->argTypes[i]; |
| 2818 |
} |
| 2819 |
|
| 2820 |
if (mathFuncPtr->builtinFuncIndex == -1) { |
| 2821 |
*procPtr = (Tcl_MathProc *) NULL; |
| 2822 |
} else { |
| 2823 |
*procPtr = mathFuncPtr->proc; |
| 2824 |
*clientDataPtr = mathFuncPtr->clientData; |
| 2825 |
} |
| 2826 |
|
| 2827 |
return TCL_OK; |
| 2828 |
} |
| 2829 |
|
| 2830 |
|
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
|
| 2845 |
|
| 2846 |
|
| 2847 |
|
| 2848 |
|
| 2849 |
Tcl_Obj * |
| 2850 |
Tcl_ListMathFuncs(interp, pattern) |
| 2851 |
Tcl_Interp *interp; |
| 2852 |
CONST char *pattern; |
| 2853 |
{ |
| 2854 |
Interp *iPtr = (Interp *) interp; |
| 2855 |
Tcl_Obj *resultList = Tcl_NewObj(); |
| 2856 |
register Tcl_HashEntry *hPtr; |
| 2857 |
Tcl_HashSearch hSearch; |
| 2858 |
CONST char *name; |
| 2859 |
|
| 2860 |
for (hPtr = Tcl_FirstHashEntry(&iPtr->mathFuncTable, &hSearch); |
| 2861 |
hPtr != NULL; hPtr = Tcl_NextHashEntry(&hSearch)) { |
| 2862 |
name = Tcl_GetHashKey(&iPtr->mathFuncTable, hPtr); |
| 2863 |
if ((pattern == NULL || Tcl_StringMatch(name, pattern)) && |
| 2864 |
|
| 2865 |
Tcl_ListObjAppendElement(interp, resultList, |
| 2866 |
Tcl_NewStringObj(name,-1)) != TCL_OK) { |
| 2867 |
Tcl_DecrRefCount(resultList); |
| 2868 |
return NULL; |
| 2869 |
} |
| 2870 |
} |
| 2871 |
return resultList; |
| 2872 |
} |
| 2873 |
|
| 2874 |
|
| 2875 |
|
| 2876 |
|
| 2877 |
|
| 2878 |
|
| 2879 |
|
| 2880 |
|
| 2881 |
|
| 2882 |
|
| 2883 |
|
| 2884 |
|
| 2885 |
|
| 2886 |
|
| 2887 |
|
| 2888 |
|
| 2889 |
|
| 2890 |
|
| 2891 |
|
| 2892 |
|
| 2893 |
int |
| 2894 |
TclInterpReady(interp) |
| 2895 |
Tcl_Interp *interp; |
| 2896 |
{ |
| 2897 |
register Interp *iPtr = (Interp *) interp; |
| 2898 |
|
| 2899 |
|
| 2900 |
|
| 2901 |
|
| 2902 |
|
| 2903 |
|
| 2904 |
Tcl_ResetResult(interp); |
| 2905 |
|
| 2906 |
|
| 2907 |
|
| 2908 |
|
| 2909 |
|
| 2910 |
if (iPtr->flags & DELETED) { |
| 2911 |
Tcl_ResetResult(interp); |
| 2912 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), |
| 2913 |
"attempt to call eval in deleted interpreter", -1); |
| 2914 |
Tcl_SetErrorCode(interp, "CORE", "IDELETE", |
| 2915 |
"attempt to call eval in deleted interpreter", |
| 2916 |
(char *) NULL); |
| 2917 |
return TCL_ERROR; |
| 2918 |
} |
| 2919 |
|
| 2920 |
|
| 2921 |
|
| 2922 |
|
| 2923 |
|
| 2924 |
|
| 2925 |
if (((iPtr->numLevels) > iPtr->maxNestingDepth) |
| 2926 |
|| (TclpCheckStackSpace() == 0)) { |
| 2927 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), |
| 2928 |
"too many nested evaluations (infinite loop?)", -1); |
| 2929 |
return TCL_ERROR; |
| 2930 |
} |
| 2931 |
|
| 2932 |
return TCL_OK; |
| 2933 |
} |
| 2934 |
|
| 2935 |
|
| 2936 |
|
| 2937 |
|
| 2938 |
|
| 2939 |
|
| 2940 |
|
| 2941 |
|
| 2942 |
|
| 2943 |
|
| 2944 |
|
| 2945 |
|
| 2946 |
|
| 2947 |
|
| 2948 |
|
| 2949 |
|
| 2950 |
|
| 2951 |
|
| 2952 |
|
| 2953 |
|
| 2954 |
|
| 2955 |
|
| 2956 |
int |
| 2957 |
TclEvalObjvInternal(interp, objc, objv, command, length, flags) |
| 2958 |
Tcl_Interp *interp; |
| 2959 |
|
| 2960 |
|
| 2961 |
int objc; |
| 2962 |
Tcl_Obj *CONST objv[]; |
| 2963 |
|
| 2964 |
CONST char *command; |
| 2965 |
|
| 2966 |
|
| 2967 |
|
| 2968 |
|
| 2969 |
|
| 2970 |
|
| 2971 |
int length; |
| 2972 |
|
| 2973 |
|
| 2974 |
int flags; |
| 2975 |
|
| 2976 |
|
| 2977 |
|
| 2978 |
|
| 2979 |
{ |
| 2980 |
Command *cmdPtr; |
| 2981 |
Interp *iPtr = (Interp *) interp; |
| 2982 |
Tcl_Obj **newObjv; |
| 2983 |
int i; |
| 2984 |
CallFrame *savedVarFramePtr; |
| 2985 |
|
| 2986 |
int code = TCL_OK; |
| 2987 |
int traceCode = TCL_OK; |
| 2988 |
int checkTraces = 1; |
| 2989 |
|
| 2990 |
if (TclInterpReady(interp) == TCL_ERROR) { |
| 2991 |
return TCL_ERROR; |
| 2992 |
} |
| 2993 |
|
| 2994 |
if (objc == 0) { |
| 2995 |
return TCL_OK; |
| 2996 |
} |
| 2997 |
|
| 2998 |
|
| 2999 |
|
| 3000 |
|
| 3001 |
|
| 3002 |
while (1) { |
| 3003 |
|
| 3004 |
|
| 3005 |
|
| 3006 |
|
| 3007 |
|
| 3008 |
|
| 3009 |
|
| 3010 |
|
| 3011 |
|
| 3012 |
|
| 3013 |
|
| 3014 |
|
| 3015 |
|
| 3016 |
savedVarFramePtr = iPtr->varFramePtr; |
| 3017 |
if (flags & (TCL_EVAL_INVOKE | TCL_EVAL_GLOBAL)) { |
| 3018 |
iPtr->varFramePtr = NULL; |
| 3019 |
} |
| 3020 |
cmdPtr = (Command *) Tcl_GetCommandFromObj(interp, objv[0]); |
| 3021 |
iPtr->varFramePtr = savedVarFramePtr; |
| 3022 |
|
| 3023 |
if (cmdPtr == NULL) { |
| 3024 |
newObjv = (Tcl_Obj **) ckalloc((unsigned) |
| 3025 |
((objc + 1) * sizeof (Tcl_Obj *))); |
| 3026 |
for (i = objc-1; i >= 0; i--) { |
| 3027 |
newObjv[i+1] = objv[i]; |
| 3028 |
} |
| 3029 |
newObjv[0] = Tcl_NewStringObj("::unknown", -1); |
| 3030 |
Tcl_IncrRefCount(newObjv[0]); |
| 3031 |
cmdPtr = (Command *) Tcl_GetCommandFromObj(interp, newObjv[0]); |
| 3032 |
if (cmdPtr == NULL) { |
| 3033 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 3034 |
"invalid command name \"", Tcl_GetString(objv[0]), "\"", |
| 3035 |
(char *) NULL); |
| 3036 |
code = TCL_ERROR; |
| 3037 |
} else { |
| 3038 |
iPtr->numLevels++; |
| 3039 |
code = TclEvalObjvInternal(interp, objc+1, newObjv, command, length, 0); |
| 3040 |
iPtr->numLevels--; |
| 3041 |
} |
| 3042 |
Tcl_DecrRefCount(newObjv[0]); |
| 3043 |
ckfree((char *) newObjv); |
| 3044 |
goto done; |
| 3045 |
} |
| 3046 |
|
| 3047 |
|
| 3048 |
|
| 3049 |
|
| 3050 |
if ((checkTraces) && (command != NULL)) { |
| 3051 |
int cmdEpoch = cmdPtr->cmdEpoch; |
| 3052 |
cmdPtr->refCount++; |
| 3053 |
|
| 3054 |
|
| 3055 |
|
| 3056 |
|
| 3057 |
|
| 3058 |
if (iPtr->tracePtr != NULL && traceCode == TCL_OK) { |
| 3059 |
traceCode = TclCheckInterpTraces(interp, command, length, |
| 3060 |
cmdPtr, code, TCL_TRACE_ENTER_EXEC, objc, objv); |
| 3061 |
} |
| 3062 |
if ((cmdPtr->flags & CMD_HAS_EXEC_TRACES) |
| 3063 |
&& (traceCode == TCL_OK)) { |
| 3064 |
traceCode = TclCheckExecutionTraces(interp, command, length, |
| 3065 |
cmdPtr, code, TCL_TRACE_ENTER_EXEC, objc, objv); |
| 3066 |
} |
| 3067 |
cmdPtr->refCount--; |
| 3068 |
if (cmdEpoch != cmdPtr->cmdEpoch) { |
| 3069 |
|
| 3070 |
checkTraces = 0; |
| 3071 |
continue; |
| 3072 |
} |
| 3073 |
} |
| 3074 |
break; |
| 3075 |
} |
| 3076 |
|
| 3077 |
|
| 3078 |
|
| 3079 |
|
| 3080 |
cmdPtr->refCount++; |
| 3081 |
iPtr->cmdCount++; |
| 3082 |
if ( code == TCL_OK && traceCode == TCL_OK) { |
| 3083 |
savedVarFramePtr = iPtr->varFramePtr; |
| 3084 |
if (flags & TCL_EVAL_GLOBAL) { |
| 3085 |
iPtr->varFramePtr = NULL; |
| 3086 |
} |
| 3087 |
code = (*cmdPtr->objProc)(cmdPtr->objClientData, interp, objc, objv); |
| 3088 |
iPtr->varFramePtr = savedVarFramePtr; |
| 3089 |
} |
| 3090 |
if (Tcl_AsyncReady()) { |
| 3091 |
code = Tcl_AsyncInvoke(interp, code); |
| 3092 |
} |
| 3093 |
|
| 3094 |
|
| 3095 |
|
| 3096 |
|
| 3097 |
if (!(cmdPtr->flags & CMD_IS_DELETED)) { |
| 3098 |
int saveErrFlags = iPtr->flags |
| 3099 |
& (ERR_IN_PROGRESS | ERR_ALREADY_LOGGED | ERROR_CODE_SET); |
| 3100 |
if ((cmdPtr->flags & CMD_HAS_EXEC_TRACES) && (traceCode == TCL_OK)) { |
| 3101 |
traceCode = TclCheckExecutionTraces (interp, command, length, |
| 3102 |
cmdPtr, code, TCL_TRACE_LEAVE_EXEC, objc, objv); |
| 3103 |
} |
| 3104 |
if (iPtr->tracePtr != NULL && traceCode == TCL_OK) { |
| 3105 |
traceCode = TclCheckInterpTraces(interp, command, length, |
| 3106 |
cmdPtr, code, TCL_TRACE_LEAVE_EXEC, objc, objv); |
| 3107 |
} |
| 3108 |
if (traceCode == TCL_OK) { |
| 3109 |
iPtr->flags |= saveErrFlags; |
| 3110 |
} |
| 3111 |
} |
| 3112 |
TclCleanupCommand(cmdPtr); |
| 3113 |
|
| 3114 |
|
| 3115 |
|
| 3116 |
|
| 3117 |
|
| 3118 |
|
| 3119 |
|
| 3120 |
|
| 3121 |
if (traceCode != TCL_OK) { |
| 3122 |
code = traceCode; |
| 3123 |
} |
| 3124 |
|
| 3125 |
|
| 3126 |
|
| 3127 |
|
| 3128 |
|
| 3129 |
|
| 3130 |
|
| 3131 |
|
| 3132 |
if (*(iPtr->result) != 0) { |
| 3133 |
(void) Tcl_GetObjResult(interp); |
| 3134 |
} |
| 3135 |
|
| 3136 |
done: |
| 3137 |
return code; |
| 3138 |
} |
| 3139 |
|
| 3140 |
|
| 3141 |
|
| 3142 |
|
| 3143 |
|
| 3144 |
|
| 3145 |
|
| 3146 |
|
| 3147 |
|
| 3148 |
|
| 3149 |
|
| 3150 |
|
| 3151 |
|
| 3152 |
|
| 3153 |
|
| 3154 |
|
| 3155 |
|
| 3156 |
|
| 3157 |
|
| 3158 |
|
| 3159 |
int |
| 3160 |
Tcl_EvalObjv(interp, objc, objv, flags) |
| 3161 |
Tcl_Interp *interp; |
| 3162 |
|
| 3163 |
|
| 3164 |
int objc; |
| 3165 |
Tcl_Obj *CONST objv[]; |
| 3166 |
|
| 3167 |
int flags; |
| 3168 |
|
| 3169 |
|
| 3170 |
|
| 3171 |
{ |
| 3172 |
Interp *iPtr = (Interp *)interp; |
| 3173 |
Trace *tracePtr; |
| 3174 |
Tcl_DString cmdBuf; |
| 3175 |
char *cmdString = ""; |
| 3176 |
|
| 3177 |
|
| 3178 |
|
| 3179 |
int cmdLen = 0; |
| 3180 |
|
| 3181 |
int code = TCL_OK; |
| 3182 |
int i; |
| 3183 |
int allowExceptions = (iPtr->evalFlags & TCL_ALLOW_EXCEPTIONS); |
| 3184 |
|
| 3185 |
for (tracePtr = iPtr->tracePtr; tracePtr; tracePtr = tracePtr->nextPtr) { |
| 3186 |
if ((tracePtr->level == 0) || (iPtr->numLevels <= tracePtr->level)) { |
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
|
| 3191 |
|
| 3192 |
Tcl_DStringInit(&cmdBuf); |
| 3193 |
for (i = 0; i < objc; i++) { |
| 3194 |
Tcl_DStringAppendElement(&cmdBuf, Tcl_GetString(objv[i])); |
| 3195 |
} |
| 3196 |
cmdString = Tcl_DStringValue(&cmdBuf); |
| 3197 |
cmdLen = Tcl_DStringLength(&cmdBuf); |
| 3198 |
break; |
| 3199 |
} |
| 3200 |
} |
| 3201 |
|
| 3202 |
iPtr->numLevels++; |
| 3203 |
code = TclEvalObjvInternal(interp, objc, objv, cmdString, cmdLen, flags); |
| 3204 |
iPtr->numLevels--; |
| 3205 |
|
| 3206 |
|
| 3207 |
|
| 3208 |
|
| 3209 |
|
| 3210 |
|
| 3211 |
if (iPtr->numLevels == 0) { |
| 3212 |
if (code == TCL_RETURN) { |
| 3213 |
code = TclUpdateReturnInfo(iPtr); |
| 3214 |
} |
| 3215 |
if ((code != TCL_OK) && (code != TCL_ERROR) |
| 3216 |
&& !allowExceptions) { |
| 3217 |
ProcessUnexpectedResult(interp, code); |
| 3218 |
code = TCL_ERROR; |
| 3219 |
} |
| 3220 |
} |
| 3221 |
|
| 3222 |
if ((code == TCL_ERROR) && !(flags & TCL_EVAL_INVOKE)) { |
| 3223 |
|
| 3224 |
|
| 3225 |
|
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
if (cmdLen == 0) { |
| 3230 |
Tcl_DStringInit(&cmdBuf); |
| 3231 |
for (i = 0; i < objc; i++) { |
| 3232 |
Tcl_DStringAppendElement(&cmdBuf, Tcl_GetString(objv[i])); |
| 3233 |
} |
| 3234 |
cmdString = Tcl_DStringValue(&cmdBuf); |
| 3235 |
cmdLen = Tcl_DStringLength(&cmdBuf); |
| 3236 |
} |
| 3237 |
Tcl_LogCommandInfo(interp, cmdString, cmdString, cmdLen); |
| 3238 |
} |
| 3239 |
|
| 3240 |
if (cmdLen != 0) { |
| 3241 |
Tcl_DStringFree(&cmdBuf); |
| 3242 |
} |
| 3243 |
return code; |
| 3244 |
} |
| 3245 |
|
| 3246 |
|
| 3247 |
|
| 3248 |
|
| 3249 |
|
| 3250 |
|
| 3251 |
|
| 3252 |
|
| 3253 |
|
| 3254 |
|
| 3255 |
|
| 3256 |
|
| 3257 |
|
| 3258 |
|
| 3259 |
|
| 3260 |
|
| 3261 |
|
| 3262 |
|
| 3263 |
|
| 3264 |
|
| 3265 |
|
| 3266 |
|
| 3267 |
|
| 3268 |
void |
| 3269 |
Tcl_LogCommandInfo(interp, script, command, length) |
| 3270 |
Tcl_Interp *interp; |
| 3271 |
CONST char *script; |
| 3272 |
|
| 3273 |
CONST char *command; |
| 3274 |
|
| 3275 |
int length; |
| 3276 |
|
| 3277 |
{ |
| 3278 |
char buffer[200]; |
| 3279 |
register CONST char *p; |
| 3280 |
char *ellipsis = ""; |
| 3281 |
Interp *iPtr = (Interp *) interp; |
| 3282 |
|
| 3283 |
if (iPtr->flags & ERR_ALREADY_LOGGED) { |
| 3284 |
|
| 3285 |
|
| 3286 |
|
| 3287 |
|
| 3288 |
|
| 3289 |
return; |
| 3290 |
} |
| 3291 |
|
| 3292 |
|
| 3293 |
|
| 3294 |
|
| 3295 |
|
| 3296 |
iPtr->errorLine = 1; |
| 3297 |
for (p = script; p != command; p++) { |
| 3298 |
if (*p == '\n') { |
| 3299 |
iPtr->errorLine++; |
| 3300 |
} |
| 3301 |
} |
| 3302 |
|
| 3303 |
|
| 3304 |
|
| 3305 |
|
| 3306 |
|
| 3307 |
|
| 3308 |
if (length < 0) { |
| 3309 |
length = strlen(command); |
| 3310 |
} |
| 3311 |
if (length > 150) { |
| 3312 |
length = 150; |
| 3313 |
ellipsis = "..."; |
| 3314 |
} |
| 3315 |
while ( (command[length] & 0xC0) == 0x80 ) { |
| 3316 |
|
| 3317 |
|
| 3318 |
|
| 3319 |
|
| 3320 |
length--; |
| 3321 |
ellipsis = "..."; |
| 3322 |
} |
| 3323 |
if (!(iPtr->flags & ERR_IN_PROGRESS)) { |
| 3324 |
sprintf(buffer, "\n while executing\n\"%.*s%s\"", |
| 3325 |
length, command, ellipsis); |
| 3326 |
} else { |
| 3327 |
sprintf(buffer, "\n invoked from within\n\"%.*s%s\"", |
| 3328 |
length, command, ellipsis); |
| 3329 |
} |
| 3330 |
Tcl_AddObjErrorInfo(interp, buffer, -1); |
| 3331 |
iPtr->flags &= ~ERR_ALREADY_LOGGED; |
| 3332 |
} |
| 3333 |
|
| 3334 |
|
| 3335 |
|
| 3336 |
|
| 3337 |
|
| 3338 |
|
| 3339 |
|
| 3340 |
|
| 3341 |
|
| 3342 |
|
| 3343 |
|
| 3344 |
|
| 3345 |
|
| 3346 |
|
| 3347 |
|
| 3348 |
|
| 3349 |
|
| 3350 |
|
| 3351 |
|
| 3352 |
|
| 3353 |
|
| 3354 |
|
| 3355 |
int |
| 3356 |
Tcl_EvalTokensStandard(interp, tokenPtr, count) |
| 3357 |
Tcl_Interp *interp; |
| 3358 |
|
| 3359 |
|
| 3360 |
Tcl_Token *tokenPtr; |
| 3361 |
|
| 3362 |
int count; |
| 3363 |
|
| 3364 |
{ |
| 3365 |
Tcl_Obj *resultPtr, *indexPtr, *valuePtr; |
| 3366 |
char buffer[TCL_UTF_MAX]; |
| 3367 |
#ifdef TCL_MEM_DEBUG |
| 3368 |
# define MAX_VAR_CHARS 5 |
| 3369 |
#else |
| 3370 |
# define MAX_VAR_CHARS 30 |
| 3371 |
#endif |
| 3372 |
char nameBuffer[MAX_VAR_CHARS+1]; |
| 3373 |
char *varName, *index; |
| 3374 |
CONST char *p = NULL; |
| 3375 |
int length, code; |
| 3376 |
|
| 3377 |
|
| 3378 |
|
| 3379 |
|
| 3380 |
|
| 3381 |
|
| 3382 |
|
| 3383 |
|
| 3384 |
code = TCL_OK; |
| 3385 |
resultPtr = NULL; |
| 3386 |
Tcl_ResetResult(interp); |
| 3387 |
for ( ; count > 0; count--, tokenPtr++) { |
| 3388 |
valuePtr = NULL; |
| 3389 |
|
| 3390 |
|
| 3391 |
|
| 3392 |
|
| 3393 |
|
| 3394 |
|
| 3395 |
|
| 3396 |
switch (tokenPtr->type) { |
| 3397 |
case TCL_TOKEN_TEXT: |
| 3398 |
p = tokenPtr->start; |
| 3399 |
length = tokenPtr->size; |
| 3400 |
break; |
| 3401 |
|
| 3402 |
case TCL_TOKEN_BS: |
| 3403 |
length = Tcl_UtfBackslash(tokenPtr->start, (int *) NULL, |
| 3404 |
buffer); |
| 3405 |
p = buffer; |
| 3406 |
break; |
| 3407 |
|
| 3408 |
case TCL_TOKEN_COMMAND: |
| 3409 |
code = Tcl_EvalEx(interp, tokenPtr->start+1, tokenPtr->size-2, |
| 3410 |
0); |
| 3411 |
if (code != TCL_OK) { |
| 3412 |
goto done; |
| 3413 |
} |
| 3414 |
valuePtr = Tcl_GetObjResult(interp); |
| 3415 |
break; |
| 3416 |
|
| 3417 |
case TCL_TOKEN_VARIABLE: |
| 3418 |
if (tokenPtr->numComponents == 1) { |
| 3419 |
indexPtr = NULL; |
| 3420 |
index = NULL; |
| 3421 |
} else { |
| 3422 |
code = Tcl_EvalTokensStandard(interp, tokenPtr+2, |
| 3423 |
tokenPtr->numComponents - 1); |
| 3424 |
if (code != TCL_OK) { |
| 3425 |
goto done; |
| 3426 |
} |
| 3427 |
indexPtr = Tcl_GetObjResult(interp); |
| 3428 |
Tcl_IncrRefCount(indexPtr); |
| 3429 |
index = Tcl_GetString(indexPtr); |
| 3430 |
} |
| 3431 |
|
| 3432 |
|
| 3433 |
|
| 3434 |
|
| 3435 |
|
| 3436 |
|
| 3437 |
|
| 3438 |
|
| 3439 |
|
| 3440 |
if (tokenPtr[1].size <= MAX_VAR_CHARS) { |
| 3441 |
varName = nameBuffer; |
| 3442 |
} else { |
| 3443 |
varName = ckalloc((unsigned) (tokenPtr[1].size + 1)); |
| 3444 |
} |
| 3445 |
strncpy(varName, tokenPtr[1].start, (size_t) tokenPtr[1].size); |
| 3446 |
varName[tokenPtr[1].size] = 0; |
| 3447 |
valuePtr = Tcl_GetVar2Ex(interp, varName, index, |
| 3448 |
TCL_LEAVE_ERR_MSG); |
| 3449 |
if (varName != nameBuffer) { |
| 3450 |
ckfree(varName); |
| 3451 |
} |
| 3452 |
if (indexPtr != NULL) { |
| 3453 |
Tcl_DecrRefCount(indexPtr); |
| 3454 |
} |
| 3455 |
if (valuePtr == NULL) { |
| 3456 |
code = TCL_ERROR; |
| 3457 |
goto done; |
| 3458 |
} |
| 3459 |
count -= tokenPtr->numComponents; |
| 3460 |
tokenPtr += tokenPtr->numComponents; |
| 3461 |
break; |
| 3462 |
|
| 3463 |
default: |
| 3464 |
panic("unexpected token type in Tcl_EvalTokensStandard"); |
| 3465 |
} |
| 3466 |
|
| 3467 |
|
| 3468 |
|
| 3469 |
|
| 3470 |
|
| 3471 |
|
| 3472 |
if (resultPtr == NULL) { |
| 3473 |
if (valuePtr != NULL) { |
| 3474 |
resultPtr = valuePtr; |
| 3475 |
} else { |
| 3476 |
resultPtr = Tcl_NewStringObj(p, length); |
| 3477 |
} |
| 3478 |
Tcl_IncrRefCount(resultPtr); |
| 3479 |
} else { |
| 3480 |
if (Tcl_IsShared(resultPtr)) { |
| 3481 |
Tcl_DecrRefCount(resultPtr); |
| 3482 |
resultPtr = Tcl_DuplicateObj(resultPtr); |
| 3483 |
Tcl_IncrRefCount(resultPtr); |
| 3484 |
} |
| 3485 |
if (valuePtr != NULL) { |
| 3486 |
p = Tcl_GetStringFromObj(valuePtr, &length); |
| 3487 |
} |
| 3488 |
Tcl_AppendToObj(resultPtr, p, length); |
| 3489 |
} |
| 3490 |
} |
| 3491 |
if (resultPtr != NULL) { |
| 3492 |
Tcl_SetObjResult(interp, resultPtr); |
| 3493 |
} else { |
| 3494 |
code = TCL_ERROR; |
| 3495 |
} |
| 3496 |
|
| 3497 |
done: |
| 3498 |
if (resultPtr != NULL) { |
| 3499 |
Tcl_DecrRefCount(resultPtr); |
| 3500 |
} |
| 3501 |
return code; |
| 3502 |
} |
| 3503 |
|
| 3504 |
|
| 3505 |
|
| 3506 |
|
| 3507 |
|
| 3508 |
|
| 3509 |
|
| 3510 |
|
| 3511 |
|
| 3512 |
|
| 3513 |
|
| 3514 |
|
| 3515 |
|
| 3516 |
|
| 3517 |
|
| 3518 |
|
| 3519 |
|
| 3520 |
|
| 3521 |
|
| 3522 |
|
| 3523 |
|
| 3524 |
|
| 3525 |
|
| 3526 |
|
| 3527 |
|
| 3528 |
|
| 3529 |
|
| 3530 |
|
| 3531 |
|
| 3532 |
Tcl_Obj * |
| 3533 |
Tcl_EvalTokens(interp, tokenPtr, count) |
| 3534 |
Tcl_Interp *interp; |
| 3535 |
|
| 3536 |
|
| 3537 |
Tcl_Token *tokenPtr; |
| 3538 |
|
| 3539 |
int count; |
| 3540 |
|
| 3541 |
{ |
| 3542 |
int code; |
| 3543 |
Tcl_Obj *resPtr; |
| 3544 |
|
| 3545 |
code = Tcl_EvalTokensStandard(interp, tokenPtr, count); |
| 3546 |
if (code == TCL_OK) { |
| 3547 |
resPtr = Tcl_GetObjResult(interp); |
| 3548 |
Tcl_IncrRefCount(resPtr); |
| 3549 |
Tcl_ResetResult(interp); |
| 3550 |
return resPtr; |
| 3551 |
} else { |
| 3552 |
return NULL; |
| 3553 |
} |
| 3554 |
} |
| 3555 |
|
| 3556 |
|
| 3557 |
|
| 3558 |
|
| 3559 |
|
| 3560 |
|
| 3561 |
|
| 3562 |
|
| 3563 |
|
| 3564 |
|
| 3565 |
|
| 3566 |
|
| 3567 |
|
| 3568 |
|
| 3569 |
|
| 3570 |
|
| 3571 |
|
| 3572 |
|
| 3573 |
|
| 3574 |
|
| 3575 |
|
| 3576 |
|
| 3577 |
|
| 3578 |
int |
| 3579 |
Tcl_EvalEx(interp, script, numBytes, flags) |
| 3580 |
Tcl_Interp *interp; |
| 3581 |
|
| 3582 |
CONST char *script; |
| 3583 |
int numBytes; |
| 3584 |
|
| 3585 |
|
| 3586 |
int flags; |
| 3587 |
|
| 3588 |
|
| 3589 |
|
| 3590 |
{ |
| 3591 |
Interp *iPtr = (Interp *) interp; |
| 3592 |
CONST char *p, *next; |
| 3593 |
Tcl_Parse parse; |
| 3594 |
#define NUM_STATIC_OBJS 20 |
| 3595 |
Tcl_Obj *staticObjArray[NUM_STATIC_OBJS], **objv; |
| 3596 |
Tcl_Token *tokenPtr; |
| 3597 |
int i, code, commandLength, bytesLeft, nested; |
| 3598 |
CallFrame *savedVarFramePtr; |
| 3599 |
|
| 3600 |
int allowExceptions = (iPtr->evalFlags & TCL_ALLOW_EXCEPTIONS); |
| 3601 |
|
| 3602 |
|
| 3603 |
|
| 3604 |
|
| 3605 |
|
| 3606 |
|
| 3607 |
|
| 3608 |
int gotParse = 0, objectsUsed = 0; |
| 3609 |
|
| 3610 |
if (numBytes < 0) { |
| 3611 |
numBytes = strlen(script); |
| 3612 |
} |
| 3613 |
Tcl_ResetResult(interp); |
| 3614 |
|
| 3615 |
savedVarFramePtr = iPtr->varFramePtr; |
| 3616 |
if (flags & TCL_EVAL_GLOBAL) { |
| 3617 |
iPtr->varFramePtr = NULL; |
| 3618 |
} |
| 3619 |
|
| 3620 |
|
| 3621 |
|
| 3622 |
|
| 3623 |
|
| 3624 |
|
| 3625 |
objv = staticObjArray; |
| 3626 |
p = script; |
| 3627 |
bytesLeft = numBytes; |
| 3628 |
if (iPtr->evalFlags & TCL_BRACKET_TERM) { |
| 3629 |
nested = 1; |
| 3630 |
} else { |
| 3631 |
nested = 0; |
| 3632 |
} |
| 3633 |
iPtr->evalFlags = 0; |
| 3634 |
do { |
| 3635 |
if (Tcl_ParseCommand(interp, p, bytesLeft, nested, &parse) |
| 3636 |
!= TCL_OK) { |
| 3637 |
code = TCL_ERROR; |
| 3638 |
goto error; |
| 3639 |
} |
| 3640 |
gotParse = 1; |
| 3641 |
|
| 3642 |
if (nested && parse.term == (script + numBytes)) { |
| 3643 |
|
| 3644 |
|
| 3645 |
|
| 3646 |
|
| 3647 |
|
| 3648 |
|
| 3649 |
code = TCL_ERROR; |
| 3650 |
goto error; |
| 3651 |
} |
| 3652 |
|
| 3653 |
if (parse.numWords > 0) { |
| 3654 |
|
| 3655 |
|
| 3656 |
|
| 3657 |
|
| 3658 |
if (parse.numWords <= NUM_STATIC_OBJS) { |
| 3659 |
objv = staticObjArray; |
| 3660 |
} else { |
| 3661 |
objv = (Tcl_Obj **) ckalloc((unsigned) |
| 3662 |
(parse.numWords * sizeof (Tcl_Obj *))); |
| 3663 |
} |
| 3664 |
for (objectsUsed = 0, tokenPtr = parse.tokenPtr; |
| 3665 |
objectsUsed < parse.numWords; |
| 3666 |
objectsUsed++, tokenPtr += (tokenPtr->numComponents + 1)) { |
| 3667 |
code = Tcl_EvalTokensStandard(interp, tokenPtr+1, |
| 3668 |
tokenPtr->numComponents); |
| 3669 |
if (code == TCL_OK) { |
| 3670 |
objv[objectsUsed] = Tcl_GetObjResult(interp); |
| 3671 |
Tcl_IncrRefCount(objv[objectsUsed]); |
| 3672 |
} else { |
| 3673 |
goto error; |
| 3674 |
} |
| 3675 |
} |
| 3676 |
|
| 3677 |
|
| 3678 |
|
| 3679 |
|
| 3680 |
|
| 3681 |
iPtr->numLevels++; |
| 3682 |
code = TclEvalObjvInternal(interp, objectsUsed, objv, |
| 3683 |
parse.commandStart, parse.commandSize, 0); |
| 3684 |
iPtr->numLevels--; |
| 3685 |
if (code != TCL_OK) { |
| 3686 |
if (iPtr->numLevels == 0) { |
| 3687 |
if (code == TCL_RETURN) { |
| 3688 |
code = TclUpdateReturnInfo(iPtr); |
| 3689 |
} |
| 3690 |
if ((code != TCL_OK) && (code != TCL_ERROR) |
| 3691 |
&& !allowExceptions) { |
| 3692 |
ProcessUnexpectedResult(interp, code); |
| 3693 |
code = TCL_ERROR; |
| 3694 |
} |
| 3695 |
} |
| 3696 |
goto error; |
| 3697 |
} |
| 3698 |
for (i = 0; i < objectsUsed; i++) { |
| 3699 |
Tcl_DecrRefCount(objv[i]); |
| 3700 |
} |
| 3701 |
objectsUsed = 0; |
| 3702 |
if (objv != staticObjArray) { |
| 3703 |
ckfree((char *) objv); |
| 3704 |
objv = staticObjArray; |
| 3705 |
} |
| 3706 |
} |
| 3707 |
|
| 3708 |
|
| 3709 |
|
| 3710 |
|
| 3711 |
|
| 3712 |
next = parse.commandStart + parse.commandSize; |
| 3713 |
bytesLeft -= next - p; |
| 3714 |
p = next; |
| 3715 |
Tcl_FreeParse(&parse); |
| 3716 |
gotParse = 0; |
| 3717 |
if (nested && (*parse.term == ']')) { |
| 3718 |
|
| 3719 |
|
| 3720 |
|
| 3721 |
|
| 3722 |
|
| 3723 |
|
| 3724 |
|
| 3725 |
iPtr->termOffset = (p - 1) - script; |
| 3726 |
iPtr->varFramePtr = savedVarFramePtr; |
| 3727 |
return TCL_OK; |
| 3728 |
} |
| 3729 |
} while (bytesLeft > 0); |
| 3730 |
iPtr->termOffset = p - script; |
| 3731 |
iPtr->varFramePtr = savedVarFramePtr; |
| 3732 |
return TCL_OK; |
| 3733 |
|
| 3734 |
error: |
| 3735 |
|
| 3736 |
|
| 3737 |
|
| 3738 |
|
| 3739 |
|
| 3740 |
|
| 3741 |
|
| 3742 |
if ((code == TCL_ERROR) && !(iPtr->flags & ERR_ALREADY_LOGGED)) { |
| 3743 |
commandLength = parse.commandSize; |
| 3744 |
if (parse.term == parse.commandStart + commandLength - 1) { |
| 3745 |
|
| 3746 |
|
| 3747 |
|
| 3748 |
|
| 3749 |
|
| 3750 |
|
| 3751 |
|
| 3752 |
commandLength -= 1; |
| 3753 |
} |
| 3754 |
Tcl_LogCommandInfo(interp, script, parse.commandStart, commandLength); |
| 3755 |
} |
| 3756 |
|
| 3757 |
for (i = 0; i < objectsUsed; i++) { |
| 3758 |
Tcl_DecrRefCount(objv[i]); |
| 3759 |
} |
| 3760 |
if (gotParse) { |
| 3761 |
Tcl_FreeParse(&parse); |
| 3762 |
} |
| 3763 |
if (objv != staticObjArray) { |
| 3764 |
ckfree((char *) objv); |
| 3765 |
} |
| 3766 |
iPtr->varFramePtr = savedVarFramePtr; |
| 3767 |
|
| 3768 |
|
| 3769 |
|
| 3770 |
|
| 3771 |
|
| 3772 |
|
| 3773 |
next = parse.commandStart + parse.commandSize; |
| 3774 |
bytesLeft -= next - p; |
| 3775 |
p = next; |
| 3776 |
|
| 3777 |
if (!nested) { |
| 3778 |
iPtr->termOffset = p - script; |
| 3779 |
return code; |
| 3780 |
} |
| 3781 |
|
| 3782 |
|
| 3783 |
|
| 3784 |
|
| 3785 |
|
| 3786 |
|
| 3787 |
|
| 3788 |
|
| 3789 |
|
| 3790 |
|
| 3791 |
|
| 3792 |
|
| 3793 |
|
| 3794 |
next = NULL; |
| 3795 |
while (bytesLeft && (*parse.term != ']')) { |
| 3796 |
if (TCL_OK != Tcl_ParseCommand(NULL, p, bytesLeft, 1, &parse)) { |
| 3797 |
|
| 3798 |
|
| 3799 |
|
| 3800 |
|
| 3801 |
|
| 3802 |
if (next == NULL) { |
| 3803 |
iPtr->termOffset = (parse.commandStart - 1) - script; |
| 3804 |
} else { |
| 3805 |
iPtr->termOffset = (next - 1) - script; |
| 3806 |
} |
| 3807 |
return code; |
| 3808 |
} |
| 3809 |
next = parse.commandStart + parse.commandSize; |
| 3810 |
bytesLeft -= next - p; |
| 3811 |
p = next; |
| 3812 |
next = parse.commandStart; |
| 3813 |
Tcl_FreeParse(&parse); |
| 3814 |
} |
| 3815 |
|
| 3816 |
if (bytesLeft) { |
| 3817 |
|
| 3818 |
|
| 3819 |
|
| 3820 |
|
| 3821 |
iPtr->termOffset = parse.term - script; |
| 3822 |
} else if (parse.term == script + numBytes) { |
| 3823 |
|
| 3824 |
|
| 3825 |
|
| 3826 |
|
| 3827 |
iPtr->termOffset = parse.term - script; |
| 3828 |
Tcl_SetObjResult(interp, |
| 3829 |
Tcl_NewStringObj("missing close-bracket", -1)); |
| 3830 |
return TCL_ERROR; |
| 3831 |
} else if (*parse.term != ']') { |
| 3832 |
|
| 3833 |
|
| 3834 |
|
| 3835 |
|
| 3836 |
iPtr->termOffset = (parse.term + 1) - script; |
| 3837 |
Tcl_SetObjResult(interp, |
| 3838 |
Tcl_NewStringObj("missing close-bracket", -1)); |
| 3839 |
return TCL_ERROR; |
| 3840 |
} else { |
| 3841 |
|
| 3842 |
|
| 3843 |
|
| 3844 |
iPtr->termOffset = parse.term - script; |
| 3845 |
} |
| 3846 |
return code; |
| 3847 |
} |
| 3848 |
|
| 3849 |
|
| 3850 |
|
| 3851 |
|
| 3852 |
|
| 3853 |
|
| 3854 |
|
| 3855 |
|
| 3856 |
|
| 3857 |
|
| 3858 |
|
| 3859 |
|
| 3860 |
|
| 3861 |
|
| 3862 |
|
| 3863 |
|
| 3864 |
|
| 3865 |
|
| 3866 |
|
| 3867 |
|
| 3868 |
|
| 3869 |
|
| 3870 |
|
| 3871 |
|
| 3872 |
|
| 3873 |
int |
| 3874 |
Tcl_Eval(interp, string) |
| 3875 |
Tcl_Interp *interp; |
| 3876 |
|
| 3877 |
CONST char *string; |
| 3878 |
{ |
| 3879 |
int code = Tcl_EvalEx(interp, string, -1, 0); |
| 3880 |
|
| 3881 |
|
| 3882 |
|
| 3883 |
|
| 3884 |
|
| 3885 |
|
| 3886 |
|
| 3887 |
Tcl_SetResult(interp, TclGetString(Tcl_GetObjResult(interp)), |
| 3888 |
TCL_VOLATILE); |
| 3889 |
return code; |
| 3890 |
} |
| 3891 |
|
| 3892 |
|
| 3893 |
|
| 3894 |
|
| 3895 |
|
| 3896 |
|
| 3897 |
|
| 3898 |
|
| 3899 |
|
| 3900 |
|
| 3901 |
|
| 3902 |
|
| 3903 |
|
| 3904 |
|
| 3905 |
|
| 3906 |
|
| 3907 |
|
| 3908 |
|
| 3909 |
#undef Tcl_EvalObj |
| 3910 |
int |
| 3911 |
Tcl_EvalObj(interp, objPtr) |
| 3912 |
Tcl_Interp * interp; |
| 3913 |
Tcl_Obj * objPtr; |
| 3914 |
{ |
| 3915 |
return Tcl_EvalObjEx(interp, objPtr, 0); |
| 3916 |
} |
| 3917 |
|
| 3918 |
#undef Tcl_GlobalEvalObj |
| 3919 |
int |
| 3920 |
Tcl_GlobalEvalObj(interp, objPtr) |
| 3921 |
Tcl_Interp * interp; |
| 3922 |
Tcl_Obj * objPtr; |
| 3923 |
{ |
| 3924 |
return Tcl_EvalObjEx(interp, objPtr, TCL_EVAL_GLOBAL); |
| 3925 |
} |
| 3926 |
|
| 3927 |
|
| 3928 |
|
| 3929 |
|
| 3930 |
|
| 3931 |
|
| 3932 |
|
| 3933 |
|
| 3934 |
|
| 3935 |
|
| 3936 |
|
| 3937 |
|
| 3938 |
|
| 3939 |
|
| 3940 |
|
| 3941 |
|
| 3942 |
|
| 3943 |
|
| 3944 |
|
| 3945 |
|
| 3946 |
|
| 3947 |
|
| 3948 |
|
| 3949 |
|
| 3950 |
|
| 3951 |
|
| 3952 |
|
| 3953 |
int |
| 3954 |
Tcl_EvalObjEx(interp, objPtr, flags) |
| 3955 |
Tcl_Interp *interp; |
| 3956 |
|
| 3957 |
|
| 3958 |
register Tcl_Obj *objPtr; |
| 3959 |
|
| 3960 |
int flags; |
| 3961 |
|
| 3962 |
|
| 3963 |
|
| 3964 |
|
| 3965 |
{ |
| 3966 |
register Interp *iPtr = (Interp *) interp; |
| 3967 |
char *script; |
| 3968 |
int numSrcBytes; |
| 3969 |
int result; |
| 3970 |
CallFrame *savedVarFramePtr; |
| 3971 |
|
| 3972 |
int allowExceptions = (iPtr->evalFlags & TCL_ALLOW_EXCEPTIONS); |
| 3973 |
|
| 3974 |
Tcl_IncrRefCount(objPtr); |
| 3975 |
|
| 3976 |
if ((iPtr->flags & USE_EVAL_DIRECT) || (flags & TCL_EVAL_DIRECT)) { |
| 3977 |
|
| 3978 |
|
| 3979 |
|
| 3980 |
|
| 3981 |
|
| 3982 |
|
| 3983 |
|
| 3984 |
|
| 3985 |
|
| 3986 |
|
| 3987 |
|
| 3988 |
|
| 3989 |
|
| 3990 |
|
| 3991 |
if (!(iPtr->flags & USE_EVAL_DIRECT) && |
| 3992 |
(objPtr->typePtr == &tclListType) && |
| 3993 |
(objPtr->bytes == NULL) ) { |
| 3994 |
register List *listRepPtr = |
| 3995 |
(List *) objPtr->internalRep.twoPtrValue.ptr1; |
| 3996 |
result = Tcl_EvalObjv(interp, listRepPtr->elemCount, |
| 3997 |
listRepPtr->elements, flags); |
| 3998 |
} else { |
| 3999 |
script = Tcl_GetStringFromObj(objPtr, &numSrcBytes); |
| 4000 |
result = Tcl_EvalEx(interp, script, numSrcBytes, flags); |
| 4001 |
} |
| 4002 |
} else { |
| 4003 |
|
| 4004 |
|
| 4005 |
|
| 4006 |
|
| 4007 |
savedVarFramePtr = iPtr->varFramePtr; |
| 4008 |
if (flags & TCL_EVAL_GLOBAL) { |
| 4009 |
iPtr->varFramePtr = NULL; |
| 4010 |
} |
| 4011 |
|
| 4012 |
result = TclCompEvalObj(interp, objPtr); |
| 4013 |
|
| 4014 |
|
| 4015 |
|
| 4016 |
|
| 4017 |
|
| 4018 |
|
| 4019 |
if (iPtr->numLevels == 0) { |
| 4020 |
if (result == TCL_RETURN) { |
| 4021 |
result = TclUpdateReturnInfo(iPtr); |
| 4022 |
} |
| 4023 |
if ((result != TCL_OK) && (result != TCL_ERROR) |
| 4024 |
&& !allowExceptions) { |
| 4025 |
ProcessUnexpectedResult(interp, result); |
| 4026 |
result = TCL_ERROR; |
| 4027 |
|
| 4028 |
|
| 4029 |
|
| 4030 |
|
| 4031 |
|
| 4032 |
|
| 4033 |
if (!(iPtr->flags & ERR_ALREADY_LOGGED)) { |
| 4034 |
script = Tcl_GetStringFromObj(objPtr, &numSrcBytes); |
| 4035 |
Tcl_LogCommandInfo(interp, script, script, numSrcBytes); |
| 4036 |
iPtr->flags &= ~ERR_ALREADY_LOGGED; |
| 4037 |
} |
| 4038 |
} |
| 4039 |
} |
| 4040 |
iPtr->evalFlags = 0; |
| 4041 |
iPtr->varFramePtr = savedVarFramePtr; |
| 4042 |
} |
| 4043 |
|
| 4044 |
TclDecrRefCount(objPtr); |
| 4045 |
return result; |
| 4046 |
} |
| 4047 |
|
| 4048 |
|
| 4049 |
|
| 4050 |
|
| 4051 |
|
| 4052 |
|
| 4053 |
|
| 4054 |
|
| 4055 |
|
| 4056 |
|
| 4057 |
|
| 4058 |
|
| 4059 |
|
| 4060 |
|
| 4061 |
|
| 4062 |
|
| 4063 |
|
| 4064 |
|
| 4065 |
|
| 4066 |
|
| 4067 |
|
| 4068 |
static void |
| 4069 |
ProcessUnexpectedResult(interp, returnCode) |
| 4070 |
Tcl_Interp *interp; |
| 4071 |
|
| 4072 |
int returnCode; |
| 4073 |
{ |
| 4074 |
Tcl_ResetResult(interp); |
| 4075 |
if (returnCode == TCL_BREAK) { |
| 4076 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), |
| 4077 |
"invoked \"break\" outside of a loop", -1); |
| 4078 |
} else if (returnCode == TCL_CONTINUE) { |
| 4079 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), |
| 4080 |
"invoked \"continue\" outside of a loop", -1); |
| 4081 |
} else { |
| 4082 |
char buf[30 + TCL_INTEGER_SPACE]; |
| 4083 |
|
| 4084 |
sprintf(buf, "command returned bad code: %d", returnCode); |
| 4085 |
Tcl_SetResult(interp, buf, TCL_VOLATILE); |
| 4086 |
} |
| 4087 |
} |
| 4088 |
|
| 4089 |
|
| 4090 |
|
| 4091 |
|
| 4092 |
|
| 4093 |
|
| 4094 |
|
| 4095 |
|
| 4096 |
|
| 4097 |
|
| 4098 |
|
| 4099 |
|
| 4100 |
|
| 4101 |
|
| 4102 |
|
| 4103 |
|
| 4104 |
|
| 4105 |
|
| 4106 |
|
| 4107 |
|
| 4108 |
|
| 4109 |
|
| 4110 |
int |
| 4111 |
Tcl_ExprLong(interp, string, ptr) |
| 4112 |
Tcl_Interp *interp; |
| 4113 |
|
| 4114 |
CONST char *string; |
| 4115 |
long *ptr; |
| 4116 |
{ |
| 4117 |
register Tcl_Obj *exprPtr; |
| 4118 |
Tcl_Obj *resultPtr; |
| 4119 |
int length = strlen(string); |
| 4120 |
int result = TCL_OK; |
| 4121 |
|
| 4122 |
if (length > 0) { |
| 4123 |
exprPtr = Tcl_NewStringObj(string, length); |
| 4124 |
Tcl_IncrRefCount(exprPtr); |
| 4125 |
result = Tcl_ExprObj(interp, exprPtr, &resultPtr); |
| 4126 |
if (result == TCL_OK) { |
| 4127 |
|
| 4128 |
|
| 4129 |
|
| 4130 |
|
| 4131 |
if (resultPtr->typePtr == &tclIntType) { |
| 4132 |
*ptr = resultPtr->internalRep.longValue; |
| 4133 |
} else if (resultPtr->typePtr == &tclDoubleType) { |
| 4134 |
*ptr = (long) resultPtr->internalRep.doubleValue; |
| 4135 |
} else { |
| 4136 |
Tcl_SetResult(interp, |
| 4137 |
"expression didn't have numeric value", TCL_STATIC); |
| 4138 |
result = TCL_ERROR; |
| 4139 |
} |
| 4140 |
Tcl_DecrRefCount(resultPtr); |
| 4141 |
} else { |
| 4142 |
|
| 4143 |
|
| 4144 |
|
| 4145 |
|
| 4146 |
|
| 4147 |
Tcl_SetResult(interp, TclGetString(Tcl_GetObjResult(interp)), |
| 4148 |
TCL_VOLATILE); |
| 4149 |
} |
| 4150 |
Tcl_DecrRefCount(exprPtr); |
| 4151 |
} else { |
| 4152 |
|
| 4153 |
|
| 4154 |
|
| 4155 |
|
| 4156 |
*ptr = 0; |
| 4157 |
} |
| 4158 |
return result; |
| 4159 |
} |
| 4160 |
|
| 4161 |
int |
| 4162 |
Tcl_ExprDouble(interp, string, ptr) |
| 4163 |
Tcl_Interp *interp; |
| 4164 |
|
| 4165 |
CONST char *string; |
| 4166 |
double *ptr; |
| 4167 |
{ |
| 4168 |
register Tcl_Obj *exprPtr; |
| 4169 |
Tcl_Obj *resultPtr; |
| 4170 |
int length = strlen(string); |
| 4171 |
int result = TCL_OK; |
| 4172 |
|
| 4173 |
if (length > 0) { |
| 4174 |
exprPtr = Tcl_NewStringObj(string, length); |
| 4175 |
Tcl_IncrRefCount(exprPtr); |
| 4176 |
result = Tcl_ExprObj(interp, exprPtr, &resultPtr); |
| 4177 |
if (result == TCL_OK) { |
| 4178 |
|
| 4179 |
|
| 4180 |
|
| 4181 |
|
| 4182 |
if (resultPtr->typePtr == &tclIntType) { |
| 4183 |
*ptr = (double) resultPtr->internalRep.longValue; |
| 4184 |
} else if (resultPtr->typePtr == &tclDoubleType) { |
| 4185 |
*ptr = resultPtr->internalRep.doubleValue; |
| 4186 |
} else { |
| 4187 |
Tcl_SetResult(interp, |
| 4188 |
"expression didn't have numeric value", TCL_STATIC); |
| 4189 |
result = TCL_ERROR; |
| 4190 |
} |
| 4191 |
Tcl_DecrRefCount(resultPtr); |
| 4192 |
} else { |
| 4193 |
|
| 4194 |
|
| 4195 |
|
| 4196 |
|
| 4197 |
|
| 4198 |
Tcl_SetResult(interp, TclGetString(Tcl_GetObjResult(interp)), |
| 4199 |
TCL_VOLATILE); |
| 4200 |
} |
| 4201 |
Tcl_DecrRefCount(exprPtr); |
| 4202 |
} else { |
| 4203 |
|
| 4204 |
|
| 4205 |
|
| 4206 |
|
| 4207 |
*ptr = 0.0; |
| 4208 |
} |
| 4209 |
return result; |
| 4210 |
} |
| 4211 |
|
| 4212 |
int |
| 4213 |
Tcl_ExprBoolean(interp, string, ptr) |
| 4214 |
Tcl_Interp *interp; |
| 4215 |
|
| 4216 |
CONST char *string; |
| 4217 |
int *ptr; |
| 4218 |
{ |
| 4219 |
register Tcl_Obj *exprPtr; |
| 4220 |
Tcl_Obj *resultPtr; |
| 4221 |
int length = strlen(string); |
| 4222 |
int result = TCL_OK; |
| 4223 |
|
| 4224 |
if (length > 0) { |
| 4225 |
exprPtr = Tcl_NewStringObj(string, length); |
| 4226 |
Tcl_IncrRefCount(exprPtr); |
| 4227 |
result = Tcl_ExprObj(interp, exprPtr, &resultPtr); |
| 4228 |
if (result == TCL_OK) { |
| 4229 |
|
| 4230 |
|
| 4231 |
|
| 4232 |
|
| 4233 |
if (resultPtr->typePtr == &tclIntType) { |
| 4234 |
*ptr = (resultPtr->internalRep.longValue != 0); |
| 4235 |
} else if (resultPtr->typePtr == &tclDoubleType) { |
| 4236 |
*ptr = (resultPtr->internalRep.doubleValue != 0.0); |
| 4237 |
} else { |
| 4238 |
result = Tcl_GetBooleanFromObj(interp, resultPtr, ptr); |
| 4239 |
} |
| 4240 |
Tcl_DecrRefCount(resultPtr); |
| 4241 |
} |
| 4242 |
if (result != TCL_OK) { |
| 4243 |
|
| 4244 |
|
| 4245 |
|
| 4246 |
|
| 4247 |
|
| 4248 |
Tcl_SetResult(interp, TclGetString(Tcl_GetObjResult(interp)), |
| 4249 |
TCL_VOLATILE); |
| 4250 |
} |
| 4251 |
Tcl_DecrRefCount(exprPtr); |
| 4252 |
} else { |
| 4253 |
|
| 4254 |
|
| 4255 |
|
| 4256 |
|
| 4257 |
*ptr = 0; |
| 4258 |
} |
| 4259 |
return result; |
| 4260 |
} |
| 4261 |
|
| 4262 |
|
| 4263 |
|
| 4264 |
|
| 4265 |
|
| 4266 |
|
| 4267 |
|
| 4268 |
|
| 4269 |
|
| 4270 |
|
| 4271 |
|
| 4272 |
|
| 4273 |
|
| 4274 |
|
| 4275 |
|
| 4276 |
|
| 4277 |
|
| 4278 |
|
| 4279 |
|
| 4280 |
|
| 4281 |
|
| 4282 |
|
| 4283 |
|
| 4284 |
int |
| 4285 |
Tcl_ExprLongObj(interp, objPtr, ptr) |
| 4286 |
Tcl_Interp *interp; |
| 4287 |
|
| 4288 |
register Tcl_Obj *objPtr; |
| 4289 |
long *ptr; |
| 4290 |
{ |
| 4291 |
Tcl_Obj *resultPtr; |
| 4292 |
int result; |
| 4293 |
|
| 4294 |
result = Tcl_ExprObj(interp, objPtr, &resultPtr); |
| 4295 |
if (result == TCL_OK) { |
| 4296 |
if (resultPtr->typePtr == &tclIntType) { |
| 4297 |
*ptr = resultPtr->internalRep.longValue; |
| 4298 |
} else if (resultPtr->typePtr == &tclDoubleType) { |
| 4299 |
*ptr = (long) resultPtr->internalRep.doubleValue; |
| 4300 |
} else { |
| 4301 |
result = Tcl_GetLongFromObj(interp, resultPtr, ptr); |
| 4302 |
if (result != TCL_OK) { |
| 4303 |
return result; |
| 4304 |
} |
| 4305 |
} |
| 4306 |
Tcl_DecrRefCount(resultPtr); |
| 4307 |
} |
| 4308 |
return result; |
| 4309 |
} |
| 4310 |
|
| 4311 |
int |
| 4312 |
Tcl_ExprDoubleObj(interp, objPtr, ptr) |
| 4313 |
Tcl_Interp *interp; |
| 4314 |
|
| 4315 |
register Tcl_Obj *objPtr; |
| 4316 |
double *ptr; |
| 4317 |
{ |
| 4318 |
Tcl_Obj *resultPtr; |
| 4319 |
int result; |
| 4320 |
|
| 4321 |
result = Tcl_ExprObj(interp, objPtr, &resultPtr); |
| 4322 |
if (result == TCL_OK) { |
| 4323 |
if (resultPtr->typePtr == &tclIntType) { |
| 4324 |
*ptr = (double) resultPtr->internalRep.longValue; |
| 4325 |
} else if (resultPtr->typePtr == &tclDoubleType) { |
| 4326 |
*ptr = resultPtr->internalRep.doubleValue; |
| 4327 |
} else { |
| 4328 |
result = Tcl_GetDoubleFromObj(interp, resultPtr, ptr); |
| 4329 |
if (result != TCL_OK) { |
| 4330 |
return result; |
| 4331 |
} |
| 4332 |
} |
| 4333 |
Tcl_DecrRefCount(resultPtr); |
| 4334 |
} |
| 4335 |
return result; |
| 4336 |
} |
| 4337 |
|
| 4338 |
int |
| 4339 |
Tcl_ExprBooleanObj(interp, objPtr, ptr) |
| 4340 |
Tcl_Interp *interp; |
| 4341 |
|
| 4342 |
register Tcl_Obj *objPtr; |
| 4343 |
int *ptr; |
| 4344 |
{ |
| 4345 |
Tcl_Obj *resultPtr; |
| 4346 |
int result; |
| 4347 |
|
| 4348 |
result = Tcl_ExprObj(interp, objPtr, &resultPtr); |
| 4349 |
if (result == TCL_OK) { |
| 4350 |
if (resultPtr->typePtr == &tclIntType) { |
| 4351 |
*ptr = (resultPtr->internalRep.longValue != 0); |
| 4352 |
} else if (resultPtr->typePtr == &tclDoubleType) { |
| 4353 |
*ptr = (resultPtr->internalRep.doubleValue != 0.0); |
| 4354 |
} else { |
| 4355 |
result = Tcl_GetBooleanFromObj(interp, resultPtr, ptr); |
| 4356 |
} |
| 4357 |
Tcl_DecrRefCount(resultPtr); |
| 4358 |
} |
| 4359 |
return result; |
| 4360 |
} |
| 4361 |
|
| 4362 |
|
| 4363 |
|
| 4364 |
|
| 4365 |
|
| 4366 |
|
| 4367 |
|
| 4368 |
|
| 4369 |
|
| 4370 |
|
| 4371 |
|
| 4372 |
|
| 4373 |
|
| 4374 |
|
| 4375 |
|
| 4376 |
|
| 4377 |
|
| 4378 |
|
| 4379 |
|
| 4380 |
|
| 4381 |
int |
| 4382 |
TclInvoke(interp, argc, argv, flags) |
| 4383 |
Tcl_Interp *interp; |
| 4384 |
int argc; |
| 4385 |
register CONST char **argv; |
| 4386 |
|
| 4387 |
int flags; |
| 4388 |
|
| 4389 |
|
| 4390 |
{ |
| 4391 |
register Tcl_Obj *objPtr; |
| 4392 |
register int i; |
| 4393 |
int length, result; |
| 4394 |
|
| 4395 |
|
| 4396 |
|
| 4397 |
|
| 4398 |
|
| 4399 |
|
| 4400 |
|
| 4401 |
#define NUM_ARGS 20 |
| 4402 |
Tcl_Obj *(objStorage[NUM_ARGS]); |
| 4403 |
register Tcl_Obj **objv = objStorage; |
| 4404 |
|
| 4405 |
|
| 4406 |
|
| 4407 |
|
| 4408 |
|
| 4409 |
|
| 4410 |
|
| 4411 |
if ((argc + 1) > NUM_ARGS) { |
| 4412 |
objv = (Tcl_Obj **) |
| 4413 |
ckalloc((unsigned)(argc + 1) * sizeof(Tcl_Obj *)); |
| 4414 |
} |
| 4415 |
|
| 4416 |
for (i = 0; i < argc; i++) { |
| 4417 |
length = strlen(argv[i]); |
| 4418 |
objv[i] = Tcl_NewStringObj(argv[i], length); |
| 4419 |
Tcl_IncrRefCount(objv[i]); |
| 4420 |
} |
| 4421 |
objv[argc] = 0; |
| 4422 |
|
| 4423 |
|
| 4424 |
|
| 4425 |
|
| 4426 |
|
| 4427 |
result = TclObjInvoke(interp, argc, objv, flags); |
| 4428 |
|
| 4429 |
|
| 4430 |
|
| 4431 |
|
| 4432 |
|
| 4433 |
|
| 4434 |
Tcl_SetResult(interp, TclGetString(Tcl_GetObjResult(interp)), |
| 4435 |
TCL_VOLATILE); |
| 4436 |
|
| 4437 |
|
| 4438 |
|
| 4439 |
|
| 4440 |
|
| 4441 |
|
| 4442 |
for (i = 0; i < argc; i++) { |
| 4443 |
objPtr = objv[i]; |
| 4444 |
Tcl_DecrRefCount(objPtr); |
| 4445 |
} |
| 4446 |
|
| 4447 |
|
| 4448 |
|
| 4449 |
|
| 4450 |
|
| 4451 |
if (objv != objStorage) { |
| 4452 |
ckfree((char *) objv); |
| 4453 |
} |
| 4454 |
return result; |
| 4455 |
#undef NUM_ARGS |
| 4456 |
} |
| 4457 |
|
| 4458 |
|
| 4459 |
|
| 4460 |
|
| 4461 |
|
| 4462 |
|
| 4463 |
|
| 4464 |
|
| 4465 |
|
| 4466 |
|
| 4467 |
|
| 4468 |
|
| 4469 |
|
| 4470 |
|
| 4471 |
|
| 4472 |
|
| 4473 |
|
| 4474 |
|
| 4475 |
|
| 4476 |
|
| 4477 |
|
| 4478 |
int |
| 4479 |
TclGlobalInvoke(interp, argc, argv, flags) |
| 4480 |
Tcl_Interp *interp; |
| 4481 |
int argc; |
| 4482 |
register CONST char **argv; |
| 4483 |
|
| 4484 |
int flags; |
| 4485 |
|
| 4486 |
|
| 4487 |
{ |
| 4488 |
register Interp *iPtr = (Interp *) interp; |
| 4489 |
int result; |
| 4490 |
CallFrame *savedVarFramePtr; |
| 4491 |
|
| 4492 |
savedVarFramePtr = iPtr->varFramePtr; |
| 4493 |
iPtr->varFramePtr = NULL; |
| 4494 |
result = TclInvoke(interp, argc, argv, flags); |
| 4495 |
iPtr->varFramePtr = savedVarFramePtr; |
| 4496 |
return result; |
| 4497 |
} |
| 4498 |
|
| 4499 |
|
| 4500 |
|
| 4501 |
|
| 4502 |
|
| 4503 |
|
| 4504 |
|
| 4505 |
|
| 4506 |
|
| 4507 |
|
| 4508 |
|
| 4509 |
|
| 4510 |
|
| 4511 |
|
| 4512 |
|
| 4513 |
|
| 4514 |
|
| 4515 |
|
| 4516 |
|
| 4517 |
|
| 4518 |
|
| 4519 |
|
| 4520 |
int |
| 4521 |
TclObjInvokeGlobal(interp, objc, objv, flags) |
| 4522 |
Tcl_Interp *interp; |
| 4523 |
|
| 4524 |
int objc; |
| 4525 |
Tcl_Obj *CONST objv[]; |
| 4526 |
|
| 4527 |
int flags; |
| 4528 |
|
| 4529 |
|
| 4530 |
|
| 4531 |
{ |
| 4532 |
register Interp *iPtr = (Interp *) interp; |
| 4533 |
int result; |
| 4534 |
CallFrame *savedVarFramePtr; |
| 4535 |
|
| 4536 |
savedVarFramePtr = iPtr->varFramePtr; |
| 4537 |
iPtr->varFramePtr = NULL; |
| 4538 |
result = TclObjInvoke(interp, objc, objv, flags); |
| 4539 |
iPtr->varFramePtr = savedVarFramePtr; |
| 4540 |
return result; |
| 4541 |
} |
| 4542 |
|
| 4543 |
|
| 4544 |
|
| 4545 |
|
| 4546 |
|
| 4547 |
|
| 4548 |
|
| 4549 |
|
| 4550 |
|
| 4551 |
|
| 4552 |
|
| 4553 |
|
| 4554 |
|
| 4555 |
|
| 4556 |
|
| 4557 |
|
| 4558 |
|
| 4559 |
|
| 4560 |
int |
| 4561 |
TclObjInvoke(interp, objc, objv, flags) |
| 4562 |
Tcl_Interp *interp; |
| 4563 |
|
| 4564 |
int objc; |
| 4565 |
Tcl_Obj *CONST objv[]; |
| 4566 |
|
| 4567 |
int flags; |
| 4568 |
|
| 4569 |
|
| 4570 |
|
| 4571 |
{ |
| 4572 |
register Interp *iPtr = (Interp *) interp; |
| 4573 |
Tcl_HashTable *hTblPtr; |
| 4574 |
char *cmdName; |
| 4575 |
register Tcl_HashEntry *hPtr; |
| 4576 |
Tcl_Command cmd; |
| 4577 |
Command *cmdPtr; |
| 4578 |
int localObjc; |
| 4579 |
Tcl_Obj **localObjv = NULL; |
| 4580 |
register int i; |
| 4581 |
int result; |
| 4582 |
|
| 4583 |
if (interp == (Tcl_Interp *) NULL) { |
| 4584 |
return TCL_ERROR; |
| 4585 |
} |
| 4586 |
|
| 4587 |
if ((objc < 1) || (objv == (Tcl_Obj **) NULL)) { |
| 4588 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), |
| 4589 |
"illegal argument vector", -1); |
| 4590 |
return TCL_ERROR; |
| 4591 |
} |
| 4592 |
|
| 4593 |
cmdName = Tcl_GetString(objv[0]); |
| 4594 |
if (flags & TCL_INVOKE_HIDDEN) { |
| 4595 |
|
| 4596 |
|
| 4597 |
|
| 4598 |
|
| 4599 |
hPtr = NULL; |
| 4600 |
hTblPtr = ((Interp *) interp)->hiddenCmdTablePtr; |
| 4601 |
if (hTblPtr != NULL) { |
| 4602 |
hPtr = Tcl_FindHashEntry(hTblPtr, cmdName); |
| 4603 |
} |
| 4604 |
if (hPtr == NULL) { |
| 4605 |
Tcl_ResetResult(interp); |
| 4606 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 4607 |
"invalid hidden command name \"", cmdName, "\"", |
| 4608 |
(char *) NULL); |
| 4609 |
return TCL_ERROR; |
| 4610 |
} |
| 4611 |
cmdPtr = (Command *) Tcl_GetHashValue(hPtr); |
| 4612 |
} else { |
| 4613 |
cmdPtr = NULL; |
| 4614 |
cmd = Tcl_FindCommand(interp, cmdName, |
| 4615 |
(Tcl_Namespace *) NULL, TCL_GLOBAL_ONLY); |
| 4616 |
if (cmd != (Tcl_Command) NULL) { |
| 4617 |
cmdPtr = (Command *) cmd; |
| 4618 |
} |
| 4619 |
if (cmdPtr == NULL) { |
| 4620 |
if (!(flags & TCL_INVOKE_NO_UNKNOWN)) { |
| 4621 |
cmd = Tcl_FindCommand(interp, "unknown", |
| 4622 |
(Tcl_Namespace *) NULL, TCL_GLOBAL_ONLY); |
| 4623 |
if (cmd != (Tcl_Command) NULL) { |
| 4624 |
cmdPtr = (Command *) cmd; |
| 4625 |
} |
| 4626 |
if (cmdPtr != NULL) { |
| 4627 |
localObjc = (objc + 1); |
| 4628 |
localObjv = (Tcl_Obj **) |
| 4629 |
ckalloc((unsigned) (sizeof(Tcl_Obj *) * localObjc)); |
| 4630 |
localObjv[0] = Tcl_NewStringObj("unknown", -1); |
| 4631 |
Tcl_IncrRefCount(localObjv[0]); |
| 4632 |
for (i = 0; i < objc; i++) { |
| 4633 |
localObjv[i+1] = objv[i]; |
| 4634 |
} |
| 4635 |
objc = localObjc; |
| 4636 |
objv = localObjv; |
| 4637 |
} |
| 4638 |
} |
| 4639 |
|
| 4640 |
|
| 4641 |
|
| 4642 |
|
| 4643 |
|
| 4644 |
|
| 4645 |
|
| 4646 |
if (cmdPtr == NULL) { |
| 4647 |
Tcl_ResetResult(interp); |
| 4648 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 4649 |
"invalid command name \"", cmdName, "\"", |
| 4650 |
(char *) NULL); |
| 4651 |
return TCL_ERROR; |
| 4652 |
} |
| 4653 |
} |
| 4654 |
} |
| 4655 |
|
| 4656 |
|
| 4657 |
|
| 4658 |
|
| 4659 |
|
| 4660 |
|
| 4661 |
|
| 4662 |
Tcl_ResetResult(interp); |
| 4663 |
iPtr->cmdCount++; |
| 4664 |
result = (*cmdPtr->objProc)(cmdPtr->objClientData, interp, objc, objv); |
| 4665 |
|
| 4666 |
|
| 4667 |
|
| 4668 |
|
| 4669 |
|
| 4670 |
|
| 4671 |
if ((result == TCL_ERROR) |
| 4672 |
&& ((flags & TCL_INVOKE_NO_TRACEBACK) == 0) |
| 4673 |
&& ((iPtr->flags & ERR_ALREADY_LOGGED) == 0)) { |
| 4674 |
Tcl_Obj *msg; |
| 4675 |
|
| 4676 |
if (!(iPtr->flags & ERR_IN_PROGRESS)) { |
| 4677 |
msg = Tcl_NewStringObj("\n while invoking\n\"", -1); |
| 4678 |
} else { |
| 4679 |
msg = Tcl_NewStringObj("\n invoked from within\n\"", -1); |
| 4680 |
} |
| 4681 |
Tcl_IncrRefCount(msg); |
| 4682 |
for (i = 0; i < objc; i++) { |
| 4683 |
CONST char *bytes; |
| 4684 |
int length; |
| 4685 |
|
| 4686 |
Tcl_AppendObjToObj(msg, objv[i]); |
| 4687 |
bytes = Tcl_GetStringFromObj(msg, &length); |
| 4688 |
if (length > 100) { |
| 4689 |
|
| 4690 |
|
| 4691 |
|
| 4692 |
|
| 4693 |
length = 100; |
| 4694 |
while ( (bytes[length] & 0xC0) == 0x80 ) { |
| 4695 |
length--; |
| 4696 |
} |
| 4697 |
Tcl_SetObjLength(msg, length); |
| 4698 |
Tcl_AppendToObj(msg, "...", -1); |
| 4699 |
break; |
| 4700 |
} |
| 4701 |
if (i != (objc - 1)) { |
| 4702 |
Tcl_AppendToObj(msg, " ", -1); |
| 4703 |
} |
| 4704 |
} |
| 4705 |
|
| 4706 |
Tcl_AppendToObj(msg, "\"", -1); |
| 4707 |
Tcl_AddObjErrorInfo(interp, Tcl_GetString(msg), -1); |
| 4708 |
Tcl_DecrRefCount(msg); |
| 4709 |
iPtr->flags &= ~ERR_ALREADY_LOGGED; |
| 4710 |
} |
| 4711 |
|
| 4712 |
|
| 4713 |
|
| 4714 |
|
| 4715 |
|
| 4716 |
if (localObjv != (Tcl_Obj **) NULL) { |
| 4717 |
Tcl_DecrRefCount(localObjv[0]); |
| 4718 |
ckfree((char *) localObjv); |
| 4719 |
} |
| 4720 |
return result; |
| 4721 |
} |
| 4722 |
|
| 4723 |
|
| 4724 |
|
| 4725 |
|
| 4726 |
|
| 4727 |
|
| 4728 |
|
| 4729 |
|
| 4730 |
|
| 4731 |
|
| 4732 |
|
| 4733 |
|
| 4734 |
|
| 4735 |
|
| 4736 |
|
| 4737 |
|
| 4738 |
|
| 4739 |
|
| 4740 |
|
| 4741 |
|
| 4742 |
|
| 4743 |
|
| 4744 |
int |
| 4745 |
Tcl_ExprString(interp, string) |
| 4746 |
Tcl_Interp *interp; |
| 4747 |
|
| 4748 |
CONST char *string; |
| 4749 |
{ |
| 4750 |
register Tcl_Obj *exprPtr; |
| 4751 |
Tcl_Obj *resultPtr; |
| 4752 |
int length = strlen(string); |
| 4753 |
char buf[TCL_DOUBLE_SPACE]; |
| 4754 |
int result = TCL_OK; |
| 4755 |
|
| 4756 |
if (length > 0) { |
| 4757 |
TclNewObj(exprPtr); |
| 4758 |
TclInitStringRep(exprPtr, string, length); |
| 4759 |
Tcl_IncrRefCount(exprPtr); |
| 4760 |
|
| 4761 |
result = Tcl_ExprObj(interp, exprPtr, &resultPtr); |
| 4762 |
if (result == TCL_OK) { |
| 4763 |
|
| 4764 |
|
| 4765 |
|
| 4766 |
|
| 4767 |
if (resultPtr->typePtr == &tclIntType) { |
| 4768 |
sprintf(buf, "%ld", resultPtr->internalRep.longValue); |
| 4769 |
Tcl_SetResult(interp, buf, TCL_VOLATILE); |
| 4770 |
} else if (resultPtr->typePtr == &tclDoubleType) { |
| 4771 |
Tcl_PrintDouble((Tcl_Interp *) NULL, |
| 4772 |
resultPtr->internalRep.doubleValue, buf); |
| 4773 |
Tcl_SetResult(interp, buf, TCL_VOLATILE); |
| 4774 |
} else { |
| 4775 |
|
| 4776 |
|
| 4777 |
|
| 4778 |
|
| 4779 |
Tcl_SetResult(interp, TclGetString(resultPtr), |
| 4780 |
TCL_VOLATILE); |
| 4781 |
} |
| 4782 |
Tcl_DecrRefCount(resultPtr); |
| 4783 |
} else { |
| 4784 |
|
| 4785 |
|
| 4786 |
|
| 4787 |
|
| 4788 |
|
| 4789 |
Tcl_SetResult(interp, TclGetString(Tcl_GetObjResult(interp)), |
| 4790 |
TCL_VOLATILE); |
| 4791 |
} |
| 4792 |
Tcl_DecrRefCount(exprPtr); |
| 4793 |
} else { |
| 4794 |
|
| 4795 |
|
| 4796 |
|
| 4797 |
|
| 4798 |
Tcl_SetResult(interp, "0", TCL_VOLATILE); |
| 4799 |
} |
| 4800 |
return result; |
| 4801 |
} |
| 4802 |
|
| 4803 |
|
| 4804 |
|
| 4805 |
|
| 4806 |
|
| 4807 |
|
| 4808 |
|
| 4809 |
|
| 4810 |
|
| 4811 |
|
| 4812 |
|
| 4813 |
|
| 4814 |
|
| 4815 |
|
| 4816 |
|
| 4817 |
|
| 4818 |
|
| 4819 |
|
| 4820 |
|
| 4821 |
|
| 4822 |
|
| 4823 |
|
| 4824 |
|
| 4825 |
|
| 4826 |
|
| 4827 |
|
| 4828 |
|
| 4829 |
|
| 4830 |
|
| 4831 |
|
| 4832 |
|
| 4833 |
|
| 4834 |
|
| 4835 |
|
| 4836 |
|
| 4837 |
|
| 4838 |
|
| 4839 |
|
| 4840 |
|
| 4841 |
|
| 4842 |
|
| 4843 |
|
| 4844 |
|
| 4845 |
|
| 4846 |
|
| 4847 |
|
| 4848 |
|
| 4849 |
|
| 4850 |
|
| 4851 |
|
| 4852 |
|
| 4853 |
|
| 4854 |
|
| 4855 |
|
| 4856 |
|
| 4857 |
|
| 4858 |
|
| 4859 |
|
| 4860 |
|
| 4861 |
|
| 4862 |
|
| 4863 |
|
| 4864 |
Tcl_Trace |
| 4865 |
Tcl_CreateObjTrace( interp, level, flags, proc, clientData, delProc ) |
| 4866 |
Tcl_Interp* interp; |
| 4867 |
int level; |
| 4868 |
int flags; |
| 4869 |
Tcl_CmdObjTraceProc* proc; |
| 4870 |
ClientData clientData; |
| 4871 |
Tcl_CmdObjTraceDeleteProc* delProc; |
| 4872 |
|
| 4873 |
{ |
| 4874 |
register Trace *tracePtr; |
| 4875 |
register Interp *iPtr = (Interp *) interp; |
| 4876 |
|
| 4877 |
|
| 4878 |
|
| 4879 |
if (!(flags & TCL_ALLOW_INLINE_COMPILATION)) { |
| 4880 |
if (iPtr->tracesForbiddingInline == 0) { |
| 4881 |
|
| 4882 |
|
| 4883 |
|
| 4884 |
|
| 4885 |
|
| 4886 |
|
| 4887 |
|
| 4888 |
|
| 4889 |
|
| 4890 |
|
| 4891 |
|
| 4892 |
|
| 4893 |
iPtr->compileEpoch++; |
| 4894 |
iPtr->flags |= DONT_COMPILE_CMDS_INLINE; |
| 4895 |
} |
| 4896 |
iPtr->tracesForbiddingInline++; |
| 4897 |
} |
| 4898 |
|
| 4899 |
tracePtr = (Trace *) ckalloc(sizeof(Trace)); |
| 4900 |
tracePtr->level = level; |
| 4901 |
tracePtr->proc = proc; |
| 4902 |
tracePtr->clientData = clientData; |
| 4903 |
tracePtr->delProc = delProc; |
| 4904 |
tracePtr->nextPtr = iPtr->tracePtr; |
| 4905 |
tracePtr->flags = flags; |
| 4906 |
iPtr->tracePtr = tracePtr; |
| 4907 |
|
| 4908 |
return (Tcl_Trace) tracePtr; |
| 4909 |
} |
| 4910 |
|
| 4911 |
|
| 4912 |
|
| 4913 |
|
| 4914 |
|
| 4915 |
|
| 4916 |
|
| 4917 |
|
| 4918 |
|
| 4919 |
|
| 4920 |
|
| 4921 |
|
| 4922 |
|
| 4923 |
|
| 4924 |
|
| 4925 |
|
| 4926 |
|
| 4927 |
|
| 4928 |
|
| 4929 |
|
| 4930 |
|
| 4931 |
|
| 4932 |
|
| 4933 |
|
| 4934 |
|
| 4935 |
|
| 4936 |
|
| 4937 |
|
| 4938 |
|
| 4939 |
|
| 4940 |
|
| 4941 |
|
| 4942 |
|
| 4943 |
|
| 4944 |
|
| 4945 |
|
| 4946 |
|
| 4947 |
|
| 4948 |
|
| 4949 |
|
| 4950 |
|
| 4951 |
|
| 4952 |
|
| 4953 |
|
| 4954 |
Tcl_Trace |
| 4955 |
Tcl_CreateTrace(interp, level, proc, clientData) |
| 4956 |
Tcl_Interp *interp; |
| 4957 |
int level; |
| 4958 |
|
| 4959 |
Tcl_CmdTraceProc *proc; |
| 4960 |
|
| 4961 |
ClientData clientData; |
| 4962 |
{ |
| 4963 |
StringTraceData* data; |
| 4964 |
data = (StringTraceData*) ckalloc( sizeof( *data )); |
| 4965 |
data->clientData = clientData; |
| 4966 |
data->proc = proc; |
| 4967 |
return Tcl_CreateObjTrace( interp, level, 0, StringTraceProc, |
| 4968 |
(ClientData) data, StringTraceDeleteProc ); |
| 4969 |
} |
| 4970 |
|
| 4971 |
|
| 4972 |
|
| 4973 |
|
| 4974 |
|
| 4975 |
|
| 4976 |
|
| 4977 |
|
| 4978 |
|
| 4979 |
|
| 4980 |
|
| 4981 |
|
| 4982 |
|
| 4983 |
|
| 4984 |
|
| 4985 |
|
| 4986 |
|
| 4987 |
|
| 4988 |
static int |
| 4989 |
StringTraceProc( clientData, interp, level, command, commandInfo, objc, objv ) |
| 4990 |
ClientData clientData; |
| 4991 |
Tcl_Interp* interp; |
| 4992 |
int level; |
| 4993 |
CONST char* command; |
| 4994 |
Tcl_Command commandInfo; |
| 4995 |
int objc; |
| 4996 |
Tcl_Obj *CONST *objv; |
| 4997 |
{ |
| 4998 |
StringTraceData* data = (StringTraceData*) clientData; |
| 4999 |
Command* cmdPtr = (Command*) commandInfo; |
| 5000 |
|
| 5001 |
CONST char** argv; |
| 5002 |
|
| 5003 |
int i; |
| 5004 |
|
| 5005 |
|
| 5006 |
|
| 5007 |
|
| 5008 |
|
| 5009 |
|
| 5010 |
argv = (CONST char **) ckalloc((unsigned) ( (objc + 1) |
| 5011 |
* sizeof(CONST char *) )); |
| 5012 |
for (i = 0; i < objc; i++) { |
| 5013 |
argv[i] = Tcl_GetString(objv[i]); |
| 5014 |
} |
| 5015 |
argv[objc] = 0; |
| 5016 |
|
| 5017 |
|
| 5018 |
|
| 5019 |
|
| 5020 |
|
| 5021 |
|
| 5022 |
|
| 5023 |
( data->proc )( data->clientData, interp, level, |
| 5024 |
(char*) command, cmdPtr->proc, cmdPtr->clientData, |
| 5025 |
objc, argv ); |
| 5026 |
ckfree( (char*) argv ); |
| 5027 |
|
| 5028 |
return TCL_OK; |
| 5029 |
} |
| 5030 |
|
| 5031 |
|
| 5032 |
|
| 5033 |
|
| 5034 |
|
| 5035 |
|
| 5036 |
|
| 5037 |
|
| 5038 |
|
| 5039 |
|
| 5040 |
|
| 5041 |
|
| 5042 |
|
| 5043 |
|
| 5044 |
|
| 5045 |
|
| 5046 |
|
| 5047 |
static void |
| 5048 |
StringTraceDeleteProc( clientData ) |
| 5049 |
ClientData clientData; |
| 5050 |
{ |
| 5051 |
ckfree( (char*) clientData ); |
| 5052 |
} |
| 5053 |
|
| 5054 |
|
| 5055 |
|
| 5056 |
|
| 5057 |
|
| 5058 |
|
| 5059 |
|
| 5060 |
|
| 5061 |
|
| 5062 |
|
| 5063 |
|
| 5064 |
|
| 5065 |
|
| 5066 |
|
| 5067 |
|
| 5068 |
|
| 5069 |
|
| 5070 |
|
| 5071 |
void |
| 5072 |
Tcl_DeleteTrace(interp, trace) |
| 5073 |
Tcl_Interp *interp; |
| 5074 |
Tcl_Trace trace; |
| 5075 |
|
| 5076 |
{ |
| 5077 |
Interp *iPtr = (Interp *) interp; |
| 5078 |
Trace *tracePtr = (Trace *) trace; |
| 5079 |
register Trace **tracePtr2 = &(iPtr->tracePtr); |
| 5080 |
|
| 5081 |
|
| 5082 |
|
| 5083 |
|
| 5084 |
|
| 5085 |
|
| 5086 |
while ((*tracePtr2) != NULL && (*tracePtr2) != tracePtr) { |
| 5087 |
tracePtr2 = &((*tracePtr2)->nextPtr); |
| 5088 |
} |
| 5089 |
if (*tracePtr2 == NULL) { |
| 5090 |
return; |
| 5091 |
} |
| 5092 |
(*tracePtr2) = (*tracePtr2)->nextPtr; |
| 5093 |
|
| 5094 |
|
| 5095 |
|
| 5096 |
|
| 5097 |
|
| 5098 |
|
| 5099 |
|
| 5100 |
|
| 5101 |
if (!(tracePtr->flags & TCL_ALLOW_INLINE_COMPILATION)) { |
| 5102 |
iPtr->tracesForbiddingInline--; |
| 5103 |
if (iPtr->tracesForbiddingInline == 0) { |
| 5104 |
iPtr->flags &= ~DONT_COMPILE_CMDS_INLINE; |
| 5105 |
iPtr->compileEpoch++; |
| 5106 |
} |
| 5107 |
} |
| 5108 |
|
| 5109 |
|
| 5110 |
|
| 5111 |
|
| 5112 |
|
| 5113 |
if (tracePtr->delProc != NULL) { |
| 5114 |
(tracePtr->delProc)(tracePtr->clientData); |
| 5115 |
} |
| 5116 |
|
| 5117 |
|
| 5118 |
|
| 5119 |
Tcl_EventuallyFree((char*)tracePtr, TCL_DYNAMIC); |
| 5120 |
} |
| 5121 |
|
| 5122 |
|
| 5123 |
|
| 5124 |
|
| 5125 |
|
| 5126 |
|
| 5127 |
|
| 5128 |
|
| 5129 |
|
| 5130 |
|
| 5131 |
|
| 5132 |
|
| 5133 |
|
| 5134 |
|
| 5135 |
|
| 5136 |
|
| 5137 |
|
| 5138 |
|
| 5139 |
|
| 5140 |
|
| 5141 |
|
| 5142 |
|
| 5143 |
void |
| 5144 |
Tcl_AddErrorInfo(interp, message) |
| 5145 |
Tcl_Interp *interp; |
| 5146 |
|
| 5147 |
CONST char *message; |
| 5148 |
{ |
| 5149 |
Tcl_AddObjErrorInfo(interp, message, -1); |
| 5150 |
} |
| 5151 |
|
| 5152 |
|
| 5153 |
|
| 5154 |
|
| 5155 |
|
| 5156 |
|
| 5157 |
|
| 5158 |
|
| 5159 |
|
| 5160 |
|
| 5161 |
|
| 5162 |
|
| 5163 |
|
| 5164 |
|
| 5165 |
|
| 5166 |
|
| 5167 |
|
| 5168 |
|
| 5169 |
|
| 5170 |
|
| 5171 |
|
| 5172 |
|
| 5173 |
|
| 5174 |
|
| 5175 |
void |
| 5176 |
Tcl_AddObjErrorInfo(interp, message, length) |
| 5177 |
Tcl_Interp *interp; |
| 5178 |
|
| 5179 |
CONST char *message; |
| 5180 |
|
| 5181 |
int length; |
| 5182 |
|
| 5183 |
|
| 5184 |
{ |
| 5185 |
register Interp *iPtr = (Interp *) interp; |
| 5186 |
Tcl_Obj *messagePtr; |
| 5187 |
|
| 5188 |
|
| 5189 |
|
| 5190 |
|
| 5191 |
|
| 5192 |
|
| 5193 |
if (!(iPtr->flags & ERR_IN_PROGRESS)) { |
| 5194 |
iPtr->flags |= ERR_IN_PROGRESS; |
| 5195 |
|
| 5196 |
if (iPtr->result[0] == 0) { |
| 5197 |
Tcl_ObjSetVar2(interp, iPtr->execEnvPtr->errorInfo, NULL, |
| 5198 |
iPtr->objResultPtr, TCL_GLOBAL_ONLY); |
| 5199 |
} else { |
| 5200 |
Tcl_ObjSetVar2(interp, iPtr->execEnvPtr->errorInfo, NULL, |
| 5201 |
Tcl_NewStringObj(interp->result, -1), TCL_GLOBAL_ONLY); |
| 5202 |
} |
| 5203 |
|
| 5204 |
|
| 5205 |
|
| 5206 |
|
| 5207 |
|
| 5208 |
|
| 5209 |
if (!(iPtr->flags & ERROR_CODE_SET)) { |
| 5210 |
Tcl_ObjSetVar2(interp, iPtr->execEnvPtr->errorCode, NULL, |
| 5211 |
Tcl_NewStringObj("NONE", -1), TCL_GLOBAL_ONLY); |
| 5212 |
} |
| 5213 |
} |
| 5214 |
|
| 5215 |
|
| 5216 |
|
| 5217 |
|
| 5218 |
|
| 5219 |
if (length != 0) { |
| 5220 |
messagePtr = Tcl_NewStringObj(message, length); |
| 5221 |
Tcl_IncrRefCount(messagePtr); |
| 5222 |
Tcl_ObjSetVar2(interp, iPtr->execEnvPtr->errorInfo, NULL, |
| 5223 |
messagePtr, (TCL_GLOBAL_ONLY | TCL_APPEND_VALUE)); |
| 5224 |
Tcl_DecrRefCount(messagePtr); |
| 5225 |
} |
| 5226 |
} |
| 5227 |
|
| 5228 |
|
| 5229 |
|
| 5230 |
|
| 5231 |
|
| 5232 |
|
| 5233 |
|
| 5234 |
|
| 5235 |
|
| 5236 |
|
| 5237 |
|
| 5238 |
|
| 5239 |
|
| 5240 |
|
| 5241 |
|
| 5242 |
|
| 5243 |
|
| 5244 |
|
| 5245 |
|
| 5246 |
int |
| 5247 |
Tcl_VarEvalVA (interp, argList) |
| 5248 |
Tcl_Interp *interp; |
| 5249 |
va_list argList; |
| 5250 |
{ |
| 5251 |
Tcl_DString buf; |
| 5252 |
char *string; |
| 5253 |
int result; |
| 5254 |
|
| 5255 |
|
| 5256 |
|
| 5257 |
|
| 5258 |
|
| 5259 |
|
| 5260 |
|
| 5261 |
|
| 5262 |
Tcl_DStringInit(&buf); |
| 5263 |
while (1) { |
| 5264 |
string = va_arg(argList, char *); |
| 5265 |
if (string == NULL) { |
| 5266 |
break; |
| 5267 |
} |
| 5268 |
Tcl_DStringAppend(&buf, string, -1); |
| 5269 |
} |
| 5270 |
|
| 5271 |
result = Tcl_Eval(interp, Tcl_DStringValue(&buf)); |
| 5272 |
Tcl_DStringFree(&buf); |
| 5273 |
return result; |
| 5274 |
} |
| 5275 |
|
| 5276 |
|
| 5277 |
|
| 5278 |
|
| 5279 |
|
| 5280 |
|
| 5281 |
|
| 5282 |
|
| 5283 |
|
| 5284 |
|
| 5285 |
|
| 5286 |
|
| 5287 |
|
| 5288 |
|
| 5289 |
|
| 5290 |
|
| 5291 |
|
| 5292 |
|
| 5293 |
|
| 5294 |
int |
| 5295 |
Tcl_VarEval TCL_VARARGS_DEF(Tcl_Interp *,arg1) |
| 5296 |
{ |
| 5297 |
Tcl_Interp *interp; |
| 5298 |
va_list argList; |
| 5299 |
int result; |
| 5300 |
|
| 5301 |
interp = TCL_VARARGS_START(Tcl_Interp *,arg1,argList); |
| 5302 |
result = Tcl_VarEvalVA(interp, argList); |
| 5303 |
va_end(argList); |
| 5304 |
|
| 5305 |
return result; |
| 5306 |
} |
| 5307 |
|
| 5308 |
|
| 5309 |
|
| 5310 |
|
| 5311 |
|
| 5312 |
|
| 5313 |
|
| 5314 |
|
| 5315 |
|
| 5316 |
|
| 5317 |
|
| 5318 |
|
| 5319 |
|
| 5320 |
|
| 5321 |
|
| 5322 |
|
| 5323 |
|
| 5324 |
|
| 5325 |
|
| 5326 |
|
| 5327 |
|
| 5328 |
int |
| 5329 |
Tcl_GlobalEval(interp, command) |
| 5330 |
Tcl_Interp *interp; |
| 5331 |
CONST char *command; |
| 5332 |
{ |
| 5333 |
register Interp *iPtr = (Interp *) interp; |
| 5334 |
int result; |
| 5335 |
CallFrame *savedVarFramePtr; |
| 5336 |
|
| 5337 |
savedVarFramePtr = iPtr->varFramePtr; |
| 5338 |
iPtr->varFramePtr = NULL; |
| 5339 |
result = Tcl_Eval(interp, command); |
| 5340 |
iPtr->varFramePtr = savedVarFramePtr; |
| 5341 |
return result; |
| 5342 |
} |
| 5343 |
|
| 5344 |
|
| 5345 |
|
| 5346 |
|
| 5347 |
|
| 5348 |
|
| 5349 |
|
| 5350 |
|
| 5351 |
|
| 5352 |
|
| 5353 |
|
| 5354 |
|
| 5355 |
|
| 5356 |
|
| 5357 |
|
| 5358 |
|
| 5359 |
|
| 5360 |
|
| 5361 |
int |
| 5362 |
Tcl_SetRecursionLimit(interp, depth) |
| 5363 |
Tcl_Interp *interp; |
| 5364 |
|
| 5365 |
int depth; |
| 5366 |
{ |
| 5367 |
Interp *iPtr = (Interp *) interp; |
| 5368 |
int old; |
| 5369 |
|
| 5370 |
old = iPtr->maxNestingDepth; |
| 5371 |
if (depth > 0) { |
| 5372 |
iPtr->maxNestingDepth = depth; |
| 5373 |
} |
| 5374 |
return old; |
| 5375 |
} |
| 5376 |
|
| 5377 |
|
| 5378 |
|
| 5379 |
|
| 5380 |
|
| 5381 |
|
| 5382 |
|
| 5383 |
|
| 5384 |
|
| 5385 |
|
| 5386 |
|
| 5387 |
|
| 5388 |
|
| 5389 |
|
| 5390 |
|
| 5391 |
|
| 5392 |
|
| 5393 |
|
| 5394 |
|
| 5395 |
|
| 5396 |
|
| 5397 |
void |
| 5398 |
Tcl_AllowExceptions(interp) |
| 5399 |
Tcl_Interp *interp; |
| 5400 |
{ |
| 5401 |
Interp *iPtr = (Interp *) interp; |
| 5402 |
|
| 5403 |
iPtr->evalFlags |= TCL_ALLOW_EXCEPTIONS; |
| 5404 |
} |
| 5405 |
|
| 5406 |
|
| 5407 |
|
| 5408 |
|
| 5409 |
|
| 5410 |
|
| 5411 |
|
| 5412 |
|
| 5413 |
|
| 5414 |
|
| 5415 |
|
| 5416 |
|
| 5417 |
|
| 5418 |
|
| 5419 |
|
| 5420 |
|
| 5421 |
|
| 5422 |
|
| 5423 |
|
| 5424 |
|
| 5425 |
void |
| 5426 |
Tcl_GetVersion(majorV, minorV, patchLevelV, type) |
| 5427 |
int *majorV; |
| 5428 |
int *minorV; |
| 5429 |
int *patchLevelV; |
| 5430 |
int *type; |
| 5431 |
{ |
| 5432 |
if (majorV != NULL) { |
| 5433 |
*majorV = TCL_MAJOR_VERSION; |
| 5434 |
} |
| 5435 |
if (minorV != NULL) { |
| 5436 |
*minorV = TCL_MINOR_VERSION; |
| 5437 |
} |
| 5438 |
if (patchLevelV != NULL) { |
| 5439 |
*patchLevelV = TCL_RELEASE_SERIAL; |
| 5440 |
} |
| 5441 |
if (type != NULL) { |
| 5442 |
*type = TCL_RELEASE_LEVEL; |
| 5443 |
} |
| 5444 |
} |
| 5445 |
|