/***************************************************************************************/ /* */ /* SCS editor Version 2 */ /* File : Parameters.pkg */ /* Version : 28 Juin 2000 */ /* Parameters struct and basic functions */ /* */ /***************************************************************************************/ /* data */ struct Parameters = [ PARAMScontent : [[S r1] r1] /* parameters list */ ] mkParameters ;; typeof SCSparameters = Parameters;; var PARAMS_bFastFlush = 1 ;; fun PARAMS_SetFlushState(bool) = { set PARAMS_bFastFlush = bool ; 0 } ;; /*************************************************************************************** Create a new Parameters struct loading its content from a list of list of strings ([[S r1] r1]). The function returns the created Parameters struct. ***************************************************************************************/ fun PARAMS_Load (content) = mkParameters [ content ] ;; /*************************************************************************************** Returns a list of list of strings containing all the parameters in order to save them in a file. ***************************************************************************************/ fun PARAMS_Save (params) = params.PARAMScontent ;; fun PARAMS_Flush() = { if !PARAMS_bFastFlush then nil else _storepack strbuild PARAMS_Save SCSparameters strcat SCS_PATH "scs2.ini" ; 0 } ;; /*************************************************************************************** Get a parameter according to the provided key string ***************************************************************************************/ fun PARAMS_GetS (params, key) = getInfo params.PARAMScontent key ;; fun PARAMS_GetLS (params, key) = switchstr params.PARAMScontent key ;; fun PARAMS_GetI (params, key) = atoi getInfo params.PARAMScontent key ;; fun PARAMS_GetLI (params, key) = let switchstr params.PARAMScontent key -> sl in _slist_to_ilist sl ;; /*************************************************************************************** Set parameters ***************************************************************************************/ fun PARAMS_SetS (params, key, value) = { let switchstr params.PARAMScontent key -> vv in if vv==nil then ( set params.PARAMScontent = (key::value::nil)::params.PARAMScontent; 1 ) else ( mutate vv <- [value _]; 0 ) ; PARAMS_Flush ; } ;; fun PARAMS_SetLS (params, key, lvalues) = { let switchstr params.PARAMScontent key -> vv in if vv == nil then ( set params.PARAMScontent = (key::lvalues)::params.PARAMScontent; 1 ) else ( mutate vv <- [hd lvalues tl lvalues]; 0 ) ; PARAMS_Flush ; };; fun PARAMS_SetI (params, key, value) = { let itoa value -> sv in PARAMS_SetS params key sv ; PARAMS_Flush ; };; fun PARAMS_SetLI (params, key, lvalues) = { let _ilist_to_slist lvalues -> sl in PARAMS_SetLS params key sl ; PARAMS_Flush ; } ;; fun PARAMS_Init () = let _getpack _checkpack strcat SCS_PATH "scs2.ini" -> pack in if pack == nil then { ERRORS_AddError 1 9 (_locSCS "errorlabel-9" nil) ; logScsError "PARAMS_Init" nil "Parameter file scs2.ini cannot be open !" nil } else set SCSparameters = PARAMS_Load strextr pack ;; fun PARAMS_Quit () = _storepack strbuild PARAMS_Save SCSparameters strcat SCS_PATH "scs2.ini" ;;