home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / STERM.ZIP / STERM.C < prev    next >
Text File  |  1991-01-14  |  5KB  |  163 lines

  1.  
  2. /*
  3.    STERM.C
  4.  
  5.    An attempt at a communications program in C for OS2 which
  6.    will eventually provide a file-transmit pipe to the IBM mainframe
  7.    and/or support SIMWARE's fullscreen mode
  8.  
  9.    Usage:  STERM control-file
  10.            where the specified control file contains
  11.            baud-rate databits parity stopbits port, etc.
  12. */
  13.  
  14. #define MAIN                 /*  this is the main function */
  15.  
  16.  
  17.  
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <stdio.h>
  21. #include <process.h>
  22. #define  INCL_SUB
  23. #define  INCL_DOS
  24. #include <os2kernl.h>
  25. #include "sterm.h"
  26.  
  27.  
  28.  
  29. /* Display an error msg (TTY mode ) */
  30. AREF void emsg( char *msg )
  31.   {
  32.   VioWrtTTY( (PCH) msg, strlen( msg ), 0 );
  33.   VioWrtTTY( (PCH) "\n\r", 2, 0 );
  34.   }
  35.  
  36. /* exit with error message */
  37. AREF void errexit(char *msg)
  38.   {
  39.   emsg( msg );
  40.   exit( 1 );
  41.   }
  42.  
  43.  
  44.  
  45. void main( int argc, char *argv[] )
  46.   {
  47.  
  48.   /* our principal set of threads */
  49.   UINT     cinthread;        /* input thread TID */
  50.   UINT     couthread;        /* output thread TID */
  51.   UINT     vouthread;        /* video thread TID */
  52.   UINT     kbdthread;        /* keybd  thread TID */
  53.  
  54.   /* and their stacks */
  55.   UINT     cominstk;         /* input thread stack token */
  56.   UINT     comoutstk;        /* output thread stack token */
  57.   UINT     voutstk;          /* video thread TID */
  58.   UINT     kbdinstk;         /* keybd  thread TID */
  59.  
  60.   #define STKSIZE 4096
  61.   MsgH   termsg = { termin, 1, ' ' };  /* termination msg */
  62.   UINT   wrtl;               /* DosWrite charcount */
  63.  
  64.  
  65.  
  66.   /************************ end main autovariables ***********/
  67.  
  68.  
  69.   emsg( "STERM: v 0.0" );
  70.  
  71.  
  72.  
  73.   if ( argc < 2 )
  74.      errexit( "Definition file not given." );
  75.  
  76.   CurP = NULL;              /* port not defined */
  77.   keymode = ignore;         /* do not put to port */
  78.   ComLog = FALSE;           /* default of no logging */
  79.   waitlen = 0;              /* no string to wait on */
  80.   Sim3270 = vtkey;          /* default 3270 tbl */
  81.   insmode = FALSE;          /* insert mode off */
  82.   xstate = TERM;            /* normal transmit state */
  83.   blkp = NULL;              /* no transmit data */
  84.   timelim = TIMELIM;        /* set await default */
  85.  
  86.   /* initialize screen */
  87.   fldmono = fldcolor = 0x07;
  88.   clrscrn();
  89.  
  90.   /* set default strings */
  91.   strcpy( initstr, "ATZ" ); /* modem init */
  92.   strcpy( waitstr, "OK" );  /* modem ready */
  93.  
  94.   /* declare the EOJ semaphore */
  95.   exitsem = 0L;  readsem = 0L;
  96.   DosSemSet( (HSEM) &exitsem );
  97.   DosSemSet( (HSEM) &readsem ); /* declare port read gate */
  98.  
  99.   /* open the set of pipes */
  100.   DosMakePipe( (PUSHORT) &vworkR, (PUSHORT) &vworkW, STKSIZE );
  101.   DosMakePipe( (PUSHORT) &kbdinR, (PUSHORT) &kbdinW, STKSIZE );
  102.   DosMakePipe( (PUSHORT) &comiR, (PUSHORT) &comiW, STKSIZE );
  103.   DosMakePipe( (PUSHORT) &comoR, (PUSHORT) &comoW, STKSIZE );
  104.  
  105.   /* start the video writer thread */
  106.   vouthread = _dosbeginthread( vidout, STKSIZE, &voutstk );
  107.   if ( !vouthread )
  108.      errexit( "Can't create Video output thread" );
  109.  
  110.   /* start port reader thread */
  111.   cinthread = _dosbeginthread( comin, STKSIZE, &cominstk );
  112.   if ( !cinthread )
  113.      errexit( "Can't create COM output thread" );
  114.  
  115.   /* start port writer thread */
  116.   couthread = _dosbeginthread( comout, STKSIZE, &comoutstk );
  117.   if ( !couthread )
  118.      errexit( "Can't create COM output thread." );
  119.  
  120.   /* start the keyboard thread */
  121.   kbdthread = _dosbeginthread( kbdin, STKSIZE, &kbdinstk );
  122.   if ( !kbdthread )
  123.      errexit( "Can't create Keyboard thread" );
  124.  
  125.   /* process cmdline filename : contains connect parms */
  126.   CurP = defile( argv[1] );
  127.   /* when definition completes, we are in terminal mode */
  128.   if ( keymode == command )
  129.      keymode = tty;  /* set default if user has not */
  130.  
  131.  
  132.  
  133.   /* wait for Alt-X from comout */
  134.   DosSemWait( (HSEM) &exitsem, -1L );
  135.  
  136.   /* tell output threads to hike out */
  137.   DosWrite( vworkW, (PVOID) &termsg, sizeof(MsgH), (PUSHORT) &wrtl );
  138.   DosWrite( comoW, (PVOID) &termsg, sizeof(MsgH), (PUSHORT) &wrtl );
  139.  
  140.   /* Do NOT DosClose the COM handle, because it waits on
  141.      a timeout before closing. If we just exit the program
  142.      OS/2 cleanup does the right thing.  I think we must set the
  143.      DCB for no timeout or set off DTR, but I don't know */
  144.  
  145.   /* close pipes */
  146.   DosClose( vworkR );
  147.   DosClose( vworkW );
  148.   DosClose( kbdinR );
  149.   DosClose( kbdinW );
  150.   DosClose( comoW );
  151.   DosClose( comoR );
  152.   DosClose( comiW );
  153.   DosClose( comiR );
  154.  
  155.   emsg( "Terminating..." );
  156.  
  157.   exit( 0 );
  158.   }  /* end of main */
  159.  
  160.  
  161.  
  162.  
  163.