From fa167f5b3e8a10d50b1f1eee7a60c9c6d6aa30b2 Mon Sep 17 00:00:00 2001 From: simonmar Date: Tue, 24 Feb 2004 12:39:42 +0000 Subject: [PATCH] [project @ 2004-02-24 12:39:12 by simonmar] New version of translate for mingw32, which correctly (allegedly) reverses the command-line translation done by the standard C runtime on Windows. --- ghc/compiler/main/SysTools.lhs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/ghc/compiler/main/SysTools.lhs b/ghc/compiler/main/SysTools.lhs index 0cba9d2..da940ad 100644 --- a/ghc/compiler/main/SysTools.lhs +++ b/ghc/compiler/main/SysTools.lhs @@ -810,16 +810,25 @@ rawSystem cmd args = do n -> return (ExitFailure n) translate :: String -> String --- Returns a string wrapped in double-quotes --- If the input string starts with double-quote, don't touch it --- If not, wrap it in double-quotes and double any backslashes --- foo\baz --> "foo\\baz" --- "foo\baz" --> "foo\baz" - translate str@('"':_) = str -- already escaped. -translate str = '"' : foldr escape "\"" str - where escape '"' str = '\\' : '"' : str - escape c str = c : str + -- ToDo: this case is wrong. It is only here because we + -- abuse the system in GHC's SysTools by putting arguments into + -- the command name; at some point we should fix it up and remove + -- the case above. +translate str = '"' : snd (foldr escape (True,"\"") str) + where escape '"' (b, str) = (True, '\\' : '"' : str) + escape '\\' (True, str) = (True, '\\' : '\\' : str) + escape '\\' (False, str) = (False, '\\' : str) + escape c (b, str) = (False, c : str) + -- This function attempts to invert the Microsoft C runtime's + -- quoting rules, which can be found here: + -- http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/progs_12.asp + -- (if this URL stops working, you might be able to find it by + -- searching for "Parsing C Command-Line Arguments" on MSDN). + -- + -- The Bool passed back along the string is True iff the + -- rest of the string is a sequence of backslashes followed by + -- a double quote. foreign import ccall "rawSystem" unsafe c_rawSystem :: CString -> IO Int -- 1.7.10.4