2008-02-05 14:11:36 -05:00
|
|
|
USING: continuations destructors io.buffers io.files io.backend
|
2008-02-09 22:34:42 -05:00
|
|
|
io.timeouts io.nonblocking io.windows io.windows.nt.backend
|
2008-02-18 08:30:16 -05:00
|
|
|
kernel libc math threads windows windows.kernel32
|
2008-02-18 06:07:40 -05:00
|
|
|
alien.c-types alien.arrays sequences combinators combinators.lib
|
2008-03-29 00:00:20 -04:00
|
|
|
sequences.lib ascii splitting alien strings assocs namespaces ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: io.windows.nt.files
|
|
|
|
|
2008-02-05 14:11:36 -05:00
|
|
|
M: windows-nt-io cwd
|
|
|
|
MAX_UNICODE_PATH dup "ushort" <c-array>
|
|
|
|
[ GetCurrentDirectory win32-error=0/f ] keep
|
|
|
|
alien>u16-string ;
|
|
|
|
|
|
|
|
M: windows-nt-io cd
|
|
|
|
SetCurrentDirectory win32-error=0/f ;
|
|
|
|
|
|
|
|
: unicode-prefix ( -- seq )
|
|
|
|
"\\\\?\\" ; inline
|
|
|
|
|
|
|
|
M: windows-nt-io root-directory? ( path -- ? )
|
2008-03-27 17:22:24 -04:00
|
|
|
{
|
|
|
|
{ [ dup empty? ] [ f ] }
|
|
|
|
{ [ dup [ path-separator? ] all? ] [ t ] }
|
|
|
|
{ [ dup right-trim-separators
|
|
|
|
{ [ dup length 2 = ] [ dup second CHAR: : = ] } && nip ] [
|
|
|
|
t
|
|
|
|
] }
|
|
|
|
{ [ t ] [ f ] }
|
|
|
|
} cond nip ;
|
2008-02-05 14:11:36 -05:00
|
|
|
|
2008-03-25 20:52:07 -04:00
|
|
|
ERROR: not-absolute-path ;
|
2008-02-05 14:11:36 -05:00
|
|
|
: root-directory ( string -- string' )
|
|
|
|
{
|
|
|
|
[ dup length 2 >= ]
|
|
|
|
[ dup second CHAR: : = ]
|
|
|
|
[ dup first Letter? ]
|
2008-03-25 20:52:07 -04:00
|
|
|
} && [ 2 head ] [ not-absolute-path ] if ;
|
2008-02-05 14:11:36 -05:00
|
|
|
|
|
|
|
: prepend-prefix ( string -- string' )
|
2008-04-01 20:00:20 -04:00
|
|
|
dup unicode-prefix head? [
|
|
|
|
unicode-prefix prepend
|
|
|
|
] unless ;
|
2008-02-05 14:11:36 -05:00
|
|
|
|
2008-04-01 20:51:49 -04:00
|
|
|
M: windows-nt-io normalize-path ( string -- string' )
|
|
|
|
(normalize-path)
|
2008-04-01 20:00:20 -04:00
|
|
|
{ { CHAR: / CHAR: \\ } } substitute
|
|
|
|
prepend-prefix ;
|
2008-02-05 14:11:36 -05:00
|
|
|
|
2007-11-23 20:17:40 -05:00
|
|
|
M: windows-nt-io CreateFile-flags ( DWORD -- DWORD )
|
|
|
|
FILE_FLAG_OVERLAPPED bitor ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
M: windows-nt-io FileArgs-overlapped ( port -- overlapped )
|
|
|
|
make-overlapped ;
|
|
|
|
|
|
|
|
: update-file-ptr ( n port -- )
|
|
|
|
port-handle
|
|
|
|
dup win32-file-ptr [
|
|
|
|
rot + swap set-win32-file-ptr
|
|
|
|
] [
|
|
|
|
2drop
|
|
|
|
] if* ;
|
|
|
|
|
2008-01-28 00:59:36 -05:00
|
|
|
: finish-flush ( overlapped port -- )
|
2007-09-20 18:09:08 -04:00
|
|
|
dup pending-error
|
2008-01-28 00:59:36 -05:00
|
|
|
tuck get-overlapped-result
|
2007-11-07 14:01:45 -05:00
|
|
|
dup pick update-file-ptr
|
|
|
|
swap buffer-consume ;
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: (flush-output) ( port -- )
|
|
|
|
dup make-FileArgs
|
2007-11-07 14:01:45 -05:00
|
|
|
tuck setup-write WriteFile
|
|
|
|
dupd overlapped-error? [
|
2008-01-28 00:59:36 -05:00
|
|
|
>r FileArgs-lpOverlapped r>
|
|
|
|
[ save-callback ] 2keep
|
2007-11-07 14:01:45 -05:00
|
|
|
[ finish-flush ] keep
|
|
|
|
dup buffer-empty? [ drop ] [ (flush-output) ] if
|
2007-09-20 18:09:08 -04:00
|
|
|
] [
|
|
|
|
2drop
|
|
|
|
] if ;
|
|
|
|
|
2007-11-09 03:01:45 -05:00
|
|
|
: flush-output ( port -- )
|
2008-02-09 22:34:42 -05:00
|
|
|
[ [ (flush-output) ] with-timeout ] with-destructors ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2007-11-09 03:01:45 -05:00
|
|
|
M: port port-flush
|
|
|
|
dup buffer-empty? [ dup flush-output ] unless drop ;
|
|
|
|
|
2008-01-28 00:59:36 -05:00
|
|
|
: finish-read ( overlapped port -- )
|
2007-09-20 18:09:08 -04:00
|
|
|
dup pending-error
|
2008-01-28 00:59:36 -05:00
|
|
|
tuck get-overlapped-result dup zero? [
|
2007-09-20 18:09:08 -04:00
|
|
|
drop t swap set-port-eof?
|
|
|
|
] [
|
2007-11-07 14:01:45 -05:00
|
|
|
dup pick n>buffer
|
2007-09-20 18:09:08 -04:00
|
|
|
swap update-file-ptr
|
|
|
|
] if ;
|
|
|
|
|
|
|
|
: ((wait-to-read)) ( port -- )
|
|
|
|
dup make-FileArgs
|
2007-11-07 14:01:45 -05:00
|
|
|
tuck setup-read ReadFile
|
|
|
|
dupd overlapped-error? [
|
2008-01-28 00:59:36 -05:00
|
|
|
>r FileArgs-lpOverlapped r>
|
|
|
|
[ save-callback ] 2keep
|
2007-09-20 18:09:08 -04:00
|
|
|
finish-read
|
2008-01-31 13:27:37 -05:00
|
|
|
] [ 2drop ] if ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
M: input-port (wait-to-read) ( port -- )
|
2008-02-09 22:34:42 -05:00
|
|
|
[ [ ((wait-to-read)) ] with-timeout ] with-destructors ;
|