[project @ 2002-02-13 10:39:36 by simonpj]
authorsimonpj <unknown>
Wed, 13 Feb 2002 10:39:36 +0000 (10:39 +0000)
committersimonpj <unknown>
Wed, 13 Feb 2002 10:39:36 +0000 (10:39 +0000)
-------------------------------
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.

ghc/utils/hsc2hs/Main.hs

index 030471a..00ff523 100644 (file)
@@ -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.