diff options
author | Steve Bennett <steveb@workware.net.au> | 2010-01-24 10:53:36 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2010-10-15 11:02:39 +1000 |
commit | 6ef810ae664dccd457fe1ed750f7d509b6f60878 (patch) | |
tree | 13f3ab69416d1fc7f5d10db06c1bf83aa0153e4f /jim-package.c | |
parent | a0017cc44c22a83df8f92600317ad8ccd635e2a1 (diff) | |
download | jimtcl-6ef810ae664dccd457fe1ed750f7d509b6f60878.zip jimtcl-6ef810ae664dccd457fe1ed750f7d509b6f60878.tar.gz jimtcl-6ef810ae664dccd457fe1ed750f7d509b6f60878.tar.bz2 |
Bugs, features and tests
source fails with zero length file
unknown can't be called recursively
*: This can be useful when using unknown to dynamically load code,
which may in turn want to dynamically load code
*: Limit it to 50 recursions though
Allow string greater/less comparison
*: Comparing two strings for order did not work
Implement file join
*: It's not to hard and is handy when working with the current dir, ""
Don't omit [unknown] completely from stack trace
*: Since we lose valuable informtion, just omit the name
Fix return from case
Turn regexp patterns into real objects
*: Thus caching the compiled regexps
Allow error to rethrow an error
Replace bcopy() with more standard memcpy()
Fixes to parray, improve errorInfo
*: errorInfo takes an optional stack trace
Add tests for rethrowing errors via errorInfo
Fix ndelay
*: Was looking at wrong param
*: Also fix usage/help for aio.socket
Package should be able to call exit
*: Currently any return from a package is changed to JIM_ERR
Line counting is incorrect for backlash newline
Diffstat (limited to 'jim-package.c')
-rw-r--r-- | jim-package.c | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/jim-package.c b/jim-package.c index f5450b5..5cdba85 100644 --- a/jim-package.c +++ b/jim-package.c @@ -108,9 +108,11 @@ static int JimLoadPackage(Jim_Interp *interp, const char *name, int flags) return retCode; } -const char *Jim_PackageRequire(Jim_Interp *interp, const char *name, int flags) +int Jim_PackageRequire(Jim_Interp *interp, const char *name, int flags) { Jim_HashEntry *he; + int retcode = 0; + const char *version; /* Start with an empty error string */ Jim_SetResultString(interp, "", 0); @@ -118,33 +120,39 @@ const char *Jim_PackageRequire(Jim_Interp *interp, const char *name, int flags) he = Jim_FindHashEntry(&interp->packages, name); if (he == NULL) { /* Try to load the package. */ - if (JimLoadPackage(interp, name, flags) == JIM_OK) { + retcode = JimLoadPackage(interp, name, flags); + if (retcode != JIM_OK) { + if (flags & JIM_ERRMSG) { + int len; + Jim_Obj *resultObj = Jim_GetResult(interp); + if (Jim_IsShared(resultObj)) { + resultObj = Jim_DuplicateObj(interp, resultObj); + } + Jim_GetString(resultObj, &len); + Jim_AppendStrings(interp, resultObj, len ? "\n" : "", + "Can't find package '", name, "'", NULL); + Jim_SetResult(interp, resultObj); + } + return retcode; + } + else { he = Jim_FindHashEntry(&interp->packages, name); if (he == NULL) { /* Did not call package provide, so we do it for them */ Jim_PackageProvide(interp, name, "1.0", 0); - return "1.0"; + version = "1.0"; } - return he->val; - } - - /* No way... return an error. */ - if (flags & JIM_ERRMSG) { - int len; - Jim_Obj *resultObj = Jim_GetResult(interp); - if (Jim_IsShared(resultObj)) { - resultObj = Jim_DuplicateObj(interp, resultObj); + else { + version = he->val; } - Jim_GetString(resultObj, &len); - Jim_AppendStrings(interp, resultObj, len ? "\n" : "", - "Can't find package '", name, "'", NULL); - Jim_SetResult(interp, resultObj); } - return NULL; - } else { - return he->val; } + else { + version = he->val; + } + Jim_SetResultString(interp, version, -1); + return retcode; } /* @@ -187,14 +195,13 @@ static int package_cmd_provide(Jim_Interp *interp, int argc, Jim_Obj *const *arg */ static int package_cmd_require(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { - const char *ver = Jim_PackageRequire(interp, Jim_GetString(argv[0], NULL), JIM_ERRMSG); + int retcode = Jim_PackageRequire(interp, Jim_GetString(argv[0], NULL), JIM_ERRMSG); - if (ver == NULL) { - /* package require failing is important enough to add to the stack */ - return JIM_ERR_ADDSTACK; + /* package require failing is important enough to add to the stack */ + if (retcode == JIM_ERR) { + retcode = JIM_ERR_ADDSTACK; } - Jim_SetResultString(interp, ver, -1); - return JIM_OK; + return retcode; } /* |