home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / sep91.zip / 9N09068A < prev    next >
Text File  |  1991-07-10  |  9KB  |  290 lines

  1. /******************************************************
  2.  * Listing 1  hc_api.c
  3.  *
  4.  * Functions to handle calls to HLLAPI.
  5.  *
  6.  *****************************************************/
  7.  
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <conio.h>
  11. #include "hc.h"
  12.  
  13. /*****************************************************
  14.  *
  15.  * connect_ps()  Connect presentation space.
  16.  *               Uses the PSID.
  17.  * return: 0 = successful
  18.  *         1 = invalid PSID
  19.  *         4 = successful, but host busy
  20.  *         5 = successful, but input inhibited
  21.  *         9 = system error
  22.  *         11= resource unavailable
  23.  *             (only under IBM Entry Level Emulator)
  24.  *
  25.  *****************************************************/
  26.  
  27. int connect_ps (void)
  28. {
  29.         char *api_str = "A";    /* IBM PC/3270  */
  30.         int api_len   = 1;      /* 1 is implied */
  31.         int api_retc  = 0;      /* return code */
  32.         int api_func  = 1;      /* connect pres space */
  33.         if (hllapi_level >=4)
  34.                 return (0);        /* simulated */
  35.         else if (hllapi_level == 1)
  36.                 *api_str = 'E';    /* IBM Entry Level */
  37.         else if (hllapi_level == 2)
  38.                 *api_str = 'B';    /* Attachmate */
  39.         else if (hllapi_level == 3)
  40.                 *api_str='1';      /* RabbitGATE */
  41.  
  42.         HLLC(&api_func, api_str, &api_len, &api_retc);
  43.  
  44.         return(api_retc);
  45. }
  46.  
  47. /*****************************************************
  48.  *
  49.  * send_key()  Send a string of keystrokes to the host
  50.  *
  51.  * return: 0 = successful
  52.  *         1 = not connected to a host session
  53.  *         2 = invalid parameter passed to HLLAPI
  54.  *         4 = host busy, not all keystrokes sent
  55.  *         5 = input inhibited or rejected
  56.  *         9 = system error
  57.  *
  58.  *****************************************************/
  59.  
  60. int send_key (char *keys)
  61. {
  62.         int api_len;            /* no. chars to send */
  63.         int api_retc  = 0;      /* return coded */
  64.         int api_func  = 3;      /* send key */
  65.         if (hllapi_level >=4) return (0);
  66.  
  67.         api_len = strlen(keys);
  68.  
  69.         HLLC(&api_func, keys, &api_len, &api_retc);
  70.  
  71.         return(api_retc);
  72. }
  73.  
  74. /*****************************************************
  75.  *
  76.  * copy_ps()  Copy presentation space to ps.
  77.  *
  78.  * return: 0 = successful
  79.  *         1 = not connected to a host session
  80.  *         4 = successful, waiting for host response
  81.  *         5 = successful, keyboard is locked
  82.  *         9 = system error
  83.  *
  84.  *****************************************************/
  85.  
  86. int copy_ps (char *ps)
  87. {
  88.         int api_len   = 0;      /* length implied */
  89.         int api_retc  = 0;      /* return code */
  90.         int api_func  = 5;      /* copy pres space */
  91.         if (hllapi_level >=4) return (0);
  92.  
  93.         HLLC(&api_func, ps, &api_len, &api_retc);
  94.  
  95.         return(api_retc);
  96.  
  97. }
  98.  
  99. /*****************************************************
  100.  *
  101.  * search_ps()  Search presentation space for first
  102.  *              occurance of str.
  103.  *
  104.  * If str_pos == 0, string not found, otherwise,
  105.  * str_pos is the offset of the string in the pres.
  106.  * space. First position in the pres. space is 1; not
  107.  * the C convention of 0.
  108.  *
  109.  * return: 0 = successful
  110.  *         1 = not connected to a host session
  111.  *         2 = error in specifying parameters
  112.  *         9 = system error
  113.  *
  114.  *****************************************************/
  115.  
  116. int search_ps(char *str, int *str_pos)
  117. {
  118.         int api_func = 6;     /* search pres. space */
  119.  
  120.         /* api_len contains length of search string on
  121.          * call; and position of string on return
  122.          */
  123.         int api_len;
  124.  
  125.         int api_retc = 0;       /* return code */
  126.         if (hllapi_level >=4) {
  127.                 *str_pos = 0;
  128.                 return (0);
  129.         }
  130.  
  131.         api_len = strlen(str);
  132.  
  133.         HLLC(&api_func, str, &api_len, &api_retc);
  134.  
  135.         /* 0 and 24 indicate successful execution of
  136.          * function
  137.          */
  138.         if (api_retc == 0 || api_retc == 24) {
  139.                 *str_pos = api_len;
  140.                 return(0);
  141.         }
  142.  
  143.         return(api_retc);
  144. }
  145.  
  146.  
  147. /*****************************************************
  148.  *
  149.  * reset()  Reset host connection and disconnect
  150.  *          presentation space.
  151.  *
  152.  * return: 0 = successful
  153.  *         9 = system error
  154.  *
  155.  *****************************************************/
  156.  
  157. int reset(void)
  158. {
  159.         char *api_str = "";     /* not required */
  160.         int api_len   = 0;      /* not required */
  161.         int api_retc  = 0;      /* return code */
  162.         int api_func  = 21;     /* reset system */
  163.         if (hllapi_level >=4) return (0);
  164.  
  165.         HLLC(&api_func, api_str, &api_len, &api_retc);
  166.  
  167.         return(api_retc);
  168. }
  169.  
  170.  
  171. /*****************************************************
  172.  *
  173.  * wait()  Wait until host is not busy, i.e., the
  174.  *         communication line is clear.
  175.  *
  176.  * return: 0 = system ready for input
  177.  *         1 = not connected to a host session
  178.  *         4 = timeout while waiting, system not ready
  179.  *             (1 minute by default)
  180.  *         5 = keyboard locked
  181.  *         9 = system error
  182.  *
  183.  *****************************************************/
  184.  
  185. int wait (void)
  186. {
  187.         char *api_str = "";     /* not required */
  188.         int api_len   = 0;      /* not required */
  189.         int api_retc  = 0;      /* return code */
  190.         int api_func  = 4;      /* wait */
  191.         if (hllapi_level >=4) return (0);
  192.  
  193.         HLLC(&api_func, api_str, &api_len, &api_retc);
  194.  
  195.         return(api_retc);
  196. }
  197.  
  198.  
  199. /*****************************************************
  200.  *
  201.  * dspy_cursor() Determine cursor position and display.
  202.  *
  203.  * Uses 2 HLLAPI calls: query cursor location (7) and
  204.  * convert cursor position (99).  Function 99 uses
  205.  * the PSID.
  206.  *
  207.  * return: 0 = successful
  208.  *         1 = session not connected
  209.  *         2 = invalid PSID or data string
  210.  *         9 = system error encountered
  211.  *
  212.  *****************************************************/
  213.  
  214. int dspy_cursor (void)
  215. {
  216.         /* query cursor location */
  217.         char api_str[3] = "";   /* not req for func 7;
  218.                                  * req for 99 */
  219.         int api_len     = 0;    /* not required */
  220.         int api_retc    = 0;    /* return code */
  221.         int api_func    = 7;    /* query cursor loc */
  222.         if (hllapi_level >=4) return (0);
  223.  
  224.         HLLC(&api_func, api_str, &api_len, &api_retc);
  225.  
  226.         if (api_retc != 0)
  227.                 return(api_retc);
  228.  
  229.         /* Convert cursor positon to row/column.  For
  230.          * function 99 the data string consists of
  231.          * the PSID and the letter P when converting
  232.          * from host pres space to row/column
  233.          */
  234.  
  235.         if (hllapi_level == 0)
  236.                 strcpy(api_str, "AP"); /* IBM PC/3270 */
  237.         else if (hllapi_level == 1)
  238.                 strcpy(api_str, "EP"); /* IBM Entry  */
  239.         else if (hllapi_level == 2)
  240.                 strcpy(api_str, "BP"); /* Attachmate */
  241.         else
  242.                 strcpy(api_str, "1P"); /* RabbitGATE */
  243.  
  244.         api_func = 99;          /* Convert position */
  245.         api_retc = api_len;     /* host pres. position
  246.                                  * passed in 4th parm
  247.                                  */
  248.  
  249.         HLLC(&api_func, api_str, &api_len, &api_retc);
  250.  
  251.         switch (api_retc) {
  252.                 case 0:    /* bad column or PS psn */
  253.                 case 9998: /* bad PSID or not con'd */
  254.                 case 9999:/* 2nd char not P or R */
  255.                         return (2);
  256.                 default:
  257.                         gotoxy(api_retc, api_len);
  258.         }
  259.         return (0);
  260. }
  261.  
  262.  
  263. /*****************************************************
  264.  *
  265.  * copy_oia() Copy the Operator Information Area to
  266.  *            api_str.
  267.  *
  268.  * Function must be called with pointer to at least
  269.  * 103 bytes--the length of the returned string.
  270.  *
  271.  *      0 = successful
  272.  *      1 = not connected to a host session
  273.  *      4 = host busy
  274.  *      5 = keyboard locked
  275.  *      9 = system error
  276.  *
  277.  *****************************************************/
  278.  
  279. int copy_oia (unsigned char *api_str)
  280. {
  281.         int api_len   = 103;    /* length of OIA str */
  282.         int api_retc  = 0;      /* return code */
  283.         int api_func  = 13;     /* Copy OIA */
  284.         if (hllapi_level >=4) return (0);
  285.  
  286.         HLLC(&api_func, api_str, &api_len, &api_retc);
  287.  
  288.         return(api_retc);
  289. }
  290.