For nhc98 only, use hsc2hs to determine System.Posix.Types.
authorMalcolm.Wallace@cs.york.ac.uk <unknown>
Fri, 13 Apr 2007 15:58:31 +0000 (15:58 +0000)
committerMalcolm.Wallace@cs.york.ac.uk <unknown>
Fri, 13 Apr 2007 15:58:31 +0000 (15:58 +0000)
Avoids the existing autoconf stuff, by introducing an auxiliary module
called NHC.PosixTypes that uses hsc2hs, which is then simply re-exported
from System.Posix.Types.

Makefile.nhc98
NHC/PosixTypes.hsc [new file with mode: 0644]
System/Posix/Types.hs

index eb6f526..f8c9684 100644 (file)
@@ -17,7 +17,7 @@ SRCS  = \
        Control/Monad.hs Control/Monad/Fix.hs Control/Monad/Instances.hs \
        Control/Arrow.hs Control/Applicative.hs \
        Debug/Trace.hs \
-       NHC/SizedTypes.hs \
+       NHC/SizedTypes.hs NHC/PosixTypes.hsc \
        System/IO.hs System/IO/Error.hs System/IO/Unsafe.hs \
        System/Environment.hs System/Exit.hs System/Locale.hs \
        System/Directory.hs System/Mem.hs System/Cmd.hs System/Info.hs \
@@ -36,7 +36,7 @@ SRCS  = \
        Text/ParserCombinators/ReadP.hs Data/Version.hs \
        Unsafe/Coerce.hs \
        WCsubst.c \
-       System/Posix/Types.hsc \
+       System/Posix/Types.hs \
 
 
 #      Text/Regex/Posix.hsc Text/Regex.hs \
diff --git a/NHC/PosixTypes.hsc b/NHC/PosixTypes.hsc
new file mode 100644 (file)
index 0000000..fabe253
--- /dev/null
@@ -0,0 +1,85 @@
+{-# OPTIONS_NHC98 -I/usr/include #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  NHC.PosixTypes
+-- Copyright   :  (c) Malcolm Wallace 2007
+-- License     :  BSD-style (see the file libraries/base/LICENSE)
+-- 
+-- Maintainer  :  libraries@haskell.org
+-- Stability   :  provisional
+-- Portability :  non-portable (requires POSIX)
+--
+-- POSIX data types: Haskell equivalents of the types defined by the
+-- @\<sys\/types.h>@ C header on a POSIX system.
+--
+-----------------------------------------------------------------------------
+
+module NHC.PosixTypes (
+
+  -- * POSIX data types
+  CDev,
+  CIno,
+  CMode,
+  COff,
+  CPid,
+  CSsize,
+
+  CGid,
+  CNlink,
+  CUid,
+  CCc,
+  CSpeed,
+  CTcflag,
+  CRLim,
+
+  Fd(..),
+
+  LinkCount,
+  UserID,
+  GroupID,
+ ) where
+
+import Foreign
+import Foreign.C
+import Data.Typeable
+import Data.Bits
+import Unsafe.Coerce
+
+import Control.Monad
+
+
+-- Curious hack to ensure that the CTypes macros are expanded *after* hsc2hs.
+##include "CTypes.h"
+-- C header files that contain all the types we are looking for here.
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/resource.h>
+#include <termios.h>
+
+ARITHMETIC_TYPE(CDev,tyConCDev,"CDev",#{type dev_t})
+INTEGRAL_TYPE(CIno,tyConCIno,"CIno",#{type ino_t})
+INTEGRAL_TYPE(CMode,tyConCMode,"CMode",#{type mode_t})
+INTEGRAL_TYPE(COff,tyConCOff,"COff",#{type off_t})
+INTEGRAL_TYPE(CPid,tyConCPid,"CPid",#{type pid_t})
+
+INTEGRAL_TYPE(CSsize,tyConCSsize,"CSsize",#{type ssize_t})
+
+INTEGRAL_TYPE(CGid,tyConCGid,"CGid",#{type gid_t})
+INTEGRAL_TYPE(CNlink,tyConCNlink,"CNlink",#{type nlink_t})
+
+INTEGRAL_TYPE(CUid,tyConCUid,"CUid",#{type uid_t})
+ARITHMETIC_TYPE(CCc,tyConCCc,"CCc",#{type cc_t})
+ARITHMETIC_TYPE(CSpeed,tyConCSpeed,"CSpeed",#{type speed_t})
+INTEGRAL_TYPE(CTcflag,tyConCTcflag,"CTcflag",#{type tcflag_t})
+INTEGRAL_TYPE(CRLim,tyConCRlim,"CRLim",#{type rlim_t})
+
+-- ToDo: blksize_t, clockid_t, blkcnt_t, fsblkcnt_t, fsfilcnt_t, id_t, key_t
+-- suseconds_t, timer_t, useconds_t
+
+-- Make an Fd type rather than using CInt everywhere
+INTEGRAL_TYPE(Fd,tyConFd,"Fd",CInt)
+
+-- nicer names, and backwards compatibility with POSIX library:
+type LinkCount      = CNlink
+type UserID         = CUid
+type GroupID        = CGid
index 7ade7bf..54fa8b8 100644 (file)
 -- @\<sys\/types.h>@ C header on a POSIX system.
 --
 -----------------------------------------------------------------------------
-
+#ifdef __NHC__
+#define HTYPE_DEV_T
+#define HTYPE_INO_T
+#define HTYPE_MODE_T
+#define HTYPE_OFF_T
+#define HTYPE_PID_T
+#define HTYPE_SSIZE_T
+#define HTYPE_GID_T
+#define HTYPE_NLINK_T
+#define HTYPE_UID_T
+#define HTYPE_CC_T
+#define HTYPE_SPEED_T
+#define HTYPE_TCFLAG_T
+#define HTYPE_RLIM_T
+#define HTYPE_NLINK_T
+#define HTYPE_UID_T
+#define HTYPE_GID_T
+#else
 #include "HsBaseConfig.h"
+#endif
 
 module System.Posix.Types (
 
@@ -84,6 +102,11 @@ module System.Posix.Types (
   Limit
  ) where
 
+#ifdef __NHC__
+import NHC.PosixTypes
+import Foreign.C
+#else
+
 import Foreign
 import Foreign.C
 import Data.Typeable
@@ -163,6 +186,8 @@ type UserID         = CUid
 type GroupID        = CGid
 #endif
 
+#endif /* !__NHC__ */
+
 type ByteCount      = CSize
 type ClockTick      = CClock
 type EpochTime      = CTime