home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 164.lha / ARexx / RefMacro_ARexx / Ref_II / reference.txed < prev    next >
Encoding:
Text File  |  1988-04-28  |  4.2 KB  |  136 lines

  1. /*    
  2. *    Reference Macro for TxEd.  Supposed to work like the
  3. *    reference utility in dme.  REQUIRES THE FULL AREXX SYSTEM
  4. *    TO WORK.  (rename file to reference.txed)
  5. */
  6.  
  7. /* I prefer to check for errors manually. (jac) */
  8. /* SIGNAL ON ERROR    */      /* catch any errors */
  9. /* OPTIONS FAILAT 60    */      /* but don't die and go away */
  10.  
  11. OPTIONS RESULTS        
  12.  
  13. 'WORD'        /*  This little move (he he) puts the cursor at the    */
  14. MWORD        /*  beginning of the word, even if it's not originally     */
  15.                                                            /* jac */
  16.  
  17. MARK 1        /* get the current word from TxEd */
  18. 'WORD'
  19. 'COPY +X'
  20. 'STATUS M+X'
  21.  
  22. /* In case the cursor was positioned on some white space: */
  23.  
  24. find = strip(result,,' ')   /* strip character is a blank */
  25. find = strip(find,,'09'x)   /* strip character is a tab   */
  26.  
  27. /* put a nice message on the txed window */
  28.  
  29. line = "Attempting to reference" find
  30. msg line
  31.  
  32. /* Extract the 'stuff' if it exists. If an error is encountered  */
  33. /* here, call ERROR:                                             */
  34.  
  35. address COMMAND 'getrefs' find    
  36.  
  37. if rc > 0 then 
  38.   call ERROR
  39. else nop                           /* A reference exists */
  40.  
  41. /* Check to see if the reference window has been opened, */
  42. /* and if so, is it still open.                          */
  43.  
  44. alreadyopen = 0
  45. newtxed = getclip("Reference")
  46. if length(newtxed) > 0 then do          /* The reference window has been    */
  47.                                         /*   previously opened.             */
  48.   portlist = showlist('P')              /* Check to see if it's still there.*/
  49.   testfile = index(portlist,newtxed)
  50.   if testfile = 0 then                    /* Nope -- open it.                 */
  51.     newtxed = OpenRefTxEd()              
  52.   else 
  53.     alreadyopen = 1
  54.   end
  55.  
  56. else                    /* No window open -- open it.       */
  57.   newtxed = OpenRefTxEd()  
  58.  
  59. if newtxed = "1" then do                /* Couldn't open new window.        */
  60.   line = "Can't open new TxEd window"
  61.   msg line
  62.   exit
  63. end
  64.  
  65. /* Tell new txed to move to top of screen and display extracted text */
  66. /* this particular set of commands will display the function call    */
  67. /* template if you are referencing the autodocs.  change to taste    */
  68.  
  69. address value newtxed
  70.  
  71. 'load ram:extract.txt'
  72. top
  73. down 4
  74.  
  75. /*
  76.       Now tell the original txed to get out of the way and
  77.     activate itself This is a kludge since you might have resized
  78.     the main TxEd window. It would be nice if there were a call
  79.     that would return the current window size. 
  80. */ 
  81.  
  82. if ~alreadyopen then do
  83.   address
  84.   'window 0 2 640 109'
  85. end
  86.  
  87. /* be nice and tidy by deleteing the temporary file */
  88.  
  89. address COMMAND 'delete ram:extract.txt'
  90.  
  91. exit
  92.  
  93.  
  94. /*==========================================================================*/
  95. /* This function opens a new TxEd window, wait's for it to                  */
  96. /* get set up, and then returns its address.                                */
  97. /*==========================================================================*/
  98.  
  99. OpenRefTxEd: procedure
  100.  
  101.     trace results
  102.  
  103.     line = setclip("Reference","1")
  104.     address COMMAND "e STARTUP refstartup"
  105.  
  106.     newtxed = "1"
  107.     do for 20 until newtxed ~= "1"
  108.       address COMMAND 'c:wait'
  109.       newtxed = getclip("Reference")    /* get address of new txed */
  110. /*      if newtxed ~= "1" then leave */
  111.     end
  112.  
  113.     return newtxed
  114.  
  115.  
  116. /*==========================================================================*/
  117. /* Error handling.  The error code will be in the variable rc so we can     */
  118. /* construct a specific error message to send back to the original txed.    */
  119. /*==========================================================================*/
  120.  
  121. ERROR:
  122.  
  123. select
  124.         when rc = 1  then line = "Can't fine GetRefs!"
  125.     when rc = 50 then line = "Bad command line to GetRefs command"
  126.     when rc = 51 then line = "Can't open reference file TxEd.refs"
  127.     when rc = 52 then line = "Reference string" find "was not found"
  128.     when rc = 53 then line = "Bad line format in TxEd.refs - couldn't decode"
  129.     when rc = 54 then line = "Can't open reference source file"
  130.     when rc = 55 then line = "Can't find referenced text"
  131.     when rc = 56 then line = "Can't open ram:extract.txt - bad news"
  132.     otherwise line = "Unrecognized error - something is very wrong"
  133. end
  134. msg line
  135. exit /* We don't exit with an error code since that erases our nice message. */
  136.