From f3f5a047efe49530fa730912c8f80d4c57b53347 Mon Sep 17 00:00:00 2001 From: Jose A Ortega Ruiz Date: Tue, 16 Feb 2010 22:56:56 +0100 Subject: Documenting that flags must be passed to cabal _install_ Ignore-this: 30cf6bf6382573808029b6650a20564 darcs-hash:20100216215656-748be-762a06cee059c8fd1083e964a4e03f455568a5af.gz --- Plugins/Monitors/Disk.hs | 2 +- Plugins/Monitors/StatFS.hsc | 71 --------------------------------------------- README | 4 +-- StatFS.hsc | 70 ++++++++++++++++++++++++++++++++++++++++++++ xmobar.cabal | 23 ++++++++------- 5 files changed, 85 insertions(+), 85 deletions(-) delete mode 100644 Plugins/Monitors/StatFS.hsc create mode 100644 StatFS.hsc diff --git a/Plugins/Monitors/Disk.hs b/Plugins/Monitors/Disk.hs index 3a9a70f..c0d8de7 100644 --- a/Plugins/Monitors/Disk.hs +++ b/Plugins/Monitors/Disk.hs @@ -17,7 +17,7 @@ module Plugins.Monitors.Disk ( diskUConfig, runDiskU ) where import Plugins.Monitors.Common -import Plugins.Monitors.StatFS +import StatFS import Control.Monad (zipWithM) import qualified Data.ByteString.Lazy.Char8 as B diff --git a/Plugins/Monitors/StatFS.hsc b/Plugins/Monitors/StatFS.hsc deleted file mode 100644 index 9c1972c..0000000 --- a/Plugins/Monitors/StatFS.hsc +++ /dev/null @@ -1,71 +0,0 @@ ------------------------------------------------------------------------------ --- | --- Module : Plugins.Monitors.StatFS --- Copyright : (c) Jose A Ortega Ruiz --- License : BSD-style (see LICENSE) --- --- Maintainer : Jose A Ortega Ruiz --- Stability : unstable --- Portability : unportable --- --- A binding to C's statvfs(2) --- ------------------------------------------------------------------------------ - -{-# LANGUAGE CPP, ForeignFunctionInterface, EmptyDataDecls #-} - - -module Plugins.Monitors.StatFS ( FileSystemStats(..) - , getFileSystemStats ) where - -import Foreign -import Foreign.C.Types -import Foreign.C.String -import Data.ByteString (useAsCString) -import Data.ByteString.Char8 (pack) - -#include - -data FileSystemStats = FileSystemStats { - fsStatBlockSize :: Integer - -- ^ Optimal transfer block size. - , fsStatBlockCount :: Integer - -- ^ Total data blocks in file system. - , fsStatByteCount :: Integer - -- ^ Total bytes in file system. - , fsStatBytesFree :: Integer - -- ^ Free bytes in file system. - , fsStatBytesAvailable :: Integer - -- ^ Free bytes available to non-superusers. - , fsStatBytesUsed :: Integer - -- ^ Bytes used. - } deriving (Show, Eq) - -data CStatfs - -foreign import ccall unsafe "sys/vfs.h statfs64" - c_statfs :: CString -> Ptr CStatfs -> IO CInt - -toI :: CLong -> Integer -toI = toInteger - -getFileSystemStats :: String -> IO (Maybe FileSystemStats) -getFileSystemStats path = - allocaBytes (#size struct statfs) $ \vfs -> - useAsCString (pack path) $ \cpath -> do - res <- c_statfs cpath vfs - if res == -1 then return Nothing - else do - bsize <- (#peek struct statfs, f_bsize) vfs - bcount <- (#peek struct statfs, f_blocks) vfs - bfree <- (#peek struct statfs, f_bfree) vfs - bavail <- (#peek struct statfs, f_bavail) vfs - let bpb = toI bsize - return $ Just FileSystemStats - { fsStatBlockSize = bpb - , fsStatBlockCount = toI bcount - , fsStatByteCount = toI bcount * bpb - , fsStatBytesFree = toI bfree * bpb - , fsStatBytesAvailable = toI bavail * bpb - , fsStatBytesUsed = toI (bcount - bfree) * bpb - } diff --git a/README b/README index 27fdcfb..4fdcf4e 100644 --- a/README +++ b/README @@ -433,7 +433,7 @@ Monitors have default aliases. - Args: list of maildirs in form [("name1","path1"),("name2","path2")] - This plugin requires INOTIFY support in Linux kernel and hinotify library. To activate, pass --flags="with_inotify" to "runhaskell Setup configure" - or to "cabal configure". + or to "cabal install". `MBox Mboxes BaseDir` @@ -447,7 +447,7 @@ Monitors have default aliases. absolute. - This plugin requires INOTIFY support in Linux kernel and hinotify library. To activate, pass --flags="with_inotify" to "runhaskell Setup - configure" or to "cabal configure". + configure" or to "cabal install". - Example: `Run MBox [("I ", "inbox", "red"), ("O ", "/foo/mbox", "")] "/var/mail/"` will look for mails in /var/mail/inbox and /foo/mbox. diff --git a/StatFS.hsc b/StatFS.hsc new file mode 100644 index 0000000..215be81 --- /dev/null +++ b/StatFS.hsc @@ -0,0 +1,70 @@ +----------------------------------------------------------------------------- +-- | +-- Module : StatFS +-- Copyright : (c) Jose A Ortega Ruiz +-- License : BSD-style (see LICENSE) +-- +-- Maintainer : Jose A Ortega Ruiz +-- Stability : unstable +-- Portability : unportable +-- +-- A binding to C's statvfs(2) +-- +----------------------------------------------------------------------------- + +{-# LANGUAGE CPP, ForeignFunctionInterface, EmptyDataDecls #-} + + +module StatFS ( FileSystemStats(..), getFileSystemStats ) where + +import Foreign +import Foreign.C.Types +import Foreign.C.String +import Data.ByteString (useAsCString) +import Data.ByteString.Char8 (pack) + +#include + +data FileSystemStats = FileSystemStats { + fsStatBlockSize :: Integer + -- ^ Optimal transfer block size. + , fsStatBlockCount :: Integer + -- ^ Total data blocks in file system. + , fsStatByteCount :: Integer + -- ^ Total bytes in file system. + , fsStatBytesFree :: Integer + -- ^ Free bytes in file system. + , fsStatBytesAvailable :: Integer + -- ^ Free bytes available to non-superusers. + , fsStatBytesUsed :: Integer + -- ^ Bytes used. + } deriving (Show, Eq) + +data CStatfs + +foreign import ccall unsafe "sys/vfs.h statfs64" + c_statfs :: CString -> Ptr CStatfs -> IO CInt + +toI :: CLong -> Integer +toI = toInteger + +getFileSystemStats :: String -> IO (Maybe FileSystemStats) +getFileSystemStats path = + allocaBytes (#size struct statfs) $ \vfs -> + useAsCString (pack path) $ \cpath -> do + res <- c_statfs cpath vfs + if res == -1 then return Nothing + else do + bsize <- (#peek struct statfs, f_bsize) vfs + bcount <- (#peek struct statfs, f_blocks) vfs + bfree <- (#peek struct statfs, f_bfree) vfs + bavail <- (#peek struct statfs, f_bavail) vfs + let bpb = toI bsize + return $ Just FileSystemStats + { fsStatBlockSize = bpb + , fsStatBlockCount = toI bcount + , fsStatByteCount = toI bcount * bpb + , fsStatBytesFree = toI bfree * bpb + , fsStatBytesAvailable = toI bavail * bpb + , fsStatBytesUsed = toI (bcount - bfree) * bpb + } diff --git a/xmobar.cabal b/xmobar.cabal index f3ded0b..24f6b36 100644 --- a/xmobar.cabal +++ b/xmobar.cabal @@ -33,17 +33,19 @@ flag with_inotify executable xmobar main-is: Main.hs - other-Modules: Xmobar, Config, Parsers, Commands, XUtil, Runnable, Plugins, Plugins.Monitors.StatFS + other-Modules: Xmobar, Config, Parsers, Commands, XUtil, StatFS, Runnable, Plugins ghc-prof-options: -prof -auto-all if true - ghc-options: -funbox-strict-fields -Wall + ghc-options: -funbox-strict-fields -Wall if impl (ghc == 6.10.1) && arch (x86_64) - ghc-options: -O0 + ghc-options: -O0 if impl (ghc >= 6.12.1) - ghc-options: -fno-warn-unused-do-bind + ghc-options: -fno-warn-unused-do-bind + + build-depends: X11>=1.3.0, mtl, unix, parsec, filepath, stm if flag(small_base) build-depends: base == 4.*, containers, process, old-time, old-locale, bytestring, directory @@ -52,15 +54,14 @@ executable xmobar build-depends: base < 3 if flag(with_xft) - build-depends: utf8-string, X11-xft >= 0.2 - cpp-options: -DXFT + build-depends: utf8-string, X11-xft >= 0.2 + cpp-options: -DXFT if flag(with_utf8) && impl (ghc < 6.12.1) - build-depends: utf8-string - cpp-options: -DUTF8 + build-depends: utf8-string + cpp-options: -DUTF8 if flag(with_inotify) - build-depends: hinotify - cpp-options: -DINOTIFY + build-depends: hinotify + cpp-options: -DINOTIFY - build-depends: X11>=1.3.0, mtl, unix, parsec, filepath, stm -- cgit v1.2.3