Category : OS/2 Files
Archive   : OS2CMAPI.ZIP
Filename : HSMPLC.C

 
Output of file : HSMPLC.C contained in archive : OS2CMAPI.ZIP
/*********************************************************************/
/* */
/* */
/* FILE NAME: HSMPLC.C */
/* */
/* MODULE NAME= HSMPLC.C */
/* */
/* DESCRIPTIVE NAME= C SAMPLE PROGRAM FOR EHLLAPI */
/* */
/* Displays EHLLAPI and session information. */
/* Writes string to host. */
/* Searches for written string on host. */
/* Displays host session screen. */
/* */
/* COPYRIGHT: XXXXXXXXX (C) COPYRIGHT IBM CORP. 1987,1988 */
/* LICENSED MATERIAL - PROGRAM PROPERTY OF IBM */
/* ALL RIGHTS RESERVED */
/* */
/* NOTES= */
/* COMPILE WITH SMALL MODEL. */
/* */
/**********************-END OF SPECIFICATIONS-************************/
/*BEGINPDL (000,001) */
/*ENDPDL */
/*BEGINCDE */

/*********************************************************************/
/********************** BEGIN INCLUDE FILES **************************/
/*********************************************************************/

#include "stdio.h"

#include "string.h"



#include "hapi_c.h" /* 000 Get EHLLAPI */
/* include file for C. */




/*********************************************************************/
/************************ FUNCTION EXTERNS ***************************/
/*********************************************************************/


/*ENDCDE */

/* The following extern was copied out of SUBCALLS.H instead of included in */
/* for ease of compiling. */
extern unsigned far pascal VIOWRTCELLSTR (
char far *, /* String to be written */
unsigned, /* Length of string */
unsigned, /* Starting position for output (row) */
unsigned, /* Starting position for output (col) */
unsigned ); /* Vio Handle */


/*BEGINPDL (000,001) */
/*ENDPDL */
/*BEGINCDE */

/*********************************************************************/
/***************************** DEFINES *******************************/
/*********************************************************************/

#define MAX_DATA_SIZE 3840 /* 000 The maximum data */
/* size for this */
/* application. */

#define EABS 0x80 /* 000 Extended attribute */
/* bit. */
#define PSS 0x40 /* 000 Programmed Symbol */
/* Set bit. */


/*********************************************************************/
/******************* BEGIN STATIC VARIABLES **************************/
/*********************************************************************/

unsigned char press_ent_msg[] =
{
"\n\nPress ENTER to continue..."
}
;
unsigned char blank_screen[] = /* 000 Poor mans blank */
{
"\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"

}
; /* 000 screen. */

unsigned char dft_sess = NULL; /* 000 Session to write */
/* string to and search */
/* from. */


unsigned char host_text[] =
{
"3270 EHLLAPI"
}
; /* 000 String to send to */
/* host and to search */
/* for. */
unsigned char home_key[] =
{
"@0" /* 000 The Home Key. */
}
;



unsigned char setparm_text[] =
{
"NOATTRB EAB XLATE"
}
; /* 000 Srting to to use */
/* for set parms. */


/* EHLLAPI variables. */
unsigned int hfunc_num; /* 000 EHLLAPI function */
/* number. */
unsigned char hdata_str[MAX_DATA_SIZE]; /* 000 EHLLAPI data */
/* string. */
unsigned int hds_len; /* 000 EHLLAPI data */
/* string length. */
unsigned int hrc; /* 000 EHLLAPI return */
/* code. */


/*********************************************************************/
/*************************** BEGIN CODE ******************************/
/*********************************************************************/

/*********************************************************************/
/* MAIN - Main code calls routines to do real work. */
/* */
/* INPUT */
/* */
/* OUTPUT */
/* */
/* */
/*********************************************************************/
main() /* 000 Entry from DOS. */


{
unsigned int rc; /* 000 return code. */

printf(blank_screen); /* 000 Clear the screen. */

rc = disp_ehllapi_info(); /* 000 Call routine to */
/* display EHLLAPI info. */

if (rc == 0)
{
printf(press_ent_msg);
fgetchar(); /* 000 Make user press */
/* ENTER. */

rc = disp_session_info(); /* 000 Call routine to */
/* display Host session */
/* info. */
}

if (rc == 0)
{
if (dft_sess != NULL) /* 000 If at least 1 dft */
/* session. */
{

printf(blank_screen); /* 000 Clear the screen. */
printf("Press ENTER to send string '");

printf(host_text);
printf("' to session short name ");

fputchar(dft_sess);
printf ("...");
fgetchar(); /* 000 Make user press */



rc = write_str_2_host(); /* 000 Call routine to */
/* write string to host */
/* session. */
}
else
{
printf("NO DFT SESSION SESSION STARTED.\n");

rc = 1; /* 000 Get out of */
/* program. */
}


}

if (rc == 0)
{
printf("Press ENTER to search for string '");

printf(host_text);
printf("' on Host Presentation Space...");

fgetchar(); /* 000 Make user press */

rc = search_str_on_host(); /* 000 Call routine to */
/* search for string on */
/* host session. */

}

if (rc == 0)

{
printf("Press ENTER to display first 1920 bytes of Host\
presentation space...");
fgetchar(); /* 000 Make user press */
/* ENTER. */
rc = disp_host_scr(); /* 000 Call routine to */
/* display Host session */
/* screen. */

}
if (rc == 0)

{
printf(
"SAMPLE PROGRAM DONE. To Exit Program Press ENTER..."
);
fgetchar(); /* 000 Make user press */
/* ENTER. */

}

}






/*ENDCDE */
/*BEGINPDL (000,001) */
/*ENDPDL */
/*BEGINCDE */








/*********************************************************************/
/* DISP_EHLLAPI_INFO - CALLs EHLLAPI QUERY_SYSTEM and then displays */
/* the requested info. */
/* */
/* INPUT */
/* */
/* OUTPUT */
/* */
/*********************************************************************/
int disp_ehllapi_info() /* 000 Routine to display */
/* EHLLAPI info. */


{
struct qsys_struct * data_ptr = (struct qsys_struct *)
hdata_str; /* 000 assign pointer */
/* EHLLAPI data string. */

unsigned int rc = 0; /* 000 return code. */



hfunc_num = HA_QUERY_SYSTEM; /* 000 Issue query */
/* system. */

hllc(&hfunc_num, data_ptr, &hds_len, &hrc);
/* 000 Call EHLLAPI. */

if (hrc == HARC_SUCCESS) /* 000 If good rc. */
{

printf(" EHLLAPI INFORMATION\n\n");


printf(" EHLLAPI version : ");

fputchar(data_ptr->qsys_hllapi_ver);

printf("\n");

printf(" EHLLAPI level : ");

fputchar(data_ptr->qsys_hllapi_lvl[0]);

fputchar(data_ptr->qsys_hllapi_lvl[1]);

printf("\n");

printf(" EHLLAPI release date : ");

wrt_str(data_ptr->qsys_hllapi_date, 6);

printf("\n");

printf(" EHLLAPI LIM version : ");

fputchar(data_ptr->qsys_lim_ver);
printf("\n");

printf(" EHLLAPI LIM level : ");

fputchar(data_ptr->qsys_lim_lvl[0]);

fputchar(data_ptr->qsys_lim_lvl[1]);

printf("\n");

printf(" EHLLAPI hardware base : ");

fputchar(data_ptr->qsys_hardware_base);

printf(" = ");
if (data_ptr->qsys_hardware_base == 'A')

{
printf("AT");
}
if (data_ptr->qsys_hardware_base == 'X')

{
printf("XT");
}
if (data_ptr->qsys_hardware_base == 'S')

{
printf("S/2");
}
if (data_ptr->qsys_hardware_base == 'Z')

{
printf("(See System model/submodel below)");

}
printf("\n");

printf(" EHLLAPI CTRL program type : ");

fputchar(data_ptr->qsys_ctrl_prog_type);

printf(" = ");
if (data_ptr->qsys_ctrl_prog_type == 'X')

{
printf("OS/2");

}
if (data_ptr->qsys_ctrl_prog_type == 'C')

{
printf("3270 PC");

}
if (data_ptr->qsys_ctrl_prog_type == 'W')

{
printf("WSP");

}
printf("\n");

printf(" EHLLAPI sequence number : ");

fputchar(data_ptr->qsys_seq_num[0]);

fputchar(data_ptr->qsys_seq_num[1]);

printf("\n");

printf(" EHLLAPI CTRL program version : ");

fputchar(data_ptr->qsys_ctrl_prog_ver[0]);

fputchar(data_ptr->qsys_ctrl_prog_ver[1]);

printf("\n");

printf(" EHLLAPI PC session name : ");

fputchar(data_ptr->qsys_pc_sname);
printf("\n");

printf(" EHLLAPI extended error 1 : ");

wrt_str(data_ptr->qsys_err1, 4);
printf("\n");

printf(" EHLLAPI extended error 2 : ");

wrt_str(data_ptr->qsys_err2, 4);
printf("\n");


printf(" EHLLAPI system model/submodel: %02X%02X",
data_ptr->qsys_sys_model, data_ptr->qsys_sys_submodel);

printf(" HEX = ");
if ((data_ptr->qsys_sys_model == 0xFC)
&& (data_ptr->qsys_sys_submodel == 0x00))

{
printf("Model PC AT");
}
if ((data_ptr->qsys_sys_model == 0xFC)
&& (data_ptr->qsys_sys_submodel == 0x01))

{
printf("Model PC AT ENHANCED");
}
if ((data_ptr->qsys_sys_model == 0xFC)
&& (data_ptr->qsys_sys_submodel == 0x02))

{
printf("Model PC XT Model 286");
}
if ((data_ptr->qsys_sys_model == 0xFA)
&& (data_ptr->qsys_sys_submodel == 0x01))

{
printf("Model 25");
}
if ((data_ptr->qsys_sys_model == 0xFA)
&& (data_ptr->qsys_sys_submodel == 0x00))

{
printf("Model 30");
}
if ((data_ptr->qsys_sys_model == 0xFC)
&& (data_ptr->qsys_sys_submodel == 0x04))

{
printf("Model 50");
}
if ((data_ptr->qsys_sys_model == 0xFC)
&& (data_ptr->qsys_sys_submodel == 0x05))

{
printf("Model 60");
}
if ((data_ptr->qsys_sys_model == 0xF8)
&& (data_ptr->qsys_sys_submodel == 0x00))

{
printf("Model 80");
}

printf("\n");

printf(" EHLLAPI National Language : %d\n",
data_ptr->qsys_pc_nls);

printf(" EHLLAPI monitor type : ");

fputchar(data_ptr->qsys_monitor_type);

printf(" = ");
if (data_ptr->qsys_monitor_type == 'M')

{
printf("PC MONOCHROME");
}
if (data_ptr->qsys_monitor_type == 'C')

{
printf("PC CGA");
}
if (data_ptr->qsys_monitor_type == 'E')

{
printf("PC EGA");
}
if (data_ptr->qsys_monitor_type == 'A')

{
printf("PS MONOCHROME");
}
if (data_ptr->qsys_monitor_type == 'V')

{
printf("PS 8512");
}
if (data_ptr->qsys_monitor_type == 'H')

{
printf("PS 8514");
}
if (data_ptr->qsys_monitor_type == 'U')

{
printf("UNKNOWN monitor type");
}
printf("\n");
}
else /* 000 Bad rc */
{
rc = hrc;

error_hand(hfunc_num, rc);

}

return(rc);


}

/*********************************************************************/
/* DISP_SESSION_INFO - CALLs EHLLAPI QUERY funtions and then displays*/
/* the requested session info. */
/* */
/* INPUT */
/* */
/* OUTPUT */
/* */
/*********************************************************************/
int disp_session_info() /* 000 Routine to display */
/* Host session info. */
{

struct qses_struct * data_ptr = (struct qses_struct *)
hdata_str; /* 000 assign pointer */
/* EHLLAPI data string. */

struct qsst_struct sess_stuc; /* 000 Query Session */
/* structure. */

unsigned int i; /* 000 Array index. */

unsigned int num_sess; /* 000 Number of session */
/* started. */

unsigned int rc = 0; /* 000 return code. */

printf("\n\n\n\n\n\n\n\n\n\n\n\n");

printf(" SESSION INFO\n\n");


hfunc_num = HA_QUERY_SESSIONS; /* 000 Issue query */
/* sessions. */

hds_len = MAX_DATA_SIZE / 12 * 12; /* 000 Make sure len is */
/* multiple of 12. */

hllc(&hfunc_num, data_ptr, &hds_len, &hrc);
/* 000 Call EHLLAPI. */

if (hrc == HARC_SUCCESS) /* 000 If good rc. */
{
num_sess = hds_len; /* 000 Number of sessions */
/* started. */

printf("Number of started sessions = %d\n\n\n", num_sess);


for(i = 0;((i < num_sess) && (rc == 0)); i++)
/* 000 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 == NULL) /* 000 If first HOST not */
/* set already */
{

dft_sess = data_ptr[i].qses_shortname; /* Set the session to write string to. */

}
}
if (data_ptr[i].qses_sestype == 'P')

{
printf("PC");
}
printf("\n");



printf("Session PS size : %d\n"
,data_ptr[i].qses_pssize);

hfunc_num = HA_QUERY_SESSION_STATUS;
/* 000 Issue query */
/* session status. */

hds_len = 18; /* 000 Set length. */

sess_stuc.qsst_shortname = data_ptr[i].qses_shortname;
/* 000 Set the short */
/* name. */

hllc(&hfunc_num, &sess_stuc, &hds_len, &hrc);
/* 000 Call EHLLAPI. */

if (hrc == HARC_SUCCESS) /* 000 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 2 : ");

wrt_str(&sess_stuc.qsst_sestype, 1);

printf(" = ");
if (sess_stuc.qsst_sestype == 'D')

{
printf("DFT Host");
}
if (sess_stuc.qsst_sestype == 'P')

{
printf("PC");
}
printf("\n");

printf("Session supports Extended attributes (EABs)? : ");

if (sess_stuc.qsst_char & EABS) /* 000 if eabs on. */
{
printf("YES\n");
}
else /* 000 no eabs. */
{
printf("NO\n");
}

printf("Session supports Program Symbols (PSS)? : ");

if (sess_stuc.qsst_char & PSS) /* 000 if programmed */
/* sysmbol set on. */
{
printf("YES\n");
}
else /* 000 no PSS. */
{
printf("NO\n");

}
printf(press_ent_msg);
fgetchar(); /* 000 Make user press */
/* ENTER. */
}
else /* 000 Bad rc. */
{

rc = hrc;

error_hand(hfunc_num, rc);

}
}

}

else /* 000 Bad rc. */
{

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. */
/* */
/* INPUT */
/* */
/* OUTPUT */
/* */
/*********************************************************************/
int write_str_2_host() /* 000 Call routine to */
/* write string to host. */
{

unsigned int rc = 0; /* 000 return code. */


hdata_str[0] = dft_sess; /* 000 Set session id to */
/* connect. */



hfunc_num = HA_CONNECT_PS; /* 000 Issue Connect */
/* Presentation Space. */

hllc(&hfunc_num, hdata_str, &hds_len, &hrc);
/* 000 Call EHLLAPI. */

if (hrc == HARC_SUCCESS) /* 000 If good rc. */
{

hfunc_num = HA_SENDKEY; /* 000 Issue sendkey. */

strcpy(hdata_str, home_key); /* 000 String to send to */
/* Host. */

hds_len = sizeof(home_key) - 1; /* 000 Set length of */
/* string. minus null */
/* char. */

hllc(&hfunc_num, hdata_str, &hds_len, &hrc);
/* 000 Call EHLLAPI. */

if (hrc == HARC_SUCCESS) /* 000 If good rc. */
{

hfunc_num = HA_SENDKEY; /* 000 Issue sendkey. */

strcpy(hdata_str, host_text); /* 000 String to send to */
/* Host. */

hds_len = sizeof(host_text) - 1; /* 000 Set length of */
/* string. minus null */
/* char. */

hllc(&hfunc_num, hdata_str, &hds_len, &hrc);
/* 000 Call EHLLAPI. */

if (hrc == HARC_SUCCESS) /* 000 If good rc. */
{
printf ("Sent String to Host.\n\n\n");

}
else /* 000 Bad rc. */
{
rc = hrc; /* 000 Set rc. */
error_hand(hfunc_num, rc);
}
}
else
{

rc = hrc; /* 000 Set rc. */
error_hand(hfunc_num, rc);
}
}
else
{

rc = hrc; /* 000 Set rc. */
error_hand(hfunc_num, rc);
}
return(rc);

}



/*********************************************************************/
/* SEARCH_STR_ON_HOST- Searches for string on host. */
/* */
/* INPUT */
/* */
/* OUTPUT */
/* */
/*********************************************************************/
int search_str_on_host() /* 000 Routine to search */
/* for string on host */
/* session. */
{

unsigned int rc = 0; /* 000 return code. */

hfunc_num = HA_SEARCH_PS; /* 000 Issue search PS. */

strcpy(hdata_str, host_text); /* 000 String to search for */
/* on Host. */

hds_len = sizeof(host_text) - 1; /* 000 Set length of */
/* string. minus null */
/* char. */

hllc(&hfunc_num, hdata_str, &hds_len, &hrc);
/* 000 Call EHLLAPI. */

if (hrc == HARC_SUCCESS) /* 000 If good rc. */
{
printf("Found string '");
printf(host_text);
printf("' at PS position %d.\n\n\n",hds_len);

}
else
{
rc = hrc; /* 000 Set rc. */
error_hand(hfunc_num, rc);
}
return(rc);

}

/*********************************************************************/
/* DISP_HOST_SCR - Displays first 1920 bytes of host screen. */
/* */
/* INPUT */
/* */
/* OUTPUT */
/* */
/*********************************************************************/
int disp_host_scr() /* 000 Routine to */
/* display host screen. */

{
unsigned int rc = 0; /* 000 return code. */

hfunc_num = HA_SET_SESSION_PARMS; /* 000 Issue Set session */
/* Parms. */


hds_len = sizeof(setparm_text) - 1; /* 000 Only copy the */
/* first 1920 bytes of */
/* the PS. */


hllc(&hfunc_num, setparm_text, &hds_len, &hrc);
/* 000 Call EHLLAPI. */

if (hrc == HARC_SUCCESS) /* 000 If good rc. */
{

hfunc_num = HA_COPY_PS_TO_STR; /* 000 Issue Copy PS 2 str */

hds_len = MAX_DATA_SIZE; /* 000 Only copy the */
/* first 1920 bytes of */
/* the PS. */

hrc = 1; /* 000 Set PS position to */
/* top,left corner. */


hllc(&hfunc_num, hdata_str, &hds_len, &hrc);
/* 000 Call EHLLAPI. */
if (hrc == HARC_SUCCESS) /* 000 If good rc. */
{
VIOWRTCELLSTR (hdata_str, MAX_DATA_SIZE, 0, 0, 0);
/* 000 Write the string */
/* in color. */
}
else /* 000 Bad rc. */
{
rc = hrc; /* 000 Set rc. */
error_hand(hfunc_num, rc);
}

}
else /* 000 Bad rc. */
{
rc = hrc; /* 000 Set rc. */
error_hand(hfunc_num, rc);
}

return(rc);

}




/*********************************************************************/
/* WRT_STR - Writes char sting to standard output. */
/* */
/* INPUT */
/* */
/* OUTPUT */
/* */
/*********************************************************************/
wrt_str(text_ptr, x) /* 000 Prints x number of */
/* characters. */
unsigned char * text_ptr; /* 000 Pointer to string */
/* to write. */
unsigned int x; /* 000 Number of bytes in */
/* string. */

{
unsigned int i; /* 000 counter. */

for (i = 0; i < x; i++)
{
fputchar(text_ptr[i]);

}
}


/*********************************************************************/
/* ERROR_HAND - Error handler. */
/* */
/* INPUT */
/* */
/* OUTPUT */
/*********************************************************************/
int error_hand(func, rc) /* 000 Error handler. */

unsigned int func;
unsigned int rc;
{
printf("UNEXPECTED RETURN CODE %d from FUNCTION #%d.",rc,
func);




}

/*ENDCDE */


  3 Responses to “Category : OS/2 Files
Archive   : OS2CMAPI.ZIP
Filename : HSMPLC.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/