home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / extras / ttx / rexx / ttx_sasc / MiddleMan.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1996-12-24  |  3.4 KB  |  151 lines

  1. /*
  2. **  $VER: Midddleman.rexx 2.1 (17.8.93)
  3. **  By Kenneth Yarnall.  This code may be freely distributed.
  4. **
  5. **  Middleman arbitrates between TTX and SCmsg.  For various reasons, SCmsg
  6. ** cannot talk directly to TTX in a clean way (it expects an editor to have
  7. ** a single ARexx port, while TTX has a separate port for each document.
  8. ** You can kludge your way around this, but it isn't any fun).  Middleman
  9. ** sets up a single port (TTX_SASC) for SCmsg to communicate with, and keeps
  10. ** track of the appropriate port with which to babble at TTX.  It opens files
  11. ** as necessary, etc.
  12. **
  13. **  If you want to close MiddleMan down, send it the ARexx command QUIT.  The
  14. ** little script KillMM.rexx will do this for you, or you can do it directly
  15. ** from a WSHell commandline.
  16. */
  17.  
  18. False = 0
  19. True = 1
  20.  
  21. Options RESULTS
  22.  
  23. /* Make sure support library is open. */
  24.  
  25. if ~Show('L',"rexxsupport.library") then do
  26.     if ~addlib("rexxsupport.library",0,-30,0) then
  27.         exit 10
  28. end
  29.  
  30. Call OpenTTX
  31.  
  32. /*
  33. **   If a filename was passed in, open that file. Note that we leave the
  34. ** quote marks around the name here, as they get stripped off later.
  35. */
  36.  
  37. Parse ARG fullname
  38.  
  39. if fullname ~= "" then
  40.     Call OpenFile fullname
  41.  
  42. /*
  43. **   Create our message port.  This is the one that
  44. ** SCmsg will talk to.
  45. */
  46.  
  47. if ~OpenPort('TTX_SASC') then
  48.     exit 10
  49.  
  50. /* Sit back and wait for messages. */
  51.  
  52. Done = False
  53. do until Done
  54.     WaitPkt('TTX_SASC')
  55.     Empty = False
  56.     do until Empty
  57.         msg = GetPkt('TTX_SASC')
  58.         if msg = '00000000'X then
  59.             Empty = True
  60.         else do
  61.             Parse VALUE GetArg(msg) WITH command arg1
  62.             Reply(msg,0)
  63.             command = Upper(command)
  64.             Select
  65.                 When command = 'QUIT' then    /* These perform the various  */
  66.                     Done = True               /* functions that Middleman   */
  67.                 When command = 'OPEN' then do /* can handle. Easy to extend */
  68.                     /* Could TTX have been closed in the meantime? */
  69.                     Call OpenTTX
  70.                     Call OpenFile arg1
  71.                 end
  72.                 When command = 'MOVE' then
  73.                     Call MoveToLine arg1
  74.                 Otherwise
  75.                     NOP
  76.             end
  77.         end
  78.     end
  79. end
  80.  
  81. ClosePort('TTX_SASC')
  82.  
  83. exit 0
  84.  
  85.  
  86.  
  87. /* Make sure TTX is afire */
  88.  
  89. OpenTTX:
  90.  
  91. if ~show('P', 'TURBOTEXT') then do
  92.     Address COMMAND
  93.     'run TTX NOWINDOW BACKGROUND'   /* run TTX.  Needs to be in the path   */
  94.     'WaitForPort' 'TURBOTEXT'       /* WaitForPort needs to be in the path */
  95.     if RC ~= 0 then do              /* couldn't find TTX                   */
  96.         exit 10
  97.     end
  98. end
  99.  
  100. Return
  101.  
  102. /*
  103. **  This ditty opens a turbotext window containing the file that is
  104. ** passed in as the argument.  The portname of that port is stored in
  105. ** a clip, so that it can be accessed at any time.
  106. */
  107.  
  108. OpenFile: Procedure
  109.  
  110. Parse ARG '"' fullname '"'
  111.  
  112. file = 'Rexx:TTX_SASC/GetFilePart'(fullname)
  113.  
  114. Address TURBOTEXT
  115.  
  116. Drop RESULT
  117. 'GetPort' file
  118. port = RESULT
  119.  
  120. if port = 'RESULT' then do
  121.     OpenDoc NAME fullname
  122.     port = RESULT
  123. end
  124.  
  125. Address VALUE port
  126. 'Window2Front'
  127.  
  128. SetClip('Actual_TTX_SASC_Port', port)
  129.  
  130. Return
  131.  
  132.  
  133.  
  134.  
  135. /*
  136. **  MoveToLine tells the current port to move to the
  137. ** appropriate line.  I bet you coulda figured that
  138. ** one out yourself.
  139. */
  140.  
  141. MoveToLine: Procedure
  142.  
  143. Parse ARG lineno
  144.  
  145. port = GetClip('Actual_TTX_SASC_Port')
  146.  
  147. Address VALUE port
  148. 'Move' lineno
  149.  
  150. Return
  151.