aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2023-07-08 09:58:48 +1000
committerSteve Bennett <steveb@workware.net.au>2023-08-13 15:05:05 +1000
commit41c73f09a2ed866b57ee67eaaee94cd7ad1a9db6 (patch)
tree54714a09a199bc8dfd241a7de3557b7e92da8dbd
parentef0b05c3fa344564529db450bc2638ad45e334a4 (diff)
downloadjimtcl-cmd-register.zip
jimtcl-cmd-register.tar.gz
jimtcl-cmd-register.tar.bz2
info: procs, commands, don't returns commands with spacescmd-register
We implement ensembles by creating commands with spaces, like {tree children}. This can clutter the commands returned by 'info procs', 'info commands'. So don't return these by default. Add the '-all' option return all commands. Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--ensemble.tcl2
-rw-r--r--jim.c64
-rw-r--r--tests/jim.test4
3 files changed, 43 insertions, 27 deletions
diff --git a/ensemble.tcl b/ensemble.tcl
index 9e87809..5c49808 100644
--- a/ensemble.tcl
+++ b/ensemble.tcl
@@ -18,7 +18,7 @@ proc ensemble {command args} {
if {$subcmd in {-commands -help}} {
# Need to remove $autoprefix from the front of these
set prefixlen [string length $autoprefix]
- set subcmds [lmap p [lsort [info commands $autoprefix*]] {
+ set subcmds [lmap p [lsort [info commands -all $autoprefix*]] {
string range $p $prefixlen end
}]
if {$subcmd eq "-commands"} {
diff --git a/jim.c b/jim.c
index 17c3277..e4d8e36 100644
--- a/jim.c
+++ b/jim.c
@@ -12036,9 +12036,12 @@ static Jim_Obj *JimHashtablePatternMatch(Jim_Interp *interp, Jim_HashTable *ht,
}
/* Keep these in order */
-#define JIM_CMDLIST_COMMANDS 0
-#define JIM_CMDLIST_PROCS 1
-#define JIM_CMDLIST_CHANNELS 2
+#define JIM_CMDLIST_COMMANDS 1
+#define JIM_CMDLIST_PROCS 2
+#define JIM_CMDLIST_CHANNELS 4
+
+#define JIM_CMDLIST_ALL 0x1000
+
/**
* Adds matching command names (procs, channels) to the list.
@@ -12049,14 +12052,18 @@ static void JimCommandMatch(Jim_Interp *interp, Jim_Obj *listObjPtr,
Jim_Cmd *cmdPtr = (Jim_Cmd *)value;
int match = 1;
- if (type == JIM_CMDLIST_PROCS && !(cmdPtr->flags & JIM_CMD_ISPROC)) {
+ if ((type & JIM_CMDLIST_PROCS) && !(cmdPtr->flags & JIM_CMD_ISPROC)) {
/* not a proc */
return;
}
- if (type == JIM_CMDLIST_CHANNELS && !(cmdPtr->flags & JIM_CMD_ISCHANNEL)) {
+ if ((type & JIM_CMDLIST_CHANNELS) && !(cmdPtr->flags & JIM_CMD_ISCHANNEL)) {
/* not a channel */
return;
}
+ if (!(type & JIM_CMDLIST_ALL) && strchr(Jim_String(keyObj), ' ')) {
+ /* contains a space and not -all */
+ return;
+ }
Jim_IncrRefCount(keyObj);
@@ -12083,10 +12090,9 @@ static Jim_Obj *JimCommandsList(Jim_Interp *interp, Jim_Obj *patternObjPtr, int
}
/* Keep these in order */
-#define JIM_VARLIST_GLOBALS 0
-#define JIM_VARLIST_LOCALS 1
-#define JIM_VARLIST_VARS 2
-#define JIM_VARLIST_MASK 0x000f
+#define JIM_VARLIST_GLOBALS 1
+#define JIM_VARLIST_LOCALS 2
+#define JIM_VARLIST_VARS 4
#define JIM_VARLIST_VALUES 0x1000
@@ -12098,7 +12104,7 @@ static void JimVariablesMatch(Jim_Interp *interp, Jim_Obj *listObjPtr,
{
Jim_VarVal *vv = (Jim_VarVal *)value;
- if ((type & JIM_VARLIST_MASK) != JIM_VARLIST_LOCALS || vv->linkFramePtr == NULL) {
+ if (!(type & JIM_VARLIST_LOCALS) || vv->linkFramePtr == NULL) {
if (patternObj == NULL || Jim_StringMatchObj(interp, patternObj, keyObj, 0)) {
Jim_ListAppendElement(interp, listObjPtr, keyObj);
if (type & JIM_VARLIST_VALUES) {
@@ -12111,13 +12117,13 @@ static void JimVariablesMatch(Jim_Interp *interp, Jim_Obj *listObjPtr,
/* mode is JIM_VARLIST_xxx */
static Jim_Obj *JimVariablesList(Jim_Interp *interp, Jim_Obj *patternObjPtr, int mode)
{
- if (mode == JIM_VARLIST_LOCALS && interp->framePtr == interp->topFramePtr) {
+ if ((mode & JIM_VARLIST_LOCALS) && interp->framePtr == interp->topFramePtr) {
/* For [info locals], if we are at top level an empty list
* is returned. I don't agree, but we aim at compatibility (SS) */
return interp->emptyObj;
}
else {
- Jim_CallFrame *framePtr = (mode == JIM_VARLIST_GLOBALS) ? interp->topFramePtr : interp->framePtr;
+ Jim_CallFrame *framePtr = (mode & JIM_VARLIST_GLOBALS) ? interp->topFramePtr : interp->framePtr;
return JimHashtablePatternMatch(interp, &framePtr->vars, patternObjPtr, JimVariablesMatch,
mode);
}
@@ -15557,7 +15563,7 @@ static int JimIsGlobalNamespace(Jim_Obj *objPtr)
static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr;
- int mode = 0;
+ int mode = 1;
/* Must be kept in order with the array below */
enum {
@@ -15593,8 +15599,8 @@ static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg
JIM_DEF_SUBCMD("alias", "command", 1, 1),
JIM_DEF_SUBCMD("args", "procname", 1, 1),
JIM_DEF_SUBCMD("body", "procname", 1, 1),
- JIM_DEF_SUBCMD("channels", "?pattern?", 0, 1),
- JIM_DEF_SUBCMD("commands", "?pattern?", 0, 1),
+ JIM_DEF_SUBCMD("channels", "?-all? ?pattern?", 0, 2),
+ JIM_DEF_SUBCMD("commands", "?-all? ?pattern?", 0, 2),
JIM_DEF_SUBCMD("complete", "script ?missing?", 1, 2),
JIM_DEF_SUBCMD("exists", "varName", 1, 1),
JIM_DEF_SUBCMD("frame", "?levelNum?", 0, 1),
@@ -15605,7 +15611,7 @@ static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg
JIM_DEF_SUBCMD("locals", "?pattern?", 0, 1),
JIM_DEF_SUBCMD("nameofexecutable", NULL, 0, 0),
JIM_DEF_SUBCMD("patchlevel", NULL, 0, 0),
- JIM_DEF_SUBCMD("procs", "?pattern?", 0, 1),
+ JIM_DEF_SUBCMD("procs", "?-all? ?pattern?", 0, 2),
JIM_DEF_SUBCMD("references", NULL, 0, 0),
JIM_DEF_SUBCMD("returncodes", "?code?", 0, 1),
JIM_DEF_SUBCMD("script", "?filename?", 0, 1),
@@ -15668,17 +15674,26 @@ static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg
return JIM_OK;
case INFO_CHANNELS:
- mode++; /* JIM_CMDLIST_CHANNELS */
+ mode <<= 1; /* JIM_CMDLIST_CHANNELS */
#ifndef jim_ext_aio
Jim_SetResultString(interp, "aio not enabled", -1);
return JIM_ERR;
#endif
/* fall through */
case INFO_PROCS:
- mode++; /* JIM_CMDLIST_PROCS */
+ mode <<= 1; /* JIM_CMDLIST_PROCS */
/* fall through */
- case INFO_COMMANDS:
- /* mode 0 => JIM_CMDLIST_COMMANDS */
+ case INFO_COMMANDS:{
+ int n = 0;
+ /* mode = 1 => JIM_CMDLIST_COMMANDS */
+ if (argc > 2 && Jim_CompareStringImmediate(interp, argv[2], "-all")) {
+ mode |= JIM_CMDLIST_ALL;
+ n++;
+ }
+ if (argc < 2 + n || argc > 3 + n) {
+ Jim_SetResultFormatted(interp, "wrong # args: should be \"info %#s %s\"", argv[1], cmds[option].args);
+ return JIM_ERR;
+ }
#ifdef jim_ext_namespace
if (!nons) {
/* Called as 'info -nons commands|procs' so respect the current namespace */
@@ -15687,17 +15702,18 @@ static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg
}
}
#endif
- Jim_SetResult(interp, JimCommandsList(interp, (argc == 3) ? argv[2] : NULL, mode));
+ Jim_SetResult(interp, JimCommandsList(interp, (argc == 3 + n) ? argv[2 + n] : NULL, mode));
return JIM_OK;
+ }
case INFO_VARS:
- mode++; /* JIM_VARLIST_VARS */
+ mode <<= 1; /* JIM_VARLIST_VARS */
/* fall through */
case INFO_LOCALS:
- mode++; /* JIM_VARLIST_LOCALS */
+ mode <<= 1; /* JIM_VARLIST_LOCALS */
/* fall through */
case INFO_GLOBALS:
- /* mode 0 => JIM_VARLIST_GLOBALS */
+ /* mode = 1 => JIM_VARLIST_GLOBALS */
#ifdef jim_ext_namespace
if (!nons) {
if (Jim_Length(interp->framePtr->nsObj) || (argc == 3 && JimIsGlobalNamespace(argv[2]))) {
diff --git a/tests/jim.test b/tests/jim.test
index eff2c1f..2d245db 100644
--- a/tests/jim.test
+++ b/tests/jim.test
@@ -3152,9 +3152,9 @@ test info-2.4 {info commands option} {
} {_test1_ _test2_}
catch {rename _test1_ {}}
catch {rename _test2_ {}}
-test info-2.5 {info commands option} {
+test info-2.5 {info commands option} -body {
list [catch {info commands a b} msg] $msg
-} {1 {wrong # args: should be "info commands ?pattern?"}}
+ } -result {1 {wrong # args: should be "info commands ?-all? ?pattern?"}}
test info-3.1 {info exists option} {
set value foo
info exists value