home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 3 Comm
/
03-Comm.zip
/
STERM.ZIP
/
STERM.C
< prev
next >
Wrap
Text File
|
1991-01-14
|
5KB
|
163 lines
/*
STERM.C
An attempt at a communications program in C for OS2 which
will eventually provide a file-transmit pipe to the IBM mainframe
and/or support SIMWARE's fullscreen mode
Usage: STERM control-file
where the specified control file contains
baud-rate databits parity stopbits port, etc.
*/
#define MAIN /* this is the main function */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <process.h>
#define INCL_SUB
#define INCL_DOS
#include <os2kernl.h>
#include "sterm.h"
/* Display an error msg (TTY mode ) */
AREF void emsg( char *msg )
{
VioWrtTTY( (PCH) msg, strlen( msg ), 0 );
VioWrtTTY( (PCH) "\n\r", 2, 0 );
}
/* exit with error message */
AREF void errexit(char *msg)
{
emsg( msg );
exit( 1 );
}
void main( int argc, char *argv[] )
{
/* our principal set of threads */
UINT cinthread; /* input thread TID */
UINT couthread; /* output thread TID */
UINT vouthread; /* video thread TID */
UINT kbdthread; /* keybd thread TID */
/* and their stacks */
UINT cominstk; /* input thread stack token */
UINT comoutstk; /* output thread stack token */
UINT voutstk; /* video thread TID */
UINT kbdinstk; /* keybd thread TID */
#define STKSIZE 4096
MsgH termsg = { termin, 1, ' ' }; /* termination msg */
UINT wrtl; /* DosWrite charcount */
/************************ end main autovariables ***********/
emsg( "STERM: v 0.0" );
if ( argc < 2 )
errexit( "Definition file not given." );
CurP = NULL; /* port not defined */
keymode = ignore; /* do not put to port */
ComLog = FALSE; /* default of no logging */
waitlen = 0; /* no string to wait on */
Sim3270 = vtkey; /* default 3270 tbl */
insmode = FALSE; /* insert mode off */
xstate = TERM; /* normal transmit state */
blkp = NULL; /* no transmit data */
timelim = TIMELIM; /* set await default */
/* initialize screen */
fldmono = fldcolor = 0x07;
clrscrn();
/* set default strings */
strcpy( initstr, "ATZ" ); /* modem init */
strcpy( waitstr, "OK" ); /* modem ready */
/* declare the EOJ semaphore */
exitsem = 0L; readsem = 0L;
DosSemSet( (HSEM) &exitsem );
DosSemSet( (HSEM) &readsem ); /* declare port read gate */
/* open the set of pipes */
DosMakePipe( (PUSHORT) &vworkR, (PUSHORT) &vworkW, STKSIZE );
DosMakePipe( (PUSHORT) &kbdinR, (PUSHORT) &kbdinW, STKSIZE );
DosMakePipe( (PUSHORT) &comiR, (PUSHORT) &comiW, STKSIZE );
DosMakePipe( (PUSHORT) &comoR, (PUSHORT) &comoW, STKSIZE );
/* start the video writer thread */
vouthread = _dosbeginthread( vidout, STKSIZE, &voutstk );
if ( !vouthread )
errexit( "Can't create Video output thread" );
/* start port reader thread */
cinthread = _dosbeginthread( comin, STKSIZE, &cominstk );
if ( !cinthread )
errexit( "Can't create COM output thread" );
/* start port writer thread */
couthread = _dosbeginthread( comout, STKSIZE, &comoutstk );
if ( !couthread )
errexit( "Can't create COM output thread." );
/* start the keyboard thread */
kbdthread = _dosbeginthread( kbdin, STKSIZE, &kbdinstk );
if ( !kbdthread )
errexit( "Can't create Keyboard thread" );
/* process cmdline filename : contains connect parms */
CurP = defile( argv[1] );
/* when definition completes, we are in terminal mode */
if ( keymode == command )
keymode = tty; /* set default if user has not */
/* wait for Alt-X from comout */
DosSemWait( (HSEM) &exitsem, -1L );
/* tell output threads to hike out */
DosWrite( vworkW, (PVOID) &termsg, sizeof(MsgH), (PUSHORT) &wrtl );
DosWrite( comoW, (PVOID) &termsg, sizeof(MsgH), (PUSHORT) &wrtl );
/* Do NOT DosClose the COM handle, because it waits on
a timeout before closing. If we just exit the program
OS/2 cleanup does the right thing. I think we must set the
DCB for no timeout or set off DTR, but I don't know */
/* close pipes */
DosClose( vworkR );
DosClose( vworkW );
DosClose( kbdinR );
DosClose( kbdinW );
DosClose( comoW );
DosClose( comoR );
DosClose( comiW );
DosClose( comiR );
emsg( "Terminating..." );
exit( 0 );
} /* end of main */