X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Futils%2Fhsc2hs%2FMain.hs;h=ee30d09ad455df6865790eb5dbc295662bd238fd;hb=c63aaee42e3e95276861121286eefce511cd1343;hp=2527516861ec68581acd054106029895a8c91994;hpb=394d30831452e862f85e8ea6458351f56130f8ba;p=ghc-hetmet.git diff --git a/ghc/utils/hsc2hs/Main.hs b/ghc/utils/hsc2hs/Main.hs index 2527516..ee30d09 100644 --- a/ghc/utils/hsc2hs/Main.hs +++ b/ghc/utils/hsc2hs/Main.hs @@ -1,5 +1,5 @@ ------------------------------------------------------------------------ --- $Id: Main.hs,v 1.40 2002/09/09 11:39:42 simonmar Exp $ +-- $Id: Main.hs,v 1.41 2002/10/27 10:38:33 mthomas Exp $ -- -- Program for converting .hsc files to .hs files, by converting the -- file into a C program which is run to generate the Haskell source. @@ -25,7 +25,23 @@ import List (intersperse) #include "../../includes/config.h" #ifdef mingw32_HOST_OS -import Win32DLL +-- import Win32DLL +import Foreign.C.String (CString, peekCString) +import Foreign.C.Types +import Foreign.Ptr (nullPtr) +import Foreign.Marshal.Alloc (mallocBytes, free) + +foreign import stdcall "GetModuleHandle" c_GetModuleHandle :: CString -> IO CUInt +foreign import stdcall "GetModuleFileName" c_GetModuleFilename :: CUInt -> CString -> CUInt -> IO CUInt + +ourName :: IO String +ourName = do h <- c_GetModuleHandle nullPtr + cstr <- mallocBytes cstr_len + rv <- c_GetModuleFilename h cstr (CUInt (fromIntegral cstr_len)) + str <- peekCString cstr + free cstr + return str + where cstr_len = 512 #endif version :: String @@ -77,8 +93,7 @@ main = do args <- getArgs let opts@(flags, files, errs) = getOpt Permute options args #ifdef mingw32_HOST_OS - h <- getModuleHandle Nothing - n <- getModuleFileName h + n <- ourName let tempName = reverse (drop (length "\\bin\\hsc2hs.exe") (reverse n)) ++ "\\template-hsc.h" let fflags = if [t | Template t <- flags] /= [] then flags else (Template tempName) : flags let opts = (fflags, files, errs) @@ -744,3 +759,4 @@ showCString = concatMap showCChar intToDigit (ord c `quot` 64), intToDigit (ord c `quot` 8 `mod` 8), intToDigit (ord c `mod` 8)] +