Annotation of gforth/locate.fs, revision 1.6

1.1       pazsan      1: \ locate, using the TAGS file
                      2: 
1.6     ! anton       3: \ Copyright (C) 2002,2003,2007 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
1.5       anton       9: \ as published by the Free Software Foundation, either version 3
1.3       anton      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
1.5       anton      18: \ along with this program. If not, see http://www.gnu.org/licenses/.
1.3       anton      19: 
1.1       pazsan     20: require string.fs
                     21: 
                     22: Variable last-file
                     23: Variable line-buf
                     24: 
                     25: \ example: invoke vi
                     26: 
                     27: Defer do-location
                     28: 
                     29: Variable sys-buf
                     30: : invoke-vi ( filename u line -- ) base @ >r decimal
                     31:     s" vi " sys-buf $!
                     32:     0 <# bl hold #S '+ hold #> sys-buf $+!
                     33:     sys-buf $+!
                     34:     r> base ! sys-buf $@ system ;
                     35: ' invoke-vi IS do-location
                     36: 
                     37: \ scan file
                     38: 
                     39: : tag-line ( fid -- flag ) >r
                     40:     s" " line-buf $!
                     41:     $100 line-buf $!len
                     42:     line-buf $@ r> read-line throw
                     43:     swap line-buf $!len ;
                     44: : check-word ( addr u -- addr u flag )
                     45:     line-buf $@ #del $split 2nip ctrl A $split 2drop
                     46:     2swap search nip nip ;
                     47: : get-file ( fid -- )
                     48:     tag-line drop line-buf $@ ', $split 2drop last-file $! ;
                     49: : print-location ( -- ) base @ >r decimal
                     50:     last-file $@ line-buf $@ ctrl A $split 2nip ', $split 2drop
                     51:     0. 2swap >number 2drop drop r> base !
                     52:     do-location ;
                     53: : locate ( "name" -- )  s" " last-file $!  bl sword
                     54:     s" TAGS" r/o open-file throw >r
                     55:     BEGIN  r@ tag-line  WHILE
1.2       anton      56:         s" " line-buf $@ str=
1.1       pazsan     57:         IF    r@ get-file
                     58:         ELSE  2dup check-word
                     59:             IF  print-location 2drop  r> close-file throw  EXIT  THEN
                     60:         THEN
                     61:     REPEAT r> close-file throw 2drop true abort" tag not found" ;

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