Update 'size-of' and move to extra from unmaintained

db4
Eduardo Cavazos 2008-12-22 06:37:33 -06:00
parent e4edfe076d
commit 75337648cf
1 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
USING: io io.encodings.ascii io.files io.files.temp io.launcher
locals math.parser sequences sequences.deep ;
IN: size-of
! Use 'size-of' to find out the size in bytes of a C type.
!
! The 'headers' argument is a list of header files to use. You may
! pass 'f' to only use 'stdio.h'.
!
! Examples:
!
! f "int" size-of .
!
! { "X11/Xlib.h" } "XAnyEvent" size-of .
:: size-of ( HEADERS TYPE -- n )
[let | C-FILE [ "size-of.c" temp-file ]
EXE-FILE [ "size-of" temp-file ]
INCLUDES [ HEADERS [| FILE | { "#include <" FILE ">" } concat ] map ] |
{
"#include <stdio.h>"
INCLUDES
"main() { printf( \"%i\" , sizeof( " TYPE " ) ) ; }"
}
flatten C-FILE ascii set-file-lines
{ "gcc" C-FILE "-o" EXE-FILE } try-process
EXE-FILE ascii <process-reader> contents string>number ] ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!