1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
module CASS.Configuration
( systemBanner, baseDir, docDir, executableName
, curryInfoAnalyses
, CConfig(..), defaultCConfig, debugLevel, setDebugLevel
, getServerAddress
, useCurryInfo, useCurryInfoCGI, fixpointMethod, withPrelude
, storeServerPortNumber, removeServerPortNumber
, getDefaultPath, waitTime, numberOfWorkers
) where
import Control.Monad ( unless, when )
import Curry.Compiler.Distribution ( curryCompiler )
import Data.List ( sort )
import Numeric ( readInt )
import System.Environment ( getEnv )
import System.FilePath ( (</>) )
import System.IO ( hPutStrLn, stderr )
import System.Directory ( getHomeDirectory, removeFile )
import System.Process ( getPID )
import Analysis.Logging ( DLevel(..), debugMessage )
import CASS.PackageConfig ( packagePath, packageExecutable, packageVersion )
systemBanner :: String
systemBanner =
let bannerText = "CASS: Curry Analysis Server System (Version " ++
packageVersion ++ " of 12/01/2025 for " ++
curryCompiler ++ ")"
bannerLine = take (length bannerText) (repeat '=')
in bannerLine ++ "\n" ++ bannerText ++ "\n" ++ bannerLine
baseDir :: String
baseDir = packagePath
docDir :: String
docDir = baseDir </> "docs"
executableName :: String
executableName = packageExecutable
getServerAddress :: IO String
getServerAddress = return "127.0.0.1"
waitTime :: Int
waitTime = -1
defaultWorkers :: Int
defaultWorkers = 0
curryInfoAnalyses :: [String]
curryInfoAnalyses =
[ "Deterministic"
, "Demand"
, "Indeterministic"
, "SolComplete"
, "Terminating"
, "Total"
, "Values"
]
data CConfig = CConfig { ccProps :: [(String,String)], ccDebugLevel :: DLevel }
defaultCConfig :: CConfig
defaultCConfig = CConfig [] Quiet
debugLevel :: CConfig -> DLevel
debugLevel = ccDebugLevel
setDebugLevel :: Int -> CConfig -> CConfig
setDebugLevel dl cc = cc { ccDebugLevel = toEnum dl }
useCurryInfo :: CConfig -> Bool
useCurryInfo cc =
maybe False (`elem` ["yes","cgi"]) (lookup "curryinfo" (ccProps cc))
useCurryInfoCGI :: CConfig -> Bool
useCurryInfoCGI cc = maybe False (=="cgi") (lookup "curryinfo" (ccProps cc))
fixpointMethod :: CConfig -> String
fixpointMethod cc = maybe "wlist" id (lookup "fixpoint" (ccProps cc))
withPrelude :: CConfig -> Bool
withPrelude cc = maybe True (/="no") (lookup "prelude" (ccProps cc))
getDefaultPath :: CConfig -> IO String
getDefaultPath cc = do
currypath <- getEnv "CURRYPATH"
return $ case lookup "path" (ccProps cc) of
Just value -> if all isSpace value
then currypath
else if null currypath then value
else currypath ++ ':' : value
Nothing -> currypath
numberOfWorkers :: CConfig -> Int
numberOfWorkers cc = do
case lookup "numberOfWorkers" (ccProps cc) of
Just value -> case readInt value of
[(int,_)] -> int
_ -> defaultWorkers
Nothing -> defaultWorkers
getServerPortFileName :: IO String
getServerPortFileName = (</> ".cass.port") `fmap` getHomeDirectory
storeServerPortNumber :: Int -> IO ()
storeServerPortNumber portnum = do
mypid <- getPID
serverPortFileName <- getServerPortFileName
writeFile serverPortFileName (show (portnum,mypid))
removeServerPortNumber :: IO ()
removeServerPortNumber = getServerPortFileName >>= removeFile
readServerPortPid :: IO (Int,Int)
readServerPortPid = getServerPortFileName >>= readFile >>= return . read
|