This section describes the p_ and q_ packages, consisting of functions that allow a TAE application program to manipulate process parameters and variables. These packages use data buffers provided by the caller. The Vm_ package, described in the TAE Plus C Reference Manual, provides the same capabilities, but allocates the memory internally. (The Vm_ package is the recommended package.)
As noted in Section 2 of the TAE Command Language (TCL) Programmer's Manual, the process parameters and variables consist of the following:
Note that, as described in Section 3.3.2 of the TAE Command Language (TCL) Programmer's Manual, process parameters are, in fact, TCL variables. All references to "TCL variables" in succeeding sections apply to locals, globals, and parameters.
The most common use of the packages is the receipt of user-supplied parameters by the application program. Also described are functions for:
Three function packages are available for parameter and variable manipulation:
The detailed calling sequences of the two packages are described below. The following introductory paragraphs explain variable manipulation.
As described in Section 2 of the TAE Command Language (TCL) Programmer's Manual, the variables for a process are defined in the PDF. The caller of the variable manipulation functions receives the process variables in the following formats:
Note that the NAME type (see Section 2.3.2 of the TAE Command Language (TCL) Programmer's Manual) is not seen directly by the p_/q_ packages: the caller of the p_ functions receives the type and value of the variable that is referenced by the NAME parameter.
The "V-block" (for "variable block") is the standard data structure for packaging process variables. A V-block is sent from TM when the process is initiated, and it is also the data structure used when variables are saved on disk. A V-block contains, for each process variable, the following items:
The C declaration of a V-block is "struct PARBLK vblock".
An application program reads variables as follows:
A programmer might update an existing V-block when it is to be saved on disk, or used in a dynamic tutor session. This is done as follows:
After update, the block may be written to disk (q_wrtb) and/or used to initiate a dynamic tutor session (q_dynp) or to send outputs (i.e., TCL variables) to TM (q_out).
An application program constructs a V-block as follows:
After construction, the block may be written to disk (q_wrtb) and/or used to initiate a dynamic tutor session (q_dynp) or to send outputs (i.e., TCL variables) to TM (q_out).
The parblk.inc include file provides a macro, DEF_PARBLK, that can be used to define PARBLKs of any size up to a limit of MAXINT bytes. The two arguments to the macro are the name of the parblk structure to be defined and the pool size. An example of its use is provided in the include file itself, in the definition of LARGE_PARBLK:
DEF_PARBLK(LARGE_PARBLK, LARGE_P_BYTES.);
where LARGE_PARBLK uses a pool space of LARGE_P_BYTES, and LARGE_P_BYTES is currently defined as 5_*MAX_COMPACT_UCOUNT bytes.
The DEF_PARBLK macro can be used to define very large parblk's to be written to disk (in association with q_wrtb and p_rdb, the routines to write a parblk to disk and to read a parblk back).
As described in Section 2 of the TAE Command Language (TCL) Programmer's Manual, the possible outputs of a process are TCL parameters of type NAME; global variables declared in a PDF (using REFGBL); and the implicit globals listed in Section 3.3.2 of the TAE Command Language (TCL) Programmer's Manual. The values for outputs may be set using q_intg, q_real and q_string into a V-block built using q_init (or an existing block received by p_inim or read by p_rdb). The V-block is sent to TM using q_out; q_out may be called at any time during process execution. The values for globals $SFI and $SKEY may also be set using z_exit (see Section 8).
After initiation, an application process may request additional parameters from the user. When the parameters are requested, TM places the user in dynamic tutor.
Dynamic tutor is not available for batch or ASYNC-PROCESS jobs. For normal asynchronous jobs, the interactive user must respond to the dynamic tutor request with the TAE REPLY command.
An application process initiates and receives the results of a dynamic tutor session as follows:
Note that prior to step 2, functions may be called to change the minimum or maximum count of a variable (q_min, q_max) to set the maximum string length (q_stringlength), or to set the valids (q_validintg, q_validreal, q_validstr).
An existing PDF must be associated with a dynamic tutor session. The PDF name is an input argument to the q_dynp call. The PDF is used by TM to determine the full declarations of the parameters and to locate the related help file.
The PDF may be the PDF for the executing process or may be an entirely different PDF. The PDF need not be a proc PDF; it may be a PARMSET PDF as described in Section 2 of the TAE Command Language (TCL)Programmer's Manual.
The q_dynp function accepts a "sub-PDF/full-PDF" flag, directing whether or not all of the parameters in the PDF are to participate in the dynamic tutor session. In sub-PDF mode, only the parameters in the V-block constructed by the process participate in the session. In full-PDF mode, all of the PDF parameters participate in the session, even if the V-block contains only some of them.
The sub-PDF feature is provided to avoid proliferation of PDFs; with subsetting, one PDF may be used for many combinations of parameters in dynamic tutor sessions.
At the beginning of a dynamic tutor session, TM checks that the V-block received from the application process is compatible with the PDF parameter definitions. If discrepancies are detected (e.g., a parameter placed in the block via q_intg is defined to be of type REAL in the PDF), the application program is aborted.
A common situation is a request for a dynamic tutor session with full-PDF, where the programmer is content to use defaults defined in the PDF. In this case, the V-block passed to TM has no parameters, i.e., the q_dynp call may immediately follow the q_mit call.
The p_/q_ packages run in "abort" or "continue" mode as selected by an argument to p_inim, z_init, p_rdb, or q_init. In continue mode, errors detected by subsequent p_/q_ function calls are returned as function codes to the calling routine; in abort mode, the p_/q_ packages generate an error message and terminate the process.
Abort mode is provided as a convenience to the programmer; in this mode there is no need for the program to check function codes and generate error messages.
When errors are detected in continue mode, a host-independent function code is returned to the p_/q_ caller. In addition, the parameter/variable manipulation package provides a function, p_herr, that retrieves the host-dependent error code for the last error reported.
The abort/continue flag is maintained by TAE in the V-block. Thus, the abort/continue mode applies to the V-block and not the entire p_/q_ package. Should there be a need for altering the setting of the abort/continue flag in a V-block, the programmer can directly store the constants P_ABORT or P_CONT into the V-block member name "mode".
As described in Section 2 of the TAE Command Language (TCL) Programmer's Manual, the V-block passed to an application process by the Terminal Monitor contains, in addition to the process parameters and explicitly declared variables, the implicitly declared TCL variables, _PROC, _STDOUT, _SUBCMD, ONFAIL, $RUNTYPE, $SESSION, $SFI, $SKEY and $SWITCH. (In addition blocks for ASYNC-PROCESS jobs contain _PARENT, _CHILD and _JOB.) See Section 3.3.2 of the TAE Command Language (TCL) Programmer's Manual for a description of these TCL variables.
These TCL variables may be obtained via standard p_find calls.
See template.c in $TAEDEMOCLASSIC for a basic program that contains many of the parameter manipulation functions. Use the command TAEBUILDEONE (in VMS) or taeccone (in UNIX) to build an executable based on template.c. See Appendix B of this manual for more elaborate examples.
Function return:
Arguments:
TAE file specification to be translated.
The file access specification. Possible values are:
The argument to receive the translated host specification, dimensioned FSPECSIZ+1.
p_file translates the TAE file specification into a host specification.
The following program segment demonstrates the use of p_files:
struct VARIABLE *p_find (vptr, name)
Function return:
Arguments:
vptr: input, struct PARBLK *vptr;
Pointer to a parameter block (PARBLK structure) -containing the V-block (VARIABLE structure) where the variable name is to be searched.
name: input, TEXT name[];
Name of the variable.
p_find is used to help retrieve the individual variables from the parameter block. P_find differs from p_fvar in that p_find honors abort mode if the variable does not exist.
Each variable is defined as a VARIABLE structure; the VARIABLE structure is defined in the symtab.inc include file.
Assuming that "v" is the returned value of a successful p_find call, the following information is available:
The (*v).v_cvp field is a pointer (in char * format) to a value vector. A value vector is:
The following C macros are defined in the SYMTAB include file to assist in accessing the values of a VARIABLE structure:
The indexing above is "C indexing", i.e., the first component of a variable is index zero. The VALUE_* macros (where * is defined to be _I, _R, or _S) are the same as the macro names IVAL, RVAL, and SVAL.
The values of a variable may also be accessed by casting the(*v) .vcvp pointer into the proper form. The following C program segment demonstrates:
struct PARBLK parblk /* parameter block */ TAEFLOAT *real; /* value vector pointer */ TAEINT *intg; /* value vector pointer */ TEXT **str; /* value vector pointer */ struct VARIABLE *vx, *vi, *vs, *p_find(); COUNT P_inim (&parblk, sizeof(struct PARBLK), P_ABORT); vx = p_find (&parblk, "X"); /* find VARIABLE structures */ vi = p_find (&parblk, "I"); vs = p_find (&parblk, "5"); real = (TAEFLOAT *) (*vx).v_cvp; /* cast value vector pointers */ intg = (TAEINT *) (*vi).v_cvp; str = (TEXT **) (*vs).v_cvp; for (i=O; i < (*vx).v_count; i++) printf ("X(%d) = %f\n", i+1, real[i]); for (i=O; i < (*vi).v_count; i++) printf ("I(%d) = %d\n", i+1, intg[i]); for (i=O; i < (*vs).v count; i++) printf ("S(%d) = %s\n", i+1, str[i]);
CODE p_forp (vptr, line, length)
Function return:
Arguments:
vptr: input, struct PARBLK *vptr;
Pointer to a PARBLK structure with the V-block from p_inifor call.
line: output, TEXT line[];
String containing next n variables from the V-block in "name=value" format. The number n is determined by the number of variables that fit within the length of the line.
Line must be long enough to receive the longest variable value (form is "name=value" including quotes) plus room for the continuation character.
length: input, COUNT length;
Length of output line in bytes.
p_forp obtains parameter values and values of global and local variables in a displayable form, i.e., as lines of text.
p_forp must be called multiple times to obtain the values in character form. Each call to p_forp receives one line of variable text, in the order the variables appear in the V-block. The format for all values is "name=value" where "name" is the name of the variable.
p_inifor must be called to initialize for a sequence of p_forp calls.
struct VARIABLE *p_fvar (vptr, name)
Function return:
Arguments:
vptr: input, struct PARBLK *vptr;
Pointer to a PARBLK structure containing the V-block where the variable name is to be searched
name: input, TEXT name[];
Name of the variable.
p_fvar is same as p_find, except that pfvar ignores the ABORT flag of the V-block.
VOID p_herr (vptr, hcode)
Function return:
Arguments:
vptr: input, struct PARBLK *vptr;
Pointer to the PARBLK structure with the V-block containing TCL variables.
hcode: output, CODE *hcode;
Pointer to the host-dependent error code.
p_herr gets the host-dependent error code associated with the last operation (that is, a p_ or q_ operation) on the specified block.
VOID p_inifor (vptr)
Function return:
Argument:
vptr: input, struct PARBLK *vptr;
Pointer to the PARBLK structure with the V-block containing TCL variables.
p_inifor initializes for multiple calls to p_forp.
Function return:
Note that the status codes listed above are available only if the block was initialized in "continue" mode.
Arguments:
vptr: input, struct PARBLK *vptr;
Pointer to a PARBLK structure to receive the V-block from the Terminal Monitor.
size: input, FUNINT size;
This argument must be sizeof(struct PARBLK).
mode: input, FUNINT mode;
p_inim or p_rdb must be called before any other call to the p package using the same V-block. P_inim receives a V-block from the Terminal Monitor. Variables in this block may then be accessed with the p_find calls.
If p_inim is called to receive the variables of a dynamic tutor session, only the parameters are returned, the implicit variables(_STDOUT, etc.) are not.
If a status code of P_KILLED is returned, the application should terminate after performing any necessary clean-up operations.
CODE p_rdb (spec, lun, vptr, size, mode)
Function return:
Note that the status codes listed above are available only if the block was initialized in "continue" mode.
Arguments:
spec: input, TEXT spec[];
Host file specification of file to be read.
lun: input, COUNT lun;
Logical unit number to use for the file I/O. On VMS and UNIX systems, this argument is ignored.
vptr: input, struct PARBLK *vptr;
Pointer to an PARBLK structure to receive the V-block.
size: input, COUNT size;
This argument must be the constant sizeof(struct PARBLK)
mode: input, FUNINT mode;
p_rdb or p_inim must be called before any other call to the p_ package using the same V-block. P_rdb reads a V-block data file into the PARBLK structure pointed to by vptr.
A V-block file is created by the tutor SAVE command, or a command mode SAVE qualifier, or by a call to q_wrtb from an executing process.
CODE q_dynp (vptr, pdfname, pdfset)
Function return:
Note that the status codes listed above are available only if the block was initialized in "continue" mode.
Arguments:
vptr: input, struct PARBLK *vptr;
Pointer to a PARBLK structure containing the V-block that has been built by the application and is to be sent to the Terminal Monitor. Any parameters or variables whose values are specified in the V-block must be defined in the PDF.
pdfname: input, TEXT pdfname[];
The PDF name to be used by the Terminal Monitor. This PDF should define all variables in the V-block. If pdfname is a simple alphanumeric string, TAE performs a standard "proc hierarchy search" to locate the PDF. If the pdfname string contains a library name, then TM uses the name as is and no hierarchy search is performed.
The pdfname may be the empty string, in which case the PDF of the current process is used.
The pdfname may include a subcommand, in which case the parameters participating in the dynamic tutor session are the parameters associated with the specified subcommand. A subcommand must be specified if the PDF has subcommands but no default subcommand.
pdfset: input, FUNINT pdfset;
pdfset is either "sub-PDF" or "full-PDF"
The q_dynp sends the V-block to the Terminal Monitor as a set of initial values for a dynamic tutor session. After calling q_dynp, the application program waits on completion of the dynamic tutor session by calling p_inim. The V-block must be constructed before calling q_dynp. p_inim, p_rdb, q_init, q_intg, q_real, q_string are functions that may be used to construct a V-block.
q_dynp is not acceptable in a batch job or an ASYNC-PROCESS job.
VOID q_init (vptr, size, mode)
Function Return: None
Arguments:
vptr: input, struct PARBLK (or LARGE_PARBLK) *vptr;
Pointer to a PARBLK (LARGE_PARBLK) structure that will become the initialized V-block.
size: input, FUNINT size;
This argument must be the size of the storage pool in the PARBLK (LARGE_PARBLK) structure, currently P_BYTES ( LARGE P_BYTES ).
The q_init is called to initialize a V-block in preparation for other q_ calls. (A V-block may also be initialized by p_inim or p_rdb.) After q_init is called, the V-block is properly formatted with zero variables.
CODE q_intg (vptr, name, count, intg, mode)
Function return:
Note that the status codes listed above are available only if the block was initialized in "continue" mode.
Arguments:
vptr: input/output, struct PARBLK *vptr;
Pointer to a PARBLK structure with the V-block in which the variable value is to be set. This block must have been initialized with a call to q_init, p_inim, z_init or p_rdb.
Name of the TCL integer variable to be set.
count: input, FUNINT count;
Multiplicity of the variable, i.e., the number of integers in the intg array.
The count values 0, -1, and -2 are special: a count of 0 means "null value"; a count of -1 means "no value", in which case the parameter becomes a mandatory parameter; and a count of -2 means "use the default value defined in the PDF."
intg: input, TAEINT intg[];
An array of integer values (an integer value vector) for the variable. If count is one, note that intg must nonetheless be an array of dimension one. (See the program examples in Appendix B.) If count is less than one, then the intg argument is ignored.
mode: input, FUNINT mode;
CODE qout (vptr)
Function return:
Note that the status code listed above is available the only if block was initialized in "continue" mode.
Argument:
vptr: input, struct PARBLK *vptr;
Pointer to a PARBLK structure with the V-block that has been built by the application program and is to be sent to the Terminal Monitor. Any parameters or variables whose values are specified in V-block must be defined in the PDF for the executing process.
q_out sends the V-block containing the values of name parameters and global variables to the Terminal Monitor.
The V-block argument must be constructed before calling q_out; p_inim, p_rdb, q_init, q_intg, q_real, q_string are functions that may be used to construct a V-block. See Section 3.3 for more details.
CODE qreal (vptr, name, count, real, mode)
Function return:
Note that the status codes listed above are available only if the block was initialized in "continue" mode.
Arguments:
vptr: input/output, struct PARBLK *vptr;
Pointer to a PARBLK structure with the V-block in which the variable value is to be set. This block must have been initialized with a call to q_init, p_inim, z_init or p_rdb.
name: input, TEXT name[];
Name of the TCL real variable to be set.
count: input, FUNINT count;
Multiplicity of the variable, i.e., the number of real values in the real array.
The count values 0, -1, and -2 are special: a count of 0 means "null value"; a count of -1 means "no value", in which case the parameter becomes a mandatory parameter; and a count of -2 means "use the default value defined in the PDF."
real: input, TAEFLOAT real[];
An array of real values (a real value vector) for the variable. If count is one, note that real must nonetheless be an array of dimension one. (See program examples in Appendix B.) If count is less than one, the real argument is ignored.
mode: input, FUNINT mode;
CODE q_string (v_ptr, name, count, vector, mode)
Function return:
Note that the status codes listed above are available only if the block was initialized in "continue" mode.
Arguments:
vptr: input/output, struct PARBLK *vptr;
Pointer to a PARBLK structure with the V-block in which the variable value is to be set. This block must have been initialized with a call to q_init, p_inim, z_init or p_rdb.
name: input, TEXT name[];
Name of the TCL string or keyword variable to be set.
count: input, FUNINT count;
Multiplicity of the variable, i.e., the number of string pointers in the vector argument.
The count values 0, -1, and -2 are special: a count of 0 means "null value"; a count of -1 means "no value", in which case the parameter becomes a mandatory parameter; and a count of -2 means "use the default value defined in the PDF."
vector: input, TEXT *vector[];
An array of pointers to strings (a string value vector) for the variable. If count is one, note that vector must nonetheless be an array of dimension one (see program example in Appendix B). If count is less than one, then the vector argument is ignored.
mode: input, FUNINT mode;
CODE q_wrtb (spec, lun, vptr)
Function return:
Note that the status codes listed above are available only if the block was initialized in "continue" mode.
Arguments:
spec: input, TEXT spec[];
Host file specification of file to be created.
lun: input, FUNINT lun;
Logical unit number to use for the file I/O. On VAX/VMS and UNIX systems, this argument is ignored.
vptr: input, struct PARBLK *vptr;
Pointer to the PARBLK structure with the V-block to be written. q_wrtb writes a PARBLK structure into a V-block data file.
CODE qmax (p, name, max)
Function return:
Arguments:
p: input/output, struct PARBLK *p;
Pointer to a PARBLK structure with the V-block in which the variable's maximum vector count is to be set. This block must have been initialized with a call to q_init, p_inim, z_init or p_rdb.
name: input, TEXT name[];
Name of the variable.
max: input, FUNINT max;
An integer value for the maximum count of the variable
q_max sets the maximum count of a variable.
If the variable has more than "max" values set, then array elements beyond the "max"th one will be lost.
CODE q_min (p, name, min)
Function return:
Arguments:
p: input/output, struct PARBLK *p;
Pointer to a PARBLK structure with the V-block in which the variable's minimum vector count is to be set. This block must have been initialized with a call to q_init, p_inim, z_init or p_rdb.
name: input, TEXT name[];
Name of the variable.
min: input, FUNINT min;
An integer value for the minimum count of the variable
q_min sets the minimum count of a variable.
CODE q_parmpage (p, name, flag)
Function return:
Arguments:
p: input/output, struct PARBLK *p;
Pointer to a PARBLK structure with the V-block in which the variable's page indicator is to be set. This block must have been initialized with a call to q_init, p_inim, z_init or p_rdb.
name: input, TEXT name[];
Name of the variable.
flag: input, BOOL flag;
q_parmpage sets the page indicator of a variable. This causes the variable to appear at the top of a new page in a tutor session.
CODE q setnextmenu (p, name)
Function return:
P_error code values are defined in include file pgminc.inc; M_ error code values are defined in include file menuinc.inc.
Arguments:
p: input/output, struct PARBLK *p;
Pointer to a PARBLK structure with the V-block in which the global $MENU is to be set. This block must have been initialized with a call to q_init, p_inim, z_init or p_rdb.
name: input, TEXT name[];
Name of the next MDF to be executed.
q_setnextmenu sets the next menu to be displayed by TM. The specified MDF is added onto the current menu stack specified by $MENU. The updated parameter block is then sent to TM.
Note that the related PDF must have a global reference (refgbl) to $MENU.
CODE q_stringlength (p, name, strlen)
Function return:
Note that the status codes listed above are available only if the object was initialized in "continue" mode with a call to p_inim, z_init, q_init, or p_rdb.
Arguments:
p: input/output, struct PARBLK *p;
Pointer to a PARBLK structure with the V-block in which the variable is to be set. This block must have been initialized with a call to q_init, p_inim, z_init or p_rdb.
name: input, TEXT name[];
Name of the TCL string or keyword variable to be set.
strlen: input, FUNINT strlen;
The maximum length of a string for the variable.
q_stringlength sets the maximum length of a string for the variable.
CODE q_validintg (p, name, count, ilow, ihigh)
Function return:
Arguments:
p: input/output, struct PARBLK *p;
Pointer to a PARBLK structure with the V-block in which the variable's valids are to be set. This block must have been initialized with a call to q_init, p_inim, z_init, or p_rdb.
name: input, TEXT name [];
Name of the TCL integer variable.
count: input, FUNINT count;
Multiplicity of the valids; i.e., the number of ranges.
ilow: input, TAEINT ilow[];
An array of integer values (an integer value vector) for the low values of the ranges.
ihigh: input, TAEINT ihigh[];
An array of integer values (an integer value vector) for the high values of the ranges.
If count is one, note that ihigh and ilow must nonetheless be an array of dimension one. If count is less than one, then the ihigh and ilow arguments are ignored.
q_validintg sets valids of an integer variable.
A call to q_validintg will replace any current valids for the specified variable that were set by previous calls to q_validintg.
The contents of the ilow and ihigh arrays are paired to form valid ranges. For example: ilow[] = {1, 2, 25}; ihigh[] = {1, 5, 73}; is equivalent to a specification of VALID=(1, 2:5, 25:73) on a PARM statement.
The valids specified in the call to q_validintg are not applied to any values that the variable might have from an earlier call to q_intg.
CODE q_validreal (p, name, count, rlow, rhigh)
Function return:
Arguments:
p: input/output, struct PARBLK *p;
Pointer to a PARBLK structure with the V-block in which the variable's valids are to be set. This block must have been initialized with a call to q_init, p_inim, z_init or p_rdb.
name: input, TEXT name[];
Name of the TCL integer variable.
Multiplicity of the valids i.e., the number of ranges.
An array of real values (a real value vector) for the low values of the ranges.
An array of real values for the high values of the ranges.
If count is one, note that rhigh and rlow must nonetheless be an array of dimension one. If count is less than one, then the rhigh and rlow arguments are ignored.
q_validreal sets valids of a real variable.
A call to q_validreal will replace any current valids for the specified variable that were set by previous calls to q_validreal.
The contents of the rlow and rhigh arrays are paired to form valid ranges. For example: rlow[] = (2.3, 21.5); rhigh[] = (5.0, 55.9); is equivalent to a specification of VALID=(2.3:5.O, 21.5:55.9) on a PARM statement.
The valids specified in the call to q_validreal are not applied to any values that the variable might have from an earlier call to q_real.
CODE q_validstr (p, name, count, vector)
Function return:
Arguments:
p: input/output, struct PARBLK *p;
Pointer to a PARBLK structure with the V-block in which the variable's valids are to be set. This block must have been initialized with call to q_init, p_inim, z_init or p_rdb.
name: input, TEXT name[];
Name of the TCL string variable.
count: input, FUNINT count;
Multiplicity of the valids, i.e., the number of string pointers in the vector argument.
vector: input, TEXT *vector[];
An array of pointers to strings (a string value vector) for the variable. If count is one, note that the vector must nonetheless be an array of dimension one. If count is less than one, then the vector argument is ignored.
q_validstr sets valids of a string variable.
A valid string may contain at most the number of characters as defined by VALIDSIZ in the file symtab.inc in the directory $TAEINC.
A call to q_validstr will replace any valids that had previously been specified for that variable.