]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/update/util/util.factor
56916cf595c49b3eacd2afae52082b3997c6b1a1
[factor.git] / unmaintained / update / util / util.factor
1
2 USING: kernel classes strings quotations words math math.parser arrays
3        combinators.smart
4        accessors
5        system prettyprint splitting
6        sequences combinators sequences.deep
7        io
8        io.launcher
9        io.encodings.utf8
10        calendar
11        calendar.format ;
12
13 IN: update.util
14
15 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16
17 DEFER: to-strings
18
19 : to-string ( obj -- str )
20   dup class-of
21     {
22       { \ string    [ ] }
23       { \ quotation [ call( -- string ) ] }
24       { \ word      [ execute( -- string ) ] }
25       { \ fixnum    [ number>string ] }
26       { \ array     [ to-strings concat ] }
27     }
28   case ;
29
30 : to-strings ( seq -- str )
31   dup [ string? ] all?
32     [ ]
33     [ [ to-string ] map flatten ]
34   if ;
35
36 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
37
38 : cpu- ( -- cpu ) cpu unparse "." split "-" join ;
39
40 : platform ( -- string ) { [ os unparse ] cpu- } to-strings "-" join ;
41
42 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
43
44 : branch-name ( -- string ) "clean-" platform append ;
45
46 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
47
48 : gnu-make ( -- string )
49     "make" ;
50
51 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
52
53 : git-id ( -- id )
54   { "git" "show" } utf8 [ readln ] with-process-reader
55   " " split second ;
56
57 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
58
59 : datestamp ( -- string )
60   now
61   [ { [ year>> ] [ month>> ] [ day>> ] [ hour>> ] [ minute>> ] } cleave ] output>array
62   [ pad-00 ] map "-" join ;