0
votes

Is it possible to extend the tcl birary dll to have the capabilities of expect?

I have a C program that executes the TCL scripts by using the tcl library tcl85.dll. It works perfectly fine.

Recently i tried to execute some expect sripts and it failed. I understand that tcl85.dll doesn't have the capability to understand the expect commands by its own and that it needs to be extended. This is the point where I am stuck. I have the expect library expect543.dll downloaded from the activesite, but i am not able to figure out how to extend it with the tcl85.dll?

Any help or guidance is really appreciated.

Thanks Sunil

2
package require Expect?Johannes Kuhn

2 Answers

2
votes

You have to stop thinking about Tcl and Expect in terms of DLLs only: both the Tcl DLL and Expect DLL implement core functionality of the respective pieces of software but are not completely self-contained:

  • The Tcl interpreter relies on a set of library files which are (dynamically) loaded off the filesystem. These files include (but are not limited to) encoding files, timezone information files and the so-called "core packages", with one example being http.
  • The Expect package, being a regular Tcl package, relies on the presense of at least a special "index file" (pkgIndex.tcl) which "knows" how to properly load and initialize the DLL containing the package's core functionality, and which actually interfaces the package to the Tcl's package loader.

So, to make all this work, you roughly have to follow this checklist:

  1. Ensure the Tcl interpreter you are embedding in your code is properly initialized, and so it's able to load external packages.

  2. Place the complete Expect package into one of the places your embedded interpreter expects to find external packages.

    Be sure to read this, this and this to understand how the packaging machinery works and how the special global variable auto_path is initialized.

  3. Call package require Expect in those scripts in your program which require the presence of the Expect package to get it loaded.

Alternatively, you might perform proper calls to Tcl C API on your embedded interpreter to load the Expect package's DLL directly, so it will be available to the script you execute later right away.

Yet another alternative (which is trickier to get right for a starter) is to employ the so-called "basekit" or "tclkit" — a Tcl library which has certain Tcl packages included within it using a virtual file system, so that these packages could be loaded at runtime off that VFS. These *kits are cool but mastering creation of a proper one is harder than just embedding a "regular" interpreter plus a regular package distributed with the main program as a set of files.


One special note: I'm not sure the license of the ActiveTcl™ product allows ripping off various parts of it and using them in your product. IANAL but I suspect you might be violating that license's terms. To be on the safe side, build both Tcl and Expect from the source — that's not hard.

0
votes

basically we need to initialize the expect interpreter. Once this is done, tht TCL_Eval(.) would understand the expect code as well.

Tcl_Interp *interp = Tcl_CreateInterp();
Tcl_FindExecutable(argv[0]);

if (Tcl_Init(interp) == TCL_ERROR) {
    fprintf(stderr,"Tcl_Init failed: %s\n",Tcl_GetStringResult (interp));
    (void) exit(1);
}
    //Initializing the expect interpreter here
if (Expect_Init(interp) == TCL_ERROR) {
    fprintf(stderr,"Expect_Init failed: %s\n",Tcl_GetStringResult (interp));
    (void) exit(1);
}
 //this can now take expect scripts as well in the buffer
 Tcl_Eval(interp, buffer);