home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / HAPI.ZIP / HAPI / HAPI_C / HSMPLC32.C < prev    next >
C/C++ Source or Header  |  1991-12-04  |  72KB  |  2,009 lines

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