X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=ghc%2Fcompiler%2Fmain%2FCmdLineOpts.lhs;fp=ghc%2Fcompiler%2Fmain%2FCmdLineOpts.lhs;h=a230e8df6d3e910d27951da07110b794868ad267;hb=9d55b184a39e35dd18764713137054f79b8aa088;hp=68616206a70d5724897a60aaeb6392c54b9f302e;hpb=812238d612a22ad86d8c823dcc1dec2af02e3350;p=ghc-hetmet.git diff --git a/ghc/compiler/main/CmdLineOpts.lhs b/ghc/compiler/main/CmdLineOpts.lhs index 6861620..a230e8d 100644 --- a/ghc/compiler/main/CmdLineOpts.lhs +++ b/ghc/compiler/main/CmdLineOpts.lhs @@ -104,6 +104,7 @@ import FastString ( FastString, mkFastString ) import Config import Maybes ( firstJust ) +import Panic ( ghcError, GhcException(UsageError) ) import GLAEXTS import DATA_IOREF ( IORef, readIORef, writeIORef ) import UNSAFE_IO ( unsafePerformIO ) @@ -708,19 +709,36 @@ packed_static_opts = map mkFastString unpacked_static_opts lookUp sw = sw `elem` packed_static_opts -lookup_str sw = firstJust (map (startsWith sw) unpacked_static_opts) +-- (lookup_str "foo") looks for the flag -foo=X or -fooX, +-- and returns the string X +lookup_str sw + = case firstJust (map (startsWith sw) unpacked_static_opts) of + Just ('=' : str) -> Just str + Just str -> Just str + Nothing -> Nothing lookup_int sw = case (lookup_str sw) of Nothing -> Nothing - Just xx -> Just (read xx) + Just xx -> Just (try_read sw xx) lookup_def_int sw def = case (lookup_str sw) of Nothing -> def -- Use default - Just xx -> read xx + Just xx -> try_read sw xx lookup_def_float sw def = case (lookup_str sw) of Nothing -> def -- Use default - Just xx -> read xx + Just xx -> try_read sw xx + + +try_read :: Read a => String -> String -> a +-- (try_read sw str) tries to read s; if it fails, it +-- bleats about flag sw +try_read sw str + = case reads str of + ((x,_):_) -> x -- Be forgiving: ignore trailing goop, and alternative parses + [] -> ghcError (UsageError ("Malformed argument " ++ str ++ " for flag " ++ sw)) + -- ToDo: hack alert. We should really parse the arugments + -- and announce errors in a more civilised way. {-