From: simonpj Date: Wed, 13 Feb 2002 10:39:36 +0000 (+0000) Subject: [project @ 2002-02-13 10:39:36 by simonpj] X-Git-Tag: Approximately_9120_patches~83 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=9b7de002ff5d580adb9777bf2777a425231e0c13;p=ghc-hetmet.git [project @ 2002-02-13 10:39:36 by simonpj] ------------------------------- dosifyPath before opening files ------------------------------- If you call hsc2hs foo/baz you get the amazing response: 'foo' is not recognized as an internal or external command, operable program or batch file. On the other hand hsc2hs foo\baz works fine. Solution: call dosifyPath before opening or writing the file. Somehow we should make it less easy to trip up when doing file I/O on Windows. And provide a library of path-manipulation primitives. --- diff --git a/ghc/utils/hsc2hs/Main.hs b/ghc/utils/hsc2hs/Main.hs index 030471a..00ff523 100644 --- a/ghc/utils/hsc2hs/Main.hs +++ b/ghc/utils/hsc2hs/Main.hs @@ -1,5 +1,5 @@ ------------------------------------------------------------------------ --- $Id: Main.hs,v 1.36 2002/02/12 15:17:24 simonmar Exp $ +-- $Id: Main.hs,v 1.37 2002/02/13 10:39:36 simonpj 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. @@ -93,14 +93,25 @@ main = do exitFailure processFile :: [Flag] -> String -> IO () -processFile flags name = do - s <- readFile name - case parser of - Parser p -> case p (SourcePos name 1) s of - Success _ _ _ toks -> output flags name toks - Failure (SourcePos name' line) msg -> do - putStrLn (name'++":"++show line++": "++msg) - exitFailure +processFile flags name + = do let file_name = dosifyPath name + s <- readFile file_name + case parser of + Parser p -> case p (SourcePos file_name 1) s of + Success _ _ _ toks -> output flags file_name toks + Failure (SourcePos name' line) msg -> do + putStrLn (name'++":"++show line++": "++msg) + exitFailure + +------------------------------------------------------------------------ +-- Convert paths foo/baz to foo\baz on Windows + +#if defined(mingw32_TARGET_OS) +subst a b ls = map (\ x -> if x == a then b else x) ls +dosifyPath xs = subst '/' '\\' xs +#else +dosifyPath xs = xs +#endif ------------------------------------------------------------------------ -- A deterministic parser which remembers the text which has been parsed.