diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2016-11-25 15:06:13 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2016-11-25 15:06:13 (GMT) |
commit | 889b8febfba9a5853a367eaf01fa14b4040087d7 (patch) | |
tree | ac31caa64067eb47d063456c7a53d6eeadd09f5a /generic/tclPkg.c | |
parent | bd4ade16893719f146b31f467f5b1cbd2d7a393c (diff) | |
parent | 7b4af51ed2c67661856796cc6669052b86bda825 (diff) | |
download | tcl-889b8febfba9a5853a367eaf01fa14b4040087d7.zip tcl-889b8febfba9a5853a367eaf01fa14b4040087d7.tar.gz tcl-889b8febfba9a5853a367eaf01fa14b4040087d7.tar.bz2 |
Merge trunk.
Implementation looks complete. Still missing: test-cases and documentation.
Diffstat (limited to 'generic/tclPkg.c')
-rw-r--r-- | generic/tclPkg.c | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/generic/tclPkg.c b/generic/tclPkg.c index 3d052a6..c258987 100644 --- a/generic/tclPkg.c +++ b/generic/tclPkg.c @@ -204,12 +204,20 @@ static void PkgFilesCleanupProc(ClientData clientData, Tcl_Interp *interp) { PkgFiles *pkgFiles = (PkgFiles *) clientData; + Tcl_HashSearch search; + Tcl_HashEntry *entry; while (pkgFiles->names) { PkgName *name = pkgFiles->names; pkgFiles->names = name->nextPtr; ckfree(name); } + entry = Tcl_FirstHashEntry(&pkgFiles->table, &search); + while (entry) { + Tcl_Obj *obj = (Tcl_Obj *)Tcl_GetHashValue(entry); + Tcl_DecrRefCount(obj); + entry = Tcl_NextHashEntry(&search); + } Tcl_DeleteHashTable(&pkgFiles->table); return; } @@ -217,9 +225,20 @@ static void PkgFilesCleanupProc(ClientData clientData, void TclPkgFileSeen(Tcl_Interp *interp, const char *fileName) { PkgFiles *pkgFiles = (PkgFiles *) Tcl_GetAssocData(interp, "tclPkgFiles", NULL); - if (pkgFiles) { + if (pkgFiles && pkgFiles->names) { const char *name = pkgFiles->names->name; - printf("Seen %s for package %s\n", fileName, name); + Tcl_HashTable *table = &pkgFiles->table; + int new; + Tcl_HashEntry *entry = Tcl_CreateHashEntry(table, name, &new); + Tcl_Obj *obj = Tcl_NewStringObj(fileName, -1); + + if (new) { + Tcl_SetHashValue(entry, obj); + Tcl_IncrRefCount(obj); + } else { + Tcl_Obj *list = Tcl_GetHashValue(entry); + Tcl_ListObjAppendElement(interp, list, obj); + } } } @@ -848,24 +867,19 @@ Tcl_PackageObjCmd( } switch ((enum pkgOptions) optionIndex) { case PKG_FILES: { - const char *keyString; - Tcl_Obj *result = Tcl_NewObj(); + PkgFiles *pkgFiles; - for (i = 2; i < objc; i++) { - keyString = TclGetString(objv[i]); - hPtr = Tcl_FindHashEntry(&iPtr->packageTable, keyString); - if (hPtr == NULL) { - continue; - } - pkgPtr = Tcl_GetHashValue(hPtr); - availPtr = pkgPtr->availPtr; - while (availPtr != NULL) { - Tcl_ListObjAppendElement(interp, result, Tcl_NewStringObj(availPtr->script, -1)); - availPtr = availPtr->nextPtr; + if (objc != 3) { + Tcl_WrongNumArgs(interp, 2, objv, "package"); + return TCL_ERROR; + } + pkgFiles = (PkgFiles *) Tcl_GetAssocData(interp, "tclPkgFiles", NULL); + if (pkgFiles) { + Tcl_HashEntry *entry = Tcl_FindHashEntry(&pkgFiles->table, Tcl_GetString(objv[2])); + if (entry) { + Tcl_SetObjResult(interp, (Tcl_Obj *)Tcl_GetHashValue(entry)); } - ckfree(pkgPtr); } - Tcl_SetObjResult(interp, result); break; } case PKG_FORGET: { |