home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / lpcs / LPS.OPL < prev    next >
Text File  |  1994-05-11  |  3KB  |  123 lines

  1. rem -- Original code written in C by Colly
  2. rem -- Adapted and translated into OPL by Tom Dolbilin
  3. rem -- Version 1.0
  4.  
  5. PROC main:
  6. local pM%        rem Pointer to MESS struct
  7. local clntPid%        rem PID of Bring client
  8. local wsrvPid%        rem PID of Window server
  9. local buf$(255)        rem Buffer to send data from
  10. local fmt&        rem Message buffer
  11. local state%        rem Server state
  12. local mtype%        rem Message type
  13. local arg1%, arg2%    rem Message arguments
  14. local mStat%, kStat%, event%(6)
  15. local ret%, name$(15)
  16.  
  17. print "Link Paste Server 1.0"
  18. print "Press Psion-Esc to exit"
  19.  
  20. rem --- Initialise messaging with MessInit
  21. ret% = call( $83, $404, 0, 0, 0, 0 )
  22. if ret% < 0
  23.     panic:( "Failed to initialise messaging", ret% )
  24. endif
  25.  
  26. rem --- Get Window Server's pid
  27. name$ = "SYS$WSRV.*"
  28. wsrvPid% = call( $188, addr( name$ ) + 1 )
  29.  
  30. rem -- Queue console event
  31. ioa( -2, 14, kStat%, event%(1), #0 )
  32.  
  33. call( $183, addr( pM% ), 0, 0, 0, addr( mStat% ) ) rem MessReceiveAsynchronous
  34.  
  35. while 1
  36.     iowait
  37.     if mStat% <> -46
  38.  
  39.         rem --- We have received a message
  40.         if mStat% <> 0 : panic:( "Bad message", ret% ) : endif
  41.         mtype% = peekw( pM% + 4 )
  42.         arg1% = peekw( pM% + 8 )
  43.         arg2% = peekw( pM% + 10 )
  44.  
  45.         if mtype% = $21
  46.             rem --- Someone wants some data
  47.             if clntPid% = 0
  48.                 rem --- First request
  49.                 fmt& = peekl( addr( arg1% ) )
  50.                 ret% = -4
  51.                 if fmt& and 7 : rem Do we support the requested format?
  52.                     clntPid% = peekw( pM% + 6 )
  53.                     rem Have WServer inform us if the client dies
  54.                     call( $883, clntPid%, $22 )
  55.                     state% = 0
  56.                     ret% = 0
  57.                 endif
  58.             else
  59.                 rem --- Subsequent request
  60.                 if arg1% = 0
  61.                     rem --- Client requests no data
  62.                     state% = 1
  63.                 endif
  64.  
  65.                 if state%
  66.                     rem --- End of conversation
  67.                     ret% = -36
  68.                     rem No longer interested if the client dies
  69.                     call( $983, clntPid%, $22 )
  70.                     clntPid% = 0
  71.                 else
  72.                     rem --- Send information over to client
  73.                     buf$ = datim$ : rem Create dummy information
  74.                     ret% = min( len( buf$ ), arg2% ) : rem How much to send
  75.                     call( $92, clntPid%, ret%, 0, addr( buf$ ) + 1, arg1% ) rem ProcCopyToById
  76.                     state% = state% + 1
  77.                 endif
  78.             endif
  79.  
  80.         elseif mtype% = $22
  81.             rem --- Our client has died
  82.             clntPid% = 0
  83.  
  84.         else
  85.             rem --- Unsupported message
  86.             ret% = -4
  87.         endif
  88.  
  89.         call( $783, pM%, ret% ) rem MessFree
  90.  
  91.         rem --- Get another message
  92.         call( $183, addr( pM% ), 0, 0, 0, addr( mStat% ) ) rem MessReceiveAsynchronous
  93.  
  94.     elseif kStat% <> -46
  95.         rem --- We have received a console event
  96.         if kStat% <> 0 : panic:( "Bad event", ret% ) : endif
  97.  
  98.         if event%(1) = $402
  99.             rem --- Going to background
  100.             fmt& = $16 rem Prepared to render in any format
  101.             rem --- Inform the window server
  102.             ret% = call( $683, wsrvPid%, 3, 0, addr( fmt& ) ) rem MessSendReceiveWithWait
  103.             if ret% < 0
  104.                 panic:( "", ret% )
  105.             endif
  106.         endif
  107.  
  108.         rem Queue another console event
  109.         ioa( -2, 14, kStat%, event%(1), #0 )
  110.     endif
  111. endwh
  112. get
  113. ENDP
  114.  
  115. PROC panic:( mess$, err% )
  116. print mess$
  117. if err%
  118.     print err$( err% )
  119. endif
  120. get
  121. stop
  122. ENDP
  123.