1 ! Copyright (C) 2008 Alfredo Beaumont
2 ! See https://factorcode.org/license.txt for BSD license.
4 ! Emacs Etags generator
5 ! Alfredo Beaumont <alfredo.beaumont@gmail.com>
6 USING: arrays assocs ctags.private fry io.backend
7 io.encodings.ascii io.files kernel make math math.parser present
8 sequences sorting strings vocabs ;
13 : etag-hash ( alist -- hash )
15 '[ first2 swap [ 2array ] dip _ push-at ] assoc-each
18 : lines>bytes ( lines -- bytes )
19 0 [ length 1 + + ] accumulate nip ;
21 : etag ( bytes seq -- str )
25 second dup number>string %
27 1 - swap nth number>string %
30 : etag-header ( vec1 resource -- vec2 )
34 dup sum-lengths number>string %
35 ] "" make prefix "\f" prefix ;
37 : make-etags ( alist -- seq )
40 [ ascii file-lines lines>bytes ] dip
42 ] dip etag-header append!
48 all-words locations etag-hash sort-keys make-etags ;
50 : write-etags ( path -- )
51 [ etags ] dip ascii set-file-lines ;