diff options
author | vincentdarley <vincentdarley> | 2001-07-31 19:12:05 (GMT) |
---|---|---|
committer | vincentdarley <vincentdarley> | 2001-07-31 19:12:05 (GMT) |
commit | c1335a91a0a2d1b2b776c7bbb5763b90e3d629ad (patch) | |
tree | 1ec44ca71eb2e561881490f7766175daa65dc9eb /generic/tclEncoding.c | |
parent | 2414705dd748a119ffa0a2976ed71abc283aff11 (diff) | |
download | tcl-c1335a91a0a2d1b2b776c7bbb5763b90e3d629ad.zip tcl-c1335a91a0a2d1b2b776c7bbb5763b90e3d629ad.tar.gz tcl-c1335a91a0a2d1b2b776c7bbb5763b90e3d629ad.tar.bz2 |
Changes from TIP#17 "Redo Tcl's filesystem"
The following files were impacted.
* doc/Access.3:
* doc/FileSystem.3:
* doc/OpenFileChnl.3:
* doc/file.n:
* doc/glob.n:
* generic/tcl.decls:
* generic/tcl.h:
* generic/tclCmdAH.c:
* generic/tclCmdIL.c:
* generic/tclCmdMZ.c:
* generic/tclDate.c:
* generic/tclDecls.h:
* generic/tclEncoding.c:
* generic/tclFCmd.c:
* generic/tclFileName.c:
* generic/tclGetDate.y:
* generic/tclIO.c:
* generic/tclIOCmd.c:
* generic/tclIOUtil.c:
* generic/tclInt.decls:
* generic/tclInt.h:
* generic/tclIntDecls.h:
* generic/tclLoad.c:
* generic/tclStubInit.c:
* generic/tclTest.c:
* generic/tclUtil.c:
* library/init.tcl:
* mac/tclMacFCmd.c:
* mac/tclMacFile.c:
* mac/tclMacInit.c:
* mac/tclMacPort.h:
* mac/tclMacResource.c:
* mac/tclMacTime.c:
* tests/cmdAH.test:
* tests/event.test:
* tests/fCmd.test:
* tests/fileName.test:
* tests/io.test:
* tests/ioCmd.test:
* tests/proc-old.test:
* tests/registry.test:
* tests/unixFCmd.test:
* tests/winDde.test:
* tests/winFCmd.test:
* unix/mkLinks:
* unix/tclUnixFCmd.c:
* unix/tclUnixFile.c:
* unix/tclUnixInit.c:
* unix/tclUnixPipe.c:
* win/tclWinFCmd.c:
* win/tclWinFile.c:
* win/tclWinInit.c:
* win/tclWinPipe.c
Diffstat (limited to 'generic/tclEncoding.c')
-rw-r--r-- | generic/tclEncoding.c | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index beb36e5..f7bc742 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclEncoding.c,v 1.6 2000/12/08 18:55:58 andreas_kupries Exp $ + * RCS: @(#) $Id: tclEncoding.c,v 1.7 2001/07/31 19:12:06 vincentdarley Exp $ */ #include "tclInt.h" @@ -563,20 +563,22 @@ Tcl_GetEncodingNames(interp) if (pathPtr != NULL) { int i, objc; Tcl_Obj **objv; - Tcl_DString pwdString; char globArgString[10]; - + Tcl_Obj* encodingObj = Tcl_NewStringObj("encoding",-1); + Tcl_IncrRefCount(encodingObj); + objc = 0; Tcl_ListObjGetElements(NULL, pathPtr, &objc, &objv); - Tcl_GetCwd(interp, &pwdString); - for (i = 0; i < objc; i++) { - char *string; - int j, objc2, length; - Tcl_Obj **objv2; - - string = Tcl_GetStringFromObj(objv[i], NULL); + Tcl_Obj *searchIn; + + /* + * Construct the path from the element of pathPtr, + * joined with 'encoding'. + */ + searchIn = Tcl_FSJoinToPath(objv[i],1,&encodingObj); + Tcl_IncrRefCount(searchIn); Tcl_ResetResult(interp); /* @@ -586,15 +588,22 @@ Tcl_GetEncodingNames(interp) */ strcpy(globArgString, "*.enc"); - if ((Tcl_Chdir(string) == 0) - && (Tcl_Chdir("encoding") == 0) - && (TclGlob(interp, globArgString, NULL, 0, NULL) == TCL_OK)) { - objc2 = 0; + /* + * The GLOBMODE_TAILS flag returns just the tail of each file + * which is the encoding name with a .enc extension + */ + if ((TclGlob(interp, globArgString, searchIn, + TCL_GLOBMODE_TAILS, NULL) == TCL_OK)) { + int objc2 = 0; + Tcl_Obj **objv2; + int j; Tcl_ListObjGetElements(NULL, Tcl_GetObjResult(interp), &objc2, &objv2); for (j = 0; j < objc2; j++) { + int length; + char *string; string = Tcl_GetStringFromObj(objv2[j], &length); length -= 4; if (length > 0) { @@ -604,9 +613,9 @@ Tcl_GetEncodingNames(interp) } } } - Tcl_Chdir(Tcl_DStringValue(&pwdString)); + Tcl_DecrRefCount(searchIn); } - Tcl_DStringFree(&pwdString); + Tcl_DecrRefCount(encodingObj); } /* @@ -1275,6 +1284,7 @@ OpenEncodingFile(dir, name) Tcl_DString pathString; char *path; Tcl_Channel chan; + Tcl_Obj *pathPtr; argv[0] = (char *) dir; argv[1] = "encoding"; @@ -1283,7 +1293,12 @@ OpenEncodingFile(dir, name) Tcl_DStringInit(&pathString); Tcl_JoinPath(3, argv, &pathString); path = Tcl_DStringAppend(&pathString, ".enc", -1); - chan = Tcl_OpenFileChannel(NULL, path, "r", 0); + pathPtr = Tcl_NewStringObj(path,-1); + + Tcl_IncrRefCount(pathPtr); + chan = Tcl_FSOpenFileChannel(NULL, pathPtr, "r", 0); + Tcl_DecrRefCount(pathPtr); + Tcl_DStringFree(&pathString); return chan; |