home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 1B
/
DATAFILE_PDCD1B.iso
/
_pocketbk
/
pocketbook
/
001
/
lpc091s_zi
/
LPCON.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-24
|
27KB
|
1,066 lines
/* LPCON.C
Copyright (C) Psion PLC 1994
Started by : DavidW
Started on: 1/1/94
*/
#include <p_std.h>
#include <p_gen.h>
#include <p_file.h>
#include <epoc.h>
#include <ats.h>
#include <wskeys.h>
#include <wlib.h>
#include <lpc.g>
#include <gate.g>
#include <hwimman.g>
#include <ipc.g>
#include "lpcdat.h"
#ifndef W_KEY_DIAMOND
#define W_KEY_DIAMOND 0x124
#endif
GLREF_D PR_GATE *DatGate;
GLREF_D VOID *DatCommandPtr;
GLREF_D VOID *DatUsedPathNamePtr;
GLREF_D VOID *DatStatusNamePtr;
GLREF_D VOID *DatProcessNamePtr;
GLREF_D VOID *DatCommandPtr;
GLREF_D UWORD DatLocked;
GLREF_D PR_APPMAN *w_am;
GLREF_D PR_WSERV *w_ws;
GLREF_D PR_DLGCHAIN *DatDialogPtr;
GLREF_C VOID WservName(VOID);
GLREF_C VOID OplComline(VOID);
GLREF_C VOID Sys$prgoName(VOID);
LOCAL_C VOID SignalCompletion(PR_LPCON *self,WORD completion)
{
*self->lpcon.pMstat=completion;
p_iosignal(); /* force completion */
}
LOCAL_C INT SendMessage(PR_LPCON *self,INT type,ATS_MESS_BODY *pu)
/*
Can be called within WaitHandler so never leaves in that case
*/
{
INT ret;
if (type==TY_ATS_RECORD)
return(p_msendreceivew(self->lpcon.pid,type,pu));
ret=p_msendreceivea(self->lpcon.pid,type,pu,self->lpcon.pMstat);
if (ret)
SignalCompletion(self,ret); /* simulate completion */
if (self->lpcon.pUstat || self->lpcon.pstr)
return(0);
p_waitstat(self->lpcon.pMstat);
return(self->lpcon.mstat);
}
LOCAL_C VOID ResetPMstat(PR_LPCON *self)
/*
Reset to use user's stat, if specified, or else internal one
*/
{
self->lpcon.pMstat=
(self->lpcon.pUstat? self->lpcon.pUstat: &self->lpcon.mstat);
}
LOCAL_C VOID CancelStringState(PR_LPCON *self)
{
self->lpcon.pstr=NULL;
ResetPMstat(self);
}
LOCAL_C INT CurrentDriveLetter(VOID)
{
INT i;
i=(*(((UBYTE *)DatCommandPtr)+P_FSYSNAMESIZE));
if (i=='M')
i='I';
return(i);
}
LOCAL_C INT LookUp(INT key)
{
switch (key)
{
case 'C':
return(W_KEY_RETURN);
case 'D':
return(W_KEY_DOWN);
case 'E':
return(W_KEY_END);
case 'H':
return(W_KEY_HOME);
case 'L':
return(W_KEY_LEFT);
case 'M':
return(W_KEY_MENU);
case 'P':
return(W_KEY_PAGE_UP);
case 'Q':
return(W_KEY_PAGE_DOWN);
case 'R':
return(W_KEY_RIGHT);
case 'T':
return(W_KEY_TAB);
case 'U':
return(W_KEY_UP);
case 'X':
return(W_KEY_ESCAPE);
case '+':
return(W_KEY_DIAMOND);
case '-':
return(W_KEY_DELETE_LEFT);
case '?':
return(CurrentDriveLetter());
}
return(key);
}
LOCAL_C VOID DoPause(PR_LPCON *self,INT delay)
/*
This will never leave since is called only within WaitHandler during string
handling, when messaging always takes place asynchronously
*/
{
p_send3(self,O_LPC_PAUSE,delay);
}
LOCAL_C VOID ProcessNextCharacterInString(PR_LPCON *self)
{
INT chr;
INT mods;
mods=0;
Again:
chr=(*self->lpcon.pstr++);
if (!chr)
{
SignalCompletion(self,-1);
return;
}
if (chr=='@')
{
chr=(*self->lpcon.pstr++);
if (!chr)
{
SignalCompletion(self,-1);
return;
}
if (chr>='0' && chr<='9')
{
mods=chr-'0';
if (mods&1)
{
mods&=(~1);
mods|=W_PSION_MODIFIER;
}
goto Again;
}
if (chr!='@')
{
mods=(p_isupper(chr)? W_PSION_MODIFIER|W_SHIFT_MODIFIER:
W_PSION_MODIFIER);
chr+=W_SPECIAL_KEY;
}
}
else if (chr=='^')
{
chr=(*self->lpcon.pstr++);
if (!chr)
{
SignalCompletion(self,-1);
return;
}
if (chr>='0' && chr<='9')
{
DoPause(self,10*(chr-'0'));
return;
}
if (chr=='%')
{
DoPause(self,5);
return;
}
if (chr=='Y')
{
p_send2(self,O_LPC_YIELD);
SignalCompletion(self,0);
return;
}
chr=LookUp(chr);
}
p_send4(self,O_LPC_KEY,chr,mods);
}
LOCAL_C VOID SendEscapeKey(PR_LPCON *self)
{
p_send4(self,O_LPC_KEY,W_KEY_ESCAPE,0);
}
#define wws ((PR_WSERV *)self->lpcon.pstr)
LOCAL_C VOID NextGroundStep(PR_LPCON *self)
{
INT ret;
VOID *win;
if (self->lpcon.strCount++==1)
{
ret=p_pcpyfr(self->lpcon.pid,&wws->wserv.bar,&win,2);
if (ret)
{
SignalCompletion(self,ret);
return;
}
if (win)
{
SendEscapeKey(self);
return;
}
}
if (self->lpcon.strCount==32)
{
SignalCompletion(self,E_GEN_TOOMANY);
return;
}
ret=p_pcpyfr(self->lpcon.pid,&wws->wserv.dial,&win,2);
if (!ret && !win)
ret=(-1);
if (ret)
{
SignalCompletion(self,ret);
return;
}
SendEscapeKey(self);
}
#undef wws
LOCAL_C INT WaitHandler(PR_LPCON *self)
{
if (self->lpcon.pid && self->lpcon.lstat!=E_FILE_PENDING)
{ /* attached process has terminated */
self->lpcon.pid=0;
if (self->lpcon.pstr)
{ /* cancel any string processing */
if (self->lpcon.sstat!=E_FILE_PENDING)
p_iowait(); /* use up the string signal */
CancelStringState(self);
self->lpcon.cancel=FALSE;
}
if (*self->lpcon.pMstat==E_FILE_PENDING)
SignalCompletion(self,E_GEN_RECEIVER);
return(P_SIGNAL_DISABLE);
}
if (!self->lpcon.pstr || self->lpcon.sstat==E_FILE_PENDING)
return(P_SIGNAL_UNUSED);
if (self->lpcon.cancel)
{
self->lpcon.cancel=FALSE;
self->lpcon.sstat=E_FILE_CANCEL;
}
if (self->lpcon.sstat<0)
{
CancelStringState(self);
if (self->lpcon.sstat==(-1))
self->lpcon.sstat=0;
SignalCompletion(self,self->lpcon.sstat);
}
else if (!self->lpcon.strCount)
ProcessNextCharacterInString(self);
else
NextGroundStep(self);
return(P_SIGNAL_ENABLE);
}
LOCAL_C VOID LogOff(PR_LPCON *self)
{
if (self->lpcon.pid)
{
p_sveccall(self->lpcon.whandler,FALSE);
if (!p_logoffa(self->lpcon.pid));
p_waitstat(&self->lpcon.lstat);
self->lpcon.pid=0;
}
}
LOCAL_C VOID LogOn(PR_LPCON *self)
{
INT ret;
ret=p_logona(self->lpcon.pid,&self->lpcon.lstat);
if (ret)
{
self->lpcon.pid=0;
f_leave(ret);
}
p_sveccall(self->lpcon.whandler,TRUE);
}
LOCAL_C INT fSendMessage(PR_LPCON *self,INT type,ATS_MESS_BODY *pu)
{
return(f_leave(SendMessage(self,type,pu)));
}
LOCAL_C VOID SendEscapeKeyWait(PR_LPCON *self)
{
ATS_MESS_BODY u;
INT ret;
u.k.mod=0;
u.k.key=W_KEY_ESCAPE;
self->lpcon.pMstat=(&self->lpcon.mstat);
ret=SendMessage(self,TY_ATS_KEY,&u);
if (self->lpcon.pUstat)
{
p_waitstat(self->lpcon.pMstat);
ret=self->lpcon.mstat;
} /* in !pUstat case, waits inside SendMessage */
ResetPMstat(self);
f_leave(ret);
}
LOCAL_C VOID CopyTo(PR_LPCON *self,VOID *trg,VOID *src,UINT len)
{
f_leave(p_pcpyto(self->lpcon.pid,trg,src,len));
}
LOCAL_C VOID CopyFrom(PR_LPCON *self,VOID *src,VOID *trg,UINT len)
{
f_leave(p_pcpyfr(self->lpcon.pid,src,trg,len));
}
LOCAL_C INT Exec