"unknown" command usage 
Author Message
 "unknown" command usage

Greetings,

I'm trying to understand how best to implement a C language routine that
executes when a user types a command that is unknown to the Tcl (8.3)
shell compiled and executed on a Linux 7.1 Intel platform.  I'm pretty
sure that what I'm doing is wrong - it works but not the way I expected
it to nor is my solution at all efficient.  I have read all the Tcl
references I've come across (Osterhout, Welch) as well as searched the
various websites but can find no information relating to this issue.

I have compiled a tcl shell and linked in my own routine "foobar" that
uses the standard tcl prototype:

int foobar(clientData, interp, argc, argv)
{
...

Quote:
}

and then during initialization issue the command:

Tcl_CreateCommand(interp, "unknown", foobar, ...);

which has the interesting effect of calling my routine twice every time
the user enters a command unknown to the interpreter.  On the first
invocation of foobar the argv list is:

"unknown", "history", "add", <entire user command line in 1 string>

and once the foobar() returns it is called again, this time with the
argv list:

"unknown", <user command>, <1st user parameter>, <2nd user parameter>...

I think what is happening is that the original "unknown" proc is
executing as well as my new definition.  I think the first invocation is
what would normally be handed to the default "unknown" proc, and the
second invocation is the effect of my Tcl_CreateCommand linkage, with
the interpreter parsing the command line up. I'm guessing - and probably
very wrong.

I would like to better understand the linkages and perhaps avoid the
double call to my function.  If anyone has the time to enlighten me or
perhaps point me to a working example of someone doing this I would most
appreciate it.

Thanks in advance,

Robb Kane

p.s. I'd really like to know if there is a way of doing this right and
not having the interpreter break the user command up into the various
argv list arguments.  In other words, if foobar could be called without
first separating out the user command line into the various argv list
entries.  Ultimately I am going to pass the user command line on to
another parser and will need to reassemble it if it is parsed into the
argv list.



Tue, 01 Jun 2004 17:47:39 GMT  
 "unknown" command usage

Quote:

> Greetings,

> I have compiled a tcl shell and linked in my own routine "foobar" that
> uses the standard tcl prototype:

> int foobar(clientData, interp, argc, argv)
> {
> ...
> }

> and then during initialization issue the command:

> Tcl_CreateCommand(interp, "unknown", foobar, ...);

What you probably did not realise is that [unknown] is defined in one
of the start-up scripts (init.tcl) which gets evaluated pretty lately.

So, you might add your version after "init.tcl" has been evaluated
or you could do it via an extension:

   package require MyOwnLittleUnknown

   ... some code

My recommendation would be the second approach: that way you can
continue using the standard shells.

Regards,

Arjen



Tue, 01 Jun 2004 18:26:37 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. "unknown" command usage

2. "Unknown Command: -quiet" in mingw

3. "unknown" command HELP

4. The usage of the command "source"

5. Help with an "unknown" APL2 symbol

6. Unknown Variable "%AppTemplateFamily"

7. ERROR "Corrupt Block/Unknown Block Freed"

8. ANYONE ELSE GETTING "UNKNOWN" NEWS POSTINGS

9. CP shows "Unknown Image Format"

10. +define+unknown="'bx" chokes verilog

11. PTUI problem, "lifo::lifo": unknown namespace

12. TK: question about "-command" usage with "{}" and double quoter

 

 
Powered by phpBB® Forum Software