Tcl Source Code

Artifact Content
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Artifact 4355d0d575e6b12f27503b7edf97129c27330202:

Attachment "tip261.patch" to ticket [1437008fff] added by dgp 2006-11-05 12:32:39.
Index: generic/tclNamesp.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclNamesp.c,v
retrieving revision 1.117
diff -u -r1.117 tclNamesp.c
--- generic/tclNamesp.c	2 Nov 2006 16:57:54 -0000	1.117
+++ generic/tclNamesp.c	5 Nov 2006 05:30:55 -0000
@@ -3705,6 +3705,10 @@
  *	treated as an error. But if the "-force" option is included, then
  *	existing commands are overwritten by the imported commands.
  *
+ *	If there are no pattern arguments and the "-force" flag isn't given,
+ *	this command returns the list of commands currently imported in
+ *	the current namespace.
+ *
  * Results:
  *	Returns TCL_OK if successful, and TCL_ERROR if anything goes wrong.
  *
@@ -3744,6 +3748,24 @@
 	    allowOverwrite = 1;
 	    firstArg++;
 	}
+    } else {
+	/* objc == 2;  Command is just [namespace import];
+	 * Introspection form to return list of imported commands. */
+	Tcl_HashEntry *hPtr;
+	Tcl_HashSearch search;
+	Namespace *nsPtr = (Namespace *) Tcl_GetCurrentNamespace(interp);
+	Tcl_Obj *listPtr = Tcl_NewObj();
+
+	for (hPtr = Tcl_FirstHashEntry(&nsPtr->cmdTable, &search);
+		hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
+  	    Command *cmdPtr = (Command *) Tcl_GetHashValue(hPtr);
+	    if (cmdPtr->deleteProc == DeleteImportedCmd) {
+		Tcl_ListObjAppendElement(NULL, listPtr, Tcl_NewStringObj(
+			Tcl_GetHashKey(&nsPtr->cmdTable, hPtr) ,-1));
+	    }
+	}
+	Tcl_SetObjResult(interp, listPtr);
+	return TCL_OK;
     }
 
     /*