home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / HAPI.ZIP / HAPI / HAPI_C / HSMPLC.C < prev    next >
C/C++ Source or Header  |  1991-10-25  |  67KB  |  1,956 lines

  1. /********************************************************************/
  2. /*                                                                  */
  3. /* FILE NAME: HSMPLC.C                                              */
  4. /*                                                                  */
  5. /* MODULE NAME= HSMPLC.C                                            */
  6. /*                                                                  */
  7. /* DESCRIPTIVE NAME= C SAMPLE PROGRAM FOR EHLLAPI                   */
  8. /*                                                                  */
  9. /*   Displays EHLLAPI and session information.                      */
  10. /*   Writes string to host.                                         */
  11. /*   Searches for written string on host.                           */
  12. /*   Displays host session screen.                                  */
  13. /*   Manipulates the Presentation Manager properties of             */
  14. /*   the emulator session to: change window title name, switch      */
  15. /*   list name, make window invisible, query window status,         */
  16. /*   window coordinates, change window size, and restore the        */
  17. /*   emulator session window to its original conditions.            */
  18. /*   Next, the structured field functions are used.  The            */
  19. /*   communications buffer is queried, the read and write buffers   */
  20. /*   allocated, a connection is initiated to the communications     */
  21. /*   buffer, and an asynchronus read structured field is issued     */
  22. /*   disabling the inbound host.  Then, the sendkey function is     */
  23. /*   used to send the command 'IND$FILE PUT SF_TEST EXEC A'         */
  24. /*   to the host which puts a non-existent file from the            */
  25. /*   PC to the host using a structured field.  Next, a get          */
  26. /*   completion request is issued to determine if the               */
  27. /*   previous asynchronus read structured field is completed,       */
  28. /*   Upon completion, a synchronus write structured field is        */
  29. /*   issued, the communications buffers are de-allocated, and       */
  30. /*   then a disconnect from structured field is issued.             */
  31. /*                                                                  */
  32. /*   COPYRIGHT:  XXXXXXXXX  (C) COPYRIGHT IBM CORP. 1987,1988,1991  */
  33. /*               LICENSED MATERIAL - PROGRAM PROPERTY OF IBM        */
  34. /*               ALL RIGHTS RESERVED                                */
  35. /*                                                                  */
  36. /* NOTES=                                                           */
  37. /*    COMPILE WITH SMALL MODEL.                                     */
  38. /*                                                                  */
  39. /*                                                                  */
  40. /* MODULE TYPE:  Microsoft C 6.0                                    */
  41. /*                                                                  */
  42. /*                                                                  */
  43. /**********************-END OF SPECIFICATIONS-***********************/
  44.  
  45. /********************************************************************/
  46. /********************** BEGIN INCLUDE FILES   ***********************/
  47. /********************************************************************/
  48.  
  49. #include "stdio.h"
  50.  
  51. #include "string.h"
  52.  
  53. #include "hapi_c.h"                    /* Get EHLLAPI include file  */
  54.  
  55.  
  56. /********************************************************************/
  57. /************************ FUNCTION EXTERNS **************************/
  58. /********************************************************************/
  59.  
  60.  
  61.  
  62. /* The following extern was copied out of SUBCALLS.H instead of     */
  63. /* included in for ease of compiling.                               */
  64.  
  65. extern unsigned far pascal VIOWRTCELLSTR (
  66.         char far *,               /* String to be written           */
  67.         unsigned,                 /* Length of string               */
  68.         unsigned,                 /* Starting position for output (row) */
  69.         unsigned,                 /* Starting position for output (col) */
  70.         unsigned );               /* Vio Handle                      */
  71.  
  72.  
  73. /* The following externs were copied from doscalls.h                   */
  74.  
  75. extern unsigned far pascal DosSleep(
  76.          long);
  77.  
  78.  
  79. /* The following extern enables direct calls to be made to EHLLAPI */
  80.  
  81. extern void far pascal hllapi(int far*,
  82.          char far *,
  83.          int far *,
  84.          int far *);
  85.  
  86. /*********************************************************************/
  87. /****************************  DEFINES *******************************/
  88. /*********************************************************************/
  89.  
  90. #define MAX_DATA_SIZE 3840              /* The maximum data          */
  91.                                         /* size for this             */
  92.                                         /* application.              */
  93. #define EABS 0x80                       /* Extended attribute        */
  94.                                         /* bit.                      */
  95. #define PSS 0x40                        /* Programmed Symbol         */
  96.                                         /* Set bit.                  */
  97. #define TIMEOUT  5000L                  /* semaphore timeout         */
  98.  
  99. /*********************************************************************/
  100. /******************* BEGIN STATIC VARIABLES    ***********************/
  101. /*********************************************************************/
  102.  
  103. unsigned char press_ent_msg[] =
  104. {
  105.   "\n\nPress ENTER to continue..."
  106. }
  107. ;
  108. unsigned char blank_screen[] =             /* Poor mans blank screen  */
  109. {
  110.  "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
  111.  
  112. }
  113. ;
  114. unsigned char dft_sess = NULL;            /* Session to write string  */
  115.                                           /* to and search from       */
  116. unsigned char host_text[] =
  117. {
  118.   "EHLLAPI"                               /* String to send to        */
  119. }                                         /* host and to search for   */
  120. ;
  121. unsigned char invis_text[] =
  122. {
  123.   "INVISIBLE WINDOW WRITE"                /* String to send to host   */
  124. }
  125. ;
  126. unsigned char home_key[] =
  127. {
  128.   "@0"                                    /* The Home Key             */
  129. }
  130. ;
  131. unsigned char setparm_text[] =
  132. {
  133.   "NOATTRB EAB XLATE"                    /* String used for set parms */
  134. }
  135. ;
  136. unsigned char test_name[ ] =
  137. {
  138.   "Sample_Test_Name"                    /* window title test name     */
  139. }
  140. ;
  141. unsigned char sf_test_str[] =           /* command string to create a */
  142. {                                       /* structured field           */
  143.   "IND$FILE PUT SF_TEST EXEC A@E"
  144. }
  145. ;
  146.  
  147. /******************** EHLLAPI variables *******************************/
  148.  
  149. unsigned int hfunc_num;                 /* EHLLAPI function number    */
  150.  
  151. unsigned char hdata_str[MAX_DATA_SIZE]; /* EHLLAPI data string        */
  152.  
  153. unsigned int hds_len;                   /* EHLLAPI data string length */
  154.  
  155. unsigned int hrc;                       /* EHLLAPI return code        */
  156.  
  157. /******************* structured field variables ***********************/
  158.  
  159. unsigned short int  sf_doid;            /* destination origin id      */
  160. unsigned char far * sf_buffer_address;  /* 4 byte pointer to buffer   */
  161. int        optimal_buffer_len;          /* optimal buffer length      */
  162. int        optimal_in_buffer_len;       /* optimal inbound buffer size*/
  163. int        optimal_out_buffer_len;      /* optimal outbound buffer size */
  164. unsigned char far * status_sem;         /* status notification semaph.*/
  165. unsigned char far * sf_asem;            /* 4 byte pointer to semaphore*/
  166. unsigned char far * read_buffer;        /* read buffer address        */
  167. unsigned char far * write_buffer;       /* write buffer address       */
  168.                                         /* DDM Base Type Query Reply  */
  169. char query_reply[12] = {0x00,0x0c,0x81,0x95,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x01};
  170.  
  171.  
  172.  
  173. /*******************************************************************/
  174. /*************************** BEGIN CODE ****************************/
  175. /*******************************************************************/
  176.  
  177.  
  178. /*******************************************************************/
  179. /* MAIN - Main code calls routines to do real work.                */
  180. /*                                                                 */
  181. /* INPUT                                                           */
  182. /*                                                                 */
  183. /* OUTPUT                                                          */
  184. /*                                                                 */
  185. /*                                                                 */
  186. /*******************************************************************/
  187. main(){                                         /* Entry from DOS. */
  188.  
  189.   unsigned int  rc;                     /* return code             */
  190.   char key = 'a' ;                      /* input character         */
  191.  
  192.   printf(blank_screen);                 /* Clear the screen        */
  193.   rc = disp_ehllapi_info();             /* Call routine to         */
  194.                                         /* display EHLLAPI info    */
  195.  
  196.   if (rc == 0){
  197.     printf(press_ent_msg);
  198.     fgetchar();                         /* Make user press ENTER   */
  199.     rc = disp_session_info();           /* Call routine to display */
  200.                                         /* Host session info       */
  201.   }
  202.  
  203.   if (rc == 0){
  204.  
  205.      if (dft_sess != NULL){              /* At least 1 dft session */
  206.  
  207.        printf(blank_screen);             /* Clear the screen.      */
  208.        printf("Press ENTER to send string '");
  209.        printf(host_text);
  210.        printf("' to session short name ");
  211.        fputchar(dft_sess);
  212.        printf ("...");
  213.        fgetchar();                       /* Make user press Enter  */
  214.  
  215.        rc = write_str_2_host(host_text); /* Call routine to write  */
  216.                                          /* string to host session */
  217.      }
  218.      else {
  219.  
  220.        printf("NO DFT SESSION SESSION STARTED.\n");
  221.        rc = 1;                           /* Get out of program     */
  222.      }
  223.   }
  224.  
  225.   if (rc == 0){
  226.  
  227.      printf("Press ENTER to search for string '");
  228.      printf(host_text);
  229.      printf("' on Host Presentation Space...");
  230.      fgetchar();                         /* Make user press Enter  */
  231.      rc = search_str_on_host();          /* Routine to search for  */
  232.                                          /* string on host session */
  233.   }
  234.  
  235.   if (rc == 0){
  236.  
  237.      printf("Press ENTER to display first 1920 bytes of Host presentation space...");
  238.      fgetchar();                         /* Make user press ENTER   */
  239.      rc = disp_host_scr();               /* Call routine to display */
  240.                                          /* Host session screen     */
  241.   }
  242.  
  243.   if (rc == 0){
  244.  
  245.      printf("Press ENTER to change the title of the presentation space...");
  246.      fgetchar();                        /* Make user press ENTER    */
  247.      rc = change_PS_window_name();      /* Call routine to          */
  248.                                         /* change window name       */
  249.   }
  250.  
  251.   if (rc == 0){
  252.  
  253.      printf("Press ENTER to change the switch list name...");
  254.      fgetchar();                        /* Make user press ENTER    */
  255.      rc = change_switch_list_LT_name(); /* Call routine to          */
  256.                                         /* change switch list name  */
  257.   }
  258.  
  259.   if (rc == 0){
  260.  
  261.      printf("Press ENTER to query the Presentation\
  262.  Manager window status...");
  263.      fgetchar();                         /* Make user press ENTER    */
  264.      printf(blank_screen);               /* Clear the screen         */
  265.      rc = query_PM_window_status();      /* Call routine to          */
  266.                                          /* query window status      */
  267.   }
  268.  
  269.   if (rc == 0){
  270.  
  271.      printf("Press ENTER to make the Presentation Manager window invisible...");
  272.     fgetchar();                           /* Make user press ENTER    */
  273.     rc = make_PM_window_invisible();      /* Call routine to make the */
  274.                                           /* PM window invisible      */
  275.   }
  276.  
  277.   if (rc == 0){
  278.  
  279.      printf("Press ENTER to send string '");
  280.      printf(invis_text);
  281.      printf("' to session short name ");
  282.      fputchar(dft_sess);
  283.      printf ("...");
  284.      fgetchar();                        /* Make user press ENTER      */
  285.      rc = write_str_2_host(invis_text); /* Call routine to write      */
  286.                                         /* string to host session     */
  287.   }
  288.  
  289.   if (rc == 0){
  290.  
  291.      printf("Press ENTER to display first 1920 bytes of Host presentation space...");
  292.      fgetchar();                       /* Make user press ENTER       */
  293.      rc = disp_host_scr();             /* Call routine to             */
  294.                                        /* display Host session screen */
  295.   }
  296.  
  297.   if (rc == 0){
  298.  
  299.      printf("Press ENTER to maximize the PM window and make it visible...");
  300.      fgetchar();                      /* Make user press ENTER        */
  301.      rc = make_PM_window_visible ();  /* Call routine to              */
  302.                                       /* make window visible          */
  303.   }
  304.  
  305.   if (rc == 0){
  306.  
  307.      printf("Press ENTER to disconnect from the Presentation Manager window...");
  308.      fgetchar();                          /* Make user press ENTER    */
  309.      rc = disconnect_PM_window_service(); /* Call routine to          */
  310.                                           /* disconnect PM window     */
  311.   }
  312.  
  313.   if (rc == 0){
  314.  
  315.      printf("Press ENTER to restore the PM window name, ");
  316.      printf("switch name, and window size...");
  317.      fgetchar();                          /* Make user press ENTER    */
  318.      rc = reset_switch_and_window_name(); /* Call routine to reset    */
  319.                                           /* window conditions        */
  320.   }
  321.  
  322.   if (rc == 0){
  323.  
  324.      printf("The sample program continues with structured field EHLLAPI calls.\n");
  325.      printf("The host session must be active and have access to\n");
  326.      printf("the IND$FILE file transfer application.\n");
  327.      printf("Do you wish to continue ? (y/n) \n");
  328.  
  329.      do {
  330.         key = getche();
  331.         }while ((key != 'Y') && (key != 'y') && (key != 'N') && (key != 'n'));
  332.   }
  333.  
  334.   if ((key == 'Y') || (key == 'y')){
  335.  
  336.      printf(blank_screen);
  337.      rc = reset_system();
  338.  
  339.      if (rc ==0) {
  340.         printf("Query The Communications Buffer Size.\n");
  341.         rc = query_com_buffer_size();
  342.      }
  343.  
  344.     if (rc == 0) {
  345.        printf("Allocate The Read Buffer.\n");
  346.        optimal_buffer_len = optimal_in_buffer_len;
  347.        rc = allocate_sf_buffer();
  348.        read_buffer = sf_buffer_address;
  349.     }
  350.  
  351.     if (rc == 0) {
  352.        printf("Allocate The Write Buffer.\n");
  353.        optimal_buffer_len = optimal_out_buffer_len;
  354.        rc = allocate_sf_buffer();
  355.        write_buffer =  sf_buffer_address;
  356.     }
  357.  
  358.     if (rc == 0) {
  359.        printf(press_ent_msg);
  360.        fgetchar();
  361.        printf(blank_screen);
  362.        printf("\nConnect To The Communications Buffer.\n");
  363.        rc = connect_structured_field();
  364.     }
  365.  
  366.     if (rc == 0) {
  367.        printf(press_ent_msg);
  368.        fgetchar();
  369.        printf("\nPerform An Asynchronus Read Structured Field.\n");
  370.        rc = read_sf_async();
  371.     }
  372.  
  373.  
  374.     if (rc == 0) {
  375.        printf(press_ent_msg);
  376.        fgetchar();
  377.        printf("\nCreating A Structured Field ...\n");
  378.        rc = create_a_structured_field();
  379.     }
  380.  
  381.     if (rc == 0) {
  382.        printf(press_ent_msg);
  383.        fgetchar();
  384.        printf("\nPerform a Get Asynchronus Completion Request.\n");
  385.        rc = get_completion_request();
  386.     }
  387.  
  388.     if (rc == 0) {
  389.        printf(press_ent_msg);
  390.        fgetchar();
  391.        printf("\nPerform Synchronus Write Structured Field.\n");
  392.        rc = write_sf_sync();
  393.     }
  394.  
  395.     if (rc == 0) {
  396.        printf(press_ent_msg);
  397.        fgetchar();
  398.        printf("\nReturn Communication Buffers To Memory.\n");
  399.        rc = free_com_buffers();
  400.     }
  401.  
  402.  
  403.     if (rc == 0) {
  404.        printf(press_ent_msg);
  405.        fgetchar();
  406.        printf("\nDisconnect From Structured Field Communications.\n");
  407.        rc = disconnect_structured_field();
  408.     }
  409.  
  410.   }
  411.  
  412.   if (rc == 0){
  413.  
  414.      printf( "\nSAMPLE PROGRAM DONE.  To Exit Program Press ENTER..." );
  415.      fgetchar();
  416.   }
  417. }
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424. /*********************************************************************/
  425. /* DISP_EHLLAPI_INFO - CALLs EHLLAPI QUERY_SYSTEM and then displays  */
  426. /*                     the requested info.                           */
  427. /*                                                                   */
  428. /*                                                                   */
  429. /*********************************************************************/
  430.  
  431. int disp_ehllapi_info(){
  432.  
  433.  
  434.   struct qsys_struct * data_ptr = (struct qsys_struct *)  hdata_str;
  435.                                         /* assign pointer            */
  436.                                         /* EHLLAPI data string.      */
  437.  
  438.   unsigned int rc = 0;                  /* return code               */
  439.  
  440.  
  441.   hfunc_num = HA_QUERY_SYSTEM;          /* Issue query system        */
  442.  
  443.   hllc(&hfunc_num, data_ptr, &hds_len, &hrc);     /* Call EHLLAPI    */
  444.  
  445.   if (hrc == HARC_SUCCESS){             /* If good rc                */
  446.  
  447.     printf("                       EHLLAPI INFORMATION\n\n");
  448.  
  449.     printf("  EHLLAPI version              : ");
  450.  
  451.     fputchar(data_ptr->qsys_hllapi_ver);
  452.  
  453.     printf("\n");
  454.  
  455.     printf("  EHLLAPI level                : ");
  456.  
  457.     fputchar(data_ptr->qsys_hllapi_lvl[0]);
  458.  
  459.     fputchar(data_ptr->qsys_hllapi_lvl[1]);
  460.  
  461.     printf("\n");
  462.  
  463.     printf("  EHLLAPI release date         : ");
  464.  
  465.     wrt_str(data_ptr->qsys_hllapi_date, 6);
  466.  
  467.     printf("\n");
  468.  
  469.     printf("  EHLLAPI LIM version          : ");
  470.  
  471.     fputchar(data_ptr->qsys_lim_ver);
  472.     printf("\n");
  473.  
  474.     printf("  EHLLAPI LIM level            : ");
  475.  
  476.     fputchar(data_ptr->qsys_lim_lvl[0]);
  477.  
  478.     fputchar(data_ptr->qsys_lim_lvl[1]);
  479.  
  480.     printf("\n");
  481.  
  482.     printf("  EHLLAPI hardware base        : ");
  483.  
  484.     fputchar(data_ptr->qsys_hardware_base);
  485.  
  486.     printf(" = ");
  487.  
  488.     if (data_ptr->qsys_hardware_base == 'Z'){
  489.  
  490.        printf("(See System model/submodel below)");
  491.  
  492.     }
  493.  
  494.     printf("\n");
  495.  
  496.     printf("  EHLLAPI CTRL program type    : ");
  497.  
  498.     fputchar(data_ptr->qsys_ctrl_prog_type);
  499.  
  500.     printf(" = ");
  501.  
  502.     if (data_ptr->qsys_ctrl_prog_type == 'X'){
  503.  
  504.       printf("OS/2");
  505.  
  506.     }
  507.  
  508.     printf("\n");
  509.  
  510.     printf("  EHLLAPI sequence number      : ");
  511.  
  512.     fputchar(data_ptr->qsys_seq_num[0]);
  513.  
  514.     fputchar(data_ptr->qsys_seq_num[1]);
  515.  
  516.     printf("\n");
  517.  
  518.     printf("  EHLLAPI CTRL program version : ");
  519.  
  520.     fputchar(data_ptr->qsys_ctrl_prog_ver[0]);
  521.  
  522.     fputchar(data_ptr->qsys_ctrl_prog_ver[1]);
  523.  
  524.     printf("\n");
  525.  
  526.     printf("  EHLLAPI PC session name      : ");
  527.  
  528.     fputchar(data_ptr->qsys_pc_sname);
  529.     printf("\n");
  530.  
  531.     printf("  EHLLAPI extended error 1     : ");
  532.  
  533.     wrt_str(data_ptr->qsys_err1, 4);
  534.     printf("\n");
  535.  
  536.     printf("  EHLLAPI extended error 2     : ");
  537.  
  538.     wrt_str(data_ptr->qsys_err2, 4);
  539.     printf("\n");
  540.  
  541.  
  542.     printf("  EHLLAPI system model/submodel: %02X%02X",
  543.          data_ptr->qsys_sys_model, data_ptr->qsys_sys_submodel);
  544.  
  545.     printf(" HEX  ");
  546.     if ((data_ptr->qsys_sys_model == 0xFC)
  547.        && (data_ptr->qsys_sys_submodel == 0x00)){
  548.  
  549.       printf("= Model PC AT");
  550.     }
  551.  
  552.     if ((data_ptr->qsys_sys_model == 0xFC)
  553.        && (data_ptr->qsys_sys_submodel == 0x01)){
  554.  
  555.       printf("= Model PC AT ENHANCED");
  556.     }
  557.  
  558.     if ((data_ptr->qsys_sys_model == 0xFC)
  559.        && (data_ptr->qsys_sys_submodel == 0x02)){
  560.  
  561.       printf("= Model PC XT Model 286");
  562.     }
  563.  
  564.     if ((data_ptr->qsys_sys_model == 0xFC)
  565.        && (data_ptr->qsys_sys_submodel == 0x04)){
  566.  
  567.       printf("= Model 50");
  568.     }
  569.  
  570.     if ((data_ptr->qsys_sys_model == 0xFC)
  571.        && (data_ptr->qsys_sys_submodel == 0x05)){
  572.  
  573.       printf("= Model 60");
  574.     }
  575.  
  576.     if ((data_ptr->qsys_sys_model == 0xF8)
  577.        && (data_ptr->qsys_sys_submodel == 0x00)){
  578.  
  579.       printf("= Model 80");
  580.     }
  581.  
  582.     if ((data_ptr->qsys_sys_model == 0xF8)
  583.        && (data_ptr->qsys_sys_submodel == 0x09)){
  584.  
  585.       printf("= Model 70");
  586.     }
  587.  
  588.     printf("\n");
  589.  
  590.     printf("  EHLLAPI National Language    : %d\n",
  591.          data_ptr->qsys_pc_nls);
  592.  
  593.     printf("  EHLLAPI monitor type         : ");
  594.  
  595.     fputchar(data_ptr->qsys_monitor_type);
  596.  
  597.     printf(" = ");
  598.     if (data_ptr->qsys_monitor_type == 'M'){
  599.  
  600.  
  601.       printf("PC MONOCHROME");
  602.     }
  603.  
  604.     if (data_ptr->qsys_monitor_type == 'C'){
  605.  
  606.       printf("PC CGA");
  607.     }
  608.  
  609.     if (data_ptr->qsys_monitor_type == 'E'){
  610.  
  611.       printf("PC EGA");
  612.     }
  613.  
  614.     if (data_ptr->qsys_monitor_type == 'A'){
  615.  
  616.       printf("PS MONOCHROME");
  617.     }
  618.  
  619.     if (data_ptr->qsys_monitor_type == 'V'){
  620.  
  621.       printf("PS 8512");
  622.     }
  623.  
  624.     if (data_ptr->qsys_monitor_type == 'H'){
  625.  
  626.       printf("PS 8514");
  627.     }
  628.  
  629.     if (data_ptr->qsys_monitor_type == 'U'){
  630.  
  631.       printf("UNKNOWN monitor type");
  632.     }
  633.     printf("\n");
  634.   }
  635.  
  636.   else  {                                 /* Bad return code         */
  637.  
  638.     rc = hrc;
  639.     error_hand(hfunc_num, rc);
  640.   }
  641.  
  642.   return(rc);
  643. }
  644.  
  645.  
  646.  
  647. /*********************************************************************/
  648. /* DISP_SESSION_INFO - CALLs EHLLAPI QUERY funtions and then displays*/
  649. /*                     the requested session info.                   */
  650. /*                                                                   */
  651. /*                                                                   */
  652. /*********************************************************************/
  653.  
  654. int disp_session_info(){                /* Routine to display        */
  655.                                         /* Host session info         */
  656.  
  657.  
  658.   struct qses_struct * data_ptr = (struct qses_struct *)
  659.        hdata_str;                       /* assign pointer            */
  660.                                         /* EHLLAPI data string.      */
  661.  
  662.   struct qsst_struct sess_stuc;         /* Query Session             */
  663.                                         /* structure.                */
  664.  
  665.   unsigned int i;                       /* Array index               */
  666.   unsigned int num_sess;                /* Number of session started */
  667.   unsigned int rc = 0;                  /* return code               */
  668.  
  669.   printf("\n\n\n\n\n\n\n\n\n\n\n\n");
  670.  
  671.   printf("                           SESSION INFO\n\n");
  672.  
  673.  
  674.   hfunc_num = HA_QUERY_SESSIONS;        /* Issue query sessions      */
  675.  
  676.   hds_len = MAX_DATA_SIZE / 12 * 12;    /* Make sure len is          */
  677.                                         /* multiple of 12            */
  678.  
  679.   hllc(&hfunc_num, data_ptr, &hds_len, &hrc);     /* Call EHLLAPI    */
  680.  
  681.  
  682.   if (hrc == HARC_SUCCESS){             /* If good rc                */
  683.  
  684.     num_sess = hds_len;                 /* Number of sessions started*/
  685.  
  686.     printf("Number of started sessions = %d\n\n\n", num_sess);
  687.  
  688.     for(i = 0;((i < num_sess) && (rc == 0)); i++)
  689.                                         /* LOOP thru queried sessions */
  690.     {
  691.       printf("Session number     : %d\n",i+1);
  692.       printf("Session Long name  : ");
  693.       wrt_str(data_ptr[i].qses_longname, 8);
  694.  
  695.       printf("\n");
  696.  
  697.       printf("Session Short name : ");
  698.       wrt_str(&data_ptr[i].qses_shortname, 1);
  699.  
  700.       printf("\n");
  701.  
  702.       printf("Session Type       : ");
  703.       wrt_str(&data_ptr[i].qses_sestype, 1);
  704.  
  705.       printf(" = ");
  706.       if (data_ptr[i].qses_sestype == 'H')
  707.  
  708.       {
  709.         printf("Host");
  710.  
  711.         if (dft_sess == NULL){          /* First HOST not set already  */
  712.  
  713.           dft_sess = data_ptr[i].qses_shortname; /* Set the session to */
  714.                                                  /*write string to     */
  715.         }
  716.       }
  717.       if (data_ptr[i].qses_sestype == 'P'){
  718.  
  719.          printf("PC");
  720.       }
  721.  
  722.       printf("\n");
  723.  
  724.       printf("Session PS size    : %d\n"
  725.            ,data_ptr[i].qses_pssize);
  726.  
  727.       hfunc_num = HA_QUERY_SESSION_STATUS;/* Issue query session status */
  728.  
  729.       hds_len = 18;                       /* Set length                 */
  730.  
  731.       sess_stuc.qsst_shortname = data_ptr[i].qses_shortname;
  732.                                         /* Set the session short name   */
  733.  
  734.       hllc(&hfunc_num, &sess_stuc, &hds_len, &hrc);
  735.  
  736.       if (hrc == HARC_SUCCESS){         /* If good rc                   */
  737.  
  738.         printf("Session PS rows    : %d\n"
  739.              ,sess_stuc.qsst_ps_rows);
  740.  
  741.         printf("Session PS columns : %d\n"
  742.              ,sess_stuc.qsst_ps_cols);
  743.  
  744.         printf("Session type 2     : ");
  745.  
  746.         wrt_str(&sess_stuc.qsst_sestype, 1);
  747.  
  748.         printf(" = ");
  749.         if (sess_stuc.qsst_sestype == 'F'){
  750.  
  751.           printf("5250");
  752.         }
  753.  
  754.         if (sess_stuc.qsst_sestype == 'G'){
  755.  
  756.           printf("5250 Printer Session");
  757.         }
  758.  
  759.         if (sess_stuc.qsst_sestype == 'D'){
  760.  
  761.           printf("DFT Host");
  762.         }
  763.  
  764.         if (sess_stuc.qsst_sestype == 'P'){
  765.  
  766.           printf("PC");
  767.         }
  768.  
  769.         printf("\n");
  770.  
  771.         printf("Session supports Extended attributes (EABs)? : ");
  772.  
  773.         if (sess_stuc.qsst_char & EABS){   /* if eabs on.             */
  774.  
  775.           printf("YES\n");
  776.         }
  777.  
  778.         else                              /* no eabs                  */
  779.  
  780.         {
  781.           printf("NO\n");
  782.         }
  783.  
  784.         printf("Session supports Program Symbols (PSS)?      : ");
  785.  
  786.         if (sess_stuc.qsst_char & PSS){ /* if programmed symbol set on */
  787.  
  788.           printf("YES\n");
  789.         }
  790.  
  791.         else                            /* no PSS                    */
  792.  
  793.         {
  794.           printf("NO\n");
  795.  
  796.         }
  797.         printf(press_ent_msg);
  798.         fgetchar();                     /* Make user press           */
  799.                                         /* ENTER.                    */
  800.       }
  801.  
  802.       else                              /* Bad return code           */
  803.  
  804.       {
  805.         rc = hrc;
  806.         error_hand(hfunc_num, rc);
  807.       }
  808.     }
  809.  
  810.   }
  811.  
  812.   else                                  /* Bad return code           */
  813.  
  814.   {
  815.     rc = hrc;
  816.     error_hand(hfunc_num, rc);
  817.   }
  818.  
  819.   return(rc);
  820.  
  821. }
  822.  
  823.  
  824.  
  825.  
  826.  
  827. /*********************************************************************/
  828. /* WRITE_STR_2_HOST  - Connects to first session and writes home_key */
  829. /*                     and string to host                            */
  830. /*                                                                   */
  831. /*                                                                   */
  832. /*********************************************************************/
  833.  
  834. int write_str_2_host(char  *in_str)     /* Call routine to           */
  835.                                         /* write string to host      */
  836. {
  837.  
  838.   unsigned int rc = 0;                  /* return code               */
  839.   hdata_str[0] = dft_sess;              /* Set session id for connect*/
  840.  
  841.   hfunc_num = HA_CONNECT_PS;            /* Issue Connect             */
  842.                                         /* Presentation Space        */
  843.  
  844.   hllc(&hfunc_num, hdata_str, &hds_len, &hrc);
  845.                                         /* Call EHLLAPI              */
  846.  
  847.   if (hrc == HARC_SUCCESS){             /* If good return code       */
  848.  
  849.     hfunc_num = HA_SENDKEY;             /* Issue sendkey             */
  850.  
  851.     strcpy(hdata_str, home_key);        /* String to send to Host    */
  852.  
  853.     hds_len = sizeof(home_key) - 1;     /* Set length of string      */
  854.                                         /* minus null character      */
  855.  
  856.     hllc(&hfunc_num, hdata_str, &hds_len, &hrc);
  857.                                         /* Call EHLLAPI              */
  858.  
  859.     if (hrc == HARC_SUCCESS){           /* If good return code       */
  860.  
  861.        hfunc_num = HA_SENDKEY;          /* Issue sendkey             */
  862.  
  863.        strcpy(hdata_str,in_str);        /* String to send to Host    */
  864.  
  865.        hds_len = strlen(in_str) ;       /* Set length of string      */
  866.                                         /* minus null character      */
  867.  
  868.        hllc(&hfunc_num, hdata_str, &hds_len, &hrc);
  869.                                         /* Call EHLLAPI              */
  870.  
  871.        if (hrc == HARC_SUCCESS){        /* If good return code       */
  872.  
  873.         printf ("Sent String to Host.\n\n\n");
  874.       }
  875.  
  876.       else                              /* Bad return code           */
  877.       {
  878.         rc = hrc;                       /* Set return code           */
  879.         error_hand(hfunc_num, rc);
  880.       }
  881.  
  882.     }
  883.     else
  884.     {
  885.  
  886.       rc = hrc;                         /* Set return code           */
  887.       error_hand(hfunc_num, rc);
  888.     }
  889.   }
  890.   else
  891.   {
  892.  
  893.     rc = hrc;                           /* Set return code           */
  894.     error_hand(hfunc_num, rc);
  895.   }
  896.   return(rc);
  897.  
  898. }
  899.  
  900.  
  901.  
  902.  
  903.  
  904. /*********************************************************************/
  905. /* SEARCH_STR_ON_HOST- Searches for string on host.                  */
  906. /*                                                                   */
  907. /*                                                                   */
  908. /*********************************************************************/
  909.  
  910. int search_str_on_host(){               /* Routine to search for     */
  911.                                         /* string on host session    */
  912.  
  913.   unsigned int rc = 0;                  /* return code               */
  914.  
  915.   hfunc_num = HA_SEARCH_PS;             /* Issue search PS           */
  916.  
  917.   strcpy(hdata_str, host_text);      /* String to search for on host */
  918.  
  919.   hds_len = sizeof(host_text) - 1;      /* Set length of string      */
  920.                                         /* minus null character      */
  921.  
  922.   hllc(&hfunc_num, hdata_str, &hds_len, &hrc);
  923.                                         /* Call EHLLAPI              */
  924.  
  925.   if (hrc == HARC_SUCCESS){             /* If good return code       */
  926.  
  927.     printf("Found string '");
  928.     printf(host_text);
  929.     printf("' at PS position %d.\n",hds_len);
  930.     printf("(press CONTROL-ESCAPE to verify)\n\n\n");
  931.   }
  932.  
  933.   else
  934.  
  935.   {
  936.     rc = hrc;                           /* Set return code           */
  937.     error_hand(hfunc_num, rc);
  938.   }
  939.   return(rc);
  940.  
  941. }
  942.  
  943.  
  944.  
  945. /*********************************************************************/
  946. /* DISP_HOST_SCR - Displays first 1920 bytes of host screen.         */
  947. /*                                                                   */
  948. /*                                                                   */
  949. /*********************************************************************/
  950.  
  951. int disp_host_scr()                     /* Routine to display        */
  952.                                         /* host screen               */
  953.  
  954. {
  955.   unsigned int rc = 0;                  /* return code               */
  956.  
  957.   hfunc_num = HA_SET_SESSION_PARMS;     /* Issue Set session Parms   */
  958.  
  959.   hds_len = sizeof(setparm_text) - 1;   /* Copy the first 1920 bytes */
  960.                                         /* of presentation space     */
  961.  
  962.   hllc(&hfunc_num, setparm_text, &hds_len, &hrc);
  963.                                         /* Call EHLLAPI              */
  964.  
  965.   if (hrc == HARC_SUCCESS){             /* If good return code       */
  966.  
  967.  
  968.      hfunc_num = HA_COPY_PS_TO_STR;     /* Issue Copy PS to string   */
  969.  
  970.      hds_len = MAX_DATA_SIZE;           /* Copy the first 1920 bytes */
  971.                                         /* of presentation space     */
  972.  
  973.      hrc = 1;                           /* Set PS position to        */
  974.                                         /* top,left corner           */
  975.  
  976.      hllc(&hfunc_num, hdata_str, &hds_len, &hrc);
  977.                                         /* Call EHLLAPI              */
  978.      if (hrc == HARC_SUCCESS){          /* If good return code       */
  979.  
  980.       VIOWRTCELLSTR (hdata_str, MAX_DATA_SIZE, 0, 0, 0);
  981.                                         /* Write the string in color */
  982.  
  983.     }
  984.     else                                /* Bad return code           */
  985.     {
  986.       rc = hrc;                         /* Set return code           */
  987.       error_hand(hfunc_num, rc);
  988.     }
  989.  
  990.   }
  991.   else                                  /* Bad return code           */
  992.   {
  993.     rc = hrc;                           /* Set return code           */
  994.     error_hand(hfunc_num, rc);
  995.   }
  996.  
  997.   return(rc);
  998.  
  999. }
  1000.  
  1001.  
  1002.  
  1003.  
  1004. /*********************************************************************/
  1005. /* WRT_STR - Writes char sting to standard output.                   */
  1006. /*                                                                   */
  1007. /* INPUT                                                             */
  1008. /*                                                                   */
  1009. /* OUTPUT                                                            */
  1010. /*                                                                   */
  1011. /*********************************************************************/
  1012.  
  1013. wrt_str(text_ptr, x)                    /* Prints x number of        */
  1014.                                         /* characters                */
  1015. unsigned char * text_ptr;               /* Pointer to string         */
  1016.                                         /* to write                  */
  1017. unsigned int x;                         /* Number of bytes in string */
  1018.  
  1019. {
  1020.   unsigned int i;                       /* counter                   */
  1021.  
  1022.   for (i = 0; i < x; i++)
  1023.   {
  1024.     fputchar(text_ptr[i]);
  1025.  
  1026.   }
  1027. }
  1028.  
  1029.  
  1030.  
  1031.  
  1032. /*******************************************************************/
  1033. /*  QUERY_PM_WINDOW_STATUS - Query PM window status information    */
  1034. /*                                                                 */
  1035. /*                                                                 */
  1036. /*                                                                 */
  1037. /*******************************************************************/
  1038.  
  1039. int query_PM_window_status()
  1040. {
  1041.         int rc = 0;                          /* return code        */
  1042.         struct stpm_struct connect_struct ;
  1043.         struct cwin_struct status_struct;
  1044.  
  1045.         connect_struct.stpm_shortname = dft_sess; /* setsession id */
  1046.  
  1047.         hfunc_num = HA_CONNECT_PM_SRVCS;     /* issue connect      */
  1048.                                              /* presentation space */
  1049.  
  1050.         hllapi(&hfunc_num,(char far *)&connect_struct,&hds_len,&hrc);
  1051.  
  1052.         if (hrc == HARC_SUCCESS){            /* if return code good*/
  1053.  
  1054.             hfunc_num = HA_PM_WINDOW_STATUS ;/* choose PM window   */
  1055.                                              /* status function    */
  1056.             status_struct.cwin_shortname = dft_sess;
  1057.             status_struct.cwin_option = 0x2;
  1058.             hllapi(&hfunc_num,(char far *)&status_struct,&hds_len,&hrc);
  1059.  
  1060.         }
  1061.  
  1062.         if (hrc == HARC_SUCCESS){
  1063.  
  1064.             printf("                     PM WINDOW STATUS\n\n" );
  1065.  
  1066.             if (status_struct.cwin_flags & 0x0008)
  1067.                 printf(" STATUS  :     The window is visible. \n" );
  1068.  
  1069.             if (status_struct.cwin_flags & 0x0010)
  1070.                 printf(" STATUS  :     The window is invisible. \n" );
  1071.  
  1072.             if (status_struct.cwin_flags & 0x0080)
  1073.                 printf(" STATUS  :     The window is activated. \n" );
  1074.  
  1075.             if (status_struct.cwin_flags & 0x0100)
  1076.                 printf(" STATUS  :     The window is deactivated. \n" );
  1077.  
  1078.             if (status_struct.cwin_flags & 0x0400)
  1079.                 printf(" STATUS  :     The window is minimized. \n" );
  1080.  
  1081.             if (status_struct.cwin_flags & 0x0800)
  1082.                 printf(" STATUS  :     The window is maximized. \n" );
  1083.  
  1084.             printf("\n\n");
  1085.  
  1086.         }
  1087.  
  1088.         if (hrc == HARC_SUCCESS){
  1089.  
  1090.             rc = query_window_coords();
  1091.         }
  1092.  
  1093.         else
  1094.  
  1095.         {
  1096.           rc = hrc;
  1097.           error_hand(hfunc_num,rc);
  1098.         }
  1099.  
  1100.         return (rc);
  1101. }
  1102.  
  1103.  
  1104.  
  1105.  
  1106. /************************************************************************/
  1107. /*  QUERY_PM_WINDOW_COORDS - Query PM window coordinates in pells       */
  1108. /*                                                                      */
  1109. /*                                                                      */
  1110. /*                                                                      */
  1111. /************************************************************************/
  1112.  
  1113. int query_window_coords()
  1114. {
  1115.  
  1116.         struct gcor_struct window_struct;
  1117.  
  1118.         int rc = 0;
  1119.  
  1120.         hfunc_num = HA_QUERY_WINDOW_COORDS;      /*  select query       */
  1121.         hrc = rc;                                /*  window coordinates */
  1122.  
  1123.         window_struct.gcor_shortname = dft_sess;
  1124.         hllc(&hfunc_num,(char far*)&window_struct,&hds_len,&hrc);  /* call Ehllapi */
  1125.  
  1126.  
  1127.         if (hrc == HARC_SUCCESS){
  1128.  
  1129.             printf("                  PM WINDOW COORDINATES\n\n");
  1130.             printf(" XLEFT    :     %lx \n",window_struct.gcor_xLeft);
  1131.             printf(" YBOTTOM  :     %lx \n",window_struct.gcor_yBottom);
  1132.             printf(" XRIGHT   :     %lx \n",window_struct.gcor_xRight);
  1133.             printf(" YTOP     :     %lx \n",window_struct.gcor_yTop);
  1134.             printf("\n");
  1135.             printf("(press CONTROL-ESCAPE to verify)\n\n\n");
  1136.         }
  1137.  
  1138.         else  {
  1139.  
  1140.             error_hand(hfunc_num,hrc);
  1141.         }
  1142.  
  1143.         return (rc);
  1144. }
  1145.  
  1146.  
  1147.  
  1148. /***********************************************************************/
  1149. /* MAKE_PM_WINDOW_INVISIBLE - Make the PM window invisible             */
  1150. /*                                                                     */
  1151. /*                                                                     */
  1152. /*                                                                     */
  1153. /***********************************************************************/
  1154.  
  1155. int make_PM_window_invisible()
  1156. {
  1157.         unsigned int rc = 0;                            /* return code */
  1158.         struct cwin_struct data_struct;
  1159.  
  1160.         hdata_str[0] = dft_sess;          /* setsession id to connect  */
  1161.  
  1162.         hfunc_num = HA_CONNECT_PM_SRVCS;  /* issue connect pm services */
  1163.  
  1164.         hllapi(&hfunc_num,hdata_str,&hds_len,&hrc);   /* call Ehllapi  */
  1165.  
  1166.         if (hrc == HARC_SUCCESS){         /* if return code good       */
  1167.                                           /* connection was successful */
  1168.  
  1169.            hfunc_num = HA_PM_WINDOW_STATUS ;/* choose PM window        */
  1170.                                             /* status function         */
  1171.            data_struct.cwin_shortname = dft_sess;
  1172.            data_struct.cwin_option = 0x1;
  1173.            data_struct.cwin_flags = 0x0010;
  1174.  
  1175.            hllapi(&hfunc_num,(char far *)&data_struct,&hds_len,&hrc);
  1176.         }
  1177.  
  1178.         if (hrc == HARC_SUCCESS){
  1179.  
  1180.             printf("The PM window is now invisible. \n" );
  1181.             printf("(press CONTROL-ESCAPE to verify)\n\n\n");
  1182.         }
  1183.  
  1184.         else {
  1185.  
  1186.             rc = hrc;                    /* make PM window invisible   */
  1187.             error_hand(hfunc_num,rc);    /* unsuccessful               */
  1188.         }
  1189.  
  1190.         return (rc);
  1191. }
  1192.  
  1193.  
  1194.  
  1195.  
  1196. /***********************************************************************/
  1197. /* MAKE_PM_WINDOW_VISIBLE - make the PM window visible and             */
  1198. /*                                      maximimize it                  */
  1199. /*                                                                     */
  1200. /*                                                                     */
  1201. /***********************************************************************/
  1202.  
  1203. int make_PM_window_visible()
  1204. {
  1205.         unsigned int rc = 0;                /* return code             */
  1206.         struct cwin_struct data_struct;     /* local data string       */
  1207.  
  1208.         hdata_str[0] = dft_sess;            /* setsession id to connect*/
  1209.  
  1210.         hfunc_num = HA_CONNECT_PM_SRVCS;    /* issue connect pm services*/
  1211.  
  1212.         hllapi(&hfunc_num,hdata_str,&hds_len,&hrc); /* call Ehllapi    */
  1213.  
  1214.         if (hrc == HARC_SUCCESS){          /* if return code good,     */
  1215.                                            /* connection was successful*/
  1216.  
  1217.           hfunc_num = HA_PM_WINDOW_STATUS ;/* choose PM window         */
  1218.                                            /* status function          */
  1219.           data_struct.cwin_shortname = dft_sess;
  1220.           data_struct.cwin_option = 0x1;
  1221.           data_struct.cwin_flags = 0x0808;
  1222.  
  1223.           hllapi(&hfunc_num,(char far*)&data_struct,&hds_len,&hrc);
  1224.         }
  1225.  
  1226.         if (hrc == HARC_SUCCESS){
  1227.  
  1228.             printf("The PM window is now visible and maximized. \n");
  1229.             printf("(press CONTROL-ESCAPE to verify)\n\n\n");
  1230.         }
  1231.         else {
  1232.  
  1233.             rc = hrc;                        /* make PM window visible */
  1234.             error_hand(hfunc_num,rc);        /* was unsuccessful       */
  1235.         }
  1236.  
  1237.         return (rc);
  1238. }
  1239.  
  1240.  
  1241.  
  1242. /***********************************************************************/
  1243. /*  CHANGE_PS_WINDOW_NAME - Change the presentation space window name  */
  1244. /*                                                                     */
  1245. /*                                                                     */
  1246. /*                                                                     */
  1247. /***********************************************************************/
  1248.  
  1249. int change_PS_window_name()
  1250. {
  1251.  
  1252.         unsigned int rc = 0;              /* return code               */
  1253.         struct chlt_struct data_struct;   /* local data structure      */
  1254.  
  1255.         hfunc_num = HA_CONNECT_PM_SRVCS;  /* issue connect pm services */
  1256.         hdata_str[0] = dft_sess;
  1257.         hllapi(&hfunc_num,hdata_str,&hds_len,&hrc); /* call Ehllapi    */
  1258.  
  1259.         if (hrc == HARC_SUCCESS){         /* if return code good       */
  1260.  
  1261.            hfunc_num = HA_CHANGE_WINDOW_NAME;
  1262.                                           /* change window name func   */
  1263.            data_struct.chlt_shortname = dft_sess;
  1264.            data_struct.chlt_option = 0x1;
  1265.            strcpy(data_struct.chlt_ltname,test_name);
  1266.            hds_len = sizeof(test_name);   /* calculate length of new   */
  1267.                                           /* window title name         */
  1268.            hds_len +=2;                   /* len of str sent to Ehllapi*/
  1269.  
  1270.            hllapi(&hfunc_num,(char far*)&data_struct,&hds_len,&hrc);
  1271.         }
  1272.  
  1273.         if (hrc == HARC_SUCCESS){
  1274.  
  1275.            printf("Window Title Changed.\n" );
  1276.            printf("(press CONTROL-ESCAPE to verify)\n\n\n");
  1277.         }
  1278.  
  1279.         else {
  1280.  
  1281.            rc = hrc;                            /* window title change */
  1282.            error_hand(hfunc_num,rc);            /* was unsuccessful    */
  1283.         }
  1284.  
  1285.         return (rc);
  1286. }
  1287.  
  1288.  
  1289.  
  1290. /***********************************************************************/
  1291. /*  CHANGE_SWITCH_LIST_LT_NAME - Change The Switch List LT Name        */
  1292. /*                                        LT - logical terminal        */
  1293. /*                                                                     */
  1294. /*                                                                     */
  1295. /***********************************************************************/
  1296.  
  1297. int change_switch_list_LT_name()
  1298. {
  1299.         unsigned int rc = 0;                /* return code             */
  1300.         struct chsw_struct data_struct;     /* local data structure    */
  1301.  
  1302.         hfunc_num = HA_CONNECT_PM_SRVCS;    /* issue connect pm services*/
  1303.         hdata_str[0] = dft_sess;
  1304.         hllapi(&hfunc_num,hdata_str,&hds_len,&hrc);    /* call Ehllapi */
  1305.  
  1306.         if (hrc == HARC_SUCCESS) {        /* if return code good,      */
  1307.                                           /* connection was successful */
  1308.  
  1309.            hfunc_num = HA_CHANGE_SWITCH_NAME ;
  1310.                                           /* choose change switch list */
  1311.                                           /* LT name function          */
  1312.  
  1313.            data_struct.chsw_shortname = dft_sess;
  1314.            data_struct.chsw_option = 0x1;
  1315.            strcpy(data_struct.chsw_swname,test_name);
  1316.  
  1317.            hds_len = sizeof(test_name)  ; /* calc length of new switch */
  1318.                                           /* list name                 */
  1319.  
  1320.            hds_len +=2;            /* length of string sent to Ehllapi */
  1321.  
  1322.            hllapi(&hfunc_num,(char far*)&data_struct,&hds_len,&hrc);
  1323.  
  1324.          }
  1325.          if (hrc == HARC_SUCCESS){
  1326.  
  1327.              printf("Switch List Name Changed.\n" );
  1328.              printf("(press CONTROL-ESCAPE to verify)\n\n\n");
  1329.          }
  1330.          else {
  1331.  
  1332.              rc = hrc;                  /* connection to presentation */
  1333.              error_hand(hfunc_num,rc);  /* space unsuccessful */
  1334.          }
  1335.  
  1336.         return (rc);
  1337. }
  1338.  
  1339.  
  1340.  
  1341. /***********************************************************************/
  1342. /*  DISCONNECT PM WINDOW SERVICE - disconnect from PM window session   */
  1343. /*                                                                     */
  1344. /*                                                                     */
  1345. /*                                                                     */
  1346. /***********************************************************************/
  1347.  
  1348. int disconnect_PM_window_service()
  1349. {
  1350.         unsigned int rc = 0;              /* return code               */
  1351.  
  1352.         hdata_str[0] = dft_sess;          /* setsession id to connect  */
  1353.  
  1354.         hfunc_num = HA_CONNECT_PM_SRVCS;  /* issue connect pm services */
  1355.  
  1356.         hllapi(&hfunc_num,hdata_str,&hds_len,&hrc);   /* call Ehllapi  */
  1357.  
  1358.         if (hrc == HARC_SUCCESS){         /* if return code good,      */
  1359.                                           /* connection was successful */
  1360.  
  1361.            hdata_str[0] = dft_sess;             /* session id          */
  1362.  
  1363.            hfunc_num = HA_DISCONNECT_PM_SRVCS ; /* choose disconnect   */
  1364.                                                 /* PM services function*/
  1365.  
  1366.            hllapi(&hfunc_num,hdata_str,&hds_len,&hrc); /* call Ehllapi */
  1367.          }
  1368.  
  1369.          if (hrc == HARC_SUCCESS)
  1370.  
  1371.              printf("PM window disconnected.\n\n\n" );
  1372.  
  1373.          else {
  1374.  
  1375.               rc = hrc;
  1376.               error_hand(hfunc_num,rc);
  1377.          }
  1378.  
  1379.          return (rc);
  1380. }
  1381.  
  1382.  
  1383.  
  1384.  
  1385. /***********************************************************************/
  1386. /*  RESET SWITCH AND WINDOW NAME - Reset the switch and window names   */
  1387. /*                                                                     */
  1388. /*                                                                     */
  1389. /*                                                                     */
  1390. /***********************************************************************/
  1391.  
  1392. int reset_switch_and_window_name(){
  1393.  
  1394.         unsigned int rc = 0;              /* return code               */
  1395.  
  1396.         struct chlt_struct window_struct; /* local data structures     */
  1397.         struct chsw_struct switch_struct;
  1398.         struct cwin_struct status_struct;
  1399.  
  1400.         hdata_str[0] = dft_sess;          /* setsession id to connect  */
  1401.  
  1402.         hfunc_num = HA_CONNECT_PM_SRVCS;  /* issue connect pm space    */
  1403.  
  1404.         hllapi(&hfunc_num,hdata_str,&hds_len,&hrc);   /* call Ehllapi  */
  1405.  
  1406.         if (hrc == HARC_SUCCESS){         /* if return code good,      */
  1407.                                           /* connection was successful */
  1408.  
  1409.            hfunc_num = HA_CHANGE_SWITCH_NAME ;
  1410.  
  1411.                                           /* choose change switch list */
  1412.                                           /* LT name function          */
  1413.  
  1414.           switch_struct.chsw_shortname = dft_sess;/* set input string to*/
  1415.                                                   /* reset switch name  */
  1416.           switch_struct.chsw_option = 0x02;
  1417.           hds_len = 2;
  1418.  
  1419.           hllapi(&hfunc_num,(char far *)&switch_struct,&hds_len,&hrc);
  1420.  
  1421.        }
  1422.  
  1423.        if (hrc == HARC_SUCCESS)
  1424.  
  1425.            printf("Switch List Name Reset.\n");
  1426.  
  1427.            if (hrc == HARC_SUCCESS)        /* if return code good,     */
  1428.                                            /* connection was sucessful */
  1429.               {
  1430.                hfunc_num = HA_CHANGE_WINDOW_NAME ;
  1431.  
  1432.                                            /* choose change switch     */
  1433.                                            /* list LT name function    */
  1434.                                            /* to reset window name     */
  1435.  
  1436.              window_struct.chlt_shortname = dft_sess;
  1437.              window_struct.chlt_option = 0x02;
  1438.              hds_len = 2;
  1439.  
  1440.              hllapi(&hfunc_num,(char far*)&window_struct,&hds_len,&hrc);
  1441.            }
  1442.  
  1443.            if (hrc == HARC_SUCCESS)
  1444.  
  1445.               printf("Window Name Reset.\n");
  1446.  
  1447.            if (hrc == HARC_SUCCESS){       /* if return code good,     */
  1448.                                            /* connection was successful*/
  1449.  
  1450.               hfunc_num = HA_PM_WINDOW_STATUS;
  1451.  
  1452.                                           /* set window status function*/
  1453.               status_struct.cwin_shortname = dft_sess;
  1454.                                           /* set input string  to      */
  1455.                                           /* restore the window size   */
  1456.               status_struct.cwin_option = 0x01;
  1457.               status_struct.cwin_flags= 0x1000;
  1458.  
  1459.  
  1460.               hllapi(&hfunc_num,(char far*)&status_struct,&hds_len,&hrc);
  1461.            }
  1462.  
  1463.            if (hrc == HARC_SUCCESS) {
  1464.  
  1465.                printf("Window Size Restored.\n" );
  1466.                printf("(press CONTROL-ESCAPE to verify)\n\n\n");
  1467.            }
  1468.  
  1469.            else {
  1470.  
  1471.                rc = hrc;                 /* connection to presentation */
  1472.                error_hand(hfunc_num,rc); /* was space unsuccessful     */
  1473.            }
  1474.  
  1475.            return (rc);
  1476. }
  1477.  
  1478.  
  1479. /***********************************************************************/
  1480. /*  RESET SYSTEM - Return Ehllapi to its initial conditions            */
  1481. /*                                                                     */
  1482. /*                                                                     */
  1483. /*                                                                     */
  1484. /***********************************************************************/
  1485.  
  1486. int reset_system(){
  1487.  
  1488.         unsigned int rc = 0;              /* return code               */
  1489.  
  1490.         hfunc_num = HA_RESET_SYSTEM;      /* issue connect pm services */
  1491.  
  1492.         hllapi(&hfunc_num,hdata_str,&hds_len,&hrc);  /* call Ehllapi   */
  1493.  
  1494.         if (hrc == HARC_SUCCESS){         /* if return code good,      */
  1495.  
  1496.             printf("Ehllapi Reset To Original Conditions. \n\n");
  1497.         }
  1498.         else {
  1499.  
  1500.             rc = hrc;                     /* return system error       */
  1501.             error_hand(hfunc_num,rc);
  1502.         }
  1503.  
  1504.         return (rc);
  1505. }
  1506.  
  1507.  
  1508.  
  1509.  
  1510. /***********************************************************************/
  1511. /*  CONNECT STRUCTURED FIELD - Connect to a Structured field           */
  1512. /*                                                                     */
  1513. /*                                                                     */
  1514. /*                                                                     */
  1515. /***********************************************************************/
  1516.  
  1517. int connect_structured_field(){
  1518.  
  1519.         struct stsf_struct *data_str;
  1520.  
  1521.         unsigned int rc = 0;                  /* return code           */
  1522.  
  1523.         data_str->stsf_shortname = dft_sess;  /* fill data string with */
  1524.                                               /* structured field      */
  1525.                                               /* input parameters      */
  1526.         data_str->stsf_query = (char far *) query_reply;
  1527.  
  1528.         hrc = rc;
  1529.         hds_len = 11;
  1530.  
  1531.         hfunc_num = HA_START_STRUCTURED_FLD;     /* issue start        */
  1532.                                                  /* structured field   */
  1533.         hllapi(&hfunc_num,(char far*)data_str,&hds_len,&hrc);
  1534.  
  1535.         if (hrc == HARC_SUCCESS){
  1536.  
  1537.            sf_doid  = data_str->stsf_doid;
  1538.            status_sem = data_str->stsf_asem;
  1539.            printf("Session Shortname      %c\n",dft_sess);
  1540.            printf("Destination/Origin ID: %x\n",sf_doid);
  1541.            printf("Structured Field Connect Initiated.\n\n");
  1542.         }
  1543.         else {
  1544.  
  1545.            rc = hrc;
  1546.            error_hand(hfunc_num,rc);
  1547.         }
  1548.  
  1549.         return (rc);
  1550. }
  1551.  
  1552.  
  1553.  
  1554. /***********************************************************************/
  1555. /*  QUERY COM BUFFER SIZE - Query Communications Buffer Size           */
  1556. /*                                                                     */
  1557. /*                                                                     */
  1558. /*                                                                     */
  1559. /***********************************************************************/
  1560.  
  1561. int query_com_buffer_size(){
  1562.  
  1563.      struct qbuf_struct  * data_str ;
  1564.      unsigned int rc = 0;                           /* return code     */
  1565.  
  1566.      hds_len = 9;
  1567.      data_str->qbuf_shortname =  dft_sess;
  1568.      printf("Session Shortname:  %c\n",data_str->qbuf_shortname);
  1569.      hfunc_num = HA_QUERY_BUFFER_SIZE;              /* issue query     */
  1570.                                                     /* buffer sizes    */
  1571.      hllapi(&hfunc_num,(char far*)data_str,&hds_len,&hrc);
  1572.  
  1573.      optimal_in_buffer_len = data_str->qbuf_opt_inbound;
  1574.      optimal_out_buffer_len = data_str->qbuf_opt_outbound;
  1575.  
  1576.      if (hrc == HARC_SUCCESS){
  1577.  
  1578. printf("Optimal Inbound Buffer Size:  %x\n",data_str->qbuf_opt_inbound);
  1579. printf("Maximum Inbound Buffer Size:  %x\n",data_str->qbuf_max_inbound);
  1580. printf("Optimal Outbound Buffer Size: %x\n",data_str->qbuf_opt_outbound);
  1581. printf("Maximum Outbound Buffer Size: %x\n",data_str->qbuf_max_outbound);
  1582. printf("Query Buffer Complete.\n\n");
  1583.  
  1584.      }
  1585.  
  1586.      else {
  1587.  
  1588.        rc = hrc;
  1589.        error_hand(hfunc_num,rc);
  1590.      }
  1591.  
  1592.      return (rc);
  1593. }
  1594.  
  1595.  
  1596.  
  1597.  
  1598. /***********************************************************************/
  1599. /*  ALLOCATE SF BUFFER - Allocate a Structured Field Buffer from the   */
  1600. /*                                  EHLLAPI Shared Memory              */
  1601. /*                                                                     */
  1602. /*                                                                     */
  1603. /***********************************************************************/
  1604.  
  1605. int allocate_sf_buffer(){
  1606.  
  1607.         struct abuf_struct  * data_str;
  1608.         int i;
  1609.         unsigned int rc = 0;                      /* return code       */
  1610.  
  1611.         hfunc_num = HA_ALLOCATE_COMMO_BUFF;       /* issue allocate    */
  1612.         hds_len =   6;                            /* structured field  */
  1613.         data_str->abuf_length  = optimal_buffer_len;
  1614.         data_str->abuf_address = 0L;
  1615.  
  1616.         printf("Buffer Length:   %x\n",data_str->abuf_length);
  1617.  
  1618.         hllapi(&hfunc_num,(char far *)data_str,&hds_len,&hrc);
  1619.  
  1620.         (char far *)sf_buffer_address = (char far *)data_str->abuf_address ;
  1621.  
  1622.         if (hrc == HARC_SUCCESS){
  1623.  
  1624.            printf("Buffer Address:  %lx\n",sf_buffer_address);
  1625.            printf("Allocate Buffer Complete.\n\n");
  1626.          }
  1627.          else {
  1628.  
  1629.            rc = hrc;
  1630.            error_hand(hfunc_num,rc);
  1631.         }
  1632.  
  1633.         return (rc);
  1634. }
  1635.  
  1636.  
  1637.  
  1638. /**********************************************************************/
  1639. /*  READ_SF_ASYNC - Read asynchronously from a structured field       */
  1640. /*                                                                    */
  1641. /*                                                                    */
  1642. /*                                                                    */
  1643. /**********************************************************************/
  1644.  
  1645. int read_sf_async()
  1646. {
  1647.         struct rdsf_struct *data_str;         /* pointer to structure */
  1648.         unsigned int rc = 0;                  /*   return code        */
  1649.         int i;
  1650.  
  1651.         hfunc_num = HA_READ_STRUCTURED_FLD;       /*    issue read    */
  1652.         hds_len = 14;                             /* structured field */
  1653.         data_str->rdsf_shortname  = dft_sess;
  1654.         data_str->rdsf_option = 'A';
  1655.         data_str->rdsf_doid   = sf_doid;
  1656.         data_str->rdsf_buffer =  read_buffer;
  1657.         data_str->rdsf_requestid = 0;
  1658.         data_str->rdsf_asem = 0L;
  1659.         for (i=0; i<5;i++){
  1660.           ((unsigned int far *) data_str->rdsf_buffer)[i] = 0x00;
  1661.         }
  1662.         ((unsigned int far *) data_str->rdsf_buffer)[2] = 0x0500;
  1663.  
  1664.         printf("Session Shortname:       %c\n",data_str->rdsf_shortname);
  1665.         printf("Control Option Selected: %c\n",data_str->rdsf_option);
  1666.         printf("Destination / Origin ID: %x\n",data_str->rdsf_doid);
  1667.  
  1668.         hllapi(&hfunc_num,(char far*)data_str,&hds_len,&hrc);
  1669.  
  1670.         if (hrc == HARC_INBOUND_DISABLED) {
  1671.                                           /* read succesful, the      */
  1672.                                           /* host is inbound disabled */
  1673.  
  1674.             sf_asem = data_str->rdsf_asem;
  1675.             printf("Semaphore Address:       %lx\n",(char far *)sf_asem);
  1676.             printf("Semaphore Contents:      %x\n",*(char far *)sf_asem);
  1677.             printf("Read SF Complete.\n\n");
  1678.         }
  1679.  
  1680.         else {
  1681.  
  1682.             rc = hrc;
  1683.             error_hand(hfunc_num,rc);
  1684.         }
  1685.  
  1686.         return (rc);
  1687. }
  1688.  
  1689.  
  1690.  
  1691.  
  1692. /************************************************************************/
  1693. /* CREATE A STRUCTURED FIELD - create a structured field using ind$file */
  1694. /*                                                                      */
  1695. /*                                                                      */
  1696. /************************************************************************/
  1697.  
  1698. int create_a_structured_field(){         /* Call routine to             */
  1699.                                          /* write string to host        */
  1700.  
  1701.     unsigned int rc = 0;                 /* return code                 */
  1702.  
  1703.     hdata_str[0] = dft_sess;             /* Set session id to connect   */
  1704.  
  1705.     hfunc_num = HA_CONNECT_PS;           /* Issue Connect to PS         */
  1706.  
  1707.     hllapi(&hfunc_num, hdata_str, &hds_len, &hrc);   /* Call EHLLAPI    */
  1708.  
  1709.     if (hrc == HARC_SUCCESS){
  1710.  
  1711.        hfunc_num = HA_SENDKEY;           /* Issue sendkey               */
  1712.  
  1713.        strcpy(hdata_str,home_key);       /* String to send to host      */
  1714.  
  1715.        hds_len = sizeof(home_key)-1;     /* Sub null char from length   */
  1716.  
  1717.        hllapi(&hfunc_num,hdata_str,&hds_len, &hrc);
  1718.     }
  1719.  
  1720.     if (hrc == HARC_SUCCESS) {
  1721.  
  1722.        hfunc_num = HA_SENDKEY;              /* Issue sendkey            */
  1723.  
  1724.        strcpy(hdata_str,sf_test_str);       /* String to send to Host   */
  1725.  
  1726.        hds_len = sizeof(sf_test_str) - 1;   /* Set length of string     */
  1727.                                             /* minus null charatcter    */
  1728.  
  1729.        hllapi(&hfunc_num, hdata_str, &hds_len, &hrc);   /* Call EHLLAPI */
  1730.     }
  1731.  
  1732.     if (hrc != HARC_SUCCESS)                 /* If bad return code      */
  1733.  
  1734.     {
  1735.  
  1736.        rc = hrc;                             /* Set return code         */
  1737.        error_hand(hfunc_num, rc);
  1738.  
  1739.     }
  1740.  
  1741.     return(rc);
  1742.  
  1743. }
  1744.  
  1745.  
  1746.  
  1747.  
  1748. /********************************************************************/
  1749. /*  GET COMPLETION REQUEST - Check if last asyncronus               */
  1750. /*                           process finished                       */
  1751. /*                                                                  */
  1752. /*                                                                  */
  1753. /********************************************************************/
  1754.  
  1755. int get_completion_request(){
  1756.  
  1757.      struct gcmp_struct data_str ;        /* disconnect data struct */
  1758.      unsigned int rc = 0;                 /* return code            */
  1759.  
  1760.      data_str.gcmp_shortname = dft_sess;  /* fill data string       */
  1761.                                           /* with completion request*/
  1762.                                           /* input parameters       */
  1763.      data_str.gcmp_option = 'W';
  1764.      data_str.gcmp_requestid = 0;
  1765.      data_str.gcmp_ret_functid = 0;
  1766.      data_str.gcmp_ret_datastr = 0L;
  1767.      data_str.gcmp_ret_length  = 0;
  1768.      data_str.gcmp_ret_retcode = 0;
  1769.      hds_len = 14;
  1770.  
  1771.      printf("Session Shortname:  %c\n",data_str.gcmp_shortname);
  1772.  
  1773.                                          /* wait for semaphore     */
  1774.                                          /* to clear               */
  1775.  
  1776.  
  1777.      hfunc_num = HA_GET_ASYNC_COMPLETION;
  1778.  
  1779.      hllapi(&hfunc_num,(char far*)&data_str,&hds_len,&hrc);
  1780.  
  1781.      if (hrc == HARC_SUCCESS){
  1782.  
  1783.         printf("Semaphore Address:  %lx\n",(char far *)sf_asem);
  1784.         printf("Semaphore Contents: %x\n",*(char far *)sf_asem);
  1785.         printf("Completion Request Successful.\n");
  1786.        }
  1787.  
  1788.       else {
  1789.  
  1790.         rc = hrc;
  1791.         error_hand(hfunc_num,rc);
  1792.      }
  1793.  
  1794.     return (rc);
  1795. }
  1796.  
  1797.  
  1798.  
  1799.  
  1800. /**********************************************************************/
  1801. /*  WRITE_SF_SYNC - Write synchronously to a structured field         */
  1802. /*                                                                    */
  1803. /*                                                                    */
  1804. /*                                                                    */
  1805. /**********************************************************************/
  1806.  
  1807. int write_sf_sync(){
  1808.  
  1809.     struct wrsf_struct *data_str;
  1810.     unsigned int rc = 0;                             /* return code   */
  1811.     int i;
  1812.  
  1813.     hfunc_num = HA_WRITE_STRUCTURED_FLD;          /*    issue write   */
  1814.     hds_len = 8;                                  /* structured field */
  1815.     data_str->wrsf_shortname  = dft_sess;
  1816.     data_str->wrsf_option = 'S';
  1817.     data_str->wrsf_doid   = sf_doid;
  1818.  
  1819.                                             /* fill buffer with zeros */
  1820.     data_str->wrsf_buffer =  write_buffer;
  1821.     for (i=0; i<0x500; i++) {
  1822.        ((char far *) data_str->wrsf_buffer)[i] = '\0';
  1823.     }
  1824.                                       /* fill structured field header */
  1825.     ((char far *)data_str->wrsf_buffer)[2]  = 0x05;
  1826.     ((char far *)data_str->wrsf_buffer)[9]  = 0x05;
  1827.     ((char far *)data_str->wrsf_buffer)[10] = 0xD0;
  1828.     ((char far *)data_str->wrsf_buffer)[12] = 0x09;
  1829.  
  1830.     printf("Session Shortname:       %c\n",data_str->wrsf_shortname);
  1831.     printf("Control Option Selected: %c\n",data_str->wrsf_option);
  1832.     printf("Destination / Origin ID: %x\n",data_str->wrsf_doid);
  1833.  
  1834.     hllapi(&hfunc_num,(char far*)data_str,&hds_len,&hrc);
  1835.  
  1836.     if (hrc == HARC_SUCCESS) {
  1837.  
  1838.        printf("Write Structured Field Complete.\n");
  1839.        DosSleep((long) TIMEOUT);                /* Allow time for   */
  1840.     }                                           /* host to complete */
  1841.                                                 /* response before  */
  1842.     else {                                      /* continuing       */
  1843.  
  1844.        rc = hrc;
  1845.        error_hand(hfunc_num,rc);
  1846.     }
  1847.  
  1848.     return (rc);
  1849. }
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855. /********************************************************************/
  1856. /*  FREE COMMUNICATIONS BUFFER - Return to the shared memory pool   */
  1857. /*                  the communications buffers no longer being used */
  1858. /*                                                                  */
  1859. /*                                                                  */
  1860. /********************************************************************/
  1861.  
  1862. int free_com_buffers(){
  1863.  
  1864.   struct fbuf_struct *data_str;
  1865.   unsigned int rc=0;
  1866.  
  1867.  
  1868.   hfunc_num = HA_FREE_COMMO_BUFF;
  1869.   hds_len = 6;
  1870.   data_str->fbuf_length = optimal_in_buffer_len;
  1871.   data_str->fbuf_address = read_buffer;
  1872.  
  1873.   hllapi(&hfunc_num,(char far*)data_str,&hds_len,&hrc);
  1874.  
  1875.   if (hrc == HARC_SUCCESS) {
  1876.  
  1877.     printf("Read Communications Buffer De-allocated.\n");
  1878.  
  1879.     hfunc_num = HA_FREE_COMMO_BUFF;
  1880.     hds_len = 6;
  1881.     data_str->fbuf_length = optimal_out_buffer_len;
  1882.     data_str->fbuf_address = write_buffer;
  1883.     hllapi(&hfunc_num,(char far*)data_str,&hds_len,&hrc);
  1884.   }
  1885.  
  1886.  if (hrc == HARC_SUCCESS)
  1887.  
  1888.     printf("Write Communications Buffer De-allocated.\n");
  1889.  
  1890.  else {
  1891.  
  1892.    rc = hrc;
  1893.    error_hand(hfunc_num,rc);
  1894.  }
  1895.  
  1896.  return(rc);
  1897. }
  1898.  
  1899.  
  1900.  
  1901.  
  1902. /***********************************************************************/
  1903. /*  DISCONNECT STRUCTURED FIELD - Disonnect to a Structured field      */
  1904. /*                                                                     */
  1905. /*                                                                     */
  1906. /*                                                                     */
  1907. /***********************************************************************/
  1908.  
  1909. int disconnect_structured_field(){
  1910.  
  1911.      struct spsf_struct *data_str ;          /* disconnect data struct */
  1912.      unsigned int rc = 0;                    /* return code            */
  1913.  
  1914.      data_str->spsf_shortname = dft_sess;    /* fill data string 2     */
  1915.                                              /* with structured field  */
  1916.                                              /* input parameters       */
  1917.      data_str->spsf_doid = sf_doid;
  1918.      hds_len = 3;
  1919.      hfunc_num = HA_STOP_STRUCTURED_FLD;           /* issue stop       */
  1920.                                                    /* structured field */
  1921.  
  1922.      printf("Short-Session Name:      %c\n",data_str->spsf_shortname);
  1923.      printf("Destination / Origin ID: %x\n",data_str->spsf_doid);
  1924.  
  1925.      hllapi(&hfunc_num,(char far*)data_str,&hds_len,&hrc);
  1926.  
  1927.      if (hrc == HARC_SUCCESS)
  1928.  
  1929.          printf("Structured Field Disconnected.\n\n");
  1930.  
  1931.      else {
  1932.  
  1933.          rc = hrc;
  1934.          error_hand(hfunc_num,rc);
  1935.      }
  1936.         return (rc);
  1937. }
  1938.  
  1939.  
  1940.  
  1941.  
  1942. /*********************************************************************/
  1943. /* ERROR_HAND - Error handler.                                       */
  1944. /*                                                                   */
  1945. /*********************************************************************/
  1946.  
  1947. int error_hand(func, rc)                /* Error handler.            */
  1948.  
  1949. unsigned int func;
  1950. unsigned int rc;
  1951. {
  1952.   printf("UNEXPECTED RETURN CODE %d from FUNCTION #%d.",rc,
  1953.        func);
  1954. }
  1955.  
  1956.