An Introduction To Embedded Tk (page 30 of 32)

[Previous Page][Next Page][Table of Contents]

12.4 An ASCII Text Editor And A File Browser

The two programs tkedit and browser implement, respectively, an ASCII text editor and a UNIX file browser utility. Source code to these programs is in the files tkedit.c, tkedit.tcl, browser.c and browser.tcl.

Both of these programs could just as well have been implemented as pure Tcl/Tk scripts, with no loss of features or performance. (In fact, the browser can be used as pure script by invoking the browser.tcl using wish.) But, sometimes you want a program to be a real executable, not a script. For instance, you may want to be able to run the program on machines that do not have Tcl/Tk installed. Or, perhaps you want the programs to run on machines that have a different, incompatible version of Tcl/Tk installed.

The tkedit and browser programs are examples of how to convert a pure Tcl/Tk script into a stand-alone program using ET. The idea is very simple. Your C code simply initializes ET, invokes your script using a single ET_INCLUDE() statement, and then enters the event loop. Like this:

  void main(int argc, char **argv){
    Et_Init(&argc,argv);
    ET_INCLUDE( browser.tcl );
    Et_MainLoop();
  }
Compiling this code results in a stand-alone application that can be run on any binary-compatible machine.

[Next Page][Table of Contents]