Annotation of gforth/locate.fs, revision 1.4
1.1 pazsan 1: \ locate, using the TAGS file
2:
1.4 ! anton 3: \ Copyright (C) 2002,2003 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., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
20:
1.1 pazsan 21: require string.fs
22:
23: Variable last-file
24: Variable line-buf
25:
26: \ example: invoke vi
27:
28: Defer do-location
29:
30: Variable sys-buf
31: : invoke-vi ( filename u line -- ) base @ >r decimal
32: s" vi " sys-buf $!
33: 0 <# bl hold #S '+ hold #> sys-buf $+!
34: sys-buf $+!
35: r> base ! sys-buf $@ system ;
36: ' invoke-vi IS do-location
37:
38: \ scan file
39:
40: : tag-line ( fid -- flag ) >r
41: s" " line-buf $!
42: $100 line-buf $!len
43: line-buf $@ r> read-line throw
44: swap line-buf $!len ;
45: : check-word ( addr u -- addr u flag )
46: line-buf $@ #del $split 2nip ctrl A $split 2drop
47: 2swap search nip nip ;
48: : get-file ( fid -- )
49: tag-line drop line-buf $@ ', $split 2drop last-file $! ;
50: : print-location ( -- ) base @ >r decimal
51: last-file $@ line-buf $@ ctrl A $split 2nip ', $split 2drop
52: 0. 2swap >number 2drop drop r> base !
53: do-location ;
54: : locate ( "name" -- ) s" " last-file $! bl sword
55: s" TAGS" r/o open-file throw >r
56: BEGIN r@ tag-line WHILE
1.2 anton 57: s" " line-buf $@ str=
1.1 pazsan 58: IF r@ get-file
59: ELSE 2dup check-word
60: IF print-location 2drop r> close-file throw EXIT THEN
61: THEN
62: REPEAT r> close-file throw 2drop true abort" tag not found" ;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>