2008-02-14 01:43:50 -05:00
|
|
|
|
|
|
|
USING: kernel words namespaces classes parser continuations
|
|
|
|
io io.files io.launcher io.sockets
|
|
|
|
math math.parser
|
|
|
|
combinators sequences splitting quotations arrays strings tools.time
|
2008-03-03 15:06:16 -05:00
|
|
|
sequences.deep new-slots accessors assocs.lib
|
2008-03-07 09:52:23 -05:00
|
|
|
io.encodings.utf8
|
2008-02-26 22:43:58 -05:00
|
|
|
combinators.cleave bake calendar calendar.format ;
|
2008-02-14 01:43:50 -05:00
|
|
|
|
|
|
|
IN: builder.util
|
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
|
|
|
: runtime ( quot -- time ) benchmark nip ;
|
|
|
|
|
|
|
|
: minutes>ms ( min -- ms ) 60 * 1000 * ;
|
|
|
|
|
2008-03-07 09:52:23 -05:00
|
|
|
: file>string ( file -- string ) utf8 [ stdio get contents ] with-file-reader ;
|
2008-02-14 01:43:50 -05:00
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
|
|
|
DEFER: to-strings
|
|
|
|
|
|
|
|
: to-string ( obj -- str )
|
|
|
|
dup class
|
|
|
|
{
|
|
|
|
{ string [ ] }
|
|
|
|
{ quotation [ call ] }
|
|
|
|
{ word [ execute ] }
|
|
|
|
{ fixnum [ number>string ] }
|
|
|
|
{ array [ to-strings concat ] }
|
|
|
|
}
|
|
|
|
case ;
|
|
|
|
|
|
|
|
: to-strings ( seq -- str )
|
|
|
|
dup [ string? ] all?
|
|
|
|
[ ]
|
|
|
|
[ [ to-string ] map flatten ]
|
|
|
|
if ;
|
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
2008-03-07 09:52:23 -05:00
|
|
|
! TUPLE: process* arguments stdin stdout stderr timeout ;
|
2008-02-14 01:43:50 -05:00
|
|
|
|
2008-03-07 09:52:23 -05:00
|
|
|
! : <process*> process* construct-empty ;
|
2008-02-14 01:43:50 -05:00
|
|
|
|
2008-03-07 09:52:23 -05:00
|
|
|
! : >desc ( process* -- desc )
|
|
|
|
! H{ } clone
|
|
|
|
! over arguments>> [ +arguments+ swap put-at ] when*
|
|
|
|
! over stdin>> [ +stdin+ swap put-at ] when*
|
|
|
|
! over stdout>> [ +stdout+ swap put-at ] when*
|
|
|
|
! over stderr>> [ +stderr+ swap put-at ] when*
|
|
|
|
! over timeout>> [ +timeout+ swap put-at ] when*
|
|
|
|
! nip ;
|
2008-02-14 01:43:50 -05:00
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
|
|
|
: host-name* ( -- name ) host-name "." split first ;
|
|
|
|
|
|
|
|
: datestamp ( -- string )
|
|
|
|
now `{ ,[ dup timestamp-year ]
|
|
|
|
,[ dup timestamp-month ]
|
|
|
|
,[ dup timestamp-day ]
|
|
|
|
,[ dup timestamp-hour ]
|
|
|
|
,[ timestamp-minute ] }
|
|
|
|
[ pad-00 ] map "-" join ;
|
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
|
|
|
: milli-seconds>time ( n -- string )
|
|
|
|
1000 /i 60 /mod >r 60 /mod r> 3array [ pad-00 ] map ":" join ;
|
|
|
|
|
2008-03-07 19:30:47 -05:00
|
|
|
: eval-file ( file -- obj ) utf8 file-contents eval ;
|
2008-02-14 01:43:50 -05:00
|
|
|
|
2008-03-07 09:52:23 -05:00
|
|
|
: cat ( file -- ) utf8 file-contents print ;
|
2008-02-14 01:43:50 -05:00
|
|
|
|
|
|
|
: run-or-bail ( desc quot -- )
|
2008-02-14 06:20:38 -05:00
|
|
|
[ [ try-process ] curry ]
|
|
|
|
[ [ throw ] compose ]
|
2008-02-14 01:43:50 -05:00
|
|
|
bi*
|
|
|
|
recover ;
|
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
2008-02-15 04:17:30 -05:00
|
|
|
USING: bootstrap.image bootstrap.image.download io.streams.null ;
|
|
|
|
|
2008-02-19 17:45:19 -05:00
|
|
|
: retrieve-image ( -- ) [ my-arch download-image ] with-null-stream ;
|
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
|
|
|
: longer? ( seq seq -- ? ) [ length ] 2apply > ;
|
|
|
|
|
|
|
|
: maybe-tail* ( seq n -- seq )
|
|
|
|
2dup longer?
|
|
|
|
[ tail* ]
|
|
|
|
[ drop ]
|
|
|
|
if ;
|
|
|
|
|
|
|
|
: cat-n ( file n -- )
|
2008-03-07 09:52:23 -05:00
|
|
|
[ utf8 file-lines ] [ ] bi*
|
2008-02-19 17:45:19 -05:00
|
|
|
maybe-tail*
|
2008-02-21 20:38:51 -05:00
|
|
|
[ print ] each ;
|
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
|
|
|
USE: prettyprint
|
|
|
|
|
2008-03-07 09:52:23 -05:00
|
|
|
: to-file ( object file -- ) utf8 [ . ] with-file-writer ;
|
2008-02-25 19:39:27 -05:00
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
2008-03-03 15:06:16 -05:00
|
|
|
: failsafe ( quot -- ) [ drop ] recover ;
|