+++ /dev/null
-Doug Coleman
+++ /dev/null
-! Copyright (C) 2008 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: system ;
-IN: system-info.backend
-
-HOOK: cpus os ( -- n )
-HOOK: cpu-mhz os ( -- n )
-HOOK: memory-load os ( -- n )
-HOOK: physical-mem os ( -- n )
-HOOK: available-mem os ( -- n )
-HOOK: total-page-file os ( -- n )
-HOOK: available-page-file os ( -- n )
-HOOK: total-virtual-mem os ( -- n )
-HOOK: available-virtual-mem os ( -- n )
-HOOK: available-virtual-extended-mem os ( -- n )
! See http://factorcode.org/license.txt for BSD license.
USING: unix alien alien.c-types kernel math sequences strings
io.backend.unix splitting io.encodings.utf8 io.encodings.string
-specialized-arrays alien.syntax ;
+specialized-arrays alien.syntax system-info ;
SPECIALIZED-ARRAY: char
IN: system-info.linux
: kernel-version ( -- seq )
release ".-" split harvest 5 "" pad-tail ;
+
+M: linux os-version f ;
\ No newline at end of file
! See http://factorcode.org/license.txt for BSD license.
USING: alien alien.c-types alien.data alien.strings alien.syntax
byte-arrays kernel namespaces sequences unix
-system-info.backend system io.encodings.utf8 ;
+system io.encodings.utf8 system-info ;
IN: system-info.macosx
+M: macosx os-version f ;
+
! See /usr/include/sys/sysctl.h for constants
LIBRARY: libc
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien.syntax kernel math prettyprint io math.parser
-combinators vocabs.loader system-info.backend system ;
+USING: combinators io kernel math math.parser system
+vocabs.loader ;
IN: system-info
+HOOK: os-version os ( -- version )
+HOOK: cpus os ( -- n )
+HOOK: cpu-mhz os ( -- n )
+HOOK: memory-load os ( -- n )
+HOOK: physical-mem os ( -- n )
+HOOK: available-mem os ( -- n )
+HOOK: total-page-file os ( -- n )
+HOOK: available-page-file os ( -- n )
+HOOK: total-virtual-mem os ( -- n )
+HOOK: available-virtual-mem os ( -- n )
+HOOK: available-virtual-extended-mem os ( -- n )
+
: write-unit ( x n str -- )
[ 2^ /f number>string write bl ] [ write ] bi* ;
: gigs ( x -- ) 30 "GB" write-unit ;
: ghz ( x -- ) 1000000000 /f number>string write bl "GHz" write ;
+: system-report. ( -- )
+ "CPUs: " write cpus number>string write nl
+ "CPU Speed: " write cpu-mhz ghz nl
+ "Physical RAM: " write physical-mem megs nl ;
+
<< {
{ [ os windows? ] [ "system-info.windows" ] }
{ [ os linux? ] [ "system-info.linux" ] }
{ [ os macosx? ] [ "system-info.macosx" ] }
- [ f ]
} cond [ require ] when* >>
-
-: system-report. ( -- )
- "CPUs: " write cpus number>string write nl
- "CPU Speed: " write cpu-mhz ghz nl
- "Physical RAM: " write physical-mem megs nl ;
-USING: math.order strings system-info.backend
-system-info.windows tools.test ;
+USING: math math.order strings system-info.windows tools.test
+system-info ;
IN: system-info.windows.tests
-[ t ] [ cpus 0 1024 between? ] unit-test
+[ t ] [ cpus integer? ] unit-test
[ t ] [ username string? ] unit-test
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.data alien.strings
-byte-arrays classes.struct combinators kernel math namespaces
-specialized-arrays system system-info.backend vocabs.loader
-windows windows.advapi32 windows.errors windows.kernel32 words ;
+arrays byte-arrays classes.struct combinators kernel math
+namespaces specialized-arrays system
+vocabs.loader windows windows.advapi32
+windows.errors windows.kernel32 words ;
SPECIALIZED-ARRAY: ushort
IN: system-info.windows
: processor-architecture ( -- n )
system-info dwOemId>> HEX: ffff0000 bitand ;
-: os-version ( -- os-version )
+: os-version-struct ( -- os-version )
OSVERSIONINFO <struct>
OSVERSIONINFO heap-size >>dwOSVersionInfoSize
dup GetVersionEx win32-error=0/f ;
: windows-major ( -- n )
- os-version dwMajorVersion>> ;
+ os-version-struct dwMajorVersion>> ;
: windows-minor ( -- n )
- os-version dwMinorVersion>> ;
+ os-version-struct dwMinorVersion>> ;
+M: winnt os-version ( -- obj )
+ os-version-struct [ dwMajorVersion>> ] [ dwMinorVersion>> ] bi 2array ;
+
: windows-build# ( -- n )
- os-version dwBuildNumber>> ;
+ os-version-struct dwBuildNumber>> ;
: windows-platform-id ( -- n )
- os-version dwPlatformId>> ;
+ os-version-struct dwPlatformId>> ;
: windows-service-pack ( -- string )
- os-version szCSDVersion>> alien>native-string ;
+ os-version-struct szCSDVersion>> alien>native-string ;
: feature-present? ( n -- ? )
IsProcessorFeaturePresent zero? not ;