1 ! Copyright (C) 2008 Alfredo Beaumont
2 ! See http://factorcode.org/license.txt for BSD license.
4 ! Emacs Etags generator
5 ! Alfredo Beaumont <alfredo.beaumont@gmail.com>
6 USING: kernel sequences sorting assocs words prettyprint ctags
7 io.encodings.ascii io.files math math.parser namespaces make
8 strings shuffle io.backend arrays present ;
11 : etag-at ( key hash -- vector )
12 at [ V{ } clone ] unless* ;
14 : etag-vector ( alist hash -- vector )
15 [ ctag-path ] dip etag-at ;
17 : etag-pair ( ctag -- seq )
23 : etag-add ( ctag hash -- )
24 [ etag-vector ] 2keep [
25 [ etag-pair ] [ ctag-path ] bi [ suffix ] dip
28 : etag-hash ( seq -- hash )
29 H{ } clone swap [ swap [ etag-add ] keep ] each ;
31 : lines>bytes ( seq n -- bytes )
32 head 0 [ length 1 + + ] reduce ;
34 : file>lines ( path -- lines )
37 : etag ( lines seq -- str )
41 second dup number>string %
43 1 - lines>bytes number>string %
46 : etag-length ( vector -- n )
47 0 [ length + ] reduce ;
49 : (etag-header) ( n path -- str )
56 : etag-header ( vec1 n resource -- vec2 )
57 normalize-path (etag-header) prefix
58 1 0x0c <string> prefix ;
60 : etag-strings ( alist -- seq )
71 : etags-write ( alist path -- )
72 [ etag-strings ] dip ascii set-file-lines ;
75 [ (ctags) sort-values etag-hash >alist ] dip etags-write ;