KUIP2TCL

Authors: M.Ballintijn(1), J.J.Bunn(1), O.Couet(1), I.Gaponenko(2), P.Lecointe(1)

(1) CERN (2) BINP

Introduction

This document describes the KUIP2TCL Starter Kit, which is a package of routines for converting applications with a KUIP-based user interface into Tk/Tcl-based applications.

The KUIP package was developed in the Applications Software and Databases Group at CERN with the intention of providing a user toolkit for interactive applications programming. The PAW program uses KUIP to provide both command line and Motif-based user interfaces.

In recent years, several Public Domain user interface packages have become available, the most famous of these being Tk/Tcl, which now enjoys enormous popularity. The Tk/Tcl package interfaces to the X-Windows system to provide the user with very convenient and easy means of creating widgets and integrating existing applications code.

The functionality of Tk/Tcl exceeds that of KUIP, and sports a multitude of add-on packages such as tkWWW, ObjectTcl, [incr Tcl], and so on. Tk/Tcl is available for most Unix platforms, for VMS, and for Windows ('95, NT and 3.1).

Why convert from KUIP to Tk/Tcl?

Why would one want to convert a KUIP-based application to Tk/Tcl? There are several reasons:

  • To ease widget programming (the Tk widgets are very easy to use, whereas programming with Motif UILs is cumbersome and a job for an expert).
  • To benefit from the various Tk/Tcl add-on packages (an application can make direct use of WWW simply by including the tkWWW package, for example).
  • To ease generation of multi-platform versions of the application (the KUIP package may require some effort to port, maintain and debug, especially on new platforms, whereas Tk/Tcl is already available and fully debugged for most platforms).
  • To allow the end-user greater flexibility. KUIP relies on a pre-compiled set of user commands to have been linked with the application by the developer, but Tk/Tcl allows end-users to generate their own commands "on the fly", and with great ease. Although this is technically possible to do in KUIP with macros and aliasses, the method is clumsy and inconvenient.
  • To profit from the standard shell Tcl (the KUIP shell is non-standard, for example the pipe "|" character is used as an inline comment delimiter).
  • To benefit from the use of a de-facto standard software package, which is widely supported in the public-domain, and which comes with excellent user documentation.

Tk/Tcl does, however, have some disadvantages compared with KUIP. These include lack of command line editing and break handling in the standard distribution, for example.

The KUIP Command Definition File (CDF)

One strength of KUIP is that it requires the applications programmer to descriptively specify the commands in the package. The description is kept in one or more CDFs, and conforms to a regular syntax. This syntax describes the individual commands, their arguments, types, options, together with their position in the command tree hierarchy. In addition, lines of "Guidance" are included that KUIP uses as online help text. Each command in the CDF is tagged with a so-called "Action Routine", which is the name of a Fortran or C module that is called whenever the command is invoked. It is the action routine which carries out the command in the application's environment.

The KUIP2TCL scheme

The principal idea here is to take the application's CDF and convert it to Tcl command definitions. This can be done automatically by a program which reads the CDF and writes the Tcl C code. The Tcl code includes logic which, when the user invokes a command, takes care of retrieving the arguments and default values, before making them available to the action command.

Once the Tcl C code has been automatically generated from the CDF, it can be called in the initialisation phase of Tk/Tcl (i.e. in TclAppinit). This instantly makes available all the application's commands at the command line.

The commands are available in two forms: either in the usual KUIP form (e.g. HIS/PLOT) or in the new form (e.g. Histogram_Plot). The conversion between the KUIP form and the new form is achieved by a special version of the "unknown" Tcl command, which attempts to resolve a command typed by the user by matching (globbing) against the set of available commands.

A simple help is available, that pops up the "guidance" text and command parameters in a top level Tk window whenever the user gives "?" as the first parameter of a command, or when the user types "help" followed by the name of a command.

The KUIP replacement routines

Existing KUIP-based applications use routines such as KUGETI (get Integer), KUGETR (get Real) etc. in the action routines to obtain the argument tokens for each command typed by the user. The KUIP2TCL package allows the use of such code without change, by providing a new set of functions KUGETI, KUGETR etc. that instead retrieve the arguments from Tcl. (In addition, the KUIP vector routines have been replaced by a set using C mallocs, so removing the previous ZEBRA Common size restriction.) The KUIP replacement routines are intended to be a full drop-in replacement for the existing KUIP package (but see below under "Restrictions").

The TREE Widget

The KUIP2TCL package offers new functionality over KUIP with the provision of a command tree widget that allows a graphical exploration of the application's command hierarchy, and windowed display of each command's help text. The tree widget may also be run as a stand-alone program for exploring command trees generated from CDF files.

Conversion Steps

To convert a KUIP-based application to Tk/Tcl, the following steps need to be taken:

  • Use the CDF2TCL program to convert the application's CDF to Tcl C code. A C routine is created that contains the Tcl command declarations.
  • Replace the application's main program by a function/subroutine call, and insert a call to that at the end of the TclAppinit procedure.
  • Recompile, and relink with the utility routines provided with KUIP2TCL, and with the Tk/Tcl libraries.

An example of KUIP application conversion

The KUIP2TCL package includes an example KUIP Fortran application that has commands to initialise and generate uniformly distributed random numbers in a given range. The example shows how this may be converted to a Tk/Tcl application with a set of buttons and text boxes, together with the command line interface.

Restrictions

KUIP2TCL is a starter kit, and it is not expected that it will perform a complete conversion in all cases. The application programmer will usually have to do some extra work before the Tk/Tcl version is ready for "Prime Time". In particular, the following limitations are noted:

  • KUIP macros must be converted to Tcl syntax and invoked using the Tcl "source" command.
  • Command options must be typed in the correct position: the option=value syntax is not yet understood.
  • There is no control_C handling.

We have successfully used KUIP2TCL to generate a Tk/Tcl version of PAW: the KUIP replacement routines provided are those which we required to make this conversion.

Supported Platforms

KUIP2TCL is provided in versions for HP/UX, SGI Irix, OpenVMS and Windows/NT,95.


Julian J. Bunn