home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / bbs / termv4.6 / extras / source / term-source.lha / EmulationProcess.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-18  |  1.9 KB  |  135 lines

  1. /*
  2. **    EmulationProcess.c
  3. **
  4. **    Terminal emulation process
  5. **
  6. **    Copyright © 1990-1996 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #ifndef _GLOBAL_H
  11. #include "Global.h"
  12. #endif
  13.  
  14. STATIC struct Process *EmulationProcess;
  15.  
  16. STATIC VOID __saveds
  17. EmulationProcessEntry(VOID)
  18. {
  19.     if(TerminalQueue = CreateMsgQueue(NULL,40))
  20.     {
  21.         ULONG         Mask = SIG_KILL | TerminalQueue -> SigMask;
  22.         struct DataMsg    *Msg;
  23.         struct MsgQueue    *Queue = TerminalQueue;
  24.         BOOL         Done = FALSE;
  25.  
  26.         EmulationProcess = (struct Process *)FindTask(NULL);
  27.  
  28.         Signal(ThisProcess,SIG_HANDSHAKE);
  29.  
  30.         do
  31.         {
  32.             if(Wait(Mask) & SIG_KILL)
  33.             {
  34.                 Forbid();
  35.  
  36.                 TerminalQueue = NULL;
  37.  
  38.                 Permit();
  39.  
  40.                 break;
  41.             }
  42.  
  43.             ObtainSemaphore(&TerminalSemaphore);
  44.  
  45.             ClearCursor();
  46.  
  47.             while(Msg = GetMsgItem(TerminalQueue))
  48.             {
  49.                     /* Remember the data. */
  50.  
  51.                 if(RememberOutput)
  52.                     RememberOutputText(Msg -> Data,Msg -> Size);
  53.  
  54.                 (*ConProcessData)(Msg -> Data,Msg -> Size);
  55.  
  56.                 DeleteMsgItem(Msg);
  57.  
  58.                 if(SetSignal(0,0) & SIG_KILL)
  59.                 {
  60.                     Forbid();
  61.  
  62.                     TerminalQueue = NULL;
  63.  
  64.                     Permit();
  65.  
  66.                     Done = TRUE;
  67.  
  68.                     break;
  69.                 }
  70.             }
  71.  
  72.             DrawCursor();
  73.  
  74.             ReleaseSemaphore(&TerminalSemaphore);
  75.         }
  76.         while(!Done);
  77.  
  78.         while(Msg = GetMsgItem(Queue))
  79.             DeleteMsgItem(Msg);
  80.  
  81.         DeleteMsgQueue(Queue);
  82.     }
  83.  
  84.     Forbid();
  85.  
  86.     EmulationProcess = NULL;
  87.  
  88.     Signal(ThisProcess,SIG_HANDSHAKE);
  89. }
  90.  
  91. VOID
  92. DeleteEmulationProcess()
  93. {
  94.     if(EmulationProcess)
  95.     {
  96.         Forbid();
  97.  
  98.         Signal(EmulationProcess,SIG_KILL);
  99.  
  100.         ClrSignal(SIG_HANDSHAKE);
  101.  
  102.         Wait(SIG_HANDSHAKE);
  103.  
  104.         Permit();
  105.     }
  106. }
  107.  
  108. BOOL
  109. CreateEmulationProcess()
  110. {
  111.     if(!EmulationProcess)
  112.     {
  113.         Forbid();
  114.  
  115.         if(CreateNewProcTags(
  116.             NP_Name,    "term Emulation Process",
  117.             NP_Entry,    EmulationProcessEntry,
  118.             NP_StackSize,    8000,
  119.             NP_WindowPtr,    Window,
  120.         TAG_DONE))
  121.         {
  122.             ClrSignal(SIG_HANDSHAKE);
  123.  
  124.             Wait(SIG_HANDSHAKE);
  125.         }
  126.  
  127.         Permit();
  128.     }
  129.  
  130.     if(EmulationProcess)
  131.         return(TRUE);
  132.     else
  133.         return(FALSE);
  134. }
  135.