[ Previous | Next | Contents | Search ]
3270 Host Connection Program 2.1 and 1.3.3 for AIX: Guide and Reference

Sample C HLLAPI Program

This sample program is part of the software offering for the HLLAPI function; it can be found in the /usr/lib/hcon/hllapi directory.

/******************************************************************/
/* FILE NAME: SAMPLE.C                                            */
/*                                                                */
/* MODULE NAME= SAMPLE.C                                          */
/*                                                                */
/* DESCRIPTIVE NAME=         C SAMPLE PROGRAM FOR HLLAPI          */
/*                                                                */
/*  Displays HLLAPI and session information.                      */
/*  Writes string to host.                                        */
/*  Searches for written string on host.                          */
/*  Displays host session screen.                                 */
/*                                                                */
/* COPYRIGHT:      XXXXXXXXX (C) COPYRIGHT IBM CORP.1992          */
/*                 LICENSED MATERIAL - PROGRAM PROPERTY OF IBM    */
/*                 ALL RIGHTS RESERVED                            */
/*                                                                */
/* NOTES=                                                         */
/*                                                                */
/*                                                                */
/*                                                                */
/*                                                                */
/*********************-END OF SPECIFICATIONS-**********************/
/******************************************************************/
/********************** BEGIN INCLUDE FILES ***********************/
/******************************************************************/
#include <stdio.h>
#include <string.h>
#include "hapi_c.h"                       /* Get HLLAPI include file*/
/******************************************************************/
/*************************** DEFINES ******************************/
/******************************************************************/
#define MAX_DATA_SIZE 1920    /* The maximum data   */
                                 /* size for this       */
                                  /* application.      */
#define EABS 0x80               /* Extended attribute   */
                               /* bit.    */
#define PSS 0x40                /* Programmed Symbol    */
                               /* Set bit.    */
/******************************************************************/
/******************** BEGIN STATIC VARIABLES **********************/
/******************************************************************/
unsigned char press_ent_msg[] = 
{
   "\n\nPress ENTER to continue..."
}
;
unsigned char blank_screen[] =  /* Poor mans blank screen */
{
   "\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"
}
;
unsigned char dft_sess = NULL;          /* Session to write str    */
                                /* to and search from    */
unsigned char host_text[] =
{
   "HLLAPI"                  /* String to send to    */
}                                /* host and to search for   */
;
unsigned char invis_text[] =
{
   "INVISIBLE WINDOW WRITE"           /* String to send to host   */
} 
;
unsigned char home_key[] =
{
   "@0"                      /* The Home Key    */
}
;
unsigned char setparm_text[] = 
{
   "NOATTRB NOEAB"          /* String used for set parms*/
}
;
/******************* HLLAPI variables *****************************/
unsigned int hfunc_num;       /* HLLAPI function number    */
unsigned char hdata_str[MAX_DATA_SIZE];/* HLLAPI data str.    */
unsigned int hds_len;         /* HLLAPI data string len    */
unsigned int hrc;             /* HLLAPI return code    */
/******************************************************************/
/************************** BEGIN CODE ****************************/
/******************************************************************/
/******************************************************************/
/* MAIN - Main code calls routines to do real work.               */
/*                                                                */
/* INPUT                                                          */
/*                                                                */
/* OUTPUT                                                         */
/*                                                                */
/*                                                                */
/******************************************************************/
 main(){ 
   int rc;                       /* return code    */
   char key = 'a' ;              /* input character    */
   printf(blank_screen);         /* Clear the screen    */
   rc = disp_hllapi_info();      /* Call routine to    */
                                 /* display HLLAPI info    */
   if (rc == 0){
     printf(press_ent_msg);
     fgetc(stdin);                 /* Make user press ENTER    */
     rc = disp_session_info();     /* Call routine to display    */
                                 /* Host session info    */
   }
   
   if (rc == 0){
     if (dft_sess){                   /* At least 1 sess    */
         printf(blank_screen);         /* Clear the screen.    */
         printf("Press ENTER to send string '");
         printf(host_text);
         printf("' to session short name ");
         fputc(dft_sess,stdout);
         printf ("...");
         fgetc(stdin);               /*Make user press ENTER    */
         rc = write_str_2_host(host_text);/* Call routine to write*/
                                 /* string to host session    */
      } 
      else
      {
         printf("NO SESSION CONFIGURED.\n");
         rc = 1;                 /* Get out of program    */
      }   
   }
   
   if (rc == 0){
      printf("Press ENTER to search for string '");
      printf(host_text);
      printf("' on Host Presentation Space...");

          
 fgetc(stdin);               /*Make user press enter   */
      rc = search_str_on_host();   /* Routine to search for    */
                             /* string on host session    */

       }

   if (rc == 0){
      printf("Press ENTER to display 1920 bytes of presentation
             space...");
      fgetc(stdin);              /*Make user press ENTERCS2C   */
      rc = disp_host_scr();      /* Call routine to display    */
                                 /* Host session screen    */
   }
   
   if (rc == 0){
      fflush(stdin);                /* Flush input buffer    */
      printf( "\nSAMPLE PROGRAM DONE. To Exit Program Press
             ENTER..." );
      fgetc(stdin);                 /* Make user press ENTER    */
    }
 }

/******************************************************************/
/* DISP_HLLAPI_INFO - CALLs HLLAPI QUERY_SYSTEM and then displays */
/*                     the requested info.                        */
/*                                                                */
/*                                                                */
/******************************************************************/
int disp_hllapi_info(){
   struct qsys_struct dsp_struct;
   struct qsys_struct * data_ptr;
                                 /* assign pointer    */
                                 /* HLLAPI data string.    */
   unsigned int rc = 0;          /* return code    */
   data_ptr = &dsp_struct;
   
   hfunc_num = HA_QUERY_SYSTEM;   /* Issue query system    */
   hllc(&hfunc_num, (char * )data_ptr, &hds_len, &hrc);            /* Call HLLAPI   */
   if (hrc == HARC_SUCCESS){    /* If good rc    */
      printf("    HLLAPI INFORMATION\n\n");
      printf(" HLLAPI version    : ");
      fputc(data_ptr->qsys_hllapi_ver,stdout);
      printf("\n");
      printf(" HLLAPI level    : ");
      fputc(data_ptr->qsys_hllapi_lvl[0],stdout);
      fputc(data_ptr->qsys_hllapi_lvl[1] ,stdout);
      printf("\n"); 
      printf(" HLLAPI release date    : ");
      wrt_str(data_ptr->qsys_hllapi_date, 6);
      printf("\n");
      printf(" HLLAPI hardware base    : ");
      fputc(data_ptr->qsys_hardware_base,stdout);
      printf("\n");
      printf(" HLLAPI CTRL program type : ");
      fputc(data_ptr->qsys_ctrl_prog_type,stdout);
      printf(" = ");
      if (data_ptr->qsys_ctrl_prog_type == 'X'){
         
         printf("IBM AIX");
      }
      printf("\n");
      printf(" HCON version level    : ");
      fputc(data_ptr->qsys_ctrl_prog_ver[0],stdout);
      fputc(data_ptr->qsys_ctrl_prog_ver[1],stdout);
      printf("\n");
   }
   else {
                                 /* Bad return code    */
      rc = hrc;
      error_hand(hfunc_num, rc);
   }
   return(rc);
}

/******************************************************************/
/* DISP_SESSION_INFO - CALLs HLLAPI QUERY funtions and then       */ /*                     displays the requested session info.       */
/*                                                                */
/*                                                                */
/******************************************************************/
   int disp_session_info(){            /* Routine to display    */
                                 /* Host session info    */
   struct qses_struct * data_ptr;
                               /* assign pointer    */
                                 /* HLLAPI data string.    */
   struct qsst_struct sess_stuc;    /* Query Session    */
                                 /* structure.    */
     unsigned int i;            /* Array index    */ 
     unsigned int num_sess;     /* Number of session started*/
     unsigned int rc = 0;       /* return code    */
     data_ptr = (_Packed struct qses_struct *)hdata_str;
     printf("\n\n\n\n\n\n\n\n\n\n\n\n");
     printf("                        SESSION INFO\n\n");
     hfunc_num = HA_QUERY_SESSIONS;   /* Issue query sessions    */
     hds_len = MAX_DATA_SIZE / 12 * 12;/* Make sure len is    */
                                 /* multiple of 12    */
     hllc(&hfunc_num, (char *)data_ptr, &hds_len, &hrc);
                                 /* Call HLLAPI */
     if (hrc == HARC_SUCCESS){      /* If good rc    */
       num_sess = hds_len;       /* Number of sessions started   */
       printf("Number of configured sessions = %d\n\n\n", num_sess);
         
       for(i = 0;((i < num_sess) && (rc == 0)); i++)
                                   /* LOOP thru queried sessions */ 
      { 
         printf("Session number : %d\n",i+1);
         printf("Session Long name : ");
         wrt_str(data_ptr[i].qses_longname, 8);
         printf("\n");
         printf("Session Short name : ");
         wrt_str(&data_ptr[i].qses_shortname, 1);
         printf("\n");
         printf("Session Type : ");
         wrt_str(&data_ptr[i].qses_sestype, 1);
         printf(" = ");
         if (data_ptr[i].qses_sestype == 'H')
         {
            printf("Host");
            if (!(dft_sess)){ /* First HOST not set alreaCS2C */
               dft_sess = data_ptr[i].qses_shortname;
                             /* Set the session to write string to*/
               } 
            } 
            printf("\n");
            printf("Session PS size : %d\n"
                 ,data_ptr[i].qses_pssize);
         
           hfunc_num = HA_QUERY_SESSION_STATUS;                                                        /* Issue query session status */
           hds_len = 18;        /* Set length    */
           sess_stuc.qsst_shortname = data_ptr[i].qses_shortname;
                                    /* Set the session short name */
           hllc(&hfunc_num, (char *)&sess_stuc, &hds_len, &hrc); 
           
            if (hrc == HARC_SUCCESS){   /* If good rc    */
           printf("Session PS rows : %d\n"
                ,sess_stuc.qsst_ps_rows);
           printf("Session PS columns : %d\n"
                ,sess_stuc.qsst_ps_cols);
           printf("Session type : ");
           wrt_str(&sess_stuc.qsst_sestype, 1);
           printf(" = ");
           if (sess_stuc.qsst_sestype == 'D'){
              printf("DFT display");
           }
           if (sess_stuc.qsst_sestype == 'S'){
              printf("SNA T2.1 display");
           }
           if (sess_stuc.qsst_sestype == 'T'){
             printf("TCP/IP display");
           }
           if (sess_stuc.qsst_sestype == 'P'){
            printf("SNA T2.1 printer");
           }
           if (sess_stuc.qsst_sestype == 'Q'){
             printf("DFT non-SNA printer");
           }
           printf("\n");         
           printf(press_ent_msg);
           fgetc(stdin);           /* Make user press ENTERCS2C*/
                                 /* ENTER.    */
      }
      else                       /* Bad return code    */
      {
         rc = hrc;
         error_hand(hfunc_num, rc);
      }
   }
 }
 else   /* Bad return code    */
 {
   rc = hrc;
   error_hand(hfunc_num, rc);
 }
 return(rc);
}
 

/******************************************************************/
/* WRITE_STR_2_HOST - Connects to first session and writes        */
/*                    home_key and string to host                 */
/******************************************************************/
int write_str_2_host(char *in_str)    /* Call routine to     */
                                 /*  write string to host     */
{
   unsigned int rc = 0;          /* return code    */
   hdata_str[0] = dft_sess;        /* Set session id for connect   */
   hdata_str[1] = 0x00;
   hfunc_num = HA_CONNECT_PS;    /* Issue Connect    */
                                 /* Presentation Space    */
   hllc(&hfunc_num, (char * )hdata_str, &hds_len, &hrc);
                                 /* Call HLLAPI    */
   if (hrc == HARC_SUCCESS){   /* If good return code    */
    hfunc_num = HA_SENDKEY;    /* Issue sendkey    */
    strcpy(hdata_str, home_key);    /* String to send to Host    */
    hds_len = sizeof(home_key) - 1;   /* Set length of string    */
                                 /* minus null character    */
   hllc(&hfunc_num, (char * )hdata_str, &hds_len, &hrc);
                                 /* Call HLLAPI    */
   if (hrc == HARC_SUCCESS){   /* If good return code    */
      hfunc_num = HA_SENDKEY;    /* Issue sendkey    */
      strcpy(hdata_str,in_str);   /* String to send to Host    */
      hds_len = strlen(in_str);   /* Set length of string    */
                                 /* minus null character    */
      hllc(&hfunc_num, (char * )hdata_str, &hds_len, &hrc);
                                 /* Call HLLAPI    */
      if (hrc == HARC_SUCCESS){   /* If good return code    */
          printf ("Sent String to Host.\n\n\n");
      }
      else   /* Bad return code    */
      { 
         rc = hrc;               /* Set return code    */
         error_hand(hfunc_num, rc);
      }
   } 
   else
   {
      rc = hrc;                  /* Set return code    */
      error_hand(hfunc_num, rc); 
   }
  }
  else
  {
   
    rc = hrc;                    /* Set return code    */
    error_hand(hfunc_num, rc); 
  }
  return(rc);
}
/******************************************************************/
/*DISP_HOST_SCR - Displays first 1920 bytes of host screen        */
/*                                                                */
/******************************************************************/
int disp_host_scr()   /* Routine to display   */
   /* host screen   */
}
  unsigned int rc = 0;   /* return code   */
  hfunc_num = HA_SET_SESSION_PARMS;   /* Issue Set sessions Parms*/
  hds_len = sizeof(setparm_text) - 1; /* Copy the first 1920 bytes*/
   /* of presentation space   */
  hllc(&hfunc_num, setparm_text, &hds_len, &hrc);
                                 /* Call HLLAPI    */
  if (hrc == HARC_SUCCESS){   /* If good return code    */
    hfunc_num = HA_COPY_PS_TO_STR;    /* Issue Copy PS to string   */
    hds_len = MAX_DATA_SIZE;   /* Copy the first 1920 bytes*/
   /* of presentation space   */
    hrc = 1;   /* Set PS position to    */
   /* top, left corner   */
    hllc(&hfunc_num, hdata_str, &hds_len, &hrc);
   /* Call HLLAPI   */
    if (hrc == HARC_SUCCESS){   /* If good return code   */
      wrt_str(hdata_str, MAX_DATA_SIZE);
   /* Write the string   */
    }
    else   /* Bad return code   */
    {
      rc = hrc;   /* Set return code   */
      error_hand(hfunc_num, rc);
    }
  }
  else   /* Bad return code   */
  {
    rc = hrc;   /* Set return code   */
    error_hand(hfunc_num, rc);
  }
  return(rc);
}
/******************************************************************/
/* WRT_STR - Writes char string to standard output.                */
/*                                                                */
/* INPUT                                                          */
/*                                                                */
/* OUTPUT                                                         */
/*                                                                */
/******************************************************************/
wrt_str(text_ptr, x)            /* Prints x number of characters   */
unsigned char * text_ptr;       /* Pointer to string to write   */
unsigned int x;                 /* Number of bytes in string    */
{
   unsigned int i;              /* counter    */
   for (i = 0; i < x; i++)
   {
      fputc(text_ptr[i],stdout);
   }
}
/******************************************************************/
/* ERROR_HAND - Error handler.                                    */
/*                                                                */
/******************************************************************/
int error_hand(func, rc)         /* Error handler.    */
unsigned int func;
unsigned int rc;
{
   printf("UNEXPECTED RETURN CODE %d from FUNCTION #%d.",rc, func); 
}

Related Information

Host Connection Program (HCON): Overview


[ Previous | Next | Contents | Search ]