Annotation of gforth/locate.fs, revision 1.1
1.1 ! pazsan 1: \ locate, using the TAGS file
! 2:
! 3: require string.fs
! 4:
! 5: Variable last-file
! 6: Variable line-buf
! 7:
! 8: \ example: invoke vi
! 9:
! 10: Defer do-location
! 11:
! 12: Variable sys-buf
! 13: : invoke-vi ( filename u line -- ) base @ >r decimal
! 14: s" vi " sys-buf $!
! 15: 0 <# bl hold #S '+ hold #> sys-buf $+!
! 16: sys-buf $+!
! 17: r> base ! sys-buf $@ system ;
! 18: ' invoke-vi IS do-location
! 19:
! 20: \ scan file
! 21:
! 22: : tag-line ( fid -- flag ) >r
! 23: s" " line-buf $!
! 24: $100 line-buf $!len
! 25: line-buf $@ r> read-line throw
! 26: swap line-buf $!len ;
! 27: : check-word ( addr u -- addr u flag )
! 28: line-buf $@ #del $split 2nip ctrl A $split 2drop
! 29: 2swap search nip nip ;
! 30: : get-file ( fid -- )
! 31: tag-line drop line-buf $@ ', $split 2drop last-file $! ;
! 32: : print-location ( -- ) base @ >r decimal
! 33: last-file $@ line-buf $@ ctrl A $split 2nip ', $split 2drop
! 34: 0. 2swap >number 2drop drop r> base !
! 35: do-location ;
! 36: : locate ( "name" -- ) s" " last-file $! bl sword
! 37: s" TAGS" r/o open-file throw >r
! 38: BEGIN r@ tag-line WHILE
! 39: s" " line-buf $@ compare 0=
! 40: IF r@ get-file
! 41: ELSE 2dup check-word
! 42: IF print-location 2drop r> close-file throw EXIT THEN
! 43: THEN
! 44: REPEAT r> close-file throw 2drop true abort" tag not found" ;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>