gtpa3m0s | Application Requester User's Guide |
Figure 21 shows the root segment for the telephone directory application package. In the sample C code the following conventions have been established:
The basic format for all of the messages used in this package is as follows:
rc /a add_parm
where:
#include <tpfeq.h> /* Include libraries */ #include <tpfapi.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #pragma map(qxp0_exm_tests,"QXP0") extern void qxp0_exm_tests(); #pragma map(qxp1_insert,"QXP1") extern void qxp1_insert(); #pragma map(qxp2_delete,"QXP2") extern void qxp2_delete(); #pragma map(qxp3_update,"QXP3") extern void qxp3_update(); #pragma map(qxp4_display,"QXP4") extern void qxp4_display(); /********************************************************************/ /* This is the root function of the SQL example segments. It */ /* will parse the input looking for the action code, then */ /* depending on the action code, it will call the appropriate */ /* routine. */ /********************************************************************/ void qxp0_exm_tests() { struct mi0mi *blk; /* Pointer to the input message: */ /* The input message is on D0 */ char action; /* Action code entered: */ /* This is from the parsed */ /* message. */
/********************************************************************/ /* The database name is placed in ebx000 so that any function */ /* that needs it can use it and if it is changed, it will only */ /* have to be changed in one spot. */ /********************************************************************/ memset ((void *) &ecbptr()->ebx000, ' ', 15); memcpy ((void *) &ecbptr()->ebx000, "DB23TST", sizeof("DB23TST")-1); /* The size of the string includes the */ /* null at the end which needs to be */ /* placed at byte 16. */ ecbptr()->ebx016 = '\0'; /********************************************************************/ /* Set up a pointer to the input message and replace the EOM */ /* character with a NULL. */ /* */ /********************************************************************/ blk = ecbptr()->ce1cr0; *strchr (blk->mi0acc,_EOM) = '\0'; /********************************************************************/ /* Parse the message block. The first parameter is unused, the */ /* second parameter is the action. The rest of the parameters */ /* depend on what the first parameter is. They will be scanned */ /* individually based on the action. Notice that the action is */ /* preceded by a /. */ /* */ /********************************************************************/ sscanf(blk->mi0acc, "%*s /%1c", &action);
/********************************************************************/ /* Based on the action entered, call the different routines. */ /* The action is converted to uppercase so that the case statement */ /* can be made smaller. */ /* */ /********************************************************************/ switch (toupper(action)) { case 'I': /* A new entry is to be inserted */ qxp1_insert(); break; case 'D': /* A display is requested. */ qxp4_display(); break; case 'R': /* A removal of an entry is needed. */ qxp2_delete(); break; case 'U': /* An update of an entry is needed. */ qxp3_update(); break; default: printf( "Action entered is incorrect. Please enter a I, D, U or R"); break; } exit(0); }