]> gitweb.factorcode.org Git - factor.git/commitdiff
Rename io.monitor to io.monitors; add log-viewer demo
authorSlava Pestov <slava@factorcode.org>
Wed, 6 Feb 2008 00:00:24 +0000 (18:00 -0600)
committerSlava Pestov <slava@factorcode.org>
Wed, 6 Feb 2008 00:00:24 +0000 (18:00 -0600)
19 files changed:
extra/help/handbook/handbook.factor
extra/io/monitor/authors.txt [deleted file]
extra/io/monitor/monitor-docs.factor [deleted file]
extra/io/monitor/monitor.factor [deleted file]
extra/io/monitor/summary.txt [deleted file]
extra/io/monitors/authors.txt [new file with mode: 0755]
extra/io/monitors/monitors-docs.factor [new file with mode: 0755]
extra/io/monitors/monitors.factor [new file with mode: 0755]
extra/io/monitors/summary.txt [new file with mode: 0755]
extra/io/unix/linux/linux.factor
extra/io/windows/nt/monitor/authors.txt [deleted file]
extra/io/windows/nt/monitor/monitor.factor [deleted file]
extra/io/windows/nt/monitors/authors.txt [new file with mode: 0755]
extra/io/windows/nt/monitors/monitors.factor [new file with mode: 0755]
extra/io/windows/nt/nt.factor
extra/log-viewer/authors.txt [new file with mode: 0755]
extra/log-viewer/log-viewer.factor [new file with mode: 0755]
extra/log-viewer/summary.txt [new file with mode: 0755]
extra/log-viewer/tags.txt [new file with mode: 0755]

index 234e7891d7ef9db049e7cd56b5a87b927a19e3ec..81e4bea7b3fa838ecff6c05f4a752c8aef3f372f 100755 (executable)
@@ -137,7 +137,7 @@ ARTICLE: "collections" "Collections"
 { $subsection "graphs" }
 { $subsection "buffers" } ;
 
-USING: io.sockets io.launcher io.mmap io.monitor ;
+USING: io.sockets io.launcher io.mmap io.monitors ;
 
 ARTICLE: "io" "Input and output" 
 { $subsection "streams" }
@@ -155,7 +155,7 @@ ARTICLE: "io" "Input and output"
 "Advanced features:"
 { $subsection "io.launcher" }
 { $subsection "io.mmap" }
-{ $subsection "io.monitor" } ;
+{ $subsection "io.monitors" } ;
 
 ARTICLE: "tools" "Developer tools"
 { $subsection "tools.annotations" }
diff --git a/extra/io/monitor/authors.txt b/extra/io/monitor/authors.txt
deleted file mode 100755 (executable)
index 1901f27..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Slava Pestov
diff --git a/extra/io/monitor/monitor-docs.factor b/extra/io/monitor/monitor-docs.factor
deleted file mode 100755 (executable)
index de649f4..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-IN: io.monitor\r
-USING: help.markup help.syntax continuations ;\r
-\r
-HELP: <monitor>\r
-{ $values { "path" "a pathname string" } { "recursive?" "a boolean" } }\r
-{ $description "Opens a file system change monitor which listens for changes on " { $snippet "path" } ". The boolean indicates whether changes in subdirectories should be reported."\r
-$nl\r
-"Not all operating systems support recursive monitors; if recursive monitoring is not available, an error is thrown and the caller must implement alternative logic for monitoring subdirectories." } ;\r
-\r
-HELP: next-change\r
-{ $values { "monitor" "a monitor" } { "path" "a pathname string" } { "changes" "a change descriptor" } }\r
-{ $description "Waits for file system changes and outputs the pathname of the first changed file. The change descriptor is aq sequence of symbols documented in " { $link "io.monitor.descriptors" } "." } ;\r
-\r
-HELP: with-monitor\r
-{ $values { "path" "a pathname string" } { "recursive?" "a boolean" } { "quot" "a quotation with stack effect " { $snippet "( monitor -- )" } } }\r
-{ $description "Opens a file system change monitor and passes it to the quotation. Closes the monitor after the quotation returns or throws an error." } ;\r
-\r
-HELP: +add-file+\r
-{ $description "Indicates that the file has been added to the directory." } ;\r
-\r
-HELP: +remove-file+\r
-{ $description "Indicates that the file has been removed from the directory." } ;\r
-\r
-HELP: +modify-file+\r
-{ $description "Indicates that the file contents have changed." } ;\r
-\r
-HELP: +rename-file+\r
-{ $description "Indicates that file has been renamed." } ;\r
-\r
-ARTICLE: "io.monitor.descriptors" "File system change descriptors"\r
-"Change descriptors output by " { $link next-change } ":"\r
-{ $subsection +add-file+ }\r
-{ $subsection +remove-file+ }\r
-{ $subsection +modify-file+ }\r
-{ $subsection +rename-file+ }\r
-{ $subsection +add-file+ } ;\r
-\r
-ARTICLE: "io.monitor" "File system change monitors"\r
-"File system change monitors listen for changes to file names, attributes and contents under a specified directory. They can optionally be recursive, in which case subdirectories are also monitored."\r
-$nl\r
-"Creating a file system change monitor and listening for changes:"\r
-{ $subsection <monitor> }\r
-{ $subsection next-change }\r
-{ $subsection "io.monitor.descriptors" }\r
-"Monitors are closed by calling " { $link dispose } " or " { $link with-disposal } "."\r
-$nl\r
-"A utility combinator which opens a monitor and cleans it up after:"\r
-{ $subsection with-monitor }\r
-"An example which watches the Factor directory for changes:"\r
-{ $code\r
-    "USE: io.monitor"\r
-    ": watch-loop ( monitor -- )"\r
-    "    dup next-change . . nl nl flush watch-loop ;"\r
-    ""\r
-    "\"\" resource-path f [ watch-loop ] with-monitor"\r
-} ;\r
-\r
-ABOUT: "io.monitor"\r
diff --git a/extra/io/monitor/monitor.factor b/extra/io/monitor/monitor.factor
deleted file mode 100755 (executable)
index 1d8499b..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-! Copyright (C) 2008 Slava Pestov.\r
-! See http://factorcode.org/license.txt for BSD license.\r
-USING: io.backend kernel continuations namespaces sequences\r
-assocs hashtables sorting arrays ;\r
-IN: io.monitor\r
-\r
-<PRIVATE\r
-\r
-TUPLE: monitor queue closed? ;\r
-\r
-: check-monitor ( monitor -- )\r
-    monitor-closed? [ "Monitor closed" throw ] when ;\r
-\r
-: (monitor) ( delegate -- monitor )\r
-    H{ } clone {\r
-        set-delegate\r
-        set-monitor-queue\r
-    } monitor construct ;\r
-\r
-HOOK: fill-queue io-backend ( monitor -- )\r
-\r
-: changed-file ( changed path -- )\r
-    namespace [ append ] change-at ;\r
-\r
-: dequeue-change ( assoc -- path changes )\r
-    delete-any prune natural-sort >array ;\r
-\r
-PRIVATE>\r
-\r
-HOOK: <monitor> io-backend ( path recursive? -- monitor )\r
-\r
-: next-change ( monitor -- path changed )\r
-    dup check-monitor\r
-    dup monitor-queue dup assoc-empty? [\r
-        drop dup fill-queue next-change\r
-    ] [ nip dequeue-change ] if ;\r
-\r
-SYMBOL: +add-file+\r
-SYMBOL: +remove-file+\r
-SYMBOL: +modify-file+\r
-SYMBOL: +rename-file+\r
-\r
-: with-monitor ( path recursive? quot -- )\r
-    >r <monitor> r> with-disposal ; inline\r
diff --git a/extra/io/monitor/summary.txt b/extra/io/monitor/summary.txt
deleted file mode 100755 (executable)
index 96d49e5..0000000
+++ /dev/null
@@ -1 +0,0 @@
-File alteration monitoring
diff --git a/extra/io/monitors/authors.txt b/extra/io/monitors/authors.txt
new file mode 100755 (executable)
index 0000000..1901f27
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
diff --git a/extra/io/monitors/monitors-docs.factor b/extra/io/monitors/monitors-docs.factor
new file mode 100755 (executable)
index 0000000..9d985ff
--- /dev/null
@@ -0,0 +1,58 @@
+IN: io.monitors\r
+USING: help.markup help.syntax continuations ;\r
+\r
+HELP: <monitor>\r
+{ $values { "path" "a pathname string" } { "recursive?" "a boolean" } }\r
+{ $description "Opens a file system change monitor which listens for changes on " { $snippet "path" } ". The boolean indicates whether changes in subdirectories should be reported."\r
+$nl\r
+"Not all operating systems support recursive monitors; if recursive monitoring is not available, an error is thrown and the caller must implement alternative logic for monitoring subdirectories." } ;\r
+\r
+HELP: next-change\r
+{ $values { "monitor" "a monitor" } { "path" "a pathname string" } { "changes" "a change descriptor" } }\r
+{ $description "Waits for file system changes and outputs the pathname of the first changed file. The change descriptor is aq sequence of symbols documented in " { $link "io.monitors.descriptors" } "." } ;\r
+\r
+HELP: with-monitor\r
+{ $values { "path" "a pathname string" } { "recursive?" "a boolean" } { "quot" "a quotation with stack effect " { $snippet "( monitor -- )" } } }\r
+{ $description "Opens a file system change monitor and passes it to the quotation. Closes the monitor after the quotation returns or throws an error." } ;\r
+\r
+HELP: +add-file+\r
+{ $description "Indicates that the file has been added to the directory." } ;\r
+\r
+HELP: +remove-file+\r
+{ $description "Indicates that the file has been removed from the directory." } ;\r
+\r
+HELP: +modify-file+\r
+{ $description "Indicates that the file contents have changed." } ;\r
+\r
+HELP: +rename-file+\r
+{ $description "Indicates that file has been renamed." } ;\r
+\r
+ARTICLE: "io.monitors.descriptors" "File system change descriptors"\r
+"Change descriptors output by " { $link next-change } ":"\r
+{ $subsection +add-file+ }\r
+{ $subsection +remove-file+ }\r
+{ $subsection +modify-file+ }\r
+{ $subsection +rename-file+ }\r
+{ $subsection +add-file+ } ;\r
+\r
+ARTICLE: "io.monitors" "File system change monitors"\r
+"File system change monitors listen for changes to file names, attributes and contents under a specified directory. They can optionally be recursive, in which case subdirectories are also monitored."\r
+$nl\r
+"Creating a file system change monitor and listening for changes:"\r
+{ $subsection <monitor> }\r
+{ $subsection next-change }\r
+{ $subsection "io.monitors.descriptors" }\r
+"Monitors are closed by calling " { $link dispose } " or " { $link with-disposal } "."\r
+$nl\r
+"A utility combinator which opens a monitor and cleans it up after:"\r
+{ $subsection with-monitor }\r
+"An example which watches the Factor directory for changes:"\r
+{ $code\r
+    "USE: io.monitors"\r
+    ": watch-loop ( monitor -- )"\r
+    "    dup next-change . . nl nl flush watch-loop ;"\r
+    ""\r
+    "\"\" resource-path f [ watch-loop ] with-monitor"\r
+} ;\r
+\r
+ABOUT: "io.monitors"\r
diff --git a/extra/io/monitors/monitors.factor b/extra/io/monitors/monitors.factor
new file mode 100755 (executable)
index 0000000..d652f34
--- /dev/null
@@ -0,0 +1,44 @@
+! Copyright (C) 2008 Slava Pestov.\r
+! See http://factorcode.org/license.txt for BSD license.\r
+USING: io.backend kernel continuations namespaces sequences\r
+assocs hashtables sorting arrays ;\r
+IN: io.monitors\r
+\r
+<PRIVATE\r
+\r
+TUPLE: monitor queue closed? ;\r
+\r
+: check-monitor ( monitor -- )\r
+    monitor-closed? [ "Monitor closed" throw ] when ;\r
+\r
+: (monitor) ( delegate -- monitor )\r
+    H{ } clone {\r
+        set-delegate\r
+        set-monitor-queue\r
+    } monitor construct ;\r
+\r
+HOOK: fill-queue io-backend ( monitor -- )\r
+\r
+: changed-file ( changed path -- )\r
+    namespace [ append ] change-at ;\r
+\r
+: dequeue-change ( assoc -- path changes )\r
+    delete-any prune natural-sort >array ;\r
+\r
+PRIVATE>\r
+\r
+HOOK: <monitor> io-backend ( path recursive? -- monitor )\r
+\r
+: next-change ( monitor -- path changed )\r
+    dup check-monitor\r
+    dup monitor-queue dup assoc-empty? [\r
+        drop dup fill-queue next-change\r
+    ] [ nip dequeue-change ] if ;\r
+\r
+SYMBOL: +add-file+\r
+SYMBOL: +remove-file+\r
+SYMBOL: +modify-file+\r
+SYMBOL: +rename-file+\r
+\r
+: with-monitor ( path recursive? quot -- )\r
+    >r <monitor> r> with-disposal ; inline\r
diff --git a/extra/io/monitors/summary.txt b/extra/io/monitors/summary.txt
new file mode 100755 (executable)
index 0000000..96d49e5
--- /dev/null
@@ -0,0 +1 @@
+File alteration monitoring
index dcf1beabf9134accd89caa34bc7a2e326fcaa95f..9c4aced03fb1b725554978fe400775dace533cc3 100755 (executable)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel io.backend io.monitor io.monitor.private io.files
+USING: kernel io.backend io.monitors io.monitors.private io.files
 io.buffers io.nonblocking io.unix.backend io.unix.select
 io.unix.launcher unix.linux.inotify assocs namespaces threads
 continuations init math alien.c-types alien ;
diff --git a/extra/io/windows/nt/monitor/authors.txt b/extra/io/windows/nt/monitor/authors.txt
deleted file mode 100755 (executable)
index 7c1b2f2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Doug Coleman
diff --git a/extra/io/windows/nt/monitor/monitor.factor b/extra/io/windows/nt/monitor/monitor.factor
deleted file mode 100755 (executable)
index 6f95676..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-! Copyright (C) 2008 Doug Coleman, Slava Pestov.
-! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types destructors io.windows
-io.windows.nt.backend kernel math windows windows.kernel32
-windows.types libc assocs alien namespaces continuations
-io.monitor io.monitor.private io.nonblocking io.buffers io.files
-io sequences hashtables sorting arrays combinators ;
-IN: io.windows.nt.monitor
-
-: open-directory ( path -- handle )
-    FILE_LIST_DIRECTORY
-    share-mode
-    f
-    OPEN_EXISTING
-    FILE_FLAG_BACKUP_SEMANTICS FILE_FLAG_OVERLAPPED bitor
-    f
-    CreateFile
-    dup invalid-handle?
-    dup close-later
-    dup add-completion
-    f <win32-file> ;
-
-TUPLE: win32-monitor path recursive? ;
-
-: <win32-monitor> ( path recursive? port -- monitor )
-    (monitor) {
-        set-win32-monitor-path
-        set-win32-monitor-recursive?
-        set-delegate
-    } win32-monitor construct ;
-
-M: windows-nt-io <monitor> ( path recursive? -- monitor )
-    [
-        over open-directory win32-monitor <buffered-port>
-        <win32-monitor>
-    ] with-destructors ;
-
-: begin-reading-changes ( monitor -- overlapped )
-    dup port-handle win32-file-handle
-    over buffer-ptr
-    pick buffer-size
-    roll win32-monitor-recursive? 1 0 ?
-    FILE_NOTIFY_CHANGE_ALL
-    0 <uint>
-    (make-overlapped)
-    [ f ReadDirectoryChangesW win32-error=0/f ] keep ;
-
-: read-changes ( monitor -- bytes )
-    [
-        [
-            dup begin-reading-changes
-            swap [ save-callback ] 2keep
-            dup check-monitor ! we may have closed it...
-            get-overlapped-result
-        ] with-port-timeout
-    ] with-destructors ;
-
-: parse-action ( action -- changed )
-    {
-        { [ dup FILE_ACTION_ADDED = ] [ +add-file+ ] }
-        { [ dup FILE_ACTION_REMOVED = ] [ +remove-file+ ] }
-        { [ dup FILE_ACTION_MODIFIED = ] [ +modify-file+ ] }
-        { [ dup FILE_ACTION_RENAMED_OLD_NAME = ] [ +rename-file+ ] }
-        { [ dup FILE_ACTION_RENAMED_NEW_NAME = ] [ +rename-file+ ] }
-        { [ t ] [ +modify-file+ ] }
-    } cond nip ;
-
-: parse-file-notify ( buffer -- changed path )
-    {
-        FILE_NOTIFY_INFORMATION-FileName
-        FILE_NOTIFY_INFORMATION-FileNameLength
-        FILE_NOTIFY_INFORMATION-Action
-    } get-slots parse-action 1array swap
-    memory>u16-string ;
-
-: (changed-files) ( buffer -- )
-    dup parse-file-notify changed-file
-    dup FILE_NOTIFY_INFORMATION-NextEntryOffset dup zero?
-    [ 2drop ] [ swap <displaced-alien> (changed-files) ] if ;
-
-M: windows-nt-io fill-queue ( monitor -- )
-    dup buffer-ptr over read-changes
-    [ zero? [ drop ] [ (changed-files) ] if ] H{ } make-assoc
-    swap set-monitor-queue ;
diff --git a/extra/io/windows/nt/monitors/authors.txt b/extra/io/windows/nt/monitors/authors.txt
new file mode 100755 (executable)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/extra/io/windows/nt/monitors/monitors.factor b/extra/io/windows/nt/monitors/monitors.factor
new file mode 100755 (executable)
index 0000000..a593e82
--- /dev/null
@@ -0,0 +1,83 @@
+! Copyright (C) 2008 Doug Coleman, Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: alien.c-types destructors io.windows
+io.windows.nt.backend kernel math windows windows.kernel32
+windows.types libc assocs alien namespaces continuations
+io.monitors io.monitors.private io.nonblocking io.buffers io.files
+io sequences hashtables sorting arrays combinators ;
+IN: io.windows.nt.monitors
+
+: open-directory ( path -- handle )
+    FILE_LIST_DIRECTORY
+    share-mode
+    f
+    OPEN_EXISTING
+    FILE_FLAG_BACKUP_SEMANTICS FILE_FLAG_OVERLAPPED bitor
+    f
+    CreateFile
+    dup invalid-handle?
+    dup close-later
+    dup add-completion
+    f <win32-file> ;
+
+TUPLE: win32-monitor path recursive? ;
+
+: <win32-monitor> ( path recursive? port -- monitor )
+    (monitor) {
+        set-win32-monitor-path
+        set-win32-monitor-recursive?
+        set-delegate
+    } win32-monitor construct ;
+
+M: windows-nt-io <monitor> ( path recursive? -- monitor )
+    [
+        over open-directory win32-monitor <buffered-port>
+        <win32-monitor>
+    ] with-destructors ;
+
+: begin-reading-changes ( monitor -- overlapped )
+    dup port-handle win32-file-handle
+    over buffer-ptr
+    pick buffer-size
+    roll win32-monitor-recursive? 1 0 ?
+    FILE_NOTIFY_CHANGE_ALL
+    0 <uint>
+    (make-overlapped)
+    [ f ReadDirectoryChangesW win32-error=0/f ] keep ;
+
+: read-changes ( monitor -- bytes )
+    [
+        [
+            dup begin-reading-changes
+            swap [ save-callback ] 2keep
+            dup check-monitor ! we may have closed it...
+            get-overlapped-result
+        ] with-port-timeout
+    ] with-destructors ;
+
+: parse-action ( action -- changed )
+    {
+        { [ dup FILE_ACTION_ADDED = ] [ +add-file+ ] }
+        { [ dup FILE_ACTION_REMOVED = ] [ +remove-file+ ] }
+        { [ dup FILE_ACTION_MODIFIED = ] [ +modify-file+ ] }
+        { [ dup FILE_ACTION_RENAMED_OLD_NAME = ] [ +rename-file+ ] }
+        { [ dup FILE_ACTION_RENAMED_NEW_NAME = ] [ +rename-file+ ] }
+        { [ t ] [ +modify-file+ ] }
+    } cond nip ;
+
+: parse-file-notify ( buffer -- changed path )
+    {
+        FILE_NOTIFY_INFORMATION-FileName
+        FILE_NOTIFY_INFORMATION-FileNameLength
+        FILE_NOTIFY_INFORMATION-Action
+    } get-slots parse-action 1array -rot memory>u16-string ;
+
+: (changed-files) ( buffer -- )
+    dup parse-file-notify changed-file
+    dup FILE_NOTIFY_INFORMATION-NextEntryOffset dup zero?
+    [ 2drop ] [ swap <displaced-alien> (changed-files) ] if ;
+
+M: windows-nt-io fill-queue ( monitor -- )
+    dup buffer-ptr over read-changes
+    [ zero? [ drop ] [ (changed-files) ] if ] H{ } make-assoc
+    swap set-monitor-queue ;
index 5bdefd7713eec02eb4f87df8aaccdaa8a836220a..b957aa2fca5f1468e9a9611d6ef85f61c978e7b4 100755 (executable)
@@ -5,7 +5,7 @@ USE: io.windows
 USE: io.windows.nt.backend
 USE: io.windows.nt.files
 USE: io.windows.nt.launcher
-USE: io.windows.nt.monitor
+USE: io.windows.nt.monitors
 USE: io.windows.nt.sockets
 USE: io.windows.mmap
 USE: io.backend
diff --git a/extra/log-viewer/authors.txt b/extra/log-viewer/authors.txt
new file mode 100755 (executable)
index 0000000..1901f27
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
diff --git a/extra/log-viewer/log-viewer.factor b/extra/log-viewer/log-viewer.factor
new file mode 100755 (executable)
index 0000000..0f139d1
--- /dev/null
@@ -0,0 +1,14 @@
+USING: kernel io io.files io.monitors ;\r
+IN: log-viewer\r
+\r
+: read-lines ( stream -- )\r
+    dup stream-readln dup\r
+    [ print read-lines ] [ 2drop flush ] if ;\r
+\r
+: tail-file-loop ( stream monitor -- )\r
+    dup next-change 2drop over read-lines tail-file-loop ;\r
+\r
+: tail-file ( file -- )\r
+    dup <file-reader> dup read-lines\r
+    swap parent-directory f <monitor>\r
+    tail-file-loop ;\r
diff --git a/extra/log-viewer/summary.txt b/extra/log-viewer/summary.txt
new file mode 100755 (executable)
index 0000000..5eb1024
--- /dev/null
@@ -0,0 +1 @@
+Simple log file watcher demo using io.monitors
diff --git a/extra/log-viewer/tags.txt b/extra/log-viewer/tags.txt
new file mode 100755 (executable)
index 0000000..cb5fc20
--- /dev/null
@@ -0,0 +1 @@
+demos