summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authorhobbs <hobbs>1999-08-19 02:59:08 (GMT)
committerhobbs <hobbs>1999-08-19 02:59:08 (GMT)
commit92e37b2bd18d8a5451699c466c1664e53403da57 (patch)
tree4ca4faf0835ac78d536738f2e313561972b933c0 /generic/tclIO.c
parent5e5c7d8418d3fbd50e237bc02c7c8d65618f5235 (diff)
downloadtcl-92e37b2bd18d8a5451699c466c1664e53403da57.zip
tcl-92e37b2bd18d8a5451699c466c1664e53403da57.tar.gz
tcl-92e37b2bd18d8a5451699c466c1664e53403da57.tar.bz2
1999-08-18 Jeff Hobbs <hobbs@scriptics.com>
* doc/OpenFileChnl.3: * doc/file.n: * tests/cmdAH.test: * tclIO.c: * tclCmdAH.c: added "file channels ?pattern?" tcl command, with associated Tcl_GetChannelNames and Tcl_GetChannelNamesEx public C APIs (added to tcl.decls as well), with docs and tests. * generic/tclCompile.c: add TCL_TOKEN_VARIABLE to the part types that cause differed compilation for exprs, to correct the expr double-evaluation problem for vars. Added test cases.
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c42
1 files changed, 35 insertions, 7 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index c35147d..ea281a4 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclIO.c,v 1.14 1999/08/10 17:35:18 redman Exp $
+ * RCS: @(#) $Id: tclIO.c,v 1.15 1999/08/19 02:59:10 hobbs Exp $
*/
#include "tclInt.h"
@@ -8157,7 +8157,6 @@ SetBlockMode(interp, chanPtr, mode)
}
return TCL_OK;
}
-
/*
*----------------------------------------------------------------------
@@ -8178,13 +8177,39 @@ SetBlockMode(interp, chanPtr, mode)
int
Tcl_GetChannelNames(Tcl_Interp *interp)
{
+ return Tcl_GetChannelNamesEx(interp, (char *) NULL);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Tcl_GetChannelNamesEx --
+ *
+ * Return the names of open channels in the interp filtered
+ * filtered through a pattern. If pattern is NULL, it returns
+ * all the open channels.
+ *
+ * Results:
+ * TCL_OK or TCL_ERROR.
+ *
+ * Side effects:
+ * Interp result modified with list of channel names.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+Tcl_GetChannelNamesEx(Tcl_Interp *interp, char *pattern)
+{
Channel *chanPtr;
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
char *name;
+ Tcl_Obj *resultPtr;
- Tcl_ResetResult(interp);
- chanPtr = tsdPtr->firstChanPtr;
- while (chanPtr != NULL) {
+ resultPtr = Tcl_GetObjResult(interp);
+ for (chanPtr = tsdPtr->firstChanPtr;
+ chanPtr != NULL;
+ chanPtr = chanPtr->nextChanPtr) {
if (chanPtr == (Channel *) tsdPtr->stdinChannel) {
name = "stdin";
} else if (chanPtr == (Channel *) tsdPtr->stdoutChannel) {
@@ -8194,8 +8219,11 @@ Tcl_GetChannelNames(Tcl_Interp *interp)
} else {
name = chanPtr->channelName;
}
- Tcl_AppendElement(interp, name);
- chanPtr = chanPtr->nextChanPtr;
+ if (((pattern == NULL) || Tcl_StringMatch(name, pattern)) &&
+ (Tcl_ListObjAppendElement(interp, resultPtr,
+ Tcl_NewStringObj(name, -1)) != TCL_OK)) {
+ return TCL_ERROR;
+ }
}
return TCL_OK;
}