---
name: "TclXCmd_Init"
section: "3tclx"
platform: "linux"
package: "tclx74-dev"
version: "7.4a-p2-5"
release: "Debian 1.3 (Bo)"
platforms: ["linux"]
url: "https://new.carta.tech/TclXCmd_Init"
---

# TclXCmd\_Init(3tclx)

Extended Tcl initialization.

## NAME

TclX\_Init, TclXCmd\_Init, TclXLib\_Init, TclX\_Main - Extended Tcl initialization.

## SYNOPSIS

```
-ltclx -ltcl
#include "tclExtend.h"
extern char *tclAppName;
extern char *tclAppLongname;
extern char *tclAppVersion;
extern int   tclAppPatchlevel;
int
Tcl_AppInit (Tcl_Interp *interp);
int
TclX_Init (Tcl_Interp *interp);
int
TclXCmd_Init (Tcl_Interp *interp);
int
TclXLib_Init (Tcl_Interp *interp);
void
TclX_Main (int               argc,
           char            **argv,
           Tcl_AppInitProc  *appInitProc);
int
TkX_Init (Tcl_Interp *interp);
void
TkX_Main (int               argc,
          char            **argv,
          Tcl_AppInitProc  *appInitProc);
```

## DESCRIPTION

These functions are used to initialize Extended Tcl and applications based on Extended Tcl.  This manual page also discusses various issues and approaches of integrating TclX into other applications.

### tclAppName

The application name to be returned by the **infox** command. This should be a short mnemonic.  This value maybe altered from the default by the application.

### tclAppLongname

The application long name to be returned by the **infox** command. This should be a natural language string.  This value maybe altered from the default by the application.

### tclAppVersion

The application version string to be returned by the **infox** command. procedures are called.  This value maybe altered from the default by the application.

### tclAppPatchlevel

The application patchlevel to be returned by the **infox** command. procedures are called.  This value maybe altered from the default by the application.

### tclX\_library

The path to the TclX runtime library. This directory contains the initialization file evaluated by TclX\_Init and is also appended to auto\_path. This variable is initialized to the compile-time specified install location. The value maybe modified before TclX\_Init or TclXLib\_Init are called to use another library in a particular application. If its set to NULL, no library will be used unless override by tclX\_libraryEnv. Setting tclX\_libraryEnv and this variable to NULL causes no library directory or initialization file to be used.

### tclX\_libraryEnv

Environment variable used to override the path stored in tclX\_library. The value maybe modified before TclX\_Init or TclXLib\_Init are called to use another environment variable for a particular application. If its set to NULL, no environment variable will allow to override. Defaults to "TCL\_LIBRARY".

### tclX\_initFile

The initialization file for TclX\_Init to source. By default the file "TclInit.tcl" in the TclX library directory is sourced. If set to an absolute path, it is not assumed to be in the TclX library directory and is independent of a library path being specified. If set to NULL, not initialization file is evaluated.

### Tcl\_AppInit

This function is used to initialize an TclX based application. It is intended to the the only file that is modified for most applications. There are two versions of this function, one for applications built on just TclX and the other for applications built on TclX and Tk.

The TclX version of this function is found in **tclXAppInit.c** and the  Tk version is found in **tkXAppInit.c**.  It should be modified according to the instructions in these files to initialize a TclX based application.

A custom application is then linked in a manner similar to:

```
  cc tclXAppInit.o mystuff.a libtclx.a libtcl.a ${SYSLIBS} -o myapp
```

or

```
  cc tkXAppInit.o mystuff.a libtkx.a libtk.a libtclx.a libtcl.a \
     ${SYSLIBS} -o myapp
```

### TclX\_Init

Initializes Extended Tcl, adding the extended command set to the interpreter. This is called from **Tcl\_AppInit**.  Normally, this function is used in an application in place of the **Tcl\_Init** function.  If used in this way, the UCB Tcl run time environment is not required and startup will be faster.  This function may also be called after **Tcl\_Init** has been called. In this case, the Tcl library mechanism defined in **init.tcl** will be replaced with the TclX mechanism.

Parameters

**o** *interp* - A pointer to the interpreter to add the commands to.

Returns:

**TCL\_OK** if all is ok, **TCL\_ERROR** if an error occurred.

### TclXCmd\_Init

Add the TclX command set to the interpreter, with the exception of the TclX library management commands.  This is normally called by **TclX\_Init** and should only be used if you don't want the TclX library handling.

Parameters

**o** *interp* - A pointer to the interpreter to add the commands to.

Returns:

**TCL\_OK** if all is ok, **TCL\_ERROR** if an error occurred.

### TclXLib\_Init

Add the TclX library management commands to the interpreter. This is normally called by **TclX\_Init**.  It also sets the Tcl variable "tclx\_library" to TclX library directory.

Parameters

**o** *interp* - A pointer to the interpreter to add the commands to.

Returns:

**TCL\_OK** if all is ok, **TCL\_ERROR** if an error occurred.

### TclX\_Main

This function parses the command line according to the TclX shell specification (Unix shell compatible). It creates an interpreter and calls the specified function **appInitProc** to initialize any application specific commands. It then either evaluates the command of script specified on the command line or enters an interactive command loop. This procedure never returns, it exits the process when it's done.  Using the TclX shell also gives you SIGINT handling in interactive shells.

### TkX\_Init

Initializes Extended Tcl Tk environment. This is called from **Tcl\_AppInit**.  Normally, this function is used in an application in place of the **Tk\_Init** function.  If used in this way, the UCB Tk run time environment is not required and startup will be faster.  This function may also be called after **Tk\_Init** has been called. In this case, the TclX Tk runtime environment will not be user or required.

Parameters

**o** *interp* - A pointer to the interpreter to add the commands to.

Returns:

**TCL\_OK** if all is ok, **TCL\_ERROR** if an error occurred.

### TclX\_Main

This function parses the command line according to the wish shell specification. It creates an interpreter and calls the specified function **appInitProc** to initialize any application specific commands. It then either evaluates the command of script specified on the command line or enters an interactive command loop. This procedure never returns, it exits the process when it's done.  Using the TclX wish shell gives you SIGINT handling in interactive shells, otherwise it is identical to standard wish.

## INTEGRATING TCLX WITH OTHER EXTENSIONS AND APPLICATIONS

There are two aspects to integrating TclX with other applications. Does the application use the Tcl/Tk standard runtime or rely only on the  TclX runtime and are the Tcl and Tk shells based on the standard Tcl/Tk shells or the TclX shells.  The tclAppInit.c is the only file that will normally need to be modified.

The normal approach to add TclX to an application is to replace the calls to **Tcl\_Init** with **TclX\_Init** and  **Tk\_Init** with **TkX\_Init**.  TclX has a functional superset of the Tcl and Tk runtimes.  The TclX, used alone, does not require the standard runtime environments to be installed on the system.  It supports faster auto loading of the runtime routines and has support for multiple version of TclX being installed (use master directory install option for most flexability).  However, some people are more comfortable adding Tcl in the same way as other extensions.  That is, calling **TclX\_Init** after **Tcl\_Init** and **TkX\_Init** after **Tk\_Init**. Currently, calling **TkX\_Init** is uncessary if the **Tk\_Init** has been called.

If only the TclX command set, but not the procedure library and runtime is desired, then **TclXCmd\_Init** is called after **Tcl\_Init**.

To get the TclX shell in a Tcl only application, with the **tcl** command functionallity, call **TclX\_Main** from the **main** function instead of **Tcl\_Main**. This shell has arguments conforming to other Unix shells and SIGINT signal handling when interactive,.

To get the Tclx shell in a Tk application, with the **wishx** command functionallity, call **TkX\_Main** from the **main** function instead of **Tk\_Main**. This shell has SIGINT signal handling when interactive,
