home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d8xx / d832 / term.lha / Term / term-3.1-Source.lha / termResponse.c < prev    next >
C/C++ Source or Header  |  1993-02-12  |  3KB  |  136 lines

  1. /*
  2. **    termResponse.c
  3. **
  4. **    Signal event handling routines
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Yet another function pointer. */
  13.  
  14. typedef BYTE (* RESPONSE)(VOID);
  15.  
  16.     /* Signal response table entry. */
  17.  
  18. struct SignalResponseInfo
  19. {
  20.     RESPONSE    Routine;
  21.     ULONG        Mask;
  22.     BYTE        Loop;
  23. };
  24.  
  25.     /* Signal response table. */
  26.  
  27. STATIC struct SignalResponseInfo    ResponseTable[10];
  28. STATIC WORD                ResponseCount;
  29. STATIC ULONG                ResponseMask;
  30.  
  31.     /* AddResponse(RESPONSE Routine,ULONG Mask,BYTE Loop):
  32.      *
  33.      *    Register a signal response routine.
  34.      */
  35.  
  36. STATIC VOID __regargs
  37. AddResponse(RESPONSE Routine,ULONG Mask,BYTE Loop)
  38. {
  39.     ResponseTable[ResponseCount] . Routine    = Routine;
  40.     ResponseTable[ResponseCount] . Mask    = Mask;
  41.     ResponseTable[ResponseCount] . Loop    = Loop;
  42.  
  43.     ResponseMask |= Mask;
  44.  
  45.     ResponseCount++;
  46. }
  47.  
  48.     /* HandleResponse():
  49.      *
  50.      *    Register routines and corresponding signals,
  51.      *    wait for events and process them.
  52.      */
  53.  
  54. VOID
  55. HandleResponse()
  56. {
  57.     register ULONG    SignalSet;
  58.     register BYTE    Running;
  59.     register WORD    Margin,i;
  60.  
  61.     ResponseMask    = NULL;
  62.     ResponseCount    = 0;
  63.  
  64.     if(WriteRequest)
  65.         AddResponse((RESPONSE)HandleSerialCheck,SIG_CHECK,FALSE);
  66.  
  67.     if(WorkbenchPort)
  68.         AddResponse((RESPONSE)HandleWorkbenchWindow,SIG_WORKBENCH,FALSE);
  69.  
  70.     if(XEM_Signal)
  71.         AddResponse((RESPONSE)HandleExternalEmulation,XEM_Signal,FALSE);
  72.  
  73.     AddResponse((RESPONSE)HandleClipboard,SIG_CLIP,FALSE);
  74.  
  75.     AddResponse((RESPONSE)ClearAudio,SIG_AUDIO,FALSE);
  76.  
  77.     Margin = ResponseCount;
  78.  
  79.     if(ReadPort && Status != STATUS_HOLDING)
  80.         AddResponse(HandleSerial,SIG_SERIAL,TRUE);
  81.  
  82.     AddResponse(HandleWindow,SIG_WINDOW,TRUE);
  83.  
  84. #ifdef USE_AREXX
  85.  
  86.     if(TermRexxPort)
  87.         AddResponse(HandleRexx,SIG_REXX,TRUE);
  88.  
  89. #endif    /* USE_AREXX */
  90.  
  91.     if(PacketWindow)
  92.         AddResponse(HandlePacket,SIG_PACKET,TRUE);
  93.  
  94.     if(ReviewPort)
  95.         AddResponse(HandleReview,SIG_REVIEW,TRUE);
  96.  
  97.         /* Wait for events. */
  98.  
  99.     if(HostReadBuffer)
  100.     {
  101.         if(ReadPort && Status != STATUS_HOLDING)
  102.             SignalSet = CheckSignal(ResponseMask) | SIG_SERIAL;
  103.         else
  104.             SignalSet = CheckSignal(ResponseMask);
  105.     }
  106.     else
  107.         SignalSet = Wait(ResponseMask);
  108.  
  109.         /* Handle single-shot events. */
  110.  
  111.     for(i = 0 ; i < Margin ; i++)
  112.     {
  113.         if(SignalSet & ResponseTable[i] . Mask)
  114.             (*ResponseTable[i] . Routine)();
  115.     }
  116.  
  117.         /* Handle loop-fed events. */
  118.  
  119.     do
  120.     {
  121.         Running = FALSE;
  122.  
  123.         for(i = Margin ; !MainTerminated && i < ResponseCount ; i++)
  124.         {
  125.             if(SignalSet & ResponseTable[i] . Mask)
  126.             {
  127.                 if((*ResponseTable[i] . Routine)())
  128.                     Running = TRUE;
  129.                 else
  130.                     SignalSet &= ~ResponseTable[i] . Mask;
  131.             }
  132.         }
  133.     }
  134.     while(Running && !MainTerminated);
  135. }
  136.