home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
JUMP.ZIP
/
JUMP.C
< prev
next >
Wrap
Text File
|
1991-08-16
|
8KB
|
238 lines
/*---------------------------------------------------------------------
This program does the maximizing and minimizing of the 3270 sessions.
It waits on a JUMP semaphore and when cleared it checks to see if it
should die. It tries to request the DIE semaphore with a timeout
if 1ms. If the request fails then it waits 1ms and returns with an
non-zero error code. If the error code is non-zero then that means
it should not die and do the jump. If the error code is zero then
clear the DIE semaphore and close it and end. The DIE semaphore is
set in JUMPLDR.EXE and when that exits, it clears the DIE semaphore
and then clears the JUMP semaphore.
---------------------------------------------------------------------*/
#define INCL_DOS
#define NUL '\0'
/* 3270 EHLLAPI bit settings */
#define SETWINDOW 0x01
#define STATUS 0x02
#define ACTIVATE 0x0080
#define MAX 0x0800
#define MIN 0x0400
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "jump.h"
void main()
{
static char szSession[26];
static char cSelectedSession=NUL;
static char cPrevSession=NUL;
HSYSSEM hsemJump;
HSYSSEM hsemDie;
GetSessions(szSession);
DosOpenSem(&hsemJump,JUMP_SEM_NAME);
DosOpenSem(&hsemDie,DIE_SEM_NAME);
do
{
DosSemWait(hsemJump,SEM_INDEFINITE_WAIT);
if((DosSemRequest(hsemDie,1)))
{
SelectSession(szSession,&cSelectedSession,&cPrevSession);
MinimizePreviousSession(cPrevSession);
MaximizeNextSession(cSelectedSession);
DosSemSet(hsemJump);
}
else
{
DosSemClear( hsemDie );
DosCloseSem( hsemDie );
break;
}
}
while (TRUE);
}
/*---------------------------------------------------------------------
GetSessions puts the active sessions (A-Z) into a null-terminated
string
---------------------------------------------------------------------*/
void GetSessions(
PSZ szSession)
{
int i;
strcpy(hll_str," ");
i=0;
for ( hll_str[0]='A'; hll_str[0] <= 'Z'; hll_str[0]++ )
{
function = 1;
hll_rtc=0;
hllapi(&function,hll_str,&str_len,&hll_rtc);
if (hll_rtc == 0)
{
szSession[i] = hll_str[0];
i++;
function = 2;
hll_rtc=0;
hllapi(&function,hll_str,&str_len,&hll_rtc);
}
}
szSession[i]=NUL;
}
/*---------------------------------------------------------------------
SelectSession determines the session to be maximized based on what
was the last session to be maximized.
---------------------------------------------------------------------*/
void SelectSession(
PSZ szSession,
char * cSelectedSession,
char * cPrevSession)
{
static int i;
if (*cPrevSession == NUL)
{
i=0;
*cSelectedSession = szSession[i];
*cPrevSession = szSession[i];
}
else
{
*cPrevSession = szSession[i];
i++;
if (!szSession[i])
i=0;
*cSelectedSession = szSession[i];
}
}
/*---------------------------------------------------------------------
MinimizeSession minimizes the session that most recently maximized
by this program. This does not check to see if is already maximized.
---------------------------------------------------------------------*/
void MinimizePreviousSession(
char cPrevSession)
{
/* this never changes */
(struct ServiceData *)fptr = (struct ServiceData *) hdata_str;
fptr-> xwinpos =0;
fptr-> ywinpos =0;
fptr-> xwinsize =0;
fptr-> ywinsize =0;
fptr-> placement=0;
/* connect to Prev session using connect PM window services*/
function = 101;
hll_rtc=0;
hll_str[1]=0;
hll_str[0] = cPrevSession;
str_len = 1;
hllapi(&function,hll_str,&str_len,&hll_rtc);
if (hll_rtc != 0)
printf ("PM Services connection error - session %c \n",cPrevSession);
/* activate session using PM window services*/
fptr->session = cPrevSession;
fptr->option = SETWINDOW;
fptr->request = ACTIVATE;
function = 104;
hll_rtc=0;
str_len = 16;
hllapi(&function,(PSZ)fptr,&str_len,&hll_rtc);
if (hll_rtc != 0)
printf ("Error Code %i - activate session %c\n",hll_rtc,cPrevSession);
/* minimize the prev session using PM window services*/
fptr->session = cPrevSession;
fptr->option = SETWINDOW;
fptr->request = MIN;
function = 104;
hll_rtc=0;
str_len = 16;
hllapi(&function,(PSZ)fptr,&str_len,&hll_rtc);
if (hll_rtc != 0)
printf ("Error Code %i - minimize session \n",hll_rtc,cPrevSession);
/* disconnect PM window services*/
function = 102;
hll_str[0] = cPrevSession;
hll_str[1]=0;
hll_rtc=0;
hllapi(&function,hll_str,&str_len,&hll_rtc);
if (hll_rtc != 0)
printf ("Error Code %i - disconnect session %c \n",hll_rtc,cPrevSession);
}
/*---------------------------------------------------------------------
MaximizeSession maximizes the session.
---------------------------------------------------------------------*/
void MaximizeNextSession(
char cWindow)
{
/* this never changes */
(struct ServiceData *)fptr = (struct ServiceData *) hdata_str;
fptr-> xwinpos =0;
fptr-> ywinpos =0;
fptr-> xwinsize =0;
fptr-> ywinsize =0;
fptr-> placement=0;
/* connect to session using connect PM window services*/
function = 101;
hll_rtc=0;
hll_str[1]=0;
hll_str[0] = cWindow;
str_len = 1;
hllapi(&function,hll_str,&str_len,&hll_rtc);
if (hll_rtc != 0)
printf ("PM Services connection error - session %c \n",cWindow);
/* activate session using PM window services*/
fptr->session = cWindow;
fptr->option = SETWINDOW;
fptr->request = ACTIVATE;
function = 104;
hll_rtc=0;
str_len = 16;
hllapi(&function,(PSZ)fptr,&str_len,&hll_rtc);
if (hll_rtc != 0)
printf ("Error Code %i - activate session %c\n",hll_rtc,cWindow);
/* minimize the prev session using PM window services*/
fptr->session = cWindow;
fptr->option = SETWINDOW;
fptr->request = MAX;
function = 104;
hll_rtc=0;
str_len = 16;
hllapi(&function,(PSZ)fptr,&str_len,&hll_rtc);
if (hll_rtc != 0)
printf ("Error Code %i - minimize session \n",hll_rtc,cWindow);
/* disconnect PM window services*/
function = 102;
hll_str[0] = cWindow;
hll_str[1]=0;
hll_rtc=0;
hllapi(&function,hll_str,&str_len,&hll_rtc);
if (hll_rtc != 0)
printf ("Error Code %i - disconnect session %c \n",hll_rtc,cWindow);
}