Commit 53d5771a authored by Michael Hanus 's avatar Michael Hanus
Browse files

More options for CASS

parent 06f617c9
......@@ -42,35 +42,46 @@ main = do
debugMessageLevel 1 systemBanner
initializeAnalysisSystem
args <- getArgs
if null args then mainServer Nothing else case args of
["-p",port] -> maybe showError
(\ (p,r) -> if all isSpace r
then mainServer (Just p)
else showError )
(readNat port)
["-h"] -> showHelp
["-?"] -> showHelp
["--help"] -> showHelp
[ananame,mname] ->
processArgs args
processArgs args = case args of
[] -> mainServer Nothing
["-p",port] -> maybe showError
(\ (p,r) -> if all isSpace r
then mainServer (Just p)
else showError )
(readNat port)
["-h"] -> showHelp
["-?"] -> showHelp
["--help"] -> showHelp
(('-':'D':kvs):rargs) -> let (key,eqvalue) = break (=='=') kvs
in if null eqvalue
then showError
else do updateCurrentProperty key (tail eqvalue)
processArgs rargs
[ananame,mname] ->
if ananame `elem` registeredAnalysisNames
then analyzeModule ananame mname AText >>=
putStrLn . formatResult mname "Text" Nothing True
else showError
_ -> showError
_ -> showError
where
showError = error "Illegal arguments (use '--help' for description)"
showError =
error ("Illegal arguments (use '--help' for description):\n"++unwords args)
--- Initializations to be done when the system is started.
initializeAnalysisSystem :: IO ()
initializeAnalysisSystem = updateRCFile
showHelp = putStrLn $
"Usage: cass [-p <port>] :\n" ++
"Usage: cass <options> [-p <port>] :\n" ++
" start analysis system in server mode\n\n"++
" <port>: port number for communication\n" ++
" (if omitted, a free port number is selected)\n\n"++
"Usage: cass <analysis name> <module name> :\n"++
"Usage: cass <options> <analysis name> <module name> :\n"++
" analyze a module with a given analysis\n\n"++
"where <options> can contain:\n"++
"-Dname=val : set property (of ~/.curryanalysisrc) 'name' as 'val'\n\n"++
"Registered analyses names:\n" ++
unlines registeredAnalysisNames
......
......@@ -10,7 +10,8 @@
--------------------------------------------------------------------------
module Configuration
(systemBanner,baseDir,getServerAddress,updateRCFile,getFPMethod,getWithPrelude,
(systemBanner,baseDir,getServerAddress,updateRCFile,updateCurrentProperty,
getFPMethod,getWithPrelude,
storeServerPortNumber,removeServerPortNumber,getServerPortNumber,
getDefaultPath,waitTime,numberOfWorkers,debugMessageLevel) where
......@@ -27,7 +28,7 @@ import Char(isSpace)
systemBanner =
let bannerText = "CASS: Curry Analysis Server System ("++
"version of 24/05/2013 for "++curryCompiler++")"
"version of 29/05/2013 for "++curryCompiler++")"
bannerLine = take (length bannerText) (repeat '=')
in bannerLine ++ "\n" ++ bannerText ++ "\n" ++ bannerLine
......@@ -60,10 +61,10 @@ installPropertyFile = do
updateRCFile :: IO ()
updateRCFile = do
installPropertyFile
rcName <- propertyFileName
userprops <- readPropertyFile rcName
userprops <- readPropertiesAndStoreLocally
distprops <- readPropertyFile defaultPropertyFileName
if (rcKeys userprops == rcKeys distprops) then done else do
rcName <- propertyFileName
putStrLn $ "Updating \"" ++ rcName ++ "\"..."
renameFile rcName $ rcName <.> "bak"
copyFile defaultPropertyFileName rcName
......@@ -75,21 +76,36 @@ updateRCFile = do
rcKeys :: [(String, String)] -> [String]
rcKeys = mergeSort (<=) . map fst
--- Reads the user property file (which must be installed!)
--- and store the properties in a global variable for next access.
readPropertiesAndStoreLocally :: IO [(String,String)]
readPropertiesAndStoreLocally = do
pfn <- propertyFileName
props <- readPropertyFile pfn
writeGlobal currProps (Just props)
return props
--- Reads the user property file (which must be installed!)
--- and store the properties in a global variable for next access.
getProperties :: IO [(String,String)]
getProperties =
(readGlobal currProps) >>=
maybe (do pfn <- propertyFileName
props <- readPropertyFile pfn
writeGlobal currProps (Just props)
return props )
return
readGlobal currProps >>= maybe readPropertiesAndStoreLocally return
--- Global variable to store the current properties.
currProps :: Global (Maybe [(String,String)])
currProps = global Nothing Temporary
-- Updates a current property.
updateCurrentProperty :: String -> String -> IO ()
updateCurrentProperty pn pv = do
currprops <- getProperties
writeGlobal currProps (Just (replaceKeyValue pn pv currprops))
replaceKeyValue k v [] = [(k,v)]
replaceKeyValue k v ((k1,v1):kvs) =
if k==k1 then (k,v):kvs else (k1,v1) : replaceKeyValue k v kvs
--------------------------------------------------------------------------
--- Gets the name of file containing the current server port and pid
--- ($HOME has to be set)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment