home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR36 / KEXX.ZIP / CTAGS.KEX < prev    next >
Text File  |  1992-06-25  |  2KB  |  80 lines

  1. * Function: Locate the definition of the C function the cursor is on.
  2. * To run:   See CTAGS.DOC.
  3. * Requires: KEDIT 4.0 or later
  4. * Version:  1.1 (July 1988) by NBM
  5.  
  6. *  get name of data file
  7.    'editv get ctags_dat'
  8.    if ctags_dat = '' then ctags_dat = 'ctags.dat'
  9.  
  10. *  if an argument is supplied, use that as the function name
  11.    if arg() then word = arg(1)
  12.    else do
  13.  
  14.    *  if on a closing brace, find the open brace
  15.       if field.2() = ')' then do
  16.          'cmatch'
  17.          if rc \= 0 then exit
  18.          end
  19.  
  20.    *  if on an open brace, move one character to the left
  21.       if field.2() = '(' then 'cursor left'
  22.  
  23.    *  if not on a function name then abort
  24.       'extract /field'
  25.       if \datatype(field.2, 'a') & field.2 \= '_' then do
  26.          'emsg Cursor is not on a C function'
  27.          exit
  28.          end
  29.  
  30.    *  get the function name, abort if invalid
  31.       do endcol = field.3
  32.          c = substr(field.1, endcol, 1)
  33.          if \datatype(c, 'a') & c \= '_' then leave
  34.          end
  35.       if c \= '(' then do
  36.          'emsg Cursor is not on a C function'
  37.          exit
  38.          end
  39.       do startcol = field.3 to 1 by -1
  40.          c = substr(field.1, startcol, 1)
  41.          if \datatype(c, 'm') & c \= '_' then leave
  42.          end
  43.       startcol = startcol + 1
  44.       word = substr(field.1, startcol, endcol - startcol)
  45.       if \datatype(substr(word, 1, 1), 'm') then do
  46.          'emsg Cursor is not on a C function'
  47.          exit
  48.          end
  49.       end
  50.  
  51. *  edit the data file
  52.    original_fid = fileid.1()
  53.    'kedit' ctags_dat '(noprofile'
  54.    if rc \= 0 then exit rc
  55.    if size.1() = 0 then do
  56.       'qquit'
  57.       'kedit' original_fid
  58.       'emsg Data file' ctags_dat 'not found or empty'
  59.       exit
  60.       end
  61.  
  62. *  find the entry for this function, abort if unsuccessful
  63.    'tfind /'word
  64.    if rc \= 0 then do
  65.       'qquit'
  66.       'kedit' original_fid
  67.       'emsg Cound not find function "'word'" in data file' ctags_dat
  68.       exit
  69.       end
  70.    'extract /curline/'
  71.    target_file = word(curline.3, 2)
  72.    target_string = substr(curline.3, pos('?', curline.3) + 2)
  73.    target_string = substr(target_string, 1, length(target_string) - 2)
  74.    'qquit'
  75.  
  76. *  make the function definition the current line
  77.    'kedit' target_file
  78.    * version 1.1 fix: use "unusual" delimiter to minimize conflicts
  79.    'locate :1 tfind ⌠'target_string
  80.