home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff297.lzh / DevKit / Rexx / LookUpTag.ced < prev    next >
Text File  |  1989-12-29  |  3KB  |  140 lines

  1. /************************************************************************
  2.  *
  3.  * LookUpTag.ced                    Copyright (c) 1989, Peter Cherna
  4.  *
  5.  * ARexx program for CygnusEd Professional that looks up the word under
  6.  * the cursor in the tags file in the directory of the current file.
  7.  *
  8.  * Version 1.05:  August 28, 1989    Release 1.2:  August 29, 1989
  9.  *
  10.  ************************************************************************/
  11.  
  12. options results
  13.  
  14. address 'rexx_ced'
  15.  
  16. tabchar = '09'X
  17.  
  18. /*    Get contents of current line: */
  19. status 55
  20. line = result
  21.  
  22. /*    Get tab size: */
  23. status 8
  24. tabadjust = result - 1
  25.  
  26. /*    Get cursor x position (relative to beginning of line = 1): */
  27. status 46
  28. cur = result + 1
  29.  
  30. i = index(line,tabchar)
  31. DO while i > 0 & i <= cur - tabadjust
  32.     cur = cur - tabadjust
  33.     i = index(line,tabchar,i+1)
  34. END
  35.  
  36. /*    If the current character is non-alphabetic, then start one character
  37.     over to the left.  This allows the cursor to be immediately after
  38.     the key word (say on a space or bracket.) */
  39.  
  40. char = substr(line,cur,1)
  41. if (~(datatype(char,'A') | char = '_') & cur > 1) then
  42.     cur = cur - 1
  43.  
  44. /*    Find leftmost and rightmost alphabetic character adjacent to current: */
  45. right = cur - 1
  46. left = cur + 1
  47. char = 'A'
  48. DO while (datatype(char,'A') | char = '_') & (left > 0)
  49.      left = left - 1
  50.     if left > 0 then
  51.         char = substr(line,left,1)
  52. END
  53. char = 'A'
  54. DO while (datatype(char,'A') | (char = '_'))
  55.     right = right + 1
  56.     char = substr(line,right,1)
  57. END
  58.  
  59. if right-left <= 1 then
  60. DO
  61.     getstring
  62.     target = result
  63.     if (target = 'RESULT') then
  64.         exit
  65. END
  66. else
  67. DO
  68.     target = substr(line,left+1,right-left-1)
  69. END
  70.  
  71. DO
  72.     /*  Get current directory: */
  73.     status 20
  74.     currdir = result
  75.     if (right(currdir,1) ~= ':') then
  76.         currdir = currdir || '/'
  77.     utarget = upper(target)
  78.     sourcefile = currdir || 'tags'
  79.     if exists(sourcefile) then
  80.     DO
  81.         call open 'searchfile', sourcefile
  82.         done = 0
  83.         DO until (done ~= 0)
  84.             searchline = readln('searchfile')
  85.             if eof('searchfile') then
  86.                 done = 2
  87.             else
  88.             DO
  89.                 parse upper var searchline function '; ' .
  90.                 if utarget = function then
  91.                     done = 1
  92.             END
  93.         END
  94.         call close 'searchfile'
  95.         if done = 2 then
  96.         DO
  97.             okay1 'No tag found for' target || '.'
  98.             exit
  99.         END
  100.         else
  101.         DO
  102.             parse var searchline function '; ' targetfile '; ' line
  103.             targetfile = currdir || targetfile
  104.  
  105.             /*  If the file is already displayed, use it,
  106.                 else open it into a new window: */
  107.  
  108.             /*    Get current file's path & name */
  109.             status 19
  110.             if upper(targetfile) ~= upper(result) then
  111.             DO
  112.                 /* Find out how many views are displayed */
  113.                 status 66
  114.  
  115.                 /* Try to find the view containing the file */
  116.                 DO numwins=result-1 to 1 by -1 until upper(result) = upper(targetfile)
  117.                     next view
  118.                     /*    Get current file's path & name */
  119.                     status 19
  120.                 END
  121.             END
  122.  
  123.             /* If we can't find the file, then ask to open it */
  124.             if upper(result) ~= upper(targetfile) then
  125.             DO
  126.                 next view        /* bring back to original view */
  127.                 open new
  128.                 open targetfile
  129.             END
  130.  
  131.             jumpto line 1
  132.         END
  133.     END
  134.     else
  135.     DO
  136.         okay1 'Tags not found.'
  137.     END
  138. END
  139. exit
  140.