File:  [gforth] / gforth / etags.fs
Revision 1.6: download - view: text, annotated - select for diffs
Fri Feb 9 17:34:08 1996 UTC (28 years, 1 month ago) by anton
Branches: MAIN
CVS tags: v0-2-1, v0-2-0, HEAD
?DUP-IF and ?DUP-0=-IF are now supported by primitives
added primitives EMIT-FILE, STDOUT, STDERR
EMIT and TYPE now work through file words
added some code for the BUGGY_LONG_LONG case (not yet complete)
eliminated D! and D@
made DMIN, DMAX, DABS high-level
added compat/control.fs (?DUP-IF etc.)

    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: 2variable last-loadfilename 0 0 last-loadfilename 2!
   68: 
   69: : put-load-file-name ( file-id -- )
   70:     >r
   71:     sourcefilename last-loadfilename 2@ d<>
   72:     if
   73: 	#ff r@ emit-file throw
   74: 	#lf r@ emit-file throw
   75: 	sourcefilename 2dup
   76: 	r@ write-file throw
   77: 	last-loadfilename 2!
   78: 	s" ,0" r@ write-line throw
   79:     endif
   80:     rdrop ;
   81: 
   82: : put-tags-entry ( -- )
   83:     \ write the entry for the last name to the TAGS file
   84:     \ if the input is from a file and it is not a local name
   85:     source-id dup 0<> swap -1 <> and	\ input from a file
   86:     current @ locals-list <> and	\ not a local name
   87:     last @ 0<> and	\ not an anonymous (i.e. noname) header
   88:     if
   89: 	tags-file-id >r 
   90: 	r@ put-load-file-name
   91: 	source drop >in @ r@ write-file throw
   92: 	127 r@ emit-file throw
   93: 	bl r@ emit-file throw
   94: 	last @ name>string r@ write-file throw
   95: 	bl r@ emit-file throw
   96: 	1 r@ emit-file throw
   97: 	base @ decimal sourceline# 0 <# #s #> r@ write-file throw base !
   98: 	s" ,0" r@ write-line throw
   99: 	\ the character position in the file; not strictly necessary AFAIK
  100: 	\ instead of using 0, we could use file-position and subtract
  101: 	\ the line length
  102: 	rdrop
  103:     endif ;
  104: 
  105: : (tags-header) ( -- )
  106:     defers header
  107:     put-tags-entry ;
  108: 
  109: ' (tags-header) IS header

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