File:  [gforth] / gforth / etags.fs
Revision 1.7: download - view: text, annotated - select for diffs
Sat Feb 8 22:58:10 1997 UTC (27 years, 1 month ago) by pazsan
Branches: MAIN
CVS tags: v0-3-0, HEAD
Merged in gforth-EC patches

    1: \ Etags support for GNU Forth.
    2: 
    3: \ Copyright (C) 1995 Free Software Foundation, Inc.
    4: 
    5: \ This file is part of Gforth.
    6: 
    7: \ Gforth is free software; you can redistribute it and/or
    8: \ modify it under the terms of the GNU General Public License
    9: \ as published by the Free Software Foundation; either version 2
   10: \ of the License, or (at your option) any later version.
   11: 
   12: \ This program is distributed in the hope that it will be useful,
   13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
   14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15: \ GNU General Public License for more details.
   16: 
   17: \ You should have received a copy of the GNU General Public License
   18: \ along with this program; if not, write to the Free Software
   19: \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   20: 
   21: 
   22: \ This does not work like etags; instead, the TAGS file is updated
   23: \ during the normal Forth interpretation/compilation process.
   24: 
   25: \ The present version has several shortcomings: It always overwrites
   26: \ the TAGS file instead of just the parts corresponding to the loaded
   27: \ files, but you can have several tag tables in emacs. Every load
   28: \ creates a new etags file and the user has to confirm that she wants
   29: \ to use it.
   30: 
   31: \ Communication of interactive programs like emacs and Forth over
   32: \ files is clumsy. There should be better cooperation between them
   33: \ (e.g. via shared memory)
   34: 
   35: \ This is ANS Forth with the following serious environmental
   36: \ dependences: the variable LAST must contain a pointer to the last
   37: \ header, NAME>STRING must convert that pointer to a string, and
   38: \ HEADER must be a deferred word that is called to create the name.
   39: 
   40: include extend.fs
   41: 
   42: : tags-file-name ( -- c-addr u )
   43:     \ for now I use just TAGS; this may become more flexible in the
   44:     \ future
   45:     s" TAGS" ;
   46: 
   47: variable tags-file 0 tags-file !
   48: 
   49: create tags-line 128 chars allot
   50:     
   51: : skip-tags ( file-id -- )
   52:     \ reads in file until it finds the end or the loadfilename
   53:     drop ;
   54: 
   55: : tags-file-id ( -- file-id )
   56:     tags-file @ 0= if
   57: 	tags-file-name w/o create-file throw
   58: \ 	2dup file-status
   59: \ 	if \ the file does not exist
   60: \ 	    drop w/o create-file throw
   61: \ 	else
   62: \ 	    drop r/w open-file throw
   63: \ 	    dup skip-tags
   64: \ 	endif
   65: 	tags-file !
   66:     endif
   67:     tags-file @ ;
   68: 
   69: 2variable last-loadfilename 0 0 last-loadfilename 2!
   70: 
   71: : put-load-file-name ( file-id -- )
   72:     >r
   73:     sourcefilename last-loadfilename 2@ d<>
   74:     if
   75: 	#ff r@ emit-file throw
   76: 	#lf r@ emit-file throw
   77: 	sourcefilename 2dup
   78: 	r@ write-file throw
   79: 	last-loadfilename 2!
   80: 	s" ,0" r@ write-line throw
   81:     endif
   82:     rdrop ;
   83: 
   84: : put-tags-entry ( -- )
   85:     \ write the entry for the last name to the TAGS file
   86:     \ if the input is from a file and it is not a local name
   87:     source-id dup 0<> swap -1 <> and	\ input from a file
   88:     current @ locals-list <> and	\ not a local name
   89:     last @ 0<> and	\ not an anonymous (i.e. noname) header
   90:     if
   91: 	tags-file-id >r 
   92: 	r@ put-load-file-name
   93: 	source drop >in @ r@ write-file throw
   94: 	127 r@ emit-file throw
   95: 	bl r@ emit-file throw
   96: 	last @ name>string r@ write-file throw
   97: 	bl r@ emit-file throw
   98: 	1 r@ emit-file throw
   99: 	base @ decimal sourceline# 0 <# #s #> r@ write-file throw base !
  100: 	s" ,0" r@ write-line throw
  101: 	\ the character position in the file; not strictly necessary AFAIK
  102: 	\ instead of using 0, we could use file-position and subtract
  103: 	\ the line length
  104: 	rdrop
  105:     endif ;
  106: 
  107: : (tags-header) ( -- )
  108:     defers header
  109:     put-tags-entry ;
  110: 
  111: ' (tags-header) IS header

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>