User's Guide to the C Editor

This class provides a text editor specialized for editing C files. It is invoked automatically when opening any file with the .c extension in its name. The EditC class is derived from the EditProgram class, and therefore inherits all of its features.

Compiling C Files

The C Editor has two menu choices to compile the current file: Compile and Compile and Load.

The Compile choice brings up the Monitor widget which will run make and compile the current file.

The Compile and Load menu choice will compile the current file and load it back into Tycho by using the Tcl load command. The Compile and Load menu choice can be used to create new Tcl commands that are written in C. Note that it is risky to test C code within Tycho, since failure of the C code could cause Tycho to crash.

When a C file is compiled and loaded, the following steps occur.

  1. If the Tcl load command is to work on a particular file, then there must be a Tcl initialization procedure in the C file (see below for details). The Add Tcl Initialization choice under the Special menu will add an initialization procedure.

    Since Tycho can't know what commands you want to register, the initialization procedure will have a body that must be modified by the user.

  2. The current directory is searched for the following files:
    1. makefile
    2. Makefile
    3. A file with the same base as the file being compiled and a .mk extension. For example, if the file being is named myTclCommands.c, then we look for myTclCommands.mk
    If none of the above makefiles are found, then we create a makefile with the same basename, as #3 above. The details of the makefile are covered below.
  3. A make command is executed with the makefile determined from the step above. Continuing our example above, the command would be make -f myTclCommand.mk.
  4. The Tcl load command is called. The load command is passed the architecture dependent shared object filename.

Generating a makefile

If a makefile does not exist, then when a C file is compiled, a makefile can be generated. The makefile will have the same basename as the C file, and a .mk extension.

The template that is used is located at $TYCHO/editors/textedit/templates/Cmakefile.mk.

The template includes two makefiles: $TYCHO/obj.$PTARCH/java.mk and $TYCHO/obj.$PTARCH/tcl.mk These two makefiles are generated by running configure. The Tcl extensions use these file as well, see $TYCHO/doc/coding/buildtclexts.html for details.

If these two makefiles are not present, then make config_tclexts is called while in the $TYCHO directory.

Initialization Procedure

The Tcl load command invokes an initialization procedure after loading the shared object. The name of the initialization procedure depends on the file name of the shared object, or on the Tcl package name. See the load command for the details, but if the shared object is named myTclCommand.so, then the initialization procedure would be
int Mytclcommand_InitProc(Tcl_Interp *interp)
Usually the initialization procedure registers commands, for example
int Mytclcommand_InitProc(Tcl_Interp *interp)
{
    Tcl_CreateCommand (interp, "mytclcommand", Tcl_MyTclCommandCmd, 
                       (ClientData) infoPtr, (Tcl_CmdDeleteProc*) NULL);
    return TCL_OK;
}

Tycho Home Page


Copyright © 1996-1998, The Regents of the University of California. All rights reserved.
Last updated: 06/12/97, comments to: eal@eecs.berkeley.edu