From 937bdbb6eca4a34f1edb5d4d87643b01840f4d10 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 8 Sep 2011 14:07:12 -0700 Subject: [PATCH] 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 --- basis/system-info/backend/authors.txt | 1 - basis/system-info/backend/backend.factor | 15 ---------- basis/system-info/linux/linux.factor | 4 ++- basis/system-info/macosx/macosx.factor | 4 ++- basis/system-info/system-info.factor | 29 +++++++++++++------ .../system-info/windows/windows-tests.factor | 6 ++-- basis/system-info/windows/windows.factor | 22 ++++++++------ 7 files changed, 42 insertions(+), 39 deletions(-) delete mode 100755 basis/system-info/backend/authors.txt delete mode 100644 basis/system-info/backend/backend.factor diff --git a/basis/system-info/backend/authors.txt b/basis/system-info/backend/authors.txt deleted file mode 100755 index 7c1b2f2279..0000000000 --- a/basis/system-info/backend/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Doug Coleman diff --git a/basis/system-info/backend/backend.factor b/basis/system-info/backend/backend.factor deleted file mode 100644 index 6e6715f619..0000000000 --- a/basis/system-info/backend/backend.factor +++ /dev/null @@ -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 ) diff --git a/basis/system-info/linux/linux.factor b/basis/system-info/linux/linux.factor index 2eb395b8d1..d5ee9915be 100644 --- a/basis/system-info/linux/linux.factor +++ b/basis/system-info/linux/linux.factor @@ -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 ; \ No newline at end of file diff --git a/basis/system-info/macosx/macosx.factor b/basis/system-info/macosx/macosx.factor index d4f2277128..faf69a881e 100644 --- a/basis/system-info/macosx/macosx.factor +++ b/basis/system-info/macosx/macosx.factor @@ -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 diff --git a/basis/system-info/system-info.factor b/basis/system-info/system-info.factor index 5bf886abd8..fdeaa50fde 100644 --- a/basis/system-info/system-info.factor +++ b/basis/system-info/system-info.factor @@ -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* >> diff --git a/basis/system-info/windows/windows-tests.factor b/basis/system-info/windows/windows-tests.factor index d26e86742c..5e8bed7c6c 100644 --- a/basis/system-info/windows/windows-tests.factor +++ b/basis/system-info/windows/windows-tests.factor @@ -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 diff --git a/basis/system-info/windows/windows.factor b/basis/system-info/windows/windows.factor index 4ff252bf25..8aa295519a 100644 --- a/basis/system-info/windows/windows.factor +++ b/basis/system-info/windows/windows.factor @@ -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 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 ;