home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cenvi23.zip
/
WINSPAWN.CMM
< prev
next >
Wrap
Text File
|
1995-02-03
|
5KB
|
164 lines
//*****************************************************************
//*** WinSpawn.cmm - Run from CEnvi for Windows to allow the ***
//*** ver.2 WinSpawn() routine in WinSpawn.lib to ***
//*** call the spawn command in Windows sessions ***
//*** running under WINOS2. ***
//*****************************************************************
if ( !defined(_WINDOWS_) ) {
printf("\a\nThis program must be executed from CEnvi for Windows\n");
printf("to serve the OS/2 WinSpawn() routine from CEnvi for OS/2.\n");
printf("Press any key to exit...");
getch();
printf("\n");
exit(EXIT_FAILURE);
}
#include <OptParms.lib>
main(argc,argv)
{
Hide = OptionalParameter(argc,argv,"HIDE");
FileName = argv[1];
WaitTime = atoi(argv[2]);
if ( 3 != argc || WaitTime < 1 ) {
Instructions();
return EXIT_FAILURE;
}
// Give this session the name of the file
sprintf(NewTitle,"WinSpawn: %s",FileName);
DynamicLink("USER","SETWINDOWTEXT",SWORD16,PASCAL,ScreenHandle(),NewTitle);
// If want to be hidden, then hide it
if ( Hide )
DynamicLink("USER","SHOWWINDOW",SWORD16,PASCAL,ScreenHandle(),0);
SpawnForever(FileName,WaitTime);
return EXIT_SUCCESS;
}
#define WIN_SPAWN 0 // spawn command and return immediately
#define WIN_SPAWN_WAIT 1 // spawn and wait until command is finished
#define WIN_SPAWN_EXIT 2 // spawn and then exit WinSpawn.cmm
SpawnForever(pFileSpec,pDelay)
// get all messages from WinSpawn.lib and spawn them
{
sprintf(FullPipeSpec,"\\PIPE\\%s",pFileSpec);
lExit = False;
do {
suspend(pDelay);
// try to read command from pipe file
if ( DosOpen(lHandle,FullPipeSpec,0xC2) ) {
// read the action to perform, how many bytes in the message,
// and then the message
if ( DosReadUWORD32(lHandle,lAction)
&& DosReadUWORD32(lHandle,lCommandLen,UWORD32)
&& lCommandLen
&& DosRead(lHandle,lCommand,lCommandLen) ) {
// final check that Command is CommandLen long
if ( strlen(lCommand) == (lCommandLen-1) ) {
// perform spawn command
if ( 1 == lCommandLen ) {
lResult = 0; // nothing happened
} else {
lResult = spawn(WIN_SPAWN_WAIT == lAction ? P_WAIT : P_NOWAIT,
lCommand);
}
// send back return code
DosRewind(lHandle);
BLObPut(lResultBLOb,0,lResult,SWORD32);
DosWrite(lHandle,lResultBLOb,BLObSize(lResultBLOb));
if ( WIN_SPAWN_EXIT == lAction )
lExit = True;
}
}
DosClose(lHandle);
}
} while ( !lExit );
}
DosOpen(pHandle,pFileName,pAttributes)
{
lInReg.ds = segment(pFileName);
lInReg.dx = offset(pFileName);
lInReg.ah = 0x3D;
lInReg.al = pAttributes;
lSuccess = interrupt(0x21,lInReg,lRegOut);
pHandle = lRegOut.ax;
return lSuccess;
}
DosClose(pHandle)
{
lReg.ah = 0x3E;
lReg.bx = pHandle;
interrupt(0x21,lReg,lRegOut);
}
DosWrite(pHandle,pBuffer,pBufferLen)
{
lInReg.ah = 0x40;
lInReg.bx = pHandle;
lInReg.cx = pBufferLen;
lInReg.ds = segment(pBuffer);
lInReg.dx = offset(pBuffer);
return ( interrupt(0x21,lInReg,lOutReg) && lOutReg.ax == pBufferLen );
}
DosRead(pHandle,pBuffer,pBufferLen)
{
BLObSize(pBuffer,pBufferLen);
lInReg.ah = 0x3F;
lInReg.bx = pHandle;
lInReg.cx = pBufferLen;
lInReg.ds = segment(pBuffer);
lInReg.dx = offset(pBuffer);
return ( interrupt(0x21,lInReg,lOutReg) && lOutReg.ax == pBufferLen );
}
DosReadUWORD32(pHandle,pUWORD32)
{
if ( !DosRead(pHandle,lBuf,4) )
return False;
pUWORD32 = BLObGet(lBuf,0,UWORD32);
return True;
}
DosRewind(pHandle)
{
lReg.ax = 0x42;
lReg.al = 0;
lReg.cx = lReg.dx = 0;
interrupt(0x21,lReg);
}
Instructions()
{
puts("\a");
puts(`WinSpawn - Perform the CEnvi spawn() function from WINOS2`);
puts(``)
puts(`SYNTAX: CENVI2 WINSPAWN <PipeSpec> <Delay> [/HIDE]`)
puts(``)
puts(`WHERE: PipeSpec - Unique 8.3 name to identify this WINSPAWN session`)
puts(` Delay - time (milliseconds) to delay between checks`)
puts(` HIDE - Optional; hide thise CEnvi program icon`)
puts(``)
puts(`Examples: the following examples run from OS/2`)
puts(` START /FS /F C:\CENVIWIN\CENVIW.EXE D:\CENVIOS2\WinSpawn FAXER 3000`)
puts(` START /WIN C:\CENVIWIN\CENVIW.EXE FAXER 5000 /HIDE`)
puts(``)
puts(`Press any key to exit...`)
getch()
}