| 1 : |
pazsan
|
1.1
|
\ locate, using the TAGS file |
| 2 : |
|
|
|
| 3 : |
anton
|
1.6
|
\ Copyright (C) 2002,2003,2007 Free Software Foundation, Inc. |
| 4 : |
anton
|
1.3
|
|
| 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 : |
anton
|
1.5
|
\ as published by the Free Software Foundation, either version 3 |
| 10 : |
anton
|
1.3
|
\ 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 : |
anton
|
1.5
|
\ along with this program. If not, see http://www.gnu.org/licenses/. |
| 19 : |
anton
|
1.3
|
|
| 20 : |
pazsan
|
1.1
|
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 |
| 56 : |
anton
|
1.2
|
s" " line-buf $@ str= |
| 57 : |
pazsan
|
1.1
|
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" ; |