-------------------------------
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.
------------------------------------------------------------------------
------------------------------------------------------------------------
--- $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.
--
-- Program for converting .hsc files to .hs files, by converting the
-- file into a C program which is run to generate the Haskell source.
exitFailure
processFile :: [Flag] -> String -> IO ()
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.
------------------------------------------------------------------------
-- A deterministic parser which remembers the text which has been parsed.