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