home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pc3270sa.zip / hllsmp / hllsmp.c next >
Text File  |  2002-02-28  |  13KB  |  374 lines

  1. /***************************************************************/
  2. /*                                                             */
  3. /*                      SAMPLE EHLLAPI PROGRAM                 */
  4. /*                                                             */
  5. /*    Author:  IBM                                             */
  6. /*    Date Written:  1996                                      */
  7. /*    For use with IBM Personal Communications/3270            */
  8. /*                                                             */
  9. /*    Certain VM/370 keywords used below may vary in function  */
  10. /*       depending on system configuration.  A host            */
  11. /*       presentation space size of 1920 is assumed.           */
  12. /*                                                             */
  13. /***************************************************************/
  14.  
  15. #include <windows.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include "hapi_c.h"                /* Get EHLLAPI include file  */
  19.  
  20. /*************************************************************/
  21. /*                                                           */
  22. /* You must set following systemid, userid, and password     */
  23. /* for your local vm system.                                 */
  24. /*                                                           */
  25. /*************************************************************/
  26.  
  27. #define systemid "systemid"
  28. #define userid   "userid"
  29. #define password "password"
  30.  
  31. #define PSID "a"
  32. #define PS_POS return_code
  33. #define DRV_NUM return_code
  34. #define CLEAR "@C"
  35. #define ENTER "@E"
  36.  
  37. /* External variables */
  38.  
  39.       void call_hllapi();
  40.       void send_keys();
  41.  
  42.       ULONG i;                       /* general counter */
  43.  
  44.       int    DRV_NUM;                /* for file transfer */
  45.       int    PS_POS;                 /* for PS search */
  46.       int    search_rc;
  47.  
  48.       int    function;               /* call parameters */
  49.       char data_string[30];
  50.       int    data_length;
  51.       int    return_code;
  52.  
  53.       int   expected_return_code;    /* check call result */
  54.  
  55.       char sf_string[47] =
  56.             {"autoexec.bat a:auto bat a (ascii crlf!"};
  57.  
  58.       char q_buffer[36];             /* for query system */
  59.       char blank_screen[] =          /* blank screen     */
  60.       {
  61.        "\n"
  62.       };
  63.  
  64. main()
  65. {
  66. /*************************************************************/
  67. /*  Reset EHLLAPI.                                           */
  68. /*************************************************************/
  69.       function = HA_RESET_SYSTEM;
  70.       expected_return_code = 0;
  71.       call_hllapi();
  72.  
  73. /*************************************************************/
  74. /*  Establish connection to the host presentation space.     */
  75. /*************************************************************/
  76.       function = HA_CONNECT_PS;
  77.       strcpy (data_string, PSID);
  78.       expected_return_code = 0;
  79.       call_hllapi();
  80.  
  81. /*************************************************************/
  82. /*  Send the system and user ids to the host.                */
  83. /*************************************************************/
  84.       strcpy (data_string, systemid);
  85.       strcat (data_string, " ");
  86.       strcat (data_string, userid);
  87.       strcat (data_string, ENTER);
  88.       data_length = strlen(data_string);
  89.       send_keys();
  90.  
  91. /*************************************************************/
  92. /*  Has CP asked for my password?  If not, wait for a host   */
  93. /*    update and check again.  Try this twice; if it still   */
  94. /*    hasn't asked, the system is either down or very slow.  */
  95. /*    In this case, just terminate.                          */
  96. /*************************************************************/
  97.       function = HA_SEARCH_PS;
  98.       strcpy (data_string, "Enter your password");
  99.       data_length = strlen(data_string);
  100.       expected_return_code = -1;
  101.       call_hllapi();
  102.  
  103.       if (return_code != 0)
  104.          {
  105.           function = HA_START_HOST_NOTIFY;
  106.           strcpy (data_string, "a   p           ");
  107.           expected_return_code = 0;
  108.           call_hllapi();
  109.  
  110.           function = HA_SET_SESSION_PARMS;
  111.           strcpy (data_string, "ipause");
  112.           data_length = strlen(data_string);
  113.           expected_return_code = 0;
  114.           call_hllapi();
  115.  
  116.           search_rc = 24;
  117.           i = 1;
  118.  
  119.           while ((i <= 2) && (search_rc != 0))
  120.              {
  121.               function = HA_PAUSE;
  122.               data_length = 10;
  123.               expected_return_code = -1;
  124.               call_hllapi();
  125.  
  126.               function = HA_QUERY_HOST_UPDATE;
  127.               strcpy (data_string, PSID);
  128.               expected_return_code = -1;
  129.               call_hllapi();
  130.  
  131.               function = HA_SEARCH_PS;
  132.               strcpy (data_string, "Enter your password");
  133.               data_length = strlen(data_string);
  134.               expected_return_code = -1;
  135.               call_hllapi();
  136.               search_rc = return_code;
  137.  
  138.               i = i + 1;
  139.              }
  140.  
  141.           if (search_rc != 0)
  142.              {
  143.               printf ("CP never asked for a password - ");
  144.               printf ("sample terminating\n");
  145.               exit(9);
  146.              }
  147.          }
  148.  
  149. /*************************************************************/
  150. /*  Stop host notification and reset 'pause'.                */
  151. /*************************************************************/
  152.       function = HA_STOP_HOST_NOTIFY;
  153.       strcpy (data_string, PSID);
  154.       expected_return_code = 0;
  155.       call_hllapi();
  156.  
  157.       function = HA_SET_SESSION_PARMS;
  158.       strcpy (data_string, "fpause");
  159.       data_length = strlen(data_string);
  160.       expected_return_code = 0;
  161.       call_hllapi();
  162.  
  163. /*************************************************************/
  164. /*  Send the password & enter.                               */
  165. /*************************************************************/
  166.       strcpy (data_string, password);
  167.       strcat (data_string, ENTER);
  168.       data_length = strlen(data_string);
  169.       send_keys();
  170.  
  171. /*************************************************************/
  172. /*  Keep clearing the host presentation space until the      */
  173. /*    ready prompt (Ready;) is found.                        */
  174. /*************************************************************/
  175.       function = HA_SET_SESSION_PARMS;
  176.       strcpy (data_string, "srchfrom");
  177.       data_length = strlen(data_string);
  178.       expected_return_code = 0;
  179.       call_hllapi();
  180.  
  181.       search_rc = 24;
  182.       while (search_rc != 0)
  183.          {
  184.           function = HA_SEARCH_PS;
  185.           strcpy (data_string, "MORE");
  186.           data_length = strlen(data_string);
  187.           PS_POS = 1900;
  188.           expected_return_code = -1;
  189.           call_hllapi();
  190.  
  191.           if (return_code == 0)
  192.              {
  193.               strcpy (data_string, CLEAR);
  194.               data_length = 2;
  195.               send_keys();
  196.              }
  197.  
  198.           function = HA_SEARCH_PS;
  199.           strcpy (data_string, "HOLDING");
  200.           data_length = strlen(data_string);
  201.           PS_POS = 1900;
  202.           expected_return_code = -1;
  203.           call_hllapi();
  204.  
  205.           if (return_code == 0)
  206.              {
  207.               strcpy (data_string, CLEAR);
  208.               data_length = 2;
  209.               send_keys();
  210.              }
  211.  
  212.           function = HA_SEARCH_PS;
  213.           strcpy (data_string, "Ready;");
  214.           data_length = strlen(data_string);
  215.           PS_POS = 1;
  216.           expected_return_code = -1;
  217.           call_hllapi();
  218.  
  219.           search_rc = return_code;
  220.          }
  221.  
  222.       function = HA_SET_SESSION_PARMS;
  223.       strcpy (data_string, "srchall");
  224.       data_length = strlen(data_string);
  225.       expected_return_code = 0;
  226.       call_hllapi();
  227.  
  228. /*************************************************************/
  229. /*  Set EOT mode on.                                         */
  230. /*************************************************************/
  231.       function = HA_SET_SESSION_PARMS;
  232.       strcpy (data_string, "streot eot=!");
  233.       data_length = strlen(data_string);
  234.       expected_return_code = 0;
  235.       call_hllapi();
  236.  
  237. /*************************************************************/
  238. /*  Block normal messages on VM.                             */
  239. /*************************************************************/
  240.       strcpy (data_string, "set msg off@E!");
  241.       send_keys();
  242.  
  243. /*************************************************************/
  244. /*  Prepare for file transfer by disconnecting from the      */
  245. /*    host presentation space.                               */
  246. /*************************************************************/
  247.       function = HA_DISCONNECT_PS;
  248.       expected_return_code = 0;
  249.       call_hllapi();
  250.  
  251. /*************************************************************/
  252. /*  Upload "autoexec.bat".                                   */
  253. /*************************************************************/
  254.       function = HA_SEND_FILE;
  255.       DRV_NUM = 4;
  256.       expected_return_code = 3;
  257.       strcpy (data_string, sf_string);
  258.       call_hllapi();
  259.  
  260. /*************************************************************/
  261. /*  Set EOT mode off.                                        */
  262. /*************************************************************/
  263.       function = HA_SET_SESSION_PARMS;
  264.       strcpy (data_string, "strlen");
  265.       data_length = strlen(data_string);
  266.       expected_return_code = 0;
  267.       call_hllapi();
  268.  
  269. /*************************************************************/
  270. /*  Reconnect to the host presentation space.                */
  271. /*************************************************************/
  272.       function = HA_CONNECT_PS;
  273.       strcpy (data_string, PSID);
  274.       expected_return_code = 0;
  275.       call_hllapi();
  276.  
  277. /*************************************************************/
  278. /*  Enable normal messages on VM.                            */
  279. /*************************************************************/
  280.       strcpy (data_string, "set msg on@E");
  281.       data_length = strlen(data_string);
  282.       send_keys();
  283.  
  284. /*************************************************************/
  285. /*  Wait for command to complete...                          */
  286. /*************************************************************/
  287.       function = HA_WAIT;
  288.       expected_return_code = 0;
  289.       call_hllapi();
  290.  
  291. /*************************************************************/
  292. /*  Execute filelist on the host.                            */
  293. /*************************************************************/
  294.       function = HA_COPY_STR_TO_PS;
  295.       strcpy (data_string, "filel");
  296.       data_length = strlen(data_string);
  297.       PS_POS = 1761;
  298.       expected_return_code = 0;
  299.       call_hllapi();
  300.  
  301.       strcpy (data_string, ENTER);
  302.       data_length = strlen(data_string);
  303.       send_keys();
  304.  
  305. /*************************************************************/
  306. /*  Wait for command to complete...                          */
  307. /*************************************************************/
  308.       function = HA_WAIT;
  309.       expected_return_code = 0;
  310.       call_hllapi();
  311.  
  312. /*************************************************************/
  313. /*  Did the file make it to the host?                        */
  314. /*************************************************************/
  315.       function = HA_SET_SESSION_PARMS;
  316.       strcpy (data_string, "srchfrom");
  317.       data_length = strlen(data_string);
  318.       expected_return_code = 0;
  319.       call_hllapi();
  320.  
  321.       function = HA_SEARCH_PS;
  322.       strcpy (data_string, "AUTO");
  323.       data_length = strlen(data_string);
  324.       PS_POS = 161;
  325.       expected_return_code = 0;
  326.       call_hllapi();
  327.  
  328. /*************************************************************/
  329. /*  Leave filelist.                                          */
  330. /*************************************************************/
  331.       strcpy (data_string, "@3");
  332.       data_length = strlen(data_string);
  333.       send_keys();
  334.       return(0);
  335. }
  336.  
  337.  
  338. void send_keys()
  339. /*************************************************************/
  340. /*  Common sendkey routine.                                  */
  341. /*************************************************************/
  342. {
  343.       function = HA_SENDKEY;
  344.       expected_return_code = 0;
  345.       call_hllapi();
  346. }
  347.  
  348. void call_hllapi()
  349. /*************************************************************/
  350. /*  Call the hllapi and verify the return code.              */
  351. /*************************************************************/
  352. {
  353.       hllapi (&function, data_string, &data_length, &return_code);
  354.  
  355.       if (return_code == 9 && function != HA_CONVERT_POS_ROW_COL)
  356.       {
  357.        function = HA_QUERY_SYSTEM;
  358.        hllapi (&function, q_buffer, &data_length, &return_code);
  359.        printf (blank_screen);
  360.        printf ("%s\n",q_buffer);
  361.        exit(9);
  362.       }
  363.  
  364.    if ((return_code != expected_return_code) &&
  365.        (expected_return_code != -1))
  366.       {
  367.        printf (blank_screen);             /* Clear the screen */
  368.        printf ("Function               %d\n", function);
  369.        printf ("Unexpected return code %d\n", return_code);
  370.        printf ("Expected return code   %d\n", expected_return_code);
  371.        printf ("Data string            %s\n", data_string);
  372.       }
  373. }
  374.