home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / mprocs / evinit.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  90 lines

  1. ############################################################################
  2. #
  3. #    File:     evinit.icn
  4. #
  5. #    Subject:  Procedures for event monitoring
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     November 5, 1995
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This file provides initialization for event monitors.
  18. #
  19. #  This file is intended for use with event monitors running under
  20. #  MT Icon.
  21. #
  22. ############################################################################
  23.  
  24. $include "evdefs.icn"
  25.  
  26. procedure EvInit(f,input,output,error)
  27.    if not MTEvInit(f,input,output,error) then fail
  28.    return
  29. end
  30.  
  31. procedure EvTerm(win)
  32.   if &eventsource === (Monitored | EventSource) then {
  33.     if type(win) == "window" then
  34.       Event(win)
  35.     }
  36. end
  37. #
  38. # MultiThread EventMon support, from file mtsupport.icn
  39. #
  40.  
  41. global Monitored, EventSource, MTEventMask
  42.  
  43. #
  44. # If EvInit is called with a string or a list, run as a standalone MT-based
  45. # event monitor -- load the icode file and overload certain EvMon symbols.
  46. #
  47. # This operation is skipped if &eventsource has already been initialized,
  48. #  presumably by some event broker such as Eve.
  49. #
  50. procedure MTEvInit(f,input,output,error)
  51.  
  52.    if \&eventsource then return
  53.  
  54.    if type(f) == "string" then {
  55.       &eventsource := EventSource := Monitored := load(f,,input,output,error) | fail
  56.       EvGet     :=: MTEvGet
  57.       }
  58.    else if type(f) == "list" then {
  59.       &eventsource := EventSource := Monitored := load(f[1],f[2:0],input,output,error) | fail
  60.       EvGet     :=: MTEvGet
  61.       }
  62.    return &eventsource
  63. end
  64.  
  65. procedure MTEvGet(c,flag)
  66.    static lastcset
  67.    initial {
  68.       lastcset := ''
  69.       }
  70.  
  71.    if c ~=== lastcset then {
  72.      lastcset := c
  73.      eventmask(\(Monitored | EventSource) ,\c | &cset,&main)
  74.      }
  75.    return MTEvGet(c,flag)
  76. end
  77.  
  78. #
  79. # Eve-specific extensions to the general model
  80. #
  81. procedure EvQuit()
  82.   EvSignal("quit")
  83. end
  84.  
  85. procedure EvSignal(x)
  86.    if type(x) == "cset" then
  87.       write(&errout, "EvSignal(", image(x), ") is ambiguous.")
  88.    return x @ &eventsource
  89. end
  90.