SECTION 2 -- GUIDE TO WRITING APPLICATION PROGRAMS

2.1 INTRODUCTION

This section describes how to implement a program (i.e., a "process")to run under TAE.

As described in Section 2 of the TAE Command Language (TCL) Programmer's Manual, a program running under TAE becomes known to TAE through a PDF. The PDF defines the program's parameters and indicates where the help information for the program can be found.

The program coordinates with the Terminal Monitor to receive and manipulate the program's TCL variables (including program parameters) through the p_ and q_ function packages described in Section 3.9 of this document, or through the Vm_ package described in the TAE Plus C Reference Manual.

(The Vm_ package allocates memory internally, whereas the p_ and q_ packages require that the caller allocates the memory. Use of the Vm_ package is recommended.)

The other function packages described are:

2.2 PROGRAM DEVELOPMENT ENVIRONMENT

2.2.1 Programming Language

The programming language for TAE applications development addressed in this document is C. For FORTRAN-77 applications development, see "TCL Runtime Services Volume 2: FORTRAN." Programs may be written in other high level languages, but must be linked with the standard TAE function library.

2.2.2 Coding Conventions

Since a major objective of TAE is portability, several conventions have been adopted to promote host-independence. These conventions are described in the following sections.

2.2.2.1 Constants and Block Sizes

This document references constants and block sizes as uppercase symbols, e.g., SUCCESS is the constant that indicates a successful status return from a function. These value definitions exist as C define statements in include files; see Section 2.2.4 of this document for details.

2.2.2.2 Entry Point Naming Conventions

Each TAE library function name begins with one or more special characters, corresponding to the utility package in which the function is grouped, followed by an underscore. For example, "p_ for the parameter and variable retrieval package, "t_ for the terminal I/O package, and "Dp_ for the dynamic PDF manipulation package.

2.2.2.3 Linking Convention

An executable image file is created using the host's object module linker. The executable file must be placed in the same library as the PDF for the program, or the PROCESS command in the PDF must supply the file specification. (See Section 3.4 of the TCL Programmer's Manual.)

For the link commands suitable to a particular host, see Appendix A of this document.

2.2.3 Program Initialization and Termination Conventions

Functions are provided in the standard TAE library for initialization (z_init) and termination (z_exit). Although there is no requirement that a program running under TAE call these functions, their use is recommended. When a program is submitted as a batch job without z_init, all output is lost. See Section 8 of Volume 1 for details.

Note that programs that are never initiated under the Terminal Monitor (e.g., some TAE Plus, WPT-based programs) need not call z_init and z_exit.

2.2.4 TAE Include Files

This section describes the TAE include files. The general conventions for TAE include files are as follows:

  1. Every program source file must include "taeconf.inp", the standard TAE "configuration" file.

  2. An include file that requires the presence of another include file must explicitly reference the required file. "taeconf.inp" is an exception to this rule; it is assumed to always be present.

  3. To avoid "double definitions" resulting from item 2, each include file defines a symbol, "I_include-file-name", and tests the existence of the symbol at the top of the file. For example, the "PARBLK" include file has the following general structure:

    /* header comments      */
    /* change log           */
    
    #ifndef I_PARBLK
    #define I_PARBLX        0
    
    #include "symtab.inc"   /* needed by PARBLK */
    
    /* PARBLK definitions  */
    
    #endif
    

    Thus, if a file is included twice in the same compilation (a common situation), the compilation works successfully.

  4. It is recommended that a source module reference only the include files that are specifically needed.

  5. Prior to Version 3.10 of TAE, include files were referenced by a single name (e.g. "PARBLK") corresponding to a logical name under VMS and a file of that name under UNIX. After Version 3.10, include file names have the form x.inc or x.inp as listed below. With the advent of TAE Plus, many include file names may also have the form x.h, a common C header file designation. The old, all-capital form will continue to be supported.

In this document the term "V-block" is equivalent to a "PARBLK structure." A discussion on the V-block can be found in Section 3.2.

2.2.4.1 Parameter Block - parblk.inc

This include file defines the record format for parameter files. The same record format is also used in communication between TM and application processes. The LARGE_PARBLK and PARBLK structures are defined here; they are required by the parameter and variable manipulation package and z_init. The file also defines LARGE_P_BYTES and P_BYTES for the storage pool size.

"parblk.inc" includes "symtab.inc" and "pgminc.inc" automatically.

2.2.4.2 TAE Application Routine Codes - pgminc.inc

This include file contains the C language definitions of the constants required for applications programs (written in C) to interface with the TAE application function library. The file defines the P_ and M_ codes. This file is automatically included with the "parblk.inc" file.

2.2.4.3 C Language Standard Header - stdh.inp

This include file contains the standard C definitions, which include such data types as COUNT, TEXT, etc. This file does not have to be explicitly referenced--it is automatically referenced by the "taeconf.inp" include file.

2.2.4.4 Symbol Table Definition -symtab.inc

This include file contains TAE symbol table definitions and macros. The primary data structure is the VARIABLE structure. The file defines V codes for variable attributes. This file is automatically included with the "parblk.inc" file. The VARIABLE structure is described in Section 3.9.2.

2.2.4.5 TAE Configuration - taeconf.inp

This include file contains TAE standard data types (e.g. CODE, FUNINT, TAEINT and TAEFLOAT) and constant definitions. In addition, it contains definitions associated with the TM configuration. This primarily includes definition of parameters which control the size of TAE internal arrays. The file taeconf.inp should be referenced by every C source module.

taeconf.inp also defines the macro MOVE STRUCT to perform structure movement. Assuming a defined structure type of ALPHA, the following code sequence demonstrates the use of MOVE_STRUCT:

struct ALPHA               a = {1, 2, 3);
struct ALPHA               b;
struct ALPHA               *ap;
struct ALPHA               *bp;
ap = &a;
bp = &b;
MOVE_STRUCT(a, b);         /* move  a to b */
MOVE_STRUCT(*ap, *bp);      /*repeat previous operation */

2.2.4.6 Terminal Package - terminc.inc

This include file contains the definitions of constants required for using the terminal package.

2.2.4.7 WPT Package - wptinc.inp

This include file contains the definition of the various WPT package functions. The file also includes wptevent.h which contains the definition of the Wpt Event data constants and structures.

Additionally there is wptdefs.h which defines many of the other constants required for using the WPT package.

2.2.4.8 Image I/O Package - xiinc.inc

This include file contains definitions of the IFCB structure and constants required for using the image I/O package.

2.3 GUIDELINES FOR WRITING COMMUNICATING ASYNC-PROCESSES

As described in Section 2.7 of the TAE Command Language (TCL) User's Manual, a user may indicate that an asynchronous proc is to run without an associated Terminal Monitor. Because there is no Terminal Monitor, there are several restrictions, described in Section 2.7.2 of the TAE Command Language (TCL) User's Manual. This section lists additional rules for those ASYNC-PROCESSes that communicate with other jobs using the SENDVAR/RECVAR protocol.

A simple ASYNC-PROCESS server in the C language is shown in Appendix B.3. The following considerations apply:

  1. All of the p_ and q_ function calls are TAE standard, and described in this manual.

  2. z_exit does not currently work for an ASYNC-PROCESS.

  3. There is a package, c_, for interproc. communication. The c_ calls are described in Section 7.

  4. The initial parameter block passed to an ASYNC-PROCESS has two automatically-generated string parameters, _CHILD and _PARENT. _CHILD is the name of the ASYNC-PROCESS and _PARENT is the name of the job that created the ASYNC-PROCESS.

    Note that the SENDVAR/RECVAR protocol requires that each message contain a string variable named JOB to identify the originator of the message. SENDVAR and RECVAR are described in the TAE Command Language (TCL) Programmer's Manual, Section 3.4.

  5. After calling c_getmsg to receive a V-BLOCK, the process must call "makeabs" to make the pointers in the V-BLOCK absolute. Manipulation of the symbol table is easier with the pointers having absolute addresses. Similarly, before sending a V-BLOCK with c_pmwcd, 'makerel' must be called to make the pointers relative. See the example in Appendix B.3, "Simple C Server," for use of "makerel" and "makeabs".

    The "makerel" and "makeabs" functions have the same arguments: the first argument is a pointer to a TAE PARBLK symbol table and the second argument is a pointer to PARBLK pool where variables are stored.

  6. The r_top function (referenced from the "send_parblk" function in the example) returns a pointer to the highest byte currently allocated in the pool passed as argument.

  7. Makerel, makeabs, and r_top are in the standard TAE run-time library. In future releases of TAE, these calls will be abstracted into higher level packages.

  8. The "emit" function shown in the example performs the same function as the TCL EMIT command. The $SFI and $SKEY emitted by this function are visible to the parent's interactive user with the SHOW-ASYNC command.

  9. The message queue limit is five messages. The message queue is created with the TCL command ENABLE-RECVAR or by c_crepath. The name of the input queue is the current job name. See Section 3.5.4 of the TAE Command Language (TCL) User's Manual for details of ENABLE-RECVAR and Section 7.1 of this document for c_crepath.

2.4 TAE LIBRARY FUNCTION DESCRIPTIONS

Sections 3 through 10 in this manual, and the TAE Plus C Reference Manual, describe the calling sequences for TAE utility functions. The functions exist to standardize access to primitive host functions and to enhance the portability of the calling programs.

The functions are grouped into packages of related routines follows:

Section     Package Name     Title

TAE Command Language (TCL) Runtime Services Volume 1: C

  3.         p_/q_         Parameter/Variable manipulation
  4.         t_            Terminal I/O
  5.         m_            Message logging
  6.         i_            Image I/O
  7.         c_            Interproc communication functions
  8.         z_            Miscellaneous
  9.         Dp_           PDFs manipulation functions
 10.         Dm_           MDFs manipulation functions

TAE Plus C Reference Manual and TAE Plus Programmer's Manual 

             Vm_           Variable manipulation with internal memory 
                           allocation 
             Co_           Collection manipulation functions
             Wpt_          TAE Plus Window Programming Tools

In subsequent sections, the function descriptions are organized as follows:

The calling sequences are defined in the function descriptions in Sections 3 through 10 of Volume 1, and in the TAE Plus C reference manual. The function code type, argument name, type, direction of I/O (input or output)and description are given. The types are:

  1. BOOL: An int used as TRUE/FALSE indicator. Defined in stdh.inp.

  2. CODE: An int whose values are defined symbols like SUCCESS, FAIL, etc. Defined in taeconf.inp.

  3. COUNT: A signed integer of at least 16 bits. Defined in stdh. inp.

  4. FUNINT: An int used as a function argument; FUNINT is a way of documenting "the caller may supply an int or anything shorter in this argument position." Defined in taeconf.inp

  5. Id: An object handle; used by packages that allocate object memory internally (Dp_, Dm_, Vm_, Co_, Wpt_).

  6. struct XXX *: C pointer to structure XXX.

  7. TAEFLOAT: The standard TAE internal form of floating variables. On most machines, TAEFLOAT is "double float", but coding as a defined type allows it to be defined as "float" on smaller machines. Defined in taeconf.inp.

  8. TAEINT: The TAE standard integer. TAEINT is at least as wide as COUNT. Defined in taeconf.inp.

  9. TEXT: A char used to contain character data. Defined in stdh. inp.

  10. VOID: Used in function declaration to document "nofunction value defined."