File:  [gforth] / gforth / etags.fs
Revision 1.3: download - view: text, annotated - select for diffs
Tue Nov 7 18:06:39 1995 UTC (28 years, 4 months ago) by anton
Branches: MAIN
CVS tags: HEAD
added copyright headers
changes to loadfilename & co. to make savesystem transparent to
 assertions and ~~

    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: : tags-file-name ( -- c-addr u )
   41:     \ for now I use just TAGS; this may become more flexible in the
   42:     \ future
   43:     s" TAGS" ;
   44: 
   45: variable tags-file 0 tags-file !
   46: 
   47: create tags-line 128 chars allot
   48:     
   49: : skip-tags ( file-id -- )
   50:     \ reads in file until it finds the end or the loadfilename
   51:     drop ;
   52: 
   53: : tags-file-id ( -- file-id )
   54:     tags-file @ 0= if
   55: 	tags-file-name w/o create-file throw
   56: \ 	2dup file-status
   57: \ 	if \ the file does not exist
   58: \ 	    drop w/o create-file throw
   59: \ 	else
   60: \ 	    drop r/w open-file throw
   61: \ 	    dup skip-tags
   62: \ 	endif
   63: 	tags-file !
   64:     endif
   65:     tags-file @ ;
   66: 
   67: create emit-file-char 0 c,
   68: 
   69: : emit-file ( c file-id -- )
   70:     swap emit-file-char c!
   71:     emit-file-char 1 chars rot write-file ;
   72: 
   73: 2variable last-loadfilename 0 0 last-loadfilename 2!
   74: 
   75: : put-load-file-name ( file-id -- )
   76:     >r
   77:     loadfilename 2@ last-loadfilename 2@ d<>
   78:     if
   79: 	#ff r@ emit-file throw
   80: 	#lf r@ emit-file throw
   81: 	loadfilename 2@ 2dup
   82: 	r@ write-file throw
   83: 	last-loadfilename 2!
   84: 	s" ,0" r@ write-line throw
   85:     endif
   86:     rdrop ;
   87: 
   88: : put-tags-entry ( -- )
   89:     \ write the entry for the last name to the TAGS file
   90:     \ if the input is from a file and it is not a local name
   91:     source-id dup 0<> swap -1 <> and	\ input from a file
   92:     get-current locals-list <> and	\ not a local name
   93:     last @ 0<> and	\ not an anonymous (i.e. noname) header
   94:     if
   95: 	tags-file-id >r 
   96: 	r@ put-load-file-name
   97: 	source drop >in @ r@ write-file throw
   98: 	127 r@ emit-file throw
   99: 	bl r@ emit-file throw
  100: 	last @ name>string r@ write-file throw
  101: 	bl r@ emit-file throw
  102: 	1 r@ emit-file throw
  103: 	base @ decimal loadline @ 0 <# #s #> r@ write-file throw base !
  104: 	s" ,0" r@ write-line throw
  105: 	\ the character position in the file; not strictly necessary AFAIK
  106: 	\ instead of using 0, we could use file-position and subtract
  107: 	\ the line length
  108: 	rdrop
  109:     endif cr ;
  110: 
  111: : (tags-header) ( -- )
  112:     defers header
  113:     put-tags-entry ;
  114: 
  115: ' (tags-header) IS header

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