]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/size-of/size-of.factor
c5fae3c647191170b19db16dc220111aebac2ac7
[factor.git] / unmaintained / size-of / size-of.factor
1
2 USING: io io.encodings.ascii io.files io.files.temp io.launcher
3        locals math.parser sequences sequences.deep
4        help.syntax
5        easy-help ;
6
7 IN: size-of
8
9 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10
11 Word: size-of
12
13 Values:
14
15     HEADERS sequence : List of header files
16     TYPE    string : A C type
17     n       integer : Size in number of bytes ..
18
19 Description:
20
21     Use 'size-of' to find out the size in bytes of a C type. 
22
23     The 'headers' argument is a list of header files to use. You may 
24     pass 'f' to only use 'stdio.h'. ..
25
26 Example:
27
28     ! Find the size of 'int'
29
30     f "int" size-of .    ..
31
32 Example:
33
34     ! Find the size of the 'XAnyEvent' struct from Xlib.h
35
36     { "X11/Xlib.h" } "XAnyEvent" size-of .    ..
37
38 ;
39
40 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
41
42 :: size-of ( HEADERS TYPE -- n )
43
44   [let | C-FILE   [ "size-of.c" temp-file ]
45          EXE-FILE [ "size-of"   temp-file ]
46          INCLUDES [ HEADERS [| FILE | { "#include <" FILE ">" } concat ] map ] |
47
48     {
49       "#include <stdio.h>"
50       INCLUDES
51       "main() { printf( \"%i\" , sizeof( " TYPE " ) ) ; }"
52     }
53
54     flatten C-FILE  ascii  set-file-lines
55
56     { "gcc" C-FILE "-o" EXE-FILE } try-process
57
58     EXE-FILE ascii <process-reader> contents string>number ] ;
59
60 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
61