1 ! Copyright (C) 2008 Slava Pestov.
\r
2 ! See http://factorcode.org/license.txt for BSD license.
\r
3 USING: threads io.files io.pathnames io.monitors init kernel
\r
4 vocabs vocabs.loader tools.vocabs namespaces continuations
\r
5 sequences splitting assocs command-line concurrency.messaging
\r
7 IN: tools.vocabs.monitor
\r
9 TR: convert-separators "/\\" ".." ;
\r
11 : vocab-dir>vocab-name ( path -- vocab )
\r
12 trim-left-separators
\r
13 trim-right-separators
\r
14 convert-separators ;
\r
16 : path>vocab-name ( path -- vocab )
\r
17 dup ".factor" tail? [ parent-directory ] when ;
\r
19 : chop-vocab-root ( path -- path' )
\r
20 "resource:" prepend-path normalize-path
\r
22 [ normalize-path ] map
\r
23 [ head? ] with find nip
\r
26 : path>vocab ( path -- vocab )
\r
27 chop-vocab-root path>vocab-name vocab-dir>vocab-name ;
\r
29 : monitor-loop ( -- )
\r
30 #! On OS X, monitors give us the full path, so we chop it
\r
31 #! off if its there.
\r
32 receive first path>vocab changed-vocab
\r
36 : add-monitor-for-path ( path -- )
\r
37 dup exists? [ t my-mailbox (monitor) ] when drop ;
\r
39 : monitor-thread ( -- )
\r
42 vocab-roots get prune [ add-monitor-for-path ] each
\r
44 H{ } clone changed-vocabs set-global
\r
45 vocabs [ changed-vocab ] each
\r
51 : start-monitor-thread ( -- )
\r
52 #! Silently ignore errors during monitor creation since
\r
53 #! monitors are not supported on all platforms.
\r
54 [ monitor-thread ] "Vocabulary monitor" spawn drop ;
\r
57 "-no-monitors" (command-line) member?
\r
58 [ start-monitor-thread ] unless
\r
59 ] "tools.vocabs.monitor" add-init-hook
\r