Add os-version hook to system-info which returns f on every platform except windows, where it returns { 5 1 } for xp and { 6 1 } for win7. Eventually do more here, like identify Snow Leopard, Lion, etc, but it's good enough to make ping tests pass.

Move system-info platform loader into system-info.backend
Add win7? and winxp? words to system-info, clean up ping-tests with new word
Merge system-info.backend into system-info. Will throw an exception when loading on *bsd now
db4
Doug Coleman 2011-09-08 14:07:12 -07:00
parent ed416d210b
commit 937bdbb6ec
7 changed files with 42 additions and 39 deletions

View File

@ -1 +0,0 @@
Doug Coleman

View File

@ -1,15 +0,0 @@
! 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 )

View File

@ -2,7 +2,7 @@
! 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
@ -23,3 +23,5 @@ FUNCTION-ALIAS: (uname)
: kernel-version ( -- seq )
release ".-" split harvest 5 "" pad-tail ;
M: linux os-version f ;

View File

@ -2,9 +2,11 @@
! 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

View File

@ -1,9 +1,21 @@
! 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* ;
@ -12,14 +24,13 @@ IN: system-info
: gigs ( x -- ) 30 "GB" write-unit ;
: ghz ( x -- ) 1000000000 /f number>string write bl "GHz" write ;
<< {
{ [ 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 ;
<< {
{ [ os windows? ] [ "system-info.windows" ] }
{ [ os linux? ] [ "system-info.linux" ] }
{ [ os macosx? ] [ "system-info.macosx" ] }
} cond [ require ] when* >>

View File

@ -1,6 +1,6 @@
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

View File

@ -1,9 +1,10 @@
! 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
@ -21,25 +22,28 @@ 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 ;