home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / PP0705.ZIP / XTYPE.C < prev   
C/C++ Source or Header  |  1988-03-15  |  2KB  |  75 lines

  1. /*---------------------------------------------------------------
  2.    XTYPE.C -- Demonstrates multiple threads of execution in OS/2
  3.               (C) 1988, Ziff-Davis Communications Company
  4.               PC Magazine * Programmed by Charles Petzold, 11/87
  5.   ---------------------------------------------------------------*/
  6.  
  7. #include <doscalls.h>
  8. #include <subcalls.h>
  9.  
  10. void far KeyWatchThread (void) ;
  11.  
  12. main (argc, argv)
  13.      int  argc ;
  14.      char *argv [] ;     {
  15.      unsigned char ThreadStack [1024] ;
  16.      char far      *Buffer ;     
  17.      unsigned int  Handle, Action, Selector,
  18.                    ThreadID, BytesRead, BytesWritten ;
  19.  
  20.      if (argc < 2)
  21.           {
  22.           puts ("Syntax: XTYPE filename") ;
  23.           return 1 ;
  24.           }
  25.  
  26.      if (DOSCREATETHREAD (KeyWatchThread, &ThreadID, ThreadStack + 1024))
  27.           {
  28.           puts ("XTYPE: Could not create thread") ;
  29.           return 1 ;
  30.           }
  31.  
  32.      if (DOSALLOCSEG (65535, &Selector, 0))
  33.           {
  34.           puts ("XTYPE: Cannot allocate memory for buffer") ;
  35.           return 1 ;
  36.           }
  37.  
  38.      Buffer = (char far *) ((long) Selector << 16) ;
  39.  
  40.      if (DOSOPEN (argv [1], &Handle, &Action, 0L, 0, 1, 0x20, 0L))
  41.           {
  42.           puts ("XTYPE: File not found or cannot be opened") ;
  43.           DOSFREESEG (Selector) ;
  44.           return 0 ;
  45.           }
  46.  
  47.      DOSREAD (Handle, Buffer, 65535, &BytesRead) ;
  48.  
  49.      while (BytesRead > 0)
  50.           {
  51.           DOSWRITE (1, Buffer, BytesRead, &BytesWritten) ;
  52.  
  53.           DOSREAD (Handle, Buffer, 65535, &BytesRead) ;
  54.           }
  55.  
  56.      DOSCLOSE (Handle) ;
  57.      DOSFREESEG (Selector) ;
  58.      return 0 ;
  59.      }
  60.  
  61. void far KeyWatchThread ()
  62.      {
  63.      struct KeyData kd ;
  64.  
  65.      while (1)
  66.           {
  67.           KBDCHARIN (&kd, 0, 0) ;
  68.           DOSSUSPENDTHREAD (1) ;
  69.  
  70.           KBDCHARIN (&kd, 0, 0) ;
  71.  
  72.           DOSRESUMETHREAD (1) ;
  73.           }
  74.      }
  75.