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 / LookUpHeader.ced < prev    next >
Text File  |  1989-12-29  |  3KB  |  155 lines

  1. /************************************************************************
  2.  *
  3.  * LookUpHeader.ced                    Copyright (c) 1989, Peter Cherna
  4.  *
  5.  * ARexx program for CygnusEd Professional that looks up the word under
  6.  * the cursor in the compiler headers.
  7.  *
  8.  * Version 1.45:  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.     address command 'WBTF'
  73.     say 'Searching for structure/#define' target '...'
  74.     utarget = upper(target)
  75.     sourcefile = 'ch:Index/Index' || left(target,1)
  76.     if exists(sourcefile) then
  77.     DO
  78.         call open 'searchfile', sourcefile
  79.         done = 0
  80.         DO until (done ~= 0)
  81.             searchline = readln('searchfile')
  82.             if eof('searchfile') then
  83.                 done = 2
  84.             else
  85.             DO
  86.                 parse upper var searchline match '; ' .
  87.                 if utarget = match then
  88.                     done = 1
  89.             END
  90.         END
  91.         call close 'searchfile'
  92.         if done = 2 then
  93.         DO
  94.             cedtofront
  95.             okay1 'Could not find' target 'in header files.'
  96.             exit
  97.         END
  98.         else
  99.         DO
  100.             parse var searchline match '; ' headerfile '; ' line
  101.             /*  If we have a help file displayed, use its window,
  102.                 else open a new one: */
  103.  
  104.             helpfile = getclip('HelpWindow')
  105.             /*    Get current file's name */
  106.             status 21
  107.             if helpfile ~= result then
  108.             DO
  109.                 /* Find out how many views are displayed */
  110.                 status 66
  111.  
  112.                 /* Try to find the view containing the help file */
  113.                 DO numwins=result-1 to 1 by -1 until result = helpfile
  114.                     next view
  115.                     /*    Get current file's name */
  116.                     status 21
  117.                 END
  118.             END
  119.  
  120.             /* If we can't find the file, then ask to open it */
  121.             if result ~= helpfile then
  122.             DO
  123.                 next view        /* bring back to original view */
  124.                 open new
  125.             END
  126.             else
  127.             DO
  128.                 /*    Only replace this file if there have been no
  129.                     changes.  Get number of changes: */
  130.                 status 18
  131.                 if result ~= 0 then
  132.                 DO
  133.                     next view
  134.                     open new
  135.                 END
  136.             END
  137.  
  138.             cedtofront
  139.             /*    Set tab size to eight: */
  140.             menu 2 1 7
  141.             open headerfile
  142.             jumpto line 1
  143.             /*    Save file name of the Help Window */
  144.             status 21
  145.             call setclip 'HelpWindow',result
  146.         END
  147.     END
  148.     else
  149.     DO
  150.         cedtofront
  151.         okay1 'Could not find' target 'in header files.'
  152.     END
  153. END
  154. exit
  155.