factor/extra/builder/util/util.factor

107 lines
2.7 KiB
Factor
Raw Normal View History

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
system
2008-02-14 01:43:50 -05:00
combinators sequences splitting quotations arrays strings tools.time
2008-03-20 21:08:32 -04:00
sequences.deep accessors assocs.lib
2008-03-07 09:52:23 -05:00
io.encodings.utf8
combinators.cleave calendar calendar.format eval ;
2008-02-14 01:43:50 -05:00
IN: builder.util
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: minutes>ms ( min -- ms ) 60 * 1000 * ;
2008-05-05 18:31:46 -04:00
: file>string ( file -- string ) utf8 file-contents ;
2008-02-14 01:43:50 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
DEFER: to-strings
: to-string ( obj -- str )
dup class
{
2008-04-12 22:54:35 -04:00
{ \ string [ ] }
{ \ quotation [ call ] }
{ \ word [ execute ] }
{ \ fixnum [ number>string ] }
{ \ array [ to-strings concat ] }
2008-02-14 01:43:50 -05:00
}
case ;
: to-strings ( seq -- str )
dup [ string? ] all?
[ ]
[ [ to-string ] map flatten ]
if ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: host-name* ( -- name ) host-name "." split first ;
: datestamp ( -- string )
2008-05-15 17:57:41 -04:00
now
{ year>> month>> day>> hour>> minute>> } <arr>
2008-02-14 01:43:50 -05:00
[ pad-00 ] map "-" join ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: milli-seconds>time ( n -- string )
1000 /i 60 /mod >r 60 /mod r> 3array [ pad-00 ] map ":" join ;
: 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 ;
: retrieve-image ( -- ) [ my-arch download-image ] with-null-stream ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2008-03-29 21:36:58 -04:00
: longer? ( seq seq -- ? ) [ length ] bi@ > ;
: 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*
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
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: cpu- ( -- cpu ) cpu unparse "." split "-" join ;
2008-04-12 22:54:35 -04:00
: platform ( -- string ) { [ os unparse ] cpu- } to-strings "-" join ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: gnu-make ( -- string )
os { freebsd openbsd netbsd } member? [ "gmake" ] [ "make" ] if ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: git-id ( -- id )
2008-05-05 18:31:46 -04:00
{ "git" "show" } utf8 <process-reader> [ readln ] with-input-stream
2008-04-12 22:54:35 -04:00
" " split second ;