Embedded Tcl: Does Tcl autocomplete commands?
We have a Tcl built in our C/C++ application, I found the place in our code where Tcl_EvalObjv is called if the command was not found. I have to admit that the code is pretty old and not many of our developers know what happens in this module.
It looks like this:
// ... there is some checking if command is registered etc., it fails and the code goes here:
std::vector<Tcl_Obj*> tclArgs = { NULL };
for (int i = 1; i < objc; ++i)
tclArgs.push_back(objv[i]);
tclArgs.shrink_to_fit();
// ...
tclArgs[0] = ::Tcl_NewStringObj(ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN_SIZE);
Tcl_IncrRefCount(tclArgs[0]);
::Tcl_ExposeCommand(pInterp, ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN);
result = ::Tcl_EvalObjv(pInterp, objc, &tclArgs[0], TCL_EVAL_GLOBAL); //<--
::Tcl_HideCommand(pInterp, ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN);
// ORIGINAL_UNKNOWN is char* it is just "unknown"
We have handlers for commands in our application, while executing Tcl_EvalObjv in CmdUnknown() function Tcl sometimes calls different commands. Examples below:
List of existing commands: "banana", "applepie", "carpet", "card"
Command: "apple", Tcl calls "applepie" (wrong, "apple" is not "applepie")
Command: "blah", Tcl gives error (correctly).
Command: "car", Tcl gives error (correctly, maybe because of 2 similar commands).
Is there are some kind of mechanism that Tcl does when it fails in searching for command? The thing is that I can't find anything that is related to our code that would complete the commands so maybe Tcl does?
c++ command embedded tcl
add a comment |
We have a Tcl built in our C/C++ application, I found the place in our code where Tcl_EvalObjv is called if the command was not found. I have to admit that the code is pretty old and not many of our developers know what happens in this module.
It looks like this:
// ... there is some checking if command is registered etc., it fails and the code goes here:
std::vector<Tcl_Obj*> tclArgs = { NULL };
for (int i = 1; i < objc; ++i)
tclArgs.push_back(objv[i]);
tclArgs.shrink_to_fit();
// ...
tclArgs[0] = ::Tcl_NewStringObj(ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN_SIZE);
Tcl_IncrRefCount(tclArgs[0]);
::Tcl_ExposeCommand(pInterp, ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN);
result = ::Tcl_EvalObjv(pInterp, objc, &tclArgs[0], TCL_EVAL_GLOBAL); //<--
::Tcl_HideCommand(pInterp, ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN);
// ORIGINAL_UNKNOWN is char* it is just "unknown"
We have handlers for commands in our application, while executing Tcl_EvalObjv in CmdUnknown() function Tcl sometimes calls different commands. Examples below:
List of existing commands: "banana", "applepie", "carpet", "card"
Command: "apple", Tcl calls "applepie" (wrong, "apple" is not "applepie")
Command: "blah", Tcl gives error (correctly).
Command: "car", Tcl gives error (correctly, maybe because of 2 similar commands).
Is there are some kind of mechanism that Tcl does when it fails in searching for command? The thing is that I can't find anything that is related to our code that would complete the commands so maybe Tcl does?
c++ command embedded tcl
1
I don't know where this is documented, but the user only needs to provide the minimum prefix of the command so that it is unambiguous:ais sufficient to differentiate "applepie" from the other commands. Similarly,b,carpandcardare unambiguous command prefixes.
– glenn jackman
Nov 14 '18 at 15:44
Now I wonder if there is a way of turning it off. So I guess I have to add special character after the command like "apple#" then if an error is returned find this character and remove it. But maybe such a function exists in tcl or flag to set?
– Adrian Michałek
Nov 14 '18 at 16:00
add a comment |
We have a Tcl built in our C/C++ application, I found the place in our code where Tcl_EvalObjv is called if the command was not found. I have to admit that the code is pretty old and not many of our developers know what happens in this module.
It looks like this:
// ... there is some checking if command is registered etc., it fails and the code goes here:
std::vector<Tcl_Obj*> tclArgs = { NULL };
for (int i = 1; i < objc; ++i)
tclArgs.push_back(objv[i]);
tclArgs.shrink_to_fit();
// ...
tclArgs[0] = ::Tcl_NewStringObj(ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN_SIZE);
Tcl_IncrRefCount(tclArgs[0]);
::Tcl_ExposeCommand(pInterp, ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN);
result = ::Tcl_EvalObjv(pInterp, objc, &tclArgs[0], TCL_EVAL_GLOBAL); //<--
::Tcl_HideCommand(pInterp, ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN);
// ORIGINAL_UNKNOWN is char* it is just "unknown"
We have handlers for commands in our application, while executing Tcl_EvalObjv in CmdUnknown() function Tcl sometimes calls different commands. Examples below:
List of existing commands: "banana", "applepie", "carpet", "card"
Command: "apple", Tcl calls "applepie" (wrong, "apple" is not "applepie")
Command: "blah", Tcl gives error (correctly).
Command: "car", Tcl gives error (correctly, maybe because of 2 similar commands).
Is there are some kind of mechanism that Tcl does when it fails in searching for command? The thing is that I can't find anything that is related to our code that would complete the commands so maybe Tcl does?
c++ command embedded tcl
We have a Tcl built in our C/C++ application, I found the place in our code where Tcl_EvalObjv is called if the command was not found. I have to admit that the code is pretty old and not many of our developers know what happens in this module.
It looks like this:
// ... there is some checking if command is registered etc., it fails and the code goes here:
std::vector<Tcl_Obj*> tclArgs = { NULL };
for (int i = 1; i < objc; ++i)
tclArgs.push_back(objv[i]);
tclArgs.shrink_to_fit();
// ...
tclArgs[0] = ::Tcl_NewStringObj(ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN_SIZE);
Tcl_IncrRefCount(tclArgs[0]);
::Tcl_ExposeCommand(pInterp, ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN);
result = ::Tcl_EvalObjv(pInterp, objc, &tclArgs[0], TCL_EVAL_GLOBAL); //<--
::Tcl_HideCommand(pInterp, ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN);
// ORIGINAL_UNKNOWN is char* it is just "unknown"
We have handlers for commands in our application, while executing Tcl_EvalObjv in CmdUnknown() function Tcl sometimes calls different commands. Examples below:
List of existing commands: "banana", "applepie", "carpet", "card"
Command: "apple", Tcl calls "applepie" (wrong, "apple" is not "applepie")
Command: "blah", Tcl gives error (correctly).
Command: "car", Tcl gives error (correctly, maybe because of 2 similar commands).
Is there are some kind of mechanism that Tcl does when it fails in searching for command? The thing is that I can't find anything that is related to our code that would complete the commands so maybe Tcl does?
c++ command embedded tcl
c++ command embedded tcl
edited Nov 15 '18 at 4:44
mrcalvin
1,265713
1,265713
asked Nov 14 '18 at 14:23
Adrian MichałekAdrian Michałek
1718
1718
1
I don't know where this is documented, but the user only needs to provide the minimum prefix of the command so that it is unambiguous:ais sufficient to differentiate "applepie" from the other commands. Similarly,b,carpandcardare unambiguous command prefixes.
– glenn jackman
Nov 14 '18 at 15:44
Now I wonder if there is a way of turning it off. So I guess I have to add special character after the command like "apple#" then if an error is returned find this character and remove it. But maybe such a function exists in tcl or flag to set?
– Adrian Michałek
Nov 14 '18 at 16:00
add a comment |
1
I don't know where this is documented, but the user only needs to provide the minimum prefix of the command so that it is unambiguous:ais sufficient to differentiate "applepie" from the other commands. Similarly,b,carpandcardare unambiguous command prefixes.
– glenn jackman
Nov 14 '18 at 15:44
Now I wonder if there is a way of turning it off. So I guess I have to add special character after the command like "apple#" then if an error is returned find this character and remove it. But maybe such a function exists in tcl or flag to set?
– Adrian Michałek
Nov 14 '18 at 16:00
1
1
I don't know where this is documented, but the user only needs to provide the minimum prefix of the command so that it is unambiguous:
a is sufficient to differentiate "applepie" from the other commands. Similarly, b, carp and card are unambiguous command prefixes.– glenn jackman
Nov 14 '18 at 15:44
I don't know where this is documented, but the user only needs to provide the minimum prefix of the command so that it is unambiguous:
a is sufficient to differentiate "applepie" from the other commands. Similarly, b, carp and card are unambiguous command prefixes.– glenn jackman
Nov 14 '18 at 15:44
Now I wonder if there is a way of turning it off. So I guess I have to add special character after the command like "apple#" then if an error is returned find this character and remove it. But maybe such a function exists in tcl or flag to set?
– Adrian Michałek
Nov 14 '18 at 16:00
Now I wonder if there is a way of turning it off. So I guess I have to add special character after the command like "apple#" then if an error is returned find this character and remove it. But maybe such a function exists in tcl or flag to set?
– Adrian Michałek
Nov 14 '18 at 16:00
add a comment |
1 Answer
1
active
oldest
votes
As glenn hinted at, Tcl in interactive (REPL) mode allows for dispatching commands using some minimal but unambiguous name prefix. I cannot tell how your embedded Tcl is configured, initialised, and ended up being run as in interactive mode. However, you may want to try to "turn off" (toggle) the interactive mode, by either:
unset ::tcl_interactive
or
set ::tcl_interactive 0
All of this is implemented by the default unknown handler. Watch out for how the list of cmds is looked up and how it is treated differently when tcl_interactive is true or false:
puts [info body unknown]
For a try: PutTcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);anywhere beforeTcl_EvalObjvis called.
– mrcalvin
Nov 14 '18 at 17:59
Thanks, it will be checked tomorrow ;)
– Adrian Michałek
Nov 14 '18 at 18:52
Update: It works.
– Adrian Michałek
Nov 15 '18 at 9:07
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53302415%2fembedded-tcl-does-tcl-autocomplete-commands%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As glenn hinted at, Tcl in interactive (REPL) mode allows for dispatching commands using some minimal but unambiguous name prefix. I cannot tell how your embedded Tcl is configured, initialised, and ended up being run as in interactive mode. However, you may want to try to "turn off" (toggle) the interactive mode, by either:
unset ::tcl_interactive
or
set ::tcl_interactive 0
All of this is implemented by the default unknown handler. Watch out for how the list of cmds is looked up and how it is treated differently when tcl_interactive is true or false:
puts [info body unknown]
For a try: PutTcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);anywhere beforeTcl_EvalObjvis called.
– mrcalvin
Nov 14 '18 at 17:59
Thanks, it will be checked tomorrow ;)
– Adrian Michałek
Nov 14 '18 at 18:52
Update: It works.
– Adrian Michałek
Nov 15 '18 at 9:07
add a comment |
As glenn hinted at, Tcl in interactive (REPL) mode allows for dispatching commands using some minimal but unambiguous name prefix. I cannot tell how your embedded Tcl is configured, initialised, and ended up being run as in interactive mode. However, you may want to try to "turn off" (toggle) the interactive mode, by either:
unset ::tcl_interactive
or
set ::tcl_interactive 0
All of this is implemented by the default unknown handler. Watch out for how the list of cmds is looked up and how it is treated differently when tcl_interactive is true or false:
puts [info body unknown]
For a try: PutTcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);anywhere beforeTcl_EvalObjvis called.
– mrcalvin
Nov 14 '18 at 17:59
Thanks, it will be checked tomorrow ;)
– Adrian Michałek
Nov 14 '18 at 18:52
Update: It works.
– Adrian Michałek
Nov 15 '18 at 9:07
add a comment |
As glenn hinted at, Tcl in interactive (REPL) mode allows for dispatching commands using some minimal but unambiguous name prefix. I cannot tell how your embedded Tcl is configured, initialised, and ended up being run as in interactive mode. However, you may want to try to "turn off" (toggle) the interactive mode, by either:
unset ::tcl_interactive
or
set ::tcl_interactive 0
All of this is implemented by the default unknown handler. Watch out for how the list of cmds is looked up and how it is treated differently when tcl_interactive is true or false:
puts [info body unknown]
As glenn hinted at, Tcl in interactive (REPL) mode allows for dispatching commands using some minimal but unambiguous name prefix. I cannot tell how your embedded Tcl is configured, initialised, and ended up being run as in interactive mode. However, you may want to try to "turn off" (toggle) the interactive mode, by either:
unset ::tcl_interactive
or
set ::tcl_interactive 0
All of this is implemented by the default unknown handler. Watch out for how the list of cmds is looked up and how it is treated differently when tcl_interactive is true or false:
puts [info body unknown]
edited Nov 14 '18 at 18:02
answered Nov 14 '18 at 16:23
mrcalvinmrcalvin
1,265713
1,265713
For a try: PutTcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);anywhere beforeTcl_EvalObjvis called.
– mrcalvin
Nov 14 '18 at 17:59
Thanks, it will be checked tomorrow ;)
– Adrian Michałek
Nov 14 '18 at 18:52
Update: It works.
– Adrian Michałek
Nov 15 '18 at 9:07
add a comment |
For a try: PutTcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);anywhere beforeTcl_EvalObjvis called.
– mrcalvin
Nov 14 '18 at 17:59
Thanks, it will be checked tomorrow ;)
– Adrian Michałek
Nov 14 '18 at 18:52
Update: It works.
– Adrian Michałek
Nov 15 '18 at 9:07
For a try: Put
Tcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); anywhere before Tcl_EvalObjv is called.– mrcalvin
Nov 14 '18 at 17:59
For a try: Put
Tcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); anywhere before Tcl_EvalObjv is called.– mrcalvin
Nov 14 '18 at 17:59
Thanks, it will be checked tomorrow ;)
– Adrian Michałek
Nov 14 '18 at 18:52
Thanks, it will be checked tomorrow ;)
– Adrian Michałek
Nov 14 '18 at 18:52
Update: It works.
– Adrian Michałek
Nov 15 '18 at 9:07
Update: It works.
– Adrian Michałek
Nov 15 '18 at 9:07
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53302415%2fembedded-tcl-does-tcl-autocomplete-commands%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I don't know where this is documented, but the user only needs to provide the minimum prefix of the command so that it is unambiguous:
ais sufficient to differentiate "applepie" from the other commands. Similarly,b,carpandcardare unambiguous command prefixes.– glenn jackman
Nov 14 '18 at 15:44
Now I wonder if there is a way of turning it off. So I guess I have to add special character after the command like "apple#" then if an error is returned find this character and remove it. But maybe such a function exists in tcl or flag to set?
– Adrian Michałek
Nov 14 '18 at 16:00