2.12 SELF-TUTOR

Within the TAE Terminal Monitor (TM), operating in ASCII mode, when a proc specifies OPTIONS=SELFTUTOR on the PROCESS or PROCEDURE command, TM turns over the responsibility for interactive parameter acquisition to the proc; the Terminal Monitor does not do the tutoring. When the user requests tutor for a SELFTUTOR proc, the proc is executed immediately to perform its own version of tutor.

When TAE receives an initial tutor request for a proc declared SELFTUTOR, a new implicit local integer variable, "_TUTOR", is set to one as a flag to the proc. If the proc is a process, TAE prepares a V-block (or vm object) with the default values defined in the PDF, and passes the V-block to the process; this V-block includes the _TUTOR flag. If the proc is a procedure, TAE begins execution of the procedure with the local variable _TUTOR set to one.

Consider the following procedure example:

procedure options=selftutor
    parm long real  ! longitude 
    parm lat real   ! latitude 
    parm satid      ! satellite
body
if (_tutor)
    GetEarthPosition long=long lat=lat
    GetSatId satid=satid
end-if
! long, lat, and satid available for use here
.
.
.
end-proc

When the user requests tutor for this procedure, the procedure is executed with the _TUTOR flag set. The procedure performs its self-tutor by running a proc, GetEarthPosition, that graphically interacts with the user to obtain a latitude and longitude. Another interactive proc, GetSatld, is then run to allow the user to select from a list of currently available satellites. If this example procedure is run from command mode, TAE sets _TUTOR to zero and the execution of GetEarthPosition and GetSatId is bypassed.

The following page (Example 1) shows the skeleton of a TAE process configured for self-tutor. The two pages following that (Example 2) show a process example where dynamic tutor is used to satisfy the self-tutor request. In the second example, self-tutor is used to allow the process to access a data base and fill in valid lists in preparation for the initial tutor session.

EXAMPLE 1
---------

/*****
self-tutor skeleton.

Note that the PDF for this program
must have the following form:

    process options=selftutor
    ...
    end-proc
*****/

#include     "taeconf.inp"
#include     "parblk.inc"
#include     "terminc.inc"

main( )
{
Id     vmid, Vm_New( );
CODE   Vm_ReadFromTM( );
struct VARIABLE *v;
struct VARIABLE *Vm_Find( );

vmid = Vm_New (P_ABORT);
Vm_ReadFromTM (vmid);
v = Vm_Find (vmid, "_tutor");   /* get _tutor */
if (IVAL(*v,O))                 /* if tutor == 1 */
    {   
    /* perform self-tutor here */

    t_write ("hello from self-tutor", T_STDCC);
    }
/* normal program execution */
}


EXAMPLE 2
---------

/*****
self-tutor example.

This program fills in the "valid" list for
the variable "x" before the initial tutor is
performed. The PDF for this program
should be:
        process options=selftutor
            parm x valid=(dummyl, dummy2)
        end-proc
*****/

#include     "taeconf.inp"
#include     "parblk.inc"
#include     "terminc.inc"
main( )
{

Id     vmid, Vm_New( );
CODE   Vm_ReadFromTM( ); 
struct VARIABLE *v; 
struct VARIABLE *x; 
struct VARIABLE *Vm_Find( ); 
static TEXT *stringVector[] =>
    {"firstValidValue", "secondValidValue", 
    "thirdValidValue", "lastValidValue");

vmid  = Vm_New (P_ABORT); 
Vm_ReadFromTM (vmid);
v = Vm_Find (vmid, "_tutor");   /* get _tutor   */

if (IVAL(*v,O))          /* if tutor == 1 */
    {

    /*****
    Here: access data base to get valid strings.
    In this example, we (instead) hard-code
    several strings. After setting the valids,
    we initiate dynamic tutor, which to the end
    user looks like initial tutor.
    *****/

    Vm_SetValidString (vmid, "x", 4, stringVector);
    Vm_DynTutor (vmid, "", M_FULLPDF);
    Vm_ReadFromTM (vmid);
    }
/* normal program execution */
x = Vm_Find (vmid, "x");
t_write (SVAL(*x,0), T_STDCC);
}


The following notes apply to self-tutor:
  1. The major motivation behind the self-tutor feature is to allow a process to use a forms manager to acquire parameters. Most commercially-available forms managers support tailored screen designs and the immediate verification of user-supplied values.

  2. When a proc is executed from command mode, the TUTOR variable is set to zero.

  3. When a proc is executed for self-tutor, some parameters may have "no value" (because no default was defined in the PDF). This is in contrast to command line execution and standard tutor execution where all parameters are guaranteed to have values. Parameters with no value have a negative vector count: the following code fragments show how to detect the "no value" condition for the parameter named "p":

    TCL:
    
    if ($count(p) < 0) write "p has no value"
    
    
    C:
    
    struct VARIABLE *v;
    Id vmid;
    vmid = Vm_New (P_ABORT);
    Vm_ReadFromTM (vmid);
    v = Vm_Find (vmid, "p");
    if ((*v).v count < 0)
        printf ("p has no value/n");
    
    
  4. The OPTIONS=SELFTUTOR declaration applies only to the initial tutor for a proc. When a process requests dynamic tutor for some PDF, the SELFTUTOR option is ignored.

  5. The OPTIONS=SELFTUTOR declaration is not available for GLOBALS and PARMSET PDFs.

  6. A self-tutor process may decide to send a message to another process (a "tutor server") to perform the self-tutor. A typical sequence would be:

  7. The initial V-block (or vm object) received by a self-tutor proc contains "primed" values from the TAE command line. For example, consider the following tutor command:

    TAE> tutor aProc x=35 y=17

    When executed for self-tutor, the proc receives a V-block with x set to 35 and y set to 17, overriding the default values in the PDF This "priming" feature. is especially powerful when the tutor command appears in a .COMMAND directive of an MDF.

  8. TAE does not honor self-tutor for procs destined to be run in batch mode or async mode. Thus, the following command uses standard TAE tutor even if the proc requests self-tutor:

    TAE> tutor aProc |runtype=batch|

  9. Self-tutor does not apply to the tutor subcommand display. The subcommand display is always handled by TAE. After the subcommand is specified, TAE then honors OPTIONS=SELFTUTOR for "parameter" tutor.

  10. The V-block (or vm object) passed to the application for self-tutor contains the valid strings from the PDF. These strings -- typically used for presenting various forms of selection lists to the user -- are accessible through the "v_valid" field of the VARIABLE structure. Note that when a proc is activated from a command line, the valid strings are not present in the V-block.

  11. OPTIONS=SELFTUTOR is ignored if the $TUTOPT global variable is set to NO_SELFTUTOR. This feature exists for testing procs before the proc's self-tutoring logic is working.